UNPKG

10.6 kBSource Map (JSON)View Raw
1{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../modules/store/schematics/ng-add/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+BAAiC;AACjC,6CAAqD;AACrD,yDAcoC;AACpC,0DAA0E;AAC1E,yDAW+B;AAG/B,SAAS,mBAAmB,CAAC,OAAyB;IACpD,OAAO,UAAC,IAAU;;QAChB,IAAM,UAAU,GAAG,OAAO,CAAC,MAAM,CAAC;QAElC,IAAI,CAAC,UAAU,EAAE;YACf,OAAO,IAAI,CAAC;SACb;QAED,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,EAAE;YAC5B,MAAM,IAAI,KAAK,CAAC,iCAAiC,CAAC,CAAC;SACpD;QAED,IAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QACnC,IAAI,IAAI,KAAK,IAAI,EAAE;YACjB,MAAM,IAAI,gCAAmB,CAAC,UAAQ,UAAU,qBAAkB,CAAC,CAAC;SACrE;QACD,IAAM,UAAU,GAAG,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;QAE1C,IAAM,MAAM,GAAG,EAAE,CAAC,gBAAgB,CAChC,UAAU,EACV,UAAU,EACV,EAAE,CAAC,YAAY,CAAC,MAAM,EACtB,IAAI,CACL,CAAC;QAEF,IAAM,mBAAmB,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,UAAU,CAAC;QAEhE,IAAM,iBAAiB,GAAG,OAAO,CAAC,OAAO;YACvC,CAAC,CAAC,IAAI;YACN,CAAC,CAAC,8BAEF,CAAC;QACH,IAAM,gBAAgB,GAAG,yBAAuB,mBAAmB,UAAK,iBAAiB,MAAG,CAAC;QAE7F,IAAM,SAAS,GAAG,MAAI,OAAO,CAAC,IAAI,SAAI,OAAO,CAAC,SAAW,CAAC;QA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,CAAC,IAAI,CAAC,EAAhC,CAAgC,CAAC;YAC9C,2BAAc,gCACT,6BAAW,GACX,OAAO,KACV,gBAAgB,kBAAA,IAChB;YACF,iBAAI,CAAC,UAAU,CAAC,IAAI,CAAC;SACtB,CAAC,CAAC;QAEH,OAAO,kBAAK,CAAC;YACX,2BAAc,CACZ,kBAAK,CAAC,CAAC,mBAAmB,CAAC,OAAO,CAAC,EAAE,sBAAS,CAAC,cAAc,CAAC,CAAC,CAAC,CACjE;YACD,OAAO,IAAI,OAAO,CAAC,eAAe,CAAC,CAAC,CAAC,iBAAI,EAAE,CAAC,CAAC,CAAC,yBAAyB,EAAE;YACzE,OAAO,IAAI,OAAO,CAAC,gBAAgB,CAAC,CAAC,CAAC,iBAAI,EAAE,CAAC,CAAC,CAAC,mBAAmB,EAAE;SACrE,CAAC,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IACpB,CAAC,CAAC;AACJ,CAAC;AA5CD,+BA4CC","sourcesContent":["import * as ts from 'typescript';\nimport { Path, dirname } from '@angular-devkit/core';\nimport {\n Rule,\n SchematicContext,\n SchematicsException,\n Tree,\n apply,\n applyTemplates,\n branchAndMerge,\n chain,\n mergeWith,\n url,\n noop,\n move,\n filter,\n} from '@angular-devkit/schematics';\nimport { NodePackageInstallTask } from '@angular-devkit/schematics/tasks';\nimport {\n InsertChange,\n addImportToModule,\n buildRelativePath,\n findModuleFromOptions,\n getProjectPath,\n insertImport,\n stringUtils,\n addPackageToPackageJson,\n platformVersion,\n parseName,\n} from '../../schematics-core';\nimport { Schema as RootStoreOptions } from './schema';\n\nfunction addImportToNgModule(options: RootStoreOptions): 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 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 storeModuleReducers = options.minimal ? `{}` : `reducers`;\n\n const storeModuleConfig = options.minimal\n ? `{}`\n : `{\n metaReducers\n }`;\n const storeModuleSetup = `StoreModule.forRoot(${storeModuleReducers}, ${storeModuleConfig})`;\n\n const statePath = `/${options.path}/${options.statePath}`;\n const relativePath = buildRelativePath(modulePath, statePath);\n const [storeNgModuleImport] = addImportToModule(\n source,\n modulePath,\n storeModuleSetup,\n relativePath\n );\n\n let changes = [\n insertImport(source, modulePath, 'StoreModule', '@ngrx/store'),\n storeNgModuleImport,\n ];\n\n if (!options.minimal) {\n changes = changes.concat([\n insertImport(\n source,\n modulePath,\n 'reducers, metaReducers',\n relativePath\n ),\n ]);\n }\n\n const recorder = host.beginUpdate(modulePath);\n\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\nfunction addNgRxStoreToPackageJson() {\n return (host: Tree, context: SchematicContext) => {\n addPackageToPackageJson(\n host,\n 'dependencies',\n '@ngrx/store',\n platformVersion\n );\n context.addTask(new NodePackageInstallTask());\n return host;\n };\n}\n\nfunction addNgRxESLintPlugin() {\n return (host: Tree, context: SchematicContext) => {\n const eslintConfigPath = '.eslintrc.json';\n const docs =\n 'https://github.com/timdeschryver/eslint-plugin-ngrx/#eslint-plugin-ngrx';\n\n const eslint = host.read(eslintConfigPath)?.toString('utf-8');\n if (!eslint) {\n return host;\n }\n\n addPackageToPackageJson(\n host,\n 'devDependencies',\n 'eslint-plugin-ngrx',\n '^1.0.0'\n );\n context.addTask(new NodePackageInstallTask());\n\n try {\n const json = JSON.parse(eslint);\n if (json.overrides) {\n json.overrides\n .filter((override: { files?: string[] }) =>\n override.files?.some((file: string) => file.endsWith('*.ts'))\n )\n .forEach(configureESLintPlugin);\n } else {\n configureESLintPlugin(json);\n }\n\n host.overwrite(eslintConfigPath, JSON.stringify(json, null, 2));\n\n context.logger.info(`\nThe NgRx ESLint Plugin is installed and configured with the recommended config.\n\nIf you want to change the configuration, please see ${docs}.\n`);\n return host;\n } catch (err) {\n context.logger.warn(`\nSomething went wrong while adding the NgRx ESLint Plugin.\nThe NgRx ESLint Plugin is installed but not configured.\n\nPlease see ${docs} to configure the NgRx ESLint Plugin.\n\nDetails:\n${err.message}\n`);\n }\n\n return host;\n };\n}\n\nfunction configureESLintPlugin(json: any): void {\n json.plugins = [...(json.plugins || []), 'ngrx'];\n json.extends = [...(json.extends || []), 'plugin:ngrx/recommended'];\n}\n\nexport default function (options: RootStoreOptions): Rule {\n return (host: Tree, context: SchematicContext) => {\n options.path = getProjectPath(host, options);\n\n const parsedPath = parseName(options.path, '');\n options.path = parsedPath.path;\n\n const statePath = `/${options.path}/${options.statePath}/index.ts`;\n const srcPath = dirname(options.path as Path);\n const environmentsPath = buildRelativePath(\n statePath,\n `/${srcPath}/environments/environment`\n );\n\n if (options.module) {\n options.module = findModuleFromOptions(host, {\n name: '',\n module: options.module,\n path: options.path,\n });\n }\n\n if (options.stateInterface && options.stateInterface !== 'State') {\n options.stateInterface = stringUtils.classify(options.stateInterface);\n }\n\n const templateSource = apply(url('./files'), [\n filter(() => (options.minimal ? false : true)),\n applyTemplates({\n ...stringUtils,\n ...options,\n environmentsPath,\n }),\n move(parsedPath.path),\n ]);\n\n return chain([\n branchAndMerge(\n chain([addImportToNgModule(options), mergeWith(templateSource)])\n ),\n options && options.skipPackageJson ? noop() : addNgRxStoreToPackageJson(),\n options && options.skipESLintPlugin ? noop() : addNgRxESLintPlugin(),\n ])(host, context);\n };\n}\n"]}
\No newline at end of file