我正在使用Oclif编写一个CLI,并试图执行我构建的自定义原理图,但是如果我使用"ng add“命令启动分离,则图表要求是正确的。如果我从Oclif发出示意图,它什么都不问。
示例:
作品:航站楼: ng add :/projects/ams-前台示意图
不要工作:
export default class New extends Command {
static description = 'Generate new project based in archetype';
static args: Parser.args.IArg[] = [ { name: 'PROJECT_NAME', required: true } ];
private answers: any;
async run(): Promise<any> {
const { args }: { args: Parser.args.Output } = this.parse(New);
const name: string = args.PROJECT_NAME;
process.setMaxListeners(0);
require('events').EventEmitter.defaultMaxListeners = 100;
await runCommand(`ng add D:/projects/schematics/ams-front-schematics`, {}, (...args: any[]) => this.log(...args)););
}
}只运行命令函数exec: npmRun库。
export function runCommand(commands: string, options: any = {}, debug: (...args: any[]) => void) {
return new Promise(resolve => {
debug('command', commands);
npmRun.exec(commands, options, (err: any, stdout: any, stderr: any) => {
debug('err', err);
debug('stdout', stdout);
debug('stderr', stderr);
if (err) {
debug(stderr);
debug('End', err);
resolve();
} else {
debug(stdout);
debug('End', true);
resolve();
}
});
});
}发布于 2020-08-28 06:19:07
您可以简单地将角度示意图cli @angular-devkit/schematics-cli集成到oclif项目中。
按照下面的代码片段,@angular-devkit/schematics-cli
运行cli即可。
注意:用于测试您必须从角项目运行此命令
import { Command } from "@oclif/command";
import { main } from "@angular-devkit/schematics-cli/bin/schematics";
class AngularSchematicsCli extends Command {
...
async run() {
...
await main({
args: ["@schematics/angular:component"],
});
// You can customise this args according to angular schematics
// args: ["@schematics/angular:component", "--name=test"],
}
}
export = AngularSchematicsCli;
https://stackoverflow.com/questions/60366513
复制相似问题