Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const root = project.root || '';
const needWebWorkerConfig = !projectTargetOptions.webWorkerTsConfig;
if (needWebWorkerConfig) {
const workerConfigPath = join(normalize(root), 'tsconfig.worker.json');
projectTargetOptions.webWorkerTsConfig = workerConfigPath;
// add worker tsconfig to lint architect target
const lintTarget = project.targets.get('lint');
if (lintTarget) {
const lintOptions = (lintTarget.options || {}) as unknown as LintBuilderOptions;
lintOptions.tsConfig = (lintOptions.tsConfig || []).concat(workerConfigPath);
}
}
const templateSource = apply(url('./files/worker'), [
applyTemplates({ ...options, ...strings }),
move(parsedPath.path),
]);
return chain([
// Add project configuration.
needWebWorkerConfig ? addConfig(options, root, projectTargetOptions.tsConfig) : noop(),
needWebWorkerConfig ? updateWorkspace(workspace) : noop(),
// Create the worker in a sibling module.
options.snippet ? addSnippet(options) : noop(),
// Add the worker.
mergeWith(templateSource),
]);
};
}
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('^', ''),
folderName,
}),
move(projectRoot),
]);
return chain([
);
}
if (!options.component) {
throw new SchematicsException(
`You need to specify a component using the --component flag`,
);
}
const component = strings.dasherize(options.component);
options.selector = component.startsWith('dt-')
? component
: `dt-${component}`;
return mergeWith(
apply(url('./files'), [template({ ...strings, ...options }), move('src')]),
);
}
return (host, context) => {
const workspace = config_1.getWorkspace(host);
if (!options.project) {
throw new schematics_1.SchematicsException('Option (project) is required.');
}
const project = workspace.projects[options.project];
if (options.path === undefined) {
options.path = project_1.buildDefaultPath(project);
}
options.type = !!options.type ? `.${options.type}` : '';
const parsedPath = parse_name_1.parseName(options.path, options.name);
options.name = parsedPath.name;
options.path = parsedPath.path;
const templateSource = schematics_1.apply(schematics_1.url('./files'), [
options.spec ? schematics_1.noop() : schematics_1.filter(path => !path.endsWith('.spec.ts')),
schematics_1.template(Object.assign({}, core_1.strings, options)),
schematics_1.move(parsedPath.path),
]);
return schematics_1.branchAndMerge(schematics_1.mergeWith(templateSource));
};
}
return wrapIntoFormat(() => {
let npmScope = schema.npmScope;
if (!npmScope) {
npmScope = readCliConfigFile().project.npmScope;
}
const options = normalizeOptions(schema);
const templateSource = apply(url('./files'), [
template({
utils: strings,
dot: '.',
tmpl: '',
offsetFromRoot: offsetFromRoot(options.fullPath),
...(options as object),
npmScope
})
]);
const selector = `${options.prefix}-root`;
return chain([
branchAndMerge(chain([mergeWith(templateSource)])),
externalSchematic('@schematics/angular', 'module', {
name: 'app',
return host => {
if (host.exists('patches/BUILD.bazel')) {
return noop;
}
return mergeWith(
apply(url('./files/root'), [
template({
tmpl: ''
}),
() => {
if (host.exists('BUILD.bazel')) {
host.delete('BUILD.bazel');
}
}
])
);
};
}
addLazyLoadedRouterConfiguration(modulePath) :
noop(),
options.routing && options.lazy && options.parentModule ?
addLoadChildren(options) :
noop(),
options.routing && !options.lazy ?
addRouterConfiguration(options, indexFile, moduleFileName, modulePath) :
noop(),
options.routing && !options.lazy && options.parentModule ?
addChildren(options) :
noop()
];
const templateSource =
apply(url(options.nomodule ? './files' : './ngfiles'), [template({
...names(options.name),
dot: '.',
tmpl: '',
...(options as object)
})]);
return {
options,
moduleFileName,
modulePath,
indexFile,
templateSource,
routingRules
};
}
cliTarget: `${project.name}:${metadata.name}${
config === '__nx_default__' ? '' : `:${config}`
}`,
bazelLabel: `${metadata.name}${
config === '__nx_default__' ? '' : `__${config}`
}`,
isBuildTarget,
outputArgument
};
})
)
.forEach(arr => {
arr.forEach(label => labels.push(label));
});
return apply(url('./files/build-file'), [
template({
tmpl: '',
project,
projectGraph,
dependencies: projectGraph.dependencies[project.name]
? projectGraph.dependencies[project.name].map(
dep =>
`//${normalize(projectGraph.nodes[dep.target].data.root)}:${
dep.target
}`
)
: [],
labels
})
]);
}
export default function LibStandalone(options: LibraryOptions): Rule {
options.path = options.path ? normalize(options.path) : options.path;
const templateSource = apply(url("./files/lib"), [
template({
...stringUtils,
...options
}),
move(options.sourceDir as string)
]);
const gulpfile = url("./files/gulpfile");
return chain([
mergeWith(templateSource),
mergeWith(gulpfile),
addScriptsToManifest(),
addDevDependenciesToManifest()
]);
}
export function addFireBug(options: any): Rule {
const source = apply(url('../utils/firebug/files'), [
move(`${options.directory}/src/bootstrapScripts`)
]);
return chain([
mergeWith(source),
tree => {
addDependencyToPackageJson(tree, options, 'node-wget', '^0.4.2', true);
addDependencyToPackageJson(tree, options, 'decompress', '^4.2.0', true);
addDependencyToPackageJson(tree, options, 'decompress-targz', '^4.1.1', true);
},
tree => {
let indexContent = '';
if (tree.exists(`${options.directory}/src/bootstrapScripts/index.ts`)) {
indexContent = getFileContent(tree, `${options.directory}/src/bootstrapScripts/index.ts`);
}
createOrOverwriteFile(tree,`${options.directory}/src/bootstrapScripts/index.ts`, indexContent + 'export * from \'./firebug\';\n');