1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | const fs = require("fs");
|
4 | const path = require("path");
|
5 | const os = require("os");
|
6 | const config_1 = require("../models/config");
|
7 | const chalk = require('chalk');
|
8 | const EmberGenerateCommand = require('../ember-cli/lib/commands/generate');
|
9 | const Blueprint = require('../ember-cli/lib/models/blueprint');
|
10 | const SilentError = require('silent-error');
|
11 | const blueprintList = fs.readdirSync(path.join(__dirname, '..', 'blueprints'));
|
12 | const blueprints = blueprintList
|
13 | .filter(bp => bp.indexOf('-test') === -1)
|
14 | .filter(bp => bp !== 'ng')
|
15 | .map(bp => Blueprint.load(path.join(__dirname, '..', 'blueprints', bp)));
|
16 | const GenerateCommand = EmberGenerateCommand.extend({
|
17 | name: 'generate',
|
18 | blueprints: blueprints,
|
19 | beforeRun: function (rawArgs) {
|
20 | if (!rawArgs.length) {
|
21 | return;
|
22 | }
|
23 |
|
24 | rawArgs[0] = mapBlueprintName(rawArgs[0]);
|
25 | this.project.ngConfig = this.project.ngConfig || config_1.CliConfig.fromProject();
|
26 | if (rawArgs[0] !== '--help' &&
|
27 | !fs.existsSync(path.join(__dirname, '..', 'blueprints', rawArgs[0]))) {
|
28 | SilentError.debugOrThrow('@angular/cli/commands/generate', `Invalid blueprint: ${rawArgs[0]}`);
|
29 | }
|
30 | if (!rawArgs[1]) {
|
31 | SilentError.debugOrThrow('@angular/cli/commands/generate', `The \`ng generate ${rawArgs[0]}\` command requires a name to be specified.`);
|
32 | }
|
33 |
|
34 | EmberGenerateCommand.prototype.printDetailedHelp = function () {
|
35 | this.ui.writeLine(chalk.cyan(' Available blueprints'));
|
36 | this.ui.writeLine(blueprints.map(bp => bp.printBasicHelp(false)).join(os.EOL));
|
37 | };
|
38 | return EmberGenerateCommand.prototype.beforeRun.apply(this, arguments);
|
39 | }
|
40 | });
|
41 | function mapBlueprintName(name) {
|
42 | let mappedName = aliasMap[name];
|
43 | return mappedName ? mappedName : name;
|
44 | }
|
45 | const aliasMap = {
|
46 | 'cl': 'class',
|
47 | 'c': 'component',
|
48 | 'd': 'directive',
|
49 | 'e': 'enum',
|
50 | 'i': 'interface',
|
51 | 'm': 'module',
|
52 | 'p': 'pipe',
|
53 | 'r': 'route',
|
54 | 's': 'service'
|
55 | };
|
56 | exports.default = GenerateCommand;
|
57 | GenerateCommand.overrideCore = true;
|
58 |
|
\ | No newline at end of file |