almighty-tool 0.0.114 → 0.0.116
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/.babelrc +17 -17
- package/.editorconfig +13 -13
- package/.eslintignore +7 -7
- package/.eslintrc.js +5 -5
- package/.nvmrc +1 -1
- package/.opencode/agents/code-reviewer.md +57 -57
- package/.opencode/agents/docs-specialist.md +49 -49
- package/.opencode/agents/test-runner.md +45 -45
- package/.opencode/commands/review.md +25 -25
- package/.opencode/commands/test.md +27 -27
- package/.opencode/skills/cryptography-dev.md +108 -108
- package/.opencode/skills/typescript-library-dev.md +94 -94
- package/.prettierrc.js +1 -1
- package/.yarnrc +11 -11
- package/AGENTS.md +69 -69
- package/CHANGELOG.md +7 -7
- package/README.md +11 -11
- package/bun.lock +2836 -2836
- package/bunfig.toml +7 -7
- package/jest.config.js +1 -1
- package/lib/utils/basic.util.d.ts +5 -0
- package/lib/utils/basic.util.js +64 -0
- package/lib/utils/basic.util.js.map +1 -1
- package/lib/utils/validate.util.d.ts +4 -0
- package/lib/utils/validate.util.js.map +1 -1
- package/opencode.json +60 -60
- package/package.json +122 -122
- package/scripts/code.util.ts +135 -135
- package/templates/eslints/eggjs.project.js +15 -15
- package/templates/eslints/element-ui.project.js +4 -4
- package/templates/eslints/recommended.js +26 -26
- package/templates/eslints/rules/recommended.js +26 -26
- package/templates/eslints/rules/vue.js +12 -12
- package/templates/eslints/server.project.js +18 -18
- package/templates/eslints/uni-app-v8.project.js +43 -43
- package/templates/eslints/uni-app.project.js +45 -45
- package/templates/eslints/vue.project.js +39 -39
- package/templates/jest/element-ui.project.js +1 -1
- package/templates/jest/recommended.js +22 -22
- package/templates/jest/vue.project.js +44 -44
- package/templates/postcss/recommended.js +4 -4
- package/templates/postcss/uni-app.js +11 -11
- package/templates/prettiers/recommended.js +26 -26
- package/templates/stylelint/recommended.js +42 -42
- package/templates/stylelint/rules/recommended.js +22 -22
- package/templates/stylelint/uni-app.project.js +11 -11
- package/templates/tsconfigs/eggjs.json +31 -31
- package/templates/tsconfigs/element-ui.json +3 -3
- package/templates/tsconfigs/lib.json +15 -15
- package/templates/tsconfigs/quasar.json +25 -25
- package/templates/tsconfigs/recommended.json +23 -23
- package/templates/tsconfigs/server.json +23 -23
- package/templates/tsconfigs/uni-app.json +39 -39
- package/templates/tsconfigs/vue.json +45 -45
- package/templates/tslints/recommended.json +13 -13
- package/test-duration.js +33 -33
- package/tsconfig.json +9 -9
package/package.json
CHANGED
|
@@ -1,122 +1,122 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "almighty-tool",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"description": "almighty-tool",
|
|
5
|
-
"author": "happy",
|
|
6
|
-
"private": false,
|
|
7
|
-
"license": "MIT",
|
|
8
|
-
"keywords": [
|
|
9
|
-
"tool",
|
|
10
|
-
"almighty",
|
|
11
|
-
"library"
|
|
12
|
-
],
|
|
13
|
-
"_moduleAliases": {
|
|
14
|
-
"@root": "."
|
|
15
|
-
},
|
|
16
|
-
"repository": {
|
|
17
|
-
"url": "https://github.com/pagesuper/almighty-tool"
|
|
18
|
-
},
|
|
19
|
-
"scripts": {
|
|
20
|
-
"eslint": "eslint --ext .js,.ts,.vue --ignore-path .eslintignore .",
|
|
21
|
-
"eslint:fix": "yarn eslint --fix",
|
|
22
|
-
"stylelint": "stylelint \"{src,source}/**/*.{css,scss,sass}\" --allow-empty-input",
|
|
23
|
-
"stylelint:fix": "yarn stylelint --fix",
|
|
24
|
-
"lint": "yarn run eslint && yarn run stylelint",
|
|
25
|
-
"lint:fix": "yarn run eslint:fix && yarn run stylelint:fix",
|
|
26
|
-
"tsc": "./node_modules/.bin/tsc -p tsconfig.json",
|
|
27
|
-
"check": "npm run test && npm run eslint",
|
|
28
|
-
"test": "jest --clearCache && jest --runInBand --detectOpenHandles"
|
|
29
|
-
},
|
|
30
|
-
"gitHooks": {
|
|
31
|
-
"pre-commit": "lint-staged"
|
|
32
|
-
},
|
|
33
|
-
"lint-staged": {
|
|
34
|
-
"*.{js,ts,vue}": [
|
|
35
|
-
"eslint --fix"
|
|
36
|
-
],
|
|
37
|
-
"*.{css,scss}": [
|
|
38
|
-
"stylelint --fix"
|
|
39
|
-
]
|
|
40
|
-
},
|
|
41
|
-
"typings": "types/index.d.ts",
|
|
42
|
-
"dependencies": {
|
|
43
|
-
"async-validator": "^4.2.5",
|
|
44
|
-
"base64-js": "^1.5.1",
|
|
45
|
-
"crypto-js": "^4.2.0",
|
|
46
|
-
"dayjs": "^1.11.7",
|
|
47
|
-
"deepmerge": "^4.3.0",
|
|
48
|
-
"inflection": "^1.13.4",
|
|
49
|
-
"is-what": "^4.1.8",
|
|
50
|
-
"jsencrypt": "^3.5.4",
|
|
51
|
-
"lodash-es": "^4.17.21",
|
|
52
|
-
"mustache": "^4.2.0",
|
|
53
|
-
"nock": "^13.3.0",
|
|
54
|
-
"qs": "^6.11.0",
|
|
55
|
-
"sanitize-html": "^2.17.0",
|
|
56
|
-
"tinyld": "^1.3.4",
|
|
57
|
-
"tslib": "^2.4.0",
|
|
58
|
-
"tsx": "^4.19.2",
|
|
59
|
-
"typescript": "^5.9.2",
|
|
60
|
-
"uuid": "^9.0.0",
|
|
61
|
-
"yargs": "^17.7.2",
|
|
62
|
-
"yorkie": "^2.0.0"
|
|
63
|
-
},
|
|
64
|
-
"devDependencies": {
|
|
65
|
-
"@babel/plugin-syntax-typescript": "^7.20.0",
|
|
66
|
-
"@babel/preset-env": "^7.20.2",
|
|
67
|
-
"@babel/preset-typescript": "^7.21.0",
|
|
68
|
-
"@types/crypto-js": "^4.2.2",
|
|
69
|
-
"@types/debug": "^4.1.8",
|
|
70
|
-
"@types/html5plus": "1.0.2",
|
|
71
|
-
"@types/inflection": "^1.13.2",
|
|
72
|
-
"@types/jest": "29.4.0",
|
|
73
|
-
"@types/lodash-es": "^4.17.12",
|
|
74
|
-
"@types/mustache": "^4.2.5",
|
|
75
|
-
"@types/node": "^20.19.15",
|
|
76
|
-
"@types/node-forge": "^1.3.11",
|
|
77
|
-
"@types/node-rsa": "^1.1.4",
|
|
78
|
-
"@types/power-assert": "1.5.8",
|
|
79
|
-
"@types/qs": "6.9.7",
|
|
80
|
-
"@types/sanitize-html": "^2.16.0",
|
|
81
|
-
"@types/uuid": "9.0.1",
|
|
82
|
-
"@types/webpack-env": "^1.18.8",
|
|
83
|
-
"@typescript-eslint/eslint-plugin": "5.54.0",
|
|
84
|
-
"@typescript-eslint/parser": "5.54.0",
|
|
85
|
-
"babel-eslint": "^10.0.1",
|
|
86
|
-
"babel-jest": "^29.4.3",
|
|
87
|
-
"babel-loader": "^8.2.3",
|
|
88
|
-
"babel-plugin-import": "^1.13.6",
|
|
89
|
-
"eslint": "8.19.0",
|
|
90
|
-
"eslint-config-prettier": "8.5.0",
|
|
91
|
-
"eslint-config-standard": "17.0.0",
|
|
92
|
-
"eslint-friendly-formatter": "4.0.1",
|
|
93
|
-
"eslint-loader": "4.0.2",
|
|
94
|
-
"eslint-plugin-html": "6.2.0",
|
|
95
|
-
"eslint-plugin-import": "2.25.4",
|
|
96
|
-
"eslint-plugin-jest": "26.5.3",
|
|
97
|
-
"eslint-plugin-n": "15.2.4",
|
|
98
|
-
"eslint-plugin-node": "11.1.0",
|
|
99
|
-
"eslint-plugin-nuxt": ">=3.1.0",
|
|
100
|
-
"eslint-plugin-prettier": "4.2.1",
|
|
101
|
-
"eslint-plugin-promise": "6.0.0",
|
|
102
|
-
"eslint-plugin-standard": "5.0.0",
|
|
103
|
-
"eslint-plugin-vue": "9.1.1",
|
|
104
|
-
"eslint-plugin-vue-scoped-css": "2.2.0",
|
|
105
|
-
"jest": "^29.4.3",
|
|
106
|
-
"lint-staged": "^13.1.2",
|
|
107
|
-
"mockdate": "^3.0.5",
|
|
108
|
-
"power-assert": "^1.6.1",
|
|
109
|
-
"prettier": "^2.8.4",
|
|
110
|
-
"stylelint": "^14.9.1",
|
|
111
|
-
"stylelint-config-rational-order": "^0.1.2",
|
|
112
|
-
"stylelint-config-standard": "^26.0.0",
|
|
113
|
-
"stylelint-config-standard-scss": "^4.0.0",
|
|
114
|
-
"stylelint-order": "^5.0.0",
|
|
115
|
-
"stylelint-scss": "^4.2.0",
|
|
116
|
-
"ts-jest": "^29.0.5",
|
|
117
|
-
"webpack-env": "^0.8.0"
|
|
118
|
-
},
|
|
119
|
-
"volta": {
|
|
120
|
-
"node": "22.17.1"
|
|
121
|
-
}
|
|
122
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "almighty-tool",
|
|
3
|
+
"version": "0.0.116",
|
|
4
|
+
"description": "almighty-tool",
|
|
5
|
+
"author": "happy",
|
|
6
|
+
"private": false,
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"keywords": [
|
|
9
|
+
"tool",
|
|
10
|
+
"almighty",
|
|
11
|
+
"library"
|
|
12
|
+
],
|
|
13
|
+
"_moduleAliases": {
|
|
14
|
+
"@root": "."
|
|
15
|
+
},
|
|
16
|
+
"repository": {
|
|
17
|
+
"url": "https://github.com/pagesuper/almighty-tool"
|
|
18
|
+
},
|
|
19
|
+
"scripts": {
|
|
20
|
+
"eslint": "eslint --ext .js,.ts,.vue --ignore-path .eslintignore .",
|
|
21
|
+
"eslint:fix": "yarn eslint --fix",
|
|
22
|
+
"stylelint": "stylelint \"{src,source}/**/*.{css,scss,sass}\" --allow-empty-input",
|
|
23
|
+
"stylelint:fix": "yarn stylelint --fix",
|
|
24
|
+
"lint": "yarn run eslint && yarn run stylelint",
|
|
25
|
+
"lint:fix": "yarn run eslint:fix && yarn run stylelint:fix",
|
|
26
|
+
"tsc": "./node_modules/.bin/tsc -p tsconfig.json",
|
|
27
|
+
"check": "npm run test && npm run eslint",
|
|
28
|
+
"test": "jest --clearCache && jest --runInBand --detectOpenHandles"
|
|
29
|
+
},
|
|
30
|
+
"gitHooks": {
|
|
31
|
+
"pre-commit": "lint-staged"
|
|
32
|
+
},
|
|
33
|
+
"lint-staged": {
|
|
34
|
+
"*.{js,ts,vue}": [
|
|
35
|
+
"eslint --fix"
|
|
36
|
+
],
|
|
37
|
+
"*.{css,scss}": [
|
|
38
|
+
"stylelint --fix"
|
|
39
|
+
]
|
|
40
|
+
},
|
|
41
|
+
"typings": "types/index.d.ts",
|
|
42
|
+
"dependencies": {
|
|
43
|
+
"async-validator": "^4.2.5",
|
|
44
|
+
"base64-js": "^1.5.1",
|
|
45
|
+
"crypto-js": "^4.2.0",
|
|
46
|
+
"dayjs": "^1.11.7",
|
|
47
|
+
"deepmerge": "^4.3.0",
|
|
48
|
+
"inflection": "^1.13.4",
|
|
49
|
+
"is-what": "^4.1.8",
|
|
50
|
+
"jsencrypt": "^3.5.4",
|
|
51
|
+
"lodash-es": "^4.17.21",
|
|
52
|
+
"mustache": "^4.2.0",
|
|
53
|
+
"nock": "^13.3.0",
|
|
54
|
+
"qs": "^6.11.0",
|
|
55
|
+
"sanitize-html": "^2.17.0",
|
|
56
|
+
"tinyld": "^1.3.4",
|
|
57
|
+
"tslib": "^2.4.0",
|
|
58
|
+
"tsx": "^4.19.2",
|
|
59
|
+
"typescript": "^5.9.2",
|
|
60
|
+
"uuid": "^9.0.0",
|
|
61
|
+
"yargs": "^17.7.2",
|
|
62
|
+
"yorkie": "^2.0.0"
|
|
63
|
+
},
|
|
64
|
+
"devDependencies": {
|
|
65
|
+
"@babel/plugin-syntax-typescript": "^7.20.0",
|
|
66
|
+
"@babel/preset-env": "^7.20.2",
|
|
67
|
+
"@babel/preset-typescript": "^7.21.0",
|
|
68
|
+
"@types/crypto-js": "^4.2.2",
|
|
69
|
+
"@types/debug": "^4.1.8",
|
|
70
|
+
"@types/html5plus": "1.0.2",
|
|
71
|
+
"@types/inflection": "^1.13.2",
|
|
72
|
+
"@types/jest": "29.4.0",
|
|
73
|
+
"@types/lodash-es": "^4.17.12",
|
|
74
|
+
"@types/mustache": "^4.2.5",
|
|
75
|
+
"@types/node": "^20.19.15",
|
|
76
|
+
"@types/node-forge": "^1.3.11",
|
|
77
|
+
"@types/node-rsa": "^1.1.4",
|
|
78
|
+
"@types/power-assert": "1.5.8",
|
|
79
|
+
"@types/qs": "6.9.7",
|
|
80
|
+
"@types/sanitize-html": "^2.16.0",
|
|
81
|
+
"@types/uuid": "9.0.1",
|
|
82
|
+
"@types/webpack-env": "^1.18.8",
|
|
83
|
+
"@typescript-eslint/eslint-plugin": "5.54.0",
|
|
84
|
+
"@typescript-eslint/parser": "5.54.0",
|
|
85
|
+
"babel-eslint": "^10.0.1",
|
|
86
|
+
"babel-jest": "^29.4.3",
|
|
87
|
+
"babel-loader": "^8.2.3",
|
|
88
|
+
"babel-plugin-import": "^1.13.6",
|
|
89
|
+
"eslint": "8.19.0",
|
|
90
|
+
"eslint-config-prettier": "8.5.0",
|
|
91
|
+
"eslint-config-standard": "17.0.0",
|
|
92
|
+
"eslint-friendly-formatter": "4.0.1",
|
|
93
|
+
"eslint-loader": "4.0.2",
|
|
94
|
+
"eslint-plugin-html": "6.2.0",
|
|
95
|
+
"eslint-plugin-import": "2.25.4",
|
|
96
|
+
"eslint-plugin-jest": "26.5.3",
|
|
97
|
+
"eslint-plugin-n": "15.2.4",
|
|
98
|
+
"eslint-plugin-node": "11.1.0",
|
|
99
|
+
"eslint-plugin-nuxt": ">=3.1.0",
|
|
100
|
+
"eslint-plugin-prettier": "4.2.1",
|
|
101
|
+
"eslint-plugin-promise": "6.0.0",
|
|
102
|
+
"eslint-plugin-standard": "5.0.0",
|
|
103
|
+
"eslint-plugin-vue": "9.1.1",
|
|
104
|
+
"eslint-plugin-vue-scoped-css": "2.2.0",
|
|
105
|
+
"jest": "^29.4.3",
|
|
106
|
+
"lint-staged": "^13.1.2",
|
|
107
|
+
"mockdate": "^3.0.5",
|
|
108
|
+
"power-assert": "^1.6.1",
|
|
109
|
+
"prettier": "^2.8.4",
|
|
110
|
+
"stylelint": "^14.9.1",
|
|
111
|
+
"stylelint-config-rational-order": "^0.1.2",
|
|
112
|
+
"stylelint-config-standard": "^26.0.0",
|
|
113
|
+
"stylelint-config-standard-scss": "^4.0.0",
|
|
114
|
+
"stylelint-order": "^5.0.0",
|
|
115
|
+
"stylelint-scss": "^4.2.0",
|
|
116
|
+
"ts-jest": "^29.0.5",
|
|
117
|
+
"webpack-env": "^0.8.0"
|
|
118
|
+
},
|
|
119
|
+
"volta": {
|
|
120
|
+
"node": "22.17.1"
|
|
121
|
+
}
|
|
122
|
+
}
|
package/scripts/code.util.ts
CHANGED
|
@@ -1,135 +1,135 @@
|
|
|
1
|
-
import fs from 'fs';
|
|
2
|
-
import path from 'path';
|
|
3
|
-
import mustache from 'mustache';
|
|
4
|
-
import * as inflection from 'inflection';
|
|
5
|
-
import yargs from 'yargs';
|
|
6
|
-
|
|
7
|
-
/** 生成代码选项 */
|
|
8
|
-
export interface CodeUtilGenerateOptions {
|
|
9
|
-
/** 模板变量 */
|
|
10
|
-
data: any;
|
|
11
|
-
/** 模板文件路径 */
|
|
12
|
-
templatePath: string;
|
|
13
|
-
/** 目标文件路径 */
|
|
14
|
-
targetPath: string;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
/** 获取生成数据选项 */
|
|
18
|
-
export interface CodeUtilGetGenerateDataOptions {
|
|
19
|
-
/** 模型名称 */
|
|
20
|
-
modelName: string;
|
|
21
|
-
/** 模块路径 */
|
|
22
|
-
modulePath: string;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export interface CodeUtilGetGenerateData {
|
|
26
|
-
/* 小驼峰 eg. authCollection */
|
|
27
|
-
FirstLowerModelName: string;
|
|
28
|
-
/* 小驼峰复数 eg. authCollections */
|
|
29
|
-
FirstLowerModelsName: string;
|
|
30
|
-
/* 模块路径 eg. service-forum/src/modules/auth */
|
|
31
|
-
ModulePath: string;
|
|
32
|
-
/* 模块名称 eg. auth */
|
|
33
|
-
ModuleName: string;
|
|
34
|
-
/* 大驼峰 eg. AuthCollection */
|
|
35
|
-
ModelName: string;
|
|
36
|
-
/* 大驼峰复数 eg. AuthCollections */
|
|
37
|
-
ModelsName: string;
|
|
38
|
-
/* 连字符 eg. auth-collection */
|
|
39
|
-
KebabCaseModelName: string;
|
|
40
|
-
/* 连字符复数 eg. auth-collections */
|
|
41
|
-
KebabCaseModelsName: string;
|
|
42
|
-
/* 下划线 eg. auth_collection */
|
|
43
|
-
UnderscoreModelName: string;
|
|
44
|
-
/* 下划线复数 eg. auth_collections */
|
|
45
|
-
UnderscoreModelsName: string;
|
|
46
|
-
/** 其他值 */
|
|
47
|
-
[key: string]: string;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
const codeUtil = {
|
|
51
|
-
/**
|
|
52
|
-
* 通过模板生成代码
|
|
53
|
-
* @param options 生成选项
|
|
54
|
-
*/
|
|
55
|
-
generate: (options: CodeUtilGenerateOptions) => {
|
|
56
|
-
const { data: variables, templatePath, targetPath } = options;
|
|
57
|
-
|
|
58
|
-
// 检查模板文件是否存在
|
|
59
|
-
if (!fs.existsSync(templatePath)) {
|
|
60
|
-
throw new Error(`Template file not found: ${templatePath}`);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
// 确保目标目录存在
|
|
64
|
-
const targetDir = path.dirname(targetPath);
|
|
65
|
-
if (!fs.existsSync(targetDir)) {
|
|
66
|
-
fs.mkdirSync(targetDir, { recursive: true });
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
// 读取模板内容
|
|
70
|
-
const template = fs.readFileSync(templatePath, 'utf-8');
|
|
71
|
-
|
|
72
|
-
// 使用变量渲染模板
|
|
73
|
-
const result = mustache
|
|
74
|
-
.render(template, variables)
|
|
75
|
-
.replace(///g, '/')
|
|
76
|
-
.replace(/{/g, '{')
|
|
77
|
-
.replace(/}/g, '}');
|
|
78
|
-
|
|
79
|
-
// 写入目标文件
|
|
80
|
-
fs.writeFileSync(targetPath, result, 'utf-8');
|
|
81
|
-
},
|
|
82
|
-
|
|
83
|
-
/** 获取布尔值 */
|
|
84
|
-
getBooleanValue: (value: string | boolean) => {
|
|
85
|
-
return ['true', true].includes(value);
|
|
86
|
-
},
|
|
87
|
-
|
|
88
|
-
/**
|
|
89
|
-
* 获取生成数据
|
|
90
|
-
* @param options 获取生成数据选项
|
|
91
|
-
*/
|
|
92
|
-
getGenerateData: (options: CodeUtilGetGenerateDataOptions) => {
|
|
93
|
-
if (!options.modelName) {
|
|
94
|
-
throw new Error('modelName is required');
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
if (!options.modulePath) {
|
|
98
|
-
throw new Error('modulePath is required');
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
const ModulePath = options.modulePath;
|
|
102
|
-
const ModulePathParts = ModulePath.split('/');
|
|
103
|
-
const ModuleName = ModulePathParts[ModulePathParts.length - 1];
|
|
104
|
-
const ModelName = inflection.camelize(options.modelName);
|
|
105
|
-
const ModelsName = inflection.pluralize(ModelName);
|
|
106
|
-
const UnderscoreModelName = inflection.underscore(ModelName);
|
|
107
|
-
const UnderscoreModelsName = inflection.underscore(ModelsName);
|
|
108
|
-
const KebabCaseModelName = inflection.dasherize(UnderscoreModelName);
|
|
109
|
-
const KebabCaseModelsName = inflection.dasherize(UnderscoreModelsName);
|
|
110
|
-
const FirstLowerModelName = inflection.camelize(ModelName, true);
|
|
111
|
-
const FirstLowerModelsName = inflection.camelize(ModelsName, true);
|
|
112
|
-
|
|
113
|
-
const data: CodeUtilGetGenerateData = {
|
|
114
|
-
FirstLowerModelName,
|
|
115
|
-
FirstLowerModelsName,
|
|
116
|
-
ModulePath,
|
|
117
|
-
ModuleName,
|
|
118
|
-
ModelName,
|
|
119
|
-
ModelsName,
|
|
120
|
-
KebabCaseModelName,
|
|
121
|
-
KebabCaseModelsName,
|
|
122
|
-
UnderscoreModelName,
|
|
123
|
-
UnderscoreModelsName,
|
|
124
|
-
};
|
|
125
|
-
|
|
126
|
-
return data;
|
|
127
|
-
},
|
|
128
|
-
|
|
129
|
-
/** 获取命令行参数 */
|
|
130
|
-
getArgv: () => {
|
|
131
|
-
return yargs(process.argv).argv as Record<string, any>;
|
|
132
|
-
},
|
|
133
|
-
};
|
|
134
|
-
|
|
135
|
-
export default codeUtil;
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import mustache from 'mustache';
|
|
4
|
+
import * as inflection from 'inflection';
|
|
5
|
+
import yargs from 'yargs';
|
|
6
|
+
|
|
7
|
+
/** 生成代码选项 */
|
|
8
|
+
export interface CodeUtilGenerateOptions {
|
|
9
|
+
/** 模板变量 */
|
|
10
|
+
data: any;
|
|
11
|
+
/** 模板文件路径 */
|
|
12
|
+
templatePath: string;
|
|
13
|
+
/** 目标文件路径 */
|
|
14
|
+
targetPath: string;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** 获取生成数据选项 */
|
|
18
|
+
export interface CodeUtilGetGenerateDataOptions {
|
|
19
|
+
/** 模型名称 */
|
|
20
|
+
modelName: string;
|
|
21
|
+
/** 模块路径 */
|
|
22
|
+
modulePath: string;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface CodeUtilGetGenerateData {
|
|
26
|
+
/* 小驼峰 eg. authCollection */
|
|
27
|
+
FirstLowerModelName: string;
|
|
28
|
+
/* 小驼峰复数 eg. authCollections */
|
|
29
|
+
FirstLowerModelsName: string;
|
|
30
|
+
/* 模块路径 eg. service-forum/src/modules/auth */
|
|
31
|
+
ModulePath: string;
|
|
32
|
+
/* 模块名称 eg. auth */
|
|
33
|
+
ModuleName: string;
|
|
34
|
+
/* 大驼峰 eg. AuthCollection */
|
|
35
|
+
ModelName: string;
|
|
36
|
+
/* 大驼峰复数 eg. AuthCollections */
|
|
37
|
+
ModelsName: string;
|
|
38
|
+
/* 连字符 eg. auth-collection */
|
|
39
|
+
KebabCaseModelName: string;
|
|
40
|
+
/* 连字符复数 eg. auth-collections */
|
|
41
|
+
KebabCaseModelsName: string;
|
|
42
|
+
/* 下划线 eg. auth_collection */
|
|
43
|
+
UnderscoreModelName: string;
|
|
44
|
+
/* 下划线复数 eg. auth_collections */
|
|
45
|
+
UnderscoreModelsName: string;
|
|
46
|
+
/** 其他值 */
|
|
47
|
+
[key: string]: string;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const codeUtil = {
|
|
51
|
+
/**
|
|
52
|
+
* 通过模板生成代码
|
|
53
|
+
* @param options 生成选项
|
|
54
|
+
*/
|
|
55
|
+
generate: (options: CodeUtilGenerateOptions) => {
|
|
56
|
+
const { data: variables, templatePath, targetPath } = options;
|
|
57
|
+
|
|
58
|
+
// 检查模板文件是否存在
|
|
59
|
+
if (!fs.existsSync(templatePath)) {
|
|
60
|
+
throw new Error(`Template file not found: ${templatePath}`);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// 确保目标目录存在
|
|
64
|
+
const targetDir = path.dirname(targetPath);
|
|
65
|
+
if (!fs.existsSync(targetDir)) {
|
|
66
|
+
fs.mkdirSync(targetDir, { recursive: true });
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// 读取模板内容
|
|
70
|
+
const template = fs.readFileSync(templatePath, 'utf-8');
|
|
71
|
+
|
|
72
|
+
// 使用变量渲染模板
|
|
73
|
+
const result = mustache
|
|
74
|
+
.render(template, variables)
|
|
75
|
+
.replace(///g, '/')
|
|
76
|
+
.replace(/{/g, '{')
|
|
77
|
+
.replace(/}/g, '}');
|
|
78
|
+
|
|
79
|
+
// 写入目标文件
|
|
80
|
+
fs.writeFileSync(targetPath, result, 'utf-8');
|
|
81
|
+
},
|
|
82
|
+
|
|
83
|
+
/** 获取布尔值 */
|
|
84
|
+
getBooleanValue: (value: string | boolean) => {
|
|
85
|
+
return ['true', true].includes(value);
|
|
86
|
+
},
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* 获取生成数据
|
|
90
|
+
* @param options 获取生成数据选项
|
|
91
|
+
*/
|
|
92
|
+
getGenerateData: (options: CodeUtilGetGenerateDataOptions) => {
|
|
93
|
+
if (!options.modelName) {
|
|
94
|
+
throw new Error('modelName is required');
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
if (!options.modulePath) {
|
|
98
|
+
throw new Error('modulePath is required');
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const ModulePath = options.modulePath;
|
|
102
|
+
const ModulePathParts = ModulePath.split('/');
|
|
103
|
+
const ModuleName = ModulePathParts[ModulePathParts.length - 1];
|
|
104
|
+
const ModelName = inflection.camelize(options.modelName);
|
|
105
|
+
const ModelsName = inflection.pluralize(ModelName);
|
|
106
|
+
const UnderscoreModelName = inflection.underscore(ModelName);
|
|
107
|
+
const UnderscoreModelsName = inflection.underscore(ModelsName);
|
|
108
|
+
const KebabCaseModelName = inflection.dasherize(UnderscoreModelName);
|
|
109
|
+
const KebabCaseModelsName = inflection.dasherize(UnderscoreModelsName);
|
|
110
|
+
const FirstLowerModelName = inflection.camelize(ModelName, true);
|
|
111
|
+
const FirstLowerModelsName = inflection.camelize(ModelsName, true);
|
|
112
|
+
|
|
113
|
+
const data: CodeUtilGetGenerateData = {
|
|
114
|
+
FirstLowerModelName,
|
|
115
|
+
FirstLowerModelsName,
|
|
116
|
+
ModulePath,
|
|
117
|
+
ModuleName,
|
|
118
|
+
ModelName,
|
|
119
|
+
ModelsName,
|
|
120
|
+
KebabCaseModelName,
|
|
121
|
+
KebabCaseModelsName,
|
|
122
|
+
UnderscoreModelName,
|
|
123
|
+
UnderscoreModelsName,
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
return data;
|
|
127
|
+
},
|
|
128
|
+
|
|
129
|
+
/** 获取命令行参数 */
|
|
130
|
+
getArgv: () => {
|
|
131
|
+
return yargs(process.argv).argv as Record<string, any>;
|
|
132
|
+
},
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
export default codeUtil;
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
module.exports = {
|
|
2
|
-
root: true,
|
|
3
|
-
parserOptions: {
|
|
4
|
-
project: '../tsconfigs/eggjs.json',
|
|
5
|
-
},
|
|
6
|
-
extends: [
|
|
7
|
-
'eslint-config-egg/typescript',
|
|
8
|
-
'eslint:recommended',
|
|
9
|
-
'standard',
|
|
10
|
-
'plugin:@typescript-eslint/recommended',
|
|
11
|
-
'plugin:prettier/recommended',
|
|
12
|
-
'prettier',
|
|
13
|
-
],
|
|
14
|
-
rules: require('./rules/recommended'),
|
|
15
|
-
};
|
|
1
|
+
module.exports = {
|
|
2
|
+
root: true,
|
|
3
|
+
parserOptions: {
|
|
4
|
+
project: '../tsconfigs/eggjs.json',
|
|
5
|
+
},
|
|
6
|
+
extends: [
|
|
7
|
+
'eslint-config-egg/typescript',
|
|
8
|
+
'eslint:recommended',
|
|
9
|
+
'standard',
|
|
10
|
+
'plugin:@typescript-eslint/recommended',
|
|
11
|
+
'plugin:prettier/recommended',
|
|
12
|
+
'prettier',
|
|
13
|
+
],
|
|
14
|
+
rules: require('./rules/recommended'),
|
|
15
|
+
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* almighty eslint推荐element-ui.project
|
|
3
|
-
*/
|
|
4
|
-
module.exports = require('./vue.project');
|
|
1
|
+
/**
|
|
2
|
+
* almighty eslint推荐element-ui.project
|
|
3
|
+
*/
|
|
4
|
+
module.exports = require('./vue.project');
|
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* almighty eslint推荐
|
|
3
|
-
*/
|
|
4
|
-
module.exports = {
|
|
5
|
-
root: true,
|
|
6
|
-
parserOptions: {
|
|
7
|
-
parser: '@typescript-eslint/parser',
|
|
8
|
-
sourceType: 'module',
|
|
9
|
-
ecmaVersion: 2020,
|
|
10
|
-
ecmaFeatures: {
|
|
11
|
-
legacyDecorators: true,
|
|
12
|
-
},
|
|
13
|
-
},
|
|
14
|
-
|
|
15
|
-
env: {
|
|
16
|
-
node: true,
|
|
17
|
-
browser: true,
|
|
18
|
-
jest: true,
|
|
19
|
-
},
|
|
20
|
-
|
|
21
|
-
extends: ['eslint:recommended', 'standard', 'plugin:@typescript-eslint/recommended', 'plugin:prettier/recommended'],
|
|
22
|
-
|
|
23
|
-
plugins: ['import', 'jest', 'node', 'promise', 'prettier', 'standard', 'html'],
|
|
24
|
-
|
|
25
|
-
rules: require('./rules/recommended'),
|
|
26
|
-
};
|
|
1
|
+
/**
|
|
2
|
+
* almighty eslint推荐
|
|
3
|
+
*/
|
|
4
|
+
module.exports = {
|
|
5
|
+
root: true,
|
|
6
|
+
parserOptions: {
|
|
7
|
+
parser: '@typescript-eslint/parser',
|
|
8
|
+
sourceType: 'module',
|
|
9
|
+
ecmaVersion: 2020,
|
|
10
|
+
ecmaFeatures: {
|
|
11
|
+
legacyDecorators: true,
|
|
12
|
+
},
|
|
13
|
+
},
|
|
14
|
+
|
|
15
|
+
env: {
|
|
16
|
+
node: true,
|
|
17
|
+
browser: true,
|
|
18
|
+
jest: true,
|
|
19
|
+
},
|
|
20
|
+
|
|
21
|
+
extends: ['eslint:recommended', 'standard', 'plugin:@typescript-eslint/recommended', 'plugin:prettier/recommended'],
|
|
22
|
+
|
|
23
|
+
plugins: ['import', 'jest', 'node', 'promise', 'prettier', 'standard', 'html'],
|
|
24
|
+
|
|
25
|
+
rules: require('./rules/recommended'),
|
|
26
|
+
};
|
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
module.exports = {
|
|
2
|
-
semi: ['error', 'always'],
|
|
3
|
-
'arrow-parens': ['error', 'always'],
|
|
4
|
-
'comma-dangle': ['error', 'always-multiline'],
|
|
5
|
-
'no-multiple-empty-lines': ['error', { max: 1, maxBOF: 1, maxEOF: 1 }],
|
|
6
|
-
'no-undef': 'off',
|
|
7
|
-
'no-use-before-define': 'off',
|
|
8
|
-
'@typescript-eslint/interface-name-prefix': 'off',
|
|
9
|
-
'@typescript-eslint/explicit-function-return-type': 'off',
|
|
10
|
-
'@typescript-eslint/no-explicit-any': 'off',
|
|
11
|
-
'@typescript-eslint/no-empty-function': 'off',
|
|
12
|
-
'@typescript-eslint/explicit-module-boundary-types': 'off',
|
|
13
|
-
'@typescript-eslint/no-namespace': 'off',
|
|
14
|
-
'@typescript-eslint/ban-types': 'off',
|
|
15
|
-
'space-before-function-paren': 'off',
|
|
16
|
-
'@typescript-eslint/no-unused-vars': ['warn', { argsIgnorePattern: '^_' }],
|
|
17
|
-
'@typescript-eslint/no-this-alias': [
|
|
18
|
-
'error',
|
|
19
|
-
{
|
|
20
|
-
// Allow `const { props, state } = this`; false by default
|
|
21
|
-
allowDestructuring: true,
|
|
22
|
-
// Allow `const self = this`; `[]` by default
|
|
23
|
-
allowedNames: ['self'],
|
|
24
|
-
},
|
|
25
|
-
],
|
|
26
|
-
};
|
|
1
|
+
module.exports = {
|
|
2
|
+
semi: ['error', 'always'],
|
|
3
|
+
'arrow-parens': ['error', 'always'],
|
|
4
|
+
'comma-dangle': ['error', 'always-multiline'],
|
|
5
|
+
'no-multiple-empty-lines': ['error', { max: 1, maxBOF: 1, maxEOF: 1 }],
|
|
6
|
+
'no-undef': 'off',
|
|
7
|
+
'no-use-before-define': 'off',
|
|
8
|
+
'@typescript-eslint/interface-name-prefix': 'off',
|
|
9
|
+
'@typescript-eslint/explicit-function-return-type': 'off',
|
|
10
|
+
'@typescript-eslint/no-explicit-any': 'off',
|
|
11
|
+
'@typescript-eslint/no-empty-function': 'off',
|
|
12
|
+
'@typescript-eslint/explicit-module-boundary-types': 'off',
|
|
13
|
+
'@typescript-eslint/no-namespace': 'off',
|
|
14
|
+
'@typescript-eslint/ban-types': 'off',
|
|
15
|
+
'space-before-function-paren': 'off',
|
|
16
|
+
'@typescript-eslint/no-unused-vars': ['warn', { argsIgnorePattern: '^_' }],
|
|
17
|
+
'@typescript-eslint/no-this-alias': [
|
|
18
|
+
'error',
|
|
19
|
+
{
|
|
20
|
+
// Allow `const { props, state } = this`; false by default
|
|
21
|
+
allowDestructuring: true,
|
|
22
|
+
// Allow `const self = this`; `[]` by default
|
|
23
|
+
allowedNames: ['self'],
|
|
24
|
+
},
|
|
25
|
+
],
|
|
26
|
+
};
|