使用自定义角度示意图创建应用程序后如何更新angular json?

时间:2019-10-08 09:24:09

标签: angular angular-schematics

使用命令创建新应用程序后如何更新angular json文件 ng g ./my-components/src/collection.json:customComponent?

export function customComponent(_options: SchemaD): Rule {
    return (tree: Tree, _context: SchematicContext) => {
        const workspaceConfigBuffer = tree.read('angular.json');
        if (!workspaceConfigBuffer) {
            throw new SchematicsException('Not angular cli workspace');
        }
        const workspaceConfig = JSON.parse(workspaceConfigBuffer.toString());
        const projectName = _options.project || workspaceConfig.defaultProject;
        const project = workspaceConfig.projects[projectName];
        const defaultProjectPath = buildDefaultPath(project);
        const parsedPath = parseName(defaultProjectPath, _options.name);
        const { name, path } = parsedPath;
        const sourceTemplates = url('./templateWithRouter');
        const sourceParametrizeTemplates = apply(sourceTemplates, [
            template({
                ..._options,
                ...strings,
                name,
            }),
            move(path),
        ]);
        return mergeWith(sourceParametrizeTemplates)(tree, _context);
    };
}

0 个答案:

没有答案