|
| 1 | +import * as fs from 'fs'; |
| 2 | +import * as path from 'path'; |
| 3 | + |
| 4 | +const Command = require('ember-cli/lib/models/command'); |
| 5 | +const EmberHelpCommand = require('ember-cli/lib/commands/help'); |
| 6 | +const stringUtils = require('ember-cli-string-utils'); |
| 7 | +const lookupCommand = require('ember-cli/lib/cli/lookup-command'); |
| 8 | + |
| 9 | +const commandsToIgnore = [ |
| 10 | + 'help', |
| 11 | + 'easter-egg', |
| 12 | + 'completion', |
| 13 | + 'github-pages-deploy' |
| 14 | +] |
| 15 | + |
| 16 | +const HelpCommand = Command.extend({ |
| 17 | + name: 'help', |
| 18 | + description: 'Shows help for the CLI', |
| 19 | + works: 'outsideProject', |
| 20 | + |
| 21 | + availableOptions: [], |
| 22 | + |
| 23 | + run: function (commandOptions: any) { |
| 24 | + let commandFiles = fs.readdirSync(__dirname) |
| 25 | + .map(file => path.parse(file).name) |
| 26 | + .map(file => file.toLowerCase()); |
| 27 | + |
| 28 | + commandFiles = commandFiles.filter(file => { |
| 29 | + return commandsToIgnore.indexOf(file) < 0; |
| 30 | + }); |
| 31 | + |
| 32 | + let commandMap = commandFiles.reduce((acc: any, curr: string) => { |
| 33 | + let classifiedName = stringUtils.classify(curr); |
| 34 | + let defaultImport = require(`./${curr}`).default |
| 35 | + |
| 36 | + acc[classifiedName] = defaultImport; |
| 37 | + |
| 38 | + return acc; |
| 39 | + }, {}); |
| 40 | + |
| 41 | + commandFiles.forEach(cmd => { |
| 42 | + let Command = lookupCommand(commandMap, cmd); |
| 43 | + |
| 44 | + let command = new Command({ |
| 45 | + ui: this.ui, |
| 46 | + project: this.project, |
| 47 | + commands: this.commands, |
| 48 | + tasks: this.tasks |
| 49 | + }); |
| 50 | + |
| 51 | + this.ui.writeLine(command.printBasicHelp(commandOptions)); |
| 52 | + }) |
| 53 | + } |
| 54 | +}); |
| 55 | + |
| 56 | +HelpCommand.overrideCore = true; |
| 57 | +export default HelpCommand; |
0 commit comments