UNPKG

flow-typed

Version:

A repository of high quality flow type definitions

105 lines (80 loc) 4.4 kB
#!/usr/bin/env node "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.outdated = exports.install = exports.createStub = exports.createDef = void 0; exports.runCLI = runCLI; exports.validateDefs = exports.updateCache = exports.update = exports.search = exports.runTests = void 0; var _yargs = _interopRequireDefault(require("yargs")); var _node = require("./lib/node"); var Install = _interopRequireWildcard(require("./commands/install")); var CreateDef = _interopRequireWildcard(require("./commands/create-def")); var CreateStub = _interopRequireWildcard(require("./commands/create-stub")); var Outdated = _interopRequireWildcard(require("./commands/outdated")); var RunTests = _interopRequireWildcard(require("./commands/runTests")); var Search = _interopRequireWildcard(require("./commands/search")); var Update = _interopRequireWildcard(require("./commands/update")); var UpdateCache = _interopRequireWildcard(require("./commands/update-cache")); var ValidateDefs = _interopRequireWildcard(require("./commands/validateDefs")); function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); } function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } const install = Install.run; exports.install = install; const createDef = CreateDef.run; exports.createDef = createDef; const createStub = CreateStub.run; exports.createStub = createStub; const outdated = Outdated.run; exports.outdated = outdated; const runTests = RunTests.run; exports.runTests = runTests; const search = Search.run; exports.search = search; const update = Update.run; exports.update = update; const updateCache = UpdateCache.run; exports.updateCache = updateCache; const validateDefs = ValidateDefs.run; exports.validateDefs = validateDefs; const identity = x => x; function runCLI() { const commands = [CreateDef, CreateStub, Install, Outdated, RunTests, Search, Update, UpdateCache, ValidateDefs]; commands.reduce((cmdYargs, cmd) => cmdYargs.command(cmd.name, cmd.description, cmd.setup || identity, args => cmd // $FlowExpectedError[extra-arg] cmd.run expects only one arg .run(args, _yargs.default).catch(err => { if (err.stack) { console.log('UNCAUGHT ERROR: %s', err.stack); } else if (typeof err === 'object' && err !== null) { console.log('UNCAUGHT ERROR: %s', JSON.stringify(err, null, 2)); } else { console.log('UNCAUGHT ERROR:', err); } process.exit(1); }).then(code => process.exit(code))), _yargs.default).demand(1).strict().recommendCommands().help('h').alias('h', 'help').argv; } /** * Look to see if the CWD is within an npm project. If it is, and that project * has a flow-typed CLI `npm install`ed, use that version instead of the global * version of the CLI. */ if (require.main === module) { const CWD = process.cwd(); let currDir = CWD; let lastDir = null; let run = runCLI; while (currDir !== lastDir) { const localCLIPath = _node.path.join(currDir, 'node_modules', '.bin', 'flow-typed'); try { if (_node.fs.statSync(localCLIPath).isFile()) { run = require.call(null, localCLIPath).runCLI; break; } } catch (e) { /* File doesn't exist, move up a dir... */ } lastDir = currDir; currDir = _node.path.resolve(currDir, '..'); } run(); }