UNPKG

2.62 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3const fs = require("fs");
4const path = require("path");
5const Command = require('../ember-cli/lib/models/command');
6const stringUtils = require('ember-cli-string-utils');
7const lookupCommand = require('../ember-cli/lib/cli/lookup-command');
8const commandsToIgnore = [
9 'easter-egg',
10 'init',
11 'destroy'
12];
13const HelpCommand = Command.extend({
14 name: 'help',
15 description: 'Shows help for the CLI.',
16 works: 'everywhere',
17 availableOptions: [],
18 anonymousOptions: ['command-name (Default: all)'],
19 run: function (commandOptions, rawArgs) {
20 let commandFiles = fs.readdirSync(__dirname)
21 .filter(file => file.match(/\.(j|t)s$/) && !file.match(/\.d.ts$/))
22 .map(file => path.parse(file).name)
23 .map(file => file.toLowerCase());
24 commandFiles = commandFiles.filter(file => {
25 return commandsToIgnore.indexOf(file) < 0;
26 });
27 let commandMap = commandFiles.reduce((acc, curr) => {
28 let classifiedName = stringUtils.classify(curr);
29 let defaultImport = require(`./${curr}`).default;
30 acc[classifiedName] = defaultImport;
31 return acc;
32 }, {});
33 if (rawArgs.indexOf('all') !== -1) {
34 rawArgs = []; // just act as if command not specified
35 }
36 commandFiles.forEach(cmd => {
37 let Command = lookupCommand(commandMap, cmd);
38 let command = new Command({
39 ui: this.ui,
40 project: this.project,
41 commands: this.commands,
42 tasks: this.tasks
43 });
44 if (rawArgs.length > 0) {
45 let commandInput = rawArgs[0];
46 const aliases = Command.prototype.aliases;
47 if (aliases && aliases.indexOf(commandInput) > -1) {
48 commandInput = Command.prototype.name;
49 }
50 if (cmd === commandInput) {
51 if (command.printDetailedHelp(commandOptions)) {
52 this.ui.writeLine(command.printDetailedHelp(commandOptions));
53 }
54 else {
55 this.ui.writeLine(command.printBasicHelp(commandOptions));
56 }
57 }
58 }
59 else {
60 this.ui.writeLine(command.printBasicHelp(commandOptions));
61 }
62 });
63 }
64});
65HelpCommand.overrideCore = true;
66exports.default = HelpCommand;
67//# sourceMappingURL=/users/hans/sources/angular-cli/commands/help.js.map
\No newline at end of file