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AC,CACjE;SACF,CAAC,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IACpB,CAAC,CAAC;AACJ,CAAC;AAxCD,4BAwCC","sourcesContent":["import {\n Rule,\n SchematicContext,\n SchematicsException,\n Tree,\n apply,\n applyTemplates,\n branchAndMerge,\n chain,\n mergeWith,\n url,\n move,\n filter,\n noop,\n} from '@angular-devkit/schematics';\nimport * as ts from 'typescript';\nimport {\n stringUtils,\n buildRelativePath,\n insertImport,\n Change,\n InsertChange,\n getProjectPath,\n isLib,\n findModuleFromOptions,\n addImportToModule,\n parseName,\n visitNgModuleImports,\n} from '../../schematics-core';\nimport { Schema as StoreOptions } from './schema';\n\nfunction addImportToNgModule(options: StoreOptions): Rule {\n return (host: Tree) => {\n const modulePath = options.module;\n\n if (!modulePath) {\n return host;\n }\n\n if (!host.exists(modulePath)) {\n throw new Error(`Specified module path ${modulePath} does not exist`);\n }\n\n const text = host.read(modulePath);\n if (text === null) {\n throw new SchematicsException(`File ${modulePath} does not exist.`);\n }\n const sourceText = text.toString('utf-8');\n\n const source = ts.createSourceFile(\n modulePath,\n sourceText,\n ts.ScriptTarget.Latest,\n true\n );\n\n const statePath = `${options.path}/${options.statePath}`;\n const relativePath = buildRelativePath(modulePath, statePath);\n\n const rootStoreReducers = options.minimal ? `{}` : `reducers`;\n const rootStoreConfig = options.minimal ? `` : `, { metaReducers }`;\n\n const storeNgModuleImport = addImportToModule(\n source,\n modulePath,\n options.root\n ? `StoreModule.forRoot(${rootStoreReducers}${rootStoreConfig})`\n : `StoreModule.forFeature(from${stringUtils.classify(\n options.name\n )}.${stringUtils.camelize(\n options.name\n )}FeatureKey, from${stringUtils.classify(\n options.name\n )}.reducers, { metaReducers: from${stringUtils.classify(\n options.name\n )}.metaReducers })`,\n relativePath\n ).shift();\n\n let commonImports = [\n insertImport(source, modulePath, 'StoreModule', '@ngrx/store'),\n storeNgModuleImport,\n ];\n\n if (options.root && !options.minimal) {\n commonImports = commonImports.concat([\n insertImport(\n source,\n modulePath,\n 'reducers, metaReducers',\n relativePath\n ),\n ]);\n } else if (!options.root) {\n commonImports = commonImports.concat([\n insertImport(\n source,\n modulePath,\n `* as from${stringUtils.classify(options.name)}`,\n relativePath,\n true\n ),\n ]);\n }\n\n let rootImports: (Change | undefined)[] = [];\n\n if (options.root) {\n let hasImports = false;\n visitNgModuleImports(source, (_, importNodes) => {\n hasImports = importNodes.length > 0;\n });\n\n // `addImportToModule` adds a comma to imports when there are already imports present\n // because at this time the store import hasn't been committed yet, `addImportToModule` wont add a comma\n // so we have to add it here for empty import arrays\n const adjectiveComma = hasImports ? '' : ', ';\n\n const storeDevtoolsNgModuleImport = addImportToModule(\n source,\n modulePath,\n `${adjectiveComma}isDevMode() ? StoreDevtoolsModule.instrument() : []`,\n relativePath\n ).shift();\n\n rootImports = rootImports.concat([\n insertImport(\n source,\n modulePath,\n 'StoreDevtoolsModule',\n '@ngrx/store-devtools'\n ),\n insertImport(source, modulePath, 'isDevMode', '@angular/core'),\n storeDevtoolsNgModuleImport,\n ]);\n }\n\n const changes = [...commonImports, ...rootImports];\n const recorder = host.beginUpdate(modulePath);\n for (const change of changes) {\n if (change instanceof InsertChange) {\n recorder.insertLeft(change.pos, change.toAdd);\n }\n }\n host.commitUpdate(recorder);\n\n return host;\n };\n}\n\nexport default function (options: StoreOptions): Rule {\n return (host: Tree, context: SchematicContext) => {\n if (!options.name && !options.root) {\n throw new Error(`Please provide a name for the feature state`);\n }\n\n options.path = getProjectPath(host, options);\n\n const parsedPath = parseName(options.path, options.name || '');\n options.name = parsedPath.name;\n options.path = parsedPath.path;\n\n if (options.module) {\n options.module = findModuleFromOptions(host, options);\n }\n\n if (\n options.root &&\n options.stateInterface &&\n options.stateInterface !== 'State'\n ) {\n options.stateInterface = stringUtils.classify(options.stateInterface);\n }\n\n const templateSource = apply(url('./files'), [\n options.root && options.minimal ? filter((_) => false) : noop(),\n applyTemplates({\n ...stringUtils,\n ...(options as object),\n isLib: isLib(host, options),\n }),\n move(parsedPath.path),\n ]);\n\n return chain([\n branchAndMerge(\n chain([addImportToNgModule(options), mergeWith(templateSource)])\n ),\n ])(host, context);\n };\n}\n"]} |