fep-migrator 1.0.4 → 1.1.0
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/index.mjs +103 -27
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -10,16 +10,18 @@ import MagicString from "magic-string";
|
|
|
10
10
|
import { parseSync } from "oxc-parser";
|
|
11
11
|
import { parse, writeBack } from "vue-sfc-descriptor-write-back";
|
|
12
12
|
|
|
13
|
-
//#region src/
|
|
14
|
-
const
|
|
13
|
+
//#region src/utils/run-ripgrep.ts
|
|
14
|
+
const run$2 = async (searchText, options) => {
|
|
15
|
+
const exclude = options.exclude.reduce((acc, cur) => {
|
|
16
|
+
acc.concat(["-g", `!${cur}`]);
|
|
17
|
+
return acc;
|
|
18
|
+
}, []);
|
|
15
19
|
const { exitCode, stdout, stderr } = await execa(rgPath, [
|
|
16
|
-
|
|
20
|
+
searchText,
|
|
17
21
|
"-l",
|
|
18
22
|
"--json",
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
return acc;
|
|
22
|
-
}, []).flat(),
|
|
23
|
+
options.root,
|
|
24
|
+
...exclude,
|
|
23
25
|
"-g",
|
|
24
26
|
"*.{css,scss,less,vue}",
|
|
25
27
|
"-g",
|
|
@@ -34,23 +36,45 @@ const finder = async (dirs) => {
|
|
|
34
36
|
],
|
|
35
37
|
reject: false
|
|
36
38
|
});
|
|
37
|
-
if (exitCode
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
39
|
+
if (exitCode === 1) return null;
|
|
40
|
+
else if (exitCode === 2) throw new Error(`❌ ripgrep 执行失败:${stderr}`);
|
|
41
|
+
return stdout;
|
|
42
|
+
};
|
|
43
|
+
var run_ripgrep_default = run$2;
|
|
44
|
+
|
|
45
|
+
//#endregion
|
|
46
|
+
//#region src/find-font-family.ts
|
|
47
|
+
const finder$1 = async (options) => {
|
|
48
|
+
const searchText = "font-family:";
|
|
49
|
+
const stdout = await run_ripgrep_default(searchText, options);
|
|
50
|
+
if (!stdout) return;
|
|
51
|
+
const list = stdout.split("\n").map((line) => JSON.parse(line));
|
|
52
|
+
list.filter((i) => i.type === "summary").forEach((i) => {
|
|
53
|
+
console.log(`\n⚠️ 发现 ${i.data.stats.searches_with_match} 个文件,在css中设置了'${searchText}'。如无必要请不要覆盖项目的字体设置,请及时修改。`);
|
|
54
|
+
});
|
|
55
|
+
list.filter((i) => i.type === "match").forEach((i) => {
|
|
56
|
+
console.log(`➡️ ${i.data.path.text}:${i.data.line_number}`);
|
|
57
|
+
console.log(i.data.lines.text.replace("\n", ""));
|
|
58
|
+
});
|
|
59
|
+
};
|
|
60
|
+
var find_font_family_default = finder$1;
|
|
61
|
+
|
|
62
|
+
//#endregion
|
|
63
|
+
//#region src/find-message-box.ts
|
|
64
|
+
const finder = async (options) => {
|
|
65
|
+
const searchText = ".el-message-box";
|
|
66
|
+
const stdout = await run_ripgrep_default(searchText, options);
|
|
67
|
+
if (!stdout) return;
|
|
44
68
|
const list = stdout.split("\n").map((line) => JSON.parse(line));
|
|
45
69
|
list.filter((i) => i.type === "summary").forEach((i) => {
|
|
46
|
-
console.log(
|
|
70
|
+
console.log(`\n⚠️ 发现 ${i.data.stats.searches_with_match} 个文件,在css中设置了'${searchText}'。如无必要请不要覆盖messagebox的css设置,请及时修改。`);
|
|
47
71
|
});
|
|
48
72
|
list.filter((i) => i.type === "match").forEach((i) => {
|
|
49
73
|
console.log(`➡️ ${i.data.path.text}:${i.data.line_number}`);
|
|
50
|
-
console.log(i.data.lines.text);
|
|
74
|
+
console.log(i.data.lines.text.replace("\n", ""));
|
|
51
75
|
});
|
|
52
76
|
};
|
|
53
|
-
var
|
|
77
|
+
var find_message_box_default = finder;
|
|
54
78
|
|
|
55
79
|
//#endregion
|
|
56
80
|
//#region src/replace-fep.ts
|
|
@@ -78,8 +102,8 @@ const resolveFep = (code, filename) => {
|
|
|
78
102
|
const hasChanged = ms.hasChanged();
|
|
79
103
|
return [hasChanged, hasChanged ? ms.toString() : code];
|
|
80
104
|
};
|
|
81
|
-
async function replacer(
|
|
82
|
-
const fileList = globbySync(
|
|
105
|
+
async function replacer(options) {
|
|
106
|
+
const fileList = globbySync([options.root, ...options.exclude.map((i) => `!${i}`)], {
|
|
83
107
|
absolute: true,
|
|
84
108
|
onlyFiles: true,
|
|
85
109
|
gitignore: true,
|
|
@@ -122,34 +146,86 @@ async function replacer(dirs) {
|
|
|
122
146
|
}
|
|
123
147
|
if (changed) {
|
|
124
148
|
const { code: resolved } = writeBack(code, descriptor);
|
|
125
|
-
fs.writeFileSync(file, resolved);
|
|
149
|
+
!options.dryRun && fs.writeFileSync(file, resolved);
|
|
150
|
+
console.error(`✅ 处理完成: [${path.relative(options.root, file)}]`);
|
|
126
151
|
statistic.success++;
|
|
127
152
|
}
|
|
128
153
|
} else {
|
|
129
154
|
const [hasChanged, resolved] = resolveFep(fs.readFileSync(file, { encoding: "utf-8" }), file);
|
|
130
155
|
if (hasChanged) {
|
|
131
|
-
fs.writeFileSync(file, resolved);
|
|
156
|
+
!options.dryRun && fs.writeFileSync(file, resolved);
|
|
157
|
+
console.error(`✅ 处理完成: [${path.relative(options.root, file)}]`);
|
|
132
158
|
statistic.success++;
|
|
133
159
|
}
|
|
134
160
|
}
|
|
135
161
|
} catch (e) {
|
|
136
|
-
console.error(`❌ 处理错误: [${path.relative(
|
|
162
|
+
console.error(`❌ 处理错误: [${path.relative(options.root, file)}], error:${e}`);
|
|
137
163
|
statistic.fail++;
|
|
138
164
|
}
|
|
139
165
|
console.log(`🏁 迁移完成。共扫描 ${statistic.total} 个文件,修改成功 ${statistic.success} 个,修改失败 ${statistic.fail} 个`);
|
|
140
166
|
}
|
|
141
167
|
var replace_fep_default = replacer;
|
|
142
168
|
|
|
169
|
+
//#endregion
|
|
170
|
+
//#region src/utils/run-command.ts
|
|
171
|
+
const run$1 = async (command, args, options) => {
|
|
172
|
+
console.log(`➡️ 执行: ${[command, ...args].join(" ")}`);
|
|
173
|
+
if (options.dryRun) return;
|
|
174
|
+
const { exitCode } = await execa(command, args, {
|
|
175
|
+
cwd: options.root,
|
|
176
|
+
stdio: [
|
|
177
|
+
"ignore",
|
|
178
|
+
"inherit",
|
|
179
|
+
"inherit"
|
|
180
|
+
],
|
|
181
|
+
reject: false
|
|
182
|
+
});
|
|
183
|
+
if (exitCode !== 0) throw new Error(`❌ 执行失败: ${[command, ...args].join(" ")}`);
|
|
184
|
+
return exitCode;
|
|
185
|
+
};
|
|
186
|
+
var run_command_default = run$1;
|
|
187
|
+
|
|
188
|
+
//#endregion
|
|
189
|
+
//#region src/run-install.ts
|
|
190
|
+
const main = async (options) => {
|
|
191
|
+
const pkgPath = path.resolve(options.root, "./package.json");
|
|
192
|
+
if (!fs.existsSync(pkgPath)) throw new Error(`❌ 未找到 \'package.json\',请在项目根目录执行`);
|
|
193
|
+
await run_command_default(options.pkgManager, [
|
|
194
|
+
"add",
|
|
195
|
+
"@falconix/fep",
|
|
196
|
+
"@falconix/icons-vue"
|
|
197
|
+
], options);
|
|
198
|
+
await run_command_default(options.pkgManager, [
|
|
199
|
+
"add",
|
|
200
|
+
"@falconix/fep-resolver",
|
|
201
|
+
"-D"
|
|
202
|
+
], options);
|
|
203
|
+
await run_command_default(options.pkgManager, [
|
|
204
|
+
"remove",
|
|
205
|
+
"element-plus",
|
|
206
|
+
"@element-plus/icons-vue"
|
|
207
|
+
], options);
|
|
208
|
+
};
|
|
209
|
+
var run_install_default = main;
|
|
210
|
+
|
|
143
211
|
//#endregion
|
|
144
212
|
//#region src/index.ts
|
|
145
213
|
const cli = cac("fep-migrator");
|
|
146
|
-
cli.
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
});
|
|
214
|
+
cli.option("-e, --exclude <dir>", "排除目录", {
|
|
215
|
+
default: [],
|
|
216
|
+
type: [String]
|
|
217
|
+
}).option("-p, --pkg-manager", "指定包管理工具,可选值:pnpm、npm、yarn", { default: "pnpm" }).option("-d, --dry-run", "模拟运行,不实际修改文件", { default: false });
|
|
150
218
|
cli.version(process.env.npm_package_version ?? "-.-.-");
|
|
151
219
|
cli.help();
|
|
152
|
-
|
|
220
|
+
const run = async () => {
|
|
221
|
+
const { options } = cli.parse();
|
|
222
|
+
options.root = process.cwd();
|
|
223
|
+
await run_install_default(options);
|
|
224
|
+
await replace_fep_default(options);
|
|
225
|
+
await find_font_family_default(options);
|
|
226
|
+
await find_message_box_default(options);
|
|
227
|
+
};
|
|
228
|
+
run();
|
|
153
229
|
|
|
154
230
|
//#endregion
|
|
155
231
|
export { };
|
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.1.0",
|
|
5
5
|
"packageManager": "pnpm@10.23.0",
|
|
6
6
|
"description": "@falconix/fep migration helper",
|
|
7
7
|
"author": "tjyuanpeng <tjyuanpeng@gmail.com>",
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
"globby": "^16.1.0",
|
|
48
48
|
"magic-string": "^0.30.21",
|
|
49
49
|
"oxc-parser": "^0.108.0",
|
|
50
|
-
"vue-sfc-descriptor-write-back": "^1.0.
|
|
50
|
+
"vue-sfc-descriptor-write-back": "^1.0.1"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
53
|
"@antfu/eslint-config": "^6.7.3",
|