zixulu 1.71.3 → 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 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 = [];
@@ -1423,6 +1468,7 @@ const config = {
1423
1468
  printWidth: 160,
1424
1469
  plugins: ["@1adybug/prettier"],
1425
1470
  controlStatementBraces: "add",
1471
+ multipleLineBraces: "add",
1426
1472
  }
1427
1473
 
1428
1474
  export default config
@@ -1449,48 +1495,21 @@ async function addPrettier() {
1449
1495
  await installDependceny();
1450
1496
  const git = simple_git();
1451
1497
  const isRepo = await git.checkIsRepo();
1452
- if (isRepo) {
1453
- consola_0.info("检测到 git 仓库");
1454
- const shouldSetupHooks = await shouldContinue("是否配置 git hooks,在每次 commit 前自动格式化修改的文件?");
1455
- if (!shouldSetupHooks) {
1456
- consola_0.info("跳过 git hooks 配置");
1457
- consola_0.success("添加 prettier 配置成功");
1458
- return;
1459
- }
1460
- consola_0.start("开始配置 pre-commit hooks");
1461
- const huskyConfig = {
1462
- package: [
1463
- "husky",
1464
- "lint-staged"
1465
- ],
1466
- type: "devDependencies"
1467
- };
1468
- await addDependency(huskyConfig);
1469
- await installDependceny();
1470
- try {
1471
- consola_0.start("初始化 husky");
1472
- await spawnAsync("bunx husky init");
1473
- consola_0.success("husky 初始化成功");
1474
- } catch (error) {
1475
- consola_0.error("husky 初始化失败", error);
1476
- }
1477
- try {
1478
- consola_0.start("配置 pre-commit hook");
1479
- const preCommitHook = "npx lint-staged";
1480
- await writeFile(".husky/pre-commit", preCommitHook, "utf-8");
1481
- consola_0.success("pre-commit hook 配置成功");
1482
- } catch (error) {
1483
- consola_0.error("pre-commit hook 配置失败", error);
1484
- }
1485
- const packageJson3 = await readPackageJson();
1486
- packageJson3["lint-staged"] = {
1487
- "**/*": "prettier --write --ignore-unknown"
1488
- };
1489
- await writePackageJson({
1490
- data: packageJson3
1491
- });
1492
- consola_0.success("lint-staged 配置成功");
1493
- } 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
+ });
1494
1513
  consola_0.success("添加 prettier 配置成功");
1495
1514
  }
1496
1515
  const prismaFile = `import { PrismaClient } from "@prisma/client"
@@ -4940,6 +4959,7 @@ program.name("格数科技").version(src_pkg.version);
4940
4959
  console.log(chalk.redBright.bold(`zixulu ${src_pkg.version}`));
4941
4960
  program.command("eslint").description("添加 ESLint 相关配置").action(actionWithBackup(addEslint, getCommitMessage("feature", "添加 ESLint 相关配置")));
4942
4961
  program.command("prettier").description("添加 prettier 配置").action(actionWithBackup(addPrettier, getCommitMessage("feature", "添加 prettier 配置文件")));
4962
+ program.command("husky").description("添加 husky 配置").action(actionWithBackup(addHusky, getCommitMessage("feature", "添加 husky 配置")));
4943
4963
  program.command("vite").description("初始化 vite 配置").action(actionWithBackup(vite, getCommitMessage("feature", "初始化 vite 配置")));
4944
4964
  program.command("rsbuild").description("初始化 rsbuild 配置").action(actionWithBackup(rsbuild, getCommitMessage("feature", "初始化 rsbuild 配置")));
4945
4965
  program.command("next").description("初始化 next 配置").action(actionWithBackup(next_next, getCommitMessage("feature", "初始化 next 配置")));