UNPKG

7.21 kBSource Map (JSON)View Raw
1{"version":3,"file":"find-component.js","sourceRoot":"","sources":["../../../../../modules/store/schematics-core/utility/find-component.ts"],"names":[],"mappings":";;;AAAA;;;;;;GAMG;AACH,6CAS8B;AAW9B;;GAEG;AACH,SAAgB,wBAAwB,CACtC,IAAU,EACV,OAAyB;IAEzB,IAAI,OAAO,CAAC,cAAc,CAAC,YAAY,CAAC,IAAI,OAAO,CAAC,UAAU,EAAE;QAC9D,OAAO,SAAS,CAAC;KAClB;IAED,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE;QACtB,IAAM,WAAW,GACf,CAAC,OAAO,CAAC,IAAI,IAAI,EAAE,CAAC;YACpB,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,GAAG,cAAO,CAAC,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC;QAE9D,OAAO,gBAAS,CAAC,aAAa,CAAC,IAAI,EAAE,WAAW,CAAC,CAAC,CAAC;KACpD;SAAM;QACL,IAAM,aAAa,GAAG,gBAAS,CAC7B,GAAG,GAAG,OAAO,CAAC,IAAI,GAAG,GAAG,GAAG,OAAO,CAAC,SAAS,CAC7C,CAAC;QACF,IAAM,iBAAiB,GAAG,gBAAS,CAAC,aAAa,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,CAAC;QAEpE,IAAI,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,EAAE;YAC9B,OAAO,gBAAS,CAAC,aAAa,CAAC,CAAC;SACjC;aAAM,IAAI,IAAI,CAAC,MAAM,CAAC,aAAa,GAAG,KAAK,CAAC,EAAE;YAC7C,OAAO,gBAAS,CAAC,aAAa,GAAG,KAAK,CAAC,CAAC;SACzC;aAAM,IAAI,IAAI,CAAC,MAAM,CAAC,aAAa,GAAG,eAAe,CAAC,EAAE;YACvD,OAAO,gBAAS,CAAC,aAAa,GAAG,eAAe,CAAC,CAAC;S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EAHT,MAAM,UAAA,EACF,UAAU,cAAA,EACT,WAAW,eACP,CAAC;IAClB,IAAM,YAAY,GAAG,eAAQ,CAAC,aAAa,EAAE,WAAW,CAAC,CAAC;IAC1D,IAAM,iBAAiB,GAAG,YAAY,CAAC,UAAU,CAAC,GAAG,CAAC;QACpD,CAAC,CAAC,YAAY;QACd,CAAC,CAAC,OAAK,YAAc,CAAC;IAExB,OAAO,CAAC,UAAU,IAAI,UAAU,KAAK,UAAU;QAC7C,CAAC,CAAC,iBAAiB;QACnB,CAAC,CAAC,MACE,iBAAiB,CAAC,QAAQ,CAAC,GAAG,CAAC;YAC7B,CAAC,CAAC,iBAAiB;YACnB,CAAC,CAAC,iBAAiB,GAAG,GAAG,IAC1B,2BAA2B,CAAC,UAAU,CAAG,CAAC;AACnD,CAAC;AAvBD,8CAuBC;AAED,SAAS,SAAS,CAAC,IAAY;IAC7B,IAAM,cAAc,GAAG,gBAAS,CAAC,IAAI,CAAS,CAAC;IAC/C,IAAM,QAAQ,GAAG,cAAO,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,eAAQ,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;IACzE,IAAM,SAAS,GAAG,QAAQ,CAAC,CAAC,CAAC,cAAO,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,cAAc,CAAC;IACtE,OAAO;QACL,IAAI,EAAE,cAAc;QACpB,QAAQ,UAAA;QACR,SAAS,WAAA;KACV,CAAC;AACJ,CAAC;AACD;;;;GAIG;AACH,SAAS,2BAA2B,CAAC,QAA4B;IAC/D,OAAO,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,qBAAqB,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;AACrE,CAAC","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 {\n Path,\n join,\n normalize,\n relative,\n strings,\n basename,\n extname,\n dirname,\n} from '@angular-devkit/core';\nimport { DirEntry, Tree } from '@angular-devkit/schematics';\n\nexport interface ComponentOptions {\n component?: string;\n name: string;\n flat?: boolean;\n path?: string;\n skipImport?: boolean;\n}\n\n/**\n * Find the component referred by a set of options passed to the schematics.\n */\nexport function findComponentFromOptions(\n host: Tree,\n options: ComponentOptions\n): Path | undefined {\n if (options.hasOwnProperty('skipImport') && options.skipImport) {\n return undefined;\n }\n\n if (!options.component) {\n const pathToCheck =\n (options.path || '') +\n (options.flat ? '' : '/' + strings.dasherize(options.name));\n\n return normalize(findComponent(host, pathToCheck));\n } else {\n const componentPath = normalize(\n '/' + options.path + '/' + options.component\n );\n const componentBaseName = normalize(componentPath).split('/').pop();\n\n if (host.exists(componentPath)) {\n return normalize(componentPath);\n } else if (host.exists(componentPath + '.ts')) {\n return normalize(componentPath + '.ts');\n } else if (host.exists(componentPath + '.component.ts')) {\n return normalize(componentPath + '.component.ts');\n } else if (\n host.exists(componentPath + '/' + componentBaseName + '.component.ts')\n ) {\n return normalize(\n componentPath + '/' + componentBaseName + '.component.ts'\n );\n } else {\n throw new Error(\n `Specified component path ${componentPath} does not exist`\n );\n }\n }\n}\n\n/**\n * Function to find the \"closest\" component to a generated file's path.\n */\nexport function findComponent(host: Tree, generateDir: string): Path {\n let dir: DirEntry | null = host.getDir('/' + generateDir);\n\n const componentRe = /\\.component\\.ts$/;\n\n while (dir) {\n const matches = dir.subfiles.filter((p) => componentRe.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(\n 'More than one component matches. Use skip-import option to skip importing ' +\n 'the component store into the closest component.'\n );\n }\n\n dir = dir.parent;\n }\n\n throw new Error(\n 'Could not find an Component. Use the skip-import ' +\n 'option to skip importing in Component.'\n );\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 const {\n path: fromPath,\n filename: fromFileName,\n directory: fromDirectory,\n } = parsePath(from);\n const {\n path: toPath,\n filename: toFileName,\n directory: toDirectory,\n } = parsePath(to);\n const relativePath = relative(fromDirectory, toDirectory);\n const fixedRelativePath = relativePath.startsWith('.')\n ? relativePath\n : `./${relativePath}`;\n\n return !toFileName || toFileName === 'index.ts'\n ? fixedRelativePath\n : `${\n fixedRelativePath.endsWith('/')\n ? fixedRelativePath\n : fixedRelativePath + '/'\n }${convertToTypeScriptFileName(toFileName)}`;\n}\n\nfunction parsePath(path: string) {\n const pathNormalized = normalize(path) as Path;\n const filename = extname(pathNormalized) ? basename(pathNormalized) : '';\n const directory = filename ? dirname(pathNormalized) : pathNormalized;\n return {\n path: pathNormalized,\n filename,\n directory,\n };\n}\n/**\n * Strips the typescript extension and clears index filenames\n * foo.ts -> foo\n * index.ts -> empty\n */\nfunction convertToTypeScriptFileName(filename: string | undefined) {\n return filename ? filename.replace(/(\\.ts)|(index\\.ts)$/, '') : '';\n}\n"]}
\No newline at end of file