@angular-devkit/schematics#schematic TypeScript Examples

The following examples show how to use @angular-devkit/schematics#schematic. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: index.ts    From ng-ant-admin with MIT License 6 votes vote down vote up
function twoLevelRule(_options: any): Rule {
    return (tree: Tree, _context: SchematicContext) => {
        let source = apply(url(`./files/src/app/pages`), [move(`./src/app/pages/${_options.mName}`), applyTemplates({
            ...strings,
            ..._options, // 使用者所輸入的參數
        })]);
        return chain([
            mergeWith(source),
            schematic('b-s', {dirname: _options.mName, filename: _options.name},),
            schematic('b-m', {name: _options.name, isTwoLevel: true},),
            move(`./src/app/pages/${_options.name}`, `./src/app/pages/${_options.mName}/${_options.name}`),
            schematic('component-lazy-m', {mName: _options.mName, name: _options.name},),
        ])
    };

}
Example #2
Source File: index.ts    From ng-ant-admin with MIT License 6 votes vote down vote up
export default function (_options: any): Rule {
    return (tree: Tree, _context: SchematicContext) => {
        /*是二级菜单*/
        if (_options.isTwoLevel == true) {
            return chain([
                schematic('layout-lazy-m', {name: _options.name}),
                schematic('b-m', {name: _options.name, isTwoLevel: false}),
                generTwoLevelModuleRoute(_options, tree),
                // schematic('component-lazy-m', {name: _options.name, isTwoLevel: false}),
            ]);
        } else {
            /*一级菜单*/
            return chain([
                /* 添加default-routing.module.ts 路由*/
                schematic('layout-lazy-m', {name: _options.name}),
                schematic('b-s', {dirname: _options.name, filename: _options.name}),
                schematic('b-m', {name: _options.name, isTwoLevel: false}),
                schematic('b-c', {name: _options.name, mName: _options.name}),
                fnGenerateImport(_options.name, `src/app/pages/${dasherize(_options.name)}/${dasherize(_options.name)}-routing.module.ts`, tree)
            ]);
        }
    };
}
Example #3
Source File: index.ts    From ng-ant-admin with MIT License 5 votes vote down vote up
export default function (_options: any): Rule {
    const isOneLevel = _options.mName === _options.name;
    return (tree: Tree, _context: SchematicContext) => {
        let rules: Rule[] = [];
        // 是一级菜单
        if (isOneLevel) {
            rules = [...rules, ...[
                oneLevelRule(_options),
                addDeclarationToNgModule(_options, `${dasherize(_options.mName)}/${dasherize(_options.name)}`),
                schematic('component-lazy-m', {
                    mName: _options.mName,
                    name: _options.name
                },),
            ]]
        } else {
            rules = [...rules, ...[
                twoLevelRule(_options),
                addDeclarationToNgModule(_options, `${dasherize(_options.mName)}/${dasherize(_options.name)}/${dasherize(_options.name)}`),
                fnGenerateImport(_options.name, `src/app/pages/${dasherize(_options.mName)}/${dasherize(_options.name)}/${dasherize(_options.name)}-routing.module.ts`, tree),
                fnGenerateRouteModulePath(tree, `src/app/pages/${dasherize(_options.mName)}/${dasherize(_options.mName)}-routing.module.ts`, _options.name,)
            ]]

        }
        if (_options.needAddModal) {
            rules.push(schematic("b-modal", {name: _options.name,isOneLevel:isOneLevel,mName:_options.mName}));
            // 业务组件中modal位置
            let modalComponentFilePath = `./src/app/pages/${_options.name}/${_options.name}.module.ts`;
            if (!isOneLevel) {
                rules.push(move(`./src/app/widget/biz-widget/${_options.name}-modal`, `./src/app/widget/biz-widget/${_options.mName}/${_options.name}-modal`),)
                modalComponentFilePath = `./src/app/pages/${_options.mName}/${_options.name}/${_options.name}.module.ts`;
            }
            // 添加import
            rules.push(fnGenerateImport(_options.name, modalComponentFilePath, tree, "Modal",isOneLevel,_options.mName))
            // 添加imports[]里面的
            rules.push(fnGenerateModalModule(tree,modalComponentFilePath,_options.name))

        }
        return chain(rules);
    };
}
Example #4
Source File: index.ts    From open-source with MIT License 5 votes vote down vote up
export default function (options: ModuleOptions): Rule {
  return async (host: Tree) => {
    const workspace = await getWorkspace(host);
    const project = workspace.projects.get(options.project as string);

    if (options.path === undefined) {
      options.path = await createDefaultPath(host, options.project as string);
    }

    if (options.module) {
      options.module = findModuleFromOptions(host, options);
    }

    if (options.prefix === undefined) {
      options.prefix = project?.prefix || '';
    }

    const parsedPath = parseName(options.path, options.name);
    options.name = parsedPath.name;
    options.path = parsedPath.path;

    const templateSource = apply(url('./files'), [
      applyTemplates({
        ...strings,
        'if-flat': (s: string) => (options.flat ? '' : s),
        ...options,
      }),
      move(parsedPath.path),
    ]);
    const moduleDasherized = strings.dasherize(options.name);
    const controlDasherized = strings.dasherize(options.controlName);
    const controlPath = `${options.path}/${
      !options.flat ? `${moduleDasherized}/` : ''
    }${options.controlPath}${options.flat ? `/${controlDasherized}` : ''}`;

    const controlOptions: ControlOptions = {
      project: options.project,
      path: controlPath,
      name: controlDasherized,
      type: options.type,
      id: options.id || 'CONTROL',
      instance: options.instance || 'Control',
      flat: options.flat,
      prefix: options.prefix,
      prefixInterface: options.prefixInterface,
      prefixClass: options.prefixClass,
    };

    return chain([
      mergeWith(templateSource),
      schematic('control', controlOptions),
      options.lintFix ? applyLintFix(options.path) : noop(),
    ]);
  };
}