nx/packages/angular/src/schematics/library/lib/normalize-options.ts
Vivek More 🧐 212fb00548 cleanup(misc): use more es6 features
- Single char alternation (e.g. a|b|c|d) in a RegExp can be simplified to use a character class ([abcd]) instead.
  This usually also provides slightly better matching performance.
- Character escapes that are replaceable with the unescaped character without a change in meaning. Inside the square brackets of a character class, many escapes are unnecessary that would be necessary outside of a character class. For example the regex [\.] is identical to [.]
- If several qualified expressions occur after the qualifier having been checked for nullable, they can be replaced with optional chaining
2021-03-24 20:11:32 -04:00

45 lines
1.3 KiB
TypeScript

import { Tree } from '@angular-devkit/schematics';
import { getNpmScope } from '@nrwl/workspace';
import { libsDir } from '@nrwl/workspace/src/utils/ast-utils';
import { Schema } from '../schema';
import { NormalizedSchema } from './normalized-schema';
import { names } from '@nrwl/devkit';
export function normalizeOptions(
host: Tree,
options: Schema
): NormalizedSchema {
const name = names(options.name).fileName;
const projectDirectory = options.directory
? `${names(options.directory).fileName}/${name}`
: name;
const projectName = projectDirectory.replace(new RegExp('/', 'g'), '-');
const fileName = options.simpleModuleName ? name : projectName;
const projectRoot = `${libsDir(host)}/${projectDirectory}`;
const moduleName = `${names(fileName).className}Module`;
const parsedTags = options.tags
? options.tags.split(',').map((s) => s.trim())
: [];
const modulePath = `${projectRoot}/src/lib/${fileName}.module.ts`;
const defaultPrefix = getNpmScope(host);
const importPath =
options.importPath || `@${defaultPrefix}/${projectDirectory}`;
return {
...options,
prefix: options.prefix ?? defaultPrefix,
name: projectName,
projectRoot,
entryFile: 'index',
moduleName,
projectDirectory,
modulePath,
parsedTags,
fileName,
importPath,
};
}