UNPKG

1.36 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3const fs = require("fs");
4const path = require("path");
5const SilentError = require('silent-error');
6function findParentModule(projectRoot, appRoot, currentDir) {
7 const sourceRoot = path.join(projectRoot, appRoot, 'app');
8 // trim currentDir
9 currentDir = currentDir.replace(path.join(appRoot, 'app'), '');
10 let pathToCheck = path.join(sourceRoot, currentDir);
11 while (pathToCheck.length >= sourceRoot.length) {
12 // TODO: refactor to not be based upon file name
13 const files = fs.readdirSync(pathToCheck)
14 .filter(fileName => !fileName.endsWith('routing.module.ts'))
15 .filter(fileName => fileName.endsWith('.module.ts'))
16 .filter(fileName => fs.statSync(path.join(pathToCheck, fileName)).isFile());
17 if (files.length === 1) {
18 return path.join(pathToCheck, files[0]);
19 }
20 else if (files.length > 1) {
21 throw new SilentError(`Multiple module files found: ${pathToCheck.replace(sourceRoot, '')}`);
22 }
23 // move to parent directory
24 pathToCheck = path.dirname(pathToCheck);
25 }
26 throw new SilentError('No module files found');
27}
28exports.default = findParentModule;
29;
30//# sourceMappingURL=/users/hans/sources/angular-cli/utilities/find-parent-module.js.map
\No newline at end of file