From 9d7fe9f2e966068ac8e7eaff23913be6b11cb577 Mon Sep 17 00:00:00 2001 From: as Date: Tue, 18 Oct 2022 17:32:25 +0800 Subject: [PATCH 1/7] feat: add first --- .vscode/launch.json | 21 + base.ts | 81 ++++ index.ts | 36 ++ package-lock.json | 143 +++++++ package.json | 20 + test/index.ts | 4 + test/resource.ts | 909 ++++++++++++++++++++++++++++++++++++++++++++ tsconfig.json | 27 ++ yapi.ts | 26 ++ yarn.lock | 257 +++++++++++++ 10 files changed, 1524 insertions(+) create mode 100644 .vscode/launch.json create mode 100644 base.ts create mode 100644 index.ts create mode 100644 package-lock.json create mode 100644 package.json create mode 100644 test/index.ts create mode 100644 test/resource.ts create mode 100644 tsconfig.json create mode 100644 yapi.ts create mode 100644 yarn.lock diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..456b989 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,21 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "Node-TS", + "type": "node", + "request": "launch", + "runtimeExecutable": "ts-node", + "runtimeArgs": ["--esm", "--experimentalSpecifierResolution=node"], + + "args": ["./test/index.ts"], + "base" + "cwd": "${workspaceRoot}", + "internalConsoleOptions": "openOnSessionStart", + "skipFiles": ["/**", "node_modules/**"] + } + ] +} \ No newline at end of file diff --git a/base.ts b/base.ts new file mode 100644 index 0000000..1b36787 --- /dev/null +++ b/base.ts @@ -0,0 +1,81 @@ +import { Propertie, UnionYapiType } from "yapi" + +const typeMap = { + 'string': 'string', + 'boolean': 'boolean', + 'integer': 'number', + 'number': 'number', + 'object': 'object', + 'array': 'array' +} +// let res = '' +// const defineTypes:string[] = [] +const defineTypeNames: string[] = [] + +export interface BaseLeaf { + name: string, + type: UnionYapiType | 'unknown', + isArray: boolean, + require?: boolean, + description?: string, + children?: BaseLeaf[], + parent?: BaseLeaf, +} +export const tree: BaseLeaf[] = [] +export const twig: BaseLeaf[] = [] + +export const toBaseLeaf = (key: string, propertie: Propertie, parent?: BaseLeaf) => { + const leaf: BaseLeaf = { + name: key, + type: propertie.type, + description: propertie.description, + isArray: false, + parent + } + if (propertie.type === 'object') { + leaf.children = [] + for (const childKey in propertie.properties) { + if (Object.prototype.hasOwnProperty.call(propertie.properties, childKey)) { + leaf.children.push(toBaseLeaf(childKey, propertie.properties[childKey], leaf)) + } + } + twig.push(leaf) + } + if (propertie.type === 'array') { + leaf.isArray = true + if (propertie.items.type === 'object') { + leaf.children = [] + for (const childKey in propertie.items.properties) { + if (Object.prototype.hasOwnProperty.call(propertie.items.properties, childKey)) { + leaf.children.push(toBaseLeaf(childKey, propertie.items.properties[childKey], leaf)) + } + } + twig.push(leaf) + } else { + leaf.type = propertie.items.type + } + } + leaf.type = toTypeName(leaf) + tree.push(leaf) + return leaf +} +const nameFactory = (value: string, parent?: BaseLeaf, isPrimary?: boolean) => { + const name = value[0].toLocaleUpperCase() + value.slice(1, value.length) + if (defineTypeNames.includes(name) && parent && isPrimary) { + const fitableName = nameFactory(`${parent.name}${name}`, parent.parent) + defineTypeNames.push(fitableName) + return fitableName + } else { + defineTypeNames.push(name) + return name + } +} +const toTypeName = (leaf: BaseLeaf) => { + if (leaf.type === 'array' && leaf.children) { + return nameFactory(leaf.name, leaf.parent, true) + } else if (leaf.type === 'object') { + return nameFactory(leaf.name, leaf.parent, true) + } else { + return typeMap[leaf.type] + } +} diff --git a/index.ts b/index.ts new file mode 100644 index 0000000..4115644 --- /dev/null +++ b/index.ts @@ -0,0 +1,36 @@ +// define +import { BaseLeaf, toBaseLeaf, twig } from './base'; +import clipboardy from 'clipboardy'; +import { Propertie } from './yapi'; + +const transformer = (tree: BaseLeaf[]) => { + let res:string[] = [] + for (let i = 0; i < tree.length; i++) { + const currentLeaf = tree[i] + // const interfaceName = currentLeaf.type === 'object' ? + let text = `interface ${currentLeaf.type} {\n` + currentLeaf.children?.forEach(item=>{ + if(item.description){ + text += ` // ${item.description}\n` + } + text += ` ${item.name}: ${item.type}${item.isArray?'[]':''};\n` + }) + text += '}' + res.push(text) + } + return res; +} +const runner = (name: string, propertie: Propertie) => { + toBaseLeaf(name, propertie) + const res = transformer(twig) + const dd = res.join('\n') + clipboardy.writeSync(dd); +} +const use = (fn)=>{ + +} + +export { + runner, + use +} \ No newline at end of file diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..21e5ba7 --- /dev/null +++ b/package-lock.json @@ -0,0 +1,143 @@ +{ + "name": "yapitool", + "version": "1.0.0", + "lockfileVersion": 1, + "requires": true, + "dependencies": { + "@cspotcode/source-map-support": { + "version": "0.8.1", + "resolved": "https://npm.dustess.com/@cspotcode%2fsource-map-support/-/source-map-support-0.8.1.tgz", + "integrity": "sha512-IchNf6dN4tHoMFIn/7OE8LWZ19Y6q/67Bmf6vnGREv8RSbBVb9LPJxEcnwrcwX6ixSvaiGoomAUvu4YSxXrVgw==", + "dev": true, + "requires": { + "@jridgewell/trace-mapping": "0.3.9" + } + }, + "@jridgewell/resolve-uri": { + "version": "3.1.0", + "resolved": "https://npm.dustess.com/@jridgewell%2fresolve-uri/-/resolve-uri-3.1.0.tgz", + "integrity": "sha512-F2msla3tad+Mfht5cJq7LSXcdudKTWCVYUgw6pLFOOHSTtZlj6SWNYAp+AhuqLmWdBO2X5hPrLcu8cVP8fy28w==", + "dev": true + }, + "@jridgewell/sourcemap-codec": { + "version": "1.4.14", + "resolved": "https://npm.dustess.com/@jridgewell%2fsourcemap-codec/-/sourcemap-codec-1.4.14.tgz", + "integrity": "sha512-XPSJHWmi394fuUuzDnGz1wiKqWfo1yXecHQMRf2l6hztTO+nPru658AyDngaBe7isIxEkRsPR3FZh+s7iVa4Uw==", + "dev": true + }, + "@jridgewell/trace-mapping": { + "version": "0.3.9", + "resolved": "https://npm.dustess.com/@jridgewell%2ftrace-mapping/-/trace-mapping-0.3.9.tgz", + "integrity": "sha512-3Belt6tdc8bPgAtbcmdtNJlirVoTmEb5e2gC94PnkwEW9jI6CAHUeoG85tjWP5WquqfavoMtMwiG4P926ZKKuQ==", + "dev": true, + "requires": { + "@jridgewell/resolve-uri": "^3.0.3", + "@jridgewell/sourcemap-codec": "^1.4.10" + } + }, + "@tsconfig/node10": { + "version": "1.0.9", + "resolved": "https://npm.dustess.com/@tsconfig%2fnode10/-/node10-1.0.9.tgz", + "integrity": "sha512-jNsYVVxU8v5g43Erja32laIDHXeoNvFEpX33OK4d6hljo3jDhCBDhx5dhCCTMWUojscpAagGiRkBKxpdl9fxqA==", + "dev": true + }, + "@tsconfig/node12": { + "version": "1.0.11", + "resolved": "https://npm.dustess.com/@tsconfig%2fnode12/-/node12-1.0.11.tgz", + "integrity": "sha512-cqefuRsh12pWyGsIoBKJA9luFu3mRxCA+ORZvA4ktLSzIuCUtWVxGIuXigEwO5/ywWFMZ2QEGKWvkZG1zDMTag==", + "dev": true + }, + "@tsconfig/node14": { + "version": "1.0.3", + "resolved": "https://npm.dustess.com/@tsconfig%2fnode14/-/node14-1.0.3.tgz", + "integrity": "sha512-ysT8mhdixWK6Hw3i1V2AeRqZ5WfXg1G43mqoYlM2nc6388Fq5jcXyr5mRsqViLx/GJYdoL0bfXD8nmF+Zn/Iow==", + "dev": true + }, + "@tsconfig/node16": { + "version": "1.0.3", + "resolved": "https://npm.dustess.com/@tsconfig%2fnode16/-/node16-1.0.3.tgz", + "integrity": "sha512-yOlFc+7UtL/89t2ZhjPvvB/DeAr3r+Dq58IgzsFkOAvVC6NMJXmCGjbptdXdR9qsX7pKcTL+s87FtYREi2dEEQ==", + "dev": true + }, + "@types/node": { + "version": "18.11.0", + "resolved": "https://npm.dustess.com/@types%2fnode/-/node-18.11.0.tgz", + "integrity": "sha512-IOXCvVRToe7e0ny7HpT/X9Rb2RYtElG1a+VshjwT00HxrM2dWBApHQoqsI6WiY7Q03vdf2bCrIGzVrkF/5t10w==", + "dev": true + }, + "acorn": { + "version": "8.8.0", + "resolved": "https://npm.dustess.com/acorn/-/acorn-8.8.0.tgz", + "integrity": "sha512-QOxyigPVrpZ2GXT+PFyZTl6TtOFc5egxHIP9IlQ+RbupQuX4RkT/Bee4/kQuC02Xkzg84JcT7oLYtDIQxp+v7w==", + "dev": true + }, + "acorn-walk": { + "version": "8.2.0", + "resolved": "https://npm.dustess.com/acorn-walk/-/acorn-walk-8.2.0.tgz", + "integrity": "sha1-dBIQ8uJCZFRQiFOi9E0KuDt/acE=", + "dev": true + }, + "arg": { + "version": "4.1.3", + "resolved": "https://npm.dustess.com/arg/-/arg-4.1.3.tgz", + "integrity": "sha1-Jp/HrVuOQstjyJbVZmAXJhwUQIk=", + "dev": true + }, + "create-require": { + "version": "1.1.1", + "resolved": "https://npm.dustess.com/create-require/-/create-require-1.1.1.tgz", + "integrity": "sha1-wdfo8eX2z8n/ZfnNNS03NIdWwzM=", + "dev": true + }, + "diff": { + "version": "4.0.2", + "resolved": "https://npm.dustess.com/diff/-/diff-4.0.2.tgz", + "integrity": "sha1-YPOuy4nV+uUgwRqhnvwruYKq3n0=", + "dev": true + }, + "make-error": { + "version": "1.3.6", + "resolved": "https://npm.dustess.com/make-error/-/make-error-1.3.6.tgz", + "integrity": "sha1-LrLjfqm2fEiR9oShOUeZr0hM96I=", + "dev": true + }, + "ts-node": { + "version": "10.9.1", + "resolved": "https://npm.dustess.com/ts-node/-/ts-node-10.9.1.tgz", + "integrity": "sha512-NtVysVPkxxrwFGUUxGYhfux8k78pQB3JqYBXlLRZgdGUqTO5wU/UyHop5p70iEbGhB7q5KmiZiU0Y3KlJrScEw==", + "dev": true, + "requires": { + "@cspotcode/source-map-support": "^0.8.0", + "@tsconfig/node10": "^1.0.7", + "@tsconfig/node12": "^1.0.7", + "@tsconfig/node14": "^1.0.0", + "@tsconfig/node16": "^1.0.2", + "acorn": "^8.4.1", + "acorn-walk": "^8.1.1", + "arg": "^4.1.0", + "create-require": "^1.1.0", + "diff": "^4.0.1", + "make-error": "^1.1.1", + "v8-compile-cache-lib": "^3.0.1", + "yn": "3.1.1" + } + }, + "typescript": { + "version": "4.8.4", + "resolved": "https://npm.dustess.com/typescript/-/typescript-4.8.4.tgz", + "integrity": "sha512-QCh+85mCy+h0IGff8r5XWzOVSbBO+KfeYrMQh7NJ58QujwcE22u+NUSmUxqF+un70P9GXKxa2HCNiTTMJknyjQ==" + }, + "v8-compile-cache-lib": { + "version": "3.0.1", + "resolved": "https://npm.dustess.com/v8-compile-cache-lib/-/v8-compile-cache-lib-3.0.1.tgz", + "integrity": "sha512-wa7YjyUGfNZngI/vtK0UHAN+lgDCxBPCylVXGp0zu59Fz5aiGtNXaq3DhIov063MorB+VfufLh3JlF2KdTK3xg==", + "dev": true + }, + "yn": { + "version": "3.1.1", + "resolved": "https://npm.dustess.com/yn/-/yn-3.1.1.tgz", + "integrity": "sha1-HodAGgnXZ8HV6rJqbkwYUYLS61A=", + "dev": true + } + } +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..fe8f177 --- /dev/null +++ b/package.json @@ -0,0 +1,20 @@ +{ + "name": "yapi-tool", + "version": "1.0.0", + "description": "", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "author": "", + "license": "ISC", + "dependencies": { + "clipboardy": "^3.0.0", + "typescript": "^4.8.4" + }, + "type": "module", + "devDependencies": { + "@types/node": "^18.11.0", + "ts-node": "^10.9.1" + } +} diff --git a/test/index.ts b/test/index.ts new file mode 100644 index 0000000..5e7a017 --- /dev/null +++ b/test/index.ts @@ -0,0 +1,4 @@ +import { runner } from '../'; +import resource from './resource'; + +runner('goodDetail', resource) \ No newline at end of file diff --git a/test/resource.ts b/test/resource.ts new file mode 100644 index 0000000..e0f4cf5 --- /dev/null +++ b/test/resource.ts @@ -0,0 +1,909 @@ +import { Propertie } from '../yapi'; + +const target:Propertie = { + 'type': 'object', + 'required': [ + 'data', + 'msg', + 'success' + ], + 'properties': { + 'code': { + 'description': 'code码', + 'type': 'integer' + }, + 'data': { + 'type': 'object', + 'properties': { + '_id': { + 'description': '商品唯一id(uuid)', + 'type': 'string' + }, + 'activitys': { + 'description': '活动信息集合', + 'type': 'array', + 'items': { + 'type': 'object', + 'properties': { + 'activityId': { + 'description': '活动id', + 'type': 'string' + }, + 'activityName': { + 'description': '活动名字', + 'type': 'string' + }, + 'cycleBuy': { + 'type': 'object', + 'properties': { + 'allowChangeAdvanceDay': { + 'description': '允许客户变更订单属性的提前天数', + 'type': 'integer' + }, + 'allowChangeAdvanceTime': { + 'description': '允许客户变更订单属性的时间 (同 allowChangeDay属性搭配使用,用于限制某类产品随意更改,降低客户损失)', + 'type': 'string' + }, + 'deliveryBeginDate': { + 'description': '起始发货日(隔日送有效)', + 'type': 'string' + }, + 'disableCoupon': { + 'description': '是否允许使用优惠券 true 禁用', + 'type': 'boolean' + }, + 'nextDayBeginDate': { + 'description': '隔日送有效起始发货日', + 'type': 'string' + }, + 'ruleText': { + 'description': '配送规则详情', + 'type': 'array', + 'items': { + 'type': 'integer' + } + }, + 'ruleType': { + 'description': '配送规则详情 配送周期类型(0-天天送,1-隔日送,2-按周送,3-按月送)', + 'type': 'integer' + }, + 'state': { + 'description': '周期购商品状态(0-草稿,1-进行中,2-暂停,3-下架)', + 'type': 'integer' + } + }, + '$$ref': '#/definitions/active.CycleActivity' + }, + 'disableCoupon': { + 'description': '是否允许使用优惠券 true 禁用', + 'type': 'boolean' + }, + 'enable': { + 'description': '是否开启活动', + 'type': 'boolean' + }, + 'endTime': { + 'description': '活动结束时间', + 'type': 'string' + }, + 'groupLine': { + 'description': '拼团活动人数需求', + 'type': 'integer' + }, + 'highestActivityPrice': { + 'description': '活动最高价格', + 'type': 'number' + }, + 'ifPrediction': { + 'description': '是否开启活动预告', + 'type': 'boolean' + }, + 'lowestActivityPrice': { + 'description': '活动最低价格', + 'type': 'number' + }, + 'skus': { + 'description': '活动sku', + 'type': 'array', + 'items': { + 'type': 'object', + 'properties': { + '_id': { + 'description': 'skuID', + 'type': 'string' + }, + 'attributeItems': { + 'description': '规格-子选项', + 'type': 'array', + 'items': { + 'type': 'string' + } + }, + 'inventory': { + 'description': 'sku 库存', + 'type': 'integer' + }, + 'lowestNumber': { + 'description': '煤气最低配送数量(周期购)', + 'type': 'integer' + }, + 'maxNum': { + 'description': '最大可用数据', + 'type': 'integer' + }, + 'name': { + 'description': 'sku名字,多个规格拼接后的名字,例如,白色-M,红色-L', + 'type': 'string' + }, + 'price': { + 'description': '活动价格', + 'type': 'number' + } + }, + '$$ref': '#/definitions/goods.ActivitySku' + } + }, + 'startTime': { + 'description': '活动开始时间', + 'type': 'string' + }, + 'totalInventory': { + 'description': '活动总库存,多个sku库存相加', + 'type': 'integer' + }, + 'type': { + 'description': '活动类型,拼团:10001001,秒杀:10002001,限时优惠:10004001 周期购:10005001', + 'type': 'string' + } + }, + '$$ref': '#/definitions/goods.Activity' + } + }, + 'agentNum': { + 'description': '代理商总数', + 'type': 'string' + }, + 'attributes': { + 'description': '商品规格,列表不返回当前数据', + 'type': 'array', + 'items': { + 'type': 'object', + 'properties': { + 'attributeId': { + 'description': '商品规格id', + 'type': 'string' + }, + 'default': { + 'description': '默认', + 'type': 'boolean' + }, + 'isShowImage': { + 'description': '是否显示图片', + 'type': 'boolean' + }, + 'name': { + 'description': '商品规格名字', + 'type': 'string' + }, + 'options': { + 'description': '可选属性', + 'type': 'array', + 'items': { + 'type': 'object', + 'properties': { + '_id': { + 'description': '规格ID', + 'type': 'string' + }, + 'default': { + 'description': '默认', + 'type': 'boolean' + }, + 'imageUrl': { + 'description': '图片', + 'type': 'string' + }, + 'value': { + 'description': '值', + 'type': 'string' + } + }, + '$$ref': '#/definitions/goods.AttributeOption' + } + } + }, + '$$ref': '#/definitions/goods.AttributeRes' + } + }, + 'categoryId': { + 'description': '分类id,自节点的id,服务器自己递归查询', + 'type': 'string' + }, + 'categoryName': { + 'description': '分类名字,拼接后的字符串,例如:衣服/鞋子,裤子/短裤,可以直接显示,详情才回返回该信息', + 'type': 'string' + }, + 'channelSet': { + 'type': 'object', + 'properties': { + 'agent': { + 'description': '代理商', + 'type': 'array', + 'items': { + 'type': 'string' + } + }, + 'agentChannel': { + 'description': '1 全部代理商 2 指定代理商', + 'type': 'integer' + } + }, + '$$ref': '#/definitions/goods.agentChannelSet' + }, + 'code': { + 'description': '商品编码', + 'type': 'string' + }, + 'content': { + 'description': '内容', + 'type': 'string' + }, + 'couponsList': { + 'description': '付费优惠券商品包含优惠券列表', + 'type': 'array', + 'items': { + 'type': 'object', + 'properties': { + 'batchId': { + 'description': '方案批次号', + 'type': 'string' + }, + 'desc': { + 'description': '描述 满1000可用', + 'type': 'string' + }, + 'discount': { + 'description': '折扣 type=2 使用', + 'type': 'number' + }, + 'id': { + 'description': 'id', + 'type': 'string' + }, + 'name': { + 'description': '优惠券名', + 'type': 'string' + }, + 'num': { + 'description': '数量', + 'type': 'integer' + }, + 'price': { + 'description': '面额 单位元 type=1 使用', + 'type': 'number' + }, + 'restCount': { + 'description': '剩余可发送数量', + 'type': 'integer' + }, + 'status': { + 'description': '0=未开始 1=进行中 2=已结束', + 'type': 'integer' + }, + 'threshold': { + 'description': '门槛 满多少可用 0=无门槛', + 'type': 'number' + }, + 'type': { + 'description': '优惠券类型: 1:满减 2:折扣 3:到店核销券', + 'type': 'integer' + }, + 'usedGoods': { + 'description': '适用商品 1:所有商品适用 2:部分商品适用', + 'type': 'integer' + }, + 'valid': { + 'description': '有效期', + 'type': 'string' + } + }, + '$$ref': '#/definitions/goods.CouponsInfoRes' + } + }, + 'createdTime': { + 'description': '创建时间', + 'type': 'string' + }, + 'defaultSku': { + 'type': 'object', + 'properties': { + 'imageUrl': { + 'description': '图片', + 'type': 'string' + }, + 'name': { + 'description': 'sku名字,多个规格拼接后的名字,例如,白色-M,红色-L', + 'type': 'string' + }, + 'price': { + 'description': '价格', + 'type': 'number' + }, + 'skuId': { + 'description': 'skuId,不传表示新建', + 'type': 'string' + } + }, + '$$ref': '#/definitions/goods.DefaultSkuData' + }, + 'detailType': { + 'description': '详情类型 0是图文视频详情 1是图文详情', + 'type': 'integer' + }, + 'dibOnShelf': { + 'description': '分销商品是否已上架', + 'type': 'boolean' + }, + 'fronOrBack': { + 'description': '展示在详情前或者后 前 : fron 后:back', + 'type': 'string' + }, + 'goodsBaseLogistics': { + 'type': 'object', + 'properties': { + '_id': { + 'description': '物流信息ID,不传表示新建', + 'type': 'string' + }, + 'chargeMode': { + 'description': '计费方式 1按件 2按重量', + 'type': 'integer' + }, + 'deliveryMethod': { + 'description': '配送方式(1:快递发货(目前只有这一个))', + 'type': 'integer' + }, + 'expressFee': { + 'description': '具体运费多少钱', + 'type': 'number' + }, + 'expressFeeTemplateId': { + 'description': '运费模板ID', + 'type': 'string' + }, + 'expressFreightMethod': { + 'description': '运费计算方式---1: 统一邮费,2:运费模板', + 'type': 'integer' + }, + 'firstFee': { + 'description': '首费,2位小数----返回数据中返回的是值最小的一个', + 'type': 'number' + }, + 'goodsId': { + 'description': '商品ID', + 'type': 'string' + }, + 'templateName': { + 'description': '模板名称', + 'type': 'string' + } + }, + '$$ref': '#/definitions/goods.goodsBaseLogistics' + }, + 'goodsExt': { + 'type': 'object', + 'properties': { + 'inventoryWarning': { + 'type': 'object', + 'properties': { + 'enable': { + 'description': '是否开启库存预警', + 'type': 'boolean' + }, + 'value': { + 'description': '库存预警阀值,只可以正数量', + 'type': 'integer' + } + }, + '$$ref': '#/definitions/goods.inventoryWarning' + }, + 'marketPrice': { + 'description': '市场价格,转换精度后的值,用于前端展示 0', + 'type': 'number' + }, + 'offlineTime': { + 'description': '下架时间', + 'type': 'string' + }, + 'onlineTime': { + 'description': '上架时间', + 'type': 'string' + }, + 'originalMarketPrice': { + 'description': '市场价格,db原始值 0', + 'type': 'integer' + }, + 'originalStandardPrice': { + 'description': '标准价格,用于筛选(就是sku里面的最低价格),db原始值 500000', + 'type': 'integer' + }, + 'qwMarketPrice': { + 'description': '市场价格 企微端-带多位小数 "0"', + 'type': 'string' + }, + 'qwStandardPrice': { + 'description': '标准价格,企微端-带多位小数 "50"', + 'type': 'string' + }, + 'standardPrice': { + 'description': '标准价格,用于筛选(就是sku里面的最低价格),用于前端展示 50', + 'type': 'number' + }, + 'unsalableWarning': { + 'type': 'object', + 'properties': { + 'day': { + 'description': '滞销天数', + 'type': 'integer' + }, + 'enable': { + 'description': '是否开启滞销预警', + 'type': 'boolean' + }, + 'value': { + 'description': '滞销阀值', + 'type': 'integer' + } + }, + '$$ref': '#/definitions/goods.unsalableWarning' + } + }, + '$$ref': '#/definitions/goods.goodsExt' + }, + 'goodsParams': { + 'type': 'array', + 'items': { + 'type': 'object', + 'properties': { + 'id': { + 'description': 'id', + 'type': 'string' + }, + 'isShowAtDetail': { + 'description': '是否展示在商详页', + 'type': 'boolean' + }, + 'name': { + 'description': '名称', + 'type': 'string' + }, + 'paramValue': { + 'description': '参数值', + 'type': 'array', + 'items': { + 'type': 'string' + } + } + }, + '$$ref': '#/definitions/goods.DetailGoodsShowParams' + } + }, + 'h5MallLink': { + 'description': 'H5 商城链接地址 (内部用-商品列表)', + 'type': 'string' + }, + 'hasCoupon': { + 'description': '是否展示优惠券', + 'type': 'boolean' + }, + 'hasSaleLimit': { + 'description': '是否限购', + 'type': 'boolean' + }, + 'hasSaleWeight': { + 'description': '销量加权值开启,关闭', + 'type': 'boolean' + }, + 'highestActivityPrice': { + 'description': '活动最高价', + 'type': 'number' + }, + 'hqGoodsStatus': { + 'description': '总部商品状态(1:上架,2:下架)(代理商模式下才有效)', + 'type': 'integer' + }, + 'inventoryStatus': { + 'description': '售罄状态 0=售罄 1=未售罄', + 'type': 'integer' + }, + 'isDib': { + 'description': '是否为分销商品', + 'type': 'boolean' + }, + 'isMemberSaleLimit': { + 'description': '是否限购', + 'type': 'boolean' + }, + 'isPriceZero': { + 'description': '判断价格是否小于0.01 true 小于0.01 false 大于0.01', + 'type': 'boolean' + }, + 'isSync': { + 'description': '是否同步代理商', + 'type': 'boolean' + }, + 'limitPurchaseNum': { + 'description': '限购数量', + 'type': 'integer' + }, + 'lowestActivityPrice': { + 'description': '活动最低价', + 'type': 'number' + }, + 'materialId': { + 'description': '素材ID', + 'type': 'string' + }, + 'memberSaleLimit': { + 'description': '用户可购买数量 只对付费优惠券类型生效', + 'type': 'integer' + }, + 'name': { + 'description': '商品名称', + 'type': 'string' + }, + 'offlineTime': { + 'description': '下架时间', + 'type': 'string' + }, + 'onlineTime': { + 'description': '上架时间', + 'type': 'string' + }, + 'rebate': { + 'description': '具体佣金金额', + 'type': 'number' + }, + 'rebateRatio': { + 'description': '佣金比例', + 'type': 'string' + }, + 'rebateTime': { + 'description': '成为分销商品的时间', + 'type': 'string' + }, + 'remark': { + 'description': '备注', + 'type': 'string' + }, + 'resources': { + 'type': 'object', + 'properties': { + 'detailImages': { + 'description': '详情图', + 'type': 'array', + 'items': { + 'type': 'object', + 'properties': { + 'name': { + 'description': '图片名称', + 'type': 'string' + }, + 'url': { + 'description': '图片地址', + 'type': 'string' + } + }, + '$$ref': '#/definitions/goods.goodsImage' + } + }, + 'detailVideoCovers': { + 'description': '详情视频封面', + 'type': 'array', + 'items': { + 'type': 'string' + } + }, + 'detailVideos': { + 'description': '详情视频', + 'type': 'array', + 'items': { + 'type': 'object', + 'properties': { + 'name': { + 'description': '视频名称', + 'type': 'string' + }, + 'second': { + 'description': '视频长度,单位:秒', + 'type': 'integer' + }, + 'size': { + 'description': '视频大小,单位:字节', + 'type': 'integer' + }, + 'url': { + 'description': '视频地址', + 'type': 'string' + } + }, + '$$ref': '#/definitions/goods.goodsVideo' + } + }, + 'images': { + 'description': '头图图片', + 'type': 'array', + 'items': { + 'type': 'object', + 'properties': { + 'name': { + 'description': '图片名称', + 'type': 'string' + }, + 'url': { + 'description': '图片地址', + 'type': 'string' + } + }, + '$$ref': '#/definitions/goods.goodsImage' + } + }, + 'videoCovers': { + 'description': '头图视频封面', + 'type': 'array', + 'items': { + 'type': 'string' + } + }, + 'videos': { + 'description': '头图视频', + 'type': 'array', + 'items': { + 'type': 'object', + 'properties': { + 'name': { + 'description': '视频名称', + 'type': 'string' + }, + 'second': { + 'description': '视频长度,单位:秒', + 'type': 'integer' + }, + 'size': { + 'description': '视频大小,单位:字节', + 'type': 'integer' + }, + 'url': { + 'description': '视频地址', + 'type': 'string' + } + }, + '$$ref': '#/definitions/goods.goodsVideo' + } + } + }, + '$$ref': '#/definitions/goods.ValGoodsResource' + }, + 'richText': { + 'description': '图文详情', + 'type': 'string' + }, + 'saleLimit': { + 'description': '限购数量', + 'type': 'integer' + }, + 'saleWeight': { + 'description': '销售加权值', + 'type': 'integer' + }, + 'sales': { + 'description': '商品销量', + 'type': 'integer' + }, + 'selfPickAddrList': { + 'description': '自提地点', + 'type': 'array', + 'items': { + 'type': 'object', + 'properties': { + 'addressDetail': { + 'description': '详细地址,省市区+详细地址', + 'type': 'string' + }, + 'addressId': { + 'description': '关联自提点ID', + 'type': 'string' + }, + 'addressName': { + 'description': '自提点名称', + 'type': 'string' + }, + 'enable': { + 'description': '地址开启状态', + 'type': 'boolean' + }, + 'forWardTimeValue': { + 'description': '非必须 预约自提时间数值 天范围1-30 小时范围1-24 分支范围1-60', + 'type': 'integer' + }, + 'forwardTimeType': { + 'description': '预约自提时间类型 1=天 2=小时 3=分钟', + 'type': 'integer' + }, + 'goodsId': { + 'description': '商品ID', + 'type': 'string' + }, + 'isDefault': { + 'description': '是否是默认自提点', + 'type': 'boolean' + }, + 'isForward': { + 'description': '自提是否提前联系', + 'type': 'boolean' + } + }, + '$$ref': '#/definitions/mallveriflication.GoodsSelfPickAddr' + } + }, + 'sendWays': { + 'description': '配送方式,1自提,2物流', + 'type': 'integer' + }, + 'showType': { + 'description': '是否在C端展示', + 'type': 'boolean' + }, + 'skus': { + 'description': '商品sku列表,列表不返回当前数据', + 'type': 'array', + 'items': { + 'type': 'object', + 'properties': { + '_id': { + 'description': 'skuId,不传表示新建', + 'type': 'string' + }, + 'activityPrice': { + 'description': '活动价格', + 'type': 'number' + }, + 'attributeItems': { + 'description': '规格-子选项', + 'type': 'array', + 'items': { + 'type': 'string' + } + }, + 'code': { + 'description': '编码,sku标识', + 'type': 'string' + }, + 'const': { + 'description': '成本 小数点2位之前', + 'type': 'number' + }, + 'default': { + 'description': '默认sku,如果商品未选择规格会默认生成一个sku的哦', + 'type': 'boolean' + }, + 'inventory': { + 'description': '库存', + 'type': 'integer' + }, + 'itemUnits': { + 'description': '计量单位(销售单位)', + 'type': 'string' + }, + 'itemWeight': { + 'description': '重量、保留2位小数', + 'type': 'number' + }, + 'maxRrp': { + 'description': '代理商的 max recommend retail price', + 'type': 'number' + }, + 'minRrp': { + 'description': '代理商的 min recommend retail price', + 'type': 'number' + }, + 'name': { + 'description': 'sku名字,多个规格拼接后的名字,例如,白色-M,红色-L', + 'type': 'string' + }, + 'originalCost': { + 'description': '成本,原始值,用于服务间使用', + 'type': 'integer' + }, + 'originalPrice': { + 'description': '价格,原始值,用于服务间使用', + 'type': 'integer' + }, + 'price': { + 'description': '价格 小数点2位之前', + 'type': 'number' + }, + 'qwConst': { + 'description': '成本 小数点多位', + 'type': 'string' + }, + 'qwPrice': { + 'description': '企微端,小数点多位', + 'type': 'string' + }, + 'rebate': { + 'description': '具体佣金金额', + 'type': 'number' + } + }, + '$$ref': '#/definitions/goods.Sku' + } + }, + 'snowflakeId': { + 'description': '雪花ID,前端展示用,制作为展示,不能用于商品详情查询,切记', + 'type': 'string' + }, + 'startPurchaseNum': { + 'description': '起购数量', + 'type': 'integer' + }, + 'startPurchaseScope': { + 'description': '起购数量的控制范围--1、全渠道,2:仅商城', + 'type': 'integer' + }, + 'status': { + 'description': '商品状态(1:上架,2:下架)', + 'type': 'integer' + }, + 'syncSet': { + 'description': '同步商品设置 1:商品标题 2:商品图片 3:标准价格', + 'type': 'integer' + }, + 'totalInventory': { + 'description': '总库存,所有sku剩余库存相加', + 'type': 'integer' + }, + 'trashedAt': { + 'description': '商品删除时间', + 'type': 'string' + }, + 'type': { + 'description': '商品类型(1:普通商品,2:虚拟商品,3:付费优惠券)', + 'type': 'integer' + }, + 'units': { + 'type': 'object', + 'properties': { + 'name': { + 'description': '单位', + 'type': 'string' + } + }, + '$$ref': '#/definitions/goods.goodsUnit' + }, + 'walletStatus': { + 'description': '0-功能未开启, 1-该商品不支持余额支付, 3-该商品支持余额支付(bitmap:从右往左,第一位控制功能开关,第二位控制商品是否支持)', + 'type': 'integer' + }, + 'weights': { + 'description': '权重', + 'type': 'integer' + } + }, + '$$ref': '#/definitions/goods.Res' + }, + 'msg': { + 'description': '请求结果的message', + 'type': 'string', + 'example': 'ok' + }, + 'success': { + 'description': '请求结果,失败:false,成功:true', + 'type': 'boolean', + 'example': true + } + }, + '$$ref': '#/definitions/http.goodsDetailRes' +} + +export default target \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..c87660e --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,27 @@ +{ + "compilerOptions": { + "target": "esnext", + "module": "esnext", + "strict": true, + "importHelpers": true, + "moduleResolution": "node", + "esModuleInterop": true, + "allowSyntheticDefaultImports": true, + "experimentalDecorators":true, + "sourceMap": true, + "skipLibCheck": true, + "baseUrl": ".", + "lib": [ + "esnext", + ], + "noImplicitAny": false + }, + "ts-node": { + "esm": true, + "experimentalSpecifierResolution": true + }, + "exclude": [ + "node_modules", + ] + } + \ No newline at end of file diff --git a/yapi.ts b/yapi.ts new file mode 100644 index 0000000..46bd95e --- /dev/null +++ b/yapi.ts @@ -0,0 +1,26 @@ +export const YapiType = ['string' , 'boolean' , 'integer' , 'object' , 'array' , 'number'] as const +export type UnionYapiType = typeof YapiType[number] + +interface BasePropertie { + type: T, + description?: string, + example?: string | boolean, + required?: string[], + default?: string | boolean | number, + $$ref?: string +} +interface NormalPropertie extends BasePropertie<'string' | 'boolean' | 'integer' | 'number'> { + type: 'string' | 'boolean' | 'integer' | 'number', +} +interface ObjectPropertie extends BasePropertie<'object'> { + type: 'object', + properties: { + [s in string]: Propertie + }, +} +interface ArrayPropertie extends BasePropertie<'array'> { + type: 'array', + items: Propertie, +} +export type Propertie = NormalPropertie | ObjectPropertie | ArrayPropertie + \ No newline at end of file diff --git a/yarn.lock b/yarn.lock new file mode 100644 index 0000000..800bb2e --- /dev/null +++ b/yarn.lock @@ -0,0 +1,257 @@ +# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. +# yarn lockfile v1 + + +"@cspotcode/source-map-support@^0.8.0": + version "0.8.1" + resolved "https://npm.dustess.com/@cspotcode%2fsource-map-support/-/source-map-support-0.8.1.tgz#00629c35a688e05a88b1cda684fb9d5e73f000a1" + integrity sha512-IchNf6dN4tHoMFIn/7OE8LWZ19Y6q/67Bmf6vnGREv8RSbBVb9LPJxEcnwrcwX6ixSvaiGoomAUvu4YSxXrVgw== + dependencies: + "@jridgewell/trace-mapping" "0.3.9" + +"@jridgewell/resolve-uri@^3.0.3": + version "3.1.0" + resolved "https://npm.dustess.com/@jridgewell%2fresolve-uri/-/resolve-uri-3.1.0.tgz#2203b118c157721addfe69d47b70465463066d78" + integrity sha512-F2msla3tad+Mfht5cJq7LSXcdudKTWCVYUgw6pLFOOHSTtZlj6SWNYAp+AhuqLmWdBO2X5hPrLcu8cVP8fy28w== + +"@jridgewell/sourcemap-codec@^1.4.10": + version "1.4.14" + resolved "https://npm.dustess.com/@jridgewell%2fsourcemap-codec/-/sourcemap-codec-1.4.14.tgz#add4c98d341472a289190b424efbdb096991bb24" + integrity sha512-XPSJHWmi394fuUuzDnGz1wiKqWfo1yXecHQMRf2l6hztTO+nPru658AyDngaBe7isIxEkRsPR3FZh+s7iVa4Uw== + +"@jridgewell/trace-mapping@0.3.9": + version "0.3.9" + resolved "https://npm.dustess.com/@jridgewell%2ftrace-mapping/-/trace-mapping-0.3.9.tgz#6534fd5933a53ba7cbf3a17615e273a0d1273ff9" + integrity sha512-3Belt6tdc8bPgAtbcmdtNJlirVoTmEb5e2gC94PnkwEW9jI6CAHUeoG85tjWP5WquqfavoMtMwiG4P926ZKKuQ== + dependencies: + "@jridgewell/resolve-uri" "^3.0.3" + "@jridgewell/sourcemap-codec" "^1.4.10" + +"@tsconfig/node10@^1.0.7": + version "1.0.9" + resolved "https://npm.dustess.com/@tsconfig%2fnode10/-/node10-1.0.9.tgz#df4907fc07a886922637b15e02d4cebc4c0021b2" + integrity sha512-jNsYVVxU8v5g43Erja32laIDHXeoNvFEpX33OK4d6hljo3jDhCBDhx5dhCCTMWUojscpAagGiRkBKxpdl9fxqA== + +"@tsconfig/node12@^1.0.7": + version "1.0.11" + resolved "https://npm.dustess.com/@tsconfig%2fnode12/-/node12-1.0.11.tgz#ee3def1f27d9ed66dac6e46a295cffb0152e058d" + integrity sha512-cqefuRsh12pWyGsIoBKJA9luFu3mRxCA+ORZvA4ktLSzIuCUtWVxGIuXigEwO5/ywWFMZ2QEGKWvkZG1zDMTag== + +"@tsconfig/node14@^1.0.0": + version "1.0.3" + resolved "https://npm.dustess.com/@tsconfig%2fnode14/-/node14-1.0.3.tgz#e4386316284f00b98435bf40f72f75a09dabf6c1" + integrity sha512-ysT8mhdixWK6Hw3i1V2AeRqZ5WfXg1G43mqoYlM2nc6388Fq5jcXyr5mRsqViLx/GJYdoL0bfXD8nmF+Zn/Iow== + +"@tsconfig/node16@^1.0.2": + version "1.0.3" + resolved "https://npm.dustess.com/@tsconfig%2fnode16/-/node16-1.0.3.tgz#472eaab5f15c1ffdd7f8628bd4c4f753995ec79e" + integrity sha512-yOlFc+7UtL/89t2ZhjPvvB/DeAr3r+Dq58IgzsFkOAvVC6NMJXmCGjbptdXdR9qsX7pKcTL+s87FtYREi2dEEQ== + +"@types/node@^18.11.0": + version "18.11.0" + resolved "https://npm.dustess.com/@types%2fnode/-/node-18.11.0.tgz#f38c7139247a1d619f6cc6f27b072606af7c289d" + integrity sha512-IOXCvVRToe7e0ny7HpT/X9Rb2RYtElG1a+VshjwT00HxrM2dWBApHQoqsI6WiY7Q03vdf2bCrIGzVrkF/5t10w== + +acorn-walk@^8.1.1: + version "8.2.0" + resolved "https://npm.dustess.com/acorn-walk/-/acorn-walk-8.2.0.tgz#741210f2e2426454508853a2f44d0ab83b7f69c1" + integrity sha1-dBIQ8uJCZFRQiFOi9E0KuDt/acE= + +acorn@^8.4.1: + version "8.8.0" + resolved "https://npm.dustess.com/acorn/-/acorn-8.8.0.tgz#88c0187620435c7f6015803f5539dae05a9dbea8" + integrity sha512-QOxyigPVrpZ2GXT+PFyZTl6TtOFc5egxHIP9IlQ+RbupQuX4RkT/Bee4/kQuC02Xkzg84JcT7oLYtDIQxp+v7w== + +arch@^2.2.0: + version "2.2.0" + resolved "https://npm.dustess.com/arch/-/arch-2.2.0.tgz#1bc47818f305764f23ab3306b0bfc086c5a29d11" + integrity sha1-G8R4GPMFdk8jqzMGsL/AhsWinRE= + +arg@^4.1.0: + version "4.1.3" + resolved "https://npm.dustess.com/arg/-/arg-4.1.3.tgz#269fc7ad5b8e42cb63c896d5666017261c144089" + integrity sha1-Jp/HrVuOQstjyJbVZmAXJhwUQIk= + +clipboardy@^3.0.0: + version "3.0.0" + resolved "https://npm.dustess.com/clipboardy/-/clipboardy-3.0.0.tgz#f3876247404d334c9ed01b6f269c11d09a5e3092" + integrity sha1-84diR0BNM0ye0BtvJpwR0JpeMJI= + dependencies: + arch "^2.2.0" + execa "^5.1.1" + is-wsl "^2.2.0" + +copy-to-clipboard@^3.3.2: + version "3.3.2" + resolved "https://npm.dustess.com/copy-to-clipboard/-/copy-to-clipboard-3.3.2.tgz#5b263ec2366224b100181dded7ce0579b340c107" + integrity sha512-Vme1Z6RUDzrb6xAI7EZlVZ5uvOk2F//GaxKUxajDqm9LhOVM1inxNAD2vy+UZDYsd0uyA9s7b3/FVZPSxqrCfg== + dependencies: + toggle-selection "^1.0.6" + +create-require@^1.1.0: + version "1.1.1" + resolved "https://npm.dustess.com/create-require/-/create-require-1.1.1.tgz#c1d7e8f1e5f6cfc9ff65f9cd352d37348756c333" + integrity sha1-wdfo8eX2z8n/ZfnNNS03NIdWwzM= + +cross-spawn@^7.0.3: + version "7.0.3" + resolved "https://npm.dustess.com/cross-spawn/-/cross-spawn-7.0.3.tgz#f73a85b9d5d41d045551c177e2882d4ac85728a6" + integrity sha1-9zqFudXUHQRVUcF34ogtSshXKKY= + dependencies: + path-key "^3.1.0" + shebang-command "^2.0.0" + which "^2.0.1" + +diff@^4.0.1: + version "4.0.2" + resolved "https://npm.dustess.com/diff/-/diff-4.0.2.tgz#60f3aecb89d5fae520c11aa19efc2bb982aade7d" + integrity sha1-YPOuy4nV+uUgwRqhnvwruYKq3n0= + +execa@^5.1.1: + version "5.1.1" + resolved "https://npm.dustess.com/execa/-/execa-5.1.1.tgz#f80ad9cbf4298f7bd1d4c9555c21e93741c411dd" + integrity sha1-+ArZy/Qpj3vR1MlVXCHpN0HEEd0= + dependencies: + cross-spawn "^7.0.3" + get-stream "^6.0.0" + human-signals "^2.1.0" + is-stream "^2.0.0" + merge-stream "^2.0.0" + npm-run-path "^4.0.1" + onetime "^5.1.2" + signal-exit "^3.0.3" + strip-final-newline "^2.0.0" + +get-stream@^6.0.0: + version "6.0.1" + resolved "https://npm.dustess.com/get-stream/-/get-stream-6.0.1.tgz#a262d8eef67aced57c2852ad6167526a43cbf7b7" + integrity sha1-omLY7vZ6ztV8KFKtYWdSakPL97c= + +human-signals@^2.1.0: + version "2.1.0" + resolved "https://npm.dustess.com/human-signals/-/human-signals-2.1.0.tgz#dc91fcba42e4d06e4abaed33b3e7a3c02f514ea0" + integrity sha1-3JH8ukLk0G5Kuu0zs+ejwC9RTqA= + +is-docker@^2.0.0: + version "2.2.1" + resolved "https://npm.dustess.com/is-docker/-/is-docker-2.2.1.tgz#33eeabe23cfe86f14bde4408a02c0cfb853acdaa" + integrity sha1-M+6r4jz+hvFL3kQIoCwM+4U6zao= + +is-stream@^2.0.0: + version "2.0.1" + resolved "https://npm.dustess.com/is-stream/-/is-stream-2.0.1.tgz#fac1e3d53b97ad5a9d0ae9cef2389f5810a5c077" + integrity sha1-+sHj1TuXrVqdCunO8jifWBClwHc= + +is-wsl@^2.2.0: + version "2.2.0" + resolved "https://npm.dustess.com/is-wsl/-/is-wsl-2.2.0.tgz#74a4c76e77ca9fd3f932f290c17ea326cd157271" + integrity sha1-dKTHbnfKn9P5MvKQwX6jJs0VcnE= + dependencies: + is-docker "^2.0.0" + +isexe@^2.0.0: + version "2.0.0" + resolved "https://npm.dustess.com/isexe/-/isexe-2.0.0.tgz#e8fbf374dc556ff8947a10dcb0572d633f2cfa10" + integrity sha1-6PvzdNxVb/iUehDcsFctYz8s+hA= + +make-error@^1.1.1: + version "1.3.6" + resolved "https://npm.dustess.com/make-error/-/make-error-1.3.6.tgz#2eb2e37ea9b67c4891f684a1394799af484cf7a2" + integrity sha1-LrLjfqm2fEiR9oShOUeZr0hM96I= + +merge-stream@^2.0.0: + version "2.0.0" + resolved "https://npm.dustess.com/merge-stream/-/merge-stream-2.0.0.tgz#52823629a14dd00c9770fb6ad47dc6310f2c1f60" + integrity sha1-UoI2KaFN0AyXcPtq1H3GMQ8sH2A= + +mimic-fn@^2.1.0: + version "2.1.0" + resolved "https://npm.dustess.com/mimic-fn/-/mimic-fn-2.1.0.tgz#7ed2c2ccccaf84d3ffcb7a69b57711fc2083401b" + integrity sha1-ftLCzMyvhNP/y3pptXcR/CCDQBs= + +npm-run-path@^4.0.1: + version "4.0.1" + resolved "https://npm.dustess.com/npm-run-path/-/npm-run-path-4.0.1.tgz#b7ecd1e5ed53da8e37a55e1c2269e0b97ed748ea" + integrity sha1-t+zR5e1T2o43pV4cImnguX7XSOo= + dependencies: + path-key "^3.0.0" + +onetime@^5.1.2: + version "5.1.2" + resolved "https://npm.dustess.com/onetime/-/onetime-5.1.2.tgz#d0e96ebb56b07476df1dd9c4806e5237985ca45e" + integrity sha1-0Oluu1awdHbfHdnEgG5SN5hcpF4= + dependencies: + mimic-fn "^2.1.0" + +path-key@^3.0.0, path-key@^3.1.0: + version "3.1.1" + resolved "https://npm.dustess.com/path-key/-/path-key-3.1.1.tgz#581f6ade658cbba65a0d3380de7753295054f375" + integrity sha1-WB9q3mWMu6ZaDTOA3ndTKVBU83U= + +shebang-command@^2.0.0: + version "2.0.0" + resolved "https://npm.dustess.com/shebang-command/-/shebang-command-2.0.0.tgz#ccd0af4f8835fbdc265b82461aaf0c36663f34ea" + integrity sha1-zNCvT4g1+9wmW4JGGq8MNmY/NOo= + dependencies: + shebang-regex "^3.0.0" + +shebang-regex@^3.0.0: + version "3.0.0" + resolved "https://npm.dustess.com/shebang-regex/-/shebang-regex-3.0.0.tgz#ae16f1644d873ecad843b0307b143362d4c42172" + integrity sha1-rhbxZE2HPsrYQ7AwexQzYtTEIXI= + +signal-exit@^3.0.3: + version "3.0.7" + resolved "https://npm.dustess.com/signal-exit/-/signal-exit-3.0.7.tgz#a9a1767f8af84155114eaabd73f99273c8f59ad9" + integrity sha512-wnD2ZE+l+SPC/uoS0vXeE9L1+0wuaMqKlfz9AMUo38JsyLSBWSFcHR1Rri62LZc12vLr1gb3jl7iwQhgwpAbGQ== + +strip-final-newline@^2.0.0: + version "2.0.0" + resolved "https://npm.dustess.com/strip-final-newline/-/strip-final-newline-2.0.0.tgz#89b852fb2fcbe936f6f4b3187afb0a12c1ab58ad" + integrity sha1-ibhS+y/L6Tb29LMYevsKEsGrWK0= + +toggle-selection@^1.0.6: + version "1.0.6" + resolved "https://npm.dustess.com/toggle-selection/-/toggle-selection-1.0.6.tgz#6e45b1263f2017fa0acc7d89d78b15b8bf77da32" + integrity sha1-bkWxJj8gF/oKzH2J14sVuL932jI= + +ts-node@^10.9.1: + version "10.9.1" + resolved "https://npm.dustess.com/ts-node/-/ts-node-10.9.1.tgz#e73de9102958af9e1f0b168a6ff320e25adcff4b" + integrity sha512-NtVysVPkxxrwFGUUxGYhfux8k78pQB3JqYBXlLRZgdGUqTO5wU/UyHop5p70iEbGhB7q5KmiZiU0Y3KlJrScEw== + dependencies: + "@cspotcode/source-map-support" "^0.8.0" + "@tsconfig/node10" "^1.0.7" + "@tsconfig/node12" "^1.0.7" + "@tsconfig/node14" "^1.0.0" + "@tsconfig/node16" "^1.0.2" + acorn "^8.4.1" + acorn-walk "^8.1.1" + arg "^4.1.0" + create-require "^1.1.0" + diff "^4.0.1" + make-error "^1.1.1" + v8-compile-cache-lib "^3.0.1" + yn "3.1.1" + +typescript@^4.8.4: + version "4.8.4" + resolved "https://npm.dustess.com/typescript/-/typescript-4.8.4.tgz#c464abca159669597be5f96b8943500b238e60e6" + integrity sha512-QCh+85mCy+h0IGff8r5XWzOVSbBO+KfeYrMQh7NJ58QujwcE22u+NUSmUxqF+un70P9GXKxa2HCNiTTMJknyjQ== + +v8-compile-cache-lib@^3.0.1: + version "3.0.1" + resolved "https://npm.dustess.com/v8-compile-cache-lib/-/v8-compile-cache-lib-3.0.1.tgz#6336e8d71965cb3d35a1bbb7868445a7c05264bf" + integrity sha512-wa7YjyUGfNZngI/vtK0UHAN+lgDCxBPCylVXGp0zu59Fz5aiGtNXaq3DhIov063MorB+VfufLh3JlF2KdTK3xg== + +which@^2.0.1: + version "2.0.2" + resolved "https://npm.dustess.com/which/-/which-2.0.2.tgz#7c6a8dd0a636a0327e10b59c9286eee93f3f51b1" + integrity sha1-fGqN0KY2oDJ+ELWckobu6T8/UbE= + dependencies: + isexe "^2.0.0" + +yn@3.1.1: + version "3.1.1" + resolved "https://npm.dustess.com/yn/-/yn-3.1.1.tgz#1e87401a09d767c1d5eab26a6e4c185182d2eb50" + integrity sha1-HodAGgnXZ8HV6rJqbkwYUYLS61A= From 7f126275dae06687cd104e2bbe82eaf61a145207 Mon Sep 17 00:00:00 2001 From: as Date: Tue, 18 Oct 2022 23:36:35 +0800 Subject: [PATCH 2/7] feat: reset yarn lock file; add a demo file --- demoTM.js | 45 ++++++++++++++++++ yarn.lock | 140 +++++++++++++++++++++++++----------------------------- 2 files changed, 109 insertions(+), 76 deletions(-) create mode 100644 demoTM.js diff --git a/demoTM.js b/demoTM.js new file mode 100644 index 0000000..e8740e7 --- /dev/null +++ b/demoTM.js @@ -0,0 +1,45 @@ +var menu = [ + { + key:'menu_type_mode', + name: ['使用type类型','使用interface类型'], + defaultValue: true, + value: true, + id: undefined + } +]; + +for (let i=0;i Date: Wed, 19 Oct 2022 09:55:51 +0800 Subject: [PATCH 3/7] feat: update --- demoTM.js | 45 --------------------------------------- index.ts | 17 +++++++++++---- package.json | 7 ++++--- tools/tampermonkey.ts | 49 +++++++++++++++++++++++++++++++++++++++++++ tsconfig.json | 1 + yarn.lock | 5 +++++ 6 files changed, 72 insertions(+), 52 deletions(-) delete mode 100644 demoTM.js create mode 100644 tools/tampermonkey.ts diff --git a/demoTM.js b/demoTM.js deleted file mode 100644 index e8740e7..0000000 --- a/demoTM.js +++ /dev/null @@ -1,45 +0,0 @@ -var menu = [ - { - key:'menu_type_mode', - name: ['使用type类型','使用interface类型'], - defaultValue: true, - value: true, - id: undefined - } -]; - -for (let i=0;i { +const middleWare = {} +const defaultConfig = { + typeMode: false +} + +const transformer = (tree: BaseLeaf[],config?:typeof defaultConfig) => { + const _conf = { + ...defaultConfig, + ...config + } let res:string[] = [] for (let i = 0; i < tree.length; i++) { const currentLeaf = tree[i] - // const interfaceName = currentLeaf.type === 'object' ? - let text = `interface ${currentLeaf.type} {\n` + let text = + _conf.typeMode?`type ${currentLeaf.type} = {\n`:`interface ${currentLeaf.type} {\n` currentLeaf.children?.forEach(item=>{ if(item.description){ - text += ` // ${item.description}\n` + text += ` /** ${item.description} */\n` } text += ` ${item.name}: ${item.type}${item.isArray?'[]':''};\n` }) diff --git a/package.json b/package.json index fe8f177..aebeb83 100644 --- a/package.json +++ b/package.json @@ -9,12 +9,13 @@ "author": "", "license": "ISC", "dependencies": { - "clipboardy": "^3.0.0", - "typescript": "^4.8.4" + "clipboardy": "^3.0.0" }, "type": "module", "devDependencies": { "@types/node": "^18.11.0", - "ts-node": "^10.9.1" + "@types/tampermonkey": "^4.0.5", + "ts-node": "^10.9.1", + "typescript": "^4.8.4" } } diff --git a/tools/tampermonkey.ts b/tools/tampermonkey.ts new file mode 100644 index 0000000..ba89be5 --- /dev/null +++ b/tools/tampermonkey.ts @@ -0,0 +1,49 @@ + +type MenuItem = { + key: string, + name: string[], + defaultValue: boolean, + value: boolean, + id?: number +} +const menu: MenuItem[] = [ + { + key: 'menu_type_mode', + name: ['使用type类型', '使用interface类型'], + defaultValue: true, + value: true, + id: undefined + } +]; + +// 注册脚本菜单 +function registerMenuCommand(menuItem?: MenuItem) { + if (menuItem) { + menuItem.value = GM_getValue(menuItem.key); + menuItem.id = GM_registerMenuCommand(menuItem.value ? menuItem.name[0] : menuItem.name[1], function () { menu_switch(menuItem) }); + } else { + for (let i = 0; i < menu.length; i++) { // 循环注册脚本菜单 + menu[i].value = GM_getValue(menu[i].key); + menu[i].id = GM_registerMenuCommand(menu[i].value ? menu[i].name[0] : menu[i].name[1], function () { menu_switch(menu[i]) }); + } + } +} +// 注销脚本菜单 +function unregisterMenuCommand(id:number) { + GM_unregisterMenuCommand(id) +} + +// 菜单开关 +function menu_switch(menuItem) { + if (menuItem.value == true) { + GM_setValue(menuItem.key, false); + GM_notification({ text: `${menuItem.name[0]}\n点击刷新网页后生效`, timeout: 3500, onclick: function () { location.reload(); } }); + } else { + GM_setValue(menuItem.key, true); + GM_notification({ text: `${menuItem.name[1]}\n点击刷新网页后生效`, timeout: 3500, onclick: function () { location.reload(); } }); + } + unregisterMenuCommand(menuItem.id) + registerMenuCommand(menuItem); // 重新注册脚本菜单 +}; + +registerMenuCommand(); \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json index c87660e..0637210 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -13,6 +13,7 @@ "baseUrl": ".", "lib": [ "esnext", + "dom" ], "noImplicitAny": false }, diff --git a/yarn.lock b/yarn.lock index 5180557..05e68a8 100644 --- a/yarn.lock +++ b/yarn.lock @@ -52,6 +52,11 @@ resolved "https://registry.yarnpkg.com/@types/node/-/node-18.11.0.tgz#f38c7139247a1d619f6cc6f27b072606af7c289d" integrity sha512-IOXCvVRToe7e0ny7HpT/X9Rb2RYtElG1a+VshjwT00HxrM2dWBApHQoqsI6WiY7Q03vdf2bCrIGzVrkF/5t10w== +"@types/tampermonkey@^4.0.5": + version "4.0.5" + resolved "https://registry.npmmirror.com/@types/tampermonkey/-/tampermonkey-4.0.5.tgz#03a0c2366a7c1fe5e1c77c88adf568f40b3c18e5" + integrity sha512-FGPo7d+qZkDF7vyrwY1WNhcUnfDyVpt2uyL7krAu3WKCUMCfIUzOuvt8aSk8N2axHT8XPr9stAEDGVHLvag6Pw== + acorn-walk@^8.1.1: version "8.2.0" resolved "https://registry.yarnpkg.com/acorn-walk/-/acorn-walk-8.2.0.tgz#741210f2e2426454508853a2f44d0ab83b7f69c1" From 01277d8ba5154a617efb124b99bfbed1a80115bc Mon Sep 17 00:00:00 2001 From: as Date: Wed, 19 Oct 2022 14:51:00 +0800 Subject: [PATCH 4/7] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0rollup=EF=BC=8C?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E7=A2=8E=E7=89=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- base.ts | 40 +++++++--- index.ts | 22 +++--- package.json | 7 +- rollup.config.js | 24 ++++++ tools/Readme.md | 21 +++++ tools/tampermonkey.ts | 179 ++++++++++++++++++++++++++++++++++-------- tsconfig.json | 2 +- yarn.lock | 162 +++++++++++++++++++++++++++++++++++++- 8 files changed, 404 insertions(+), 53 deletions(-) create mode 100644 rollup.config.js create mode 100644 tools/Readme.md diff --git a/base.ts b/base.ts index 1b36787..77e0efa 100644 --- a/base.ts +++ b/base.ts @@ -21,10 +21,22 @@ export interface BaseLeaf { children?: BaseLeaf[], parent?: BaseLeaf, } -export const tree: BaseLeaf[] = [] -export const twig: BaseLeaf[] = [] - -export const toBaseLeaf = (key: string, propertie: Propertie, parent?: BaseLeaf) => { +export class ApiTree { + tree:BaseLeaf[] = [] + twig:BaseLeaf[] = [] +} +interface IToBaseLeaf { + key: string, + propertie: Propertie, + apiTree: ApiTree, + parent?: BaseLeaf +} +export const toBaseLeaf = ({ + key, + propertie, + apiTree, + parent +}:IToBaseLeaf) => { const leaf: BaseLeaf = { name: key, type: propertie.type, @@ -36,10 +48,15 @@ export const toBaseLeaf = (key: string, propertie: Propertie, parent?: BaseLeaf) leaf.children = [] for (const childKey in propertie.properties) { if (Object.prototype.hasOwnProperty.call(propertie.properties, childKey)) { - leaf.children.push(toBaseLeaf(childKey, propertie.properties[childKey], leaf)) + leaf.children.push(toBaseLeaf({ + key:childKey, + propertie:propertie.properties[childKey], + apiTree, + parent:leaf + })) } } - twig.push(leaf) + apiTree.twig.push(leaf) } if (propertie.type === 'array') { leaf.isArray = true @@ -47,16 +64,21 @@ export const toBaseLeaf = (key: string, propertie: Propertie, parent?: BaseLeaf) leaf.children = [] for (const childKey in propertie.items.properties) { if (Object.prototype.hasOwnProperty.call(propertie.items.properties, childKey)) { - leaf.children.push(toBaseLeaf(childKey, propertie.items.properties[childKey], leaf)) + leaf.children.push(toBaseLeaf({ + key:childKey, + propertie:propertie.items.properties[childKey], + apiTree, + parent:leaf + })) } } - twig.push(leaf) + apiTree.twig.push(leaf) } else { leaf.type = propertie.items.type } } leaf.type = toTypeName(leaf) - tree.push(leaf) + apiTree.tree.push(leaf) return leaf } const nameFactory = (value: string, parent?: BaseLeaf, isPrimary?: boolean) => { diff --git a/index.ts b/index.ts index e5a5c58..e77621a 100644 --- a/index.ts +++ b/index.ts @@ -1,6 +1,5 @@ // define -import { BaseLeaf, toBaseLeaf, twig } from './base'; -import clipboardy from 'clipboardy'; +import { ApiTree, BaseLeaf, toBaseLeaf } from './base'; import { Propertie } from './yapi'; const middleWare = {} @@ -8,14 +7,14 @@ const defaultConfig = { typeMode: false } -const transformer = (tree: BaseLeaf[],config?:typeof defaultConfig) => { +const transformer = (twig: BaseLeaf[],config?:typeof defaultConfig) => { const _conf = { ...defaultConfig, ...config } let res:string[] = [] - for (let i = 0; i < tree.length; i++) { - const currentLeaf = tree[i] + for (let i = 0; i < twig.length; i++) { + const currentLeaf = twig[i] let text = _conf.typeMode?`type ${currentLeaf.type} = {\n`:`interface ${currentLeaf.type} {\n` currentLeaf.children?.forEach(item=>{ @@ -29,11 +28,16 @@ const transformer = (tree: BaseLeaf[],config?:typeof defaultConfig) => { } return res; } -const runner = (name: string, propertie: Propertie) => { - toBaseLeaf(name, propertie) - const res = transformer(twig) +const runner = (name: string, propertie: Propertie, conf?: typeof defaultConfig) => { + const apiTree = new ApiTree() + toBaseLeaf({ + key: name, + propertie, + apiTree + }) + const res = transformer(apiTree.twig, conf) const dd = res.join('\n') - clipboardy.writeSync(dd); + return dd } const use = (fn)=>{ diff --git a/package.json b/package.json index aebeb83..8b746ab 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "description": "", "main": "index.js", "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" + "build": "rollup -c --bundleConfigAsCjs" }, "author": "", "license": "ISC", @@ -15,7 +15,12 @@ "devDependencies": { "@types/node": "^18.11.0", "@types/tampermonkey": "^4.0.5", + "rollup": "^3.2.3", + "rollup-plugin-commonjs": "^10.1.0", + "rollup-plugin-sourcemaps": "^0.6.3", + "rollup-plugin-typescript": "^1.0.1", "ts-node": "^10.9.1", + "tslib": "^2.4.0", "typescript": "^4.8.4" } } diff --git a/rollup.config.js b/rollup.config.js new file mode 100644 index 0000000..83c27e5 --- /dev/null +++ b/rollup.config.js @@ -0,0 +1,24 @@ +import typescript from "rollup-plugin-typescript"; +import sourceMaps from "rollup-plugin-sourcemaps"; +import commonjs from 'rollup-plugin-commonjs' +export default { + input: "./tools/tampermonkey.ts", + output: [ + { + format: "cjs", + file: "dist/bundle.cjs.js", + sourcemap: true + }, + { + format: "es", + file: "dist/bundle.esm.js" + } + ], + plugins: [ + commonjs({ + include: /node_modules/ + }), + typescript(), + sourceMaps() + ], +}; diff --git a/tools/Readme.md b/tools/Readme.md new file mode 100644 index 0000000..c6555f8 --- /dev/null +++ b/tools/Readme.md @@ -0,0 +1,21 @@ +# 在开头添加如下注释 + +```js +// ==UserScript== +// @name Yapi +// @namespace http://tampermonkey.net/ +// @version 0.1 +// @description try to take over the world! +// @author You +// @match https://*/project/* +// @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw== +// @grant GM_xmlhttpRequest +// @grant GM_registerMenuCommand +// @grant GM_unregisterMenuCommand +// @grant GM_openInTab +// @grant GM_getValue +// @grant GM_setValue +// @grant GM_notification +// ==/UserScript== + +``` diff --git a/tools/tampermonkey.ts b/tools/tampermonkey.ts index ba89be5..61fb8f8 100644 --- a/tools/tampermonkey.ts +++ b/tools/tampermonkey.ts @@ -1,49 +1,164 @@ +import { runner } from "../index" +import { Propertie } from "../yapi" type MenuItem = { - key: string, - name: string[], - defaultValue: boolean, - value: boolean, - id?: number + key: string, + name: string[], + defaultValue: boolean, + value: boolean, + id?: number +} +type YapiData = { + /** 描述 */ + desc: string, + /** 转换后的入参 */ + req: Propertie + /** 转换后的返回 */ + res: Propertie + /** 转换前的入参 */ + req_body_other: string + /** 转换前的返回 */ + res_body: string + /** 请求路径 */ + path: string + /** method */ + method: 'POST'|'GET' } const menu: MenuItem[] = [ - { - key: 'menu_type_mode', - name: ['使用type类型', '使用interface类型'], - defaultValue: true, - value: true, - id: undefined - } + { + key: 'menu_type_mode', + name: ['使用type类型', '使用interface类型'], + defaultValue: true, + value: true, + id: undefined + } ]; // 注册脚本菜单 function registerMenuCommand(menuItem?: MenuItem) { - if (menuItem) { - menuItem.value = GM_getValue(menuItem.key); - menuItem.id = GM_registerMenuCommand(menuItem.value ? menuItem.name[0] : menuItem.name[1], function () { menu_switch(menuItem) }); - } else { - for (let i = 0; i < menu.length; i++) { // 循环注册脚本菜单 - menu[i].value = GM_getValue(menu[i].key); - menu[i].id = GM_registerMenuCommand(menu[i].value ? menu[i].name[0] : menu[i].name[1], function () { menu_switch(menu[i]) }); - } + if (menuItem) { + menuItem.value = GM_getValue(menuItem.key); + menuItem.id = GM_registerMenuCommand(menuItem.value ? menuItem.name[0] : menuItem.name[1], function () { menu_switch(menuItem) }); + } else { + for (let i = 0; i < menu.length; i++) { // 循环注册脚本菜单 + menu[i].value = GM_getValue(menu[i].key); + menu[i].id = GM_registerMenuCommand(menu[i].value ? menu[i].name[0] : menu[i].name[1], function () { menu_switch(menu[i]) }); } + } } // 注销脚本菜单 -function unregisterMenuCommand(id:number) { - GM_unregisterMenuCommand(id) +function unregisterMenuCommand(id: number) { + GM_unregisterMenuCommand(id) } // 菜单开关 function menu_switch(menuItem) { - if (menuItem.value == true) { - GM_setValue(menuItem.key, false); - GM_notification({ text: `${menuItem.name[0]}\n点击刷新网页后生效`, timeout: 3500, onclick: function () { location.reload(); } }); - } else { - GM_setValue(menuItem.key, true); - GM_notification({ text: `${menuItem.name[1]}\n点击刷新网页后生效`, timeout: 3500, onclick: function () { location.reload(); } }); - } - unregisterMenuCommand(menuItem.id) - registerMenuCommand(menuItem); // 重新注册脚本菜单 + if (menuItem.value == true) { + GM_setValue(menuItem.key, false); + GM_notification({ text: `${menuItem.name[0]}\n点击刷新网页后生效`, timeout: 3500, onclick: function () { location.reload(); } }); + } else { + GM_setValue(menuItem.key, true); + GM_notification({ text: `${menuItem.name[1]}\n点击刷新网页后生效`, timeout: 3500, onclick: function () { location.reload(); } }); + } + unregisterMenuCommand(menuItem.id) + registerMenuCommand(menuItem); // 重新注册脚本菜单 }; -registerMenuCommand(); \ No newline at end of file +registerMenuCommand(); + + +async function getYApiData(): Promise { + const id = window.location.pathname.split('/')[5]; + const href = window.location.origin + '/api/interface/get?id=' + id; + + const yapiReq = await fetch(href, { + "body": null, + "method": "GET" + }); + + const { data } = await yapiReq.json(); + try { + data.req = JSON.parse(data.req_body_other) + data.res = JSON.parse(data.res_body) + } catch (error) { + console.warn(error) + } + return data +} + +const buttons = { + req: document.createElement('button'),// req + res: document.createElement('button'),// res +} +buttons.req.className = "lucky-btn" +buttons.res.className = "lucky-btn" + +buttons.req.addEventListener('click', async () => { + const data = await getYApiData() + if(data.method === 'GET'){ + alert('get请求暂不支持') + return + } + const name = data.path.split('/').map(p => p.charAt(0).toLocaleUpperCase() + p.slice(1)).join('') + 'Req'; + const res = runner(name, data.req, { typeMode: GM_getValue(menu[0].key) }) + console.log(res) + navigator.clipboard.writeText(res) + GM_notification({ text: `帮你放到剪贴板了,直接粘贴到文件吧`, timeout: 3500 }); +}) +buttons.res.addEventListener('click', async () => { + const data = await getYApiData() + if(data.method === 'GET'){ + alert('get请求暂不支持') + return + } + const name = data.path.split('/').map(p => p.charAt(0).toLocaleUpperCase() + p.slice(1)).join('') + 'Res'; + const res = runner(name, data.res, { typeMode: GM_getValue(menu[0].key) }) + console.log(res) + navigator.clipboard.writeText(res) + GM_notification({ text: `帮你放到剪贴板了,直接粘贴到文件吧`, timeout: 3500 }); +}) + +function insertButtons() { + const targetReqHtml = document.querySelectorAll('h2')[2]; + const targetResHtml = document.querySelectorAll('h2')[3]; + buttons.req.innerText = "TS " + GM_getValue(menu[0].key) ? "type" : "interface" + buttons.res.innerText = "TS " + GM_getValue(menu[0].key) ? "type" : "interface" + if (targetReqHtml) { + targetReqHtml.appendChild(buttons.req); + } + if (targetResHtml) { + targetResHtml.appendChild(buttons.res); + } +} +function addGlobalStyle(css: string) { + var head, style; + head = document.getElementsByTagName('head')[0]; + if (!head) { return; } + style = document.createElement('style'); + style.type = 'text/css'; + style.innerHTML = css; + head.appendChild(style); +} +addGlobalStyle(` +.lucky-btn { + font-size: 16px; + line-height: 16px; + border: aqua solid 1px; + border-radius: 4px; + padding: 2px 4px; + margin-left: 8px; + background: aquamarine; + color: white; + cursor: pointer; +} +`) + +setTimeout(() => { + insertButtons() + const apiChangeButton = document.querySelectorAll('.ant-tree-node-content-wrapper'); + apiChangeButton.forEach(bu => { + bu.addEventListener('click', () => { + insertButtons() + }); + }); +}, 2000) \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json index 0637210..a3e3fe1 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -15,7 +15,7 @@ "esnext", "dom" ], - "noImplicitAny": false + "noImplicitAny": false, }, "ts-node": { "esm": true, diff --git a/yarn.lock b/yarn.lock index 05e68a8..78ed2f1 100644 --- a/yarn.lock +++ b/yarn.lock @@ -27,6 +27,15 @@ "@jridgewell/resolve-uri" "^3.0.3" "@jridgewell/sourcemap-codec" "^1.4.10" +"@rollup/pluginutils@^3.0.9": + version "3.1.0" + resolved "https://registry.npmmirror.com/@rollup/pluginutils/-/pluginutils-3.1.0.tgz#706b4524ee6dc8b103b3c995533e5ad680c02b9b" + integrity sha512-GksZ6pr6TpIjHm8h9lSQ8pi8BE9VeubNT0OMJ3B5uZJ8pz73NPiqOtCog/x2/QzM1ENChPKxMDhiQuRHsqc+lg== + dependencies: + "@types/estree" "0.0.39" + estree-walker "^1.0.1" + picomatch "^2.2.2" + "@tsconfig/node10@^1.0.7": version "1.0.9" resolved "https://registry.yarnpkg.com/@tsconfig/node10/-/node10-1.0.9.tgz#df4907fc07a886922637b15e02d4cebc4c0021b2" @@ -47,6 +56,16 @@ resolved "https://registry.yarnpkg.com/@tsconfig/node16/-/node16-1.0.3.tgz#472eaab5f15c1ffdd7f8628bd4c4f753995ec79e" integrity sha512-yOlFc+7UtL/89t2ZhjPvvB/DeAr3r+Dq58IgzsFkOAvVC6NMJXmCGjbptdXdR9qsX7pKcTL+s87FtYREi2dEEQ== +"@types/estree@*": + version "1.0.0" + resolved "https://registry.npmmirror.com/@types/estree/-/estree-1.0.0.tgz#5fb2e536c1ae9bf35366eed879e827fa59ca41c2" + integrity sha512-WulqXMDUTYAXCjZnk6JtIHPigp55cVtDgDrO2gHRwhyJto21+1zbVCtOYB2L1F9w4qCQ0rOGWBnBe0FNTiEJIQ== + +"@types/estree@0.0.39": + version "0.0.39" + resolved "https://registry.npmmirror.com/@types/estree/-/estree-0.0.39.tgz#e177e699ee1b8c22d23174caaa7422644389509f" + integrity sha512-EYNwp3bU+98cpU4lAWYYL7Zz+2gryWH1qbdDTidVd6hkiR6weksdbMadyXKXNPEkQFhXM+hVO9ZygomHXp+AIw== + "@types/node@^18.11.0": version "18.11.0" resolved "https://registry.yarnpkg.com/@types/node/-/node-18.11.0.tgz#f38c7139247a1d619f6cc6f27b072606af7c289d" @@ -77,6 +96,11 @@ arg@^4.1.0: resolved "https://registry.yarnpkg.com/arg/-/arg-4.1.3.tgz#269fc7ad5b8e42cb63c896d5666017261c144089" integrity sha512-58S9QDqG0Xx27YwPSt9fJxivjYl432YCwfDMfZ+71RAqUrZef7LrKQZ3LHLOwCS4FLNBplP533Zx895SeOCHvA== +atob@^2.1.2: + version "2.1.2" + resolved "https://registry.npmmirror.com/atob/-/atob-2.1.2.tgz#6d9517eb9e030d2436666651e86bd9f6f13533c9" + integrity sha512-Wm6ukoaOGJi/73p/cl2GvLjTI5JM1k/O14isD73YML8StrH/7/lRFgmg8nICZgD3bZZvjwCGxtMOD3wWNAu8cg== + clipboardy@^3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/clipboardy/-/clipboardy-3.0.0.tgz#f3876247404d334c9ed01b6f269c11d09a5e3092" @@ -100,11 +124,26 @@ cross-spawn@^7.0.3: shebang-command "^2.0.0" which "^2.0.1" +decode-uri-component@^0.2.0: + version "0.2.0" + resolved "https://registry.npmmirror.com/decode-uri-component/-/decode-uri-component-0.2.0.tgz#eb3913333458775cb84cd1a1fae062106bb87545" + integrity sha512-hjf+xovcEn31w/EUYdTXQh/8smFL/dzYjohQGEIgjyNavaJfBY2p5F527Bo1VPATxv0VYTUC2bOcXvqFwk78Og== + diff@^4.0.1: version "4.0.2" resolved "https://registry.yarnpkg.com/diff/-/diff-4.0.2.tgz#60f3aecb89d5fae520c11aa19efc2bb982aade7d" integrity sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A== +estree-walker@^0.6.1: + version "0.6.1" + resolved "https://registry.npmmirror.com/estree-walker/-/estree-walker-0.6.1.tgz#53049143f40c6eb918b23671d1fe3219f3a1b362" + integrity sha512-SqmZANLWS0mnatqbSfRP5g8OXZC12Fgg1IwNtLsyHDzJizORW4khDfjPqJZsemPWBB2uqykUah5YpQ6epsqC/w== + +estree-walker@^1.0.1: + version "1.0.1" + resolved "https://registry.npmmirror.com/estree-walker/-/estree-walker-1.0.1.tgz#31bc5d612c96b704106b477e6dd5d8aa138cb700" + integrity sha512-1fMXF3YP4pZZVozF8j/ZLfvnR8NSIljt56UhbZ5PeeDmmGHpgpdwQt7ITlGvYaQukCvuBRMLEiKiYC+oeIg4cg== + execa@^5.1.1: version "5.1.1" resolved "https://registry.yarnpkg.com/execa/-/execa-5.1.1.tgz#f80ad9cbf4298f7bd1d4c9555c21e93741c411dd" @@ -120,21 +159,52 @@ execa@^5.1.1: signal-exit "^3.0.3" strip-final-newline "^2.0.0" +fsevents@~2.3.2: + version "2.3.2" + resolved "https://registry.npmmirror.com/fsevents/-/fsevents-2.3.2.tgz#8a526f78b8fdf4623b709e0b975c52c24c02fd1a" + integrity sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA== + +function-bind@^1.1.1: + version "1.1.1" + resolved "https://registry.npmmirror.com/function-bind/-/function-bind-1.1.1.tgz#a56899d3ea3c9bab874bb9773b7c5ede92f4895d" + integrity sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A== + get-stream@^6.0.0: version "6.0.1" resolved "https://registry.yarnpkg.com/get-stream/-/get-stream-6.0.1.tgz#a262d8eef67aced57c2852ad6167526a43cbf7b7" integrity sha512-ts6Wi+2j3jQjqi70w5AlN8DFnkSwC+MqmxEzdEALB2qXZYV3X/b1CTfgPLGJNMeAWxdPfU8FO1ms3NUfaHCPYg== +has@^1.0.3: + version "1.0.3" + resolved "https://registry.npmmirror.com/has/-/has-1.0.3.tgz#722d7cbfc1f6aa8241f16dd814e011e1f41e8796" + integrity sha512-f2dvO0VU6Oej7RkWJGrehjbzMAjFp5/VKPp5tTpWIV4JHHZK1/BxbFRtf/siA2SWTe09caDmVtYYzWEIbBS4zw== + dependencies: + function-bind "^1.1.1" + human-signals@^2.1.0: version "2.1.0" resolved "https://registry.yarnpkg.com/human-signals/-/human-signals-2.1.0.tgz#dc91fcba42e4d06e4abaed33b3e7a3c02f514ea0" integrity sha512-B4FFZ6q/T2jhhksgkbEW3HBvWIfDW85snkQgawt07S7J5QXTk6BkNV+0yAeZrM5QpMAdYlocGoljn0sJ/WQkFw== +is-core-module@^2.9.0: + version "2.11.0" + resolved "https://registry.npmmirror.com/is-core-module/-/is-core-module-2.11.0.tgz#ad4cb3e3863e814523c96f3f58d26cc570ff0144" + integrity sha512-RRjxlvLDkD1YJwDbroBHMb+cukurkDWNyHx7D3oNB5x9rb5ogcksMC5wHCadcXoo67gVr/+3GFySh3134zi6rw== + dependencies: + has "^1.0.3" + is-docker@^2.0.0: version "2.2.1" resolved "https://registry.yarnpkg.com/is-docker/-/is-docker-2.2.1.tgz#33eeabe23cfe86f14bde4408a02c0cfb853acdaa" integrity sha512-F+i2BKsFrH66iaUFc0woD8sLy8getkwTwtOBjvs56Cx4CgJDeKQeqfz8wAYiSb8JOprWhHH5p77PbmYCvvUuXQ== +is-reference@^1.1.2: + version "1.2.1" + resolved "https://registry.npmmirror.com/is-reference/-/is-reference-1.2.1.tgz#8b2dac0b371f4bc994fdeaba9eb542d03002d0b7" + integrity sha512-U82MsXXiFIrjCK4otLT+o2NA2Cd2g5MLoOVXUZjIOhLurrRxpEXzI8O0KZHr3IjLvlAH1kTPYSuqer5T9ZVBKQ== + dependencies: + "@types/estree" "*" + is-stream@^2.0.0: version "2.0.1" resolved "https://registry.yarnpkg.com/is-stream/-/is-stream-2.0.1.tgz#fac1e3d53b97ad5a9d0ae9cef2389f5810a5c077" @@ -152,6 +222,13 @@ isexe@^2.0.0: resolved "https://registry.yarnpkg.com/isexe/-/isexe-2.0.0.tgz#e8fbf374dc556ff8947a10dcb0572d633f2cfa10" integrity sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw== +magic-string@^0.25.2: + version "0.25.9" + resolved "https://registry.npmmirror.com/magic-string/-/magic-string-0.25.9.tgz#de7f9faf91ef8a1c91d02c2e5314c8277dbcdd1c" + integrity sha512-RmF0AsMzgt25qzqqLc1+MbHmhdx0ojF2Fvs4XnOqz2ZOBXzzkEwc/dJQZCYHAn7v1jbVOjAZfK8msRn4BxO4VQ== + dependencies: + sourcemap-codec "^1.4.8" + make-error@^1.1.1: version "1.3.6" resolved "https://registry.yarnpkg.com/make-error/-/make-error-1.3.6.tgz#2eb2e37ea9b67c4891f684a1394799af484cf7a2" @@ -186,6 +263,66 @@ path-key@^3.0.0, path-key@^3.1.0: resolved "https://registry.yarnpkg.com/path-key/-/path-key-3.1.1.tgz#581f6ade658cbba65a0d3380de7753295054f375" integrity sha512-ojmeN0qd+y0jszEtoY48r0Peq5dwMEkIlCOu6Q5f41lfkswXuKtYrhgoTpLnyIcHm24Uhqx+5Tqm2InSwLhE6Q== +path-parse@^1.0.7: + version "1.0.7" + resolved "https://registry.npmmirror.com/path-parse/-/path-parse-1.0.7.tgz#fbc114b60ca42b30d9daf5858e4bd68bbedb6735" + integrity sha512-LDJzPVEEEPR+y48z93A0Ed0yXb8pAByGWo/k5YYdYgpY2/2EsOsksJrq7lOHxryrVOn1ejG6oAp8ahvOIQD8sw== + +picomatch@^2.2.2: + version "2.3.1" + resolved "https://registry.npmmirror.com/picomatch/-/picomatch-2.3.1.tgz#3ba3833733646d9d3e4995946c1365a67fb07a42" + integrity sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA== + +resolve@^1.10.0, resolve@^1.11.0: + version "1.22.1" + resolved "https://registry.npmmirror.com/resolve/-/resolve-1.22.1.tgz#27cb2ebb53f91abb49470a928bba7558066ac177" + integrity sha512-nBpuuYuY5jFsli/JIs1oldw6fOQCBioohqWZg/2hiaOybXOft4lonv85uDOKXdf8rhyK159cxU5cDcK/NKk8zw== + dependencies: + is-core-module "^2.9.0" + path-parse "^1.0.7" + supports-preserve-symlinks-flag "^1.0.0" + +rollup-plugin-commonjs@^10.1.0: + version "10.1.0" + resolved "https://registry.npmmirror.com/rollup-plugin-commonjs/-/rollup-plugin-commonjs-10.1.0.tgz#417af3b54503878e084d127adf4d1caf8beb86fb" + integrity sha512-jlXbjZSQg8EIeAAvepNwhJj++qJWNJw1Cl0YnOqKtP5Djx+fFGkp3WRh+W0ASCaFG5w1jhmzDxgu3SJuVxPF4Q== + dependencies: + estree-walker "^0.6.1" + is-reference "^1.1.2" + magic-string "^0.25.2" + resolve "^1.11.0" + rollup-pluginutils "^2.8.1" + +rollup-plugin-sourcemaps@^0.6.3: + version "0.6.3" + resolved "https://registry.npmmirror.com/rollup-plugin-sourcemaps/-/rollup-plugin-sourcemaps-0.6.3.tgz#bf93913ffe056e414419607f1d02780d7ece84ed" + integrity sha512-paFu+nT1xvuO1tPFYXGe+XnQvg4Hjqv/eIhG8i5EspfYYPBKL57X7iVbfv55aNVASg3dzWvES9dmWsL2KhfByw== + dependencies: + "@rollup/pluginutils" "^3.0.9" + source-map-resolve "^0.6.0" + +rollup-plugin-typescript@^1.0.1: + version "1.0.1" + resolved "https://registry.npmmirror.com/rollup-plugin-typescript/-/rollup-plugin-typescript-1.0.1.tgz#86565033b714c3d1f3aba510aad3dc519f7091e9" + integrity sha512-rwJDNn9jv/NsKZuyBb/h0jsclP4CJ58qbvZt2Q9zDIGILF2LtdtvCqMOL+Gq9IVq5MTrTlHZNrn8h7VjQgd8tw== + dependencies: + resolve "^1.10.0" + rollup-pluginutils "^2.5.0" + +rollup-pluginutils@^2.5.0, rollup-pluginutils@^2.8.1: + version "2.8.2" + resolved "https://registry.npmmirror.com/rollup-pluginutils/-/rollup-pluginutils-2.8.2.tgz#72f2af0748b592364dbd3389e600e5a9444a351e" + integrity sha512-EEp9NhnUkwY8aif6bxgovPHMoMoNr2FulJziTndpt5H9RdwC47GSGuII9XxpSdzVGM0GWrNPHV6ie1LTNJPaLQ== + dependencies: + estree-walker "^0.6.1" + +rollup@^3.2.3: + version "3.2.3" + resolved "https://registry.npmmirror.com/rollup/-/rollup-3.2.3.tgz#67d894c981ad50cc811779748e52c05742560c64" + integrity sha512-qfadtkY5kl0F5e4dXVdj2D+GtOdifasXHFMiL1SMf9ADQDv5Eti6xReef9FKj+iQPR2pvtqWna57s/PjARY4fg== + optionalDependencies: + fsevents "~2.3.2" + shebang-command@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/shebang-command/-/shebang-command-2.0.0.tgz#ccd0af4f8835fbdc265b82461aaf0c36663f34ea" @@ -203,11 +340,29 @@ signal-exit@^3.0.3: resolved "https://registry.yarnpkg.com/signal-exit/-/signal-exit-3.0.7.tgz#a9a1767f8af84155114eaabd73f99273c8f59ad9" integrity sha512-wnD2ZE+l+SPC/uoS0vXeE9L1+0wuaMqKlfz9AMUo38JsyLSBWSFcHR1Rri62LZc12vLr1gb3jl7iwQhgwpAbGQ== +source-map-resolve@^0.6.0: + version "0.6.0" + resolved "https://registry.npmmirror.com/source-map-resolve/-/source-map-resolve-0.6.0.tgz#3d9df87e236b53f16d01e58150fc7711138e5ed2" + integrity sha512-KXBr9d/fO/bWo97NXsPIAW1bFSBOuCnjbNTBMO7N59hsv5i9yzRDfcYwwt0l04+VqnKC+EwzvJZIP/qkuMgR/w== + dependencies: + atob "^2.1.2" + decode-uri-component "^0.2.0" + +sourcemap-codec@^1.4.8: + version "1.4.8" + resolved "https://registry.npmmirror.com/sourcemap-codec/-/sourcemap-codec-1.4.8.tgz#ea804bd94857402e6992d05a38ef1ae35a9ab4c4" + integrity sha512-9NykojV5Uih4lgo5So5dtw+f0JgJX30KCNI8gwhz2J9A15wD0Ml6tjHKwf6fTSa6fAdVBdZeNOs9eJ71qCk8vA== + strip-final-newline@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/strip-final-newline/-/strip-final-newline-2.0.0.tgz#89b852fb2fcbe936f6f4b3187afb0a12c1ab58ad" integrity sha512-BrpvfNAE3dcvq7ll3xVumzjKjZQ5tI1sEUIKr3Uoks0XUl45St3FlatVqef9prk4jRDzhW6WZg+3bk93y6pLjA== +supports-preserve-symlinks-flag@^1.0.0: + version "1.0.0" + resolved "https://registry.npmmirror.com/supports-preserve-symlinks-flag/-/supports-preserve-symlinks-flag-1.0.0.tgz#6eda4bd344a3c94aea376d4cc31bc77311039e09" + integrity sha512-ot0WnXS9fgdkgIcePe6RHNk1WA8+muPa6cSjeR3V8K27q9BB1rTE3R1p7Hv0z1ZyAc8s6Vvv8DIyWf681MAt0w== + ts-node@^10.9.1: version "10.9.1" resolved "https://registry.yarnpkg.com/ts-node/-/ts-node-10.9.1.tgz#e73de9102958af9e1f0b168a6ff320e25adcff4b" @@ -227,9 +382,14 @@ ts-node@^10.9.1: v8-compile-cache-lib "^3.0.1" yn "3.1.1" +tslib@^2.4.0: + version "2.4.0" + resolved "https://registry.npmmirror.com/tslib/-/tslib-2.4.0.tgz#7cecaa7f073ce680a05847aa77be941098f36dc3" + integrity sha512-d6xOpEDfsi2CZVlPQzGeux8XMwLT9hssAsaPYExaQMuYskwb+x1x7J371tWlbBdWHroy99KnVB6qIkUbs5X3UQ== + typescript@^4.8.4: version "4.8.4" - resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.8.4.tgz#c464abca159669597be5f96b8943500b238e60e6" + resolved "https://registry.npmmirror.com/typescript/-/typescript-4.8.4.tgz#c464abca159669597be5f96b8943500b238e60e6" integrity sha512-QCh+85mCy+h0IGff8r5XWzOVSbBO+KfeYrMQh7NJ58QujwcE22u+NUSmUxqF+un70P9GXKxa2HCNiTTMJknyjQ== v8-compile-cache-lib@^3.0.1: From a15f5e7616d37ae3cdaba82780fe6c4e35c40ab5 Mon Sep 17 00:00:00 2001 From: as Date: Wed, 19 Oct 2022 15:47:39 +0800 Subject: [PATCH 5/7] =?UTF-8?q?feat:=20get=E5=8F=AA=E6=98=AF=E6=B2=A1?= =?UTF-8?q?=E8=AF=B7=E6=B1=82=E7=B1=BB=E5=9E=8B=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tools/Readme.md | 2 +- tools/tampermonkey.ts | 4 ---- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/tools/Readme.md b/tools/Readme.md index c6555f8..c6ec424 100644 --- a/tools/Readme.md +++ b/tools/Readme.md @@ -2,7 +2,7 @@ ```js // ==UserScript== -// @name Yapi +// @name Yapi-ts-tools // @namespace http://tampermonkey.net/ // @version 0.1 // @description try to take over the world! diff --git a/tools/tampermonkey.ts b/tools/tampermonkey.ts index 61fb8f8..32a43b7 100644 --- a/tools/tampermonkey.ts +++ b/tools/tampermonkey.ts @@ -107,10 +107,6 @@ buttons.req.addEventListener('click', async () => { }) buttons.res.addEventListener('click', async () => { const data = await getYApiData() - if(data.method === 'GET'){ - alert('get请求暂不支持') - return - } const name = data.path.split('/').map(p => p.charAt(0).toLocaleUpperCase() + p.slice(1)).join('') + 'Res'; const res = runner(name, data.res, { typeMode: GM_getValue(menu[0].key) }) console.log(res) From e02fe9334a4f8a62401eec494b1d9842385677cf Mon Sep 17 00:00:00 2001 From: as Date: Wed, 19 Oct 2022 16:06:05 +0800 Subject: [PATCH 6/7] =?UTF-8?q?feat:=20=E6=94=B9=E5=88=B0=E5=8F=B3?= =?UTF-8?q?=E4=B8=8B=E8=A7=92=E5=8E=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tools/tampermonkey.ts | 112 +++++++++++++++++++----------------------- 1 file changed, 50 insertions(+), 62 deletions(-) diff --git a/tools/tampermonkey.ts b/tools/tampermonkey.ts index 32a43b7..0e85245 100644 --- a/tools/tampermonkey.ts +++ b/tools/tampermonkey.ts @@ -77,12 +77,8 @@ async function getYApiData(): Promise { }); const { data } = await yapiReq.json(); - try { - data.req = JSON.parse(data.req_body_other) - data.res = JSON.parse(data.res_body) - } catch (error) { - console.warn(error) - } + data.req = JSON.parse(data.req_body_other||'') + data.res = JSON.parse(data.res_body||'') return data } @@ -90,71 +86,63 @@ const buttons = { req: document.createElement('button'),// req res: document.createElement('button'),// res } -buttons.req.className = "lucky-btn" -buttons.res.className = "lucky-btn" - +const boxContainer = document.createElement('div'); +boxContainer.className = 'ts-tools'; +buttons.req.className = "lucky-btn"; +buttons.req.innerHTML = 'req type' +buttons.res.className = "lucky-btn"; +buttons.res.innerHTML = 'res type' +boxContainer.appendChild(buttons.req) +boxContainer.appendChild(buttons.res) buttons.req.addEventListener('click', async () => { - const data = await getYApiData() - if(data.method === 'GET'){ - alert('get请求暂不支持') - return - } - const name = data.path.split('/').map(p => p.charAt(0).toLocaleUpperCase() + p.slice(1)).join('') + 'Req'; - const res = runner(name, data.req, { typeMode: GM_getValue(menu[0].key) }) - console.log(res) - navigator.clipboard.writeText(res) - GM_notification({ text: `帮你放到剪贴板了,直接粘贴到文件吧`, timeout: 3500 }); -}) + const data = await getYApiData(); + if (data.method === 'GET') { + alert('get请求暂不支持'); + return; + } + const name = data.path.split('/').map(p => p.charAt(0).toLocaleUpperCase() + p.slice(1)).join('') + 'Req'; + const res = runner(name, data.req, { typeMode: GM_getValue(menu[0].key) }); + console.log(res); + navigator.clipboard.writeText(res); + GM_notification({ text: `帮你放到剪贴板了,直接粘贴到文件吧`, timeout: 3500 }); +}); buttons.res.addEventListener('click', async () => { - const data = await getYApiData() - const name = data.path.split('/').map(p => p.charAt(0).toLocaleUpperCase() + p.slice(1)).join('') + 'Res'; - const res = runner(name, data.res, { typeMode: GM_getValue(menu[0].key) }) - console.log(res) - navigator.clipboard.writeText(res) - GM_notification({ text: `帮你放到剪贴板了,直接粘贴到文件吧`, timeout: 3500 }); -}) - -function insertButtons() { - const targetReqHtml = document.querySelectorAll('h2')[2]; - const targetResHtml = document.querySelectorAll('h2')[3]; - buttons.req.innerText = "TS " + GM_getValue(menu[0].key) ? "type" : "interface" - buttons.res.innerText = "TS " + GM_getValue(menu[0].key) ? "type" : "interface" - if (targetReqHtml) { - targetReqHtml.appendChild(buttons.req); - } - if (targetResHtml) { - targetResHtml.appendChild(buttons.res); - } -} -function addGlobalStyle(css: string) { - var head, style; - head = document.getElementsByTagName('head')[0]; - if (!head) { return; } - style = document.createElement('style'); - style.type = 'text/css'; - style.innerHTML = css; - head.appendChild(style); + const data = await getYApiData(); + const name = data.path.split('/').map(p => p.charAt(0).toLocaleUpperCase() + p.slice(1)).join('') + 'Res'; + const res = runner(name, data.res, { typeMode: GM_getValue(menu[0].key) }); + console.log(res); + navigator.clipboard.writeText(res); + GM_notification({ text: `帮你放到剪贴板了,直接粘贴到文件吧`, timeout: 3500 }); +}); +function addGlobalStyle(css) { + var head, style; + head = document.getElementsByTagName('head')[0]; + if (!head) { + return; + } + style = document.createElement('style'); + style.type = 'text/css'; + style.innerHTML = css; + head.appendChild(style); } addGlobalStyle(` +.ts-tools { + position: fixed; + right: 20px; + bottom: 20px; + display: flex; + flex-direction: column; +} .lucky-btn { font-size: 16px; line-height: 16px; - border: aqua solid 1px; + border: none; border-radius: 4px; padding: 2px 4px; - margin-left: 8px; - background: aquamarine; + margin-bottom: 8px; + background: rgb(127 255 212 / 50%); color: white; cursor: pointer; } -`) - -setTimeout(() => { - insertButtons() - const apiChangeButton = document.querySelectorAll('.ant-tree-node-content-wrapper'); - apiChangeButton.forEach(bu => { - bu.addEventListener('click', () => { - insertButtons() - }); - }); -}, 2000) \ No newline at end of file +`); +document.body.appendChild(boxContainer) \ No newline at end of file From 948d97743ea097b8f17d566ac0293ec912af679d Mon Sep 17 00:00:00 2001 From: as Date: Wed, 19 Oct 2022 16:13:09 +0800 Subject: [PATCH 7/7] fix: bug --- tools/tampermonkey.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/tampermonkey.ts b/tools/tampermonkey.ts index 0e85245..c5dd903 100644 --- a/tools/tampermonkey.ts +++ b/tools/tampermonkey.ts @@ -77,8 +77,8 @@ async function getYApiData(): Promise { }); const { data } = await yapiReq.json(); - data.req = JSON.parse(data.req_body_other||'') - data.res = JSON.parse(data.res_body||'') + data.req = JSON.parse(data.req_body_other||'{}') + data.res = JSON.parse(data.res_body||'{}') return data }