How to use the @angular-devkit/core.strings.classify function in @angular-devkit/core

To help you get started, we’ve selected a few @angular-devkit/core 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 angular / angular-cli / packages / schematics / angular / component / index.ts View on Github external
}
    }
    host.commitUpdate(declarationRecorder);

    if (options.export) {
      // Need to refresh the AST because we overwrote the file in the host.
      const text = host.read(modulePath);
      if (text === null) {
        throw new SchematicsException(`File ${modulePath} does not exist.`);
      }
      const sourceText = text.toString('utf-8');
      const source = ts.createSourceFile(modulePath, sourceText, ts.ScriptTarget.Latest, true);

      const exportRecorder = host.beginUpdate(modulePath);
      const exportChanges = addExportToModule(source, modulePath,
                                              strings.classify(`${options.name}Component`),
                                              relativePath);

      for (const change of exportChanges) {
        if (change instanceof InsertChange) {
          exportRecorder.insertLeft(change.pos, change.toAdd);
        }
      }
      host.commitUpdate(exportRecorder);
    }


    return host;
  };
}
github positive-js / mosaic / packages / cdk / schematics / utils / build-component.ts View on Github external
}
            }
            host.commitUpdate(exportRecorder);
        }

        if (options.entryComponent) {
            // Need to refresh the AST because we overwrote the file in the host.
            source = readIntoSourceFile(host, modulePath);

            const entryComponentRecorder = host.beginUpdate(modulePath);
            const entryComponentChanges = addEntryComponentToModule(
                // TODO: TypeScript version mismatch due to @schematics/angular using a different version
                // Cast to any to avoid the type assignment failure.
                source as any,
                modulePath,
                strings.classify(`${options.name}Component`),
                relativePath);

            for (const change of entryComponentChanges) {
                if (change instanceof InsertChange) {
                    entryComponentRecorder.insertLeft(change.pos, change.toAdd);
                }
            }
            host.commitUpdate(entryComponentRecorder);
        }


        return host;
    };
}
github ng-alain / delon / packages / schematics / utils / alain.ts View on Github external
function buildComponentName(schema: CommonSchema, _projectPrefix: string) {
  const ret: string[] = [schema.module!];
  if (schema.target && schema.target.length > 0) {
    ret.push(...schema.target.split('/'));
  }
  ret.push(schema.name!);
  ret.push(`Component`);
  return strings.classify(ret.join('-'));
}
github mselerin / yang-schematics / src / feature / index_spec.ts View on Github external
it('should update routing', async () => {
      appTree = await yangSchematicRunner.runSchematicAsync('feature', {
        name: featureName
      }, appTree).toPromise();

      const fileContent = getFileContent(appTree, YangUtils.FEATURES_MODULE_FILE);
      const path = `{ path: '${strings.dasherize(featureName)}', loadChildren: () => import('@app/features/${strings.dasherize(featureName)}/${strings.dasherize(featureName)}.module').then(m => m.${strings.classify(featureName)}Module) }`

      expect(fileContent).toContain(path);
    });
  });
github dynatrace-oss / barista / tools / schematics / dt-component / index.ts View on Github external
'src',
      'ui-test-app',
      'ui-test-app-module.ts',
    );
    const sourceFile = getSourceFile(host, sourceFilePath);

    const changes: InsertChange[] = [];
    /** @dynatrace/angular-component import */
    changes.push(
      addDynatraceSubPackageImport(sourceFilePath, sourceFile, options),
    );

    /**
     * relative UI import
     */
    const uiImportName = `${strings.classify(options.name)}UI`;
    const uiImportLocation = `'./${strings.dasherize(
      options.name,
    )}/${strings.dasherize(options.name)}-ui';`;
    changes.push(
      addImport(sourceFilePath, sourceFile, uiImportName, uiImportLocation),
    );

    /**
     * add to exports of DynatraceAngularCompModule
     */
    changes.push(
      addToNgModule(sourceFilePath, sourceFile, options.moduleName, 'exports'),
    );

    /**
     * Add to declarations of UiTestAppModule
github dynatrace-oss / barista / tools / schematics / utils / ast-utils.ts View on Github external
sourceFile,
      ts.SyntaxKind.PropertyAssignment,
    ) as ts.PropertyAssignment[];
    const assignment = assignments.find(
      (a: ts.PropertyAssignment) => a.name.getText() === 'declarations',
    );
    if (assignment === undefined) {
      throw Error("No AppModule 'declarations' section found");
    }

    const arrLiteral = assignment.initializer as ts.ArrayLiteralExpression;
    const elements = arrLiteral.elements;
    const end = arrLiteral.elements.end;

    const indentation = getIndentation(elements);
    const toInsert = `${indentation}${strings.classify(name)}Demo,`;
    const importsChange = new InsertChange(modulePath, end, toInsert);

    const changes = [importChange, importsChange];
    return commitChanges(host, changes, modulePath);
  };
}
github ionic-team / ionic-cli / packages / @ionic / schematics-angular / page / index.ts View on Github external
throw new SchematicsException(`File ${module} does not exist.`);
    }

    const sourceText = text.toString('utf8');
    const source = ts.createSourceFile(module, sourceText, ts.ScriptTarget.Latest, true);

    const pagePath = (
      `/${options.path}/` +
      (options.flat ? '' : `${strings.dasherize(options.name)}/`) +
      `${strings.dasherize(options.name)}.module`
    );

    const relativePath = buildRelativePath(module, pagePath);

    const routePath = options.routePath ? options.routePath : options.name;
    const routeLoadChildren = `${relativePath}#${strings.classify(options.name)}PageModule`;
    const changes = addRouteToRoutesArray(source, module, routePath, routeLoadChildren);
    const recorder = host.beginUpdate(module);

    for (const change of changes) {
      if (change instanceof InsertChange) {
        recorder.insertLeft(change.pos, change.toAdd);
      }
    }

    host.commitUpdate(recorder);

    return host;
  };
}
github fusionfabric / finastra-design-system / tools / schematics / angular-component / index.ts View on Github external
return async (host: Tree, context: SchematicContext) => {
    const globalGitConfig = gitParse.sync({ path: gitPath({ type: 'global' }), cwd: '/' }) || {};
    const localGitConfig = gitParse.sync({ path: gitPath({ type: 'local' }), cwd: '/' }) || {};

    const user = {
      name: (localGitConfig.user && localGitConfig.user.name) || globalGitConfig.user.name,
      email: (localGitConfig.user && localGitConfig.user.email) || globalGitConfig.user.email
    };

    const pkg = JSON.parse((await readFile(join(process.cwd(), './package.json'))).toString());
    const filename = strings.dasherize(schema.name);
    const dest = `libs/angular-components/${filename}`;
    const classNamePrefix = strings.classify(schema.name);

    const templateSource = apply(url('./files'), [
      applyTemplates({
        ...strings,
        className: classNamePrefix,
        filename,
        version: pkg.version,
        author: `${user.name} <${user.email}>`
      }),
      move(dest)
    ]);

    return chain([
      addToIndex({
        indexPath: 'libs/angular-components/index.ts',
        filename
github devonfw / devon4node / packages / schematics / src / lib / crud / crud.factory.ts View on Github external
}

    let fileContent = addToModuleDecorator(
      tree.read(module)!.toString('utf-8'),
      moduleName,
      './services',
      strings.classify(crudName) + 'CrudService',
      'providers',
      false,
    );

    fileContent = addToModuleDecorator(
      fileContent!,
      moduleName,
      './controllers',
      strings.classify(crudName) + 'CrudController',
      'controllers',
      false,
    );

    if (fileContent) {
      tree.overwrite(module, formatTsFile(fileContent));
    }

    addBarrels(tree, join(modulePath as Path, 'services'), crudName + '.crud.service');
    addBarrels(tree, join(modulePath as Path, 'controllers'), crudName + '.crud.controller');

    return tree;
  };
}
github mohammedzamakhan / ngx-loadable / projects / schematics / src / module / index.ts View on Github external
return host;
    }

    const modulePath = options.module;

    const text = host.read(modulePath);
    if (text === null) {
      throw new SchematicsException(`File ${modulePath} does not exist.`);
    }
    const sourceText = text.toString();
    const source = ts.createSourceFile(modulePath, sourceText, ts.ScriptTarget.Latest, true);

    const relativePath = buildRelativeModulePath(options, modulePath);
    const changes = addImportToModule(source,
                                      modulePath,
                                      strings.classify(`${options.name}Module`),
                                      relativePath);

    const recorder = host.beginUpdate(modulePath);
    for (const change of changes) {
      if (change instanceof InsertChange) {
        recorder.insertLeft(change.pos, change.toAdd);
      }
    }
    host.commitUpdate(recorder);

    return host;
  };
}