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,161 @@
|
|
|
1
|
+
import { defineConfig } from 'eslint/config';
|
|
2
|
+
import eslint from '@eslint/js';
|
|
3
|
+
import type { ConfigWithExtendsArray } from '@eslint/config-helpers';
|
|
4
|
+
import tsEslint, { ConfigArray, parser } from 'typescript-eslint';
|
|
5
|
+
import eslintPluginVue from 'eslint-plugin-vue';
|
|
6
|
+
import vueParser from 'vue-eslint-parser';
|
|
7
|
+
import eslintPluginPrettierRecommended from 'eslint-plugin-prettier/recommended';
|
|
8
|
+
import unusedImports from 'eslint-plugin-unused-imports';
|
|
9
|
+
import eslintPluginImport from 'eslint-plugin-import';
|
|
10
|
+
import globals from 'globals';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* 基于基础规则,定义 eslint 配置
|
|
14
|
+
*
|
|
15
|
+
* @export
|
|
16
|
+
* @param {...ConfigWithExtendsArray} configs
|
|
17
|
+
* @returns {*} {ConfigArray}
|
|
18
|
+
*/
|
|
19
|
+
export function defineEslintConfig(
|
|
20
|
+
...configs: ConfigWithExtendsArray
|
|
21
|
+
): ConfigArray {
|
|
22
|
+
return defineConfig(
|
|
23
|
+
// 基础配置
|
|
24
|
+
eslint.configs.recommended,
|
|
25
|
+
tsEslint.configs.recommended,
|
|
26
|
+
tsEslint.configs.strict,
|
|
27
|
+
tsEslint.configs.stylistic,
|
|
28
|
+
eslintPluginVue.configs['flat/recommended'],
|
|
29
|
+
eslintPluginPrettierRecommended,
|
|
30
|
+
eslintPluginImport.flatConfigs.recommended,
|
|
31
|
+
eslintPluginImport.flatConfigs.warnings,
|
|
32
|
+
eslintPluginImport.flatConfigs.errors,
|
|
33
|
+
eslintPluginImport.flatConfigs.typescript,
|
|
34
|
+
|
|
35
|
+
// 自定义配置
|
|
36
|
+
{
|
|
37
|
+
ignores: [
|
|
38
|
+
'**/node_modules',
|
|
39
|
+
'lerna.json',
|
|
40
|
+
'package.json',
|
|
41
|
+
'tsconfig.json',
|
|
42
|
+
'pnpm-lock.yaml',
|
|
43
|
+
'pnpm-workspace.yaml',
|
|
44
|
+
'eslint.config.mjs',
|
|
45
|
+
'**/dist',
|
|
46
|
+
'**/out',
|
|
47
|
+
'**/es',
|
|
48
|
+
'**/lib',
|
|
49
|
+
],
|
|
50
|
+
files: ['**/*.{ts,tsx,vue}'],
|
|
51
|
+
plugins: {
|
|
52
|
+
'unused-imports': unusedImports,
|
|
53
|
+
},
|
|
54
|
+
languageOptions: {
|
|
55
|
+
globals: {
|
|
56
|
+
...globals.browser,
|
|
57
|
+
...globals.node,
|
|
58
|
+
},
|
|
59
|
+
parser: parser,
|
|
60
|
+
parserOptions: {
|
|
61
|
+
ecmaFeatures: {
|
|
62
|
+
impliedStrict: true, // 全局严格模式
|
|
63
|
+
jsx: true, // 启用 JSX
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
rules: {
|
|
68
|
+
// 基础规则覆盖
|
|
69
|
+
'no-console': 'off',
|
|
70
|
+
'no-debugger': 'off',
|
|
71
|
+
'no-undef': 'off',
|
|
72
|
+
'no-plusplus': [
|
|
73
|
+
'error',
|
|
74
|
+
{
|
|
75
|
+
allowForLoopAfterthoughts: true,
|
|
76
|
+
},
|
|
77
|
+
],
|
|
78
|
+
'no-underscore-dangle': 'off',
|
|
79
|
+
'no-restricted-syntax': 'off',
|
|
80
|
+
'no-useless-assignment': 'off',
|
|
81
|
+
'no-continue': 'off',
|
|
82
|
+
'no-unused-vars': 'off', // 关闭基础规则,由 TypeScript 规则接管
|
|
83
|
+
'no-extraneous-class': 'off',
|
|
84
|
+
'no-param-reassign': 'off',
|
|
85
|
+
'no-useless-constructor': 'off',
|
|
86
|
+
'no-empty-function': 'off',
|
|
87
|
+
|
|
88
|
+
// unused-imports 插件规则
|
|
89
|
+
'unused-imports/no-unused-imports': 'error',
|
|
90
|
+
'consistent-return': 'off',
|
|
91
|
+
'func-names': 'off',
|
|
92
|
+
|
|
93
|
+
// import 插件规则
|
|
94
|
+
'import/no-unresolved': 'off',
|
|
95
|
+
'import/extensions': 'off',
|
|
96
|
+
'import/prefer-default-export': 'off',
|
|
97
|
+
|
|
98
|
+
// TypeScript 规则覆盖
|
|
99
|
+
'@typescript-eslint/no-unused-vars': [
|
|
100
|
+
'error',
|
|
101
|
+
{
|
|
102
|
+
argsIgnorePattern: '^_',
|
|
103
|
+
},
|
|
104
|
+
],
|
|
105
|
+
'@typescript-eslint/no-inferrable-types': 'off',
|
|
106
|
+
'@typescript-eslint/no-explicit-any': ['error'],
|
|
107
|
+
'@typescript-eslint/explicit-module-boundary-types': 'off',
|
|
108
|
+
'@typescript-eslint/no-non-null-assertion': 'off',
|
|
109
|
+
'@typescript-eslint/no-extraneous-class': 'off',
|
|
110
|
+
'@typescript-eslint/no-dynamic-delete': 'off',
|
|
111
|
+
// 其他规则覆盖
|
|
112
|
+
'class-methods-use-this': 'off',
|
|
113
|
+
'prefer-destructuring': 'off',
|
|
114
|
+
'no-restricted-imports': [
|
|
115
|
+
'error',
|
|
116
|
+
{
|
|
117
|
+
paths: [
|
|
118
|
+
{
|
|
119
|
+
name: '@/index',
|
|
120
|
+
message: '禁止从 index 导入内容',
|
|
121
|
+
},
|
|
122
|
+
{
|
|
123
|
+
name: '@/loader',
|
|
124
|
+
message: '禁止从 loader 导入内容',
|
|
125
|
+
},
|
|
126
|
+
{
|
|
127
|
+
name: '..',
|
|
128
|
+
message: '禁止从内部导入内容自身内容',
|
|
129
|
+
},
|
|
130
|
+
],
|
|
131
|
+
},
|
|
132
|
+
],
|
|
133
|
+
},
|
|
134
|
+
},
|
|
135
|
+
{
|
|
136
|
+
name: 'ts-vue-override',
|
|
137
|
+
files: ['**/*.vue'],
|
|
138
|
+
languageOptions: {
|
|
139
|
+
parser: vueParser,
|
|
140
|
+
globals: { ...globals.browser, ...globals.node },
|
|
141
|
+
parserOptions: {
|
|
142
|
+
/** typescript项目需要用到这个 */
|
|
143
|
+
parser: tsEslint.parser,
|
|
144
|
+
ecmaVersion: 'latest',
|
|
145
|
+
/** 允许在.vue 文件中使用 JSX */
|
|
146
|
+
ecmaFeatures: {
|
|
147
|
+
jsx: true,
|
|
148
|
+
},
|
|
149
|
+
},
|
|
150
|
+
},
|
|
151
|
+
rules: {
|
|
152
|
+
'@typescript-eslint/no-unused-vars': 'off',
|
|
153
|
+
'@typescript-eslint/no-unused-expressions': 'off',
|
|
154
|
+
// Vue 规则覆盖
|
|
155
|
+
'vue/no-setup-props-destructure': 'off',
|
|
156
|
+
'vue/require-default-prop': 'off',
|
|
157
|
+
},
|
|
158
|
+
},
|
|
159
|
+
...configs,
|
|
160
|
+
);
|
|
161
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { defineEslintConfig } from './eslint-config/eslint-config';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { definePrettierConfig } from './prettier-config/prettier-config';
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { Options } from 'prettier';
|
|
2
|
+
import { mergeConfig } from '../../util';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* 基于基础配置,定义 prettier 配置
|
|
6
|
+
*
|
|
7
|
+
* @description 提交信息规范,提交格式: type: description
|
|
8
|
+
* feat: 新功能(feature)
|
|
9
|
+
* fix: 修补bug
|
|
10
|
+
* docs: 文档(documentation)
|
|
11
|
+
* style: 格式(不影响代码运行的变动)
|
|
12
|
+
* refactor: 重构(即不是新增功能,也不是修改bug的代码变动)
|
|
13
|
+
* test: 增加测试,或测试变更
|
|
14
|
+
* perf : 性能优化
|
|
15
|
+
* revert: 撤销上一次的提交
|
|
16
|
+
* build: 构建工具或构建过程等的变动,如:关联包升级等
|
|
17
|
+
* chore: 其他修改(不在上述类型中的修改)
|
|
18
|
+
* release: 发布新版本
|
|
19
|
+
*
|
|
20
|
+
* @export
|
|
21
|
+
* @param {Options} config
|
|
22
|
+
* @returns {*} {Options}
|
|
23
|
+
*/
|
|
24
|
+
export function definePrettierConfig(config: Options = {}): Options {
|
|
25
|
+
return mergeConfig<Options, Options>(
|
|
26
|
+
{
|
|
27
|
+
// 起始格式化间隔
|
|
28
|
+
tabWidth: 2,
|
|
29
|
+
// 使用单引号
|
|
30
|
+
singleQuote: true,
|
|
31
|
+
// jsx 中使用单引号
|
|
32
|
+
jsxSingleQuote: true,
|
|
33
|
+
// 对象中的 key 是否需要引号。as-needed: 只有在必须时才要
|
|
34
|
+
quoteProps: 'as-needed',
|
|
35
|
+
// 每行结尾是否需要分号
|
|
36
|
+
trailingComma: 'all',
|
|
37
|
+
// 括号中参数前后补充空格
|
|
38
|
+
bracketSpacing: true,
|
|
39
|
+
// 箭头函数,参数是否添加括号
|
|
40
|
+
arrowParens: 'avoid',
|
|
41
|
+
// jsx 元素最后末尾的 > ,换行放置
|
|
42
|
+
bracketSameLine: false,
|
|
43
|
+
// 设置换行符
|
|
44
|
+
endOfLine: 'lf',
|
|
45
|
+
},
|
|
46
|
+
config,
|
|
47
|
+
);
|
|
48
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { defineStylelintConfig } from './stylelint-config/stylelint-config';
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { merge } from 'lodash-es';
|
|
2
|
+
import { Config } from 'stylelint';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* 基于基础规则,定义 stylelint 配置
|
|
6
|
+
*
|
|
7
|
+
* @export
|
|
8
|
+
* @param {Config} config
|
|
9
|
+
* @returns {*} {Config}
|
|
10
|
+
*/
|
|
11
|
+
export function defineStylelintConfig(config: Config = {}): Config {
|
|
12
|
+
return merge(
|
|
13
|
+
{
|
|
14
|
+
extends: [
|
|
15
|
+
'stylelint-config-standard-scss',
|
|
16
|
+
'stylelint-config-recess-order',
|
|
17
|
+
],
|
|
18
|
+
rules: {
|
|
19
|
+
'annotation-no-unknown': null,
|
|
20
|
+
'color-no-invalid-hex': true,
|
|
21
|
+
'function-name-case': null, // 强制样式方法名称小写或大写
|
|
22
|
+
'no-duplicate-selectors': null,
|
|
23
|
+
'selector-class-pattern': null,
|
|
24
|
+
'scss/dollar-variable-pattern': null,
|
|
25
|
+
'scss/at-function-pattern': null,
|
|
26
|
+
'scss/dollar-variable-empty-line-before': null, // 变量声明之间不可以有空白行
|
|
27
|
+
'nesting-selector-no-missing-scoping-root': null,
|
|
28
|
+
'selector-pseudo-class-no-unknown': [
|
|
29
|
+
true,
|
|
30
|
+
{
|
|
31
|
+
// css modules 的 :global 伪类
|
|
32
|
+
ignorePseudoClasses: ['global'],
|
|
33
|
+
},
|
|
34
|
+
],
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
config,
|
|
38
|
+
);
|
|
39
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
declare module 'eslint-plugin-import';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './unocss.config';
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import {
|
|
2
|
+
defineConfig,
|
|
3
|
+
presetTypography,
|
|
4
|
+
presetUno,
|
|
5
|
+
presetWebFonts,
|
|
6
|
+
UserConfig,
|
|
7
|
+
} from 'unocss';
|
|
8
|
+
import { mergeConfig } from '../util';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* 定义 unocss 配置,基于此配置构建其他 unocss 配置
|
|
12
|
+
*
|
|
13
|
+
* @export
|
|
14
|
+
* @param {UserConfig} config
|
|
15
|
+
* @return {*} {UserConfig}
|
|
16
|
+
*/
|
|
17
|
+
export function defineUnoConfig(config: UserConfig): UserConfig {
|
|
18
|
+
return defineConfig(
|
|
19
|
+
mergeConfig<UserConfig, UserConfig>(
|
|
20
|
+
{
|
|
21
|
+
shortcuts: {
|
|
22
|
+
'ks-row': 'flex',
|
|
23
|
+
'ks-column': 'flex flex-col',
|
|
24
|
+
'ks-col': 'flex-1',
|
|
25
|
+
'ks-row-middle': 'flex items-center',
|
|
26
|
+
'ks-row-start': 'flex items-start',
|
|
27
|
+
'ks-row-end': 'flex items-end',
|
|
28
|
+
'ks-row-center': 'flex justify-center',
|
|
29
|
+
'ks-row-left': 'flex justify-start',
|
|
30
|
+
'ks-row-right': 'flex justify-end',
|
|
31
|
+
'ks-row-center-middle': 'flex items-center justify-center',
|
|
32
|
+
'ks-row-center-between': 'flex items-center justify-between',
|
|
33
|
+
'ks-row-center-around': 'flex items-center justify-around',
|
|
34
|
+
'ks-row-between': 'flex justify-between',
|
|
35
|
+
ell: 'text-ellipsis whitespace-nowrap overflow-hidden',
|
|
36
|
+
'gct-color-text-1': 'text-[#1A1D23]',
|
|
37
|
+
'gct-color-text-4': 'text-[#5A5F6B]',
|
|
38
|
+
'gct-color-text-5': 'text-[#8B8B8B]',
|
|
39
|
+
},
|
|
40
|
+
presets: [presetUno(), presetTypography(), presetWebFonts({})],
|
|
41
|
+
},
|
|
42
|
+
config,
|
|
43
|
+
),
|
|
44
|
+
);
|
|
45
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { mergeWith } from 'lodash-es';
|
|
2
|
+
|
|
3
|
+
export { isBuildPluginEnv } from './env-state/env-state';
|
|
4
|
+
export { IS_NODE_MODULE } from './reg-exp/reg-exp';
|
|
5
|
+
export { CopyWatch } from './watcher/watcher';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* win 路径 \\ 转 linux 路径 /
|
|
9
|
+
*
|
|
10
|
+
* @export
|
|
11
|
+
* @param {string} pathStr
|
|
12
|
+
* @return {*} {string}
|
|
13
|
+
*/
|
|
14
|
+
export function winToUnixPath(pathStr: string): string {
|
|
15
|
+
return pathStr.replace(/\\/g, '/');
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* linux 路径 / 转 win 路径 \\
|
|
20
|
+
*
|
|
21
|
+
* @export
|
|
22
|
+
* @param {string} pathStr
|
|
23
|
+
* @return {*} {string}
|
|
24
|
+
*/
|
|
25
|
+
export function unixToWinPath(pathStr: string): string {
|
|
26
|
+
return pathStr.replace(/\//g, '\\');
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* 自定义合并配置,数据非替换为 concat 合并
|
|
31
|
+
*
|
|
32
|
+
* @author chitanda
|
|
33
|
+
* @date 2025-08-20 20:08:45
|
|
34
|
+
* @export
|
|
35
|
+
* @template T
|
|
36
|
+
* @param {T} obj
|
|
37
|
+
* @param {U} obj2
|
|
38
|
+
* @returns {*} {T}
|
|
39
|
+
*/
|
|
40
|
+
export function mergeConfig<T extends object, U extends object>(
|
|
41
|
+
obj: T,
|
|
42
|
+
obj2: U,
|
|
43
|
+
): T & U {
|
|
44
|
+
return mergeWith(obj, obj2, (objValue, srcValue) => {
|
|
45
|
+
// 如果都是数组类型,进行合并而非替换
|
|
46
|
+
if (Array.isArray(objValue) && Array.isArray(srcValue)) {
|
|
47
|
+
return objValue.concat(srcValue);
|
|
48
|
+
}
|
|
49
|
+
// 其他类型使用默认合并策略
|
|
50
|
+
return undefined;
|
|
51
|
+
});
|
|
52
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const IS_NODE_MODULE = /node_modules\//;
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import * as chokidar from 'chokidar';
|
|
2
|
+
import fs from 'fs-extra';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
import * as rimraf from 'rimraf';
|
|
5
|
+
import { copyFileSync } from 'copy-file';
|
|
6
|
+
import log from 'consola';
|
|
7
|
+
import colors from 'picocolors';
|
|
8
|
+
import { EventName } from 'chokidar/handler';
|
|
9
|
+
import { merge } from 'lodash-es';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* 文件监控类
|
|
13
|
+
*
|
|
14
|
+
* @export
|
|
15
|
+
* @class CopyWatch
|
|
16
|
+
*/
|
|
17
|
+
export class CopyWatch {
|
|
18
|
+
protected w: chokidar.FSWatcher;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Creates an instance of CopyWatch.
|
|
22
|
+
*
|
|
23
|
+
* @param {string[]} dir 需要监控的目录
|
|
24
|
+
* @param {string} copyDir 需要拷贝到的目录
|
|
25
|
+
*/
|
|
26
|
+
constructor(
|
|
27
|
+
public dir: string,
|
|
28
|
+
public copyDir: string,
|
|
29
|
+
opts: chokidar.ChokidarOptions = {},
|
|
30
|
+
) {
|
|
31
|
+
this.w = chokidar.watch(
|
|
32
|
+
this.dir,
|
|
33
|
+
merge(
|
|
34
|
+
{
|
|
35
|
+
awaitWriteFinish: {
|
|
36
|
+
stabilityThreshold: 300, // 等待0.3秒防抖
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
opts,
|
|
40
|
+
),
|
|
41
|
+
);
|
|
42
|
+
log.debug(`拷贝监控文件夹: ${this.dir}`);
|
|
43
|
+
this.init();
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* 初始化
|
|
48
|
+
*
|
|
49
|
+
* @protected
|
|
50
|
+
*/
|
|
51
|
+
protected init(): void {
|
|
52
|
+
this.watchAll = this.watchAll.bind(this);
|
|
53
|
+
this.watchErr = this.watchErr.bind(this);
|
|
54
|
+
this.w.on('all', this.watchAll);
|
|
55
|
+
this.w.on('error', this.watchErr);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* 文件监控变更
|
|
60
|
+
*
|
|
61
|
+
* @protected
|
|
62
|
+
* @param {("add" | "addDir" | "change" | "unlink" | "unlinkDir")} eventName
|
|
63
|
+
* @param {string} pathStr
|
|
64
|
+
* @param {(fs.Stats)} [stats]
|
|
65
|
+
*/
|
|
66
|
+
protected watchAll(
|
|
67
|
+
eventName: EventName,
|
|
68
|
+
pathStr: string,
|
|
69
|
+
stats?: fs.Stats,
|
|
70
|
+
): void {
|
|
71
|
+
if (stats && stats.size <= 0) {
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
const cwd = process.cwd();
|
|
75
|
+
const source = path.resolve(cwd, pathStr);
|
|
76
|
+
const target = path.resolve(this.copyDir, path.relative(this.dir, pathStr));
|
|
77
|
+
switch (eventName) {
|
|
78
|
+
case 'add':
|
|
79
|
+
case 'change':
|
|
80
|
+
log.info(`拷贝文件: ${colors.cyan(source)} => ${colors.cyan(target)}`);
|
|
81
|
+
copyFileSync(source, target);
|
|
82
|
+
break;
|
|
83
|
+
case 'addDir':
|
|
84
|
+
break;
|
|
85
|
+
case 'unlink':
|
|
86
|
+
case 'unlinkDir':
|
|
87
|
+
log.info(`删除文件或目录: ${target}`);
|
|
88
|
+
rimraf.sync(target);
|
|
89
|
+
break;
|
|
90
|
+
default:
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* 文件监控异常
|
|
96
|
+
*
|
|
97
|
+
* @protected
|
|
98
|
+
* @param {string} path
|
|
99
|
+
* @param {(fs.Stats | undefined)} [stats]
|
|
100
|
+
*/
|
|
101
|
+
protected watchErr(err: unknown): void {
|
|
102
|
+
log.error(`监控文件发生错误: ${err}`);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* 停止监控
|
|
107
|
+
*/
|
|
108
|
+
unwatch(): void {
|
|
109
|
+
this.w.off('all', this.watchAll);
|
|
110
|
+
this.w.off('error', this.watchErr);
|
|
111
|
+
this.w.unwatch(this.dir);
|
|
112
|
+
this.w.close();
|
|
113
|
+
}
|
|
114
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export { defineViteBaseConfig } from './vite-config/vite-base-config';
|
|
2
|
+
export { defineViteConfig, defineLoaderViteConfig } from './vite-config/vite-config';
|
|
3
|
+
export { defineDevViteConfig } from './vite-config/vite-dev-config';
|
|
4
|
+
export { definePkgDevViteConfig } from './vite-config/vite-pkg-dev-config';
|
|
5
|
+
export {
|
|
6
|
+
definePluginViteConfig,
|
|
7
|
+
defineDesignPluginViteConfig,
|
|
8
|
+
defineMobilePluginViteConfig,
|
|
9
|
+
definePadPluginViteConfig,
|
|
10
|
+
defineWebPluginViteConfig,
|
|
11
|
+
} from './vite-config/vite-plugin-config';
|
|
12
|
+
export { defineProjectViteConfig } from './vite-config/vite-project-config';
|
|
13
|
+
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { defineConfig, UserConfig } from 'vite';
|
|
2
|
+
import vue from '@vitejs/plugin-vue';
|
|
3
|
+
import vueJsx from '@vitejs/plugin-vue-jsx';
|
|
4
|
+
import path from 'path';
|
|
5
|
+
import { DEFAULT_EXTERNAL } from '../../constants';
|
|
6
|
+
import { mergeConfig } from '../../util';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* 构建 vite 通用配置,基于此配置构建其他 vite 配置
|
|
10
|
+
*
|
|
11
|
+
* @export
|
|
12
|
+
* @param {UserConfig} [opts={}]
|
|
13
|
+
* @returns {*} {UserConfig}
|
|
14
|
+
*/
|
|
15
|
+
export function defineViteBaseConfig(opts: UserConfig = {}): UserConfig {
|
|
16
|
+
// 当前脚本执行的工作目录
|
|
17
|
+
const cwd = process.cwd();
|
|
18
|
+
// 编译文件输出目录
|
|
19
|
+
const outDir = path.resolve(cwd, 'dist');
|
|
20
|
+
|
|
21
|
+
return mergeConfig<UserConfig, UserConfig>(
|
|
22
|
+
defineConfig({
|
|
23
|
+
resolve: {
|
|
24
|
+
alias: {
|
|
25
|
+
'@': path.resolve(cwd, './src'),
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
css: {
|
|
29
|
+
preprocessorOptions: {
|
|
30
|
+
scss: {
|
|
31
|
+
additionalData: `@use "@gct-paas/scss/style/global.scss" as *;`,
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
build: {
|
|
36
|
+
outDir,
|
|
37
|
+
target: 'chrome89',
|
|
38
|
+
rolldownOptions: {
|
|
39
|
+
external: DEFAULT_EXTERNAL,
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
plugins: [
|
|
43
|
+
vue(),
|
|
44
|
+
vueJsx(),
|
|
45
|
+
],
|
|
46
|
+
}),
|
|
47
|
+
opts,
|
|
48
|
+
);
|
|
49
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { defineConfig, mergeConfig, PluginOption, UserConfig } from 'vite';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import UnoCSS from 'unocss/vite';
|
|
4
|
+
import { defineViteBaseConfig } from './vite-base-config';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* 构建 vite 通用配置,基于此配置构建其他 vite 配置
|
|
8
|
+
*
|
|
9
|
+
* @export
|
|
10
|
+
* @param {UserConfig} [opts={}]
|
|
11
|
+
* @returns {*} {UserConfig}
|
|
12
|
+
*/
|
|
13
|
+
export function defineViteConfig(opts: UserConfig = {}): UserConfig {
|
|
14
|
+
// 当前脚本执行的工作目录
|
|
15
|
+
const cwd = process.cwd();
|
|
16
|
+
|
|
17
|
+
return mergeConfig<UserConfig, UserConfig>(
|
|
18
|
+
defineViteBaseConfig(
|
|
19
|
+
defineConfig({
|
|
20
|
+
build: {
|
|
21
|
+
minify: 'terser',
|
|
22
|
+
terserOptions: {
|
|
23
|
+
// 压缩选项,控制代码压缩行为
|
|
24
|
+
compress: {
|
|
25
|
+
// 是否移除 console.* 调用;false 表示保留,避免生产环境丢失重要日志
|
|
26
|
+
drop_console: false,
|
|
27
|
+
// 是否移除永远不会执行的死代码(如 if(false){...})
|
|
28
|
+
dead_code: true,
|
|
29
|
+
// 是否移除未被引用的变量和函数,减小产物体积
|
|
30
|
+
unused: true,
|
|
31
|
+
// 压缩算法的执行轮数;多轮压缩可以发现单轮无法消除的冗余代码,但会增加构建耗时
|
|
32
|
+
passes: 2,
|
|
33
|
+
},
|
|
34
|
+
// 是否混淆变量名、函数名等标识符,使产物更难以阅读反编译,同时进一步缩小体积
|
|
35
|
+
mangle: true,
|
|
36
|
+
},
|
|
37
|
+
lib: {
|
|
38
|
+
entry: path.resolve(cwd, 'src/index.ts'),
|
|
39
|
+
formats: ['es'],
|
|
40
|
+
cssFileName: 'index.min',
|
|
41
|
+
fileName: '[name].[format].min',
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
plugins: [
|
|
45
|
+
UnoCSS({ hmrTopLevelAwait: false }) as PluginOption,
|
|
46
|
+
]
|
|
47
|
+
}),
|
|
48
|
+
),
|
|
49
|
+
opts,
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* 构建 loader 模块的 vite 配置,基于此配置构建基于 index 模式下的上层样式加载封装
|
|
55
|
+
*
|
|
56
|
+
* @export
|
|
57
|
+
* @param {UserConfig} [opts={}]
|
|
58
|
+
* @return {*} {UserConfig}
|
|
59
|
+
*/
|
|
60
|
+
export function defineLoaderViteConfig(opts: UserConfig = {}): UserConfig {
|
|
61
|
+
// 当前脚本执行的工作目录
|
|
62
|
+
const cwd = process.cwd();
|
|
63
|
+
|
|
64
|
+
return mergeConfig<UserConfig, UserConfig>(
|
|
65
|
+
defineViteConfig({
|
|
66
|
+
build: {
|
|
67
|
+
lib: {
|
|
68
|
+
entry: path.resolve(cwd, 'src/loader.ts'),
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
}),
|
|
72
|
+
opts,
|
|
73
|
+
);
|
|
74
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { defineConfig, mergeConfig, PluginOption, UserConfig } from 'vite';
|
|
2
|
+
import vue from '@vitejs/plugin-vue';
|
|
3
|
+
import vueJsx from '@vitejs/plugin-vue-jsx';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* 构建本地开发 vite 通用配置,基于此配置构建其他 vite 配置
|
|
7
|
+
*
|
|
8
|
+
* @export
|
|
9
|
+
* @param {UserConfig} [opts={}]
|
|
10
|
+
* @returns {*} {UserConfig}
|
|
11
|
+
*/
|
|
12
|
+
export function defineDevViteConfig(opts: UserConfig = {}): UserConfig {
|
|
13
|
+
return mergeConfig<UserConfig, UserConfig>(
|
|
14
|
+
defineConfig({
|
|
15
|
+
css: {
|
|
16
|
+
preprocessorOptions: {
|
|
17
|
+
scss: {
|
|
18
|
+
additionalData: `@use "@gct-paas/scss/style/global.scss" as *;`,
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
plugins: [vue() as PluginOption, vueJsx() as PluginOption],
|
|
23
|
+
}),
|
|
24
|
+
opts,
|
|
25
|
+
);
|
|
26
|
+
}
|