How to use the @angular-devkit/core.strings.dasherize 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 / library / index.ts View on Github external
validateProjectName(options.name);

    // If scoped project (i.e. "@foo/bar"), convert projectDir to "foo/bar".
    const projectName = options.name;
    const packageName = strings.dasherize(projectName);
    let scopeName = null;
    if (/^@.*\/.*/.test(options.name)) {
      const [scope, name] = options.name.split('/');
      scopeName = scope.replace(/^@/, '');
      options.name = name;
    }

    const workspace = await getWorkspace(host);
    const newProjectRoot = workspace.extensions.newProjectRoot as (string | undefined) || '';

    const scopeFolder = scopeName ? strings.dasherize(scopeName) + '/' : '';
    const folderName = `${scopeFolder}${strings.dasherize(options.name)}`;
    const projectRoot = join(normalize(newProjectRoot), folderName);
    const distRoot = `dist/${folderName}`;
    const sourceDir = `${projectRoot}/src/lib`;

    const templateSource = apply(url('./files'), [
      applyTemplates({
        ...strings,
        ...options,
        packageName,
        projectRoot,
        distRoot,
        relativePathToWorkspaceRoot: relativePathToWorkspaceRoot(projectRoot),
        prefix,
        angularLatestVersion: latestVersions.Angular.replace('~', '').replace('^', ''),
        tsLibLatestVersion: latestVersions.TsLib.replace('~', '').replace('^', ''),
github mselerin / yang-schematics / src / feature / index.ts View on Github external
if (options.module === YangUtils.FEATURES_MODULE_FILE) {
      file = YangUtils.FEATURES_MODULE_FILE;
      varName = 'FEATURES_ROUTES';
    }
    else {
      file = options.module.replace('.module.ts', '-routing.module.ts');
      varName = 'ROUTES';
    }

    // Ajouter la route
    const sourceFile = CodeUtils.readSourceFile(host, file);
    let path = (options.path || '').replace('/src/app/', '@app/');

    CodeUtils.insertInVariableArray(sourceFile, varName,
      `{ path: '${strings.dasherize(options.name)}', loadChildren: () => import('${path}/${strings.dasherize(options.name)}.module').then(m => m.${strings.classify(options.name)}Module) }`
    );

    CodeUtils.writeSourceFile(host, file, sourceFile);
    return host;
  };
}
github angular / angular-cli / packages / schematics / angular / module / index.ts View on Github external
function buildRelativeModulePath(options: ModuleOptions, modulePath: string): string {
  const importModulePath = normalize(
    `/${options.path}/`
    + (options.flat ? '' : strings.dasherize(options.name) + '/')
    + strings.dasherize(options.name)
    + '.module',
  );

  return buildRelativePath(modulePath, importModulePath);
}
github nestjs / schematics / src / lib / module / module.factory.ts View on Github external
function transform(source: ModuleOptions): ModuleOptions {
  const target: ModuleOptions = Object.assign({}, source);
  target.metadata = 'imports';
  target.type = 'module';

  const location: Location = new NameParser().parse(target);
  target.name = strings.dasherize(location.name);
  target.language = target.language !== undefined ? target.language : 'ts';
  target.path = strings.dasherize(location.path);

  target.path = target.flat
    ? target.path
    : join(target.path as Path, target.name);
  return target;
}
github devonfw / devon4node / packages / schematics / src / lib / interceptor / interceptor.factory.ts View on Github external
export function main(options: InterceptorOptions) {
  const newOptions = { ...options };
  newOptions.name = options.name.startsWith('app/') ? options.name : 'app/' + options.name;
  if (newOptions.path) {
    newOptions.path = join(options.path as Path, 'src');
  }
  newOptions.language = 'ts';
  const path = newOptions.path || './src';
  const dir = dirname(newOptions.name as Path);
  const base = strings.dasherize(basename(newOptions.name as Path));

  return chain([
    externalSchematic('@nestjs/schematics', 'interceptor', newOptions),
    move(
      strings.dasherize(join(path as Path, dir, base + '.interceptor.ts')),
      strings.dasherize(join(path as Path, dir, 'interceptors', base + '.interceptor.ts')),
    ),
    move(
      strings.dasherize(join(path as Path, dir, base + '.interceptor.spec.ts')),
      strings.dasherize(join(path as Path, dir, 'interceptors', base + '.interceptor.spec.ts')),
    ),
  ]);
}
github ng-matero / ng-matero / schematics / utils / build-component.ts View on Github external
function buildRelativeComponentPath(options: ComponentOptions, modulePath: string): string {
  const componentPath =
    `/${options.path}/` +
    (options.flat ? '' : strings.dasherize(options.name) + '/') +
    strings.dasherize(options.name) +
    '.component';

  return buildRelativePath(modulePath, componentPath);
}
github nestjs / schematics / src / lib / controller / controller.factory.ts View on Github external
function transform(source: ControllerOptions): ControllerOptions {
  const target: ControllerOptions = Object.assign({}, source);
  const defaultSourceRoot =
    source.sourceRoot !== undefined ? source.sourceRoot : DEFAULT_PATH_NAME;

  target.metadata = ELEMENT_METADATA;
  target.type = ELEMENT_TYPE;
  target.path =
    target.path !== undefined
      ? join(normalize(defaultSourceRoot), target.path)
      : normalize(defaultSourceRoot);

  const location: Location = new NameParser().parse(target);
  target.name = strings.dasherize(location.name);
  target.path = strings.dasherize(location.path);
  target.language =
    target.language !== undefined ? target.language : DEFAULT_LANGUAGE;

  target.path = target.flat
    ? target.path
    : join(target.path as Path, target.name);
  return target;
}
github angular / angular-cli / packages / angular / cli / models / schematic-command.ts View on Github external
          ? ' ' + schematicArgs.map(a => `<${strings.dasherize(a.name)}>`).join(' ')
          : '';
github devonfw / devon4node / packages / schematics / src / lib / service / service.factory.ts View on Github external
export function main(options: IServiceOptions): Rule {
  const name = strings.dasherize(basename(options.name as Path));
  const projectPath = options.path || '.';
  const path: Path = strings.dasherize(normalize(join(projectPath as Path, 'src/app', options.name, '..'))) as Path;

  return chain([
    mergeWith(
      apply(url('./files'), [
        options.spec ? noop() : filter(p => !p.endsWith('.spec.ts')),
        template({
          ...strings,
          name,
        }),
        formatTsFiles(),
        move(path),
      ]),
    ),
    (tree: Tree): Tree => {
github nestjs / schematics / src / lib / interceptor / interceptor.factory.ts View on Github external
function transform(options: InterceptorOptions): InterceptorOptions {
  const target: InterceptorOptions = Object.assign({}, options);
  if (!target.name) {
    throw new SchematicsException('Option (name) is required.');
  }
  const location: Location = new NameParser().parse(target);
  target.name = strings.dasherize(location.name);
  target.path = strings.dasherize(location.path);
  target.language = target.language !== undefined ? target.language : 'ts';

  target.path = target.flat
    ? target.path
    : join(target.path as Path, target.name);
  return target;
}