@magic-xpa/cli 4.800.0-dev480.94 → 4.801.0-dev000.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +1 -1
- package/index.js.map +1 -1
- package/package.json +1 -1
- package/src/collection.json +1 -0
- package/src/public_api.js +3 -3
- package/src/public_api.js.map +1 -1
- package/src/schematics/magic-utils/env.js +5 -5
- package/src/schematics/magic-utils/env.js.map +1 -1
- package/src/schematics/magic-utils/env.ts +5 -5
- package/src/schematics/magic-utils/metadata.class.js +3 -3
- package/src/schematics/magic-utils/metadata.class.js.map +1 -1
- package/src/schematics/magic-utils/process-json.js +4 -4
- package/src/schematics/magic-utils/process-json.js.map +1 -1
- package/src/schematics/magic-utils/rules/build-control.rule.js +4 -4
- package/src/schematics/magic-utils/rules/build-control.rule.js.map +1 -1
- package/src/schematics/magic-utils/rules/build-view.rule.js +4 -4
- package/src/schematics/magic-utils/rules/build-view.rule.js.map +1 -1
- package/src/schematics/magic-utils/rules/component-list.rule.js +31 -54
- package/src/schematics/magic-utils/rules/component-list.rule.js.map +1 -1
- package/src/schematics/magic-utils/rules/component-list.rule.ts +3 -32
- package/src/schematics/magic-utils/rules/generate.rule.js +3 -3
- package/src/schematics/magic-utils/rules/generate.rule.js.map +1 -1
- package/src/schematics/magic-utils/rules/init-add-modules.rule.js +40 -24
- package/src/schematics/magic-utils/rules/init-add-modules.rule.js.map +1 -1
- package/src/schematics/magic-utils/rules/init-add-modules.rule.ts +21 -1
- package/src/schematics/magic-utils/rules/init-gen-components.rule.js +9 -9
- package/src/schematics/magic-utils/rules/init-gen-components.rule.js.map +1 -1
- package/src/schematics/magic-utils/rules/init-magic-metadata.rule.js +2 -2
- package/src/schematics/magic-utils/rules/init-magic-metadata.rule.js.map +1 -1
- package/src/schematics/magic-utils/rules/load-views-gen.rule.js +5 -5
- package/src/schematics/magic-utils/rules/load-views-gen.rule.js.map +1 -1
- package/src/schematics/magic-utils/utils.js +10 -10
- package/src/schematics/magic-utils/utils.js.map +1 -1
- package/src/schematics/mg-Install-prerequisites/index.js +3 -3
- package/src/schematics/mg-Install-prerequisites/index.js.map +1 -1
- package/src/schematics/mg-Install-prerequisites/schema.json +1 -1
- package/src/schematics/mg-add/files/src/app/magic/lazy-loader.service.ts +10 -0
- package/src/schematics/mg-add/files/src/app/magic/magic.gen.lib.module.ts +3 -1
- package/src/schematics/mg-add/index.js +52 -16
- package/src/schematics/mg-add/index.js.map +1 -1
- package/src/schematics/mg-add/index.ts +42 -3
- package/src/schematics/mg-add/schema.json +1 -1
- package/src/schematics/mg-add/utils/add-declaration-to-root-module.js +2 -2
- package/src/schematics/mg-add/utils/add-declaration-to-root-module.js.map +1 -1
- package/src/schematics/mg-add-tasks/schema.json +1 -1
- package/src/schematics/mg-delete-files/index.js +3 -3
- package/src/schematics/mg-delete-files/index.js.map +1 -1
- package/src/schematics/mg-delete-files/schema.json +1 -1
- package/src/schematics/mg-gen-module/index.js +4 -4
- package/src/schematics/mg-gen-module/index.js.map +1 -1
- package/src/schematics/mg-gen-module/schema.json +1 -1
- package/src/schematics/mg-generate/index.js +3 -3
- package/src/schematics/mg-generate/index.js.map +1 -1
- package/src/schematics/mg-generate/schema.json +1 -1
- package/src/schematics/mg-install/index.js +2 -2
- package/src/schematics/mg-install/index.js.map +1 -1
- package/src/schematics/mg-install/schema.json +1 -1
- package/src/schematics/mg-routes/index.js +6 -6
- package/src/schematics/mg-routes/index.js.map +1 -1
- package/src/schematics/mg-routes/schema.json +1 -1
- package/src/schematics/mg-single-control/index.js +4 -4
- package/src/schematics/mg-single-control/index.js.map +1 -1
- package/src/schematics/mg-single-control/schema.json +1 -1
- package/src/schematics/utils/ast.js +6 -6
- package/src/schematics/utils/ast.js.map +1 -1
- package/src/schematics/utils/devkit-utils/ast-utils_old.js +2 -2
- package/src/schematics/utils/devkit-utils/ast-utils_old.js.map +1 -1
- package/src/schematics/utils/devkit-utils/component.js +16 -16
- package/src/schematics/utils/devkit-utils/component.js.map +1 -1
- package/src/schematics/utils/devkit-utils/find-module.js +11 -11
- package/src/schematics/utils/devkit-utils/find-module.js.map +1 -1
- package/src/schematics/utils/devkit-utils/ng-ast-utils.js +6 -6
- package/src/schematics/utils/devkit-utils/ng-ast-utils.js.map +1 -1
- package/src/schematics/utils/devkit-utils/parse-name.js +3 -3
- package/src/schematics/utils/devkit-utils/parse-name.js.map +1 -1
- package/src/schematics/utils/devkit-utils/route-utils.js +16 -16
- package/src/schematics/utils/devkit-utils/route-utils.js.map +1 -1
- package/src/schematics/utils/html.js +1 -1
- package/src/schematics/utils/html.js.map +1 -1
- package/src/schematics/utils/testing.js +1 -1
- package/src/schematics/utils/testing.js.map +1 -1
- package/src/types/enums/Enums.js +5 -1
- package/src/types/enums/Enums.js.map +1 -1
- package/src/types/index.js +7 -7
- package/src/types/index.js.map +1 -1
- package/templates/themes/material/edit.ejs +16 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ast.js","sourceRoot":"","sources":["ast.ts"],"names":[],"mappings":";;;AAAA,+CAA+C;AAC/C,2DAAqE;AACrE,iCAAiC;AACjC,wDAA2D;AAC3D,kDAAmD;AACnD,kDAA4D;AAC5D,8DAAsF;AACtF,4DAAsG;AAGtG,gEAAgE;AAChE,SAAgB,aAAa,CAAC,IAAU,EAAE,IAAY;IACpD,MAAM,MAAM,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC/B,IAAI,CAAC,MAAM,EAAE;QACX,MAAM,IAAI,gCAAmB,CAAC,iCAAiC,IAAI,EAAE,CAAC,CAAC;KACxE;IACD,MAAM,OAAO,GAAG,MAAM,CAAC,QAAQ,EAAE,CAAC;IAClC,OAAO,EAAE,CAAC,gBAAgB,CAAC,IAAI,EAAE,OAAO,EAAE,EAAE,CAAC,YAAY,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;AAC1E,CAAC;AAPD,sCAOC;AAED,gDAAgD;AAChD,SAAgB,2BAA2B,C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B,MAAM,oBAAoB,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,qBAAqB,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;QAC7E,IAAI,oBAAoB,EAAE;YACxB,OAAO,IAAA,gBAAS,EAAC,oBAAoB,CAAC,CAAC;SACxC;QAED,mEAAmE;QACnE,MAAM,iBAAiB,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;QACpE,IAAI,iBAAiB,EAAE;YACrB,OAAO,IAAA,gBAAS,EAAC,iBAAiB,CAAC,CAAC;SACrC;KACF;IAED,MAAM,IAAI,gCAAmB,CAAC,iEAAiE,CAAC,CAAC;AACnG,CAAC;AArBD,sCAqBC;AAED,gFAAgF;AAChF,SAAgB,qBAAqB,CAAC,IAAU,EAAE,OAAY;IAC5D,MAAM,SAAS,GAAG,IAAA,qBAAY,EAAC,IAAI,CAAC,CAAC;IACrC,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE;QACpB,OAAO,CAAC,OAAO,GAAG,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC;KACtD;IAED,MAAM,OAAO,GAAG,SAAS,CAAC,QAAQ,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;IAEpD,IAAI,OAAO,CAAC,IAAI,KAAK,SAAS,EAAE;QAC9B,OAAO,CAAC,IAAI,GAAG,IAAI,OAAO,CAAC,IAAI,UAAU,CAAC;KAC3C;IAED,OAAO,IAAA,mCAAkB,EAAC,IAAI,EAAE,OAAO,CAAC,CAAC;AAC3C,CAAC;AAbD,sDAaC","sourcesContent":["import {normalize} from '@angular-devkit/core';\nimport {SchematicsException, Tree} from '@angular-devkit/schematics';\nimport * as ts from 'typescript';\nimport {addImportToModule} from './devkit-utils/ast-utils';\nimport {InsertChange} from './devkit-utils/change';\nimport {Project, getWorkspace} from './devkit-utils/config';\nimport {findBootstrapModulePath, getAppModulePath} from './devkit-utils/ng-ast-utils';\nimport {ModuleOptions, findModuleFromOptions as internalFindModule} from './devkit-utils/find-module';\n\n\n/** Reads file given path and returns TypeScript source file. */\nexport function getSourceFile(host: Tree, path: string): ts.SourceFile {\n const buffer = host.read(path);\n if (!buffer) {\n throw new SchematicsException(`Could not find file for path: ${path}`);\n }\n const content = buffer.toString();\n return ts.createSourceFile(path, content, ts.ScriptTarget.Latest, true);\n}\n\n/** Import and add module to root app module. */\nexport function addModuleImportToRootModule(host: Tree, moduleName: string, src: string, project: Project) {\n const modulePath = getAppModulePath(host, project.architect.build.options.main);\n addModuleImportToModule(host, modulePath, moduleName, src);\n}\n\n/**\n * Import and add module to specific module path.\n * @param host the tree we are updating\n * @param modulePath src location of the module to import\n * @param moduleName name of module to import\n * @param src src location to import\n */\nexport function addModuleImportToModule(\n host: Tree, modulePath: string, moduleName: string, src: string) {\n const moduleSource = getSourceFile(host, modulePath);\n\n if (!moduleSource) {\n throw new SchematicsException(`Module not found: ${modulePath}`);\n }\n\n const changes = addImportToModule(moduleSource, modulePath, moduleName, src);\n const recorder = host.beginUpdate(modulePath);\n\n changes.forEach((change) => {\n if (change instanceof InsertChange) {\n recorder.insertLeft(change.pos, change.toAdd);\n }\n });\n\n host.commitUpdate(recorder);\n}\n\n/** Gets the app index.html file */\nexport function getIndexHtmlPath(host: Tree, project: Project): string {\n const buildTarget = project.architect.build.options;\n\n if (buildTarget.index && buildTarget.index.endsWith('index.html')) {\n return buildTarget.index;\n }\n\n throw new SchematicsException('No index.html file was found.');\n}\n\n/** Get the root stylesheet file. */\nexport function getStylesPath(host: Tree, project: Project): string {\n const buildTarget = project.architect['build'];\n\n if (buildTarget.options && buildTarget.options.styles && buildTarget.options.styles.length) {\n const styles = buildTarget.options.styles.map(s => s.input);\n\n // First, see if any of the assets is called \"styles.(le|sc|c)ss\", which is the default\n // \"main\" style sheet.\n const defaultMainStylePath = styles.find(a => /styles\\.(c|le|sc)ss/.test(a));\n if (defaultMainStylePath) {\n return normalize(defaultMainStylePath);\n }\n\n // If there was no obvious default file, use the first style asset.\n const fallbackStylePath = styles.find(a => /\\.(c|le|sc)ss/.test(a));\n if (fallbackStylePath) {\n return normalize(fallbackStylePath);\n }\n }\n\n throw new SchematicsException('No style files could be found into which a theme could be added');\n}\n\n/** Wraps the internal find module from options with undefined path handling */\nexport function findModuleFromOptions(host: Tree, options: any) {\n const workspace = getWorkspace(host);\n if (!options.project) {\n options.project = Object.keys(workspace.projects)[0];\n }\n\n const project = workspace.projects[options.project];\n\n if (options.path === undefined) {\n options.path = `/${project.root}/src/app`;\n }\n\n return internalFindModule(host, options);\n}\n"]}
|
|
@@ -281,7 +281,7 @@ function addSymbolToNgModuleMetadata(source, ngModulePath, metadataField, symbol
|
|
|
281
281
|
if (importPath !== null) {
|
|
282
282
|
return [
|
|
283
283
|
new change_1.InsertChange(ngModulePath, position, toInsert),
|
|
284
|
-
route_utils_1.insertImport(source, ngModulePath, symbolName.replace(/\..*$/, ''), importPath),
|
|
284
|
+
(0, route_utils_1.insertImport)(source, ngModulePath, symbolName.replace(/\..*$/, ''), importPath),
|
|
285
285
|
];
|
|
286
286
|
}
|
|
287
287
|
else {
|
|
@@ -354,7 +354,7 @@ function addSymbolToNgModuleMetadata(source, ngModulePath, metadataField, symbol
|
|
|
354
354
|
if (importPath !== null) {
|
|
355
355
|
return [
|
|
356
356
|
new change_1.InsertChange(ngModulePath, position, toInsert),
|
|
357
|
-
route_utils_1.insertImport(source, ngModulePath, symbolName.replace(/\..*$/, ''), importPath),
|
|
357
|
+
(0, route_utils_1.insertImport)(source, ngModulePath, symbolName.replace(/\..*$/, ''), importPath),
|
|
358
358
|
];
|
|
359
359
|
}
|
|
360
360
|
return [new change_1.InsertChange(ngModulePath, position, toInsert)];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ast-utils_old.js","sourceRoot":"","sources":["ast-utils_old.ts"],"names":[],"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,SAAS,CAAC,GAAG,CAAC,YAAY,EAAE,EAAE,CAAC,UAAU,CAAC,eAAe,CAAC;aACrE,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,EAAE,KAAK,cAAc,CAAC,CAAC;QAE/C,OAAO,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC;IAC1B,CAAC,CAAC,CAAC;IAEL,OAAO,aAAa,CAAC,MAAM,GAAG,CAAC,CAAC;AAClC,CAAC;AArBD,gCAqBC","sourcesContent":["/**\n * @license\n * Copyright Google Inc. All Rights Reserved.\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://angular.io/license\n */\nimport * as ts from 'typescript';\nimport { Change, InsertChange } from './change';\nimport { insertImport } from './route-utils';\n\n\n/**\n * Find all nodes from the AST in the subtree of node of SyntaxKind kind.\n * @param node\n * @param kind\n * @param max The maximum number of items to return.\n * @return all nodes of kind, or [] if none is found\n */\nexport function findNodes(node: ts.Node, kind: ts.SyntaxKind, max = Infinity): ts.Node[] {\n if (!node || max == 0) {\n return [];\n }\n\n const arr: ts.Node[] = [];\n if (node.kind === kind) {\n arr.push(node);\n max--;\n }\n if (max > 0) {\n for (const child of node.getChildren()) {\n findNodes(child, kind, max).forEach(node => {\n if (max > 0) {\n arr.push(node);\n }\n max--;\n });\n\n if (max <= 0) {\n break;\n }\n }\n }\n\n return arr;\n}\n\n\n\nexport function getSourceNodes(sourceFile: ts.SourceFile): ts.Node[] {\n const nodes: ts.Node[] = [sourceFile];\n const result = [];\n\n while (nodes.length > 0) {\n const node = nodes.shift();\n\n if (node) {\n result.push(node);\n if (node.getChildCount(sourceFile) >= 0) {\n nodes.unshift(...node.getChildren());\n }\n }\n }\n\n return result;\n}\n\nexport function findNode(node: ts.Node, kind: ts.SyntaxKind, text: string): ts.Node | null {\n if (node.kind === kind && node.getText() === text) {\n // throw new Error(node.getText());\n return node;\n }\n\n let foundNode: ts.Node | null = null;\n ts.forEachChild(node, childNode => {\n foundNode = foundNode || findNode(childNode, kind, text);\n });\n\n return foundNode;\n}\n\n\n/**\n * Helper for sorting nodes.\n * @return function to sort nodes in increasing order of position in sourceFile\n */\nfunction nodesByPosition(first: ts.Node, second: ts.Node): number {\n return first.getStart() - second.getStart();\n}\n\n\n/**\n * Insert `toInsert` after the last occurence of `ts.SyntaxKind[nodes[i].kind]`\n * or after the last of occurence of `syntaxKind` if the last occurence is a sub child\n * of ts.SyntaxKind[nodes[i].kind] and save the changes in file.\n *\n * @param nodes insert after the last occurence of nodes\n * @param toInsert string to insert\n * @param file file to insert changes into\n * @param fallbackPos position to insert if toInsert happens to be the first occurence\n * @param syntaxKind the ts.SyntaxKind of the subchildren to insert after\n * @return Change instance\n * @throw Error if toInsert is first occurence but fall back is not set\n */\nexport function insertAfterLastOccurrence(nodes: ts.Node[],\n toInsert: string,\n file: string,\n fallbackPos: number,\n syntaxKind?: ts.SyntaxKind): Change {\n let lastItem = nodes.sort(nodesByPosition).pop();\n if (!lastItem) {\n //throw new Error();\n // No imports exist....\n new InsertChange(file, 0, toInsert);\n }\n if (syntaxKind) {\n lastItem = findNodes(lastItem, syntaxKind).sort(nodesByPosition).pop();\n }\n if (!lastItem && fallbackPos == undefined) {\n throw new Error(`tried to insert ${toInsert} as first occurence with no fallback position`);\n }\n const lastItemPosition: number = lastItem ? lastItem.getEnd() : fallbackPos;\n\n return new InsertChange(file, lastItemPosition, toInsert);\n}\n\n\nexport function getContentOfKeyLiteral(_source: ts.SourceFile, node: ts.Node): string | null {\n if (node.kind == ts.SyntaxKind.Identifier) {\n return (node as ts.Identifier).text;\n } else if (node.kind == ts.SyntaxKind.StringLiteral) {\n return (node as ts.StringLiteral).text;\n } else {\n return null;\n }\n}\n\n\nfunction _angularImportsFromNode(node: ts.ImportDeclaration,\n _sourceFile: ts.SourceFile): {[name: string]: string} {\n const ms = node.moduleSpecifier;\n let modulePath: string;\n switch (ms.kind) {\n case ts.SyntaxKind.StringLiteral:\n modulePath = (ms as ts.StringLiteral).text;\n break;\n default:\n return {};\n }\n\n if (!modulePath.startsWith('@angular/')) {\n return {};\n }\n\n if (node.importClause) {\n if (node.importClause.name) {\n // This is of the form `import Name from 'path'`. Ignore.\n return {};\n } else if (node.importClause.namedBindings) {\n const nb = node.importClause.namedBindings;\n if (nb.kind == ts.SyntaxKind.NamespaceImport) {\n // This is of the form `import * as name from 'path'`. Return `name.`.\n return {\n [(nb as ts.NamespaceImport).name.text + '.']: modulePath,\n };\n } else {\n // This is of the form `import {a,b,c} from 'path'`\n const namedImports = nb as ts.NamedImports;\n\n return namedImports.elements\n .map((is: ts.ImportSpecifier) => is.propertyName ? is.propertyName.text : is.name.text)\n .reduce((acc: {[name: string]: string}, curr: string) => {\n acc[curr] = modulePath;\n\n return acc;\n }, {});\n }\n }\n\n return {};\n } else {\n // This is of the form `import 'path';`. Nothing to do.\n return {};\n }\n}\n\n\nexport function getDecoratorMetadata(source: ts.SourceFile, identifier: string,\n module: string): ts.Node[] {\n const angularImports: {[name: string]: string}\n = findNodes(source, ts.SyntaxKind.ImportDeclaration)\n .map((node: ts.ImportDeclaration) => _angularImportsFromNode(node, source))\n .reduce((acc: {[name: string]: string}, current: {[name: string]: string}) => {\n for (const key of Object.keys(current)) {\n acc[key] = current[key];\n }\n\n return acc;\n }, {});\n\n return getSourceNodes(source)\n .filter(node => {\n return node.kind == ts.SyntaxKind.Decorator\n && (node as ts.Decorator).expression.kind == ts.SyntaxKind.CallExpression;\n })\n .map(node => (node as ts.Decorator).expression as ts.CallExpression)\n .filter(expr => {\n if (expr.expression.kind == ts.SyntaxKind.Identifier) {\n const id = expr.expression as ts.Identifier;\n\n return id.getFullText(source) == identifier\n && angularImports[id.getFullText(source)] === module;\n } else if (expr.expression.kind == ts.SyntaxKind.PropertyAccessExpression) {\n // This covers foo.NgModule when importing * as foo.\n const paExpr = expr.expression as ts.PropertyAccessExpression;\n // If the left expression is not an identifier, just give up at that point.\n if (paExpr.expression.kind !== ts.SyntaxKind.Identifier) {\n return false;\n }\n\n const id = paExpr.name.text;\n const moduleId = (paExpr.expression as ts.Identifier).getText(source);\n\n return id === identifier && (angularImports[moduleId + '.'] === module);\n }\n\n return false;\n })\n .filter(expr => expr.arguments[0]\n && expr.arguments[0].kind == ts.SyntaxKind.ObjectLiteralExpression)\n .map(expr => expr.arguments[0] as ts.ObjectLiteralExpression);\n}\n\nfunction findClassDeclarationParent(node: ts.Node): ts.ClassDeclaration|undefined {\n if (ts.isClassDeclaration(node)) {\n return node;\n }\n\n return node.parent && findClassDeclarationParent(node.parent);\n}\n\n/**\n * Given a source file with @NgModule class(es), find the name of the first @NgModule class.\n *\n * @param source source file containing one or more @NgModule\n * @returns the name of the first @NgModule, or `undefined` if none is found\n */\nexport function getFirstNgModuleName(source: ts.SourceFile): string|undefined {\n // First, find the @NgModule decorators.\n const ngModulesMetadata = getDecoratorMetadata(source, 'NgModule', '@angular/core');\n if (ngModulesMetadata.length === 0) {\n return undefined;\n }\n\n // Then walk parent pointers up the AST, looking for the ClassDeclaration parent of the NgModule\n // metadata.\n const moduleClass = findClassDeclarationParent(ngModulesMetadata[0]);\n if (!moduleClass || !moduleClass.name) {\n return undefined;\n }\n\n // Get the class name of the module ClassDeclaration.\n return moduleClass.name.text;\n}\n\nexport function addSymbolToNgModuleMetadata(\n source: ts.SourceFile,\n ngModulePath: string,\n metadataField: string,\n symbolName: string,\n importPath: string | null = null,\n): Change[] {\n const nodes = getDecoratorMetadata(source, 'NgModule', '@angular/core');\n let node: any = nodes[0]; // tslint:disable-line:no-any\n\n // Find the decorator declaration.\n if (!node) {\n return [];\n }\n\n // Get all the children property assignment of object literals.\n const matchingProperties: ts.ObjectLiteralElement[] =\n (node as ts.ObjectLiteralExpression).properties\n .filter(prop => prop.kind == ts.SyntaxKind.PropertyAssignment)\n // Filter out every fields that's not \"metadataField\". Also handles string literals\n // (but not expressions).\n .filter((prop: ts.PropertyAssignment) => {\n const name = prop.name;\n switch (name.kind) {\n case ts.SyntaxKind.Identifier:\n return (name as ts.Identifier).getText(source) == metadataField;\n case ts.SyntaxKind.StringLiteral:\n return (name as ts.StringLiteral).text == metadataField;\n }\n\n return false;\n });\n\n // Get the last node of the array literal.\n if (!matchingProperties) {\n return [];\n }\n if (matchingProperties.length == 0) {\n // We haven't found the field in the metadata declaration. Insert a new field.\n const expr = node as ts.ObjectLiteralExpression;\n let position: number;\n let toInsert: string;\n if (expr.properties.length == 0) {\n position = expr.getEnd() - 1;\n toInsert = ` ${metadataField}: [${symbolName}]\\n`;\n } else {\n node = expr.properties[expr.properties.length - 1];\n position = node.getEnd();\n // Get the indentation of the last element, if any.\n const text = node.getFullText(source);\n const matches = text.match(/^\\r?\\n\\s*/);\n if (matches.length > 0) {\n toInsert = `,${matches[0]}${metadataField}: [${symbolName}]`;\n } else {\n toInsert = `, ${metadataField}: [${symbolName}]`;\n }\n }\n if (importPath !== null) {\n return [\n new InsertChange(ngModulePath, position, toInsert),\n insertImport(source, ngModulePath, symbolName.replace(/\\..*$/, ''), importPath),\n ];\n } else {\n return [new InsertChange(ngModulePath, position, toInsert)];\n }\n }\n const assignment = matchingProperties[0] as ts.PropertyAssignment;\n\n // If it's not an array, nothing we can do really.\n if (assignment.initializer.kind !== ts.SyntaxKind.ArrayLiteralExpression) {\n return [];\n }\n\n const arrLiteral = assignment.initializer as ts.ArrayLiteralExpression;\n if (arrLiteral.elements.length == 0) {\n // Forward the property.\n node = arrLiteral;\n } else {\n node = arrLiteral.elements;\n }\n\n if (!node) {\n console.log('No app module found. Please add your new class to your component.');\n\n return [];\n }\n\n if (Array.isArray(node)) {\n const nodeArray = node as {} as Array<ts.Node>;\n const symbolsArray = nodeArray.map(node => node.getText());\n if (symbolsArray.includes(symbolName)) {\n return [];\n }\n\n node = node[node.length - 1];\n }\n\n let toInsert: string;\n let position = node.getEnd();\n if (node.kind == ts.SyntaxKind.ObjectLiteralExpression) {\n // We haven't found the field in the metadata declaration. Insert a new\n // field.\n const expr = node as ts.ObjectLiteralExpression;\n if (expr.properties.length == 0) {\n position = expr.getEnd() - 1;\n toInsert = ` ${metadataField}: [${symbolName}]\\n`;\n } else {\n node = expr.properties[expr.properties.length - 1];\n position = node.getEnd();\n // Get the indentation of the last element, if any.\n const text = node.getFullText(source);\n if (text.match('^\\r?\\r?\\n')) {\n toInsert = `,${text.match(/^\\r?\\n\\s+/)[0]}${metadataField}: [${symbolName}]`;\n } else {\n toInsert = `, ${metadataField}: [${symbolName}]`;\n }\n }\n } else if (node.kind == ts.SyntaxKind.ArrayLiteralExpression) {\n // We found the field but it's empty. Insert it just before the `]`.\n position--;\n toInsert = `${symbolName}`;\n } else {\n // Get the indentation of the last element, if any.\n const text = node.getFullText(source);\n if (text.match(/^\\r?\\n/)) {\n toInsert = `,${text.match(/^\\r?\\n(\\r?)\\s+/)[0]}${symbolName}`;\n } else {\n toInsert = `, ${symbolName}`;\n }\n }\n if (importPath !== null) {\n return [\n new InsertChange(ngModulePath, position, toInsert),\n insertImport(source, ngModulePath, symbolName.replace(/\\..*$/, ''), importPath),\n ];\n }\n\n return [new InsertChange(ngModulePath, position, toInsert)];\n}\n\n/**\n * Custom function to insert a declaration (component, pipe, directive)\n * into NgModule declarations. It also imports the component.\n */\nexport function addDeclarationToModule(source: ts.SourceFile,\n modulePath: string, classifiedName: string,\n importPath: string): Change[] {\n return addSymbolToNgModuleMetadata(\n source, modulePath, 'declarations', classifiedName, importPath);\n}\n\n/**\n * Custom function to insert an NgModule into NgModule imports. It also imports the module.\n */\nexport function addImportToModule(source: ts.SourceFile,\n modulePath: string, classifiedName: string,\n importPath: string): Change[] {\n\n return addSymbolToNgModuleMetadata(source, modulePath, 'imports', classifiedName, importPath);\n}\n\n/**\n * Custom function to insert a provider into NgModule. It also imports it.\n */\nexport function addProviderToModule(source: ts.SourceFile,\n modulePath: string, classifiedName: string,\n importPath: string): Change[] {\n return addSymbolToNgModuleMetadata(source, modulePath, 'providers', classifiedName, importPath);\n}\n\n/**\n * Custom function to insert an export into NgModule. It also imports it.\n */\nexport function addExportToModule(source: ts.SourceFile,\n modulePath: string, classifiedName: string,\n importPath: string): Change[] {\n return addSymbolToNgModuleMetadata(source, modulePath, 'exports', classifiedName, importPath);\n}\n\n/**\n * Custom function to insert an export into NgModule. It also imports it.\n */\nexport function addBootstrapToModule(source: ts.SourceFile,\n modulePath: string, classifiedName: string,\n importPath: string): Change[] {\n return addSymbolToNgModuleMetadata(source, modulePath, 'bootstrap', classifiedName, importPath);\n}\n\n/**\n * Determine if an import already exists.\n */\nexport function isImported(source: ts.SourceFile,\n classifiedName: string,\n importPath: string): boolean {\n const allNodes = getSourceNodes(source);\n const matchingNodes = allNodes\n .filter(node => node.kind === ts.SyntaxKind.ImportDeclaration)\n .filter((imp: ts.ImportDeclaration) => imp.moduleSpecifier.kind === ts.SyntaxKind.StringLiteral)\n .filter((imp: ts.ImportDeclaration) => {\n return (<ts.StringLiteral> imp.moduleSpecifier).text === importPath;\n })\n .filter((imp: ts.ImportDeclaration) => {\n if (!imp.importClause) {\n return false;\n }\n const nodes = findNodes(imp.importClause, ts.SyntaxKind.ImportSpecifier)\n .filter(n => n.getText() === classifiedName);\n\n return nodes.length > 0;\n });\n\n return matchingNodes.length > 0;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"ast-utils_old.js","sourceRoot":"","sources":["ast-utils_old.ts"],"names":[],"mappings":";;;AAAA;;;;;;GAMG;AACH,iCAAiC;AACjC,qCAAgD;AAChD,+CAA6C;AAG7C;;;;;;GAMG;AACH,SAAgB,SAAS,CAAC,IAAa,EAAE,IAAmB,EAAE,GAAG,GAAG,QAAQ;IAC1E,IAAI,CAAC,IAAI,IAAI,GAAG,IAAI,CAAC,EAAE;QACrB,OAAO,EAAE,CAAC;KACX;IAED,MAAM,GAAG,GAAc,EAAE,CAAC;IAC1B,IAAI,IAAI,CAAC,IAAI,KAAK,IAAI,EAAE;QACtB,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACf,GAAG,EAAE,CAAC;KACP;IACD,IAAI,GAAG,GA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AAoB,CAAC,MAAqB,EACrB,UAAkB,EAAE,cAAsB,EAC1C,UAAkB;IACrD,OAAO,2BAA2B,CAAC,MAAM,EAAE,UAAU,EAAE,WAAW,EAAE,cAAc,EAAE,UAAU,CAAC,CAAC;AAClG,CAAC;AAJD,oDAIC;AAED;;GAEG;AACH,SAAgB,UAAU,CAAC,MAAqB,EACrB,cAAsB,EACtB,UAAkB;IAC3C,MAAM,QAAQ,GAAG,cAAc,CAAC,MAAM,CAAC,CAAC;IACxC,MAAM,aAAa,GAAG,QAAQ;SAC3B,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,IAAI,KAAK,EAAE,CAAC,UAAU,CAAC,iBAAiB,CAAC;SAC7D,MAAM,CAAC,CAAC,GAAyB,EAAE,EAAE,CAAC,GAAG,CAAC,eAAe,CAAC,IAAI,KAAK,EAAE,CAAC,UAAU,CAAC,aAAa,CAAC;SAC/F,MAAM,CAAC,CAAC,GAAyB,EAAE,EAAE;QACpC,OAA2B,GAAG,CAAC,eAAgB,CAAC,IAAI,KAAK,UAAU,CAAC;IACtE,CAAC,CAAC;SACD,MAAM,CAAC,CAAC,GAAyB,EAAE,EAAE;QACpC,IAAI,CAAC,GAAG,CAAC,YAAY,EAAE;YACrB,OAAO,KAAK,CAAC;SACd;QACD,MAAM,KAAK,GAAG,SAAS,CAAC,GAAG,CAAC,YAAY,EAAE,EAAE,CAAC,UAAU,CAAC,eAAe,CAAC;aACrE,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,EAAE,KAAK,cAAc,CAAC,CAAC;QAE/C,OAAO,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC;IAC1B,CAAC,CAAC,CAAC;IAEL,OAAO,aAAa,CAAC,MAAM,GAAG,CAAC,CAAC;AAClC,CAAC;AArBD,gCAqBC","sourcesContent":["/**\n * @license\n * Copyright Google Inc. All Rights Reserved.\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://angular.io/license\n */\nimport * as ts from 'typescript';\nimport { Change, InsertChange } from './change';\nimport { insertImport } from './route-utils';\n\n\n/**\n * Find all nodes from the AST in the subtree of node of SyntaxKind kind.\n * @param node\n * @param kind\n * @param max The maximum number of items to return.\n * @return all nodes of kind, or [] if none is found\n */\nexport function findNodes(node: ts.Node, kind: ts.SyntaxKind, max = Infinity): ts.Node[] {\n if (!node || max == 0) {\n return [];\n }\n\n const arr: ts.Node[] = [];\n if (node.kind === kind) {\n arr.push(node);\n max--;\n }\n if (max > 0) {\n for (const child of node.getChildren()) {\n findNodes(child, kind, max).forEach(node => {\n if (max > 0) {\n arr.push(node);\n }\n max--;\n });\n\n if (max <= 0) {\n break;\n }\n }\n }\n\n return arr;\n}\n\n\n\nexport function getSourceNodes(sourceFile: ts.SourceFile): ts.Node[] {\n const nodes: ts.Node[] = [sourceFile];\n const result = [];\n\n while (nodes.length > 0) {\n const node = nodes.shift();\n\n if (node) {\n result.push(node);\n if (node.getChildCount(sourceFile) >= 0) {\n nodes.unshift(...node.getChildren());\n }\n }\n }\n\n return result;\n}\n\nexport function findNode(node: ts.Node, kind: ts.SyntaxKind, text: string): ts.Node | null {\n if (node.kind === kind && node.getText() === text) {\n // throw new Error(node.getText());\n return node;\n }\n\n let foundNode: ts.Node | null = null;\n ts.forEachChild(node, childNode => {\n foundNode = foundNode || findNode(childNode, kind, text);\n });\n\n return foundNode;\n}\n\n\n/**\n * Helper for sorting nodes.\n * @return function to sort nodes in increasing order of position in sourceFile\n */\nfunction nodesByPosition(first: ts.Node, second: ts.Node): number {\n return first.getStart() - second.getStart();\n}\n\n\n/**\n * Insert `toInsert` after the last occurence of `ts.SyntaxKind[nodes[i].kind]`\n * or after the last of occurence of `syntaxKind` if the last occurence is a sub child\n * of ts.SyntaxKind[nodes[i].kind] and save the changes in file.\n *\n * @param nodes insert after the last occurence of nodes\n * @param toInsert string to insert\n * @param file file to insert changes into\n * @param fallbackPos position to insert if toInsert happens to be the first occurence\n * @param syntaxKind the ts.SyntaxKind of the subchildren to insert after\n * @return Change instance\n * @throw Error if toInsert is first occurence but fall back is not set\n */\nexport function insertAfterLastOccurrence(nodes: ts.Node[],\n toInsert: string,\n file: string,\n fallbackPos: number,\n syntaxKind?: ts.SyntaxKind): Change {\n let lastItem = nodes.sort(nodesByPosition).pop();\n if (!lastItem) {\n //throw new Error();\n // No imports exist....\n new InsertChange(file, 0, toInsert);\n }\n if (syntaxKind) {\n lastItem = findNodes(lastItem, syntaxKind).sort(nodesByPosition).pop();\n }\n if (!lastItem && fallbackPos == undefined) {\n throw new Error(`tried to insert ${toInsert} as first occurence with no fallback position`);\n }\n const lastItemPosition: number = lastItem ? lastItem.getEnd() : fallbackPos;\n\n return new InsertChange(file, lastItemPosition, toInsert);\n}\n\n\nexport function getContentOfKeyLiteral(_source: ts.SourceFile, node: ts.Node): string | null {\n if (node.kind == ts.SyntaxKind.Identifier) {\n return (node as ts.Identifier).text;\n } else if (node.kind == ts.SyntaxKind.StringLiteral) {\n return (node as ts.StringLiteral).text;\n } else {\n return null;\n }\n}\n\n\nfunction _angularImportsFromNode(node: ts.ImportDeclaration,\n _sourceFile: ts.SourceFile): {[name: string]: string} {\n const ms = node.moduleSpecifier;\n let modulePath: string;\n switch (ms.kind) {\n case ts.SyntaxKind.StringLiteral:\n modulePath = (ms as ts.StringLiteral).text;\n break;\n default:\n return {};\n }\n\n if (!modulePath.startsWith('@angular/')) {\n return {};\n }\n\n if (node.importClause) {\n if (node.importClause.name) {\n // This is of the form `import Name from 'path'`. Ignore.\n return {};\n } else if (node.importClause.namedBindings) {\n const nb = node.importClause.namedBindings;\n if (nb.kind == ts.SyntaxKind.NamespaceImport) {\n // This is of the form `import * as name from 'path'`. Return `name.`.\n return {\n [(nb as ts.NamespaceImport).name.text + '.']: modulePath,\n };\n } else {\n // This is of the form `import {a,b,c} from 'path'`\n const namedImports = nb as ts.NamedImports;\n\n return namedImports.elements\n .map((is: ts.ImportSpecifier) => is.propertyName ? is.propertyName.text : is.name.text)\n .reduce((acc: {[name: string]: string}, curr: string) => {\n acc[curr] = modulePath;\n\n return acc;\n }, {});\n }\n }\n\n return {};\n } else {\n // This is of the form `import 'path';`. Nothing to do.\n return {};\n }\n}\n\n\nexport function getDecoratorMetadata(source: ts.SourceFile, identifier: string,\n module: string): ts.Node[] {\n const angularImports: {[name: string]: string}\n = findNodes(source, ts.SyntaxKind.ImportDeclaration)\n .map((node: ts.ImportDeclaration) => _angularImportsFromNode(node, source))\n .reduce((acc: {[name: string]: string}, current: {[name: string]: string}) => {\n for (const key of Object.keys(current)) {\n acc[key] = current[key];\n }\n\n return acc;\n }, {});\n\n return getSourceNodes(source)\n .filter(node => {\n return node.kind == ts.SyntaxKind.Decorator\n && (node as ts.Decorator).expression.kind == ts.SyntaxKind.CallExpression;\n })\n .map(node => (node as ts.Decorator).expression as ts.CallExpression)\n .filter(expr => {\n if (expr.expression.kind == ts.SyntaxKind.Identifier) {\n const id = expr.expression as ts.Identifier;\n\n return id.getFullText(source) == identifier\n && angularImports[id.getFullText(source)] === module;\n } else if (expr.expression.kind == ts.SyntaxKind.PropertyAccessExpression) {\n // This covers foo.NgModule when importing * as foo.\n const paExpr = expr.expression as ts.PropertyAccessExpression;\n // If the left expression is not an identifier, just give up at that point.\n if (paExpr.expression.kind !== ts.SyntaxKind.Identifier) {\n return false;\n }\n\n const id = paExpr.name.text;\n const moduleId = (paExpr.expression as ts.Identifier).getText(source);\n\n return id === identifier && (angularImports[moduleId + '.'] === module);\n }\n\n return false;\n })\n .filter(expr => expr.arguments[0]\n && expr.arguments[0].kind == ts.SyntaxKind.ObjectLiteralExpression)\n .map(expr => expr.arguments[0] as ts.ObjectLiteralExpression);\n}\n\nfunction findClassDeclarationParent(node: ts.Node): ts.ClassDeclaration|undefined {\n if (ts.isClassDeclaration(node)) {\n return node;\n }\n\n return node.parent && findClassDeclarationParent(node.parent);\n}\n\n/**\n * Given a source file with @NgModule class(es), find the name of the first @NgModule class.\n *\n * @param source source file containing one or more @NgModule\n * @returns the name of the first @NgModule, or `undefined` if none is found\n */\nexport function getFirstNgModuleName(source: ts.SourceFile): string|undefined {\n // First, find the @NgModule decorators.\n const ngModulesMetadata = getDecoratorMetadata(source, 'NgModule', '@angular/core');\n if (ngModulesMetadata.length === 0) {\n return undefined;\n }\n\n // Then walk parent pointers up the AST, looking for the ClassDeclaration parent of the NgModule\n // metadata.\n const moduleClass = findClassDeclarationParent(ngModulesMetadata[0]);\n if (!moduleClass || !moduleClass.name) {\n return undefined;\n }\n\n // Get the class name of the module ClassDeclaration.\n return moduleClass.name.text;\n}\n\nexport function addSymbolToNgModuleMetadata(\n source: ts.SourceFile,\n ngModulePath: string,\n metadataField: string,\n symbolName: string,\n importPath: string | null = null,\n): Change[] {\n const nodes = getDecoratorMetadata(source, 'NgModule', '@angular/core');\n let node: any = nodes[0]; // tslint:disable-line:no-any\n\n // Find the decorator declaration.\n if (!node) {\n return [];\n }\n\n // Get all the children property assignment of object literals.\n const matchingProperties: ts.ObjectLiteralElement[] =\n (node as ts.ObjectLiteralExpression).properties\n .filter(prop => prop.kind == ts.SyntaxKind.PropertyAssignment)\n // Filter out every fields that's not \"metadataField\". Also handles string literals\n // (but not expressions).\n .filter((prop: ts.PropertyAssignment) => {\n const name = prop.name;\n switch (name.kind) {\n case ts.SyntaxKind.Identifier:\n return (name as ts.Identifier).getText(source) == metadataField;\n case ts.SyntaxKind.StringLiteral:\n return (name as ts.StringLiteral).text == metadataField;\n }\n\n return false;\n });\n\n // Get the last node of the array literal.\n if (!matchingProperties) {\n return [];\n }\n if (matchingProperties.length == 0) {\n // We haven't found the field in the metadata declaration. Insert a new field.\n const expr = node as ts.ObjectLiteralExpression;\n let position: number;\n let toInsert: string;\n if (expr.properties.length == 0) {\n position = expr.getEnd() - 1;\n toInsert = ` ${metadataField}: [${symbolName}]\\n`;\n } else {\n node = expr.properties[expr.properties.length - 1];\n position = node.getEnd();\n // Get the indentation of the last element, if any.\n const text = node.getFullText(source);\n const matches = text.match(/^\\r?\\n\\s*/);\n if (matches.length > 0) {\n toInsert = `,${matches[0]}${metadataField}: [${symbolName}]`;\n } else {\n toInsert = `, ${metadataField}: [${symbolName}]`;\n }\n }\n if (importPath !== null) {\n return [\n new InsertChange(ngModulePath, position, toInsert),\n insertImport(source, ngModulePath, symbolName.replace(/\\..*$/, ''), importPath),\n ];\n } else {\n return [new InsertChange(ngModulePath, position, toInsert)];\n }\n }\n const assignment = matchingProperties[0] as ts.PropertyAssignment;\n\n // If it's not an array, nothing we can do really.\n if (assignment.initializer.kind !== ts.SyntaxKind.ArrayLiteralExpression) {\n return [];\n }\n\n const arrLiteral = assignment.initializer as ts.ArrayLiteralExpression;\n if (arrLiteral.elements.length == 0) {\n // Forward the property.\n node = arrLiteral;\n } else {\n node = arrLiteral.elements;\n }\n\n if (!node) {\n console.log('No app module found. Please add your new class to your component.');\n\n return [];\n }\n\n if (Array.isArray(node)) {\n const nodeArray = node as {} as Array<ts.Node>;\n const symbolsArray = nodeArray.map(node => node.getText());\n if (symbolsArray.includes(symbolName)) {\n return [];\n }\n\n node = node[node.length - 1];\n }\n\n let toInsert: string;\n let position = node.getEnd();\n if (node.kind == ts.SyntaxKind.ObjectLiteralExpression) {\n // We haven't found the field in the metadata declaration. Insert a new\n // field.\n const expr = node as ts.ObjectLiteralExpression;\n if (expr.properties.length == 0) {\n position = expr.getEnd() - 1;\n toInsert = ` ${metadataField}: [${symbolName}]\\n`;\n } else {\n node = expr.properties[expr.properties.length - 1];\n position = node.getEnd();\n // Get the indentation of the last element, if any.\n const text = node.getFullText(source);\n if (text.match('^\\r?\\r?\\n')) {\n toInsert = `,${text.match(/^\\r?\\n\\s+/)[0]}${metadataField}: [${symbolName}]`;\n } else {\n toInsert = `, ${metadataField}: [${symbolName}]`;\n }\n }\n } else if (node.kind == ts.SyntaxKind.ArrayLiteralExpression) {\n // We found the field but it's empty. Insert it just before the `]`.\n position--;\n toInsert = `${symbolName}`;\n } else {\n // Get the indentation of the last element, if any.\n const text = node.getFullText(source);\n if (text.match(/^\\r?\\n/)) {\n toInsert = `,${text.match(/^\\r?\\n(\\r?)\\s+/)[0]}${symbolName}`;\n } else {\n toInsert = `, ${symbolName}`;\n }\n }\n if (importPath !== null) {\n return [\n new InsertChange(ngModulePath, position, toInsert),\n insertImport(source, ngModulePath, symbolName.replace(/\\..*$/, ''), importPath),\n ];\n }\n\n return [new InsertChange(ngModulePath, position, toInsert)];\n}\n\n/**\n * Custom function to insert a declaration (component, pipe, directive)\n * into NgModule declarations. It also imports the component.\n */\nexport function addDeclarationToModule(source: ts.SourceFile,\n modulePath: string, classifiedName: string,\n importPath: string): Change[] {\n return addSymbolToNgModuleMetadata(\n source, modulePath, 'declarations', classifiedName, importPath);\n}\n\n/**\n * Custom function to insert an NgModule into NgModule imports. It also imports the module.\n */\nexport function addImportToModule(source: ts.SourceFile,\n modulePath: string, classifiedName: string,\n importPath: string): Change[] {\n\n return addSymbolToNgModuleMetadata(source, modulePath, 'imports', classifiedName, importPath);\n}\n\n/**\n * Custom function to insert a provider into NgModule. It also imports it.\n */\nexport function addProviderToModule(source: ts.SourceFile,\n modulePath: string, classifiedName: string,\n importPath: string): Change[] {\n return addSymbolToNgModuleMetadata(source, modulePath, 'providers', classifiedName, importPath);\n}\n\n/**\n * Custom function to insert an export into NgModule. It also imports it.\n */\nexport function addExportToModule(source: ts.SourceFile,\n modulePath: string, classifiedName: string,\n importPath: string): Change[] {\n return addSymbolToNgModuleMetadata(source, modulePath, 'exports', classifiedName, importPath);\n}\n\n/**\n * Custom function to insert an export into NgModule. It also imports it.\n */\nexport function addBootstrapToModule(source: ts.SourceFile,\n modulePath: string, classifiedName: string,\n importPath: string): Change[] {\n return addSymbolToNgModuleMetadata(source, modulePath, 'bootstrap', classifiedName, importPath);\n}\n\n/**\n * Determine if an import already exists.\n */\nexport function isImported(source: ts.SourceFile,\n classifiedName: string,\n importPath: string): boolean {\n const allNodes = getSourceNodes(source);\n const matchingNodes = allNodes\n .filter(node => node.kind === ts.SyntaxKind.ImportDeclaration)\n .filter((imp: ts.ImportDeclaration) => imp.moduleSpecifier.kind === ts.SyntaxKind.StringLiteral)\n .filter((imp: ts.ImportDeclaration) => {\n return (<ts.StringLiteral> imp.moduleSpecifier).text === importPath;\n })\n .filter((imp: ts.ImportDeclaration) => {\n if (!imp.importClause) {\n return false;\n }\n const nodes = findNodes(imp.importClause, ts.SyntaxKind.ImportSpecifier)\n .filter(n => n.getText() === classifiedName);\n\n return nodes.length > 0;\n });\n\n return matchingNodes.length > 0;\n}\n"]}
|
|
@@ -26,9 +26,9 @@ function addDeclarationToNgModule(options) {
|
|
|
26
26
|
+ (options.flat ? '' : core_1.strings.dasherize(options.name) + '/')
|
|
27
27
|
+ core_1.strings.dasherize(options.name)
|
|
28
28
|
+ '.component';
|
|
29
|
-
const relativePath = find_module_1.buildRelativePath(modulePath, componentPath);
|
|
29
|
+
const relativePath = (0, find_module_1.buildRelativePath)(modulePath, componentPath);
|
|
30
30
|
const classifiedName = core_1.strings.classify(`${options.name}Component`);
|
|
31
|
-
const declarationChanges = ast_utils_1.addDeclarationToModule(source, modulePath, classifiedName, relativePath);
|
|
31
|
+
const declarationChanges = (0, ast_utils_1.addDeclarationToModule)(source, modulePath, classifiedName, relativePath);
|
|
32
32
|
const declarationRecorder = host.beginUpdate(modulePath);
|
|
33
33
|
for (const change of declarationChanges) {
|
|
34
34
|
if (change instanceof change_1.InsertChange) {
|
|
@@ -45,7 +45,7 @@ function addDeclarationToNgModule(options) {
|
|
|
45
45
|
const sourceText = text.toString('utf-8');
|
|
46
46
|
const source = ts.createSourceFile(modulePath, sourceText, ts.ScriptTarget.Latest, true);
|
|
47
47
|
const exportRecorder = host.beginUpdate(modulePath);
|
|
48
|
-
const exportChanges = ast_utils_1.addExportToModule(source, modulePath, core_1.strings.classify(`${options.name}Component`), relativePath);
|
|
48
|
+
const exportChanges = (0, ast_utils_1.addExportToModule)(source, modulePath, core_1.strings.classify(`${options.name}Component`), relativePath);
|
|
49
49
|
for (const change of exportChanges) {
|
|
50
50
|
if (change instanceof change_1.InsertChange) {
|
|
51
51
|
exportRecorder.insertLeft(change.pos, change.toAdd);
|
|
@@ -65,7 +65,7 @@ function buildSelector(options) {
|
|
|
65
65
|
}
|
|
66
66
|
function buildComponent(options) {
|
|
67
67
|
return (host, context) => {
|
|
68
|
-
const workspace = config_1.getWorkspace(host);
|
|
68
|
+
const workspace = (0, config_1.getWorkspace)(host);
|
|
69
69
|
if (!options.project) {
|
|
70
70
|
options.project = Object.keys(workspace.projects)[0];
|
|
71
71
|
}
|
|
@@ -74,22 +74,22 @@ function buildComponent(options) {
|
|
|
74
74
|
options.path = `/${project.root}/src/app`;
|
|
75
75
|
}
|
|
76
76
|
options.selector = options.selector || buildSelector(options);
|
|
77
|
-
options.module = find_module_1.findModuleFromOptions(host, options);
|
|
78
|
-
const parsedPath = parse_name_1.parseName(options.path, options.name);
|
|
77
|
+
options.module = (0, find_module_1.findModuleFromOptions)(host, options);
|
|
78
|
+
const parsedPath = (0, parse_name_1.parseName)(options.path, options.name);
|
|
79
79
|
options.name = parsedPath.name;
|
|
80
80
|
options.path = parsedPath.path;
|
|
81
|
-
validation_1.validateName(options.name);
|
|
82
|
-
const templateSource = schematics_1.apply(schematics_1.url('./files'), [
|
|
83
|
-
options.spec ? schematics_1.noop() : schematics_1.filter(path => !path.endsWith('.spec.ts')),
|
|
84
|
-
options.inlineStyle ? schematics_1.filter(path => !path.endsWith('.__styleext__')) : schematics_1.noop(),
|
|
85
|
-
options.inlineTemplate ? schematics_1.filter(path => !path.endsWith('.html')) : schematics_1.noop(),
|
|
86
|
-
schematics_1.template(Object.assign(Object.assign(Object.assign({}, core_1.strings), { 'if-flat': (s) => options.flat ? '' : s }), options)),
|
|
87
|
-
schematics_1.move(null, parsedPath.path),
|
|
81
|
+
(0, validation_1.validateName)(options.name);
|
|
82
|
+
const templateSource = (0, schematics_1.apply)((0, schematics_1.url)('./files'), [
|
|
83
|
+
options.spec ? (0, schematics_1.noop)() : (0, schematics_1.filter)(path => !path.endsWith('.spec.ts')),
|
|
84
|
+
options.inlineStyle ? (0, schematics_1.filter)(path => !path.endsWith('.__styleext__')) : (0, schematics_1.noop)(),
|
|
85
|
+
options.inlineTemplate ? (0, schematics_1.filter)(path => !path.endsWith('.html')) : (0, schematics_1.noop)(),
|
|
86
|
+
(0, schematics_1.template)(Object.assign(Object.assign(Object.assign({}, core_1.strings), { 'if-flat': (s) => options.flat ? '' : s }), options)),
|
|
87
|
+
(0, schematics_1.move)(null, parsedPath.path),
|
|
88
88
|
]);
|
|
89
|
-
return schematics_1.chain([
|
|
90
|
-
schematics_1.branchAndMerge(schematics_1.chain([
|
|
89
|
+
return (0, schematics_1.chain)([
|
|
90
|
+
(0, schematics_1.branchAndMerge)((0, schematics_1.chain)([
|
|
91
91
|
addDeclarationToNgModule(options),
|
|
92
|
-
schematics_1.mergeWith(templateSource),
|
|
92
|
+
(0, schematics_1.mergeWith)(templateSource),
|
|
93
93
|
])),
|
|
94
94
|
])(host, context);
|
|
95
95
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"component.js","sourceRoot":"","sources":["component.ts"],"names":[],"mappings":";;;AAAA,+CAAwD;AACxD,2DAcoC;AACpC,iCAAiC;AACjC,2CAAsE;AACtE,qCAAsC;AACtC,+CAAuE;AACvE,qCAAsC;AACtC,6CAAuC;AACvC,6CAA0C;AAE1C,SAAS,wBAAwB,CAAC,OAAY;IAC5C,OAAO,CAAC,IAAU,EAAE,EAAE;QACpB,IAAI,OAAO,CAAC,UAAU,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE;YACzC,OAAO,IAAI,CAAC;SACb;QAED,MAAM,UAAU,GAAG,OAAO,CAAC,MAAM,CAAC;QAClC,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QACnC,IAAI,IAAI,KAAK,IAAI,EAAE;YACjB,MAAM,IAAI,gCAAmB,CAAC,QAAQ,UAAU,kBAAkB,CA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AO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,KAC5C,OAAO,EACV;YACF,IAAA,iBAAI,EAAC,IAAI,EAAE,UAAU,CAAC,IAAI,CAAC;SAC5B,CAAC,CAAC;QAEH,OAAO,IAAA,kBAAK,EAAC;YACX,IAAA,2BAAc,EAAC,IAAA,kBAAK,EAAC;gBACnB,wBAAwB,CAAC,OAAO,CAAC;gBACjC,IAAA,sBAAS,EAAC,cAAc,CAAC;aAC1B,CAAC,CAAC;SACJ,CAAC,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IACpB,CAAC,CAAC;AACJ,CAAC;AAxCD,wCAwCC","sourcesContent":["import {normalize, strings} from '@angular-devkit/core';\nimport {\n apply,\n branchAndMerge,\n chain,\n filter,\n mergeWith,\n move,\n noop,\n Rule,\n SchematicContext,\n SchematicsException,\n template,\n Tree,\n url,\n} from '@angular-devkit/schematics';\nimport * as ts from 'typescript';\nimport {addDeclarationToModule, addExportToModule} from './ast-utils';\nimport {InsertChange} from './change';\nimport {buildRelativePath, findModuleFromOptions} from './find-module';\nimport {getWorkspace} from './config';\nimport {parseName} from './parse-name';\nimport {validateName} from './validation';\n\nfunction addDeclarationToNgModule(options: any): Rule {\n return (host: Tree) => {\n if (options.skipImport || !options.module) {\n return host;\n }\n\n const modulePath = options.module;\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 const source = ts.createSourceFile(modulePath, sourceText, ts.ScriptTarget.Latest, true);\n\n const componentPath = `/${options.path}/`\n + (options.flat ? '' : strings.dasherize(options.name) + '/')\n + strings.dasherize(options.name)\n + '.component';\n const relativePath = buildRelativePath(modulePath, componentPath);\n const classifiedName = strings.classify(`${options.name}Component`);\n const declarationChanges = addDeclarationToModule(source,\n modulePath,\n classifiedName,\n relativePath);\n\n const declarationRecorder = host.beginUpdate(modulePath);\n for (const change of declarationChanges) {\n if (change instanceof InsertChange) {\n declarationRecorder.insertLeft(change.pos, change.toAdd);\n }\n }\n host.commitUpdate(declarationRecorder);\n\n if (options.export) {\n // Need to refresh the AST because we overwrote the file in the host.\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 const source = ts.createSourceFile(modulePath, sourceText, ts.ScriptTarget.Latest, true);\n\n const exportRecorder = host.beginUpdate(modulePath);\n const exportChanges = addExportToModule(source, modulePath,\n strings.classify(`${options.name}Component`),\n relativePath);\n\n for (const change of exportChanges) {\n if (change instanceof InsertChange) {\n exportRecorder.insertLeft(change.pos, change.toAdd);\n }\n }\n host.commitUpdate(exportRecorder);\n }\n\n\n return host;\n };\n}\n\n\nfunction buildSelector(options: any) {\n let selector = strings.dasherize(options.name);\n if (options.prefix) {\n selector = `${options.prefix}-${selector}`;\n }\n\n return selector;\n}\n\n\nexport function buildComponent(options: any): Rule {\n return (host: Tree, context: SchematicContext) => {\n const workspace = getWorkspace(host);\n if (!options.project) {\n options.project = Object.keys(workspace.projects)[0];\n }\n const project = workspace.projects[options.project];\n\n if (options.path === undefined) {\n options.path = `/${project.root}/src/app`;\n }\n\n options.selector = options.selector || buildSelector(options);\n options.module = findModuleFromOptions(host, options);\n\n const parsedPath = parseName(options.path, options.name);\n options.name = parsedPath.name;\n options.path = parsedPath.path;\n\n validateName(options.name);\n\n const templateSource = apply(url('./files'), [\n options.spec ? noop() : filter(path => !path.endsWith('.spec.ts')),\n options.inlineStyle ? filter(path => !path.endsWith('.__styleext__')) : noop(),\n options.inlineTemplate ? filter(path => !path.endsWith('.html')) : noop(),\n template({\n ...strings,\n 'if-flat': (s: string) => options.flat ? '' : s,\n ...options,\n }),\n move(null, parsedPath.path),\n ]);\n\n return chain([\n branchAndMerge(chain([\n addDeclarationToNgModule(options),\n mergeWith(templateSource),\n ])),\n ])(host, context);\n };\n}\n"]}
|
|
@@ -19,22 +19,22 @@ function findModuleFromOptions(host, options) {
|
|
|
19
19
|
if (!options.module) {
|
|
20
20
|
const pathToCheck = (options.path || '')
|
|
21
21
|
+ (options.flat ? '' : '/' + core_1.strings.dasherize(options.name));
|
|
22
|
-
return core_1.normalize(findModule(host, pathToCheck));
|
|
22
|
+
return (0, core_1.normalize)(findModule(host, pathToCheck));
|
|
23
23
|
}
|
|
24
24
|
else {
|
|
25
|
-
const modulePath = core_1.normalize('/' + (options.path) + '/' + options.module);
|
|
26
|
-
const moduleBaseName = core_1.normalize(modulePath).split('/').pop();
|
|
25
|
+
const modulePath = (0, core_1.normalize)('/' + (options.path) + '/' + options.module);
|
|
26
|
+
const moduleBaseName = (0, core_1.normalize)(modulePath).split('/').pop();
|
|
27
27
|
if (host.exists(modulePath)) {
|
|
28
|
-
return core_1.normalize(modulePath);
|
|
28
|
+
return (0, core_1.normalize)(modulePath);
|
|
29
29
|
}
|
|
30
30
|
else if (host.exists(modulePath + '.ts')) {
|
|
31
|
-
return core_1.normalize(modulePath + '.ts');
|
|
31
|
+
return (0, core_1.normalize)(modulePath + '.ts');
|
|
32
32
|
}
|
|
33
33
|
else if (host.exists(modulePath + '.module.ts')) {
|
|
34
|
-
return core_1.normalize(modulePath + '.module.ts');
|
|
34
|
+
return (0, core_1.normalize)(modulePath + '.module.ts');
|
|
35
35
|
}
|
|
36
36
|
else if (host.exists(modulePath + '/' + moduleBaseName + '.module.ts')) {
|
|
37
|
-
return core_1.normalize(modulePath + '/' + moduleBaseName + '.module.ts');
|
|
37
|
+
return (0, core_1.normalize)(modulePath + '/' + moduleBaseName + '.module.ts');
|
|
38
38
|
}
|
|
39
39
|
else {
|
|
40
40
|
throw new Error('Specified module does not exist');
|
|
@@ -52,7 +52,7 @@ function findModule(host, generateDir) {
|
|
|
52
52
|
while (dir) {
|
|
53
53
|
const matches = dir.subfiles.filter(p => moduleRe.test(p) && !routingModuleRe.test(p));
|
|
54
54
|
if (matches.length == 1) {
|
|
55
|
-
return core_1.join(dir.path, matches[0]);
|
|
55
|
+
return (0, core_1.join)(dir.path, matches[0]);
|
|
56
56
|
}
|
|
57
57
|
else if (matches.length > 1) {
|
|
58
58
|
throw new Error('More than one module matches. Use skip-import option to skip importing '
|
|
@@ -68,15 +68,15 @@ exports.findModule = findModule;
|
|
|
68
68
|
* Build a relative path from one file path to another file path.
|
|
69
69
|
*/
|
|
70
70
|
function buildRelativePath(from, to) {
|
|
71
|
-
from = core_1.normalize(from);
|
|
72
|
-
to = core_1.normalize(to);
|
|
71
|
+
from = (0, core_1.normalize)(from);
|
|
72
|
+
to = (0, core_1.normalize)(to);
|
|
73
73
|
// Convert to arrays.
|
|
74
74
|
const fromParts = from.split('/');
|
|
75
75
|
const toParts = to.split('/');
|
|
76
76
|
// Remove file names (preserving destination)
|
|
77
77
|
fromParts.pop();
|
|
78
78
|
const toFileName = toParts.pop();
|
|
79
|
-
const relativePath = core_1.relative(core_1.normalize(fromParts.join('/')), core_1.normalize(toParts.join('/')));
|
|
79
|
+
const relativePath = (0, core_1.relative)((0, core_1.normalize)(fromParts.join('/')), (0, core_1.normalize)(toParts.join('/')));
|
|
80
80
|
let pathPrefix = '';
|
|
81
81
|
// Set the path prefix for same dir or child dir, parent dir starts with `..`
|
|
82
82
|
if (!relativePath) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"find-module.js","sourceRoot":"","sources":["find-module.ts"],"names":[],"mappings":";;;AAAA;;;;;;GAMG;AACH,+CAAgF;AAahF;;GAEG;AACH,SAAgB,qBAAqB,CAAC,IAAU,EAAE,OAAsB;IACtE,IAAI,OAAO,CAAC,cAAc,CAAC,YAAY,CAAC,IAAI,OAAO,CAAC,UAAU,EAAE;QAC9D,OAAO,SAAS,CAAC;KAClB;IAED,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE;QACnB,MAAM,WAAW,GAAG,CAAC,OAAO,CAAC,IAAI,IAAI,EAAE,CAAC;cACpB,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAA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iBAAiB,CAAC,IAAY,EAAE,EAAU;IACxD,IAAI,GAAG,IAAA,gBAAS,EAAC,IAAI,CAAC,CAAC;IACvB,EAAE,GAAG,IAAA,gBAAS,EAAC,EAAE,CAAC,CAAC;IAEnB,qBAAqB;IACrB,MAAM,SAAS,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAClC,MAAM,OAAO,GAAG,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAE9B,6CAA6C;IAC7C,SAAS,CAAC,GAAG,EAAE,CAAC;IAChB,MAAM,UAAU,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC;IAEjC,MAAM,YAAY,GAAG,IAAA,eAAQ,EAAC,IAAA,gBAAS,EAAC,SAAS,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAA,gBAAS,EAAC,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;IAC5F,IAAI,UAAU,GAAG,EAAE,CAAC;IAEpB,6EAA6E;IAC7E,IAAI,CAAC,YAAY,EAAE;QACjB,UAAU,GAAG,GAAG,CAAC;KAClB;SAAM,IAAI,CAAC,YAAY,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE;QACxC,UAAU,GAAG,IAAI,CAAC;KACnB;IACD,IAAI,UAAU,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE;QAC3C,UAAU,IAAI,GAAG,CAAC;KACnB;IAED,OAAO,UAAU,GAAG,CAAC,YAAY,CAAC,CAAC,CAAC,YAAY,GAAG,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,GAAG,UAAU,CAAC;AAC5E,CAAC;AA1BD,8CA0BC","sourcesContent":["/**\n * @license\n * Copyright Google Inc. All Rights Reserved.\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://angular.io/license\n */\nimport { Path, join, normalize, relative, strings } from '@angular-devkit/core';\nimport { DirEntry, Tree } from '@angular-devkit/schematics';\n\n\nexport interface ModuleOptions {\n module?: string;\n name: string;\n flat?: boolean;\n path?: string;\n skipImport?: boolean;\n}\n\n\n/**\n * Find the module referred by a set of options passed to the schematics.\n */\nexport function findModuleFromOptions(host: Tree, options: ModuleOptions): Path | undefined {\n if (options.hasOwnProperty('skipImport') && options.skipImport) {\n return undefined;\n }\n\n if (!options.module) {\n const pathToCheck = (options.path || '')\n + (options.flat ? '' : '/' + strings.dasherize(options.name));\n\n return normalize(findModule(host, pathToCheck));\n } else {\n const modulePath = normalize(\n '/' + (options.path) + '/' + options.module);\n const moduleBaseName = normalize(modulePath).split('/').pop();\n\n if (host.exists(modulePath)) {\n return normalize(modulePath);\n } else if (host.exists(modulePath + '.ts')) {\n return normalize(modulePath + '.ts');\n } else if (host.exists(modulePath + '.module.ts')) {\n return normalize(modulePath + '.module.ts');\n } else if (host.exists(modulePath + '/' + moduleBaseName + '.module.ts')) {\n return normalize(modulePath + '/' + moduleBaseName + '.module.ts');\n } else {\n throw new Error('Specified module does not exist');\n }\n }\n}\n\n/**\n * Function to find the \"closest\" module to a generated file's path.\n */\nexport function findModule(host: Tree, generateDir: string): Path {\n let dir: DirEntry | null = host.getDir('/' + generateDir);\n\n const moduleRe = /\\.module\\.ts$/;\n const routingModuleRe = /-routing\\.module\\.ts/;\n\n while (dir) {\n const matches = dir.subfiles.filter(p => moduleRe.test(p) && !routingModuleRe.test(p));\n\n if (matches.length == 1) {\n return join(dir.path, matches[0]);\n } else if (matches.length > 1) {\n throw new Error('More than one module matches. Use skip-import option to skip importing '\n + 'the component into the closest module.');\n }\n\n dir = dir.parent;\n }\n\n throw new Error('Could not find an NgModule. Use the skip-import '\n + 'option to skip importing in NgModule.');\n}\n\n/**\n * Build a relative path from one file path to another file path.\n */\nexport function buildRelativePath(from: string, to: string): string {\n from = normalize(from);\n to = normalize(to);\n\n // Convert to arrays.\n const fromParts = from.split('/');\n const toParts = to.split('/');\n\n // Remove file names (preserving destination)\n fromParts.pop();\n const toFileName = toParts.pop();\n\n const relativePath = relative(normalize(fromParts.join('/')), normalize(toParts.join('/')));\n let pathPrefix = '';\n\n // Set the path prefix for same dir or child dir, parent dir starts with `..`\n if (!relativePath) {\n pathPrefix = '.';\n } else if (!relativePath.startsWith('.')) {\n pathPrefix = `./`;\n }\n if (pathPrefix && !pathPrefix.endsWith('/')) {\n pathPrefix += '/';\n }\n\n return pathPrefix + (relativePath ? relativePath + '/' : '') + toFileName;\n}\n"]}
|
|
@@ -20,11 +20,11 @@ function findBootstrapModuleCall(host, mainPath) {
|
|
|
20
20
|
}
|
|
21
21
|
const mainText = mainBuffer.toString('utf-8');
|
|
22
22
|
const source = ts.createSourceFile(mainPath, mainText, ts.ScriptTarget.Latest, true);
|
|
23
|
-
const allNodes = ast_utils_1.getSourceNodes(source);
|
|
23
|
+
const allNodes = (0, ast_utils_1.getSourceNodes)(source);
|
|
24
24
|
let bootstrapCall = null;
|
|
25
25
|
for (const node of allNodes) {
|
|
26
26
|
let bootstrapCallNode = null;
|
|
27
|
-
bootstrapCallNode = ast_utils_1.findNode(node, ts.SyntaxKind.Identifier, 'bootstrapModule');
|
|
27
|
+
bootstrapCallNode = (0, ast_utils_1.findNode)(node, ts.SyntaxKind.Identifier, 'bootstrapModule');
|
|
28
28
|
// Walk up the parent until CallExpression is found.
|
|
29
29
|
while (bootstrapCallNode && bootstrapCallNode.parent
|
|
30
30
|
&& bootstrapCallNode.parent.kind !== ts.SyntaxKind.CallExpression) {
|
|
@@ -52,11 +52,11 @@ function findBootstrapModulePath(host, mainPath) {
|
|
|
52
52
|
}
|
|
53
53
|
const mainText = mainBuffer.toString('utf-8');
|
|
54
54
|
const source = ts.createSourceFile(mainPath, mainText, ts.ScriptTarget.Latest, true);
|
|
55
|
-
const allNodes = ast_utils_1.getSourceNodes(source);
|
|
55
|
+
const allNodes = (0, ast_utils_1.getSourceNodes)(source);
|
|
56
56
|
const bootstrapModuleRelativePath = allNodes
|
|
57
57
|
.filter(node => node.kind === ts.SyntaxKind.ImportDeclaration)
|
|
58
58
|
.filter(imp => {
|
|
59
|
-
return ast_utils_1.findNode(imp, ts.SyntaxKind.Identifier, bootstrapModule.getText());
|
|
59
|
+
return (0, ast_utils_1.findNode)(imp, ts.SyntaxKind.Identifier, bootstrapModule.getText());
|
|
60
60
|
})
|
|
61
61
|
.map((imp) => {
|
|
62
62
|
const modulePathStringLiteral = imp.moduleSpecifier;
|
|
@@ -67,8 +67,8 @@ function findBootstrapModulePath(host, mainPath) {
|
|
|
67
67
|
exports.findBootstrapModulePath = findBootstrapModulePath;
|
|
68
68
|
function getAppModulePath(host, mainPath) {
|
|
69
69
|
const moduleRelativePath = findBootstrapModulePath(host, mainPath);
|
|
70
|
-
const mainDir = path_1.dirname(mainPath);
|
|
71
|
-
const modulePath = core_1.normalize(`/${mainDir}/${moduleRelativePath}.ts`);
|
|
70
|
+
const mainDir = (0, path_1.dirname)(mainPath);
|
|
71
|
+
const modulePath = (0, core_1.normalize)(`/${mainDir}/${moduleRelativePath}.ts`);
|
|
72
72
|
return modulePath;
|
|
73
73
|
}
|
|
74
74
|
exports.getAppModulePath = getAppModulePath;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ng-ast-utils.js","sourceRoot":"","sources":["ng-ast-utils.ts"],"names":[],"mappings":";;;AAAA;;;;;;GAMG;AACH,+CAAiD;AACjD,2DAAuE;AACvE,+BAA+B;AAC/B,iCAAiC;AACjC,2CAAuD;AAEvD,SAAgB,uBAAuB,CAAC,IAAU,EAAE,QAAgB;IAClE,MAAM,UAAU,GAAG,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IACvC,IAAI,CAAC,UAAU,EAAE;QACf,MAAM,IAAI,gCAAmB,CAAC,cAAc,QAAQ,aAAa,CAAC,CAAC;KACpE;IACD,MAAM,QAAQ,GAAG,UAAU,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;IAC9C,MAAM,MAAM,GAAG,EAAE,CAAC,gBAAgB,CAAC,QAAQ,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E,CAAC,CAAC;SACD,GAAG,CAAC,CAAC,GAAyB,EAAE,EAAE;QACjC,MAAM,uBAAuB,GAAsB,GAAG,CAAC,eAAe,CAAC;QAEvE,OAAO,uBAAuB,CAAC,IAAI,CAAC;IACtC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAER,OAAO,2BAA2B,CAAC;AACrC,CAAC;AA3BD,0DA2BC;AAED,SAAgB,gBAAgB,CAAC,IAAU,EAAE,QAAgB;IAC3D,MAAM,kBAAkB,GAAG,uBAAuB,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;IACnE,MAAM,OAAO,GAAG,IAAA,cAAO,EAAC,QAAQ,CAAC,CAAC;IAClC,MAAM,UAAU,GAAG,IAAA,gBAAS,EAAC,IAAI,OAAO,IAAI,kBAAkB,KAAK,CAAC,CAAC;IAErE,OAAO,UAAU,CAAC;AACpB,CAAC;AAND,4CAMC","sourcesContent":["/**\n * @license\n * Copyright Google Inc. All Rights Reserved.\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://angular.io/license\n */\nimport { normalize } from '@angular-devkit/core';\nimport { SchematicsException, Tree } from '@angular-devkit/schematics';\nimport { dirname } from 'path';\nimport * as ts from 'typescript';\nimport { findNode, getSourceNodes } from './ast-utils';\n\nexport function findBootstrapModuleCall(host: Tree, mainPath: string): ts.CallExpression | null {\n const mainBuffer = host.read(mainPath);\n if (!mainBuffer) {\n throw new SchematicsException(`Main file (${mainPath}) not found`);\n }\n const mainText = mainBuffer.toString('utf-8');\n const source = ts.createSourceFile(mainPath, mainText, ts.ScriptTarget.Latest, true);\n\n const allNodes = getSourceNodes(source);\n\n let bootstrapCall: ts.CallExpression | null = null;\n\n for (const node of allNodes) {\n\n let bootstrapCallNode: ts.Node | null = null;\n bootstrapCallNode = findNode(node, ts.SyntaxKind.Identifier, 'bootstrapModule');\n\n // Walk up the parent until CallExpression is found.\n while (bootstrapCallNode && bootstrapCallNode.parent\n && bootstrapCallNode.parent.kind !== ts.SyntaxKind.CallExpression) {\n\n bootstrapCallNode = bootstrapCallNode.parent;\n }\n\n if (bootstrapCallNode !== null &&\n bootstrapCallNode.parent !== undefined &&\n bootstrapCallNode.parent.kind === ts.SyntaxKind.CallExpression) {\n bootstrapCall = bootstrapCallNode.parent as ts.CallExpression;\n break;\n }\n }\n\n return bootstrapCall;\n}\n\nexport function findBootstrapModulePath(host: Tree, mainPath: string): string {\n const bootstrapCall = findBootstrapModuleCall(host, mainPath);\n if (!bootstrapCall) {\n throw new SchematicsException('Bootstrap call not found');\n }\n\n const bootstrapModule = bootstrapCall.arguments[0];\n\n const mainBuffer = host.read(mainPath);\n if (!mainBuffer) {\n throw new SchematicsException(`Client app main file (${mainPath}) not found`);\n }\n const mainText = mainBuffer.toString('utf-8');\n const source = ts.createSourceFile(mainPath, mainText, ts.ScriptTarget.Latest, true);\n const allNodes = getSourceNodes(source);\n const bootstrapModuleRelativePath = allNodes\n .filter(node => node.kind === ts.SyntaxKind.ImportDeclaration)\n .filter(imp => {\n return findNode(imp, ts.SyntaxKind.Identifier, bootstrapModule.getText());\n })\n .map((imp: ts.ImportDeclaration) => {\n const modulePathStringLiteral = <ts.StringLiteral> imp.moduleSpecifier;\n\n return modulePathStringLiteral.text;\n })[0];\n\n return bootstrapModuleRelativePath;\n}\n\nexport function getAppModulePath(host: Tree, mainPath: string): string {\n const moduleRelativePath = findBootstrapModulePath(host, mainPath);\n const mainDir = dirname(mainPath);\n const modulePath = normalize(`/${mainDir}/${moduleRelativePath}.ts`);\n\n return modulePath;\n}\n"]}
|
|
@@ -10,11 +10,11 @@ exports.parseName = void 0;
|
|
|
10
10
|
*/
|
|
11
11
|
const core_1 = require("@angular-devkit/core");
|
|
12
12
|
function parseName(path, name) {
|
|
13
|
-
const nameWithoutPath = core_1.basename(name);
|
|
14
|
-
const namePath = core_1.dirname((path + '/' + name));
|
|
13
|
+
const nameWithoutPath = (0, core_1.basename)(name);
|
|
14
|
+
const namePath = (0, core_1.dirname)((path + '/' + name));
|
|
15
15
|
return {
|
|
16
16
|
name: nameWithoutPath,
|
|
17
|
-
path: core_1.normalize('/' + namePath),
|
|
17
|
+
path: (0, core_1.normalize)('/' + namePath),
|
|
18
18
|
};
|
|
19
19
|
}
|
|
20
20
|
exports.parseName = parseName;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parse-name.js","sourceRoot":"","sources":["parse-name.ts"],"names":[],"mappings":";;;AACA;;;;;;GAMG;AACH,+CAA0E;AAO1E,SAAgB,SAAS,CAAC,IAAY,EAAE,IAAY;IAClD,MAAM,eAAe,GAAG,eAAQ,
|
|
1
|
+
{"version":3,"file":"parse-name.js","sourceRoot":"","sources":["parse-name.ts"],"names":[],"mappings":";;;AACA;;;;;;GAMG;AACH,+CAA0E;AAO1E,SAAgB,SAAS,CAAC,IAAY,EAAE,IAAY;IAClD,MAAM,eAAe,GAAG,IAAA,eAAQ,EAAC,IAAY,CAAC,CAAC;IAC/C,MAAM,QAAQ,GAAG,IAAA,cAAO,EAAC,CAAC,IAAI,GAAG,GAAG,GAAG,IAAI,CAAS,CAAC,CAAC;IAEtD,OAAO;QACL,IAAI,EAAE,eAAe;QACrB,IAAI,EAAE,IAAA,gBAAS,EAAC,GAAG,GAAG,QAAQ,CAAC;KAChC,CAAC;AACJ,CAAC;AARD,8BAQC","sourcesContent":["\n/**\n * @license\n * Copyright Google Inc. All Rights Reserved.\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://angular.io/license\n */\nimport { Path, basename, dirname, normalize } from '@angular-devkit/core';\n\nexport interface Location {\n name: string;\n path: Path;\n}\n\nexport function parseName(path: string, name: string): Location {\n const nameWithoutPath = basename(name as Path);\n const namePath = dirname((path + '/' + name) as Path);\n\n return {\n name: nameWithoutPath,\n path: normalize('/' + namePath),\n };\n}\n"]}
|
|
@@ -23,7 +23,7 @@ const schematics_1 = require("@angular-devkit/schematics");
|
|
|
23
23
|
*/
|
|
24
24
|
function insertImport2(source, fileToEdit, symbolName, asSymbolName, fileName, isDefault = false) {
|
|
25
25
|
const rootNode = source;
|
|
26
|
-
const allImports = ast_utils_1.findNodes(rootNode, ts.SyntaxKind.ImportDeclaration);
|
|
26
|
+
const allImports = (0, ast_utils_1.findNodes)(rootNode, ts.SyntaxKind.ImportDeclaration);
|
|
27
27
|
// get nodes that map to import statements from the file fileName
|
|
28
28
|
const relevantImports = allImports.filter(node => {
|
|
29
29
|
// StringLiteral of the ImportDeclaration is the import file (fileName in this case).
|
|
@@ -37,8 +37,8 @@ function insertImport2(source, fileToEdit, symbolName, asSymbolName, fileName, i
|
|
|
37
37
|
// imports from import file
|
|
38
38
|
const imports = [];
|
|
39
39
|
relevantImports.forEach(n => {
|
|
40
|
-
Array.prototype.push.apply(imports, ast_utils_1.findNodes(n, ts.SyntaxKind.Identifier));
|
|
41
|
-
if (ast_utils_1.findNodes(n, ts.SyntaxKind.AsteriskToken).length > 0) {
|
|
40
|
+
Array.prototype.push.apply(imports, (0, ast_utils_1.findNodes)(n, ts.SyntaxKind.Identifier));
|
|
41
|
+
if ((0, ast_utils_1.findNodes)(n, ts.SyntaxKind.AsteriskToken).length > 0) {
|
|
42
42
|
importsAsterisk = true;
|
|
43
43
|
}
|
|
44
44
|
});
|
|
@@ -49,14 +49,14 @@ function insertImport2(source, fileToEdit, symbolName, asSymbolName, fileName, i
|
|
|
49
49
|
const importTextNodes = imports.filter(n => n.text === symbolName);
|
|
50
50
|
// insert import if it's not there
|
|
51
51
|
if (importTextNodes.length === 0) {
|
|
52
|
-
const fallbackPos = ast_utils_1.findNodes(relevantImports[0], ts.SyntaxKind.CloseBraceToken)[0].getStart() ||
|
|
53
|
-
ast_utils_1.findNodes(relevantImports[0], ts.SyntaxKind.FromKeyword)[0].getStart();
|
|
54
|
-
return ast_utils_1.insertAfterLastOccurrence(imports, `, ${symbolName} as ${asSymbolName}`, fileToEdit, fallbackPos);
|
|
52
|
+
const fallbackPos = (0, ast_utils_1.findNodes)(relevantImports[0], ts.SyntaxKind.CloseBraceToken)[0].getStart() ||
|
|
53
|
+
(0, ast_utils_1.findNodes)(relevantImports[0], ts.SyntaxKind.FromKeyword)[0].getStart();
|
|
54
|
+
return (0, ast_utils_1.insertAfterLastOccurrence)(imports, `, ${symbolName} as ${asSymbolName}`, fileToEdit, fallbackPos);
|
|
55
55
|
}
|
|
56
56
|
return new change_1.NoopChange();
|
|
57
57
|
}
|
|
58
58
|
// no such import declaration exists
|
|
59
|
-
const useStrict = ast_utils_1.findNodes(rootNode, ts.SyntaxKind.StringLiteral)
|
|
59
|
+
const useStrict = (0, ast_utils_1.findNodes)(rootNode, ts.SyntaxKind.StringLiteral)
|
|
60
60
|
.filter((n) => n.text === 'use strict');
|
|
61
61
|
let fallbackPos = 0;
|
|
62
62
|
if (useStrict.length > 0) {
|
|
@@ -69,12 +69,12 @@ function insertImport2(source, fileToEdit, symbolName, asSymbolName, fileName, i
|
|
|
69
69
|
const separator = insertAtBeginning ? '' : ';\n';
|
|
70
70
|
const toInsert = `${separator}import ${open}${symbolName} as ${asSymbolName}${close}` +
|
|
71
71
|
` from '${fileName}'${insertAtBeginning ? ';\n' : ''}`;
|
|
72
|
-
return ast_utils_1.insertAfterLastOccurrence(allImports, toInsert, fileToEdit, fallbackPos, ts.SyntaxKind.StringLiteral);
|
|
72
|
+
return (0, ast_utils_1.insertAfterLastOccurrence)(allImports, toInsert, fileToEdit, fallbackPos, ts.SyntaxKind.StringLiteral);
|
|
73
73
|
}
|
|
74
74
|
exports.insertImport2 = insertImport2;
|
|
75
75
|
function insertImport(source, fileToEdit, symbolName, fileName, isDefault = false) {
|
|
76
76
|
const rootNode = source;
|
|
77
|
-
const allImports = ast_utils_1.findNodes(rootNode, ts.SyntaxKind.ImportDeclaration);
|
|
77
|
+
const allImports = (0, ast_utils_1.findNodes)(rootNode, ts.SyntaxKind.ImportDeclaration);
|
|
78
78
|
// get nodes that map to import statements from the file fileName
|
|
79
79
|
const relevantImports = allImports.filter(node => {
|
|
80
80
|
// StringLiteral of the ImportDeclaration is the import file (fileName in this case).
|
|
@@ -88,8 +88,8 @@ function insertImport(source, fileToEdit, symbolName, fileName, isDefault = fals
|
|
|
88
88
|
// imports from import file
|
|
89
89
|
const imports = [];
|
|
90
90
|
relevantImports.forEach(n => {
|
|
91
|
-
Array.prototype.push.apply(imports, ast_utils_1.findNodes(n, ts.SyntaxKind.Identifier));
|
|
92
|
-
if (ast_utils_1.findNodes(n, ts.SyntaxKind.AsteriskToken).length > 0) {
|
|
91
|
+
Array.prototype.push.apply(imports, (0, ast_utils_1.findNodes)(n, ts.SyntaxKind.Identifier));
|
|
92
|
+
if ((0, ast_utils_1.findNodes)(n, ts.SyntaxKind.AsteriskToken).length > 0) {
|
|
93
93
|
importsAsterisk = true;
|
|
94
94
|
}
|
|
95
95
|
});
|
|
@@ -100,14 +100,14 @@ function insertImport(source, fileToEdit, symbolName, fileName, isDefault = fals
|
|
|
100
100
|
const importTextNodes = imports.filter(n => n.text === symbolName);
|
|
101
101
|
// insert import if it's not there
|
|
102
102
|
if (importTextNodes.length === 0) {
|
|
103
|
-
const fallbackPos = ast_utils_1.findNodes(relevantImports[0], ts.SyntaxKind.CloseBraceToken)[0].getStart() ||
|
|
104
|
-
ast_utils_1.findNodes(relevantImports[0], ts.SyntaxKind.FromKeyword)[0].getStart();
|
|
105
|
-
return ast_utils_1.insertAfterLastOccurrence(imports, `, ${symbolName}`, fileToEdit, fallbackPos);
|
|
103
|
+
const fallbackPos = (0, ast_utils_1.findNodes)(relevantImports[0], ts.SyntaxKind.CloseBraceToken)[0].getStart() ||
|
|
104
|
+
(0, ast_utils_1.findNodes)(relevantImports[0], ts.SyntaxKind.FromKeyword)[0].getStart();
|
|
105
|
+
return (0, ast_utils_1.insertAfterLastOccurrence)(imports, `, ${symbolName}`, fileToEdit, fallbackPos);
|
|
106
106
|
}
|
|
107
107
|
return new change_1.NoopChange();
|
|
108
108
|
}
|
|
109
109
|
// no such import declaration exists
|
|
110
|
-
const useStrict = ast_utils_1.findNodes(rootNode, ts.SyntaxKind.StringLiteral)
|
|
110
|
+
const useStrict = (0, ast_utils_1.findNodes)(rootNode, ts.SyntaxKind.StringLiteral)
|
|
111
111
|
.filter((n) => n.text === 'use strict');
|
|
112
112
|
let fallbackPos = 0;
|
|
113
113
|
if (useStrict.length > 0) {
|
|
@@ -120,7 +120,7 @@ function insertImport(source, fileToEdit, symbolName, fileName, isDefault = fals
|
|
|
120
120
|
const separator = insertAtBeginning ? '' : ';\n';
|
|
121
121
|
const toInsert = `${separator}import ${open}${symbolName}${close}` +
|
|
122
122
|
` from '${fileName}'${insertAtBeginning ? ';\n' : ''}`;
|
|
123
|
-
return ast_utils_1.insertAfterLastOccurrence(allImports, toInsert, fileToEdit, fallbackPos, ts.SyntaxKind.StringLiteral);
|
|
123
|
+
return (0, ast_utils_1.insertAfterLastOccurrence)(allImports, toInsert, fileToEdit, fallbackPos, ts.SyntaxKind.StringLiteral);
|
|
124
124
|
}
|
|
125
125
|
exports.insertImport = insertImport;
|
|
126
126
|
function getSourceFile(host, path) {
|