UNPKG

8.21 kBSource Map (JSON)View Raw
1{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../modules/schematics/src/effect/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+BAAiC;AACjC,yDAcoC;AACpC,yDAU+B;AAG/B,SAAS,mBAAmB,CAAC,OAAsB;IACjD,OAAO,UAAC,IAAU;;QAChB,IAAM,UAAU,GAAG,OAAO,CAAC,MAAM,CAAC;QAElC,IAAI,CAAC,UAAU,EAAE,CAAC;YAChB,OAAO,IAAI,CAAC;QACd,CAAC;QAED,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,EAAE,CAAC;YAC7B,MAAM,IAAI,KAAK,CAAC,gCAAyB,UAAU,oBAAiB,CAAC,CAAC;QACxE,CAAC;QAED,IAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QACnC,IAAI,IAAI,KAAK,IAAI,EAAE,CAAC;YAClB,MAAM,IAAI,gCAAmB,CAAC,eAAQ,UAAU,qBAAkB,CAAC,CAAC;QACtE,CAAC;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,WAAW,GAAG,UAAG,6BAAW,CAAC,QAAQ,CAAC,UAAG,OAAO,CAAC,IAAI,YAAS,CAAC,CAAE,CAAC;QAExE,IAAM,mBAAmB,GAAG,IAAA,8BAAY,EACtC,MAAM,EACN,UAAU,EACV,eAAe,EACf,eAAe,CAChB,CAAC;QAEF,IAAM,WAAW,GACf,WAAI,OAAO,CAAC,IAAI,MAAG;YACnB,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,6BAAW,CA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CAAC,EAAnC,CAAmC,CAAC;gBACvD,CAAC,CAAC,IAAA,iBAAI,GAAE;YACV,OAAO,CAAC,IAAI,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,IAAA,mBAAM,EAAC,UAAC,CAAC,IAAK,OAAA,KAAK,EAAL,CAAK,CAAC,CAAC,CAAC,CAAC,IAAA,iBAAI,GAAE;YAC/D,IAAA,2BAAc,EAAC,+BACV,6BAAW,KACd,SAAS,EAAE,UAAC,CAAS;oBACnB,OAAA,6BAAW,CAAC,KAAK,CACf,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,EACrB,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,CAC/B;gBAHD,CAGC,EACH,YAAY,EAAE,cAAc,EAC5B,WAAW,EAAE,cAAc,CAAC,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,MAAM,CAAC,EACzD,SAAS,EAAE,QAAQ,GAAG,OAAO,KACzB,OAAkB,CAChB,CAAC;YACT,IAAA,iBAAI,EAAC,UAAU,CAAC,IAAI,CAAC;SACtB,CAAC,CAAC;QAEH,OAAO,IAAA,kBAAK,EAAC;YACX,IAAA,2BAAc,EACZ,IAAA,kBAAK,EAAC,CAAC,mBAAmB,CAAC,OAAO,CAAC,EAAE,IAAA,sBAAS,EAAC,cAAc,CAAC,CAAC,CAAC,CACjE;SACF,CAAC,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IACpB,CAAC,CAAC;AACJ,CAAC;AAtCD,4BAsCC","sourcesContent":["import * as ts from 'typescript';\nimport {\n Rule,\n SchematicContext,\n SchematicsException,\n Tree,\n apply,\n applyTemplates,\n branchAndMerge,\n chain,\n filter,\n mergeWith,\n move,\n noop,\n url,\n} from '@angular-devkit/schematics';\nimport {\n InsertChange,\n addImportToModule,\n buildRelativePath,\n findModuleFromOptions,\n getProjectPath,\n insertImport,\n parseName,\n stringUtils,\n getPrefix,\n} from '../../schematics-core';\nimport { Schema as EffectOptions } from './schema';\n\nfunction addImportToNgModule(options: EffectOptions): 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 effectsName = `${stringUtils.classify(`${options.name}Effects`)}`;\n\n const effectsModuleImport = insertImport(\n source,\n modulePath,\n 'EffectsModule',\n '@ngrx/effects'\n );\n\n const effectsPath =\n `/${options.path}/` +\n (options.flat ? '' : stringUtils.dasherize(options.name) + '/') +\n (options.group ? 'effects/' : '') +\n stringUtils.dasherize(options.name) +\n '.effects';\n const relativePath = buildRelativePath(modulePath, effectsPath);\n const effectsImport = insertImport(\n source,\n modulePath,\n effectsName,\n relativePath\n );\n\n const effectsSetup =\n options.root && options.minimal ? `[]` : `[${effectsName}]`;\n const [effectsNgModuleImport] = addImportToModule(\n source,\n modulePath,\n `EffectsModule.for${options.root ? 'Root' : 'Feature'}(${effectsSetup})`,\n relativePath\n );\n\n let changes = [effectsModuleImport, effectsNgModuleImport];\n\n if (!options.root || (options.root && !options.minimal)) {\n changes = changes.concat([effectsImport]);\n }\n\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\nfunction getEffectStart(name: string, effectPrefix: string): string {\n const effectName = stringUtils.classify(name);\n const effectMethodPrefix = stringUtils.camelize(effectPrefix);\n\n return (\n `${effectMethodPrefix}${effectName}s$ = createEffect(() => {` +\n '\\n return this.actions$.pipe(\\n'\n );\n}\n\nexport default function (options: EffectOptions): Rule {\n return (host: Tree, context: SchematicContext) => {\n options.path = getProjectPath(host, options);\n const parsedPath = parseName(options.path, options.name || '');\n options.name = parsedPath.name;\n options.path = parsedPath.path;\n options.prefix = getPrefix(options);\n\n if (options.module) {\n options.module = findModuleFromOptions(host, options);\n }\n\n const templateSource = apply(url('./files'), [\n options.skipTests\n ? filter((path) => !path.endsWith('.spec.ts.template'))\n : noop(),\n options.root && options.minimal ? filter((_) => false) : noop(),\n applyTemplates({\n ...stringUtils,\n 'if-flat': (s: string) =>\n stringUtils.group(\n options.flat ? '' : s,\n options.group ? 'effects' : ''\n ),\n effectMethod: 'createEffect',\n effectStart: getEffectStart(options.name, options.prefix),\n effectEnd: ' );\\n' + ' });',\n ...(options as object),\n } as any),\n move(parsedPath.path),\n ]);\n\n return chain([\n branchAndMerge(\n chain([addImportToNgModule(options), mergeWith(templateSource)])\n ),\n ])(host, context);\n };\n}\n"]}
\No newline at end of file