Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return (host: Tree) => {
const moduleSource = host.read(options.modulePath)!.toString('utf-8');
const sourceFile = ts.createSourceFile(
options.modulePath,
moduleSource,
ts.ScriptTarget.Latest,
true
);
insert(host, options.modulePath, [
insertImport(
sourceFile,
options.modulePath,
'RouterModule',
'@angular/router'
),
...addImportToModule(
sourceFile,
options.modulePath,
`
RouterModule.forChild([
/* {path: '', pathMatch: 'full', component: InsertYourComponentHere} */
]) `
)
]);
return host;
};
true
);
host.overwrite(
componentSpecPath,
componentSpecSource
.replace('.content span', 'h1')
.replace(
`${options.name} app is running!`,
`Welcome to ${options.name}!`
)
);
if (options.routing) {
insert(host, componentSpecPath, [
insertImport(
componentSpecSourceFile,
componentSpecPath,
'RouterTestingModule',
'@angular/router/testing'
),
...addImportToTestBed(
componentSpecSourceFile,
componentSpecPath,
`RouterTestingModule`
)
]);
}
}
return host;
};
const addImport = (
symbolName: string,
fileName: string,
isDefault = false
): Change => {
return insertImport(source, modulePath, symbolName, fileName, isDefault);
};
return (host: Tree) => {
const moduleSource = host.read(options.modulePath)!.toString('utf-8');
const moduleSourceFile = ts.createSourceFile(
options.modulePath,
moduleSource,
ts.ScriptTarget.Latest,
true
);
const constName = `${toPropertyName(options.fileName)}Routes`;
insert(host, options.modulePath, [
insertImport(
moduleSourceFile,
options.modulePath,
'RouterModule, Route',
'@angular/router'
),
...addImportToModule(
moduleSourceFile,
options.modulePath,
`RouterModule`
),
...addGlobal(
moduleSourceFile,
options.modulePath,
`export const ${constName}: Route[] = [];`
)
]);
return (host: Tree) => {
const { moduleClassName, modulePath, moduleSource } = readBootstrapInfo(
host,
options.project
);
insert(host, modulePath, [
insertImport(
moduleSource,
modulePath,
`configure${toClassName(options.name)}, upgradedComponents`,
`../${toFileName(options.name)}-setup`
),
insertImport(
moduleSource,
modulePath,
'UpgradeModule',
'@angular/upgrade/static'
),
...addImportToModule(moduleSource, modulePath, 'UpgradeModule'),
...addDeclarationToModule(
moduleSource,
modulePath,
'...upgradedComponents'
),
...addEntryComponents(
moduleSource,
modulePath,
getBootstrapComponent(moduleSource, moduleClassName)
)