zixulu 1.81.2 → 1.81.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/dist/index.js +19 -16
- package/dist/index.js.map +1 -1
- package/dist/src/utils/addApi.d.ts +3 -1
- package/package.json +1 -1
- package/src/index.ts +3 -1
- package/src/utils/addApi.ts +17 -14
package/dist/index.js
CHANGED
|
@@ -373,8 +373,9 @@ async function addApi_writeFile(...args) {
|
|
|
373
373
|
}
|
|
374
374
|
return await writeFile(...args);
|
|
375
375
|
}
|
|
376
|
-
async function addApi({ type, api, hook, idType = AddApiIdType.字符串, name }) {
|
|
376
|
+
async function addApi({ type, api, hook, idType = AddApiIdType.字符串, name, prefix = "", suffix = "" }) {
|
|
377
377
|
type = capitalize(type);
|
|
378
|
+
const itemType = `${prefix ? capitalize(prefix) : ""}${type}${suffix ? capitalize(suffix) : ""}`;
|
|
378
379
|
name ??= type;
|
|
379
380
|
api ??= "apis";
|
|
380
381
|
hook ??= "hooks";
|
|
@@ -406,13 +407,13 @@ export interface Query${type}Params {
|
|
|
406
407
|
pageNum?: number
|
|
407
408
|
}
|
|
408
409
|
|
|
409
|
-
export interface ${
|
|
410
|
+
export interface ${itemType} {
|
|
410
411
|
id: ${idType}
|
|
411
412
|
name: string
|
|
412
413
|
}
|
|
413
414
|
|
|
414
415
|
export async function query${type}(params: Query${type}Params) {
|
|
415
|
-
const response = await request<Page<${
|
|
416
|
+
const response = await request<Page<${itemType}>>("/${type2}/query", {
|
|
416
417
|
method: "POST",
|
|
417
418
|
body: params,
|
|
418
419
|
})
|
|
@@ -420,7 +421,7 @@ export async function query${type}(params: Query${type}Params) {
|
|
|
420
421
|
}
|
|
421
422
|
|
|
422
423
|
export async function getAll${type}() {
|
|
423
|
-
const response = await request<${
|
|
424
|
+
const response = await request<${itemType}[]>("/${type2}/getAll", {
|
|
424
425
|
method: "POST",
|
|
425
426
|
})
|
|
426
427
|
return response
|
|
@@ -429,12 +430,12 @@ export async function getAll${type}() {
|
|
|
429
430
|
if (items.includes("query")) await addApi_writeFile(join(api, `query${type}.ts`), query);
|
|
430
431
|
const add = `import { request } from "@/utils/request"
|
|
431
432
|
|
|
432
|
-
import type { ${
|
|
433
|
+
import type { ${itemType} } from "./query${type}"
|
|
433
434
|
|
|
434
|
-
export interface Add${type}Params extends Pick<${
|
|
435
|
+
export interface Add${type}Params extends Pick<${itemType}, "name"> {}
|
|
435
436
|
|
|
436
437
|
export async function add${type}(params: Add${type}Params) {
|
|
437
|
-
const response = await request<${
|
|
438
|
+
const response = await request<${itemType}>("/${type2}/add", {
|
|
438
439
|
method: "POST",
|
|
439
440
|
body: params,
|
|
440
441
|
})
|
|
@@ -444,12 +445,12 @@ export async function add${type}(params: Add${type}Params) {
|
|
|
444
445
|
if (items.includes("add")) await addApi_writeFile(join(api, `add${type}.ts`), add);
|
|
445
446
|
const update = `import { request } from "@/utils/request"
|
|
446
447
|
|
|
447
|
-
import type { ${
|
|
448
|
+
import type { ${itemType} } from "./query${type}"
|
|
448
449
|
|
|
449
|
-
export interface Update${type}Params extends Pick<${
|
|
450
|
+
export interface Update${type}Params extends Pick<${itemType}, "id" | "name"> {}
|
|
450
451
|
|
|
451
452
|
export async function update${type}(params: Update${type}Params) {
|
|
452
|
-
const response = await request<${
|
|
453
|
+
const response = await request<${itemType}>("/${type2}/update", {
|
|
453
454
|
method: "POST",
|
|
454
455
|
body: params,
|
|
455
456
|
})
|
|
@@ -459,10 +460,10 @@ export async function update${type}(params: Update${type}Params) {
|
|
|
459
460
|
if (items.includes("update")) await addApi_writeFile(join(api, `update${type}.ts`), update);
|
|
460
461
|
const _delete = `import { request } from "@/utils/request"
|
|
461
462
|
|
|
462
|
-
import type { ${
|
|
463
|
+
import type { ${itemType} } from "./query${type}"
|
|
463
464
|
|
|
464
465
|
export async function delete${type}(id: ${idType}) {
|
|
465
|
-
const response = await request<${
|
|
466
|
+
const response = await request<${itemType}>(\`/${type2}/delete/\${id}\`, {
|
|
466
467
|
method: "DELETE",
|
|
467
468
|
})
|
|
468
469
|
return response
|
|
@@ -471,10 +472,10 @@ export async function delete${type}(id: ${idType}) {
|
|
|
471
472
|
if (items.includes("delete")) await addApi_writeFile(join(api, `delete${type}.ts`), _delete);
|
|
472
473
|
const get = `import { request } from "@/utils/request"
|
|
473
474
|
|
|
474
|
-
import type { ${
|
|
475
|
+
import type { ${itemType} } from "./query${type}"
|
|
475
476
|
|
|
476
477
|
export async function get${type}(id: ${idType}) {
|
|
477
|
-
const response = await request<${
|
|
478
|
+
const response = await request<${itemType}>(\`/${type2}/get/\${id}\`, {
|
|
478
479
|
method: "POST",
|
|
479
480
|
})
|
|
480
481
|
return response
|
|
@@ -6455,12 +6456,14 @@ program.command("set-env").description("设置环境变量").argument("key", "
|
|
|
6455
6456
|
await setEnv(key, value);
|
|
6456
6457
|
consola.success("设置环境变量成功");
|
|
6457
6458
|
});
|
|
6458
|
-
program.command("add-api").description("添加 api 文件").argument("type", "api 类型").option("-a, --api <api>", "api 文件夹路径").option("-h, --hook <hook>", "hook 文件夹路径").addOption(new Option("--id-type <idType>", "id 类型,可选 string 或 number").choices(Object.values(AddApiIdType)).default(AddApiIdType["字符串"])).option("-n, --name <name>", "名称,默认与 type 一致").action(async (type, { api, hook, idType, name })=>addApi({
|
|
6459
|
+
program.command("add-api").description("添加 api 文件").argument("type", "api 类型").option("-a, --api <api>", "api 文件夹路径").option("-h, --hook <hook>", "hook 文件夹路径").addOption(new Option("--id-type <idType>", "id 类型,可选 string 或 number").choices(Object.values(AddApiIdType)).default(AddApiIdType["字符串"])).option("-n, --name <name>", "名称,默认与 type 一致").option("-p, --prefix <prefix>", "item 类型名前缀").option("-s, --suffix <suffix>", "item 类型名后缀").action(async (type, { api, hook, idType, name, prefix, suffix })=>addApi({
|
|
6459
6460
|
type,
|
|
6460
6461
|
api,
|
|
6461
6462
|
hook,
|
|
6462
6463
|
idType,
|
|
6463
|
-
name
|
|
6464
|
+
name,
|
|
6465
|
+
prefix,
|
|
6466
|
+
suffix
|
|
6464
6467
|
}));
|
|
6465
6468
|
program.command("rslib").description("rslib 配置").action(rslib);
|
|
6466
6469
|
program.command("init-node").description("初始化 node 项目").action(initNode);
|