1 | "use strict";
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports.name = exports.description = void 0;
|
7 | exports.run = run;
|
8 | exports.setup = setup;
|
9 |
|
10 | var _chalk = _interopRequireDefault(require("chalk"));
|
11 |
|
12 | var _node = require("../lib/node");
|
13 |
|
14 | var _npmLibDefs = require("../lib/npm/npmLibDefs");
|
15 |
|
16 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
17 |
|
18 | const name = 'validate-defs <definitionsDirPath>';
|
19 | exports.name = name;
|
20 | const description = 'Validate the structure of the /definitions dir';
|
21 | exports.description = description;
|
22 |
|
23 | function setup(yargs) {
|
24 | return yargs.positional('definitionsDirPath', {
|
25 | describe: 'Please specify the path of the /definitions directory to be validated ' + 'as the first arg of this command.',
|
26 | type: 'string'
|
27 | });
|
28 | }
|
29 |
|
30 | async function run(args) {
|
31 | const defsDirPath = args.definitionsDirPath;
|
32 |
|
33 | if (typeof defsDirPath !== 'string') {
|
34 | throw new Error('definitionsDirPath should be a string');
|
35 | }
|
36 |
|
37 | if (!(await _node.fs.exists(defsDirPath))) {
|
38 | console.error('Error: Path does not exist: %s', defsDirPath);
|
39 | return 1;
|
40 | }
|
41 |
|
42 | const defsDirPathStat = await _node.fs.stat(defsDirPath);
|
43 |
|
44 | if (!defsDirPathStat.isDirectory()) {
|
45 | console.error('Error: Path is not a directory: %s', defsDirPath);
|
46 | return 1;
|
47 | }
|
48 |
|
49 | try {
|
50 | console.log(_chalk.default.green(`Validating all definitions from \`${defsDirPath}\``));
|
51 | const npmLibDefs = await (0, _npmLibDefs.getNpmLibDefs)(defsDirPath, true);
|
52 | console.log('All libdefs are named and structured correctly. ' + `(Found ${npmLibDefs.length})`);
|
53 | return 0;
|
54 | } catch (errors) {
|
55 | if (Array.isArray(errors)) {
|
56 | errors.forEach(error => {
|
57 | console.log(' • ' + error.message);
|
58 | });
|
59 | return 1;
|
60 | } else {
|
61 | throw errors;
|
62 | }
|
63 | }
|
64 | } |
\ | No newline at end of file |