node-cnb 1.2.9 → 1.2.10
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/package.json +1 -1
- package/.ide/Dockerfile +0 -20
- package/CHANGELOG.md +0 -70
- package/CONTRIBUTING.md +0 -23
- package/build.js +0 -156
- package/cache.dockerfile +0 -14
package/package.json
CHANGED
package/.ide/Dockerfile
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
# .ide/Dockerfile
|
|
2
|
-
FROM node:20
|
|
3
|
-
|
|
4
|
-
# 以及按需安装其他软件
|
|
5
|
-
RUN apt-get update && apt-get install -y git
|
|
6
|
-
|
|
7
|
-
# 安装 code-server 和 vscode 常用插件
|
|
8
|
-
RUN curl -fsSL https://code-server.dev/install.sh | sh \
|
|
9
|
-
&& code-server --install-extension redhat.vscode-yaml \
|
|
10
|
-
&& code-server --install-extension dbaeumer.vscode-eslint \
|
|
11
|
-
&& code-server --install-extension eamodio.gitlens \
|
|
12
|
-
&& code-server --install-extension tencent-cloud.coding-copilot \
|
|
13
|
-
&& echo done
|
|
14
|
-
|
|
15
|
-
# 安装 ssh 服务,用于支持 VSCode 客户端通过 Remote-SSH 访问开发环境
|
|
16
|
-
RUN apt-get update && apt-get install -y wget unzip openssh-server
|
|
17
|
-
|
|
18
|
-
# 指定字符集支持命令行输入中文(根据需要选择字符集)
|
|
19
|
-
ENV LANG C.UTF-8
|
|
20
|
-
ENV LANGUAGE C.UTF-8
|
package/CHANGELOG.md
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
# Changelog
|
|
2
|
-
|
|
3
|
-
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
|
-
|
|
5
|
-
### [1.2.9](https://cnb.cool/cnb/sdk/node-cnb/compare/v1.2.8...v1.2.9) (2025-02-12)
|
|
6
|
-
|
|
7
|
-
### [1.2.8](https://cnb.cool/cnb/sdk/node-cnb/compare/v1.2.7...v1.2.8) (2025-02-12)
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
### Bug Fixes
|
|
11
|
-
|
|
12
|
-
* 更正ci配置 ([e4ee23d](https://cnb.cool/cnb/sdk/node-cnb/commit/e4ee23d2eb5459cda2582974d921943d17fcbcef))
|
|
13
|
-
|
|
14
|
-
### [1.2.7](https://cnb.cool/cnb/sdk/node-cnb/compare/v1.2.6...v1.2.7) (2025-02-12)
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
### Bug Fixes
|
|
18
|
-
|
|
19
|
-
* npm publish换用token ([debb51a](https://cnb.cool/cnb/sdk/node-cnb/commit/debb51ae93b6e8d1384e4f4519c745aac0507847))
|
|
20
|
-
|
|
21
|
-
### [1.2.6](https://cnb.cool/cnb/sdk/node-cnb/compare/v1.2.5...v1.2.6) (2025-02-12)
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
### Bug Fixes
|
|
25
|
-
|
|
26
|
-
* 更换npm插件修复npm发布报错 ([82ebce5](https://cnb.cool/cnb/sdk/node-cnb/commit/82ebce59059d40c3f941954c0437fc071362d7bb))
|
|
27
|
-
|
|
28
|
-
### [1.2.5](https://cnb.cool/cnb/sdk/node-cnb/compare/v1.2.4...v1.2.5) (2025-02-12)
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
### Bug Fixes
|
|
32
|
-
|
|
33
|
-
* 修复构建报错 ([240069a](https://cnb.cool/cnb/sdk/node-cnb/commit/240069afb3eb18e49d231f80470e813fdc856dbc))
|
|
34
|
-
|
|
35
|
-
### [1.2.4](https://cnb.cool/cnb/sdk/node-cnb/compare/v1.2.3...v1.2.4) (2025-02-12)
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
### Bug Fixes
|
|
39
|
-
|
|
40
|
-
* 更正流水线报错 ([80500ac](https://cnb.cool/cnb/sdk/node-cnb/commit/80500acf043a91366209bd0261df20ba60a28765))
|
|
41
|
-
|
|
42
|
-
### [1.2.3](https://cnb.cool/cnb/sdk/node-cnb/compare/v1.2.2...v1.2.3) (2025-02-12)
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
### Bug Fixes
|
|
46
|
-
|
|
47
|
-
* 修复流水线报错 ([26f01b2](https://cnb.cool/cnb/sdk/node-cnb/commit/26f01b2e33a1a9cad2e54406aed28e4859546c8f))
|
|
48
|
-
|
|
49
|
-
### [1.2.2](https://cnb.cool/cnb/sdk/node-cnb/compare/v1.2.1...v1.2.2) (2025-02-12)
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
### Bug Fixes
|
|
53
|
-
|
|
54
|
-
* 更正缓存镜像的node版本 ([5384a07](https://cnb.cool/cnb/sdk/node-cnb/commit/5384a070c4c1552566bec5c2d0433c750a4bcc4b))
|
|
55
|
-
|
|
56
|
-
### [1.2.1](https://cnb.cool/cnb/sdk/node-cnb/compare/v1.2.0...v1.2.1) (2025-02-12)
|
|
57
|
-
|
|
58
|
-
## 1.2.0 (2025-02-12)
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
### Features
|
|
62
|
-
|
|
63
|
-
* 编写文档以及修复post参数不生效问题 ([d65cc4f](https://cnb.cool/cnb/sdk/node-cnb/commit/d65cc4f51e1068c9e6b190df3328a1021342bf63))
|
|
64
|
-
* 初步完成代码编译 ([be40568](https://cnb.cool/cnb/sdk/node-cnb/commit/be40568efb7a2debefeef0e036acd7fc05082797))
|
|
65
|
-
* 初始提交 ([f3e6333](https://cnb.cool/cnb/sdk/node-cnb/commit/f3e6333e488417bb66dfa342ff57ca727e5f12f1))
|
|
66
|
-
* 生成类型声明和ts代码初稿 ([1ff64fd](https://cnb.cool/cnb/sdk/node-cnb/commit/1ff64fd4efc9971bcece7a42c8f021f405e57671))
|
|
67
|
-
|
|
68
|
-
# Changelog
|
|
69
|
-
|
|
70
|
-
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
package/CONTRIBUTING.md
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
# 原理
|
|
2
|
-
|
|
3
|
-
cnb 会编译出 open api 的 [swagger json](https://api.cnb.cool/swagger.json),并生成 api 页面。
|
|
4
|
-
|
|
5
|
-
本仓库依据 swagger json 编译生成对应的 typescript 代码。
|
|
6
|
-
|
|
7
|
-
# 命令
|
|
8
|
-
|
|
9
|
-
```shell
|
|
10
|
-
# 依据 swagger json 生成 types.d.ts 和 client.d.ts 并编译 ts 到 dist 目录
|
|
11
|
-
npm run build
|
|
12
|
-
|
|
13
|
-
# 更新 package.json 的 version,打 tag 并 push 到仓库
|
|
14
|
-
npm run release
|
|
15
|
-
```
|
|
16
|
-
|
|
17
|
-
# 开发
|
|
18
|
-
|
|
19
|
-
1. 更新 swagger json
|
|
20
|
-
1. 修改 build.js
|
|
21
|
-
1. 修改 src/index.ts
|
|
22
|
-
|
|
23
|
-
改完后调试需手动执行下 `npm run build`
|
package/build.js
DELETED
|
@@ -1,156 +0,0 @@
|
|
|
1
|
-
const fs = require('fs');
|
|
2
|
-
const cp = require('child_process');
|
|
3
|
-
const _ = require('lodash');
|
|
4
|
-
const apiSwagger = require('./openapi_swagger.json');
|
|
5
|
-
const { definitions } = apiSwagger;
|
|
6
|
-
const pathMethodNameMap = require('./pathMethodMap.json');
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* 实现原理
|
|
10
|
-
*
|
|
11
|
-
* cnb 会编译出 open api 的 [swagger json](https://api.cnb.cool/swagger.json),并生成 api 页面。
|
|
12
|
-
*
|
|
13
|
-
* 本仓库依据 swagger json 编译生成对应的 typescript 代码。
|
|
14
|
-
*/
|
|
15
|
-
|
|
16
|
-
const pathMethodsMap = {}
|
|
17
|
-
|
|
18
|
-
const buildPathMethods = () => {
|
|
19
|
-
Object.keys(apiSwagger.paths).forEach(path => {
|
|
20
|
-
const pathValue = apiSwagger.paths[path];
|
|
21
|
-
Object.keys(pathValue).forEach(method => {
|
|
22
|
-
const methodValue = pathValue[method];
|
|
23
|
-
methodValue.path = path;
|
|
24
|
-
methodValue.method = method;
|
|
25
|
-
|
|
26
|
-
const pathMethod = method === 'get' && methodValue.responses['200']?.schema?.type === 'array' ? 'list' : method;
|
|
27
|
-
const methodPath = pathMethodNameMap[path] ? pathMethodNameMap[path] : [...path.replace(/\/\{([^\}]+)\}\/-\//g, '/$1/').replace(/\/\{[^\}]+\}/g, '/').split('/').map(item => _.camelCase(item)).filter(Boolean), pathMethod].join('.');
|
|
28
|
-
const methodValues = pathMethodsMap[methodPath] || []
|
|
29
|
-
methodValues.push(methodValue)
|
|
30
|
-
pathMethodsMap[methodPath] = methodValues;
|
|
31
|
-
if (methodValues.length > 1) {
|
|
32
|
-
console.log('重复的path', methodPath, methodValues.map(item => item.path))
|
|
33
|
-
}
|
|
34
|
-
})
|
|
35
|
-
})
|
|
36
|
-
|
|
37
|
-
fs.writeFileSync('./src/paths.json', JSON.stringify(pathMethodsMap, null, 2));
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
const convertTypeName = (type) => {
|
|
41
|
-
let typeName = _.camelCase(type.split('.').join('-'));
|
|
42
|
-
typeName = typeName.charAt(0).toUpperCase() + typeName.slice(1);
|
|
43
|
-
return typeName;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
const typeMap = {
|
|
47
|
-
'integer': 'number',
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
function convertSchemaToType(schema) {
|
|
51
|
-
if (schema.type === 'object') {
|
|
52
|
-
let properties = '';
|
|
53
|
-
if (!schema.properties) {
|
|
54
|
-
return 'any'
|
|
55
|
-
}
|
|
56
|
-
for (const [key, value] of Object.entries(schema.properties)) {
|
|
57
|
-
const typeName = key.includes('-') ? `'${key}'` : key;
|
|
58
|
-
if (typeName !== key) {
|
|
59
|
-
console.log('typeName', key, typeName)
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
if (value.description) {
|
|
63
|
-
properties += `\n /**${value.description}*/\n`
|
|
64
|
-
}
|
|
65
|
-
properties += ` ${typeName}: ${convertSchemaToType(value)};\n`;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
return `{\n${properties}}`;
|
|
69
|
-
} else if (schema.type === 'array') {
|
|
70
|
-
return `${convertSchemaToType(schema.items)}[]`;
|
|
71
|
-
} else if (schema['$ref']) {
|
|
72
|
-
return convertTypeName(schema['$ref'].replace('#/definitions/', ''))
|
|
73
|
-
} else {
|
|
74
|
-
return typeMap[schema.type] || schema.type || 'any';
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
const buildDefinitions = () => {
|
|
79
|
-
function convertDefinitionsToTypes(definitions) {
|
|
80
|
-
let types = '';
|
|
81
|
-
|
|
82
|
-
for (const [key, value] of Object.entries(definitions)) {
|
|
83
|
-
|
|
84
|
-
const convetValue = convertSchemaToType(value);
|
|
85
|
-
if (!convetValue) {
|
|
86
|
-
continue;
|
|
87
|
-
}
|
|
88
|
-
types += `export type ${convertTypeName(key)} = ${convetValue};\n\n`;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
return types;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
// 提取 definitions 并转换为类型声明
|
|
95
|
-
const types = convertDefinitionsToTypes(definitions);
|
|
96
|
-
|
|
97
|
-
// 将类型声明写入 TypeScript 文件
|
|
98
|
-
fs.writeFileSync('./src/types.d.ts', types, 'utf8');
|
|
99
|
-
}
|
|
100
|
-
const importTypes = [];
|
|
101
|
-
const buildClientInterface = () => {
|
|
102
|
-
const pathTree = {};
|
|
103
|
-
Object.keys(pathMethodsMap).forEach(methodPath => {
|
|
104
|
-
let currentSub = pathTree;
|
|
105
|
-
const methodList = methodPath.split('.');
|
|
106
|
-
methodList.forEach((method) => {
|
|
107
|
-
currentSub[method] = currentSub[method] || {};
|
|
108
|
-
currentSub = currentSub[method];
|
|
109
|
-
})
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
const getMethodContent = (tree, path) => {
|
|
113
|
-
let content = '';
|
|
114
|
-
Object.keys(tree).forEach(method => {
|
|
115
|
-
content += `
|
|
116
|
-
${_.camelCase(method)}: ${getMethodContent(tree[method], [path, method].filter(Boolean).join('.'))}
|
|
117
|
-
`;
|
|
118
|
-
})
|
|
119
|
-
if (!content) {
|
|
120
|
-
const methodValue = pathMethodsMap[path]?.[0] || {};
|
|
121
|
-
const resultType = convertSchemaToType(methodValue.responses?.['200']?.schema || {});
|
|
122
|
-
importTypes.push(resultType.replace('[]', ''))
|
|
123
|
-
|
|
124
|
-
content = `(params: {${(methodValue.parameters || []).map(param => {
|
|
125
|
-
|
|
126
|
-
return param.name + (param.required ? '' : '?') + ': ' + convertSchemaToType(param)
|
|
127
|
-
})}}) => Promise<${resultType}>`
|
|
128
|
-
} else {
|
|
129
|
-
content = `{
|
|
130
|
-
${content}
|
|
131
|
-
}`
|
|
132
|
-
}
|
|
133
|
-
return content;
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
let interfaceContent = `
|
|
137
|
-
export interface Client ${getMethodContent(pathTree, '')}
|
|
138
|
-
`;
|
|
139
|
-
const distinctImportTypes = _.uniq(importTypes.filter(item => !/^[a-z]+$/.test(item))).join(', ');
|
|
140
|
-
interfaceContent = `import {${distinctImportTypes}} from './types';
|
|
141
|
-
${interfaceContent}`
|
|
142
|
-
fs.writeFileSync('./src/client.d.ts', interfaceContent, 'utf8');
|
|
143
|
-
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
const prettier = () => {
|
|
147
|
-
cp.execSync('npx prettier --write ./src/*.ts');
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
buildPathMethods();
|
|
151
|
-
|
|
152
|
-
buildDefinitions();
|
|
153
|
-
|
|
154
|
-
buildClientInterface();
|
|
155
|
-
|
|
156
|
-
prettier();
|