Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const buffer = host.read(indexFilePath);
if (!!buffer) {
// AST to 'index.ts' barrel for the public API
const indexSource = buffer!.toString('utf-8');
const indexSourceFile = ts.createSourceFile(
indexFilePath,
indexSource,
ts.ScriptTarget.Latest,
true
);
// Public API for the feature interfaces, selectors, and facade
const { fileName } = names(options.name);
const statePath = `./lib/${options.directory}/${fileName}`;
insert(host, indexFilePath, [
...addGlobal(
indexSourceFile,
indexFilePath,
exportBarrels
? `import * as ${className}Actions from '${statePath}.actions';`
: `export * from '${statePath}.actions';`
),
...addGlobal(
indexSourceFile,
indexFilePath,
exportBarrels
? `import * as ${className}Feature from '${statePath}.reducer';`
: `export * from '${statePath}.reducer';`
),
...addGlobal(
indexSourceFile,
const storeRouterModule = 'StoreRouterConnectingModule.forRoot()';
// InsertImport [symbol,source] value pairs
const nxModuleImport = ['NxModule', '@nrwl/angular'];
const storeModule = ['StoreModule', '@ngrx/store'];
const effectsModule = ['EffectsModule', '@ngrx/effects'];
const storeDevTools = ['StoreDevtoolsModule', '@ngrx/store-devtools'];
const environment = ['environment', '../environments/environment'];
const storeRouter = ['StoreRouterConnectingModule', '@ngrx/router-store'];
// this is just a heuristic
const hasRouter = sourceText.indexOf('RouterModule') > -1;
const hasNxModule = sourceText.includes('NxModule.forRoot()');
if (context.options.onlyEmptyRoot || context.options.minimal) {
insert(host, modulePath, [
addImport.apply(this, storeModule),
addImport.apply(this, effectsModule),
addImport.apply(this, storeDevTools),
addImport.apply(this, environment),
...(hasRouter ? [addImport.apply(this, storeRouter)] : []),
...addImportToModule(source, modulePath, storeForRoot),
...addImportToModule(source, modulePath, effectsForEmptyRoot),
...addImportToModule(source, modulePath, devTools),
...(hasRouter
? addImportToModule(source, modulePath, storeRouterModule)
: [])
]);
} else {
let common = [
addImport.apply(this, storeModule),
addImport.apply(this, effectsModule),
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;
}').then(module => module.${options.moduleName})}`
)
]);
const tsConfig = findClosestTsConfigApp(host, options.parentModule);
if (tsConfig) {
const tsConfigAppSource = host.read(tsConfig)!.toString('utf-8');
const tsConfigAppFile = ts.createSourceFile(
tsConfig,
tsConfigAppSource,
ts.ScriptTarget.Latest,
true
);
const offset = offsetFromRoot(path.dirname(tsConfig));
insert(host, tsConfig, [
...addIncludeToTsConfig(
tsConfig,
tsConfigAppFile,
`\n , "${offset}${options.projectRoot}/src/index.ts"\n`
)
]);
} else {
// we should warn the user about not finding the config
}
return host;
};
}
const value = node
.getText(sourceFile)
.substr(1, node.getText(sourceFile).length - 2);
if (value === '@nrwl/builders/plugins/jest/resolver') {
changes.push(
new ReplaceChange(
'jest.config.js',
node.getStart(sourceFile),
node.getText(sourceFile),
`'@nrwl/jest/plugins/resolver'`
)
);
}
}
});
insert(host, 'jest.config.js', changes);
};
function addRouterToComponent(host: Tree) {
const appPath = join(
options.appProjectRoot,
`src/app/${options.fileName}.tsx`
);
const appFileContent = host.read(appPath).toString('utf-8');
const appSource = ts.createSourceFile(
appPath,
appFileContent,
ts.ScriptTarget.Latest,
true
);
insert(host, appPath, addInitialRoutes(appPath, appSource, context));
},
addDepsToPackageJson(
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[] = [];`
)
function addBrowserRouterToMain(host: Tree) {
const { content, source } = readComponent(host, options.appMain);
const isRouterPresent = content.match(/react-router-dom/);
if (!isRouterPresent) {
insert(
host,
options.appMain,
addBrowserRouter(options.appMain, source, context)
);
}
},
function addInitialAppRoutes(host: Tree) {
return (host: Tree) => {
const { modulePath, moduleSource, moduleClassName } = readBootstrapInfo(
host,
options.project
);
insert(host, modulePath, [
...addMethod(moduleSource, modulePath, {
className: moduleClassName,
methodHeader: 'ngDoBootstrap(): void',
body: ``
}),
...removeFromNgModule(moduleSource, modulePath, 'bootstrap')
]);
return host;
};
}
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,