Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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,
effectsName,
relativePath
);
const effectsSetup =
options.root && options.minimal ? `[]` : `[${effectsName}]`;
const [effectsNgModuleImport] = addImportToModule(
source,
modulePath,
`EffectsModule.for${options.root ? 'Root' : 'Feature'}(${effectsSetup})`,
relativePath
);
const text = host.read(componentPath);
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();
return (host: Tree, context: SchematicContext) => {
if (!options.name && !options.root) {
throw new Error(`Please provide a name for the feature state`);
}
options.path = getProjectPath(host, options);
const parsedPath = parseName(options.path, options.name || '');
options.name = parsedPath.name;
options.path = parsedPath.path;
const statePath = `/${options.path}/${options.statePath}/index.ts`;
const srcPath = dirname(options.path as Path);
const environmentsPath = buildRelativePath(
statePath,
`${srcPath}/environments/environment`
);
if (options.module) {
options.module = findModuleFromOptions(host, options);
}
if (
options.root &&
options.stateInterface &&
options.stateInterface !== 'State'
) {
options.stateInterface = stringUtils.classify(options.stateInterface);
}
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 statePath = `${options.path}/${options.statePath}`;
const relativePath = buildRelativePath(modulePath, statePath);
const environmentsPath = buildRelativePath(
statePath,
`${options.path}/environments/environment`
);
const runtimeChecks = `
runtimeChecks: {
strictStateImmutability: true,
strictActionImmutability: true,
}
`;
const rootStoreReducers = options.minimal ? `{}` : `reducers`;
const rootStoreConfig = options.minimal
? `{ ${runtimeChecks} }`
: `{
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 statePath = `${options.path}/${options.statePath}`;
const relativePath = buildRelativePath(modulePath, statePath);
const environmentsPath = buildRelativePath(
statePath,
`${options.path}/environments/environment`
);
const runtimeChecks = `
runtimeChecks: {
strictStateImmutability: true,
strictActionImmutability: true,
}
`;
const rootStoreReducers = options.minimal ? `{}` : `reducers`;
const rootStoreConfig = options.minimal