fep-migrator 1.0.3 → 1.0.5
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/README.md +8 -4
- package/dist/index.mjs +51 -4
- package/package.json +4 -2
package/README.md
CHANGED
|
@@ -8,24 +8,28 @@
|
|
|
8
8
|
npx fep-migrator <...dir>
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
-
`dir` 为需要迁移的 fep
|
|
11
|
+
`dir` 为需要迁移的 fep 项目目录
|
|
12
|
+
|
|
13
|
+
支持多个目录同时迁移,例如:
|
|
12
14
|
|
|
13
15
|
```shell
|
|
14
|
-
fep-migrator
|
|
16
|
+
fep-migrator web mobile
|
|
15
17
|
```
|
|
16
18
|
|
|
17
19
|
可以使用glob语法排除掉文件夹,例如:
|
|
18
20
|
|
|
19
21
|
```shell
|
|
20
|
-
fep-migrator
|
|
22
|
+
fep-migrator . "!**/public"
|
|
21
23
|
```
|
|
22
24
|
|
|
23
25
|
## 注意事项
|
|
24
26
|
|
|
27
|
+
使用前请备份好文件,确保文件已经提交到git仓库
|
|
28
|
+
|
|
25
29
|
`fep-migrator` 会迁移两个包的内容:
|
|
26
30
|
|
|
27
31
|
- element-plus => @falconix/fep
|
|
28
32
|
|
|
29
33
|
- @element-plus/icons-vue => @falconix/icons-vue
|
|
30
34
|
|
|
31
|
-
|
|
35
|
+
`fep-migrator` 会检测文件中是否含有 `font-family:` 如果有,会提示用户修改
|
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import process from "node:process";
|
|
3
3
|
import { cac } from "cac";
|
|
4
|
+
import { rgPath } from "@vscode/ripgrep";
|
|
5
|
+
import { execa } from "execa";
|
|
4
6
|
import fs from "node:fs";
|
|
5
7
|
import path from "node:path";
|
|
6
8
|
import { globbySync } from "globby";
|
|
@@ -8,6 +10,49 @@ import MagicString from "magic-string";
|
|
|
8
10
|
import { parseSync } from "oxc-parser";
|
|
9
11
|
import { parse, writeBack } from "vue-sfc-descriptor-write-back";
|
|
10
12
|
|
|
13
|
+
//#region src/find-font-family.ts
|
|
14
|
+
const finder = async (dirs) => {
|
|
15
|
+
const { exitCode, stdout, stderr } = await execa(rgPath, [
|
|
16
|
+
"font-family:",
|
|
17
|
+
"-l",
|
|
18
|
+
"--json",
|
|
19
|
+
...dirs.reduce((acc, cur) => {
|
|
20
|
+
acc.push(cur.startsWith("!") ? ["--glob", cur] : cur);
|
|
21
|
+
return acc;
|
|
22
|
+
}, []).flat(),
|
|
23
|
+
"-g",
|
|
24
|
+
"*.{css,scss,less,vue}",
|
|
25
|
+
"-g",
|
|
26
|
+
"!**/node_modules/**",
|
|
27
|
+
"-g",
|
|
28
|
+
"!**/public/**"
|
|
29
|
+
], {
|
|
30
|
+
stdio: [
|
|
31
|
+
"ignore",
|
|
32
|
+
"pipe",
|
|
33
|
+
"pipe"
|
|
34
|
+
],
|
|
35
|
+
reject: false
|
|
36
|
+
});
|
|
37
|
+
if (exitCode !== 0) {
|
|
38
|
+
if (exitCode === 2) {
|
|
39
|
+
console.error(`❌ ripgrep 运行错误:`);
|
|
40
|
+
console.error(stderr);
|
|
41
|
+
}
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
const list = stdout.split("\n").map((line) => JSON.parse(line));
|
|
45
|
+
list.filter((i) => i.type === "summary").forEach((i) => {
|
|
46
|
+
console.log(`⚠️ 发现 ${i.data.stats.searches_with_match} 个文件,在css中设置了'font-family'。如无必要请不要覆盖项目的字体设置,请及时修改。`);
|
|
47
|
+
});
|
|
48
|
+
list.filter((i) => i.type === "match").forEach((i) => {
|
|
49
|
+
console.log(`➡️ ${i.data.path.text}:${i.data.line_number}`);
|
|
50
|
+
console.log(i.data.lines.text);
|
|
51
|
+
});
|
|
52
|
+
};
|
|
53
|
+
var find_font_family_default = finder;
|
|
54
|
+
|
|
55
|
+
//#endregion
|
|
11
56
|
//#region src/replace-fep.ts
|
|
12
57
|
const resolveFep = (code, filename) => {
|
|
13
58
|
const ms = new MagicString(code);
|
|
@@ -56,7 +101,7 @@ async function replacer(dirs) {
|
|
|
56
101
|
fail: 0,
|
|
57
102
|
total: fileList.length
|
|
58
103
|
};
|
|
59
|
-
console.log("
|
|
104
|
+
console.log("🚀 开始迁移...");
|
|
60
105
|
for (const file of fileList) try {
|
|
61
106
|
if (file.endsWith(".vue")) {
|
|
62
107
|
const { code, descriptor } = parse(file);
|
|
@@ -91,16 +136,18 @@ async function replacer(dirs) {
|
|
|
91
136
|
console.error(`❌ 处理错误: [${path.relative(process.cwd(), file)}], error:${e}`);
|
|
92
137
|
statistic.fail++;
|
|
93
138
|
}
|
|
94
|
-
console.log(
|
|
139
|
+
console.log(`🏁 迁移完成。共扫描 ${statistic.total} 个文件,修改成功 ${statistic.success} 个,修改失败 ${statistic.fail} 个`);
|
|
95
140
|
}
|
|
96
141
|
var replace_fep_default = replacer;
|
|
97
142
|
|
|
98
143
|
//#endregion
|
|
99
144
|
//#region src/index.ts
|
|
100
145
|
const cli = cac("fep-migrator");
|
|
101
|
-
cli.
|
|
102
|
-
replace_fep_default(dirs);
|
|
146
|
+
cli.command("<...dir>", "处理路径").action(async (dirs) => {
|
|
147
|
+
await replace_fep_default(dirs);
|
|
148
|
+
await find_font_family_default(dirs);
|
|
103
149
|
});
|
|
150
|
+
cli.version(process.env.npm_package_version ?? "-.-.-");
|
|
104
151
|
cli.help();
|
|
105
152
|
cli.parse();
|
|
106
153
|
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fep-migrator",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.0.
|
|
4
|
+
"version": "1.0.5",
|
|
5
5
|
"packageManager": "pnpm@10.23.0",
|
|
6
6
|
"description": "@falconix/fep migration helper",
|
|
7
7
|
"author": "tjyuanpeng <tjyuanpeng@gmail.com>",
|
|
@@ -40,12 +40,14 @@
|
|
|
40
40
|
"typecheck": "tsc --noEmit"
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
|
+
"@vscode/ripgrep": "^1.17.0",
|
|
43
44
|
"@vue/compiler-sfc": "^3.5.26",
|
|
44
45
|
"cac": "^6.7.14",
|
|
46
|
+
"execa": "^9.6.1",
|
|
45
47
|
"globby": "^16.1.0",
|
|
46
48
|
"magic-string": "^0.30.21",
|
|
47
49
|
"oxc-parser": "^0.108.0",
|
|
48
|
-
"vue-sfc-descriptor-write-back": "^1.0.
|
|
50
|
+
"vue-sfc-descriptor-write-back": "^1.0.1"
|
|
49
51
|
},
|
|
50
52
|
"devDependencies": {
|
|
51
53
|
"@antfu/eslint-config": "^6.7.3",
|