Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const reducersPath = core_1.normalize(`/${options.path}/${options.reducers}`);
if (!host.exists(reducersPath)) {
throw new Error(`Specified reducers path ${reducersPath} does not exist`);
}
const text = host.read(reducersPath);
if (text === null) {
throw new schematics_1.SchematicsException(`File ${reducersPath} does not exist.`);
}
const sourceText = text.toString('utf-8');
const source = ts.createSourceFile(reducersPath, sourceText, ts.ScriptTarget.Latest, true);
const reducerPath = `/${options.path}/` +
(options.flat ? '' : stringUtils.dasherize(options.name) + '/') +
(options.group ? 'reducers/' : '') +
stringUtils.dasherize(options.name) +
'.reducer';
const relativePath = find_module_1.buildRelativePath(reducersPath, reducerPath);
const reducerImport = ast_utils_1.insertImport(source, reducersPath, `* as from${stringUtils.classify(options.name)}`, relativePath, true);
const stateInterfaceInsert = addReducerToStateInterface(source, reducersPath, options);
const reducerMapInsert = addReducerToActionReducerMap(source, reducersPath, options);
const changes = [reducerImport, stateInterfaceInsert, reducerMapInsert];
const recorder = host.beginUpdate(reducersPath);
for (const change of changes) {
if (change instanceof change_1.InsertChange) {
recorder.insertLeft(change.pos, change.toAdd);
}
}
host.commitUpdate(recorder);
return host;
};
}
}
const text = host.read(modulePath);
if (text === null) {
throw new schematics_1.SchematicsException(`File ${modulePath} does not exist.`);
}
const sourceText = text.toString('utf-8');
const source = ts.createSourceFile(modulePath, sourceText, ts.ScriptTarget.Latest, true);
const commonImports = [
ast_utils_1.insertImport(source, modulePath, 'StoreModule', '@ngrx/store'),
];
const reducerPath = `/${options.path}/` +
(options.flat ? '' : stringUtils.dasherize(options.name) + '/') +
(options.group ? 'reducers/' : '') +
stringUtils.dasherize(options.name) +
'.reducer';
const relativePath = find_module_1.buildRelativePath(modulePath, reducerPath);
const reducerImport = ast_utils_1.insertImport(source, modulePath, `* as from${stringUtils.classify(options.name)}`, relativePath, true);
const [storeNgModuleImport] = ast_utils_1.addImportToModule(source, modulePath, `StoreModule.forFeature('${stringUtils.camelize(options.name)}', from${stringUtils.classify(options.name)}.reducer)`, relativePath);
const changes = [...commonImports, reducerImport, storeNgModuleImport];
const recorder = host.beginUpdate(modulePath);
for (const change of changes) {
if (change instanceof change_1.InsertChange) {
recorder.insertLeft(change.pos, change.toAdd);
}
}
host.commitUpdate(recorder);
return host;
};
}