yapi-to-typescript2 1.0.0 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/esm/cli.js CHANGED
@@ -1,10 +1,44 @@
1
1
  #!/usr/bin/env node
2
- import _taggedTemplateLiteralLoose from "@babel/runtime/helpers/esm/taggedTemplateLiteralLoose";
3
- import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
4
-
5
- var _templateObject, _templateObject2;
6
-
7
- import _regeneratorRuntime from "@babel/runtime/regenerator";
2
+ var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) {
3
+ if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
4
+ return cooked;
5
+ };
6
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
7
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
8
+ return new (P || (P = Promise))(function (resolve, reject) {
9
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
10
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
11
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
12
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
13
+ });
14
+ };
15
+ var __generator = (this && this.__generator) || function (thisArg, body) {
16
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
17
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
18
+ function verb(n) { return function (v) { return step([n, v]); }; }
19
+ function step(op) {
20
+ if (f) throw new TypeError("Generator is already executing.");
21
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
22
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
23
+ if (y = 0, t) op = [op[0] & 2, t.value];
24
+ switch (op[0]) {
25
+ case 0: case 1: t = op; break;
26
+ case 4: _.label++; return { value: op[1], done: false };
27
+ case 5: _.label++; y = op[1]; op = [0]; continue;
28
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
29
+ default:
30
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
31
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
32
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
33
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
34
+ if (t[2]) _.ops.pop();
35
+ _.trys.pop(); continue;
36
+ }
37
+ op = body.call(thisArg, _);
38
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
39
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
40
+ }
41
+ };
8
42
  import * as TSNode from 'ts-node';
9
43
  import consola from 'consola';
10
44
  import fs from 'fs-extra';
@@ -15,243 +49,176 @@ import yargs from 'yargs';
15
49
  import { dedent, wait } from 'vtils';
16
50
  import { Generator } from './Generator';
17
51
  TSNode.register({
18
- // 不加载本地的 tsconfig.json
19
- skipProject: true,
20
- // 仅转译,不做类型检查
21
- transpileOnly: true,
22
- // 自定义编译选项
23
- compilerOptions: {
24
- strict: false,
25
- target: 'es2017',
26
- module: 'commonjs',
27
- moduleResolution: 'node',
28
- declaration: false,
29
- removeComments: false,
30
- esModuleInterop: true,
31
- allowSyntheticDefaultImports: true,
32
- importHelpers: false,
33
- // 转换 js,支持在 ytt.config.js 里使用最新语法
34
- allowJs: true,
35
- lib: ['es2017']
36
- }
52
+ // 不加载本地的 tsconfig.json
53
+ skipProject: true,
54
+ // 仅转译,不做类型检查
55
+ transpileOnly: true,
56
+ // 自定义编译选项
57
+ compilerOptions: {
58
+ strict: false,
59
+ target: 'es2017',
60
+ module: 'commonjs',
61
+ moduleResolution: 'node',
62
+ declaration: false,
63
+ removeComments: false,
64
+ esModuleInterop: true,
65
+ allowSyntheticDefaultImports: true,
66
+ importHelpers: false,
67
+ // 转换 js,支持在 ytt.config.js 里使用最新语法
68
+ allowJs: true,
69
+ lib: ['es2017'],
70
+ },
37
71
  });
38
- export function run(_x, _x2) {
39
- return _run.apply(this, arguments);
40
- }
41
- /* istanbul ignore next */
42
-
43
- function _run() {
44
- _run = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(cmd, options) {
45
- var useCustomConfigFile, cwd, configTSFile, configJSFile, configFile, configFileExist, configTSFileExist, configJSFileExist, answers, outputConfigFile, outputConfigFileType, _answers, _config2, _config2$hooks, config, generator, spinner, _hooks, delayNotice, output, _spinner, _generator, _config, _config$hooks;
46
-
47
- return _regeneratorRuntime.wrap(function _callee$(_context) {
48
- while (1) {
49
- switch (_context.prev = _context.next) {
50
- case 0:
51
- useCustomConfigFile = false;
52
-
53
- if (options != null && options.configFile) {
54
- _context.next = 18;
55
- break;
56
- }
57
-
58
- cwd = process.cwd();
59
- configTSFile = path.join(cwd, 'ytt.config.ts');
60
- configJSFile = path.join(cwd, 'ytt.config.js');
61
- _context.next = 7;
62
- return fs.pathExists(configTSFile);
63
-
64
- case 7:
65
- configTSFileExist = _context.sent;
66
- _context.t0 = !configTSFileExist;
67
-
68
- if (!_context.t0) {
69
- _context.next = 13;
70
- break;
71
- }
72
-
73
- _context.next = 12;
74
- return fs.pathExists(configJSFile);
75
-
76
- case 12:
77
- _context.t0 = _context.sent;
78
-
79
- case 13:
80
- configJSFileExist = _context.t0;
81
- configFileExist = configTSFileExist || configJSFileExist;
82
- configFile = configTSFileExist ? configTSFile : configJSFile;
83
- _context.next = 24;
84
- break;
85
-
86
- case 18:
87
- useCustomConfigFile = true;
88
- configFile = options.configFile;
89
- cwd = path.dirname(configFile);
90
- _context.next = 23;
91
- return fs.pathExists(configFile);
92
-
93
- case 23:
94
- configFileExist = _context.sent;
95
-
96
- case 24:
97
- if (!(cmd === 'help')) {
98
- _context.next = 28;
99
- break;
100
- }
101
-
102
- console.log("\n" + dedent(_templateObject || (_templateObject = _taggedTemplateLiteralLoose(["\n # \u7528\u6CD5\n \u521D\u59CB\u5316\u914D\u7F6E\u6587\u4EF6: ytt init\n \u751F\u6210\u4EE3\u7801: ytt\n \u67E5\u770B\u5E2E\u52A9: ytt help\n\n # GitHub\n https://github.com/fjc0k/yapi-to-typescript\n "]))) + "\n");
103
- _context.next = 87;
104
- break;
105
-
106
- case 28:
107
- if (!(cmd === 'init')) {
108
- _context.next = 51;
109
- break;
72
+ export function run(cmd, options) {
73
+ var _a, _b, _c, _d, _e, _f;
74
+ return __awaiter(this, void 0, void 0, function () {
75
+ var useCustomConfigFile, cwd, configTSFile, configJSFile, configFile, configFileExist, configTSFileExist, configJSFileExist, _g, answers, outputConfigFile, outputConfigFileType, answers, config, generator, spinner_1, delayNotice, output, err_1;
76
+ return __generator(this, function (_h) {
77
+ switch (_h.label) {
78
+ case 0:
79
+ useCustomConfigFile = false;
80
+ if (!!(options === null || options === void 0 ? void 0 : options.configFile)) return [3 /*break*/, 4];
81
+ cwd = process.cwd();
82
+ configTSFile = path.join(cwd, 'ytt.config.ts');
83
+ configJSFile = path.join(cwd, 'ytt.config.js');
84
+ return [4 /*yield*/, fs.pathExists(configTSFile)];
85
+ case 1:
86
+ configTSFileExist = _h.sent();
87
+ _g = !configTSFileExist;
88
+ if (!_g) return [3 /*break*/, 3];
89
+ return [4 /*yield*/, fs.pathExists(configJSFile)];
90
+ case 2:
91
+ _g = (_h.sent());
92
+ _h.label = 3;
93
+ case 3:
94
+ configJSFileExist = _g;
95
+ configFileExist = configTSFileExist || configJSFileExist;
96
+ configFile = configTSFileExist ? configTSFile : configJSFile;
97
+ return [3 /*break*/, 6];
98
+ case 4:
99
+ useCustomConfigFile = true;
100
+ configFile = options.configFile;
101
+ cwd = path.dirname(configFile);
102
+ return [4 /*yield*/, fs.pathExists(configFile)];
103
+ case 5:
104
+ configFileExist = _h.sent();
105
+ _h.label = 6;
106
+ case 6:
107
+ if (!(cmd === 'help')) return [3 /*break*/, 7];
108
+ console.log("\n".concat(dedent(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n # \u7528\u6CD5\n \u521D\u59CB\u5316\u914D\u7F6E\u6587\u4EF6: ytt init\n \u751F\u6210\u4EE3\u7801: ytt\n \u67E5\u770B\u5E2E\u52A9: ytt help\n\n # GitHub\n https://github.com/fjc0k/yapi-to-typescript\n "], ["\n # \u7528\u6CD5\n \u521D\u59CB\u5316\u914D\u7F6E\u6587\u4EF6: ytt init\n \u751F\u6210\u4EE3\u7801: ytt\n \u67E5\u770B\u5E2E\u52A9: ytt help\n\n # GitHub\n https://github.com/fjc0k/yapi-to-typescript\n "]))), "\n"));
109
+ return [3 /*break*/, 26];
110
+ case 7:
111
+ if (!(cmd === 'init')) return [3 /*break*/, 14];
112
+ if (!configFileExist) return [3 /*break*/, 9];
113
+ consola.info("\u68C0\u6D4B\u5230\u914D\u7F6E\u6587\u4EF6: ".concat(configFile));
114
+ return [4 /*yield*/, prompt({
115
+ message: '是否覆盖已有配置文件?',
116
+ name: 'override',
117
+ type: 'confirm',
118
+ })];
119
+ case 8:
120
+ answers = _h.sent();
121
+ if (!answers.override)
122
+ return [2 /*return*/];
123
+ _h.label = 9;
124
+ case 9:
125
+ outputConfigFile = void 0;
126
+ outputConfigFileType = void 0;
127
+ if (!useCustomConfigFile) return [3 /*break*/, 10];
128
+ outputConfigFile = configFile;
129
+ outputConfigFileType = configFile.endsWith('.js') ? 'js' : 'ts';
130
+ return [3 /*break*/, 12];
131
+ case 10: return [4 /*yield*/, prompt({
132
+ message: '选择配置文件类型?',
133
+ name: 'configFileType',
134
+ type: 'select',
135
+ choices: [
136
+ { title: 'TypeScript(ytt.config.ts)', value: 'ts' },
137
+ { title: 'JavaScript(ytt.config.js)', value: 'js' },
138
+ ],
139
+ })];
140
+ case 11:
141
+ answers = _h.sent();
142
+ outputConfigFile =
143
+ answers.configFileType === 'js' ? configJSFile : configTSFile;
144
+ outputConfigFileType = answers.configFileType;
145
+ _h.label = 12;
146
+ case 12: return [4 /*yield*/, fs.outputFile(outputConfigFile, dedent(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n import { defineConfig } from 'yapi-to-typescript2'\n\n export default defineConfig([\n {\n serverUrl: 'http://foo.bar',\n typesOnly: false,\n target: '", "',\n reactHooks: {\n enabled: false,\n },\n prodEnvName: 'production',\n outputFilePath: 'src/api/index.", "',\n requestFunctionFilePath: 'src/api/request.", "',\n dataKey: 'data',\n projects: [\n {\n token: 'hello',\n categories: [\n {\n id: 0,\n getRequestFunctionName(interfaceInfo, changeCase) {\n // \u4EE5\u63A5\u53E3\u5168\u8DEF\u5F84\u751F\u6210\u8BF7\u6C42\u51FD\u6570\u540D\n return changeCase.camelCase(interfaceInfo.path)\n\n // \u82E5\u751F\u6210\u7684\u8BF7\u6C42\u51FD\u6570\u540D\u5B58\u5728\u8BED\u6CD5\u5173\u952E\u8BCD\u62A5\u9519\u3001\u6216\u60F3\u901A\u8FC7\u67D0\u4E2A\u5173\u952E\u8BCD\u89E6\u53D1 IDE \u81EA\u52A8\u5F15\u5165\u63D0\u793A\uFF0C\u53EF\u8003\u8651\u52A0\u524D\u7F00\uFF0C\u5982:\n // return changeCase.camelCase(`api_${interfaceInfo.path}`)\n\n // \u82E5\u751F\u6210\u7684\u8BF7\u6C42\u51FD\u6570\u540D\u6709\u91CD\u590D\u62A5\u9519\uFF0C\u53EF\u8003\u8651\u5C06\u63A5\u53E3\u8BF7\u6C42\u65B9\u5F0F\u7EB3\u5165\u751F\u6210\u6761\u4EF6\uFF0C\u5982:\n // return changeCase.camelCase(`${interfaceInfo.method}_${interfaceInfo.path}`)\n },\n },\n ],\n },\n ],\n },\n ])\n "], ["\n import { defineConfig } from 'yapi-to-typescript2'\n\n export default defineConfig([\n {\n serverUrl: 'http://foo.bar',\n typesOnly: false,\n target: '", "',\n reactHooks: {\n enabled: false,\n },\n prodEnvName: 'production',\n outputFilePath: 'src/api/index.", "',\n requestFunctionFilePath: 'src/api/request.", "',\n dataKey: 'data',\n projects: [\n {\n token: 'hello',\n categories: [\n {\n id: 0,\n getRequestFunctionName(interfaceInfo, changeCase) {\n // \u4EE5\u63A5\u53E3\u5168\u8DEF\u5F84\u751F\u6210\u8BF7\u6C42\u51FD\u6570\u540D\n return changeCase.camelCase(interfaceInfo.path)\n\n // \u82E5\u751F\u6210\u7684\u8BF7\u6C42\u51FD\u6570\u540D\u5B58\u5728\u8BED\u6CD5\u5173\u952E\u8BCD\u62A5\u9519\u3001\u6216\u60F3\u901A\u8FC7\u67D0\u4E2A\u5173\u952E\u8BCD\u89E6\u53D1 IDE \u81EA\u52A8\u5F15\u5165\u63D0\u793A\uFF0C\u53EF\u8003\u8651\u52A0\u524D\u7F00\uFF0C\u5982:\n // return changeCase.camelCase(\\`api_\\${interfaceInfo.path}\\`)\n\n // \u82E5\u751F\u6210\u7684\u8BF7\u6C42\u51FD\u6570\u540D\u6709\u91CD\u590D\u62A5\u9519\uFF0C\u53EF\u8003\u8651\u5C06\u63A5\u53E3\u8BF7\u6C42\u65B9\u5F0F\u7EB3\u5165\u751F\u6210\u6761\u4EF6\uFF0C\u5982:\n // return changeCase.camelCase(\\`\\${interfaceInfo.method}_\\${interfaceInfo.path}\\`)\n },\n },\n ],\n },\n ],\n },\n ])\n "])), (outputConfigFileType === 'js'
147
+ ? 'javascript'
148
+ : 'typescript'), outputConfigFileType, outputConfigFileType))];
149
+ case 13:
150
+ _h.sent();
151
+ consola.success('写入配置文件完毕');
152
+ return [3 /*break*/, 26];
153
+ case 14:
154
+ if (!configFileExist) {
155
+ return [2 /*return*/, consola.error("\u627E\u4E0D\u5230\u914D\u7F6E\u6587\u4EF6: ".concat(useCustomConfigFile
156
+ ? configFile
157
+ : "".concat(configTSFile, " \u6216 ").concat(configJSFile)))];
158
+ }
159
+ consola.success("\u627E\u5230\u914D\u7F6E\u6587\u4EF6: ".concat(configFile));
160
+ config = void 0;
161
+ generator = void 0;
162
+ _h.label = 15;
163
+ case 15:
164
+ _h.trys.push([15, 21, , 24]);
165
+ config = require(configFile).default;
166
+ generator = new Generator(config, { cwd: cwd });
167
+ spinner_1 = ora('正在获取数据并生成代码...').start();
168
+ delayNotice = wait(5000);
169
+ delayNotice.then(function () {
170
+ spinner_1.text = "\u6B63\u5728\u83B7\u53D6\u6570\u636E\u5E76\u751F\u6210\u4EE3\u7801... (\u82E5\u957F\u65F6\u95F4\u5904\u4E8E\u6B64\u72B6\u6001\uFF0C\u8BF7\u68C0\u67E5\u662F\u5426\u6709\u63A5\u53E3\u5B9A\u4E49\u7684\u6570\u636E\u8FC7\u5927\u5BFC\u81F4\u62C9\u53D6\u6216\u89E3\u6790\u7F13\u6162)";
171
+ });
172
+ return [4 /*yield*/, generator.prepare()];
173
+ case 16:
174
+ _h.sent();
175
+ delayNotice.cancel();
176
+ return [4 /*yield*/, generator.generate()];
177
+ case 17:
178
+ output = _h.sent();
179
+ spinner_1.stop();
180
+ consola.success('获取数据并生成代码完毕');
181
+ return [4 /*yield*/, generator.write(output)];
182
+ case 18:
183
+ _h.sent();
184
+ consola.success('写入文件完毕');
185
+ return [4 /*yield*/, generator.destroy()];
186
+ case 19:
187
+ _h.sent();
188
+ return [4 /*yield*/, ((_b = (_a = config.hooks) === null || _a === void 0 ? void 0 : _a.success) === null || _b === void 0 ? void 0 : _b.call(_a))];
189
+ case 20:
190
+ _h.sent();
191
+ return [3 /*break*/, 24];
192
+ case 21:
193
+ err_1 = _h.sent();
194
+ spinner_1 === null || spinner_1 === void 0 ? void 0 : spinner_1.stop();
195
+ return [4 /*yield*/, (generator === null || generator === void 0 ? void 0 : generator.destroy())];
196
+ case 22:
197
+ _h.sent();
198
+ return [4 /*yield*/, ((_d = (_c = config === null || config === void 0 ? void 0 : config.hooks) === null || _c === void 0 ? void 0 : _c.fail) === null || _d === void 0 ? void 0 : _d.call(_c))
199
+ /* istanbul ignore next */
200
+ ];
201
+ case 23:
202
+ _h.sent();
203
+ /* istanbul ignore next */
204
+ consola.error(err_1);
205
+ return [3 /*break*/, 24];
206
+ case 24: return [4 /*yield*/, ((_f = (_e = config === null || config === void 0 ? void 0 : config.hooks) === null || _e === void 0 ? void 0 : _e.complete) === null || _f === void 0 ? void 0 : _f.call(_e))];
207
+ case 25:
208
+ _h.sent();
209
+ _h.label = 26;
210
+ case 26: return [2 /*return*/];
110
211
  }
111
-
112
- if (!configFileExist) {
113
- _context.next = 36;
114
- break;
115
- }
116
-
117
- consola.info("\u68C0\u6D4B\u5230\u914D\u7F6E\u6587\u4EF6: " + configFile);
118
- _context.next = 33;
119
- return prompt({
120
- message: '是否覆盖已有配置文件?',
121
- name: 'override',
122
- type: 'confirm'
123
- });
124
-
125
- case 33:
126
- answers = _context.sent;
127
-
128
- if (answers.override) {
129
- _context.next = 36;
130
- break;
131
- }
132
-
133
- return _context.abrupt("return");
134
-
135
- case 36:
136
- if (!useCustomConfigFile) {
137
- _context.next = 41;
138
- break;
139
- }
140
-
141
- outputConfigFile = configFile;
142
- outputConfigFileType = configFile.endsWith('.js') ? 'js' : 'ts';
143
- _context.next = 46;
144
- break;
145
-
146
- case 41:
147
- _context.next = 43;
148
- return prompt({
149
- message: '选择配置文件类型?',
150
- name: 'configFileType',
151
- type: 'select',
152
- choices: [{
153
- title: 'TypeScript(ytt.config.ts)',
154
- value: 'ts'
155
- }, {
156
- title: 'JavaScript(ytt.config.js)',
157
- value: 'js'
158
- }]
159
- });
160
-
161
- case 43:
162
- _answers = _context.sent;
163
- outputConfigFile = _answers.configFileType === 'js' ? configJSFile : configTSFile;
164
- outputConfigFileType = _answers.configFileType;
165
-
166
- case 46:
167
- _context.next = 48;
168
- return fs.outputFile(outputConfigFile, dedent(_templateObject2 || (_templateObject2 = _taggedTemplateLiteralLoose(["\n import { defineConfig } from 'yapi-to-typescript'\n\n export default defineConfig([\n {\n serverUrl: 'http://foo.bar',\n typesOnly: false,\n target: '", "',\n reactHooks: {\n enabled: false,\n },\n prodEnvName: 'production',\n outputFilePath: 'src/api/index.", "',\n requestFunctionFilePath: 'src/api/request.", "',\n dataKey: 'data',\n projects: [\n {\n token: 'hello',\n categories: [\n {\n id: 0,\n getRequestFunctionName(interfaceInfo, changeCase) {\n // \u4EE5\u63A5\u53E3\u5168\u8DEF\u5F84\u751F\u6210\u8BF7\u6C42\u51FD\u6570\u540D\n return changeCase.camelCase(interfaceInfo.path)\n\n // \u82E5\u751F\u6210\u7684\u8BF7\u6C42\u51FD\u6570\u540D\u5B58\u5728\u8BED\u6CD5\u5173\u952E\u8BCD\u62A5\u9519\u3001\u6216\u60F3\u901A\u8FC7\u67D0\u4E2A\u5173\u952E\u8BCD\u89E6\u53D1 IDE \u81EA\u52A8\u5F15\u5165\u63D0\u793A\uFF0C\u53EF\u8003\u8651\u52A0\u524D\u7F00\uFF0C\u5982:\n // return changeCase.camelCase(`api_${interfaceInfo.path}`)\n\n // \u82E5\u751F\u6210\u7684\u8BF7\u6C42\u51FD\u6570\u540D\u6709\u91CD\u590D\u62A5\u9519\uFF0C\u53EF\u8003\u8651\u5C06\u63A5\u53E3\u8BF7\u6C42\u65B9\u5F0F\u7EB3\u5165\u751F\u6210\u6761\u4EF6\uFF0C\u5982:\n // return changeCase.camelCase(`${interfaceInfo.method}_${interfaceInfo.path}`)\n },\n },\n ],\n },\n ],\n },\n ])\n "], ["\n import { defineConfig } from 'yapi-to-typescript'\n\n export default defineConfig([\n {\n serverUrl: 'http://foo.bar',\n typesOnly: false,\n target: '", "',\n reactHooks: {\n enabled: false,\n },\n prodEnvName: 'production',\n outputFilePath: 'src/api/index.", "',\n requestFunctionFilePath: 'src/api/request.", "',\n dataKey: 'data',\n projects: [\n {\n token: 'hello',\n categories: [\n {\n id: 0,\n getRequestFunctionName(interfaceInfo, changeCase) {\n // \u4EE5\u63A5\u53E3\u5168\u8DEF\u5F84\u751F\u6210\u8BF7\u6C42\u51FD\u6570\u540D\n return changeCase.camelCase(interfaceInfo.path)\n\n // \u82E5\u751F\u6210\u7684\u8BF7\u6C42\u51FD\u6570\u540D\u5B58\u5728\u8BED\u6CD5\u5173\u952E\u8BCD\u62A5\u9519\u3001\u6216\u60F3\u901A\u8FC7\u67D0\u4E2A\u5173\u952E\u8BCD\u89E6\u53D1 IDE \u81EA\u52A8\u5F15\u5165\u63D0\u793A\uFF0C\u53EF\u8003\u8651\u52A0\u524D\u7F00\uFF0C\u5982:\n // return changeCase.camelCase(\\`api_\\${interfaceInfo.path}\\`)\n\n // \u82E5\u751F\u6210\u7684\u8BF7\u6C42\u51FD\u6570\u540D\u6709\u91CD\u590D\u62A5\u9519\uFF0C\u53EF\u8003\u8651\u5C06\u63A5\u53E3\u8BF7\u6C42\u65B9\u5F0F\u7EB3\u5165\u751F\u6210\u6761\u4EF6\uFF0C\u5982:\n // return changeCase.camelCase(\\`\\${interfaceInfo.method}_\\${interfaceInfo.path}\\`)\n },\n },\n ],\n },\n ],\n },\n ])\n "])), outputConfigFileType === 'js' ? 'javascript' : 'typescript', outputConfigFileType, outputConfigFileType));
169
-
170
- case 48:
171
- consola.success('写入配置文件完毕');
172
- _context.next = 87;
173
- break;
174
-
175
- case 51:
176
- if (configFileExist) {
177
- _context.next = 53;
178
- break;
179
- }
180
-
181
- return _context.abrupt("return", consola.error("\u627E\u4E0D\u5230\u914D\u7F6E\u6587\u4EF6: " + (useCustomConfigFile ? configFile : configTSFile + " \u6216 " + configJSFile)));
182
-
183
- case 53:
184
- consola.success("\u627E\u5230\u914D\u7F6E\u6587\u4EF6: " + configFile);
185
- _context.prev = 54;
186
- config = require(configFile).default;
187
- generator = new Generator(config, {
188
- cwd: cwd
189
- });
190
- spinner = ora('正在获取数据并生成代码...').start();
191
- delayNotice = wait(5000);
192
- delayNotice.then(function () {
193
- spinner.text = "\u6B63\u5728\u83B7\u53D6\u6570\u636E\u5E76\u751F\u6210\u4EE3\u7801... (\u82E5\u957F\u65F6\u95F4\u5904\u4E8E\u6B64\u72B6\u6001\uFF0C\u8BF7\u68C0\u67E5\u662F\u5426\u6709\u63A5\u53E3\u5B9A\u4E49\u7684\u6570\u636E\u8FC7\u5927\u5BFC\u81F4\u62C9\u53D6\u6216\u89E3\u6790\u7F13\u6162)";
194
- });
195
- _context.next = 62;
196
- return generator.prepare();
197
-
198
- case 62:
199
- delayNotice.cancel();
200
- _context.next = 65;
201
- return generator.generate();
202
-
203
- case 65:
204
- output = _context.sent;
205
- spinner.stop();
206
- consola.success('获取数据并生成代码完毕');
207
- _context.next = 70;
208
- return generator.write(output);
209
-
210
- case 70:
211
- consola.success('写入文件完毕');
212
- _context.next = 73;
213
- return generator.destroy();
214
-
215
- case 73:
216
- _context.next = 75;
217
- return (_hooks = config.hooks) == null ? void 0 : _hooks.success == null ? void 0 : _hooks.success();
218
-
219
- case 75:
220
- _context.next = 85;
221
- break;
222
-
223
- case 77:
224
- _context.prev = 77;
225
- _context.t1 = _context["catch"](54);
226
- (_spinner = spinner) == null ? void 0 : _spinner.stop();
227
- _context.next = 82;
228
- return (_generator = generator) == null ? void 0 : _generator.destroy();
229
-
230
- case 82:
231
- _context.next = 84;
232
- return (_config = config) == null ? void 0 : (_config$hooks = _config.hooks) == null ? void 0 : _config$hooks.fail == null ? void 0 : _config$hooks.fail();
233
-
234
- case 84:
235
- /* istanbul ignore next */
236
- consola.error(_context.t1);
237
-
238
- case 85:
239
- _context.next = 87;
240
- return (_config2 = config) == null ? void 0 : (_config2$hooks = _config2.hooks) == null ? void 0 : _config2$hooks.complete == null ? void 0 : _config2$hooks.complete();
241
-
242
- case 87:
243
- case "end":
244
- return _context.stop();
245
- }
246
- }
247
- }, _callee, null, [[54, 77]]);
248
- }));
249
- return _run.apply(this, arguments);
212
+ });
213
+ });
250
214
  }
251
-
215
+ /* istanbul ignore next */
252
216
  if (require.main === module) {
253
- var argv = yargs(process.argv).alias('c', 'config').argv;
254
- run(argv._[2], {
255
- configFile: argv.config ? path.resolve(process.cwd(), argv.config) : undefined
256
- });
257
- }
217
+ var argv = yargs(process.argv).alias('c', 'config').argv;
218
+ run(argv._[2], {
219
+ configFile: argv.config
220
+ ? path.resolve(process.cwd(), argv.config)
221
+ : undefined,
222
+ });
223
+ }
224
+ var templateObject_1, templateObject_2;
@@ -0,0 +1,49 @@
1
+ import { CliHooks, Config, ConfigWithHooks, RequestConfig, RequestFunctionParams } from './types';
2
+ import type { AppendOptions } from 'form-data';
3
+ /**
4
+ * 定义配置。
5
+ *
6
+ * @param config 配置
7
+ */
8
+ export declare function defineConfig(config: Config, hooks?: CliHooks): ConfigWithHooks;
9
+ export declare class FileData<T = any> {
10
+ /**
11
+ * 原始文件数据。
12
+ */
13
+ private originalFileData;
14
+ /**
15
+ * 选项。
16
+ */
17
+ private options;
18
+ /**
19
+ * 文件数据辅助类,统一网页、小程序等平台的文件上传。
20
+ *
21
+ * @param originalFileData 原始文件数据
22
+ * @param options 若使用内部的 getFormData,则选项会被其使用
23
+ */
24
+ constructor(originalFileData: T, options?: AppendOptions);
25
+ /**
26
+ * 获取原始文件数据。
27
+ *
28
+ * @returns 原始文件数据
29
+ */
30
+ getOriginalFileData(): T;
31
+ /**
32
+ * 获取选项。
33
+ */
34
+ getOptions(): AppendOptions | undefined;
35
+ }
36
+ /**
37
+ * 解析请求数据,从请求数据中分离出普通数据和文件数据。
38
+ *
39
+ * @param requestData 要解析的请求数据
40
+ * @returns 包含普通数据(data)和文件数据(fileData)的对象,data、fileData 为空对象时,表示没有此类数据
41
+ */
42
+ export declare function parseRequestData(requestData?: any): {
43
+ data: any;
44
+ fileData: any;
45
+ };
46
+ /**
47
+ * 准备要传给请求函数的参数。
48
+ */
49
+ export declare function prepare(requestConfig: RequestConfig, requestData: any): RequestFunctionParams;