Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (!options.state && !options.stateInterface) {
return host;
}
const statePath = `/${options.path}/${options.state}`;
if (options.state) {
if (!host.exists(statePath)) {
throw new Error(`The Specified state path ${statePath} does not exist`);
}
}
const componentPath =
`/${options.path}/` +
(options.flat ? '' : stringUtils.dasherize(options.name) + '/') +
stringUtils.dasherize(options.name) +
'.component.ts';
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
);
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,
effectsName,
relativePath
);
const effectsSetup =
options.root && options.minimal ? `[]` : `[${effectsName}]`;
const [effectsNgModuleImport] = addImportToModule(
source,
modulePath,
return (host: Tree) => {
if (!options.state && !options.stateInterface) {
return host;
}
const statePath = `/${options.path}/${options.state}`;
if (options.state) {
if (!host.exists(statePath)) {
throw new Error(`The Specified state path ${statePath} does not exist`);
}
}
const componentPath =
`/${options.path}/` +
(options.flat ? '' : stringUtils.dasherize(options.name) + '/') +
stringUtils.dasherize(options.name) +
'.component.ts';
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 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