flow-typed
Version:
A repository of high quality flow type definitions
64 lines (51 loc) • 1.82 kB
JavaScript
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.name = exports.description = void 0;
exports.run = run;
exports.setup = setup;
var _chalk = _interopRequireDefault(require("chalk"));
var _node = require("../lib/node");
var _npmLibDefs = require("../lib/npm/npmLibDefs");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
const name = 'validate-defs <definitionsDirPath>';
exports.name = name;
const description = 'Validate the structure of the /definitions dir';
exports.description = description;
function setup(yargs) {
return yargs.positional('definitionsDirPath', {
describe: 'Please specify the path of the /definitions directory to be validated ' + 'as the first arg of this command.',
type: 'string'
});
}
async function run(args) {
const defsDirPath = args.definitionsDirPath;
if (typeof defsDirPath !== 'string') {
throw new Error('definitionsDirPath should be a string');
}
if (!(await _node.fs.exists(defsDirPath))) {
console.error('Error: Path does not exist: %s', defsDirPath);
return 1;
}
const defsDirPathStat = await _node.fs.stat(defsDirPath);
if (!defsDirPathStat.isDirectory()) {
console.error('Error: Path is not a directory: %s', defsDirPath);
return 1;
}
try {
console.log(_chalk.default.green(`Validating all definitions from \`${defsDirPath}\``));
const npmLibDefs = await (0, _npmLibDefs.getNpmLibDefs)(defsDirPath, true);
console.log('All libdefs are named and structured correctly. ' + `(Found ${npmLibDefs.length})`);
return 0;
} catch (errors) {
if (Array.isArray(errors)) {
errors.forEach(error => {
console.log(' • ' + error.message);
});
return 1;
} else {
throw errors;
}
}
}
;