@gopowerteam/request-generate 0.2.1 → 0.2.3
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/bin/download.mts +2 -2
- package/bin/generate.mts +1 -1
- package/bin/index.mts +2 -2
- package/dist/index.d.ts +1 -1
- package/dist/index.js +11 -9
- package/dist/index.mjs +11 -9
- package/dist/templates/partials/export-service-namespace.hbs +1 -1
- package/dist/vite-plugin/index.d.ts +1 -1
- package/dist/vite-plugin/index.js +12 -4
- package/dist/vite-plugin/index.mjs +11 -3
- package/package.json +1 -1
package/bin/download.mts
CHANGED
|
@@ -32,7 +32,7 @@ const configFilePaths = [
|
|
|
32
32
|
* 加载配置文件
|
|
33
33
|
* @param {*} filePath
|
|
34
34
|
*/
|
|
35
|
-
async function loadConfigFile(filePath) {
|
|
35
|
+
async function loadConfigFile(filePath: string) {
|
|
36
36
|
if (filePath) {
|
|
37
37
|
configFilePaths.unshift(filePath)
|
|
38
38
|
}
|
|
@@ -62,7 +62,7 @@ if (RequestGenerate) {
|
|
|
62
62
|
console.log('接口文件更新完成')
|
|
63
63
|
process.exit(0)
|
|
64
64
|
})
|
|
65
|
-
.catch((error) => {
|
|
65
|
+
.catch((error: Error) => {
|
|
66
66
|
console.error(error)
|
|
67
67
|
process.exit(1)
|
|
68
68
|
})
|
package/bin/generate.mts
CHANGED
package/bin/index.mts
CHANGED
|
@@ -33,7 +33,7 @@ const configFilePaths = [
|
|
|
33
33
|
* @param {*} filePath
|
|
34
34
|
* @returns Promise
|
|
35
35
|
*/
|
|
36
|
-
async function loadConfigFile(filePath) {
|
|
36
|
+
async function loadConfigFile(filePath: string) {
|
|
37
37
|
if (filePath) {
|
|
38
38
|
configFilePaths.unshift(filePath)
|
|
39
39
|
}
|
|
@@ -64,7 +64,7 @@ if (RequestGenerate) {
|
|
|
64
64
|
.then(() => {
|
|
65
65
|
process.exit(0)
|
|
66
66
|
})
|
|
67
|
-
.catch((error) => {
|
|
67
|
+
.catch((error: Error) => {
|
|
68
68
|
console.error(error)
|
|
69
69
|
process.exit(1)
|
|
70
70
|
})
|
package/dist/index.d.ts
CHANGED
|
@@ -137,7 +137,7 @@ declare class Generate {
|
|
|
137
137
|
* @returns Promise<void>
|
|
138
138
|
*/
|
|
139
139
|
static startup(options: GenerateOptions): Promise<void>;
|
|
140
|
-
static getApiDocument(
|
|
140
|
+
static getApiDocument(input: string): Promise<UnkownVersionDocument>;
|
|
141
141
|
/**
|
|
142
142
|
* 生成应用
|
|
143
143
|
*/
|
package/dist/index.js
CHANGED
|
@@ -994,6 +994,10 @@ function updateOptionsFromLocalConfig(options, output) {
|
|
|
994
994
|
return false;
|
|
995
995
|
}
|
|
996
996
|
});
|
|
997
|
+
options.forEach((item) => {
|
|
998
|
+
const file = path2.default.resolve(".request", `${item.name}.json`);
|
|
999
|
+
item.input = file;
|
|
1000
|
+
});
|
|
997
1001
|
writeLocalConfig(toUpdateOptions, config);
|
|
998
1002
|
return options;
|
|
999
1003
|
}
|
|
@@ -1133,17 +1137,15 @@ var _Generate = class {
|
|
|
1133
1137
|
_Generate.writeClient(application.client, application.options);
|
|
1134
1138
|
});
|
|
1135
1139
|
}
|
|
1136
|
-
static async getApiDocument(
|
|
1137
|
-
if (retry >= 3) {
|
|
1138
|
-
console.error(`\u8BF7\u6C42[${url}]\u5931\u8D25,\u8BF7\u7A0D\u540E\u91CD\u8BD5.`);
|
|
1139
|
-
_process2.default.exit(0);
|
|
1140
|
-
}
|
|
1140
|
+
static async getApiDocument(input) {
|
|
1141
1141
|
try {
|
|
1142
|
-
|
|
1143
|
-
|
|
1142
|
+
const document = await getOpenApiDocument(
|
|
1143
|
+
input
|
|
1144
1144
|
);
|
|
1145
|
+
return document;
|
|
1145
1146
|
} catch (e) {
|
|
1146
|
-
|
|
1147
|
+
console.error(`\u8BF7\u6C42\u6587\u4EF6[${input}]\u5931\u8D25,\u8BF7\u7A0D\u540E\u91CD\u8BD5.`);
|
|
1148
|
+
_process2.default.exit(0);
|
|
1147
1149
|
}
|
|
1148
1150
|
}
|
|
1149
1151
|
/**
|
|
@@ -1186,7 +1188,7 @@ var _Generate = class {
|
|
|
1186
1188
|
var Generate = _Generate;
|
|
1187
1189
|
_chunkXXPGZHWZjs.__publicField.call(void 0, Generate, "options");
|
|
1188
1190
|
|
|
1189
|
-
// src/
|
|
1191
|
+
// src/define-config.ts
|
|
1190
1192
|
function defineConfig(config) {
|
|
1191
1193
|
return config;
|
|
1192
1194
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -995,6 +995,10 @@ function updateOptionsFromLocalConfig(options, output) {
|
|
|
995
995
|
return false;
|
|
996
996
|
}
|
|
997
997
|
});
|
|
998
|
+
options.forEach((item) => {
|
|
999
|
+
const file = path4.resolve(".request", `${item.name}.json`);
|
|
1000
|
+
item.input = file;
|
|
1001
|
+
});
|
|
998
1002
|
writeLocalConfig(toUpdateOptions, config);
|
|
999
1003
|
return options;
|
|
1000
1004
|
}
|
|
@@ -1134,17 +1138,15 @@ var _Generate = class {
|
|
|
1134
1138
|
_Generate.writeClient(application.client, application.options);
|
|
1135
1139
|
});
|
|
1136
1140
|
}
|
|
1137
|
-
static async getApiDocument(
|
|
1138
|
-
if (retry >= 3) {
|
|
1139
|
-
console.error(`\u8BF7\u6C42[${url}]\u5931\u8D25,\u8BF7\u7A0D\u540E\u91CD\u8BD5.`);
|
|
1140
|
-
process.exit(0);
|
|
1141
|
-
}
|
|
1141
|
+
static async getApiDocument(input) {
|
|
1142
1142
|
try {
|
|
1143
|
-
|
|
1144
|
-
|
|
1143
|
+
const document = await getOpenApiDocument(
|
|
1144
|
+
input
|
|
1145
1145
|
);
|
|
1146
|
+
return document;
|
|
1146
1147
|
} catch {
|
|
1147
|
-
|
|
1148
|
+
console.error(`\u8BF7\u6C42\u6587\u4EF6[${input}]\u5931\u8D25,\u8BF7\u7A0D\u540E\u91CD\u8BD5.`);
|
|
1149
|
+
process.exit(0);
|
|
1148
1150
|
}
|
|
1149
1151
|
}
|
|
1150
1152
|
/**
|
|
@@ -1187,7 +1189,7 @@ var _Generate = class {
|
|
|
1187
1189
|
var Generate = _Generate;
|
|
1188
1190
|
__publicField(Generate, "options");
|
|
1189
1191
|
|
|
1190
|
-
// src/
|
|
1192
|
+
// src/define-config.ts
|
|
1191
1193
|
function defineConfig(config) {
|
|
1192
1194
|
return config;
|
|
1193
1195
|
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }require('../chunk-XXPGZHWZ.js');
|
|
2
2
|
|
|
3
3
|
// src/vite-plugin/index.ts
|
|
4
4
|
var _child_process = require('child_process');
|
|
5
5
|
var _fs = require('fs'); var fs = _interopRequireWildcard(_fs);
|
|
6
6
|
var _path = require('path'); var path = _interopRequireWildcard(_path);
|
|
7
|
+
var _process = require('process'); var _process2 = _interopRequireDefault(_process);
|
|
7
8
|
var _handlebars = require('handlebars'); var _handlebars2 = _interopRequireDefault(_handlebars);
|
|
8
9
|
|
|
9
10
|
// src/vite-plugin/templates.ts
|
|
@@ -119,13 +120,20 @@ function genretateDeclareAndCode(options) {
|
|
|
119
120
|
const services = getServiceItems(paths);
|
|
120
121
|
const groups = getServiceGroups(services);
|
|
121
122
|
if (services && services.length) {
|
|
122
|
-
generateDeclare(services, groups, options);
|
|
123
123
|
generateCode(services, groups);
|
|
124
|
+
if (options.dts !== false) {
|
|
125
|
+
generateDeclare(services, groups, options);
|
|
126
|
+
}
|
|
124
127
|
}
|
|
125
128
|
}
|
|
126
129
|
function generateRequestCode() {
|
|
127
130
|
const generateScript = path.resolve(viteConfig.root, "node_modules", ".bin", "request-generate");
|
|
128
|
-
_child_process.execSync.call(void 0, `${generateScript}
|
|
131
|
+
_child_process.execSync.call(void 0, `${generateScript}`, {
|
|
132
|
+
env: {
|
|
133
|
+
..._process2.default.env,
|
|
134
|
+
FORCE_COLOR: "1"
|
|
135
|
+
}
|
|
136
|
+
});
|
|
129
137
|
}
|
|
130
138
|
var vite_plugin_default = (options) => {
|
|
131
139
|
return {
|
|
@@ -215,7 +223,7 @@ function generateDeclare(services, groups, options) {
|
|
|
215
223
|
MODULE_ID
|
|
216
224
|
});
|
|
217
225
|
fs.writeFileSync(
|
|
218
|
-
path.resolve(viteConfig.root,
|
|
226
|
+
path.resolve(viteConfig.root, typeof options.dts === "string" ? options.dts : DECLARATION_FILE),
|
|
219
227
|
content.replace(/\r\n/g, "\n"),
|
|
220
228
|
"utf-8"
|
|
221
229
|
);
|
|
@@ -4,6 +4,7 @@ import "../chunk-WF3XBEPN.mjs";
|
|
|
4
4
|
import { execSync } from "node:child_process";
|
|
5
5
|
import * as fs from "node:fs";
|
|
6
6
|
import * as path from "node:path";
|
|
7
|
+
import process from "node:process";
|
|
7
8
|
import Handlebars from "handlebars";
|
|
8
9
|
|
|
9
10
|
// src/vite-plugin/templates.ts
|
|
@@ -119,13 +120,20 @@ function genretateDeclareAndCode(options) {
|
|
|
119
120
|
const services = getServiceItems(paths);
|
|
120
121
|
const groups = getServiceGroups(services);
|
|
121
122
|
if (services && services.length) {
|
|
122
|
-
generateDeclare(services, groups, options);
|
|
123
123
|
generateCode(services, groups);
|
|
124
|
+
if (options.dts !== false) {
|
|
125
|
+
generateDeclare(services, groups, options);
|
|
126
|
+
}
|
|
124
127
|
}
|
|
125
128
|
}
|
|
126
129
|
function generateRequestCode() {
|
|
127
130
|
const generateScript = path.resolve(viteConfig.root, "node_modules", ".bin", "request-generate");
|
|
128
|
-
execSync(`${generateScript}
|
|
131
|
+
execSync(`${generateScript}`, {
|
|
132
|
+
env: {
|
|
133
|
+
...process.env,
|
|
134
|
+
FORCE_COLOR: "1"
|
|
135
|
+
}
|
|
136
|
+
});
|
|
129
137
|
}
|
|
130
138
|
var vite_plugin_default = (options) => {
|
|
131
139
|
return {
|
|
@@ -215,7 +223,7 @@ function generateDeclare(services, groups, options) {
|
|
|
215
223
|
MODULE_ID
|
|
216
224
|
});
|
|
217
225
|
fs.writeFileSync(
|
|
218
|
-
path.resolve(viteConfig.root, options.dts
|
|
226
|
+
path.resolve(viteConfig.root, typeof options.dts === "string" ? options.dts : DECLARATION_FILE),
|
|
219
227
|
content.replace(/\r\n/g, "\n"),
|
|
220
228
|
"utf-8"
|
|
221
229
|
);
|