1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | const fs = require("fs");
|
4 | const path = require("path");
|
5 | const SilentError = require('silent-error');
|
6 | function findParentModule(projectRoot, appRoot, currentDir) {
|
7 | const sourceRoot = path.join(projectRoot, appRoot, 'app');
|
8 |
|
9 | currentDir = currentDir.replace(path.join(appRoot, 'app'), '');
|
10 | let pathToCheck = path.join(sourceRoot, currentDir);
|
11 | while (pathToCheck.length >= sourceRoot.length) {
|
12 |
|
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 |
|
24 | pathToCheck = path.dirname(pathToCheck);
|
25 | }
|
26 | throw new SilentError('No module files found');
|
27 | }
|
28 | exports.default = findParentModule;
|
29 | ;
|
30 |
|
\ | No newline at end of file |