zixulu 1.71.4 → 1.71.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/dist/index.js +62 -43
- package/dist/index.js.map +1 -1
- package/dist/src/utils/addHusky.d.ts +11 -0
- package/package.json +1 -1
- package/src/index.ts +6 -0
- package/src/utils/addHusky.ts +79 -0
- package/src/utils/addPrettier.ts +17 -51
package/dist/index.js
CHANGED
|
@@ -15,8 +15,8 @@ import { createWriteStream, existsSync, readFileSync } from "fs";
|
|
|
15
15
|
import { homedir, tmpdir } from "os";
|
|
16
16
|
import { parse as toml_parse, stringify } from "@iarna/toml";
|
|
17
17
|
import { writeFile as promises_writeFile } from "node:fs/promises";
|
|
18
|
-
import json5 from "json5";
|
|
19
18
|
import simple_git, { simpleGit } from "simple-git";
|
|
19
|
+
import json5 from "json5";
|
|
20
20
|
import dayjs from "dayjs";
|
|
21
21
|
import clipboardy from "clipboardy";
|
|
22
22
|
import yaml_0 from "yaml";
|
|
@@ -1216,6 +1216,51 @@ async function addGitignore() {
|
|
|
1216
1216
|
const message = await addRuleToGitIgnore(...addedRules);
|
|
1217
1217
|
return message;
|
|
1218
1218
|
}
|
|
1219
|
+
async function addHusky(params) {
|
|
1220
|
+
const options = params ?? {};
|
|
1221
|
+
const git = simple_git();
|
|
1222
|
+
const isRepo = await git.checkIsRepo();
|
|
1223
|
+
if (!isRepo) return void consola_0.info("当前目录不是 git 仓库,跳过 husky 配置");
|
|
1224
|
+
if (options.skipConfirm) consola_0.info("已根据外部指令跳过 husky 配置确认");
|
|
1225
|
+
else {
|
|
1226
|
+
const shouldSetupHooks = await shouldContinue("是否配置 husky hooks,在每次 commit 前自动格式化修改的文件?");
|
|
1227
|
+
if (!shouldSetupHooks) return void consola_0.info("已取消 husky 配置");
|
|
1228
|
+
}
|
|
1229
|
+
consola_0.start("开始配置 husky");
|
|
1230
|
+
const huskyConfig = {
|
|
1231
|
+
package: [
|
|
1232
|
+
"husky",
|
|
1233
|
+
"lint-staged"
|
|
1234
|
+
],
|
|
1235
|
+
type: "devDependencies"
|
|
1236
|
+
};
|
|
1237
|
+
await addDependency(huskyConfig);
|
|
1238
|
+
await installDependceny();
|
|
1239
|
+
try {
|
|
1240
|
+
consola_0.start("初始化 husky");
|
|
1241
|
+
await spawnAsync("bunx husky init");
|
|
1242
|
+
consola_0.success("husky 初始化成功");
|
|
1243
|
+
} catch (error) {
|
|
1244
|
+
consola_0.error("husky 初始化失败", error);
|
|
1245
|
+
}
|
|
1246
|
+
try {
|
|
1247
|
+
consola_0.start("配置 pre-commit hook");
|
|
1248
|
+
const preCommitHook = "npx lint-staged";
|
|
1249
|
+
await writeFile(".husky/pre-commit", preCommitHook, "utf-8");
|
|
1250
|
+
consola_0.success("pre-commit hook 配置成功");
|
|
1251
|
+
} catch (error) {
|
|
1252
|
+
consola_0.error("pre-commit hook 配置失败", error);
|
|
1253
|
+
}
|
|
1254
|
+
const packageJson = await readPackageJson();
|
|
1255
|
+
packageJson["lint-staged"] = {
|
|
1256
|
+
"**/*": "prettier --write --ignore-unknown"
|
|
1257
|
+
};
|
|
1258
|
+
await writePackageJson({
|
|
1259
|
+
data: packageJson
|
|
1260
|
+
});
|
|
1261
|
+
consola_0.success("lint-staged 配置成功");
|
|
1262
|
+
consola_0.success("husky 配置完成");
|
|
1263
|
+
}
|
|
1219
1264
|
async function getFiles_getFiles(options) {
|
|
1220
1265
|
const { dir = ".", match, count, depth, exclude } = options;
|
|
1221
1266
|
const result = [];
|
|
@@ -1450,48 +1495,21 @@ async function addPrettier() {
|
|
|
1450
1495
|
await installDependceny();
|
|
1451
1496
|
const git = simple_git();
|
|
1452
1497
|
const isRepo = await git.checkIsRepo();
|
|
1453
|
-
if (isRepo) {
|
|
1454
|
-
consola_0.info("
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
consola_0.
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
};
|
|
1469
|
-
await addDependency(huskyConfig);
|
|
1470
|
-
await installDependceny();
|
|
1471
|
-
try {
|
|
1472
|
-
consola_0.start("初始化 husky");
|
|
1473
|
-
await spawnAsync("bunx husky init");
|
|
1474
|
-
consola_0.success("husky 初始化成功");
|
|
1475
|
-
} catch (error) {
|
|
1476
|
-
consola_0.error("husky 初始化失败", error);
|
|
1477
|
-
}
|
|
1478
|
-
try {
|
|
1479
|
-
consola_0.start("配置 pre-commit hook");
|
|
1480
|
-
const preCommitHook = "npx lint-staged";
|
|
1481
|
-
await writeFile(".husky/pre-commit", preCommitHook, "utf-8");
|
|
1482
|
-
consola_0.success("pre-commit hook 配置成功");
|
|
1483
|
-
} catch (error) {
|
|
1484
|
-
consola_0.error("pre-commit hook 配置失败", error);
|
|
1485
|
-
}
|
|
1486
|
-
const packageJson3 = await readPackageJson();
|
|
1487
|
-
packageJson3["lint-staged"] = {
|
|
1488
|
-
"**/*": "prettier --write --ignore-unknown"
|
|
1489
|
-
};
|
|
1490
|
-
await writePackageJson({
|
|
1491
|
-
data: packageJson3
|
|
1492
|
-
});
|
|
1493
|
-
consola_0.success("lint-staged 配置成功");
|
|
1494
|
-
} else consola_0.info("当前目录不是 git 仓库,跳过 git hooks 配置");
|
|
1498
|
+
if (!isRepo) {
|
|
1499
|
+
consola_0.info("当前目录不是 git 仓库,跳过 git hooks 配置");
|
|
1500
|
+
consola_0.success("添加 prettier 配置成功");
|
|
1501
|
+
return;
|
|
1502
|
+
}
|
|
1503
|
+
consola_0.info("检测到 git 仓库");
|
|
1504
|
+
const shouldSetupHooks = await shouldContinue("是否配置 git hooks,在每次 commit 前自动格式化修改的文件?");
|
|
1505
|
+
if (!shouldSetupHooks) {
|
|
1506
|
+
consola_0.info("跳过 git hooks 配置");
|
|
1507
|
+
consola_0.success("添加 prettier 配置成功");
|
|
1508
|
+
return;
|
|
1509
|
+
}
|
|
1510
|
+
await addHusky({
|
|
1511
|
+
skipConfirm: true
|
|
1512
|
+
});
|
|
1495
1513
|
consola_0.success("添加 prettier 配置成功");
|
|
1496
1514
|
}
|
|
1497
1515
|
const prismaFile = `import { PrismaClient } from "@prisma/client"
|
|
@@ -4941,6 +4959,7 @@ program.name("格数科技").version(src_pkg.version);
|
|
|
4941
4959
|
console.log(chalk.redBright.bold(`zixulu ${src_pkg.version}`));
|
|
4942
4960
|
program.command("eslint").description("添加 ESLint 相关配置").action(actionWithBackup(addEslint, getCommitMessage("feature", "添加 ESLint 相关配置")));
|
|
4943
4961
|
program.command("prettier").description("添加 prettier 配置").action(actionWithBackup(addPrettier, getCommitMessage("feature", "添加 prettier 配置文件")));
|
|
4962
|
+
program.command("husky").description("添加 husky 配置").action(actionWithBackup(addHusky, getCommitMessage("feature", "添加 husky 配置")));
|
|
4944
4963
|
program.command("vite").description("初始化 vite 配置").action(actionWithBackup(vite, getCommitMessage("feature", "初始化 vite 配置")));
|
|
4945
4964
|
program.command("rsbuild").description("初始化 rsbuild 配置").action(actionWithBackup(rsbuild, getCommitMessage("feature", "初始化 rsbuild 配置")));
|
|
4946
4965
|
program.command("next").description("初始化 next 配置").action(actionWithBackup(next_next, getCommitMessage("feature", "初始化 next 配置")));
|