@quiteer/scripts 0.0.7 → 0.0.10
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 +97 -79
- package/package.json +3 -2
package/dist/index.mjs
CHANGED
|
@@ -12,7 +12,7 @@ import enquirer from "enquirer";
|
|
|
12
12
|
import { versionBump } from "bumpp";
|
|
13
13
|
|
|
14
14
|
//#region package.json
|
|
15
|
-
var version = "0.0.
|
|
15
|
+
var version = "0.0.10";
|
|
16
16
|
|
|
17
17
|
//#endregion
|
|
18
18
|
//#region src/locales/changelog.ts
|
|
@@ -250,15 +250,8 @@ async function getRepoWebUrl() {
|
|
|
250
250
|
async function prependFile(filePath, content) {
|
|
251
251
|
try {
|
|
252
252
|
await access(filePath);
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
content.trim(),
|
|
256
|
-
"",
|
|
257
|
-
prev.trim()
|
|
258
|
-
].join("\n"), "utf8");
|
|
259
|
-
} catch {
|
|
260
|
-
await writeFile(filePath, `${content.trim()}\n`, "utf8");
|
|
261
|
-
}
|
|
253
|
+
} catch {}
|
|
254
|
+
await writeFile(filePath, `${content.trim()}\n`, "utf8");
|
|
262
255
|
}
|
|
263
256
|
/**
|
|
264
257
|
* 为每个提交补充变更文件与统计信息
|
|
@@ -445,6 +438,74 @@ async function cleanup(paths) {
|
|
|
445
438
|
await rimraf(paths, { glob: true });
|
|
446
439
|
}
|
|
447
440
|
|
|
441
|
+
//#endregion
|
|
442
|
+
//#region src/commands/dir-tree.ts
|
|
443
|
+
/**
|
|
444
|
+
* 生成目录树结构字符串(ASCII Tree)
|
|
445
|
+
* - 默认忽略常见目录:node_modules、.git、dist、out、logs
|
|
446
|
+
* @param root 起始目录,默认为当前工作目录
|
|
447
|
+
* @returns 目录树字符串
|
|
448
|
+
*/
|
|
449
|
+
async function buildDirTree(root = process.cwd(), ignoreList) {
|
|
450
|
+
const ignore = new Set(ignoreList ?? [
|
|
451
|
+
"node_modules",
|
|
452
|
+
".git",
|
|
453
|
+
"dist",
|
|
454
|
+
"out",
|
|
455
|
+
"logs"
|
|
456
|
+
]);
|
|
457
|
+
async function walk(dir, prefix = "") {
|
|
458
|
+
const items = (await readdir(dir, { withFileTypes: true })).filter((e) => !ignore.has(e.name)).map((e) => ({
|
|
459
|
+
name: e.name,
|
|
460
|
+
isDir: e.isDirectory()
|
|
461
|
+
})).sort((a, b) => a.isDir === b.isDir ? a.name.localeCompare(b.name) : a.isDir ? -1 : 1);
|
|
462
|
+
const lines = [];
|
|
463
|
+
const lastIdx = items.length - 1;
|
|
464
|
+
for (let i = 0; i < items.length; i++) {
|
|
465
|
+
const it = items[i];
|
|
466
|
+
const isLast = i === lastIdx;
|
|
467
|
+
const connector = isLast ? "└── " : "├── ";
|
|
468
|
+
const nextPrefix = prefix + (isLast ? " " : "│ ");
|
|
469
|
+
lines.push(`${prefix}${connector}${it.name}`);
|
|
470
|
+
if (it.isDir) {
|
|
471
|
+
const sub = await walk(path.join(dir, it.name), nextPrefix);
|
|
472
|
+
lines.push(...sub);
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
return lines;
|
|
476
|
+
}
|
|
477
|
+
const title = path.basename(root);
|
|
478
|
+
const content = await walk(root);
|
|
479
|
+
return [`|-- ${title}`, ...content].join("\n");
|
|
480
|
+
}
|
|
481
|
+
/**
|
|
482
|
+
* 根据目录树内容生成 Markdown 并写入文件
|
|
483
|
+
* - 使用代码块包裹,便于阅读
|
|
484
|
+
* @param tree 目录树字符串
|
|
485
|
+
* @param outfile 输出文件路径,默认 `DIRECTORY_TREE.md`
|
|
486
|
+
*/
|
|
487
|
+
async function writeDirTreeMd(tree, outfile = "DIRECTORY_TREE.md") {
|
|
488
|
+
const md = `## 目录结构
|
|
489
|
+
|
|
490
|
+
\`\`\`text\n${tree}\n\`\`\`\n`;
|
|
491
|
+
await writeFile(path.join(process.cwd(), outfile), md, "utf8");
|
|
492
|
+
}
|
|
493
|
+
/**
|
|
494
|
+
* 生成并输出目录结构,支持可选生成 Markdown 文件
|
|
495
|
+
* - 默认只在控制台输出
|
|
496
|
+
* @param dir 目标目录,默认当前工作目录
|
|
497
|
+
* @param md 是否生成 Markdown 文件,默认 false
|
|
498
|
+
*/
|
|
499
|
+
async function generateDirTree(dir, opts) {
|
|
500
|
+
const tree = await buildDirTree(dir ? path.resolve(process.cwd(), dir) : process.cwd(), opts?.ignore);
|
|
501
|
+
console.info("quiteer-script :>>", gray(`\n${tree}\n`));
|
|
502
|
+
if (opts?.md) {
|
|
503
|
+
const out = opts?.output || "DIRECTORY_TREE.md";
|
|
504
|
+
await writeDirTreeMd(tree, out);
|
|
505
|
+
console.info(lightCyan("quiteer-script :>>"), lightGreen(`已生成 Markdown: ${lightBlue(out)}`));
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
|
|
448
509
|
//#endregion
|
|
449
510
|
//#region src/config/index.ts
|
|
450
511
|
const defaultOptions = {
|
|
@@ -850,6 +911,21 @@ async function release(tagPrefix) {
|
|
|
850
911
|
//#endregion
|
|
851
912
|
//#region src/commands/self-update.ts
|
|
852
913
|
/**
|
|
914
|
+
* 获取当前命令来源路径(本地 node_modules/.bin 或全局)
|
|
915
|
+
* @returns 可执行文件路径(若无法获取返回空字符串)
|
|
916
|
+
*/
|
|
917
|
+
async function getCurrentBinPath() {
|
|
918
|
+
try {
|
|
919
|
+
const p = await execCommand("command", ["-v", "qui"]);
|
|
920
|
+
if (p) return p;
|
|
921
|
+
} catch {}
|
|
922
|
+
try {
|
|
923
|
+
return await execCommand("which", ["qui"]);
|
|
924
|
+
} catch {
|
|
925
|
+
return "";
|
|
926
|
+
}
|
|
927
|
+
}
|
|
928
|
+
/**
|
|
853
929
|
* 检查 @quiteer/scripts 是否有新版本并提示更新
|
|
854
930
|
* - 启动任意命令时调用,仅提示不执行安装
|
|
855
931
|
*/
|
|
@@ -860,7 +936,12 @@ async function checkUpdateAndNotify() {
|
|
|
860
936
|
"@quiteer/scripts",
|
|
861
937
|
"version"
|
|
862
938
|
]);
|
|
863
|
-
|
|
939
|
+
const binPath = await getCurrentBinPath();
|
|
940
|
+
const isLocal = binPath.includes("node_modules/.bin");
|
|
941
|
+
if (latest && latest !== version) {
|
|
942
|
+
console.info("quiteer-script :>> ", lightCyan(`检测到新版本 ${lightGreen(latest)},当前版本 ${lightBlue(version)},建议执行 ${bgGreen(white("qui su"))} 进行更新`));
|
|
943
|
+
if (isLocal) console.info("quiteer-script :>> ", lightBlue(`当前正在使用本地工作区命令:${binPath}`));
|
|
944
|
+
}
|
|
864
945
|
} catch {}
|
|
865
946
|
}
|
|
866
947
|
/**
|
|
@@ -889,6 +970,11 @@ async function selfUpdate() {
|
|
|
889
970
|
`@quiteer/scripts@${latest}`
|
|
890
971
|
], { stdio: "inherit" });
|
|
891
972
|
console.info("quiteer-script :>> ", lightGreen("更新完成,请重新运行命令"));
|
|
973
|
+
if ((await getCurrentBinPath()).includes("node_modules/.bin")) {
|
|
974
|
+
console.info("quiteer-script :>> ", lightBlue("当前命令来源于本地工作区,如需使用全局最新版本:"));
|
|
975
|
+
console.info("quiteer-script :>> ", lightBlue("1) 退出当前仓库目录后执行 `qui`"));
|
|
976
|
+
console.info("quiteer-script :>> ", lightBlue("2) 或使用临时执行:`pnpm dlx @quiteer/scripts <command>`"));
|
|
977
|
+
}
|
|
892
978
|
} catch (e) {
|
|
893
979
|
console.info("quiteer-script :>> ", lightBlue(`更新失败:${e?.message || "未知错误"}`));
|
|
894
980
|
}
|
|
@@ -900,74 +986,6 @@ async function updatePkg(args = ["--deep", "-u"]) {
|
|
|
900
986
|
execCommand("npx", ["npm-check-updates", ...args], { stdio: "inherit" });
|
|
901
987
|
}
|
|
902
988
|
|
|
903
|
-
//#endregion
|
|
904
|
-
//#region src/commands/dir-tree.ts
|
|
905
|
-
/**
|
|
906
|
-
* 生成目录树结构字符串(ASCII Tree)
|
|
907
|
-
* - 默认忽略常见目录:node_modules、.git、dist、out、logs
|
|
908
|
-
* @param root 起始目录,默认为当前工作目录
|
|
909
|
-
* @returns 目录树字符串
|
|
910
|
-
*/
|
|
911
|
-
async function buildDirTree(root = process.cwd(), ignoreList) {
|
|
912
|
-
const ignore = new Set(ignoreList ?? [
|
|
913
|
-
"node_modules",
|
|
914
|
-
".git",
|
|
915
|
-
"dist",
|
|
916
|
-
"out",
|
|
917
|
-
"logs"
|
|
918
|
-
]);
|
|
919
|
-
async function walk(dir, prefix = "") {
|
|
920
|
-
const items = (await readdir(dir, { withFileTypes: true })).filter((e) => !ignore.has(e.name)).map((e) => ({
|
|
921
|
-
name: e.name,
|
|
922
|
-
isDir: e.isDirectory()
|
|
923
|
-
})).sort((a, b) => a.isDir === b.isDir ? a.name.localeCompare(b.name) : a.isDir ? -1 : 1);
|
|
924
|
-
const lines = [];
|
|
925
|
-
const lastIdx = items.length - 1;
|
|
926
|
-
for (let i = 0; i < items.length; i++) {
|
|
927
|
-
const it = items[i];
|
|
928
|
-
const isLast = i === lastIdx;
|
|
929
|
-
const connector = isLast ? "└── " : "├── ";
|
|
930
|
-
const nextPrefix = prefix + (isLast ? " " : "│ ");
|
|
931
|
-
lines.push(`${prefix}${connector}${it.name}`);
|
|
932
|
-
if (it.isDir) {
|
|
933
|
-
const sub = await walk(path.join(dir, it.name), nextPrefix);
|
|
934
|
-
lines.push(...sub);
|
|
935
|
-
}
|
|
936
|
-
}
|
|
937
|
-
return lines;
|
|
938
|
-
}
|
|
939
|
-
const title = path.basename(root);
|
|
940
|
-
const content = await walk(root);
|
|
941
|
-
return [`|-- ${title}`, ...content].join("\n");
|
|
942
|
-
}
|
|
943
|
-
/**
|
|
944
|
-
* 根据目录树内容生成 Markdown 并写入文件
|
|
945
|
-
* - 使用代码块包裹,便于阅读
|
|
946
|
-
* @param tree 目录树字符串
|
|
947
|
-
* @param outfile 输出文件路径,默认 `DIRECTORY_TREE.md`
|
|
948
|
-
*/
|
|
949
|
-
async function writeDirTreeMd(tree, outfile = "DIRECTORY_TREE.md") {
|
|
950
|
-
const md = `## 目录结构
|
|
951
|
-
|
|
952
|
-
\`\`\`text\n${tree}\n\`\`\`\n`;
|
|
953
|
-
await writeFile(path.join(process.cwd(), outfile), md, "utf8");
|
|
954
|
-
}
|
|
955
|
-
/**
|
|
956
|
-
* 生成并输出目录结构,支持可选生成 Markdown 文件
|
|
957
|
-
* - 默认只在控制台输出
|
|
958
|
-
* @param dir 目标目录,默认当前工作目录
|
|
959
|
-
* @param md 是否生成 Markdown 文件,默认 false
|
|
960
|
-
*/
|
|
961
|
-
async function generateDirTree(dir, opts) {
|
|
962
|
-
const tree = await buildDirTree(dir ? path.resolve(process.cwd(), dir) : process.cwd(), opts?.ignore);
|
|
963
|
-
console.info("quiteer-script :>>", gray(`\n${tree}\n`));
|
|
964
|
-
if (opts?.md) {
|
|
965
|
-
const out = opts?.output || "DIRECTORY_TREE.md";
|
|
966
|
-
await writeDirTreeMd(tree, out);
|
|
967
|
-
console.info(lightCyan("quiteer-script :>>"), lightGreen(`已生成 Markdown: ${lightBlue(out)}`));
|
|
968
|
-
}
|
|
969
|
-
}
|
|
970
|
-
|
|
971
989
|
//#endregion
|
|
972
990
|
//#region src/index.ts
|
|
973
991
|
async function setupCli() {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@quiteer/scripts",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.10",
|
|
5
5
|
"homepage": "https://taiaiac.github.io/web/ci/scripts.html",
|
|
6
6
|
"publishConfig": {
|
|
7
7
|
"access": "public",
|
|
@@ -49,6 +49,7 @@
|
|
|
49
49
|
"scripts": {
|
|
50
50
|
"dev": "tsdown -w",
|
|
51
51
|
"build": "tsdown",
|
|
52
|
-
"release": "qui r --tag-prefix scripts"
|
|
52
|
+
"release": "qui r --tag-prefix scripts",
|
|
53
|
+
"build:release": "tsdown && pnpm publish"
|
|
53
54
|
}
|
|
54
55
|
}
|