@gct-paas/cli 0.0.1-dev.0 → 0.0.1-dev.2
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/dist/bin.d.ts +2 -0
- package/dist/commands/index.d.ts +5 -0
- package/dist/commands/index.mjs +14 -0
- package/dist/core/commitlint/commitlint-config/commitlint-config.d.ts +9 -0
- package/dist/core/commitlint/commitlint-config/commitlint-config.mjs +28 -0
- package/dist/core/commitlint/index.d.ts +1 -0
- package/dist/core/commitlint/index.mjs +1 -0
- package/{src/core/constants/index.ts → dist/core/constants/index.d.ts} +2 -2
- package/dist/core/constants/index.mjs +2 -0
- package/dist/core/eslint/eslint-config/eslint-config.d.ts +9 -0
- package/dist/core/eslint/eslint-config/eslint-config.mjs +109 -0
- package/dist/core/eslint/index.d.ts +1 -0
- package/dist/core/eslint/index.mjs +1 -0
- package/dist/core/index.d.ts +7 -0
- package/dist/core/index.mjs +7 -0
- package/dist/core/prettier/index.d.ts +1 -0
- package/dist/core/prettier/index.mjs +1 -0
- package/dist/core/prettier/prettier-config/prettier-config.d.ts +22 -0
- package/dist/core/prettier/prettier-config/prettier-config.mjs +26 -0
- package/dist/core/rollup/index.d.ts +2 -0
- package/dist/core/rollup/index.mjs +2 -0
- package/dist/core/rollup/rollup-config/dev-config.d.ts +9 -0
- package/dist/core/rollup/rollup-config/dev-config.mjs +98 -0
- package/dist/core/rollup/rollup-plugins/copy-file.d.ts +37 -0
- package/dist/core/rollup/rollup-plugins/copy-file.mjs +18 -0
- package/dist/core/rollup/rollup-plugins/ignore-compiler-file.d.ts +8 -0
- package/dist/core/rollup/rollup-plugins/ignore-compiler-file.mjs +17 -0
- package/dist/core/rollup/rollup-plugins/index.mjs +2 -0
- package/dist/core/stylelint/index.d.ts +1 -0
- package/dist/core/stylelint/index.mjs +1 -0
- package/dist/core/stylelint/stylelint-config/stylelint-config.d.ts +9 -0
- package/dist/core/stylelint/stylelint-config/stylelint-config.mjs +21 -0
- package/{src/core/util/index.ts → dist/core/util/index.d.ts} +2 -8
- package/dist/core/util/index.mjs +7 -0
- package/dist/core/util/watcher/watcher.d.ts +61 -0
- package/{src/core/util/watcher/watcher.ts → dist/core/util/watcher/watcher.mjs} +33 -54
- package/dist/core/vite/index.d.ts +1 -0
- package/dist/core/vite/index.mjs +1 -0
- package/dist/core/vite/vite-config/vite-config.d.ts +9 -0
- package/dist/core/vite/vite-config/vite-config.mjs +47 -0
- package/dist/index.d.ts +2 -0
- package/dist/interface/i-command/i-command.d.ts +28 -0
- package/dist/interface/i-command/i-command.mjs +0 -0
- package/dist/interface/index.mjs +1 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.mjs +4 -0
- package/dist/utils/local-binaries/local-binaries.d.ts +3 -0
- package/dist/utils/local-binaries/local-binaries.mjs +11 -0
- package/package.json +31 -3
- package/src/bin.ts +0 -5
- package/src/commands/index.ts +0 -16
- package/src/core/index.ts +0 -3
- package/src/core/rollup/index.ts +0 -2
- package/src/core/rollup/rollup-config/dev-config.ts +0 -135
- package/src/core/rollup/rollup-plugins/copy-file.ts +0 -57
- package/src/core/rollup/rollup-plugins/ignore-compiler-file.ts +0 -25
- package/src/core/vite/index.ts +0 -1
- package/src/core/vite/vite-config/vite-config.ts +0 -59
- package/src/index.ts +0 -36
- package/src/interface/i-command/i-command.ts +0 -29
- package/src/utils/index.ts +0 -4
- package/src/utils/local-binaries/local-binaries.ts +0 -16
- /package/{src/core/rollup/rollup-plugins/index.ts → dist/core/rollup/rollup-plugins/index.d.ts} +0 -0
- /package/{src/interface/index.ts → dist/interface/index.d.ts} +0 -0
|
@@ -1,24 +1,11 @@
|
|
|
1
|
-
import * as chokidar from
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import { EventName } from 'chokidar/handler';
|
|
9
|
-
import { merge } from 'lodash-es';
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* 文件监控类
|
|
13
|
-
*
|
|
14
|
-
* @author chitanda
|
|
15
|
-
* @date 2022-05-24 14:05:22
|
|
16
|
-
* @export
|
|
17
|
-
* @class CopyWatch
|
|
18
|
-
*/
|
|
1
|
+
import * as chokidar from "chokidar";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import * as rimraf from "rimraf";
|
|
4
|
+
import { copyFileSync } from "copy-file";
|
|
5
|
+
import consola from "consola";
|
|
6
|
+
import colors from "picocolors";
|
|
7
|
+
import { merge } from "lodash-es";
|
|
19
8
|
export class CopyWatch {
|
|
20
|
-
protected w: chokidar.FSWatcher;
|
|
21
|
-
|
|
22
9
|
/**
|
|
23
10
|
* Creates an instance of CopyWatch.
|
|
24
11
|
*
|
|
@@ -27,26 +14,25 @@ export class CopyWatch {
|
|
|
27
14
|
* @param {string[]} dir 需要监控的目录
|
|
28
15
|
* @param {string} copyDir 需要拷贝到的目录
|
|
29
16
|
*/
|
|
30
|
-
constructor(
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
opts: chokidar.ChokidarOptions = {},
|
|
34
|
-
) {
|
|
17
|
+
constructor(dir, copyDir, opts = {}) {
|
|
18
|
+
this.dir = dir;
|
|
19
|
+
this.copyDir = copyDir;
|
|
35
20
|
this.w = chokidar.watch(
|
|
36
21
|
this.dir,
|
|
37
22
|
merge(
|
|
38
23
|
{
|
|
39
24
|
awaitWriteFinish: {
|
|
40
|
-
stabilityThreshold: 300
|
|
41
|
-
|
|
25
|
+
stabilityThreshold: 300
|
|
26
|
+
// 等待0.3秒防抖
|
|
27
|
+
}
|
|
42
28
|
},
|
|
43
|
-
opts
|
|
44
|
-
)
|
|
29
|
+
opts
|
|
30
|
+
)
|
|
45
31
|
);
|
|
46
|
-
consola.debug(
|
|
32
|
+
consola.debug(`\u62F7\u8D1D\u76D1\u63A7\u6587\u4EF6\u5939: ${this.dir}`);
|
|
47
33
|
this.init();
|
|
48
34
|
}
|
|
49
|
-
|
|
35
|
+
w;
|
|
50
36
|
/**
|
|
51
37
|
* 初始化
|
|
52
38
|
*
|
|
@@ -54,13 +40,12 @@ export class CopyWatch {
|
|
|
54
40
|
* @date 2022-05-24 14:05:34
|
|
55
41
|
* @protected
|
|
56
42
|
*/
|
|
57
|
-
|
|
43
|
+
init() {
|
|
58
44
|
this.watchAll = this.watchAll.bind(this);
|
|
59
45
|
this.watchErr = this.watchErr.bind(this);
|
|
60
|
-
this.w.on(
|
|
61
|
-
this.w.on(
|
|
46
|
+
this.w.on("all", this.watchAll);
|
|
47
|
+
this.w.on("error", this.watchErr);
|
|
62
48
|
}
|
|
63
|
-
|
|
64
49
|
/**
|
|
65
50
|
* 文件监控变更
|
|
66
51
|
*
|
|
@@ -71,11 +56,7 @@ export class CopyWatch {
|
|
|
71
56
|
* @param {string} pathStr
|
|
72
57
|
* @param {(fs.Stats)} [stats]
|
|
73
58
|
*/
|
|
74
|
-
|
|
75
|
-
eventName: EventName,
|
|
76
|
-
pathStr: string,
|
|
77
|
-
stats?: fs.Stats,
|
|
78
|
-
): void {
|
|
59
|
+
watchAll(eventName, pathStr, stats) {
|
|
79
60
|
if (stats && stats.size <= 0) {
|
|
80
61
|
return;
|
|
81
62
|
}
|
|
@@ -83,24 +64,23 @@ export class CopyWatch {
|
|
|
83
64
|
const source = path.resolve(cwd, pathStr);
|
|
84
65
|
const target = path.resolve(this.copyDir, path.relative(this.dir, pathStr));
|
|
85
66
|
switch (eventName) {
|
|
86
|
-
case
|
|
87
|
-
case
|
|
67
|
+
case "add":
|
|
68
|
+
case "change":
|
|
88
69
|
consola.info(
|
|
89
|
-
|
|
70
|
+
`\u62F7\u8D1D\u6587\u4EF6: ${colors.cyan(source)} => ${colors.cyan(target)}`
|
|
90
71
|
);
|
|
91
72
|
copyFileSync(source, target);
|
|
92
73
|
break;
|
|
93
|
-
case
|
|
74
|
+
case "addDir":
|
|
94
75
|
break;
|
|
95
|
-
case
|
|
96
|
-
case
|
|
97
|
-
consola.info(
|
|
76
|
+
case "unlink":
|
|
77
|
+
case "unlinkDir":
|
|
78
|
+
consola.info(`\u5220\u9664\u6587\u4EF6\u6216\u76EE\u5F55: ${target}`);
|
|
98
79
|
rimraf.sync(target);
|
|
99
80
|
break;
|
|
100
81
|
default:
|
|
101
82
|
}
|
|
102
83
|
}
|
|
103
|
-
|
|
104
84
|
/**
|
|
105
85
|
* 文件监控异常
|
|
106
86
|
*
|
|
@@ -110,19 +90,18 @@ export class CopyWatch {
|
|
|
110
90
|
* @param {string} path
|
|
111
91
|
* @param {(fs.Stats | undefined)} [stats]
|
|
112
92
|
*/
|
|
113
|
-
|
|
114
|
-
consola.error(
|
|
93
|
+
watchErr(err) {
|
|
94
|
+
consola.error(`\u76D1\u63A7\u6587\u4EF6\u53D1\u751F\u9519\u8BEF: ${err}`);
|
|
115
95
|
}
|
|
116
|
-
|
|
117
96
|
/**
|
|
118
97
|
* 停止监控
|
|
119
98
|
*
|
|
120
99
|
* @author chitanda
|
|
121
100
|
* @date 2022-05-24 14:05:06
|
|
122
101
|
*/
|
|
123
|
-
unwatch()
|
|
124
|
-
this.w.off(
|
|
125
|
-
this.w.off(
|
|
102
|
+
unwatch() {
|
|
103
|
+
this.w.off("all", this.watchAll);
|
|
104
|
+
this.w.off("error", this.watchErr);
|
|
126
105
|
this.w.unwatch(this.dir);
|
|
127
106
|
this.w.close();
|
|
128
107
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { defineViteConfig } from './vite-config/vite-config';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { defineViteConfig } from "./vite-config/vite-config.mjs";
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { defineConfig, mergeConfig } from "vite";
|
|
2
|
+
import vue from "@vitejs/plugin-vue";
|
|
3
|
+
import vueJsx from "@vitejs/plugin-vue-jsx";
|
|
4
|
+
import { babel } from "@rollup/plugin-babel";
|
|
5
|
+
import path from "path";
|
|
6
|
+
import * as rf from "rimraf";
|
|
7
|
+
export function defineViteConfig(opts = {}) {
|
|
8
|
+
const cwd = process.cwd();
|
|
9
|
+
const outDir = path.resolve(cwd, "dist");
|
|
10
|
+
rf.sync(outDir);
|
|
11
|
+
return mergeConfig(
|
|
12
|
+
defineConfig({
|
|
13
|
+
build: {
|
|
14
|
+
outDir,
|
|
15
|
+
lib: {
|
|
16
|
+
entry: path.resolve(cwd, "src/index.ts"),
|
|
17
|
+
formats: ["system", "cjs"]
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
plugins: [
|
|
21
|
+
vue(),
|
|
22
|
+
vueJsx(),
|
|
23
|
+
babel({
|
|
24
|
+
babelHelpers: "bundled",
|
|
25
|
+
presets: [
|
|
26
|
+
[
|
|
27
|
+
"@babel/preset-env",
|
|
28
|
+
{
|
|
29
|
+
useBuiltIns: "usage",
|
|
30
|
+
corejs: 3,
|
|
31
|
+
bugfixes: true,
|
|
32
|
+
babelHelpers: "bundled",
|
|
33
|
+
targets: {
|
|
34
|
+
chrome: ">=85",
|
|
35
|
+
edge: ">=85",
|
|
36
|
+
firefox: ">=79",
|
|
37
|
+
safari: ">=14.1"
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
]
|
|
41
|
+
]
|
|
42
|
+
})
|
|
43
|
+
]
|
|
44
|
+
}),
|
|
45
|
+
opts
|
|
46
|
+
);
|
|
47
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
/**
|
|
3
|
+
* 命令项
|
|
4
|
+
*
|
|
5
|
+
* @author chitanda
|
|
6
|
+
* @date 2021-12-18 15:12:13
|
|
7
|
+
* @export
|
|
8
|
+
* @interface ICommand
|
|
9
|
+
*/
|
|
10
|
+
export interface ICommand {
|
|
11
|
+
/**
|
|
12
|
+
* 加载命令
|
|
13
|
+
*
|
|
14
|
+
* @author chitanda
|
|
15
|
+
* @date 2021-12-18 15:12:22
|
|
16
|
+
* @param {Command} program
|
|
17
|
+
*/
|
|
18
|
+
load(program: Command): void;
|
|
19
|
+
/**
|
|
20
|
+
* 执行行为
|
|
21
|
+
*
|
|
22
|
+
* @author chitanda
|
|
23
|
+
* @date 2021-12-21 16:12:22
|
|
24
|
+
* @param {...unknown[]} args
|
|
25
|
+
* @return {*} {(void | Promise<void>)}
|
|
26
|
+
*/
|
|
27
|
+
action(...args: unknown[]): void | Promise<void>;
|
|
28
|
+
}
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./i-command/i-command.mjs";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
declare module 'eslint-plugin-import';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { localBinExists, loadLocalBinCommandLoader, } from './local-binaries/local-binaries';
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { join, posix } from "path";
|
|
2
|
+
import fs from "fs-extra";
|
|
3
|
+
const localBinPathSegments = [process.cwd(), "node_modules", "@nestjs", "cli"];
|
|
4
|
+
export function localBinExists() {
|
|
5
|
+
return fs.existsSync(join(...localBinPathSegments));
|
|
6
|
+
}
|
|
7
|
+
export function loadLocalBinCommandLoader() {
|
|
8
|
+
const path = posix.join(...localBinPathSegments, "commands");
|
|
9
|
+
const commandsFile = require(path);
|
|
10
|
+
return commandsFile.CommandLoader;
|
|
11
|
+
}
|
package/package.json
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gct-paas/cli",
|
|
3
|
-
"version": "0.0.1-dev.
|
|
3
|
+
"version": "0.0.1-dev.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "paas 平台核心包",
|
|
6
6
|
"bin": {
|
|
7
7
|
"gct-build": "dist/bin.mjs"
|
|
8
8
|
},
|
|
9
9
|
"main": "dist/index.mjs",
|
|
10
|
+
"types": "dist/index.d.ts",
|
|
10
11
|
"files": [
|
|
11
|
-
"
|
|
12
|
+
"dist",
|
|
12
13
|
"CHANGELOG.md",
|
|
13
14
|
"README.md"
|
|
14
15
|
],
|
|
@@ -32,25 +33,52 @@
|
|
|
32
33
|
"publish:npm": "npm run build && npm publish --access public --registry=https://registry.npmjs.org/"
|
|
33
34
|
},
|
|
34
35
|
"dependencies": {
|
|
36
|
+
"@babel/core": "^7.26.0",
|
|
37
|
+
"@babel/preset-env": "^7.26.0",
|
|
38
|
+
"@commitlint/cli": "^19.6.1",
|
|
39
|
+
"@commitlint/config-conventional": "^19.6.0",
|
|
40
|
+
"@eslint/js": "^9.17.0",
|
|
41
|
+
"@rollup/plugin-babel": "^6.0.4",
|
|
35
42
|
"@rollup/plugin-commonjs": "^28.0.2",
|
|
43
|
+
"@rollup/plugin-eslint": "^9.0.5",
|
|
36
44
|
"@rollup/plugin-json": "^6.1.0",
|
|
37
45
|
"@rollup/plugin-node-resolve": "^16.0.0",
|
|
38
46
|
"@vitejs/plugin-vue": "^5.2.1",
|
|
39
47
|
"@vitejs/plugin-vue-jsx": "^4.1.1",
|
|
48
|
+
"@vue/compiler-sfc": "^3.5.13",
|
|
40
49
|
"chokidar": "^4.0.3",
|
|
41
50
|
"commander": "^13.0.0",
|
|
51
|
+
"consola": "^3.3.3",
|
|
42
52
|
"copy-file": "^11.0.0",
|
|
43
53
|
"cpy": "^11.1.0",
|
|
54
|
+
"eslint": "^9.17.0",
|
|
55
|
+
"eslint-plugin-import": "^2.31.0",
|
|
56
|
+
"eslint-plugin-prettier": "^5.2.1",
|
|
57
|
+
"eslint-plugin-unused-imports": "^4.1.4",
|
|
58
|
+
"eslint-plugin-vue": "^9.32.0",
|
|
44
59
|
"fast-glob": "^3.3.3",
|
|
45
60
|
"fs-extra": "^11.2.0",
|
|
61
|
+
"globals": "^15.14.0",
|
|
46
62
|
"lodash-es": "^4.17.21",
|
|
47
63
|
"picocolors": "^1.1.1",
|
|
64
|
+
"prettier": "^3.4.2",
|
|
48
65
|
"rimraf": "^6.0.1",
|
|
49
66
|
"rollup": "^4.30.0",
|
|
50
67
|
"rollup-plugin-esbuild": "^6.1.1",
|
|
51
|
-
"
|
|
68
|
+
"stylelint": "^16.12.0",
|
|
69
|
+
"stylelint-config-standard": "^36.0.1",
|
|
70
|
+
"stylelint-config-standard-scss": "^14.0.0",
|
|
71
|
+
"typescript-eslint": "^8.19.0",
|
|
72
|
+
"vite-plugin-dts": "^4.4.0",
|
|
73
|
+
"vue-tsc": "^2.2.0"
|
|
52
74
|
},
|
|
53
75
|
"devDependencies": {
|
|
76
|
+
"@commitlint/types": "^19.5.0",
|
|
77
|
+
"@types/babel__core": "^7.20.5",
|
|
78
|
+
"@types/babel__preset-env": "^7.9.7",
|
|
79
|
+
"@types/fs-extra": "^11.0.4",
|
|
80
|
+
"@types/lodash-es": "^4.17.12",
|
|
81
|
+
"@types/node": "^22.10.5",
|
|
54
82
|
"typescript": "^5.7.2",
|
|
55
83
|
"unbuild": "^3.2.0"
|
|
56
84
|
}
|
package/src/bin.ts
DELETED
package/src/commands/index.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { consola } from 'consola';
|
|
2
|
-
import { Command } from 'commander';
|
|
3
|
-
|
|
4
|
-
export class CommandLoader {
|
|
5
|
-
public static load(program: Command): void {
|
|
6
|
-
this.handleInvalidCommand(program);
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
private static handleInvalidCommand(program: Command) {
|
|
10
|
-
program.on('command:*', () => {
|
|
11
|
-
consola.error(`未支持的命令: `, program.args.join(' '));
|
|
12
|
-
consola.log(`请使用 --help 查看已支持的命令.\n`);
|
|
13
|
-
process.exit(1);
|
|
14
|
-
});
|
|
15
|
-
}
|
|
16
|
-
}
|
package/src/core/index.ts
DELETED
package/src/core/rollup/index.ts
DELETED
|
@@ -1,135 +0,0 @@
|
|
|
1
|
-
import { defineConfig, OutputOptions, RollupOptions } from 'rollup';
|
|
2
|
-
import { merge } from 'lodash-es';
|
|
3
|
-
import path from 'path';
|
|
4
|
-
import glob from 'fast-glob';
|
|
5
|
-
import { nodeResolve } from '@rollup/plugin-node-resolve';
|
|
6
|
-
import commonjs from '@rollup/plugin-commonjs';
|
|
7
|
-
import json from '@rollup/plugin-json';
|
|
8
|
-
import esbuild from 'rollup-plugin-esbuild';
|
|
9
|
-
import dts from 'vite-plugin-dts';
|
|
10
|
-
import vue from '@vitejs/plugin-vue';
|
|
11
|
-
import vueJsx from '@vitejs/plugin-vue-jsx';
|
|
12
|
-
import * as rf from 'rimraf';
|
|
13
|
-
import cpy from 'cpy';
|
|
14
|
-
import fs from 'fs-extra';
|
|
15
|
-
import { copyFile, ignoreCompilerFile } from '../rollup-plugins';
|
|
16
|
-
import { PROD_MODE } from '../../constants';
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* 开发包基础编译配置
|
|
20
|
-
*
|
|
21
|
-
* @export
|
|
22
|
-
* @param {RollupOptions} [opts={}]
|
|
23
|
-
* @returns {*} {RollupOptions}
|
|
24
|
-
*/
|
|
25
|
-
export function devRollupConfig(opts: RollupOptions = {}): RollupOptions {
|
|
26
|
-
// 监控 ctrl + c 停止进程,触发 exit 事件
|
|
27
|
-
process.on('SIGINT', () => {
|
|
28
|
-
process.exit();
|
|
29
|
-
});
|
|
30
|
-
// 当前脚本执行的工作目录
|
|
31
|
-
const cwd = process.cwd();
|
|
32
|
-
// 是否为生产编译模式
|
|
33
|
-
const isProd = process.env.NODE_ENV === PROD_MODE;
|
|
34
|
-
// 项目脚本目录
|
|
35
|
-
const rootDir = path.resolve(cwd, 'src');
|
|
36
|
-
// es模块输出目录
|
|
37
|
-
const outDir = path.resolve(cwd, 'es');
|
|
38
|
-
// commonjs 模块输出目录
|
|
39
|
-
// const libOutDir = path.resolve(cwd, 'lib');
|
|
40
|
-
// 静态资源目录
|
|
41
|
-
const assetsDir = path.resolve(cwd, 'public');
|
|
42
|
-
|
|
43
|
-
// 需要忽略编译,以及直接拷贝的文件
|
|
44
|
-
const externalCompileFileReg = /\.(vue|scss|css|less)+$/;
|
|
45
|
-
|
|
46
|
-
// 删除之前编译的文件
|
|
47
|
-
rf.sync(outDir);
|
|
48
|
-
|
|
49
|
-
const input = glob.sync('src/**/*.{ts,tsx}', {
|
|
50
|
-
cwd,
|
|
51
|
-
absolute: true,
|
|
52
|
-
onlyFiles: true,
|
|
53
|
-
ignore: ['**/*.test.ts', '**/*.test.tsx', '**/*.d.ts'],
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
if (isProd) {
|
|
57
|
-
if (fs.pathExistsSync(assetsDir)) {
|
|
58
|
-
cpy(assetsDir, outDir);
|
|
59
|
-
}
|
|
60
|
-
cpy(path.resolve(cwd, 'src/**/*.{vue,scss,css,less}'), outDir);
|
|
61
|
-
} else {
|
|
62
|
-
// 拷贝静态资源目录,和排除编译的文件
|
|
63
|
-
copyFile([
|
|
64
|
-
{
|
|
65
|
-
from: assetsDir,
|
|
66
|
-
to: outDir,
|
|
67
|
-
},
|
|
68
|
-
{
|
|
69
|
-
from: rootDir,
|
|
70
|
-
to: outDir,
|
|
71
|
-
opts: {
|
|
72
|
-
ignored: (file, stats) => {
|
|
73
|
-
if (stats && stats.isFile()) {
|
|
74
|
-
return !externalCompileFileReg.test(file);
|
|
75
|
-
}
|
|
76
|
-
return false;
|
|
77
|
-
},
|
|
78
|
-
},
|
|
79
|
-
},
|
|
80
|
-
]);
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
const output: OutputOptions[] = [
|
|
84
|
-
{
|
|
85
|
-
dir: outDir,
|
|
86
|
-
format: 'es',
|
|
87
|
-
sourcemap: false,
|
|
88
|
-
preserveModules: true,
|
|
89
|
-
preserveModulesRoot: rootDir,
|
|
90
|
-
entryFileNames: '[name].mjs',
|
|
91
|
-
},
|
|
92
|
-
];
|
|
93
|
-
|
|
94
|
-
// if (isProd) {
|
|
95
|
-
// output.push({
|
|
96
|
-
// dir: libOutDir,
|
|
97
|
-
// format: 'cjs',
|
|
98
|
-
// sourcemap: false,
|
|
99
|
-
// exports: 'named',
|
|
100
|
-
// preserveModules: true,
|
|
101
|
-
// preserveModulesRoot: rootDir,
|
|
102
|
-
// entryFileNames: '[name].cjs',
|
|
103
|
-
// });
|
|
104
|
-
// }
|
|
105
|
-
|
|
106
|
-
return merge(
|
|
107
|
-
defineConfig({
|
|
108
|
-
input,
|
|
109
|
-
treeshake: false,
|
|
110
|
-
external: ['vue'],
|
|
111
|
-
output,
|
|
112
|
-
plugins: [
|
|
113
|
-
ignoreCompilerFile(externalCompileFileReg),
|
|
114
|
-
json(),
|
|
115
|
-
nodeResolve({
|
|
116
|
-
extensions: ['.cjs', '.mjs', '.js', '.ts'],
|
|
117
|
-
}),
|
|
118
|
-
commonjs(),
|
|
119
|
-
esbuild({
|
|
120
|
-
logLevel: 'verbose',
|
|
121
|
-
sourceMap: false,
|
|
122
|
-
target: ['esnext'],
|
|
123
|
-
}),
|
|
124
|
-
vue({
|
|
125
|
-
isProduction: false,
|
|
126
|
-
}),
|
|
127
|
-
vueJsx({}),
|
|
128
|
-
dts({
|
|
129
|
-
outDir: [outDir],
|
|
130
|
-
}),
|
|
131
|
-
],
|
|
132
|
-
}),
|
|
133
|
-
opts,
|
|
134
|
-
);
|
|
135
|
-
}
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import * as chokidar from 'chokidar';
|
|
2
|
-
import { CopyWatch } from '../../util';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* 文件拷贝插件配置参数
|
|
6
|
-
*
|
|
7
|
-
* @export
|
|
8
|
-
* @interface CopyFilePluginOptions
|
|
9
|
-
*/
|
|
10
|
-
export interface CopyFilePluginOptions {
|
|
11
|
-
/**
|
|
12
|
-
* 源文件
|
|
13
|
-
*
|
|
14
|
-
* @type {string}
|
|
15
|
-
* @memberof CopyFilePluginOptions
|
|
16
|
-
*/
|
|
17
|
-
from: string;
|
|
18
|
-
/**
|
|
19
|
-
* 目标文件
|
|
20
|
-
*
|
|
21
|
-
* @type {string}
|
|
22
|
-
* @memberof CopyFilePluginOptions
|
|
23
|
-
*/
|
|
24
|
-
to: string;
|
|
25
|
-
/**
|
|
26
|
-
* chokidar watch 配置
|
|
27
|
-
*
|
|
28
|
-
* @type {chokidar.ChokidarOptions}
|
|
29
|
-
*/
|
|
30
|
-
opts?: chokidar.ChokidarOptions;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* 文件拷贝插件,在开发模式下会监控文件变更,并自动拷贝文件
|
|
35
|
-
*
|
|
36
|
-
* @export
|
|
37
|
-
* @param {CopyFilePluginOptions[]} opts
|
|
38
|
-
* @return {*} {Plugin}
|
|
39
|
-
*/
|
|
40
|
-
export function copyFile(opts: CopyFilePluginOptions[]): void {
|
|
41
|
-
if (opts.length === 0) {
|
|
42
|
-
return;
|
|
43
|
-
}
|
|
44
|
-
const arr: CopyWatch[] = [];
|
|
45
|
-
opts.forEach(opt => {
|
|
46
|
-
arr.push(new CopyWatch(opt.from, opt.to, opt.opts));
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
process.on('exit', () => {
|
|
50
|
-
if (!opts.length) {
|
|
51
|
-
return;
|
|
52
|
-
}
|
|
53
|
-
arr.forEach(item => {
|
|
54
|
-
item.unwatch();
|
|
55
|
-
});
|
|
56
|
-
});
|
|
57
|
-
}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { Plugin } from 'rollup';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* 忽略编译的文件类型
|
|
5
|
-
*
|
|
6
|
-
* @export
|
|
7
|
-
* @returns {*} {Plugin}
|
|
8
|
-
*/
|
|
9
|
-
export function ignoreCompilerFile(extReg: RegExp): Plugin {
|
|
10
|
-
return {
|
|
11
|
-
name: 'gct:ignore-compiler-file',
|
|
12
|
-
resolveId(source) {
|
|
13
|
-
if (extReg.test(source)) {
|
|
14
|
-
return {
|
|
15
|
-
id: source,
|
|
16
|
-
external: true,
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
return null;
|
|
20
|
-
},
|
|
21
|
-
load() {
|
|
22
|
-
return null;
|
|
23
|
-
},
|
|
24
|
-
};
|
|
25
|
-
}
|
package/src/core/vite/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { buildViteConfig } from './vite-config/vite-config';
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import { defineConfig, mergeConfig, UserConfig } from 'vite';
|
|
2
|
-
import vue from '@vitejs/plugin-vue';
|
|
3
|
-
import vueJsx from '@vitejs/plugin-vue-jsx';
|
|
4
|
-
import { babel } from '@rollup/plugin-babel';
|
|
5
|
-
import path from 'path';
|
|
6
|
-
import * as rf from 'rimraf';
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* 构建 vite 通用配置,基于此配置构建其他 vite 配置
|
|
10
|
-
*
|
|
11
|
-
* @export
|
|
12
|
-
* @param {UserConfig} [opts={}]
|
|
13
|
-
* @returns {*} {UserConfig}
|
|
14
|
-
*/
|
|
15
|
-
export function buildViteConfig(opts: UserConfig = {}): UserConfig {
|
|
16
|
-
// 当前脚本执行的工作目录
|
|
17
|
-
const cwd = process.cwd();
|
|
18
|
-
// 编译文件输出目录
|
|
19
|
-
const outDir = path.resolve(cwd, 'dist');
|
|
20
|
-
// 删除历史编译文件
|
|
21
|
-
rf.sync(outDir);
|
|
22
|
-
|
|
23
|
-
return mergeConfig(
|
|
24
|
-
defineConfig({
|
|
25
|
-
build: {
|
|
26
|
-
outDir,
|
|
27
|
-
lib: {
|
|
28
|
-
entry: path.resolve(cwd, 'src/index.ts'),
|
|
29
|
-
formats: ['system', 'cjs'],
|
|
30
|
-
},
|
|
31
|
-
},
|
|
32
|
-
plugins: [
|
|
33
|
-
vue(),
|
|
34
|
-
vueJsx(),
|
|
35
|
-
babel({
|
|
36
|
-
babelHelpers: 'bundled',
|
|
37
|
-
presets: [
|
|
38
|
-
[
|
|
39
|
-
'@babel/preset-env',
|
|
40
|
-
{
|
|
41
|
-
useBuiltIns: 'usage',
|
|
42
|
-
corejs: 3,
|
|
43
|
-
bugfixes: true,
|
|
44
|
-
babelHelpers: 'bundled',
|
|
45
|
-
targets: {
|
|
46
|
-
chrome: '>=85',
|
|
47
|
-
edge: '>=85',
|
|
48
|
-
firefox: '>=79',
|
|
49
|
-
safari: '>=14.1',
|
|
50
|
-
},
|
|
51
|
-
},
|
|
52
|
-
],
|
|
53
|
-
],
|
|
54
|
-
}),
|
|
55
|
-
],
|
|
56
|
-
}),
|
|
57
|
-
opts,
|
|
58
|
-
);
|
|
59
|
-
}
|