2 Object.defineProperty(exports, "__esModule", { value: true });
3 // Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
4 /* Initialize access to schematics registry */
7 //first try to use schematics utils approach
8 provider = require("./schematicsProvider60");
12 //if not working than try to load SchematicCommand
13 provider = require("./schematicsProvider62");
16 console.info("No schematics");
20 var path = require("path");
21 var fs = require("fs");
22 var engineHost = provider.getEngineHost();
23 var includeHidden = process.argv[2] === "--includeHidden";
24 var defaultCollectionName;
26 defaultCollectionName = require('@angular/cli/utilities/config').getDefaultSchematicCollection();
29 defaultCollectionName = require('@angular/cli/models/config').CliConfig.getValue('defaults.schematics.collection');
31 var collections = getAvailableSchematicCollections();
32 if (collections.indexOf(defaultCollectionName) < 0) {
33 collections.push(defaultCollectionName);
35 var allSchematics = collections
36 // Update schematics should be executed only with `ng update`
37 .filter(function (c) { return c !== "@schematics/update"; })
38 .map(getCollectionSchematics)
39 .reduce(function (a, b) { return a.concat.apply(a, b); });
40 console.info(JSON.stringify(allSchematics, null, 2));
41 function getAvailableSchematicCollections() {
44 fs.readdirSync(path.resolve(process.cwd(), "node_modules")).forEach(function (dir) {
45 if (dir.startsWith("@")) {
46 fs.readdirSync(path.resolve(process.cwd(), "node_modules/" + dir)).forEach(function (subDir) {
47 packages.push(dir + "/" + subDir);
54 for (var _i = 0, packages_1 = packages; _i < packages_1.length; _i++) {
55 var pkgName = packages_1[_i];
56 var pkgPath = path.resolve(process.cwd(), "node_modules/" + pkgName + "/package.json");
57 if (fs.existsSync(pkgPath)) {
58 var subInfo = require(pkgPath);
59 if (subInfo !== undefined && subInfo.schematics !== undefined) {
66 function getCollectionSchematics(collectionName) {
70 collection = provider.getCollection(collectionName);
71 schematicNames = includeHidden
72 ? listAllSchematics(collection)
73 : engineHost.listSchematics(collection);
82 var schematicInfos = schematicNames
83 .map(function (name) { return provider.getSchematic(collection, name).description; })
84 //`ng-add` schematics should be executed only with `ng add`
85 .filter(function (info) { return (info.name !== "ng-add" || includeHidden) && info.schemaJson !== undefined; });
86 var newFormat_1 = schematicInfos
87 .map(function (info) { return info.schemaJson.properties; })
88 .map(function (prop) { return Object.keys(prop).map(function (k) { return prop[k]; }); })
89 .reduce(function (a, b) { return a.concat(b); }, [])
90 .find(function (prop) { return prop.$default; });
91 return schematicInfos.map(function (info) {
92 var required = info.schemaJson.required || [];
94 description: info.description,
95 name: (collectionName === defaultCollectionName ? "" : collectionName + ":") + info.name,
97 options: filterProps(info.schemaJson, function (key, prop) { return newFormat_1 ? prop.$default === undefined : required.indexOf(key) < 0; })
98 .concat(coreOptions()),
99 arguments: filterProps(info.schemaJson, function (key, prop) { return newFormat_1 ? prop.$default !== undefined && prop.$default.$source === "argv" : required.indexOf(key) >= 0; })
104 console.error(e.stack || e);
108 function listAllSchematics(collection) {
109 collection = collection.description;
111 for (var _i = 0, _a = Object.keys(collection.schematics); _i < _a.length; _i++) {
113 var schematic = collection.schematics[key];
114 if (schematic.private) {
117 // If extends is present without a factory it is an alias, do not return it
118 // unless it is from another collection.
119 if (!schematic.extends || schematic.factory) {
120 schematics.push(key);
122 else if (schematic.extends && schematic.extends.indexOf(':') !== -1) {
123 schematics.push(key);
128 function filterProps(schemaJson, filter) {
129 var required = schemaJson.required || [];
130 var props = schemaJson.properties;
131 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]); });
133 function coreOptions() {
140 description: 'Run through without making any changes.',
147 description: 'Forces overwriting of files.',