UNPKG

842 BJavaScriptView Raw
1'use strict'
2
3const path = require('path')
4const PLUGIN_PATH = require('../util/path').PLUGIN_PATH
5const info = require(path.join(PLUGIN_PATH, 'package.json'))
6const dependencies = info.dependencies
7
8module.exports = function (program) {
9 for (var name in dependencies) {
10 if (/^xdc-(\S+)-command$/.test(name)) {
11 const commandName = name.replace(/^xdc-(\S+)-command$/, '$1')
12 const description = require(path.join(name, 'package.json')).description
13 const action = (_name => () => require(_name)(program))(name)
14 const command = program.command(commandName)
15
16 command.allowUnknownOption()
17 command.description(description)
18 try {
19 require(path.join(name, 'options'))(command)
20 } catch (_) {
21 // options.js 文件不存在则不处理
22 }
23 command.action(action)
24 }
25 }
26}