Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const effectsModuleImport = insertImport(
source,
modulePath,
'EffectsModule',
'@ngrx/effects'
);
const effectsPath =
`/${options.path}/` +
(options.flat ? '' : stringUtils.dasherize(options.name) + '/') +
(options.group ? 'effects/' : '') +
stringUtils.dasherize(options.name) +
'.effects';
const relativePath = buildRelativePath(modulePath, effectsPath);
const effectsImport = insertImport(
source,
modulePath,
effectsName,
relativePath
);
const effectsSetup =
options.root && options.minimal ? `[]` : `[${effectsName}]`;
const [effectsNgModuleImport] = addImportToModule(
source,
modulePath,
`EffectsModule.for${options.root ? 'Root' : 'Feature'}(${effectsSetup})`,
relativePath
);
let changes = [effectsModuleImport, effectsNgModuleImport];
const text = host.read(modulePath);
if (text === null) {
throw new SchematicsException(`File ${modulePath} does not exist.`);
}
const sourceText = text.toString('utf-8');
const source = ts.createSourceFile(
modulePath,
sourceText,
ts.ScriptTarget.Latest,
true
);
const effectsName = `${stringUtils.classify(`${options.name}Effects`)}`;
const effectsModuleImport = insertImport(
source,
modulePath,
'EffectsModule',
'@ngrx/effects'
);
const effectsPath =
`/${options.path}/` +
(options.flat ? '' : stringUtils.dasherize(options.name) + '/') +
(options.group ? 'effects/' : '') +
stringUtils.dasherize(options.name) +
'.effects';
const relativePath = buildRelativePath(modulePath, effectsPath);
const effectsImport = insertImport(
source,
modulePath,
if (options.root) {
const storeDevtoolsNgModuleImport = addImportToModule(
source,
modulePath,
`!environment.production ? StoreDevtoolsModule.instrument() : []`,
relativePath
).shift();
rootImports = rootImports.concat([
insertImport(
source,
modulePath,
'StoreDevtoolsModule',
'@ngrx/store-devtools'
),
insertImport(source, modulePath, 'environment', environmentsPath),
storeDevtoolsNgModuleImport,
]);
}
const changes = [...commonImports, ...rootImports];
const recorder = host.beginUpdate(modulePath);
for (const change of changes) {
if (change instanceof InsertChange) {
recorder.insertLeft(change.pos, change.toAdd);
}
}
host.commitUpdate(recorder);
return host;
};
}
options.root
? `StoreModule.forRoot(${rootStoreReducers}, ${rootStoreConfig})`
: `StoreModule.forFeature(from${stringUtils.classify(
options.name
)}.${stringUtils.camelize(
options.name
)}FeatureKey, from${stringUtils.classify(
options.name
)}.reducers, { metaReducers: from${stringUtils.classify(
options.name
)}.metaReducers })`,
relativePath
).shift();
let commonImports = [
insertImport(source, modulePath, 'StoreModule', '@ngrx/store'),
storeNgModuleImport,
];
if (options.root && !options.minimal) {
commonImports = commonImports.concat([
insertImport(
source,
modulePath,
'reducers, metaReducers',
relativePath
),
]);
} else if (!options.root) {
commonImports = commonImports.concat([
insertImport(
source,
)}FeatureKey, from${stringUtils.classify(
options.name
)}.reducers, { metaReducers: from${stringUtils.classify(
options.name
)}.metaReducers })`,
relativePath
).shift();
let commonImports = [
insertImport(source, modulePath, 'StoreModule', '@ngrx/store'),
storeNgModuleImport,
];
if (options.root && !options.minimal) {
commonImports = commonImports.concat([
insertImport(
source,
modulePath,
'reducers, metaReducers',
relativePath
),
]);
} else if (!options.root) {
commonImports = commonImports.concat([
insertImport(
source,
modulePath,
`* as from${stringUtils.classify(options.name)}`,
relativePath,
true
),
]);
if (text === null) {
throw new SchematicsException(`File ${componentPath} does not exist.`);
}
const sourceText = text.toString('utf-8');
const source = ts.createSourceFile(
componentPath,
sourceText,
ts.ScriptTarget.Latest,
true
);
const stateImportPath = buildRelativePath(componentPath, statePath);
const storeImport = insertImport(
source,
componentPath,
'Store',
'@ngrx/store'
);
const stateImport = options.state
? insertImport(
source,
componentPath,
`* as fromStore`,
stateImportPath,
true
)
: new NoopChange();
const componentClass = source.statements.find(
),
]);
}
let rootImports: (Change | undefined)[] = [];
if (options.root) {
const storeDevtoolsNgModuleImport = addImportToModule(
source,
modulePath,
`!environment.production ? StoreDevtoolsModule.instrument() : []`,
relativePath
).shift();
rootImports = rootImports.concat([
insertImport(
source,
modulePath,
'StoreDevtoolsModule',
'@ngrx/store-devtools'
),
insertImport(source, modulePath, 'environment', environmentsPath),
storeDevtoolsNgModuleImport,
]);
}
const changes = [...commonImports, ...rootImports];
const recorder = host.beginUpdate(modulePath);
for (const change of changes) {
if (change instanceof InsertChange) {
recorder.insertLeft(change.pos, change.toAdd);
}