UNPKG

2.37 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3const fs = require("fs");
4const path = require("path");
5const os = require("os");
6const config_1 = require("../models/config");
7const chalk = require('chalk');
8const EmberGenerateCommand = require('../ember-cli/lib/commands/generate');
9const Blueprint = require('../ember-cli/lib/models/blueprint');
10const SilentError = require('silent-error');
11const blueprintList = fs.readdirSync(path.join(__dirname, '..', 'blueprints'));
12const blueprints = blueprintList
13 .filter(bp => bp.indexOf('-test') === -1)
14 .filter(bp => bp !== 'ng')
15 .map(bp => Blueprint.load(path.join(__dirname, '..', 'blueprints', bp)));
16const GenerateCommand = EmberGenerateCommand.extend({
17 name: 'generate',
18 blueprints: blueprints,
19 beforeRun: function (rawArgs) {
20 if (!rawArgs.length) {
21 return;
22 }
23 // map the blueprint name to allow for aliases
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 // Override default help to hide ember blueprints
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});
41function mapBlueprintName(name) {
42 let mappedName = aliasMap[name];
43 return mappedName ? mappedName : name;
44}
45const 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};
56exports.default = GenerateCommand;
57GenerateCommand.overrideCore = true;
58//# sourceMappingURL=/users/hans/sources/angular-cli/commands/generate.js.map
\No newline at end of file