2 Object.defineProperty(exports, "__esModule", { value: true });
4 require('@angular/cli/utilities/schematics');
7 console.info("No schematics");
10 var schematics_1 = require("@angular/cli/utilities/schematics");
11 var path = require("path");
12 var fs = require("fs");
13 var engineHost = schematics_1.getEngineHost();
14 var includeHidden = process.argv[2] === "--includeHidden";
15 var defaultCollectionName;
17 defaultCollectionName = require('@angular/cli/utilities/config').getDefaultSchematicCollection();
20 defaultCollectionName = require('@angular/cli/models/config').CliConfig.getValue('defaults.schematics.collection');
22 var collections = getAvailableSchematicCollections();
23 if (collections.indexOf(defaultCollectionName) < 0) {
24 collections.push(defaultCollectionName);
26 var allSchematics = collections
27 // Update schematics should be executed only with `ng update`
28 .filter(function (c) { return c !== "@schematics/update"; })
29 .map(getCollectionSchematics)
30 .reduce(function (a, b) { return a.concat.apply(a, b); });
31 console.info(JSON.stringify(allSchematics, null, 2));
32 function getAvailableSchematicCollections() {
35 fs.readdirSync(path.resolve(process.cwd(), "node_modules")).forEach(function (dir) {
36 if (dir.startsWith("@")) {
37 fs.readdirSync(path.resolve(process.cwd(), "node_modules/" + dir)).forEach(function (subDir) {
38 packages.push(dir + "/" + subDir);
45 for (var _i = 0, packages_1 = packages; _i < packages_1.length; _i++) {
46 var pkgName = packages_1[_i];
47 var pkgPath = path.resolve(process.cwd(), "node_modules/" + pkgName + "/package.json");
48 if (fs.existsSync(pkgPath)) {
49 var subInfo = require(pkgPath);
50 if (subInfo !== undefined && subInfo.schematics !== undefined) {
57 function getCollectionSchematics(collectionName) {
61 collection = schematics_1.getCollection(collectionName);
62 schematicNames = includeHidden
63 ? listAllSchematics(collection)
64 : engineHost.listSchematics(collection);
73 var schematicInfos = schematicNames
74 .map(function (name) { return schematics_1.getSchematic(collection, name).description; })
75 //`ng-add` schematics should be executed only with `ng add`
76 .filter(function (info) { return (info.name !== "ng-add" || includeHidden) && info.schemaJson !== undefined; });
77 var newFormat_1 = schematicInfos
78 .map(function (info) { return info.schemaJson.properties; })
79 .map(function (prop) { return Object.keys(prop).map(function (k) { return prop[k]; }); })
80 .reduce(function (a, b) { return a.concat(b); }, [])
81 .find(function (prop) { return prop.$default; });
82 return schematicInfos.map(function (info) {
83 var required = info.schemaJson.required || [];
85 description: info.description,
86 name: (collectionName === defaultCollectionName ? "" : collectionName + ":") + info.name,
88 options: filterProps(info.schemaJson, function (key, prop) { return newFormat_1 ? prop.$default === undefined : required.indexOf(key) < 0; })
89 .concat(coreOptions()),
90 arguments: filterProps(info.schemaJson, function (key, prop) { return newFormat_1 ? prop.$default !== undefined && prop.$default.$source === "argv" : required.indexOf(key) >= 0; })
95 console.error(e.stack || e);
99 function listAllSchematics(collection) {
100 collection = collection.description;
102 for (var _i = 0, _a = Object.keys(collection.schematics); _i < _a.length; _i++) {
104 var schematic = collection.schematics[key];
105 if (schematic.private) {
108 // If extends is present without a factory it is an alias, do not return it
109 // unless it is from another collection.
110 if (!schematic.extends || schematic.factory) {
111 schematics.push(key);
113 else if (schematic.extends && schematic.extends.indexOf(':') !== -1) {
114 schematics.push(key);
119 function filterProps(schemaJson, filter) {
120 var required = schemaJson.required || [];
121 var props = schemaJson.properties;
122 return Object.keys(props).filter(function (key) { return filter(key, props[key]); }).map(function (k) { return Object.assign({ name: k, required: required.indexOf(k) >= 0 }, props[k]); });
124 function coreOptions() {
131 description: 'Run through without making any changes.',
138 description: 'Forces overwriting of files.',