Skip to content

Commit 1b63dfb

Browse files
committed
fix(app): handle package.json file not available
1 parent 95eba20 commit 1b63dfb

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

src/index.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,20 @@ import * as path from 'path';
33
import * as fs from 'fs';
44
import * as program from 'commander';
55
import { fork } from 'child_process';
6+
import * as chalk from 'chalk';
67
const forked = fork(path.join(__dirname, './worker.js'));
7-
const projectProject = require(path.join('..', 'package.json'));
8-
const userProjectPackage = require(path.join(process.cwd(), 'package.json'));
8+
let projectProject;
9+
let userProjectPackage;
10+
try {
11+
projectProject = require(path.join('..', 'package.json'));
12+
} catch (e) {
13+
console.log(chalk.red('Could not read project package.json file.'));
14+
}
15+
try {
16+
userProjectPackage = require(path.join(process.cwd(), 'package.json'));
17+
} catch (e) {
18+
console.log(chalk.red('Could not read user project package.json file.'));
19+
}
920

1021
const AVAILABLE_STATS = ['decorators', 'classes', 'interfaces', 'imports', 'exports', 'specs', 'loc', 'files'];
1122

0 commit comments

Comments
 (0)