1 | 'use strict';
|
2 |
|
3 | import fs = require('fs');
|
4 | import path = require('path');
|
5 |
|
6 |
|
7 | (function findRoot(pth: string) : void {
|
8 |
|
9 | let possiblePkgDotJsonPath = path.resolve(String(pth) + '/package.json');
|
10 |
|
11 | try {
|
12 | fs.statSync(possiblePkgDotJsonPath).isFile();
|
13 | console.log(pth);
|
14 | process.exit(0);
|
15 | }
|
16 | catch (err) {
|
17 | let subPath = path.resolve(String(pth) + '/../');
|
18 | if (subPath === pth) {
|
19 | console.error(' => Cannot find path to project root.');
|
20 | process.exit(1);
|
21 | }
|
22 | else {
|
23 | return findRoot(subPath);
|
24 | }
|
25 | }
|
26 |
|
27 | })(process.cwd());
|