UNPKG

4.4 kBJavaScriptView Raw
1#!/usr/bin/env node
2"use strict";
3
4Object.defineProperty(exports, "__esModule", {
5 value: true
6});
7exports.outdated = exports.install = exports.createStub = exports.createDef = void 0;
8exports.runCLI = runCLI;
9exports.validateDefs = exports.updateCache = exports.update = exports.search = exports.runTests = void 0;
10
11var _yargs = _interopRequireDefault(require("yargs"));
12
13var _node = require("./lib/node");
14
15var Install = _interopRequireWildcard(require("./commands/install"));
16
17var CreateDef = _interopRequireWildcard(require("./commands/create-def"));
18
19var CreateStub = _interopRequireWildcard(require("./commands/create-stub"));
20
21var Outdated = _interopRequireWildcard(require("./commands/outdated"));
22
23var RunTests = _interopRequireWildcard(require("./commands/runTests"));
24
25var Search = _interopRequireWildcard(require("./commands/search"));
26
27var Update = _interopRequireWildcard(require("./commands/update"));
28
29var UpdateCache = _interopRequireWildcard(require("./commands/update-cache"));
30
31var ValidateDefs = _interopRequireWildcard(require("./commands/validateDefs"));
32
33function _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); }
34
35function _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; }
36
37function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
38
39const install = Install.run;
40exports.install = install;
41const createDef = CreateDef.run;
42exports.createDef = createDef;
43const createStub = CreateStub.run;
44exports.createStub = createStub;
45const outdated = Outdated.run;
46exports.outdated = outdated;
47const runTests = RunTests.run;
48exports.runTests = runTests;
49const search = Search.run;
50exports.search = search;
51const update = Update.run;
52exports.update = update;
53const updateCache = UpdateCache.run;
54exports.updateCache = updateCache;
55const validateDefs = ValidateDefs.run;
56exports.validateDefs = validateDefs;
57
58const identity = x => x;
59
60function runCLI() {
61 const commands = [CreateDef, CreateStub, Install, Outdated, RunTests, Search, Update, UpdateCache, ValidateDefs];
62 commands.reduce((cmdYargs, cmd) => cmdYargs.command(cmd.name, cmd.description, cmd.setup || identity, args => cmd // $FlowExpectedError[extra-arg] cmd.run expects only one arg
63 .run(args, _yargs.default).catch(err => {
64 if (err.stack) {
65 console.log('UNCAUGHT ERROR: %s', err.stack);
66 } else if (typeof err === 'object' && err !== null) {
67 console.log('UNCAUGHT ERROR: %s', JSON.stringify(err, null, 2));
68 } else {
69 console.log('UNCAUGHT ERROR:', err);
70 }
71
72 process.exit(1);
73 }).then(code => process.exit(code))), _yargs.default).demand(1).strict().recommendCommands().help('h').alias('h', 'help').argv;
74}
75/**
76 * Look to see if the CWD is within an npm project. If it is, and that project
77 * has a flow-typed CLI `npm install`ed, use that version instead of the global
78 * version of the CLI.
79 */
80
81
82if (require.main === module) {
83 const CWD = process.cwd();
84 let currDir = CWD;
85 let lastDir = null;
86 let run = runCLI;
87
88 while (currDir !== lastDir) {
89 const localCLIPath = _node.path.join(currDir, 'node_modules', '.bin', 'flow-typed');
90
91 try {
92 if (_node.fs.statSync(localCLIPath).isFile()) {
93 run = require.call(null, localCLIPath).runCLI;
94 break;
95 }
96 } catch (e) {
97 /* File doesn't exist, move up a dir... */
98 }
99
100 lastDir = currDir;
101 currDir = _node.path.resolve(currDir, '..');
102 }
103
104 run();
105}
\No newline at end of file