zixulu 1.71.0 → 1.71.1
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 +158 -112
- package/dist/index.js.map +1 -1
- package/package.json +9 -3
- package/src/index.ts +2 -2
- package/src/utils/addPrettier.ts +63 -1
- package/src/utils/addTag.ts +3 -4
- package/src/utils/preprocessRegex.ts +0 -1
- package/src/utils/removeTag.ts +2 -4
- package/src/utils/replaceCommitMessage.ts +7 -5
- package/src/utils/replaceTag.ts +4 -3
package/dist/index.js
CHANGED
|
@@ -1422,6 +1422,7 @@ const config = {
|
|
|
1422
1422
|
endOfLine: "lf",
|
|
1423
1423
|
printWidth: 160,
|
|
1424
1424
|
plugins: ["./prettier-plugin-sort-imports.mjs"],
|
|
1425
|
+
controlStatementBraces: "add",
|
|
1425
1426
|
}
|
|
1426
1427
|
|
|
1427
1428
|
export default config
|
|
@@ -1432,6 +1433,7 @@ function getPluginConfig({ isTailwind, isReact }) {
|
|
|
1432
1433
|
import { readFileSync } from "fs"
|
|
1433
1434
|
import { builtinModules } from "module"
|
|
1434
1435
|
|
|
1436
|
+
import removeBraces from "@1adybug/prettier-plugin-remove-braces"
|
|
1435
1437
|
import { createPlugin } from "@1adybug/prettier-plugin-sort-imports"
|
|
1436
1438
|
import JSON5 from "json5"
|
|
1437
1439
|
import blockPadding from "prettier-plugin-block-padding"${isTailwind ? `
|
|
@@ -1513,7 +1515,7 @@ ${isReact ? `
|
|
|
1513
1515
|
separator: "",
|
|
1514
1516
|
sortSideEffect: true,
|
|
1515
1517
|
removeUnusedImports: true,
|
|
1516
|
-
otherPlugins: [blockPadding${isTailwind ? ", tailwindcss" : ""}],
|
|
1518
|
+
otherPlugins: [blockPadding${isTailwind ? ", tailwindcss" : ""}, removeBraces],
|
|
1517
1519
|
})
|
|
1518
1520
|
`;
|
|
1519
1521
|
return config;
|
|
@@ -1548,6 +1550,50 @@ async function addPrettier() {
|
|
|
1548
1550
|
data: packageJson2
|
|
1549
1551
|
});
|
|
1550
1552
|
await installDependceny();
|
|
1553
|
+
const git = simple_git();
|
|
1554
|
+
const isRepo = await git.checkIsRepo();
|
|
1555
|
+
if (isRepo) {
|
|
1556
|
+
consola_0.info("检测到 git 仓库");
|
|
1557
|
+
const shouldSetupHooks = await shouldContinue("是否配置 git hooks,在每次 commit 前自动格式化修改的文件?");
|
|
1558
|
+
if (!shouldSetupHooks) {
|
|
1559
|
+
consola_0.info("跳过 git hooks 配置");
|
|
1560
|
+
consola_0.success("添加 prettier 配置成功");
|
|
1561
|
+
return;
|
|
1562
|
+
}
|
|
1563
|
+
consola_0.start("开始配置 pre-commit hooks");
|
|
1564
|
+
const huskyConfig = {
|
|
1565
|
+
package: [
|
|
1566
|
+
"husky",
|
|
1567
|
+
"lint-staged"
|
|
1568
|
+
],
|
|
1569
|
+
type: "devDependencies"
|
|
1570
|
+
};
|
|
1571
|
+
await addDependency(huskyConfig);
|
|
1572
|
+
await installDependceny();
|
|
1573
|
+
try {
|
|
1574
|
+
consola_0.start("初始化 husky");
|
|
1575
|
+
await spawnAsync("bunx husky init");
|
|
1576
|
+
consola_0.success("husky 初始化成功");
|
|
1577
|
+
} catch (error) {
|
|
1578
|
+
consola_0.error("husky 初始化失败", error);
|
|
1579
|
+
}
|
|
1580
|
+
try {
|
|
1581
|
+
consola_0.start("配置 pre-commit hook");
|
|
1582
|
+
const preCommitHook = "bunx lint-staged";
|
|
1583
|
+
await writeFile(".husky/pre-commit", preCommitHook, "utf-8");
|
|
1584
|
+
consola_0.success("pre-commit hook 配置成功");
|
|
1585
|
+
} catch (error) {
|
|
1586
|
+
consola_0.error("pre-commit hook 配置失败", error);
|
|
1587
|
+
}
|
|
1588
|
+
const packageJson3 = await readPackageJson();
|
|
1589
|
+
packageJson3["lint-staged"] = {
|
|
1590
|
+
"**/*": "prettier --write --ignore-unknown"
|
|
1591
|
+
};
|
|
1592
|
+
await writePackageJson({
|
|
1593
|
+
data: packageJson3
|
|
1594
|
+
});
|
|
1595
|
+
consola_0.success("lint-staged 配置成功");
|
|
1596
|
+
} else consola_0.info("当前目录不是 git 仓库,跳过 git hooks 配置");
|
|
1551
1597
|
consola_0.success("添加 prettier 配置成功");
|
|
1552
1598
|
}
|
|
1553
1599
|
const prismaFile = `import { PrismaClient } from "@prisma/client"
|
|
@@ -1855,6 +1901,75 @@ main()
|
|
|
1855
1901
|
});
|
|
1856
1902
|
return getCommitMessage("feature", "添加同步包脚本");
|
|
1857
1903
|
}
|
|
1904
|
+
function preprocessRegex(reg) {
|
|
1905
|
+
return reg.replace(/\{\{CARET\}\}/g, "^");
|
|
1906
|
+
}
|
|
1907
|
+
async function addTag({ reg, flags, replacement, push, remote = "origin", force }) {
|
|
1908
|
+
const git = simpleGit();
|
|
1909
|
+
const isRepo = await git.checkIsRepo();
|
|
1910
|
+
if (!isRepo) return void consola.error("当前目录不是 git 仓库");
|
|
1911
|
+
const status = await git.status();
|
|
1912
|
+
if (status.files.length > 0) return void consola.error("当前 Git 仓库存在未提交的文件,请先提交或暂存这些文件");
|
|
1913
|
+
const processedReg = preprocessRegex(reg);
|
|
1914
|
+
consola.info(`正则表达式: /${processedReg}/${flags ?? ""}`);
|
|
1915
|
+
consola.info(`替换字符串: ${replacement}`);
|
|
1916
|
+
const cont = await shouldContinue("是否继续?");
|
|
1917
|
+
if (!cont) return void consola.info("操作已取消");
|
|
1918
|
+
const log = await git.log();
|
|
1919
|
+
const commits = log.all;
|
|
1920
|
+
if (0 === commits.length) return void consola.warn("当前仓库没有任何 commit");
|
|
1921
|
+
consola.info(`找到 ${commits.length} 个 commit`);
|
|
1922
|
+
const existingTags = await git.tags();
|
|
1923
|
+
const allExistingTags = new Set(existingTags.all);
|
|
1924
|
+
const tagsToAdd = [];
|
|
1925
|
+
for (const commit of commits){
|
|
1926
|
+
const regexp = new RegExp(processedReg, flags);
|
|
1927
|
+
if (regexp.test(commit.message)) {
|
|
1928
|
+
const tagName = commit.message.replace(new RegExp(processedReg, flags), replacement);
|
|
1929
|
+
if (tagName && tagName.trim()) tagsToAdd.push({
|
|
1930
|
+
hash: commit.hash,
|
|
1931
|
+
message: commit.message,
|
|
1932
|
+
tagName: tagName.trim()
|
|
1933
|
+
});
|
|
1934
|
+
}
|
|
1935
|
+
}
|
|
1936
|
+
if (0 === tagsToAdd.length) return void consola.warn("没有匹配的 commit 需要添加 tag");
|
|
1937
|
+
consola.info(`将要为 ${tagsToAdd.length} 个 commit 添加 tag`);
|
|
1938
|
+
for (const { hash, message, tagName } of tagsToAdd)try {
|
|
1939
|
+
if (allExistingTags.has(tagName)) if (force) {
|
|
1940
|
+
await git.tag([
|
|
1941
|
+
"-d",
|
|
1942
|
+
tagName
|
|
1943
|
+
]);
|
|
1944
|
+
consola.info(`删除已存在的 tag: ${tagName}`);
|
|
1945
|
+
} else {
|
|
1946
|
+
consola.warn(`tag ${tagName} 已存在,跳过 (使用 force 选项可覆盖)`);
|
|
1947
|
+
continue;
|
|
1948
|
+
}
|
|
1949
|
+
await git.tag([
|
|
1950
|
+
tagName,
|
|
1951
|
+
hash
|
|
1952
|
+
]);
|
|
1953
|
+
consola.success(`本地: 为 commit ${hash.substring(0, 7)} (${message.substring(0, 50)}...) 添加 tag ${tagName}`);
|
|
1954
|
+
if (push) try {
|
|
1955
|
+
const pushArgs = force ? [
|
|
1956
|
+
remote,
|
|
1957
|
+
tagName,
|
|
1958
|
+
"--force"
|
|
1959
|
+
] : [
|
|
1960
|
+
remote,
|
|
1961
|
+
tagName
|
|
1962
|
+
];
|
|
1963
|
+
await git.push(pushArgs);
|
|
1964
|
+
consola.success(`远程: 推送 tag ${tagName}`);
|
|
1965
|
+
} catch (error) {
|
|
1966
|
+
consola.error(`推送 tag ${tagName} 到远程失败:`, error);
|
|
1967
|
+
}
|
|
1968
|
+
} catch (error) {
|
|
1969
|
+
consola.error(`为 commit ${hash} 添加 tag ${tagName} 失败:`, error);
|
|
1970
|
+
}
|
|
1971
|
+
consola.success("所有匹配的 tag 添加完成");
|
|
1972
|
+
}
|
|
1858
1973
|
const postcssConfig = `// @ts-check
|
|
1859
1974
|
|
|
1860
1975
|
/** @type {import("postcss-load-config").Config} */
|
|
@@ -2013,75 +2128,6 @@ async function addTailwind() {
|
|
|
2013
2128
|
await addPrettier();
|
|
2014
2129
|
consola_0.success("添加 tailwind 配置成功");
|
|
2015
2130
|
}
|
|
2016
|
-
function preprocessRegex(reg) {
|
|
2017
|
-
return reg.replace(/\{\{CARET\}\}/g, "^");
|
|
2018
|
-
}
|
|
2019
|
-
async function addTag({ reg, flags, replacement, push, remote = "origin", force }) {
|
|
2020
|
-
const git = simpleGit();
|
|
2021
|
-
const isRepo = await git.checkIsRepo();
|
|
2022
|
-
if (!isRepo) return void consola.error("当前目录不是 git 仓库");
|
|
2023
|
-
const status = await git.status();
|
|
2024
|
-
if (status.files.length > 0) return void consola.error("当前 Git 仓库存在未提交的文件,请先提交或暂存这些文件");
|
|
2025
|
-
const processedReg = preprocessRegex(reg);
|
|
2026
|
-
consola.info(`正则表达式: /${processedReg}/${flags ?? ""}`);
|
|
2027
|
-
consola.info(`替换字符串: ${replacement}`);
|
|
2028
|
-
const cont = await shouldContinue("是否继续?");
|
|
2029
|
-
if (!cont) return void consola.info("操作已取消");
|
|
2030
|
-
const log = await git.log();
|
|
2031
|
-
const commits = log.all;
|
|
2032
|
-
if (0 === commits.length) return void consola.warn("当前仓库没有任何 commit");
|
|
2033
|
-
consola.info(`找到 ${commits.length} 个 commit`);
|
|
2034
|
-
const existingTags = await git.tags();
|
|
2035
|
-
const allExistingTags = new Set(existingTags.all);
|
|
2036
|
-
const tagsToAdd = [];
|
|
2037
|
-
for (const commit of commits){
|
|
2038
|
-
const regexp = new RegExp(processedReg, flags);
|
|
2039
|
-
if (regexp.test(commit.message)) {
|
|
2040
|
-
const tagName = commit.message.replace(new RegExp(processedReg, flags), replacement);
|
|
2041
|
-
if (tagName && tagName.trim()) tagsToAdd.push({
|
|
2042
|
-
hash: commit.hash,
|
|
2043
|
-
message: commit.message,
|
|
2044
|
-
tagName: tagName.trim()
|
|
2045
|
-
});
|
|
2046
|
-
}
|
|
2047
|
-
}
|
|
2048
|
-
if (0 === tagsToAdd.length) return void consola.warn("没有匹配的 commit 需要添加 tag");
|
|
2049
|
-
consola.info(`将要为 ${tagsToAdd.length} 个 commit 添加 tag`);
|
|
2050
|
-
for (const { hash, message, tagName } of tagsToAdd)try {
|
|
2051
|
-
if (allExistingTags.has(tagName)) if (force) {
|
|
2052
|
-
await git.tag([
|
|
2053
|
-
"-d",
|
|
2054
|
-
tagName
|
|
2055
|
-
]);
|
|
2056
|
-
consola.info(`删除已存在的 tag: ${tagName}`);
|
|
2057
|
-
} else {
|
|
2058
|
-
consola.warn(`tag ${tagName} 已存在,跳过 (使用 force 选项可覆盖)`);
|
|
2059
|
-
continue;
|
|
2060
|
-
}
|
|
2061
|
-
await git.tag([
|
|
2062
|
-
tagName,
|
|
2063
|
-
hash
|
|
2064
|
-
]);
|
|
2065
|
-
consola.success(`本地: 为 commit ${hash.substring(0, 7)} (${message.substring(0, 50)}...) 添加 tag ${tagName}`);
|
|
2066
|
-
if (push) try {
|
|
2067
|
-
const pushArgs = force ? [
|
|
2068
|
-
remote,
|
|
2069
|
-
tagName,
|
|
2070
|
-
"--force"
|
|
2071
|
-
] : [
|
|
2072
|
-
remote,
|
|
2073
|
-
tagName
|
|
2074
|
-
];
|
|
2075
|
-
await git.push(pushArgs);
|
|
2076
|
-
consola.success(`远程: 推送 tag ${tagName}`);
|
|
2077
|
-
} catch (error) {
|
|
2078
|
-
consola.error(`推送 tag ${tagName} 到远程失败:`, error);
|
|
2079
|
-
}
|
|
2080
|
-
} catch (error) {
|
|
2081
|
-
consola.error(`为 commit ${hash} 添加 tag ${tagName} 失败:`, error);
|
|
2082
|
-
}
|
|
2083
|
-
consola.success("所有匹配的 tag 添加完成");
|
|
2084
|
-
}
|
|
2085
2131
|
const zipDistContent = `// @ts-check
|
|
2086
2132
|
import { rm } from "fs/promises"
|
|
2087
2133
|
import { zip } from "soda-nodejs"
|
|
@@ -3525,6 +3571,48 @@ async function removeLock() {
|
|
|
3525
3571
|
await addRuleToGitIgnore("package-lock.json", "yarn.lock", "pnpm-lock.yaml", "bun.lockb", "bun.lock");
|
|
3526
3572
|
return getCommitMessage("feature", "删除包管理 lock 文件");
|
|
3527
3573
|
}
|
|
3574
|
+
async function removeTag({ reg, flags, push, remote = "origin" }) {
|
|
3575
|
+
const git = simpleGit();
|
|
3576
|
+
const isRepo = await git.checkIsRepo();
|
|
3577
|
+
if (!isRepo) return void consola.error("当前目录不是 git 仓库");
|
|
3578
|
+
const status = await git.status();
|
|
3579
|
+
if (status.files.length > 0) return void consola.error("当前 Git 仓库存在未提交的文件,请先提交或暂存这些文件");
|
|
3580
|
+
const processedReg = preprocessRegex(reg);
|
|
3581
|
+
consola.info(`正则表达式: /${processedReg}/${flags ?? ""}`);
|
|
3582
|
+
const cont = await shouldContinue("是否继续?");
|
|
3583
|
+
if (!cont) return void consola.info("操作已取消");
|
|
3584
|
+
const tags = await git.tags();
|
|
3585
|
+
const allTags = tags.all;
|
|
3586
|
+
if (0 === allTags.length) return void consola.warn("当前仓库没有任何 tag");
|
|
3587
|
+
consola.info(`找到 ${allTags.length} 个 tag`);
|
|
3588
|
+
const tagsToRemove = [];
|
|
3589
|
+
for (const tag of allTags){
|
|
3590
|
+
const regexp = new RegExp(processedReg, flags);
|
|
3591
|
+
if (regexp.test(tag)) tagsToRemove.push(tag);
|
|
3592
|
+
}
|
|
3593
|
+
if (0 === tagsToRemove.length) return void consola.warn("没有匹配的 tag 需要删除");
|
|
3594
|
+
consola.info(`将要删除 ${tagsToRemove.length} 个 tag`);
|
|
3595
|
+
for (const tag of tagsToRemove)try {
|
|
3596
|
+
await git.tag([
|
|
3597
|
+
"-d",
|
|
3598
|
+
tag
|
|
3599
|
+
]);
|
|
3600
|
+
consola.success(`本地: 删除 ${tag}`);
|
|
3601
|
+
if (push) try {
|
|
3602
|
+
await git.push([
|
|
3603
|
+
remote,
|
|
3604
|
+
"--delete",
|
|
3605
|
+
tag
|
|
3606
|
+
]);
|
|
3607
|
+
consola.success(`远程: 删除 ${tag}`);
|
|
3608
|
+
} catch (error) {
|
|
3609
|
+
consola.warn(`远程可能不存在 ${tag},跳过删除`);
|
|
3610
|
+
}
|
|
3611
|
+
} catch (error) {
|
|
3612
|
+
consola.error(`删除 ${tag} 失败:`, error);
|
|
3613
|
+
}
|
|
3614
|
+
consola.success("所有匹配的 tag 删除完成");
|
|
3615
|
+
}
|
|
3528
3616
|
function isAsset(url) {
|
|
3529
3617
|
const lower = url.toLowerCase();
|
|
3530
3618
|
return lower.endsWith(".svg") || lower.endsWith(".png") || lower.endsWith(".jpg") || lower.endsWith(".jpeg") || lower.endsWith(".gif") || lower.endsWith(".webp") || lower.endsWith(".ico") || lower.endsWith(".ttf") || lower.endsWith(".woff") || lower.endsWith(".woff2") || lower.endsWith(".css") || lower.endsWith(".js") || lower.endsWith(".json") || lower.includes("/img/") || lower.includes("/file/") || lower.includes("/assets/");
|
|
@@ -3768,48 +3856,6 @@ process.stdin.on("end", () => {
|
|
|
3768
3856
|
} catch {}
|
|
3769
3857
|
}
|
|
3770
3858
|
}
|
|
3771
|
-
async function removeTag({ reg, flags, push, remote = "origin" }) {
|
|
3772
|
-
const git = simpleGit();
|
|
3773
|
-
const isRepo = await git.checkIsRepo();
|
|
3774
|
-
if (!isRepo) return void consola.error("当前目录不是 git 仓库");
|
|
3775
|
-
const status = await git.status();
|
|
3776
|
-
if (status.files.length > 0) return void consola.error("当前 Git 仓库存在未提交的文件,请先提交或暂存这些文件");
|
|
3777
|
-
const processedReg = preprocessRegex(reg);
|
|
3778
|
-
consola.info(`正则表达式: /${processedReg}/${flags ?? ""}`);
|
|
3779
|
-
const cont = await shouldContinue("是否继续?");
|
|
3780
|
-
if (!cont) return void consola.info("操作已取消");
|
|
3781
|
-
const tags = await git.tags();
|
|
3782
|
-
const allTags = tags.all;
|
|
3783
|
-
if (0 === allTags.length) return void consola.warn("当前仓库没有任何 tag");
|
|
3784
|
-
consola.info(`找到 ${allTags.length} 个 tag`);
|
|
3785
|
-
const tagsToRemove = [];
|
|
3786
|
-
for (const tag of allTags){
|
|
3787
|
-
const regexp = new RegExp(processedReg, flags);
|
|
3788
|
-
if (regexp.test(tag)) tagsToRemove.push(tag);
|
|
3789
|
-
}
|
|
3790
|
-
if (0 === tagsToRemove.length) return void consola.warn("没有匹配的 tag 需要删除");
|
|
3791
|
-
consola.info(`将要删除 ${tagsToRemove.length} 个 tag`);
|
|
3792
|
-
for (const tag of tagsToRemove)try {
|
|
3793
|
-
await git.tag([
|
|
3794
|
-
"-d",
|
|
3795
|
-
tag
|
|
3796
|
-
]);
|
|
3797
|
-
consola.success(`本地: 删除 ${tag}`);
|
|
3798
|
-
if (push) try {
|
|
3799
|
-
await git.push([
|
|
3800
|
-
remote,
|
|
3801
|
-
"--delete",
|
|
3802
|
-
tag
|
|
3803
|
-
]);
|
|
3804
|
-
consola.success(`远程: 删除 ${tag}`);
|
|
3805
|
-
} catch (error) {
|
|
3806
|
-
consola.warn(`远程可能不存在 ${tag},跳过删除`);
|
|
3807
|
-
}
|
|
3808
|
-
} catch (error) {
|
|
3809
|
-
consola.error(`删除 ${tag} 失败:`, error);
|
|
3810
|
-
}
|
|
3811
|
-
consola.success("所有匹配的 tag 删除完成");
|
|
3812
|
-
}
|
|
3813
3859
|
async function replaceTag({ reg, replace, flags, push, remote = "origin" }) {
|
|
3814
3860
|
const git = simpleGit();
|
|
3815
3861
|
const isRepo = await git.checkIsRepo();
|