Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
rules.push((tree: Tree, context: SchematicContext) => {
// update project name
updateProject(tree, options);
const ngToolkitSettings = getNgToolkitInfo(tree, options);
if (!ngToolkitSettings.universal) {
return chain([
mergeWith(templateSource, MergeStrategy.Overwrite),
tree => {
if (isUniversal(tree, options)) {
tree.rename(`${options.directory}/server_universal.ts`, `${options.directory}/server.ts`);
tree.rename(`${options.directory}/server_static.ts`, `${options.directory}/temp/server_static.ts${new Date().getDate()}`);
} else {
tree.rename(`${options.directory}/server_universal.ts`, `${options.directory}temp/server_universal.ts${new Date().getDate()}`);
tree.rename(`${options.directory}/server_static.ts`, `${options.directory}/server.ts`);
}
const serverFileContent = getFileContent(tree, `${options.directory}/server.ts`);
tree.overwrite(`${options.directory}/server.ts`, serverFileContent
.replace('__distBrowserFolder__', getBrowserDistFolder(tree, options))
.replace('__distServerFolder__', getServerDistFolder(tree, options))
);
}
apply(url(`./files/lib`), [
template({
...options,
...names(options.name),
tmpl: '',
offsetFromRoot: offsetFromRoot(options.projectRoot)
}),
move(options.projectRoot),
options.unitTestRunner === 'none'
? filter(file => !file.endsWith('spec.ts'))
: noop(),
options.publishable
? noop()
: filter(file => !file.endsWith('package.json'))
]),
MergeStrategy.Overwrite
);
}
);
const templates = provideServerAndWebpackServerConfigs(options);
return chain([
addPackageJsonDependencies(),
externalSchematic('@nguniversal/express-engine', 'ng-add', {
clientProject: options.project,
}),
addPackageJsonScripts(options),
addServerConfigInAngularJsonFile(options),
modifyTSConfigServerFile(),
modifyAppServerModuleFile(),
modifyIndexHtmlFile(project, options),
branchAndMerge(
chain([mergeWith(templates, MergeStrategy.Overwrite)]),
MergeStrategy.Overwrite
),
modifyMainServerTSFile(),
installPackageJsonDependencies(),
])(tree, context);
};
}
options.name = options.name || path.basename(process.cwd());
if (!options.name) {
throw new SchematicsException(`Invalid options, "name" is required.`);
}
return chain([
mergeWith(apply(url('./files/root'), [
template({
...strings,
...options,
buildDate: new Date().toISOString()
}),
move(''),
forceOverwrite(host)
]), MergeStrategy.Overwrite),
updatePackageJson(),
updateTsConfig(),
updateGitIgnore(),
updatePolyfills(),
updateEnvironments(),
updateAngularJson(),
schematic('feature', {
name: 'home',
component: true,
template: true,
styles: true
}),
mergeWith(apply(url('./files/home'), [
return (host: Tree, context: SchematicContext) => {
const project = getClientProject(host, options);
const path = normalize(project.workspace.root);
const templateSource = apply(url('./_files'), [
applyTemplates({
atLeastAngular8: atLeastAngular8(),
prefix: project.workspace.prefix,
routing: options.routing,
usingBrowserAnimationsModule: options.usingBrowserAnimationsModule,
}),
move(path)
]);
const rule = mergeWith(templateSource, MergeStrategy.Overwrite);
context.logger.info(`Generated 'main.single-spa.ts`);
context.logger.info(`Generated 'single-spa-props.ts`);
context.logger.info(`Generated asset-url.ts`);
context.logger.info(`Generated extra-webpack.config.js`);
return rule(host, context);
}
}
possibleProjectFiles
);
const templates = provideServerAndWebpackServerConfigs(options);
return chain([
addPackageJsonDependencies(),
externalSchematic('@nguniversal/express-engine', 'ng-add', {
clientProject: options.project,
}),
addPackageJsonScripts(options),
addServerConfigInAngularJsonFile(options),
modifyTSConfigServerFile(),
modifyAppServerModuleFile(),
modifyIndexHtmlFile(project, options),
branchAndMerge(
chain([mergeWith(templates, MergeStrategy.Overwrite)]),
MergeStrategy.Overwrite
),
modifyMainServerTSFile(),
installPackageJsonDependencies(),
])(tree, context);
};
}
tree.rename("gitignore", ".gitignore");
}
},
(tree: Tree, context: IgxSchematicContext) => {
if (!allOptionsProvided) {
return defer(async () => {
prompt.setContext(context, tree, options.name as string);
await prompt.chooseActionLoop(projLibrary);
return tree;
});
}
},
(_tree: Tree, _context: IgxSchematicContext) => {
return move(options.name!);
}
]), MergeStrategy.Overwrite
),
(tree: Tree, context: IgxSchematicContext) => {
const installChain = [];
if (!options.skipInstall) {
const installTask = context.addTask(new NodePackageInstallTask(options.name));
installChain.push(installTask);
}
if (!options.skipGit) {
const gitTask = context.addTask(
new RepositoryInitializerTask(options.name, { message: `Initial commit for project: ${options.name}` }),
[...installChain] //copy
);
installChain.push(gitTask);
}
if (!options.skipInstall && !allOptionsProvided) {
routing: options.routing,
style: options.style,
skipTests: options.skipTests
};
const yangInitOptions: YangInitOptions = {
name: options.name
};
return chain([
mergeWith(
apply(empty(), [
externalSchematic('@schematics/angular', 'ng-new', ngNewOptions),
schematic('init', yangInitOptions),
move(options.directory),
]), MergeStrategy.Overwrite
),
(host: Tree, context: SchematicContext) => {
let packageTask;
if (!options.skipInstall) {
packageTask = context.addTask(new NodePackageInstallTask(options.directory));
if (options.linkCli) {
packageTask = context.addTask(
new NodePackageLinkTask('@angular/cli', options.directory),
[packageTask],
);
}
}
if (!options.skipGit) {
const commit = typeof options.commit == 'object'
? options.commit
: (!!options.commit ? {} : false);
);
return tree;
}),
mergeWith(
apply(url(`./templates/jest`), [
forEach(template => {
const templatePath = config.app
? `${template.path}`
: `src/${template.path}`;
tree.exists(`${root}${templatePath}`)
? tree.overwrite(`${root}${templatePath}`, template.content)
: tree.create(`${root}${templatePath}`, template.content);
return null;
})
]),
MergeStrategy.Overwrite
)
]);
};
}