UNPKG

7.93 kBSource Map (JSON)View Raw
1{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../modules/schematics/src/container/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAAA,yDAcoC;AACpC,+BAAiC;AACjC,yDAU+B;AAG/B,SAAS,mBAAmB,CAAC,OAAkC;IAC7D,OAAO,UAAC,IAAU;;QAChB,IAAI,CAAC,OAAO,CAAC,KAAK,IAAI,CAAC,OAAO,CAAC,cAAc,EAAE,CAAC;YAC9C,OAAO,IAAI,CAAC;QACd,CAAC;QAED,IAAM,SAAS,GAAG,WAAI,OAAO,CAAC,IAAI,cAAI,OAAO,CAAC,KAAK,CAAE,CAAC;QAEtD,IAAI,OAAO,CAAC,KAAK,EAAE,CAAC;YAClB,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,EAAE,CAAC;gBAC5B,MAAM,IAAI,KAAK,CAAC,mCAA4B,SAAS,oBAAiB,CAAC,CAAC;YAC1E,CAAC;QACH,CAAC;QAED,IAAM,aAAa,GACjB,WAAI,OAAO,CAAC,IAAI,MAAG;YACnB,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,6BAAW,CAAC,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,GAAG,CAAC;YAC/D,6BAAW,CAAC,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC;YACnC,eAAe,CAAC;QAElB,IAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;QAEtC,IAAI,IAAI,KAAK,IAAI,EAAE,CAAC;YAClB,MAAM,IAAI,gCAAmB,CAAC,eAAQ,aAAa,qBAAkB,CAAC,CAAC;QACzE,CAAC;QAED,IAAM,UAAU,GAAG,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;QAE1C,IAAM,MAAM,GAAG,EAAE,CAAC,gBAAgB,CAChC,aAAa,EACb,UAAU,EACV,EA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AAC,CAAC,CAAC,CAAC,EAAvB,CAAuB,IAC9C,6BAAW,GACV,OAAkB,CAChB,CAAC;YACT,IAAA,iBAAI,EAAC,UAAU,CAAC,IAAI,CAAC;SACtB,CACF,CAAC;QAEF,oGAAoG;QACnG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAgC,CAAC,OAAO,CAAC,UAAC,GAAG;YAC5D,OAAA,IAAI,CAAC,GAAG,CAAC,KAAK,SAAS,CAAC,CAAC,CAAC,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE;QAA/C,CAA+C,CAChD,CAAC;QAEF,OAAO,IAAA,kBAAK,EAAC;YACX,IAAA,8BAAiB,EAAC,qBAAqB,EAAE,WAAW,wBAC/C,IAAI,KACP,SAAS,EAAE,IAAI,IACf;YACF,mBAAmB,CAAC,OAAO,CAAC;YAC5B,IAAA,sBAAS,EAAC,cAAc,CAAC;SAC1B,CAAC,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IACpB,CAAC,CAAC;AACJ,CAAC;AA5CD,4BA4CC","sourcesContent":["import {\n Rule,\n SchematicContext,\n SchematicsException,\n Tree,\n chain,\n externalSchematic,\n apply,\n applyTemplates,\n url,\n noop,\n filter,\n move,\n mergeWith,\n} from '@angular-devkit/schematics';\nimport * as ts from 'typescript';\nimport {\n stringUtils,\n buildRelativePath,\n insertImport,\n NoopChange,\n ReplaceChange,\n InsertChange,\n getProjectPath,\n omit,\n parseName,\n} from '../../schematics-core';\nimport { Schema as ContainerOptions } from './schema';\n\nfunction addStateToComponent(options: Partial<ContainerOptions>) {\n return (host: Tree) => {\n if (!options.state && !options.stateInterface) {\n return host;\n }\n\n const statePath = `/${options.path}/${options.state}`;\n\n if (options.state) {\n if (!host.exists(statePath)) {\n throw new Error(`The Specified state path ${statePath} does not exist`);\n }\n }\n\n const componentPath =\n `/${options.path}/` +\n (options.flat ? '' : stringUtils.dasherize(options.name) + '/') +\n stringUtils.dasherize(options.name) +\n '.component.ts';\n\n const text = host.read(componentPath);\n\n if (text === null) {\n throw new SchematicsException(`File ${componentPath} does not exist.`);\n }\n\n const sourceText = text.toString('utf-8');\n\n const source = ts.createSourceFile(\n componentPath,\n sourceText,\n ts.ScriptTarget.Latest,\n true\n );\n\n const stateImportPath = buildRelativePath(componentPath, statePath);\n const storeImport = insertImport(\n source,\n componentPath,\n 'Store',\n '@ngrx/store'\n );\n const stateImport = options.state\n ? insertImport(\n source,\n componentPath,\n `* as fromStore`,\n stateImportPath,\n true\n )\n : new NoopChange();\n\n const componentClass = source.statements.find(\n (stm) => stm.kind === ts.SyntaxKind.ClassDeclaration\n ) as ts.ClassDeclaration;\n const constructorUpdate = new ReplaceChange(\n componentPath,\n componentClass.members.pos,\n '\\n',\n `\\n constructor(private store: Store) {}`\n );\n\n const changes = [storeImport, stateImport, constructorUpdate];\n const recorder = host.beginUpdate(componentPath);\n\n for (const change of changes) {\n if (change instanceof InsertChange) {\n recorder.insertLeft(change.pos, change.toAdd);\n } else if (change instanceof ReplaceChange) {\n recorder.remove(change.pos, change.oldText.length);\n recorder.insertLeft(change.order, change.newText);\n }\n }\n\n host.commitUpdate(recorder);\n\n return host;\n };\n}\n\nexport default function (options: ContainerOptions): Rule {\n return (host: Tree, context: SchematicContext) => {\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 const opts = ['state', 'stateInterface', 'testDepth'].reduce(\n (current: Partial<ContainerOptions>, key) => {\n return omit(current, key as any);\n },\n options\n );\n\n const templateSource = apply(\n url(options.testDepth === 'unit' ? './files' : './integration-files'),\n [\n options.skipTests\n ? filter((path) => !path.endsWith('.spec.ts.template'))\n : noop(),\n applyTemplates({\n 'if-flat': (s: string) => (options.flat ? '' : s),\n ...stringUtils,\n ...(options as object),\n } as any),\n move(parsedPath.path),\n ]\n );\n\n // Remove all undefined values to use the schematic defaults (in angular.json or the Angular schema)\n (Object.keys(opts) as (keyof ContainerOptions)[]).forEach((key) =>\n opts[key] === undefined ? delete opts[key] : {}\n );\n\n return chain([\n externalSchematic('@schematics/angular', 'component', {\n ...opts,\n skipTests: true,\n }),\n addStateToComponent(options),\n mergeWith(templateSource),\n ])(host, context);\n };\n}\n"]}
\No newline at end of file