1 | "use strict";
|
2 | const fs = require('fs');
|
3 | const path = require('path');
|
4 | const SilentError = require('silent-error');
|
5 | function findParentModule(project, currentDir) {
|
6 | const sourceRoot = path.join(project.root, project.ngConfig.apps[0].root, 'app');
|
7 |
|
8 | currentDir = currentDir.replace(path.join(project.ngConfig.apps[0].root, 'app'), '');
|
9 | let pathToCheck = path.join(sourceRoot, currentDir);
|
10 | while (pathToCheck.length >= sourceRoot.length) {
|
11 |
|
12 | const files = fs.readdirSync(pathToCheck)
|
13 | .filter(fileName => !fileName.endsWith('routing.module.ts'))
|
14 | .filter(fileName => fileName.endsWith('.module.ts'))
|
15 | .filter(fileName => 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 |
|
23 | pathToCheck = path.dirname(pathToCheck);
|
24 | }
|
25 | throw new SilentError('No module files found');
|
26 | }
|
27 | Object.defineProperty(exports, "__esModule", { value: true });
|
28 | exports.default = findParentModule;
|
29 | ;
|
30 |
|
\ | No newline at end of file |