UNPKG

rap2itf

Version:
94 lines (93 loc) 2.99 kB
#!/usr/bin/env node 'use strict' var __assign = (this && this.__assign) || function () { __assign = Object.assign || function (t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i] for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p] } return t } return __assign.apply(this, arguments) } exports.__esModule = true var index_1 = require('./index') var path_1 = require('path') var chalk_1 = require('chalk') var program = require('commander') var getConfig = function () { var cmdPath = process.cwd() var config = require((0, path_1.resolve)(cmdPath, './package.json')) if (!config.rapper) { // console.log(chalk.yellow('尚未在 package.json 中配置 rapper')); var path = (0, path_1.resolve)(cmdPath, '.raprc') console.log( chalk_1['default'].yellow('\u6B63\u5728\u8BFB\u53D6' + path + '\u4E2D\u7684\u914D\u7F6E'), ) config = require(path) } var _a = config.rapper || config, projectId = _a.projectId, rapUrl = _a.rapUrl, apiUrl = _a.apiUrl, rapperPath = _a.rapperPath, interfaceId = _a.interfaceId, token = _a.token, split = _a.split return { projectId: projectId, rapUrl: rapUrl, apiUrl: apiUrl, rapperPath: rapperPath, interfaceId: interfaceId, token: token, split: split, } } ;(function () { program .option('--apiUrl <apiUrl>', '设置Rap平台后端地址') .option('--rapUrl <rapUrl>', '设置Rap平台前端地址') .option('--rapperPath <rapperPath>', '设置生成代码所在目录') .option('--i <i>', '接口id') .option('--interfaceId <interfaceId>', '接口id') .option('--projectId <projectId>', '项目id') .option('--p <p>', '项目id') .option('--token <token>', '用户token') .option('--split <split>', '截取路径长度作为文件名') .option('--s <s>', '截取路径长度作为文件名') program.parse(process.argv) var apiUrl = program.apiUrl, rapUrl = program.rapUrl, rapperPath = program.rapperPath, token = program.token, i = program.i, interfaceId = program.interfaceId, p = program.p, projectId = program.projectId, split = program.split, s = program.s var rapperConfig var config = getConfig() apiUrl = apiUrl || config.apiUrl rapperPath = rapperPath || config.rapperPath token = token || config.token projectId = p || projectId || config.projectId interfaceId = i || interfaceId || config.interfaceId split = s || split || config.split rapUrl = rapUrl || config.rapUrl rapperConfig = __assign(__assign({}, config), { split: split, token: token, apiUrl: apiUrl + '/repository/get?id=' + projectId + '&token=' + token, rapperPath: (0, path_1.resolve)(process.cwd(), rapperPath || './src/types'), projectId: projectId, interfaceId: interfaceId, rapUrl: rapUrl, }) ;(0, index_1.rapper)(rapperConfig) })()