UNPKG

flow-typed

Version:

A repository of high quality flow type definitions

82 lines (63 loc) 2.17 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.name = exports.description = void 0; exports.run = run; exports.setup = setup; var _path = _interopRequireDefault(require("path")); var _fs = _interopRequireDefault(require("fs")); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } const flowVersion = '0.83.x'; const name = 'create-def <libName> <ver>'; exports.name = name; const description = 'Create template library definitions in flow-typed'; exports.description = description; function setup(yargs) { return yargs.usage(`$0 ${name}`).positional('libName', { describe: 'Please provide the names of library', type: 'string' }).positional('ver', { describe: 'Please provide the version range you want to add', type: 'string' }).example('$0 create-def foo 1.x.x', '').help('h').alias('h', 'help'); } async function run({ libName, ver }) { if (typeof libName !== 'string' || typeof ver !== 'string') { return 1; } if (ver.startsWith('v')) { console.error("ERROR: You don't need to specify `v` with your version"); return 1; } const scope = libName.startsWith('@') ? libName.split('/')[0] : ''; const packageName = scope ? libName.split('/')[1] : libName; const definitionsPath = _path.default.join(process.cwd(), '/definitions/npm', scope !== null && scope !== void 0 ? scope : ''); const rootDefDir = `${definitionsPath}/${packageName}_v${ver}`; const defDir = `${rootDefDir}/flow_v${flowVersion}-`; if (scope) { try { _fs.default.mkdirSync(definitionsPath); } catch (err) { if (err.code !== 'EEXIST') { throw err; } } } _fs.default.mkdirSync(rootDefDir); _fs.default.mkdirSync(defDir); _fs.default.writeFileSync(`${defDir}/${packageName}_v${ver}.js`, `declare module '${libName}' { declare module.exports: any; }`); _fs.default.writeFileSync(`${defDir}/test_${packageName}_v${ver}.js`, `// @flow import { describe, it } from 'flow-typed-test'; // import library from '${libName}'; describe('${libName}', () => { it('', () => { }); });`); return 0; }