paas-build-package 0.0.1
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/.editorconfig +13 -0
- package/.vscode/extensions.json +13 -0
- package/.vscode/settings.json +19 -0
- package/.vscode/tasks.json +158 -0
- package/LICENSE +21 -0
- package/README.md +1 -0
- package/lerna.json +8 -0
- package/package.json +37 -0
- package/packages/build/CHANGELOG.md +14 -0
- package/packages/build/LICENSE +21 -0
- package/packages/build/README.md +1 -0
- package/packages/build/build.config.ts +22 -0
- package/packages/build/eslint.config.js +8 -0
- package/packages/build/package.json +103 -0
- package/packages/build/prettier.config.js +3 -0
- package/packages/build/src/commitlint/commitlint-config/commitlint-config.ts +37 -0
- package/packages/build/src/commitlint/index.ts +1 -0
- package/packages/build/src/constants/index.ts +70 -0
- package/packages/build/src/eslint/eslint-config/eslint-config.ts +161 -0
- package/packages/build/src/eslint/index.ts +1 -0
- package/packages/build/src/index.ts +8 -0
- package/packages/build/src/prettier/index.ts +1 -0
- package/packages/build/src/prettier/prettier-config/prettier-config.ts +48 -0
- package/packages/build/src/stylelint/index.ts +1 -0
- package/packages/build/src/stylelint/stylelint-config/stylelint-config.ts +39 -0
- package/packages/build/src/types/index.d.ts +1 -0
- package/packages/build/src/unocss/index.ts +1 -0
- package/packages/build/src/unocss/unocss.config.ts +45 -0
- package/packages/build/src/util/env-state/env-state.ts +9 -0
- package/packages/build/src/util/index.ts +52 -0
- package/packages/build/src/util/reg-exp/reg-exp.ts +1 -0
- package/packages/build/src/util/watcher/watcher.ts +114 -0
- package/packages/build/src/vite/index.ts +13 -0
- package/packages/build/src/vite/vite-config/vite-base-config.ts +49 -0
- package/packages/build/src/vite/vite-config/vite-config.ts +74 -0
- package/packages/build/src/vite/vite-config/vite-dev-config.ts +26 -0
- package/packages/build/src/vite/vite-config/vite-pkg-dev-config.ts +123 -0
- package/packages/build/src/vite/vite-config/vite-plugin-config.ts +149 -0
- package/packages/build/src/vite/vite-config/vite-project-config.ts +82 -0
- package/packages/build/src/vite/vite-plugins/imnport-external-plugin.ts +21 -0
- package/packages/build/src/vite/vite-plugins/inject-importmap-plugin.ts +133 -0
- package/packages/build/tsconfig.json +32 -0
- package/packages/cli/CHANGELOG.md +20 -0
- package/packages/cli/LICENSE +21 -0
- package/packages/cli/README.md +1 -0
- package/packages/cli/build.config.ts +22 -0
- package/packages/cli/hbs-temp/api-config.ts.hbs +21 -0
- package/packages/cli/hbs-temp/apis/{{api}}.service.d.ts.hbs +39 -0
- package/packages/cli/hbs-temp/entities.d.ts.hbs +19 -0
- package/packages/cli/hbs-temp/index.d.ts.hbs +9 -0
- package/packages/cli/package.json +72 -0
- package/packages/cli/src/actions/gen-api/api-manage.ts +96 -0
- package/packages/cli/src/actions/gen-api/gen-api.ts +211 -0
- package/packages/cli/src/actions/gen-api/model-manage.ts +269 -0
- package/packages/cli/src/actions/gen-api/special-entities.config.ts +26 -0
- package/packages/cli/src/actions/gen-cdn-lib/gen-cdn-lib.ts +149 -0
- package/packages/cli/src/actions/index.ts +3 -0
- package/packages/cli/src/actions/init-git/init-git.ts +28 -0
- package/packages/cli/src/bin.ts +5 -0
- package/packages/cli/src/commands/gen-api/gen-api.ts +65 -0
- package/packages/cli/src/commands/gen-cdn-lib/gen-cdn-lib.ts +25 -0
- package/packages/cli/src/commands/index.ts +22 -0
- package/packages/cli/src/commands/init-git/init-git.ts +16 -0
- package/packages/cli/src/core/handlebars/constant/index.ts +4 -0
- package/packages/cli/src/core/handlebars/handlebars-engine.ts +143 -0
- package/packages/cli/src/core/handlebars/helpers/and/and.ts +24 -0
- package/packages/cli/src/core/handlebars/helpers/camel-case/camel-case.ts +23 -0
- package/packages/cli/src/core/handlebars/helpers/concat/concat.ts +20 -0
- package/packages/cli/src/core/handlebars/helpers/eq/eq.ts +27 -0
- package/packages/cli/src/core/handlebars/helpers/format-import/format-import.ts +46 -0
- package/packages/cli/src/core/handlebars/helpers/format-import-item/format-import-item.ts +67 -0
- package/packages/cli/src/core/handlebars/helpers/format-js-type/format-js-type.ts +50 -0
- package/packages/cli/src/core/handlebars/helpers/gt/gt.ts +27 -0
- package/packages/cli/src/core/handlebars/helpers/gte/gte.ts +27 -0
- package/packages/cli/src/core/handlebars/helpers/helper-base.ts +27 -0
- package/packages/cli/src/core/handlebars/helpers/includes/includes.ts +25 -0
- package/packages/cli/src/core/handlebars/helpers/index.ts +52 -0
- package/packages/cli/src/core/handlebars/helpers/json/json.ts +23 -0
- package/packages/cli/src/core/handlebars/helpers/lower-case/lower-case.ts +22 -0
- package/packages/cli/src/core/handlebars/helpers/lt/lt.ts +27 -0
- package/packages/cli/src/core/handlebars/helpers/lte/lte.ts +27 -0
- package/packages/cli/src/core/handlebars/helpers/neq/neq.ts +27 -0
- package/packages/cli/src/core/handlebars/helpers/not/not.ts +25 -0
- package/packages/cli/src/core/handlebars/helpers/not-includes/not-includes.ts +25 -0
- package/packages/cli/src/core/handlebars/helpers/or/or.ts +26 -0
- package/packages/cli/src/core/handlebars/helpers/pascal-case/pascal-case.ts +23 -0
- package/packages/cli/src/core/handlebars/helpers/snake-case/snake-case.ts +23 -0
- package/packages/cli/src/core/handlebars/helpers/spinal-case/spinal-case.ts +23 -0
- package/packages/cli/src/core/handlebars/helpers/upper-case/upper-case.ts +22 -0
- package/packages/cli/src/core/handlebars/index.ts +2 -0
- package/packages/cli/src/core/handlebars/utils/helper/helper.ts +67 -0
- package/packages/cli/src/core/handlebars/utils/index.ts +23 -0
- package/packages/cli/src/core/index.ts +2 -0
- package/packages/cli/src/core/interface/index.ts +4 -0
- package/packages/cli/src/index.ts +36 -0
- package/packages/cli/src/interface/i-command/i-command.ts +23 -0
- package/packages/cli/src/interface/i-gen-cdn-lib-options/i-gen-cdn-lib-options.ts +58 -0
- package/packages/cli/src/interface/index.ts +2 -0
- package/packages/cli/src/types/index.d.ts +1 -0
- package/packages/cli/src/utils/index.ts +4 -0
- package/packages/cli/src/utils/local-binaries/local-binaries.ts +16 -0
- package/packages/cli/tsconfig.json +32 -0
- package/pnpm-workspace.yaml +10 -0
- package/tsconfig.app.json +18 -0
- package/tsconfig.json +11 -0
- package/tsconfig.node.json +26 -0
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { defineConfig, UserConfig, PluginOption } from 'vite';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import * as rf from 'rimraf';
|
|
4
|
+
import vue from '@vitejs/plugin-vue';
|
|
5
|
+
import vueJsx from '@vitejs/plugin-vue-jsx';
|
|
6
|
+
import { libInjectCss } from 'vite-plugin-lib-inject-css';
|
|
7
|
+
import { viteStaticCopy } from 'vite-plugin-static-copy';
|
|
8
|
+
import dts from 'vite-plugin-dts';
|
|
9
|
+
import { readFileSync, existsSync } from 'fs';
|
|
10
|
+
// import UnoCSS from 'unocss/vite';
|
|
11
|
+
import { mergeConfig, IS_NODE_MODULE } from '../../util';
|
|
12
|
+
import { DEFAULT_EXTERNAL } from '../../constants';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* pkg 包开发编译 vite 配置
|
|
16
|
+
*
|
|
17
|
+
* @export
|
|
18
|
+
* @param {UserConfig} [opts={}]
|
|
19
|
+
* @return {*} {UserConfig}
|
|
20
|
+
*/
|
|
21
|
+
export function definePkgDevViteConfig(opts: UserConfig = {}): UserConfig {
|
|
22
|
+
// 当前脚本执行的工作目录
|
|
23
|
+
const cwd = process.cwd();
|
|
24
|
+
// 编译文件输出目录
|
|
25
|
+
const outDir = path.resolve(cwd, 'es');
|
|
26
|
+
// 删除历史编译文件
|
|
27
|
+
rf.sync(outDir);
|
|
28
|
+
|
|
29
|
+
// 是否为开发模式启动
|
|
30
|
+
const isDev = process.env.NODE_ENV === 'development';
|
|
31
|
+
|
|
32
|
+
// 读取 package.json 中的 dependencies
|
|
33
|
+
let pkgDependencies: string[] = [];
|
|
34
|
+
try {
|
|
35
|
+
const pkgJsonPath = path.resolve(cwd, 'package.json');
|
|
36
|
+
const pkgJson = JSON.parse(readFileSync(pkgJsonPath, 'utf-8'));
|
|
37
|
+
pkgDependencies = Object.keys(pkgJson.dependencies || {});
|
|
38
|
+
} catch (error) {
|
|
39
|
+
console.warn('Failed to read package.json dependencies:', error);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return mergeConfig<UserConfig, UserConfig>(
|
|
43
|
+
defineConfig({
|
|
44
|
+
css: {
|
|
45
|
+
preprocessorOptions: {
|
|
46
|
+
scss: {
|
|
47
|
+
additionalData: `@use "@gct-paas/scss/style/global.scss" as *;`,
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
build: {
|
|
52
|
+
outDir,
|
|
53
|
+
target: 'esnext',
|
|
54
|
+
minify: false,
|
|
55
|
+
sourcemap: isDev,
|
|
56
|
+
rolldownOptions: {
|
|
57
|
+
external: (id: string) => {
|
|
58
|
+
// 排除 package.json 中声明的所有依赖
|
|
59
|
+
if (
|
|
60
|
+
pkgDependencies.some(
|
|
61
|
+
dep => id === dep || id.startsWith(dep + '/'),
|
|
62
|
+
)
|
|
63
|
+
) {
|
|
64
|
+
return true;
|
|
65
|
+
}
|
|
66
|
+
// 排除 node_modules 下的模块
|
|
67
|
+
if (IS_NODE_MODULE.test(id)) {
|
|
68
|
+
return true;
|
|
69
|
+
}
|
|
70
|
+
// 排除基础组件包
|
|
71
|
+
if (DEFAULT_EXTERNAL.includes(id)) {
|
|
72
|
+
return true;
|
|
73
|
+
}
|
|
74
|
+
return false;
|
|
75
|
+
},
|
|
76
|
+
output: {
|
|
77
|
+
preserveModules: true,
|
|
78
|
+
entryFileNames: ({ name }) => `${name}.mjs`,
|
|
79
|
+
assetFileNames: '[name][extname]', // 样式文件保留原名
|
|
80
|
+
},
|
|
81
|
+
},
|
|
82
|
+
lib: {
|
|
83
|
+
entry: path.resolve(process.cwd(), 'src/index.ts'),
|
|
84
|
+
formats: ['es'],
|
|
85
|
+
},
|
|
86
|
+
},
|
|
87
|
+
plugins: [
|
|
88
|
+
vue() as PluginOption,
|
|
89
|
+
vueJsx() as PluginOption,
|
|
90
|
+
// UnoCSS({ hmrTopLevelAwait: false }) as PluginOption,
|
|
91
|
+
libInjectCss(),
|
|
92
|
+
dts({
|
|
93
|
+
outDir: [outDir],
|
|
94
|
+
compilerOptions: {
|
|
95
|
+
declarationMap: isDev,
|
|
96
|
+
},
|
|
97
|
+
// 排除测试目录,以及测试文件
|
|
98
|
+
exclude: [
|
|
99
|
+
'**/test/**',
|
|
100
|
+
'**/*.test.ts',
|
|
101
|
+
'**/*.test.tsx',
|
|
102
|
+
'**/*.spec.ts',
|
|
103
|
+
'**/*.spec.tsx',
|
|
104
|
+
],
|
|
105
|
+
}),
|
|
106
|
+
...(existsSync(path.resolve(cwd, 'src/types'))
|
|
107
|
+
? [
|
|
108
|
+
viteStaticCopy({
|
|
109
|
+
targets: [
|
|
110
|
+
{
|
|
111
|
+
// 将 src/types 目录下的文件复制到编译输出目录
|
|
112
|
+
src: 'src/types',
|
|
113
|
+
dest: '.',
|
|
114
|
+
},
|
|
115
|
+
],
|
|
116
|
+
}),
|
|
117
|
+
]
|
|
118
|
+
: []),
|
|
119
|
+
],
|
|
120
|
+
}),
|
|
121
|
+
opts,
|
|
122
|
+
);
|
|
123
|
+
}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { mergeConfig, UserConfig } from 'vite';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
// import { federation } from '@module-federation/vite';
|
|
4
|
+
import { defineViteBaseConfig } from './vite-base-config';
|
|
5
|
+
import { DEFAULT_EXTERNAL } from '../../constants';
|
|
6
|
+
import { importMapExternalPlugin } from '../vite-plugins/imnport-external-plugin';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* 插件构建配置
|
|
10
|
+
*
|
|
11
|
+
* @export
|
|
12
|
+
* @param {UserConfig} [opts={}]
|
|
13
|
+
* @return {*} {UserConfig}
|
|
14
|
+
*/
|
|
15
|
+
export function definePluginViteConfig(opts: UserConfig = {}): UserConfig {
|
|
16
|
+
// 当前脚本执行的工作目录
|
|
17
|
+
const cwd = process.cwd();
|
|
18
|
+
// 设计界面插件打包入口文件
|
|
19
|
+
const entry = path.resolve(cwd, 'src/index.ts');
|
|
20
|
+
// 封装样式加载的 loader 模块打包入口文件
|
|
21
|
+
const loaderEntry = path.resolve(cwd, 'src/loader.ts');
|
|
22
|
+
// 是否生产模式
|
|
23
|
+
const isProd = process.env.NODE_ENV === 'production';
|
|
24
|
+
|
|
25
|
+
return mergeConfig<UserConfig, UserConfig>(
|
|
26
|
+
defineViteBaseConfig({
|
|
27
|
+
optimizeDeps: {
|
|
28
|
+
exclude: DEFAULT_EXTERNAL,
|
|
29
|
+
},
|
|
30
|
+
build: {
|
|
31
|
+
minify: isProd ? 'terser' : false,
|
|
32
|
+
terserOptions: {
|
|
33
|
+
// 压缩选项,控制代码压缩行为
|
|
34
|
+
compress: {
|
|
35
|
+
// 是否移除 console.* 调用;false 表示保留,避免生产环境丢失重要日志
|
|
36
|
+
drop_console: false,
|
|
37
|
+
// 是否移除永远不会执行的死代码(如 if(false){...})
|
|
38
|
+
dead_code: true,
|
|
39
|
+
// 是否移除未被引用的变量和函数,减小产物体积
|
|
40
|
+
unused: true,
|
|
41
|
+
// 压缩算法的执行轮数;多轮压缩可以发现单轮无法消除的冗余代码,但会增加构建耗时
|
|
42
|
+
passes: 2,
|
|
43
|
+
},
|
|
44
|
+
// 是否混淆变量名、函数名等标识符,使产物更难以阅读反编译,同时进一步缩小体积
|
|
45
|
+
mangle: true,
|
|
46
|
+
},
|
|
47
|
+
lib: {
|
|
48
|
+
entry: isProd ? loaderEntry : entry,
|
|
49
|
+
formats: ['es'],
|
|
50
|
+
cssFileName: 'index.min',
|
|
51
|
+
fileName: '[name].[format].min',
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
plugins: [
|
|
55
|
+
...importMapExternalPlugin(DEFAULT_EXTERNAL),
|
|
56
|
+
// federation({
|
|
57
|
+
// name: 'gct-paas-plugin',
|
|
58
|
+
// filename: 'remoteEntry.js',
|
|
59
|
+
// dts: false,
|
|
60
|
+
// manifest: true,
|
|
61
|
+
// exposes: {
|
|
62
|
+
// '.': './src/index.ts',
|
|
63
|
+
// },
|
|
64
|
+
// }),
|
|
65
|
+
],
|
|
66
|
+
}),
|
|
67
|
+
opts,
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* 设计界面插件构建配置
|
|
73
|
+
*
|
|
74
|
+
* @export
|
|
75
|
+
* @param {UserConfig} [opts={}]
|
|
76
|
+
* @return {*} {UserConfig}
|
|
77
|
+
*/
|
|
78
|
+
export function defineDesignPluginViteConfig(opts: UserConfig = {}): UserConfig {
|
|
79
|
+
return mergeConfig<UserConfig, UserConfig>(
|
|
80
|
+
definePluginViteConfig({
|
|
81
|
+
server: {
|
|
82
|
+
port: 7001,
|
|
83
|
+
host: '0.0.0.0',
|
|
84
|
+
allowedHosts: true,
|
|
85
|
+
},
|
|
86
|
+
}),
|
|
87
|
+
opts,
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* 设计界面插件构建配置
|
|
93
|
+
*
|
|
94
|
+
* @export
|
|
95
|
+
* @param {UserConfig} [opts={}]
|
|
96
|
+
* @return {*} {UserConfig}
|
|
97
|
+
*/
|
|
98
|
+
export function defineMobilePluginViteConfig(opts: UserConfig = {}): UserConfig {
|
|
99
|
+
return mergeConfig<UserConfig, UserConfig>(
|
|
100
|
+
definePluginViteConfig({
|
|
101
|
+
server: {
|
|
102
|
+
port: 7002,
|
|
103
|
+
host: '0.0.0.0',
|
|
104
|
+
allowedHosts: true,
|
|
105
|
+
},
|
|
106
|
+
}),
|
|
107
|
+
opts,
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* 设计界面插件构建配置
|
|
113
|
+
*
|
|
114
|
+
* @export
|
|
115
|
+
* @param {UserConfig} [opts={}]
|
|
116
|
+
* @return {*} {UserConfig}
|
|
117
|
+
*/
|
|
118
|
+
export function definePadPluginViteConfig(opts: UserConfig = {}): UserConfig {
|
|
119
|
+
return mergeConfig<UserConfig, UserConfig>(
|
|
120
|
+
definePluginViteConfig({
|
|
121
|
+
server: {
|
|
122
|
+
port: 7003,
|
|
123
|
+
host: '0.0.0.0',
|
|
124
|
+
allowedHosts: true,
|
|
125
|
+
},
|
|
126
|
+
}),
|
|
127
|
+
opts,
|
|
128
|
+
);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* 设计界面插件构建配置
|
|
133
|
+
*
|
|
134
|
+
* @export
|
|
135
|
+
* @param {UserConfig} [opts={}]
|
|
136
|
+
* @return {*} {UserConfig}
|
|
137
|
+
*/
|
|
138
|
+
export function defineWebPluginViteConfig(opts: UserConfig = {}): UserConfig {
|
|
139
|
+
return mergeConfig<UserConfig, UserConfig>(
|
|
140
|
+
definePluginViteConfig({
|
|
141
|
+
server: {
|
|
142
|
+
port: 7004,
|
|
143
|
+
host: '0.0.0.0',
|
|
144
|
+
allowedHosts: true,
|
|
145
|
+
},
|
|
146
|
+
}),
|
|
147
|
+
opts,
|
|
148
|
+
);
|
|
149
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import {
|
|
2
|
+
defineConfig,
|
|
3
|
+
PluginOption,
|
|
4
|
+
UserConfig,
|
|
5
|
+
UserConfigFnPromise,
|
|
6
|
+
} from 'vite';
|
|
7
|
+
import vue from '@vitejs/plugin-vue';
|
|
8
|
+
import vueJsx from '@vitejs/plugin-vue-jsx';
|
|
9
|
+
import UnoCSS from 'unocss/vite';
|
|
10
|
+
import path from 'path';
|
|
11
|
+
import fse from 'fs-extra';
|
|
12
|
+
import { mergeConfig } from '../../util';
|
|
13
|
+
import { DEFAULT_EXTERNAL } from '../../constants';
|
|
14
|
+
import { injectImportMapPlugin } from '../vite-plugins/inject-importmap-plugin';
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* 构建本地开发 project 项目 vite 通用配置,基于此配置构建其他 vite 配置
|
|
18
|
+
* 参数合并时,数组会被合并而不是被替换
|
|
19
|
+
*
|
|
20
|
+
* @author chitanda
|
|
21
|
+
* @date 2025-08-24 11:08:04
|
|
22
|
+
* @export
|
|
23
|
+
* @param {UserConfig} [opts={}]
|
|
24
|
+
* @returns {*} {Promise<UserConfig>}
|
|
25
|
+
*/
|
|
26
|
+
export function defineProjectViteConfig(
|
|
27
|
+
opts: UserConfig = {},
|
|
28
|
+
): UserConfigFnPromise {
|
|
29
|
+
return defineConfig(async () => {
|
|
30
|
+
// 获取当前工作目录
|
|
31
|
+
const cwd = process.cwd();
|
|
32
|
+
// 获取工作目录 package.json 文件内容
|
|
33
|
+
const pkg = fse.readJsonSync(path.resolve(cwd, 'package.json'));
|
|
34
|
+
|
|
35
|
+
return mergeConfig<UserConfig, UserConfig>(
|
|
36
|
+
{
|
|
37
|
+
resolve: {
|
|
38
|
+
alias: {
|
|
39
|
+
'@/*': 'src/*',
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
base: './',
|
|
43
|
+
build: {
|
|
44
|
+
rolldownOptions: {
|
|
45
|
+
external: DEFAULT_EXTERNAL,
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
css: {
|
|
49
|
+
preprocessorOptions: {
|
|
50
|
+
scss: {
|
|
51
|
+
additionalData: `@use "@gct-paas/scss/style/global.scss" as *;`,
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
server: {
|
|
56
|
+
host: '0.0.0.0',
|
|
57
|
+
allowedHosts: true,
|
|
58
|
+
cors: true,
|
|
59
|
+
fs: {
|
|
60
|
+
strict: false,
|
|
61
|
+
},
|
|
62
|
+
proxy: {
|
|
63
|
+
hostname: '0.0.0.0',
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
define: {
|
|
67
|
+
'import.meta.env.pkg': {
|
|
68
|
+
name: pkg.name,
|
|
69
|
+
version: pkg.version,
|
|
70
|
+
},
|
|
71
|
+
},
|
|
72
|
+
plugins: [
|
|
73
|
+
vue() as PluginOption,
|
|
74
|
+
vueJsx() as PluginOption,
|
|
75
|
+
UnoCSS({ hmrTopLevelAwait: false }) as PluginOption,
|
|
76
|
+
injectImportMapPlugin() as PluginOption,
|
|
77
|
+
],
|
|
78
|
+
},
|
|
79
|
+
opts,
|
|
80
|
+
);
|
|
81
|
+
});
|
|
82
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 在 dev 模式下:告诉 Rollup/Rolldown 指定模块是 external
|
|
3
|
+
*
|
|
4
|
+
* @export
|
|
5
|
+
* @param {string[]} modules
|
|
6
|
+
* @return {*}
|
|
7
|
+
*/
|
|
8
|
+
export function importMapExternalPlugin(modules: string[]) {
|
|
9
|
+
return [
|
|
10
|
+
{
|
|
11
|
+
name: 'gct-vite-plugin:import-external',
|
|
12
|
+
apply: 'serve' as const,
|
|
13
|
+
enforce: 'pre' as const,
|
|
14
|
+
resolveId(id: string) {
|
|
15
|
+
if (modules.includes(id)) {
|
|
16
|
+
return { id, external: true };
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
];
|
|
21
|
+
}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { simpleGit } from 'simple-git';
|
|
4
|
+
import type { Plugin, HtmlTagDescriptor } from 'vite';
|
|
5
|
+
import { isBuildPluginEnv } from '../../util';
|
|
6
|
+
|
|
7
|
+
export interface InjectImportMapPluginOptions {
|
|
8
|
+
/**
|
|
9
|
+
* 仓库地址,默认为 https://git.gct-china.com/paas/frontend/gct-paas-cdn.git
|
|
10
|
+
*/
|
|
11
|
+
repoUrl?: string;
|
|
12
|
+
/**
|
|
13
|
+
* 需要读取的文件路径,默认为 extras/import-map.json
|
|
14
|
+
*/
|
|
15
|
+
filePath?: string;
|
|
16
|
+
/**
|
|
17
|
+
* 指定分支,若未指定则自动获取当前主工程对应的分支
|
|
18
|
+
*/
|
|
19
|
+
branch?: string;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// importMap 开发态前缀路径
|
|
23
|
+
const DEV_IMPORT_MAP_PREFIX: string[] = ['/plugin-kit/@id/', '/plugin-design/@id/', '/plugin-render-mobile/@id/', '/plugin-render-pad/@id/', '/plugin-render-web/@id/'];
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* 编译时读取并注入 import-map 配置的插件
|
|
27
|
+
*/
|
|
28
|
+
export function injectImportMapPlugin(options: InjectImportMapPluginOptions = {}): Plugin {
|
|
29
|
+
const {
|
|
30
|
+
repoUrl = 'https://git.gct-china.com/paas/frontend/gct-paas-cdn.git',
|
|
31
|
+
filePath = 'extras/import-map.json',
|
|
32
|
+
} = options;
|
|
33
|
+
|
|
34
|
+
let importMapContent = '{}';
|
|
35
|
+
|
|
36
|
+
return {
|
|
37
|
+
name: 'gct-vite-plugin:inject-importmap',
|
|
38
|
+
apply: 'build',
|
|
39
|
+
async buildStart() {
|
|
40
|
+
const cwd = process.cwd();
|
|
41
|
+
let targetBranch = options.branch;
|
|
42
|
+
|
|
43
|
+
// 1. 如果未传 branch,则获取当前工作区的 branch
|
|
44
|
+
if (!targetBranch) {
|
|
45
|
+
// CI 环境(如 GitLab CI)会设置标准环境变量,优先使用
|
|
46
|
+
targetBranch = process.env.CI_COMMIT_BRANCH || process.env.CI_BUILD_REF_NAME;
|
|
47
|
+
|
|
48
|
+
if (!targetBranch) {
|
|
49
|
+
const cwdGit = simpleGit(cwd);
|
|
50
|
+
try {
|
|
51
|
+
const raw = await cwdGit.revparse(['--abbrev-ref', 'HEAD']);
|
|
52
|
+
const resolved = raw.trim();
|
|
53
|
+
// 游离 HEAD 状态(detached HEAD)下返回字面量 "HEAD",分支名无效
|
|
54
|
+
if (resolved && resolved !== 'HEAD') {
|
|
55
|
+
targetBranch = resolved;
|
|
56
|
+
}
|
|
57
|
+
} catch {
|
|
58
|
+
// 忽略,下方统一处理
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
if (!targetBranch) {
|
|
63
|
+
this.error(
|
|
64
|
+
'无法自动获取当前 git 分支:当前可能处于游离 HEAD(detached HEAD)状态(CI 环境常见)。' +
|
|
65
|
+
'请通过 options.branch 明确指定分支名,或确保环境变量 CI_COMMIT_BRANCH / CI_BUILD_REF_NAME 已设置。',
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// 2. 准备缓存目录,使用 sparse checkout 减少体积
|
|
71
|
+
const cacheDir = path.resolve(cwd, 'node_modules/.gct/cache/importmap-repo-cache');
|
|
72
|
+
|
|
73
|
+
try {
|
|
74
|
+
if (!fs.existsSync(cacheDir)) {
|
|
75
|
+
fs.mkdirSync(cacheDir, { recursive: true });
|
|
76
|
+
const git = simpleGit(cacheDir);
|
|
77
|
+
await git.init();
|
|
78
|
+
await git.addRemote('origin', repoUrl);
|
|
79
|
+
await git.raw(['config', 'core.sparseCheckout', 'true']);
|
|
80
|
+
// 写入需要拉取的单一文件到 sparse-checkout 配置中
|
|
81
|
+
fs.writeFileSync(path.join(cacheDir, '.git/info/sparse-checkout'), filePath);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// 3. 每次执行都进行 fetch 确保拿到最新文件
|
|
85
|
+
const git = simpleGit(cacheDir);
|
|
86
|
+
// 重置 origin,防止 url 变更或者后期添加 token 等
|
|
87
|
+
await git.remote(['set-url', 'origin', repoUrl]);
|
|
88
|
+
// 浅拉取对应分支,depth=1
|
|
89
|
+
await git.fetch('origin', targetBranch!, { '--depth': 1 });
|
|
90
|
+
// 强制重置工作区到远程最新的快照,丢弃并覆盖过期内容
|
|
91
|
+
await git.reset(['--hard', `origin/${targetBranch}`]);
|
|
92
|
+
|
|
93
|
+
// 4. 读取文件并验证 JSON
|
|
94
|
+
const targetFilePath = path.join(cacheDir, filePath);
|
|
95
|
+
if (!fs.existsSync(targetFilePath)) {
|
|
96
|
+
this.error(`在仓库 ${repoUrl} 的 ${targetBranch} 分支中,未找到文件: ${filePath}。`);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const rawContent = fs.readFileSync(targetFilePath, 'utf-8');
|
|
100
|
+
try {
|
|
101
|
+
// 验证并过滤格式
|
|
102
|
+
const parsed = JSON.parse(rawContent);
|
|
103
|
+
// 补充开发态前缀路径,确保本地调试时能够正确解析模块
|
|
104
|
+
if (isBuildPluginEnv() && parsed.imports) {
|
|
105
|
+
const keys = Object.keys(parsed.imports);
|
|
106
|
+
DEV_IMPORT_MAP_PREFIX.forEach(prefix => {
|
|
107
|
+
keys.forEach(key => {
|
|
108
|
+
const val = parsed.imports[key];
|
|
109
|
+
parsed.imports[prefix + key] = val;
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
importMapContent = JSON.stringify(parsed);
|
|
114
|
+
} catch (parseError) {
|
|
115
|
+
this.error(`目标文件 ${filePath} 包含非法的 JSON 格式: ${parseError}`);
|
|
116
|
+
}
|
|
117
|
+
} catch (error) {
|
|
118
|
+
this.error(`从 Git 仓库拉取或读取 import-map.json 时发生错误: ${error}`);
|
|
119
|
+
}
|
|
120
|
+
},
|
|
121
|
+
|
|
122
|
+
transformIndexHtml(): HtmlTagDescriptor[] {
|
|
123
|
+
return [
|
|
124
|
+
{
|
|
125
|
+
tag: 'script',
|
|
126
|
+
attrs: { type: 'importmap' },
|
|
127
|
+
injectTo: 'head-prepend',
|
|
128
|
+
children: importMapContent,
|
|
129
|
+
},
|
|
130
|
+
];
|
|
131
|
+
},
|
|
132
|
+
};
|
|
133
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"module": "esnext",
|
|
4
|
+
"target": "esnext",
|
|
5
|
+
"lib": [
|
|
6
|
+
"ES2022"
|
|
7
|
+
],
|
|
8
|
+
"moduleResolution": "bundler",
|
|
9
|
+
"noEmit": true,
|
|
10
|
+
"allowImportingTsExtensions": true,
|
|
11
|
+
"sourceMap": false,
|
|
12
|
+
"declaration": true,
|
|
13
|
+
"declarationMap": true,
|
|
14
|
+
"strict": true,
|
|
15
|
+
"skipDefaultLibCheck": true,
|
|
16
|
+
"skipLibCheck": true,
|
|
17
|
+
"experimentalDecorators": true,
|
|
18
|
+
"esModuleInterop": true,
|
|
19
|
+
"resolveJsonModule": true,
|
|
20
|
+
"forceConsistentCasingInFileNames": true,
|
|
21
|
+
"rootDir": "src",
|
|
22
|
+
"outDir": "dist",
|
|
23
|
+
"types": ["./src/types"]
|
|
24
|
+
},
|
|
25
|
+
"include": [
|
|
26
|
+
"src/**/*.ts"
|
|
27
|
+
],
|
|
28
|
+
"exclude": [
|
|
29
|
+
"node_modules",
|
|
30
|
+
"test"
|
|
31
|
+
]
|
|
32
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# 版本变更日志
|
|
2
|
+
|
|
3
|
+
这个项目的所有关键变化都将记录在此文件中.
|
|
4
|
+
|
|
5
|
+
此日志格式基于 [Keep a Changelog](https://keepachangelog.com/zh-CN/1.1.0/),
|
|
6
|
+
并且此项目遵循 [Semantic Versioning](https://semver.org/lang/zh-CN/).
|
|
7
|
+
|
|
8
|
+
## [Unreleased]
|
|
9
|
+
|
|
10
|
+
## [0.1.3] - 2025-06-16
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
|
|
14
|
+
- 新增对 ResponseEntity«List«Tree«string»»»、ResponseEntity«PageBase«AgentResponse»» 类似类型的处理
|
|
15
|
+
|
|
16
|
+
## [0.0.1] - 2025-01-07
|
|
17
|
+
|
|
18
|
+
### Added
|
|
19
|
+
|
|
20
|
+
- 初始化项目.
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 冠骋信息技术有限公司
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { defineBuildConfig } from 'unbuild';
|
|
2
|
+
|
|
3
|
+
export default defineBuildConfig({
|
|
4
|
+
entries: [
|
|
5
|
+
{
|
|
6
|
+
builder: 'mkdist',
|
|
7
|
+
input: './src/',
|
|
8
|
+
outDir: './es',
|
|
9
|
+
format: 'esm',
|
|
10
|
+
ext: 'mjs',
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
builder: 'mkdist',
|
|
14
|
+
input: './src/',
|
|
15
|
+
outDir: './dist',
|
|
16
|
+
format: 'cjs',
|
|
17
|
+
ext: 'cjs',
|
|
18
|
+
},
|
|
19
|
+
],
|
|
20
|
+
// Generates .d.ts declaration file
|
|
21
|
+
declaration: true,
|
|
22
|
+
});
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
2
|
+
export const apiConfig: any[] = [
|
|
3
|
+
{{#each entities as |entity|}}
|
|
4
|
+
{
|
|
5
|
+
name: '{{camelCase entity.entityName}}',
|
|
6
|
+
entityName: '{{entity.entityName}}',
|
|
7
|
+
apis: [
|
|
8
|
+
{{#each methods as |method|}}
|
|
9
|
+
{
|
|
10
|
+
mode: '{{ method.mode }}',
|
|
11
|
+
method: '{{ method.mode }}{{#if method.name}}{{pascalCase (camelCase method.name) }}{{/if}}',
|
|
12
|
+
path: '{{#eq method.name '{id}'}}{{else}}{{method.model.requestPath}}{{/eq}}',
|
|
13
|
+
{{#gt method.pathParams.length 0}}hasPathParams: true,{{/gt}}
|
|
14
|
+
{{#gt method.queries.length 0}}hasQuery: true,{{/gt}}
|
|
15
|
+
{{#if method.requestEntity}}hasData: true{{/if}}
|
|
16
|
+
},
|
|
17
|
+
{{/each}}
|
|
18
|
+
]
|
|
19
|
+
},
|
|
20
|
+
{{/each}}
|
|
21
|
+
]
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
+
import type { AxiosRequestConfig } from 'axios';
|
|
3
|
+
{{#gt entityRefs.length 0}}
|
|
4
|
+
import type { {{formatImport entityRefs}} } from '../entities';
|
|
5
|
+
|
|
6
|
+
{{/gt}}
|
|
7
|
+
{{#each methods as |method|}}
|
|
8
|
+
{{#gt method.queries.length 0}}
|
|
9
|
+
export interface {{ method.mode }}{{#if method.name}}{{pascalCase (camelCase method.name) }}{{/if}}Query {
|
|
10
|
+
{{#each method.queries as |query|}}
|
|
11
|
+
{{#neq query.description ""}}
|
|
12
|
+
/**
|
|
13
|
+
* {{query.description}}
|
|
14
|
+
*/
|
|
15
|
+
{{/neq}}
|
|
16
|
+
{{#eq query.name "requestParam"}}
|
|
17
|
+
[key: any]: any;
|
|
18
|
+
{{else}}
|
|
19
|
+
{{camelCase query.name}}{{#if query.required}}{{else}}?{{/if}}: {{#if query.items}}{{formatJsType query}}{{else}}{{formatJsType query}}{{/if}};
|
|
20
|
+
{{/eq}}
|
|
21
|
+
{{/each}}
|
|
22
|
+
}
|
|
23
|
+
{{/gt}}
|
|
24
|
+
{{#gt method.pathParams.length 0}}
|
|
25
|
+
export interface {{ method.mode }}{{#if method.name}}{{pascalCase (camelCase method.name) }}{{/if}}PathParams {
|
|
26
|
+
{{#each method.pathParams as |param|}}
|
|
27
|
+
{{camelCase param}}: string;
|
|
28
|
+
{{/each}}
|
|
29
|
+
}
|
|
30
|
+
{{/gt}}
|
|
31
|
+
{{/each}}
|
|
32
|
+
export interface {{pascalCase (camelCase entityName) }}Service {
|
|
33
|
+
{{#each methods as |method|}}
|
|
34
|
+
/**
|
|
35
|
+
* {{ method.model.summary }}
|
|
36
|
+
*/
|
|
37
|
+
{{ method.mode }}{{#if method.name}}{{pascalCase (camelCase method.name) }}{{/if}}({{#gt method.pathParams.length 0}}path: {{ method.mode }}{{#if method.name}}{{pascalCase (camelCase method.name) }}{{/if}}PathParams, {{/gt}}{{#gt method.queries.length 0}}query: {{ method.mode }}{{#if method.name}}{{pascalCase (camelCase method.name) }}{{/if}}Query, {{/gt}}{{#if method.requestEntity}}data: {{method.requestEntity.title}}, {{/if}}config?: Partial<AxiosRequestConfig>): Promise<{{#if method.responseEntity}}{{formatImportItem method.responseEntity.title}}{{else}}any{{/if}}>;
|
|
38
|
+
{{/each}}
|
|
39
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-empty-object-type */
|
|
2
|
+
{{#each definitions as |entity|}}
|
|
3
|
+
{{#notIncludes entity.title '«'}}
|
|
4
|
+
export interface {{ entity.title }} {
|
|
5
|
+
{{#gt entity.propertySize 0}}
|
|
6
|
+
{{#each entity.properties as |property key|}}
|
|
7
|
+
/**
|
|
8
|
+
* {{ property.description }}
|
|
9
|
+
*
|
|
10
|
+
* @type {{{formatJsType property }}}
|
|
11
|
+
*/
|
|
12
|
+
{{ key }}{{#if property.required}}{{else}}?{{/if}}: {{formatJsType property }};
|
|
13
|
+
{{/each}}
|
|
14
|
+
{{else}}
|
|
15
|
+
// 暂无属性
|
|
16
|
+
{{/gt}}
|
|
17
|
+
}
|
|
18
|
+
{{/notIncludes}}
|
|
19
|
+
{{/each}}
|