0

我想先调用Angular的ng-new原理图,然后我的Rule需要对结果进行操作。

所以像:

 chain([
                    externalSchematic('@schematics/angular', 'ng-new', options),
                    schematic('someRule', options)
])

但这不起作用。我的规则需要 angular.json ngNew 应该创建,因为当我的规则开始时显然不存在,所以规则失败。

那么有没有办法等待完成以下任一或以下操作:

a) 等待外部原理图完成,然后运行另一个原理图 b) 使第二个原理图使用第一个原理图返回的树?

就像:

chain([
      externalSchematic('@schematics/angular', 'ng-new', options),
      mergeWith(apply(source(/* tree created by ng-new */), [
        schematic('someStuff', options)
      ])
    )])
4

1 回答 1

0

我不确定为什么最初的方法不适合您,但是您可以angular-cli.json在运行ng-new原理图后使用文件提供的功能之一获取文件内容@angular/schematics/utilities/config.d.ts

export declare function getWorkspacePath(host: Tree): string;
export declare function getWorkspace(host: Tree): WorkspaceSchema;
export declare function addProjectToWorkspace<TProjectType extends ProjectType = ProjectType.Application>(workspace: WorkspaceSchema, name: string, project: WorkspaceProject<TProjectType>): Rule;
export declare function updateWorkspace(workspace: WorkspaceSchema): Rule;
export declare const configPath = "/.angular-cli.json";
export declare function getConfig(host: Tree): CliConfig;
export declare function getAppFromConfig(config: CliConfig, appIndexOrName: string): AppConfig | null;

在这种情况下,getWorkspace会给你angular-cli.json文件的内容。

于 2020-01-07T14:04:14.090 回答