@quiteer/scripts 0.0.7 → 0.0.9
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 +95 -70
- 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.9";
|
|
16
16
|
|
|
17
17
|
//#endregion
|
|
18
18
|
//#region src/locales/changelog.ts
|
|
@@ -445,6 +445,74 @@ async function cleanup(paths) {
|
|
|
445
445
|
await rimraf(paths, { glob: true });
|
|
446
446
|
}
|
|
447
447
|
|
|
448
|
+
//#endregion
|
|
449
|
+
//#region src/commands/dir-tree.ts
|
|
450
|
+
/**
|
|
451
|
+
* 生成目录树结构字符串(ASCII Tree)
|
|
452
|
+
* - 默认忽略常见目录:node_modules、.git、dist、out、logs
|
|
453
|
+
* @param root 起始目录,默认为当前工作目录
|
|
454
|
+
* @returns 目录树字符串
|
|
455
|
+
*/
|
|
456
|
+
async function buildDirTree(root = process.cwd(), ignoreList) {
|
|
457
|
+
const ignore = new Set(ignoreList ?? [
|
|
458
|
+
"node_modules",
|
|
459
|
+
".git",
|
|
460
|
+
"dist",
|
|
461
|
+
"out",
|
|
462
|
+
"logs"
|
|
463
|
+
]);
|
|
464
|
+
async function walk(dir, prefix = "") {
|
|
465
|
+
const items = (await readdir(dir, { withFileTypes: true })).filter((e) => !ignore.has(e.name)).map((e) => ({
|
|
466
|
+
name: e.name,
|
|
467
|
+
isDir: e.isDirectory()
|
|
468
|
+
})).sort((a, b) => a.isDir === b.isDir ? a.name.localeCompare(b.name) : a.isDir ? -1 : 1);
|
|
469
|
+
const lines = [];
|
|
470
|
+
const lastIdx = items.length - 1;
|
|
471
|
+
for (let i = 0; i < items.length; i++) {
|
|
472
|
+
const it = items[i];
|
|
473
|
+
const isLast = i === lastIdx;
|
|
474
|
+
const connector = isLast ? "└── " : "├── ";
|
|
475
|
+
const nextPrefix = prefix + (isLast ? " " : "│ ");
|
|
476
|
+
lines.push(`${prefix}${connector}${it.name}`);
|
|
477
|
+
if (it.isDir) {
|
|
478
|
+
const sub = await walk(path.join(dir, it.name), nextPrefix);
|
|
479
|
+
lines.push(...sub);
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
return lines;
|
|
483
|
+
}
|
|
484
|
+
const title = path.basename(root);
|
|
485
|
+
const content = await walk(root);
|
|
486
|
+
return [`|-- ${title}`, ...content].join("\n");
|
|
487
|
+
}
|
|
488
|
+
/**
|
|
489
|
+
* 根据目录树内容生成 Markdown 并写入文件
|
|
490
|
+
* - 使用代码块包裹,便于阅读
|
|
491
|
+
* @param tree 目录树字符串
|
|
492
|
+
* @param outfile 输出文件路径,默认 `DIRECTORY_TREE.md`
|
|
493
|
+
*/
|
|
494
|
+
async function writeDirTreeMd(tree, outfile = "DIRECTORY_TREE.md") {
|
|
495
|
+
const md = `## 目录结构
|
|
496
|
+
|
|
497
|
+
\`\`\`text\n${tree}\n\`\`\`\n`;
|
|
498
|
+
await writeFile(path.join(process.cwd(), outfile), md, "utf8");
|
|
499
|
+
}
|
|
500
|
+
/**
|
|
501
|
+
* 生成并输出目录结构,支持可选生成 Markdown 文件
|
|
502
|
+
* - 默认只在控制台输出
|
|
503
|
+
* @param dir 目标目录,默认当前工作目录
|
|
504
|
+
* @param md 是否生成 Markdown 文件,默认 false
|
|
505
|
+
*/
|
|
506
|
+
async function generateDirTree(dir, opts) {
|
|
507
|
+
const tree = await buildDirTree(dir ? path.resolve(process.cwd(), dir) : process.cwd(), opts?.ignore);
|
|
508
|
+
console.info("quiteer-script :>>", gray(`\n${tree}\n`));
|
|
509
|
+
if (opts?.md) {
|
|
510
|
+
const out = opts?.output || "DIRECTORY_TREE.md";
|
|
511
|
+
await writeDirTreeMd(tree, out);
|
|
512
|
+
console.info(lightCyan("quiteer-script :>>"), lightGreen(`已生成 Markdown: ${lightBlue(out)}`));
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
|
|
448
516
|
//#endregion
|
|
449
517
|
//#region src/config/index.ts
|
|
450
518
|
const defaultOptions = {
|
|
@@ -850,6 +918,21 @@ async function release(tagPrefix) {
|
|
|
850
918
|
//#endregion
|
|
851
919
|
//#region src/commands/self-update.ts
|
|
852
920
|
/**
|
|
921
|
+
* 获取当前命令来源路径(本地 node_modules/.bin 或全局)
|
|
922
|
+
* @returns 可执行文件路径(若无法获取返回空字符串)
|
|
923
|
+
*/
|
|
924
|
+
async function getCurrentBinPath() {
|
|
925
|
+
try {
|
|
926
|
+
const p = await execCommand("command", ["-v", "qui"]);
|
|
927
|
+
if (p) return p;
|
|
928
|
+
} catch {}
|
|
929
|
+
try {
|
|
930
|
+
return await execCommand("which", ["qui"]);
|
|
931
|
+
} catch {
|
|
932
|
+
return "";
|
|
933
|
+
}
|
|
934
|
+
}
|
|
935
|
+
/**
|
|
853
936
|
* 检查 @quiteer/scripts 是否有新版本并提示更新
|
|
854
937
|
* - 启动任意命令时调用,仅提示不执行安装
|
|
855
938
|
*/
|
|
@@ -860,7 +943,12 @@ async function checkUpdateAndNotify() {
|
|
|
860
943
|
"@quiteer/scripts",
|
|
861
944
|
"version"
|
|
862
945
|
]);
|
|
863
|
-
|
|
946
|
+
const binPath = await getCurrentBinPath();
|
|
947
|
+
const isLocal = binPath.includes("node_modules/.bin");
|
|
948
|
+
if (latest && latest !== version) {
|
|
949
|
+
console.info("quiteer-script :>> ", lightCyan(`检测到新版本 ${lightGreen(latest)},当前版本 ${lightBlue(version)},建议执行 ${bgGreen(white("qui su"))} 进行更新`));
|
|
950
|
+
if (isLocal) console.info("quiteer-script :>> ", lightBlue(`当前正在使用本地工作区命令:${binPath}`));
|
|
951
|
+
}
|
|
864
952
|
} catch {}
|
|
865
953
|
}
|
|
866
954
|
/**
|
|
@@ -889,6 +977,11 @@ async function selfUpdate() {
|
|
|
889
977
|
`@quiteer/scripts@${latest}`
|
|
890
978
|
], { stdio: "inherit" });
|
|
891
979
|
console.info("quiteer-script :>> ", lightGreen("更新完成,请重新运行命令"));
|
|
980
|
+
if ((await getCurrentBinPath()).includes("node_modules/.bin")) {
|
|
981
|
+
console.info("quiteer-script :>> ", lightBlue("当前命令来源于本地工作区,如需使用全局最新版本:"));
|
|
982
|
+
console.info("quiteer-script :>> ", lightBlue("1) 退出当前仓库目录后执行 `qui`"));
|
|
983
|
+
console.info("quiteer-script :>> ", lightBlue("2) 或使用临时执行:`pnpm dlx @quiteer/scripts <command>`"));
|
|
984
|
+
}
|
|
892
985
|
} catch (e) {
|
|
893
986
|
console.info("quiteer-script :>> ", lightBlue(`更新失败:${e?.message || "未知错误"}`));
|
|
894
987
|
}
|
|
@@ -900,74 +993,6 @@ async function updatePkg(args = ["--deep", "-u"]) {
|
|
|
900
993
|
execCommand("npx", ["npm-check-updates", ...args], { stdio: "inherit" });
|
|
901
994
|
}
|
|
902
995
|
|
|
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
996
|
//#endregion
|
|
972
997
|
//#region src/index.ts
|
|
973
998
|
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.9",
|
|
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
|
}
|