UNPKG

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