UNPKG

3.63 kBJavaScriptView Raw
1// TODO REDESIGN for new schematics version!
2//
3// import {RuntimeLoader} from '../base/RuntimeLoader';
4// import {Inject} from 'typedi';
5// import {Config} from 'commons-config';
6// import {terminal, } from '@angular-devkit/core';
7// import * as _ from 'lodash';
8//
9// import {PlatformUtils, FileUtils} from 'commons-base';
10// import {SchematicsExecutor} from '../index';
11// import {ICommand} from '../libs/commands/ICommand';
12//
13// export class GenerateCommand implements ICommand {
14//
15//
16// @Inject('RuntimeLoader')
17// loader: RuntimeLoader;
18//
19// command = 'generate [schematic] [collection]';
20//
21// aliases = 'g';
22//
23// describe = 'Generate schematics';
24//
25//
26// builder(yargs: any) {
27// return yargs;
28// }
29//
30// async handler(argv: any) {
31//
32// const _argv = Config.get('argv');
33// const infos = await this.loader.getSchematicsInfos();
34//
35// if (!argv.schematic) {
36// console.log(terminal.yellow('No schematic selected.') + '\n\nSelect one of the following:\n');
37// for (const info of infos) {
38// let out = ' ' + info.name + '\n';
39//
40// for (const collName in info.collection.schematics) {
41// const def = info.collection.schematics[collName];
42// out += ' - ' + collName + '\n';
43// out += ' ' + def.description + '\n';
44//
45// }
46// console.log(out);
47// }
48// } else {
49// const res = _.filter(infos, x => {
50// const _x = _.has(x.collection.schematics, argv.schematic);
51// if (argv.collection) {
52// return _x && x.name === argv.collection;
53// }
54// return _x;
55// });
56//
57// if (res.length === 1) {
58// // okay!
59// const info = res.shift();
60//
61// const defSchematic = info.collection.schematics[argv.schematic];
62// const schema = await FileUtils.getJson(PlatformUtils.join(info.path, defSchematic.schema));
63//
64// if (_argv.schema) {
65// console.log(schema);
66//
67// } else {
68// console.log('\n' + argv.schematic + ' from ' + info.name + '\n');
69//
70// const workdir = _argv.workdir ? _argv.workdir : '.';
71// const appdir = _argv.appdir ? _argv.appdir : '.';
72//
73// let requiredChecked = true;
74//
75// if (schema.required) {
76// for (const r of schema.required) {
77// if (!_.has(_argv, r)) {
78// requiredChecked = false;
79// console.log(' - required parameter \"' + r + '\" is not set');
80// }
81// }
82// }
83//
84// if (requiredChecked) {
85//
86// const executor = new SchematicsExecutor({
87// workdir: PlatformUtils.pathResolve(workdir),
88// basedir: PlatformUtils.pathResolve(appdir),
89// collectionName: info.internal || info.submodule ? info.path : info.name,
90// schematicName: argv.schematic,
91// argv: _argv
92// });
93//
94// try {
95// await executor.run();
96// } catch (e) {
97// console.error(e);
98// }
99//
100// } else {
101// console.log('\nMissing required parameter. Processing skipped.\n');
102// }
103// }
104//
105// } else if (res.length > 1) {
106// console.log('more then one results (' + res.length + ') for ' +
107// 'schematic ' + argv.schematic + '. Append collection name to reduce results.');
108// } else {
109// console.log('No schematic with this name found.');
110// }
111// }
112//
113// }
114// }
115//
116
117//# sourceMappingURL=GenerateCommand.js.map