@angular-devkit/schematics#applyTemplates TypeScript Examples

The following examples show how to use @angular-devkit/schematics#applyTemplates. 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: angular-universal.adapter.ts    From nx-plugins with MIT License 6 votes vote down vote up
getApplicationTypeTemplate(): Rule {
    const buildTarget = this.project.targets.get('build') as TargetDefinition;
    return applyTemplates({
      getRootDirectory: () => '',
      buildPath: join(
        `../../../${(buildTarget.options as JsonObject).outputPath}`
      ),
      projectName: this.options.project
    });
  }
Example #2
Source File: nestjs.adapter.ts    From nx-plugins with MIT License 6 votes vote down vote up
getApplicationTypeTemplate(): Rule {
    return applyTemplates({
      rootDir: 'src',
      getRootDirectory: () => 'src',
      stripTsExtension: (s: string) => s.replace(/\.ts$/, ''),
      getRootModuleName: () => 'AppModule',
      getRootModulePath: () => 'app/app.module',
      projectName: this.options.project
    });
  }
Example #3
Source File: webapp.adapter.ts    From nx-plugins with MIT License 6 votes vote down vote up
getApplicationTypeTemplate(): Rule {
    const buildTarget = this.project.targets.get('build') as TargetDefinition;
    return applyTemplates({
      buildPath: join(
        `../../../${(buildTarget.options as JsonObject).outputPath}`
      ),
      projectName: this.options.project
    });
  }
Example #4
Source File: templates.ts    From cli with Apache License 2.0 6 votes vote down vote up
/**
 * Schematic rule that copies files into the Angular project.
 *
 * @export
 * @param {CoveoSchema} _options
 * @param {string} [workspaceRootPath='./']      The root path from which the applyTemplates function will start pasting files.
 *                                               The default value is "./" because the file structure is already defined within the ./files directories
 * @param {string} [templateFilePath='./files']  Path containing the files to copy into the Angular project
 * @returns {Rule}
 */
export function createFiles(
  _options: CoveoSchema,
  workspaceRootPath = './',
  templateFilePath = './files',
  customFilter = isNotNodeModuleFile
): Rule {
  return (tree: Tree, context: SchematicContext) => {
    const templateSource = apply(url(templateFilePath), [
      filter(customFilter),
      applyTemplates({
        ..._options,
      }),
      move(normalize(workspaceRootPath)),
      overwriteIfExists(tree),
    ]);

    const rule = mergeWith(templateSource);
    return rule(tree, context);
  };
}
Example #5
Source File: index.ts    From ng-ant-admin with MIT License 6 votes vote down vote up
function oneLevelRule(_options: any): Rule {
    return (tree: Tree, _context: SchematicContext) => {
        const sourceTemplates = url('./files'); // 使用範本
        const sourceParametrizedTemplates = apply(sourceTemplates, [
            // renameTemplateFiles(), // 去掉后缀
            applyTemplates({
                ...strings,
                ..._options, // 使用者所輸入的參數
            })
        ]);
        return mergeWith(sourceParametrizedTemplates);
    };

}
Example #6
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 #7
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) => {
        const sourceTemplates = url('./files'); // 使用範本
        const sourceParametrizedTemplates = apply(sourceTemplates, [
            // renameTemplateFiles(), // 去掉后缀
            applyTemplates({
                ...strings,
                ..._options, // 使用者所輸入的參數
            })
        ]);
        return mergeWith(sourceParametrizedTemplates);
    };
}
Example #8
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) => {
    const sourceTemplates = url('./files'); // 使用範本
    const sourceParametrizedTemplates = apply(sourceTemplates, [
      // renameTemplateFiles(), // 去掉后缀
      applyTemplates({
        ...strings,
        ..._options, // 使用者所輸入的參數
      })
    ]);
    return mergeWith(sourceParametrizedTemplates);
  };
}
Example #9
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) => {
    const sourceTemplates = url('./files'); // 使用範本
    const sourceParametrizedTemplates = apply(sourceTemplates, [
      // renameTemplateFiles(), // 去掉后缀
      applyTemplates({
        ...strings,
        ..._options, // 使用者所輸入的參數
      })
    ]);
    return mergeWith(sourceParametrizedTemplates);
  };
}
Example #10
Source File: express.adapter.ts    From nx-plugins with MIT License 5 votes vote down vote up
getApplicationTypeTemplate(): Rule {
    return applyTemplates({
      rootDir: 'src',
      getRootDirectory: () => 'src',
      stripTsExtension: (s: string) => s.replace(/\.ts$/, ''),
      projectName: this.options.project
    });
  }
Example #11
Source File: index.ts    From garment with MIT License 5 votes vote down vote up
export default function(options: PackageSchematicOptions): Rule {
  return (tree: Tree, context: SchematicContext) => {
    const { name, directory } = options;
    if (!options.name) {
      throw new SchematicsException('name option is required.');
    }
    if (!tree.getDir('.').subdirs.includes(directory as any)) {
      throw new SchematicsException(`Directory "${directory}" doesn't exist`);
    }

    const dashedName = strings.dasherize(name);
    const packagePath = Path.join(directory, dashedName);

    context.addTask(
      new NodePackageInstallTask({
        workingDirectory: packagePath,
        packageManager: 'yarn'
      })
    );

    let source = apply(url('../../templates/package'), [
      applyTemplates({
        packageName: dashedName,
        dot: '.',
        camelize: strings.camelize,
        dasherize: strings.dasherize
      }),
      move(packagePath)
    ]);

    return chain([
      mergeWith(source),
      addProjectToGarmentJson({
        garmentJsonPath: '/garment.json',
        name: dashedName,
        path: packagePath,
        extendProjects: ['tspackage']
      })
    ]);
  };
}
Example #12
Source File: index.ts    From garment with MIT License 5 votes vote down vote up
export default function(options: Options): Rule {
  return (_tree: Tree, context: SchematicContext) => {
    const { name } = options;
    if (!options.name) {
      throw new SchematicsException('name option is required.');
    }

    const directory = 'plugins';

    const dashedName = strings.dasherize(name);
    const projectName = dashedName;

    context.logger.info(`Creating project called "${projectName}"...`);

    const packagePath = Path.join(directory, projectName);

    context.addTask(
      new NodePackageInstallTask({
        workingDirectory: packagePath,
        packageManager: 'yarn'
      })
    );

    let source = apply(url('../../templates/plugin'), [
      applyTemplates({
        name,
        ...strings
      }),
      move(packagePath)
    ]);

    return chain([
      mergeWith(source),
      addPackageJsonDependencies(
        `${packagePath}/package.json`,
        'core/workspace/package.json'
      ),
      addProjectToGarmentJson({
        garmentJsonPath: '/garment.json',
        name: projectName,
        path: packagePath,
        extendProjects: ['tspackage']
      })
    ]);
  };
}
Example #13
Source File: index.ts    From open-source with MIT License 5 votes vote down vote up
export default function (options: ComponentOptions): Rule {
   return async (host: Tree) => {
     const workspace = await getWorkspace(host);
     const project = workspace.projects.get(options.project as string);

     if (options.path === undefined && project) {
       options.path = buildDefaultPath(project);
     }

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

     options.module = findModuleFromOptions(host, options);

     const parsedPath = parseName(options.path as string, options.name);
     options.name = parsedPath.name;
     options.path = parsedPath.path;
     options.selector =
       options.selector || buildSelector(options, (project && project.prefix) || '');

     validateName(options.name);
     validateHtmlSelector(options.selector);

     const templateSource = apply(url('./files'), [
       options.skipTests ? filter((path) => !path.endsWith('.spec.ts.template')) : noop(),
       applyTemplates({
         ...strings,
         'if-flat': (s: string) => (options.flat ? '' : s),
         ...options,
       }),
       !options.type
         ? forEach(((file) => {
             return file.path.includes('..')
               ? {
                   content: file.content,
                   path: file.path.replace('..', '.'),
                 }
               : file;
           }) as FileOperator)
         : noop(),
       move(parsedPath.path),
     ]);

     return chain([
       addDeclarationToNgModule(options),
       mergeWith(templateSource),
       options.lintFix ? applyLintFix(options.path) : noop(),
     ]);
   };
 }
Example #14
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(),
    ]);
  };
}