How to use the @schematics/angular/utility/project.buildDefaultPath function in @schematics/angular

To help you get started, we’ve selected a few @schematics/angular examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github intershop / intershop-pwa / schematics / src / page / factory.js View on Github external
const match = options.name.match(/(.*)\-([a-z0-9]+)/);
    if (match && match[1] && match[2]) {
        const parent = match[1];
        child = match[2];
        // tslint:disable-next-line:no-console
        console.log(`detected subpage, will insert '${child}' as sub page of '${parent}'`);
        routingModuleLocation = options.extension
            ? `extensions/${options.extension}/pages/${parent}/${parent}-page.module.ts`
            : `pages/${parent}/${parent}-page.module.ts`;
    }
    else {
        routingModuleLocation = options.extension
            ? `extensions/${options.extension}/pages/${options.extension}-routing.module.ts`
            : 'pages/app-routing.module.ts';
    }
    const routingModule = core_1.normalize(`${project_1.buildDefaultPath(project)}/${routingModuleLocation}`);
    return Object.assign({}, options, { routingModule,
        child });
}
function addRouteToRoutingModule(options) {
github intershop / intershop-pwa / schematics / src / page / factory.ts View on Github external
const match = options.name.match(/(.*)\-([a-z0-9]+)/);
  if (match && match[1] && match[2]) {
    const parent = match[1];
    child = match[2];
    // tslint:disable-next-line:no-console
    console.log(`detected subpage, will insert '${child}' as sub page of '${parent}'`);
    routingModuleLocation = options.extension
      ? `extensions/${options.extension}/pages/${parent}/${parent}-page.module.ts`
      : `pages/${parent}/${parent}-page.module.ts`;
  } else {
    routingModuleLocation = options.extension
      ? `extensions/${options.extension}/pages/${options.extension}-routing.module.ts`
      : 'pages/app-routing.module.ts';
  }

  const routingModule = normalize(`${buildDefaultPath(project)}/${routingModuleLocation}`);
  return {
    ...options,
    routingModule,
    child,
  };
}
github intershop / intershop-pwa / schematics / src / utils / common.js View on Github external
function applyNameAndPath(artifact, host, options) {
    let path = options.path;
    let name = options.name;
    const project = project_1.getProject(host, options.project);
    // remove possible added path from root
    if (name && name.startsWith('src/app/')) {
        name = name.substr(8);
    }
    const parsedPath = parse_name_1.parseName(path || project_1.buildDefaultPath(project), name);
    name = parsedPath.name;
    if (artifact) {
        name = name.replace(new RegExp(`\-?${artifact}$`), '');
    }
    if (!options.restricted) {
        path = parsedPath.path;
    }
    if (options.artifactFolder) {
        // add artifact folder
        const containingFolder = `/${artifact}s`;
        if (!options.flat && !path.endsWith(containingFolder)) {
            path += containingFolder;
        }
    }
    validation_1.validateName(name);
    return Object.assign({}, options, { name,
github positive-js / mosaic / packages / cdk / schematics / utils / build-component.ts View on Github external
context.schematic.description.path :
            dirname(context.schematic.description.path);

        const schematicFilesUrl = './files';
        const schematicFilesPath = resolve(schematicPath, schematicFilesUrl);

        // Add the default component option values to the options if an option is not explicitly
        // specified but a default component option is available.
        Object.keys(options)
            .filter((optionName) => options[optionName] == null && defaultComponentOptions[optionName])
            .forEach((optionName) => options[optionName] = defaultComponentOptions[optionName]);

        if (options.path === undefined) {
            // TODO(jelbourn): figure out if the need for this `as any` is a bug due to two different
            // incompatible `WorkspaceProject` classes in @angular-devkit
            options.path = buildDefaultPath(project as any);
        }

        options.module = findModuleFromOptions(host, options);

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

        options.name = parsedPath.name;
        options.path = parsedPath.path;
        options.selector = options.selector || buildSelector(options, project.prefix);

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

        // In case the specified style extension is not part of the supported CSS supersets,
        // we generate the stylesheets with the "css" extension. This ensures that we don't
        // accidentally generate invalid stylesheets (e.g. drag-drop-comp.styl) which will
github xmlking / ngx-starter-kit / tools / src / schematics / store / index.ts View on Github external
return (host: Tree, context: SchematicContext) => {
    if (!options.project) {
      throw new SchematicsException('Option (project) is required.');
    }
    const id = getProjectName(options, getWorkspace(host));
    const project = getProject(host, id);

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

    options.module = findModuleFromOptions(host, options);

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

    validateName(options.name);
    console.log(options);

    const templateSource = apply(url('./_files'), [
      template({
        ...strings,
        ...options,
      }),
github intershop / intershop-pwa / schematics / src / extension / factory.ts View on Github external
options = applyNameAndPath('extension', host, options);
    options = determineArtifactName('extension', host, options);

    const operations: Rule[] = [];
    operations.push(
      mergeWith(
        apply(url('./files'), [
          template({
            ...strings,
            ...options,
          }),
          move(options.path),
        ])
      )
    );
    const projectRoot = buildDefaultPath(getProject(host, options.project));
    const artifactName = strings.classify(options.name) + 'ExportsModule';
    const moduleImportPath = `${projectRoot}/extensions/${strings.dasherize(options.name)}/exports/${strings.dasherize(
      options.name
    )}-exports.module`;

    const sharedModuleOptions = {
      module: `${projectRoot}/shared/shared.module.ts`,
      artifactName,
      moduleImportPath,
    };
    operations.push(addExportToNgModule(sharedModuleOptions));
    operations.push(addImportToNgModule(sharedModuleOptions));

    const appModuleOptions = {
      module: `${projectRoot}/app.module.ts`,
      artifactName,
github valor-software / ng2-charts / ng2-charts-schematics / src / ng2-charts-schematics / ng2-process-tree.ts View on Github external
export function ng2ProcessTree(
  tree: Tree,
  _context: SchematicContext,
  _options: any,
  newCode: string,
  newMarkup: string,
  newImports: [string, string][] = []) {
  if (!_options.project) {
    throw new SchematicsException('Option (project) is required.');
  }
  const project = getProject(tree, _options.project);

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

  _options.module = findModuleFromOptions(tree, _options);

  const codeAction = tree.actions.filter(r => r.path.endsWith('.component.ts'))[0];
  const markupActions = tree.actions.filter(r => r.path.endsWith('.component.html'));
  const codeSource = readIntoSourceFile(tree, codeAction.path);
  const nodes = getSourceNodes(codeSource);
  const classNodes = nodes.filter(r => findNodes(r, ts.SyntaxKind.ClassDeclaration).length);
  const classDecl = findNodes(classNodes[0], ts.SyntaxKind.ClassDeclaration)[0] as ts.ClassDeclaration;
  let inlineTemplate = false;
  let template: ts.PropertyAssignment;
  const changes = newImports.map(([a, b]) => insertImport(codeSource, codeAction.path, a, b));
  const recorder = tree.beginUpdate(codeAction.path);
  if (classDecl.decorators) {
    const decorator = classDecl.decorators[0];
github valor-software / ng2-charts / ng2-charts-schematics / src / ng2-charts-schematics / build-meta-config.ts View on Github external
return (tree: Tree, _context: SchematicContext) => {
    if (!_options.project) {
      throw new SchematicsException('Option (project) is required.');
    }
    const project = getProject(tree, _options.project);

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

    _options.module = findModuleFromOptions(tree, _options);

    const parsedPath = parseName(dirname(normalize(_options.module)), 'not applicable');
    _options.metaname = parsedPath.name;
    _options.metapath = parsedPath.path;

    const metaConfigExists = tree.exists('/src/app/app-chart-config.ts');

    if (metaConfigExists) {
      return tree;
    }

    const templateSource = apply(url('./files'), [
      applyTemplates({