1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 | 'use strict';
|
9 |
|
10 | const assert = require('assert');
|
11 | const fs = require('fs');
|
12 | const path = require('path');
|
13 |
|
14 | const EXTRACT_MODULE_NAME_REGEX = /'\.\/(.+)'/;
|
15 |
|
16 | let didError = false;
|
17 |
|
18 |
|
19 | assert(
|
20 | process.argv.length >= 3,
|
21 | 'Expected to receive an argument to a lib directory'
|
22 | );
|
23 |
|
24 | const pathToLib = path.resolve(process.cwd(), process.argv[2]);
|
25 |
|
26 | fs.readdir(pathToLib, (err, files) => {
|
27 | files = files.filter((filename) => path.parse(filename).ext === '.js');
|
28 |
|
29 | files.forEach((filename) => {
|
30 | const requirePath = path.join(pathToLib, filename);
|
31 | const moduleName = path.parse(filename).name;
|
32 |
|
33 | try {
|
34 | require(requirePath);
|
35 | } catch (e) {
|
36 | if (e.code === 'MODULE_NOT_FOUND') {
|
37 | const missingModule = e.toString().match(EXTRACT_MODULE_NAME_REGEX)[1];
|
38 | console.error(moduleName, 'is missing a dependency:', missingModule);
|
39 | } else {
|
40 | console.error('UNKNOWN ERROR', e);
|
41 | }
|
42 | didError = true;
|
43 | }
|
44 | });
|
45 |
|
46 | process.exit(didError ? 1 : 0);
|
47 | });
|