@tnotesjs/core 0.1.9 → 0.1.11
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/README.md +3 -3
- package/dist/{chunk-DT6HO7XD.js → chunk-4WE4NND3.js} +49 -371
- package/dist/cli/index.js +6 -241
- package/dist/vitepress/config/index.js +1 -1
- package/package.json +1 -1
- package/types/shims.d.ts +10 -0
package/README.md
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
#
|
|
1
|
+
# tnotesjs/core
|
|
2
2
|
|
|
3
3
|
TNotes 知识库系统的核心共享脚本,通过 Git Submodule 被所有 [TNotes.xxx](https://github.com/orgs/tnotesjs/repositories) 知识库引用。
|
|
4
4
|
|
|
5
5
|
## 简介
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
tnotesjs/core 包含了 TNotes 知识库系统的 CLI 命令、VitePress 主题/插件、服务层、工具函数等核心代码。各 TNotes.xxx 仓库不再各自拷贝脚本,而是统一以 Git Submodule 的形式引用本仓库,挂载到 `.vitepress/tnotes/` 路径下。
|
|
8
8
|
|
|
9
9
|
## 目录结构
|
|
10
10
|
|
|
11
11
|
```
|
|
12
|
-
|
|
12
|
+
tnotesjs/core/
|
|
13
13
|
├── commands/ # CLI 命令(dev、build、push、update 等)
|
|
14
14
|
├── config/ # 配置管理(ConfigManager、默认配置、模板)
|
|
15
15
|
├── core/ # 核心模块(GitManager、NoteManager、ReadmeGenerator 等)
|
|
@@ -14,8 +14,6 @@ var COMMAND_NAMES = {
|
|
|
14
14
|
PULL: "pull",
|
|
15
15
|
PUSH: "push",
|
|
16
16
|
RENAME_NOTE: "rename-note",
|
|
17
|
-
SYNC_CORE: "sync-core",
|
|
18
|
-
SYNC: "sync",
|
|
19
17
|
UPDATE: "update",
|
|
20
18
|
UPDATE_COMPLETED_COUNT: "update-completed-count",
|
|
21
19
|
UPDATE_NOTE_CONFIG: "update-note-config"
|
|
@@ -27,17 +25,14 @@ var COMMAND_DESCRIPTIONS = {
|
|
|
27
25
|
[COMMAND_NAMES.UPDATE]: "\u6839\u636E\u7B14\u8BB0\u5185\u5BB9\u66F4\u65B0\u77E5\u8BC6\u5E93",
|
|
28
26
|
[COMMAND_NAMES.UPDATE_COMPLETED_COUNT]: "\u66F4\u65B0\u5B8C\u6210\u7B14\u8BB0\u6570\u91CF\u5386\u53F2\u8BB0\u5F55\uFF08\u8FD1 1 \u5E74\uFF0C\u6700\u8FD1 12 \u4E2A\u6708\uFF09",
|
|
29
27
|
[COMMAND_NAMES.CREATE_NOTES]: "\u65B0\u5EFA\u7B14\u8BB0\uFF08\u652F\u6301\u6279\u91CF\u521B\u5EFA\uFF09",
|
|
30
|
-
[COMMAND_NAMES.PUSH]: "\u5C06\u77E5\u8BC6\u5E93\u63A8\u9001\u5230 GitHub
|
|
31
|
-
[COMMAND_NAMES.PULL]: "\u5C06 GitHub \u7684\u77E5\u8BC6\u5E93\u62C9\u4E0B\u6765
|
|
32
|
-
[COMMAND_NAMES.SYNC]: "\u540C\u6B65\u672C\u5730\u548C\u8FDC\u7A0B\u7684\u77E5\u8BC6\u5E93\u72B6\u6001 (\u4F7F\u7528 --all \u540C\u6B65\u6240\u6709\u77E5\u8BC6\u5E93)",
|
|
33
|
-
[COMMAND_NAMES.SYNC_CORE]: "\u540C\u6B65\u6240\u6709\u5144\u5F1F\u77E5\u8BC6\u5E93\u7684 tnotesjs/core \u5230\u6700\u65B0\u7248\u672C",
|
|
28
|
+
[COMMAND_NAMES.PUSH]: "\u5C06\u77E5\u8BC6\u5E93\u63A8\u9001\u5230 GitHub",
|
|
29
|
+
[COMMAND_NAMES.PULL]: "\u5C06 GitHub \u7684\u77E5\u8BC6\u5E93\u62C9\u4E0B\u6765",
|
|
34
30
|
[COMMAND_NAMES.FIX_TIMESTAMPS]: "\u4FEE\u590D\u6240\u6709\u7B14\u8BB0\u7684\u65F6\u95F4\u6233\uFF08\u57FA\u4E8E git \u5386\u53F2\uFF09",
|
|
35
31
|
[COMMAND_NAMES.UPDATE_NOTE_CONFIG]: "\u66F4\u65B0\u7B14\u8BB0\u914D\u7F6E\u6587\u4EF6",
|
|
36
32
|
[COMMAND_NAMES.RENAME_NOTE]: "\u91CD\u547D\u540D\u7B14\u8BB0",
|
|
37
33
|
[COMMAND_NAMES.HELP]: "\u663E\u793A\u5E2E\u52A9\u4FE1\u606F"
|
|
38
34
|
};
|
|
39
35
|
var COMMAND_OPTIONS = {
|
|
40
|
-
ALL: "all",
|
|
41
36
|
QUIET: "quiet",
|
|
42
37
|
FORCE: "force"
|
|
43
38
|
};
|
|
@@ -419,21 +414,6 @@ function getChangedIds() {
|
|
|
419
414
|
return new Set(changedIds);
|
|
420
415
|
}
|
|
421
416
|
|
|
422
|
-
// utils/getTargetDirs.ts
|
|
423
|
-
import { readdirSync } from "fs";
|
|
424
|
-
import { join } from "path";
|
|
425
|
-
var getTargetDirs = (baseDir, prefix, excludeDirs = []) => {
|
|
426
|
-
try {
|
|
427
|
-
const entries = readdirSync(baseDir, { withFileTypes: true });
|
|
428
|
-
const targetDirs = entries.filter((entry) => entry.isDirectory() && entry.name.startsWith(prefix)).map((entry) => join(baseDir, entry.name)).filter((dir) => !excludeDirs.includes(dir));
|
|
429
|
-
return targetDirs;
|
|
430
|
-
} catch (error) {
|
|
431
|
-
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
432
|
-
console.error(`\u8BFB\u53D6\u76EE\u5F55 ${baseDir} \u65F6\u51FA\u9519\uFF1A${errorMessage}`);
|
|
433
|
-
return [];
|
|
434
|
-
}
|
|
435
|
-
};
|
|
436
|
-
|
|
437
417
|
// utils/markdown.ts
|
|
438
418
|
function createAddNumberToTitle() {
|
|
439
419
|
const titleNumbers = Array(7).fill(0);
|
|
@@ -595,8 +575,8 @@ async function waitForPort(port2, timeout = 5e3) {
|
|
|
595
575
|
}
|
|
596
576
|
|
|
597
577
|
// core/NoteManager.ts
|
|
598
|
-
import { existsSync, readFileSync, readdirSync
|
|
599
|
-
import { join
|
|
578
|
+
import { existsSync, readFileSync, readdirSync, writeFileSync } from "fs";
|
|
579
|
+
import { join } from "path";
|
|
600
580
|
|
|
601
581
|
// config/constants.ts
|
|
602
582
|
import { resolve } from "path";
|
|
@@ -613,9 +593,6 @@ var {
|
|
|
613
593
|
root_item
|
|
614
594
|
} = config;
|
|
615
595
|
var rootPath = configManager.getRootPath();
|
|
616
|
-
var TNOTES_BASE_DIR = resolve(rootPath, "..");
|
|
617
|
-
var TNOTES_CORE_DIR = resolve(TNOTES_BASE_DIR, "TNotes.core");
|
|
618
|
-
var EN_WORDS_DIR = resolve(TNOTES_BASE_DIR, "TNotes.en-words");
|
|
619
596
|
var ROOT_DIR_PATH = rootPath;
|
|
620
597
|
var ROOT_README_PATH = resolve(ROOT_DIR_PATH, "README.md");
|
|
621
598
|
var ROOT_CONFIG_PATH = resolve(ROOT_DIR_PATH, ".tnotes.json");
|
|
@@ -722,7 +699,7 @@ var NoteManager = class _NoteManager {
|
|
|
722
699
|
*/
|
|
723
700
|
getNoteDirs() {
|
|
724
701
|
if (!existsSync(NOTES_PATH)) return [];
|
|
725
|
-
return
|
|
702
|
+
return readdirSync(NOTES_PATH, { withFileTypes: true }).filter(
|
|
726
703
|
(entry) => entry.isDirectory() && !entry.name.startsWith(".") && _NoteManager.NOTE_INDEX_REGEX.test(entry.name)
|
|
727
704
|
).map((entry) => entry.name).sort();
|
|
728
705
|
}
|
|
@@ -731,9 +708,9 @@ var NoteManager = class _NoteManager {
|
|
|
731
708
|
* @returns NoteInfo 或 undefined(README 不存在时)
|
|
732
709
|
*/
|
|
733
710
|
buildNoteInfo(dirName) {
|
|
734
|
-
const notePath =
|
|
735
|
-
const readmePath =
|
|
736
|
-
const configPath =
|
|
711
|
+
const notePath = join(NOTES_PATH, dirName);
|
|
712
|
+
const readmePath = join(notePath, "README.md");
|
|
713
|
+
const configPath = join(notePath, ".tnotes.json");
|
|
737
714
|
if (!existsSync(readmePath)) {
|
|
738
715
|
logger.warn(`README not found in note: ${dirName}`);
|
|
739
716
|
return void 0;
|
|
@@ -1100,173 +1077,6 @@ async function runCommand(command, dir) {
|
|
|
1100
1077
|
});
|
|
1101
1078
|
}
|
|
1102
1079
|
|
|
1103
|
-
// utils/syncRepo.ts
|
|
1104
|
-
async function pushAllRepos(options) {
|
|
1105
|
-
const {
|
|
1106
|
-
parallel = true,
|
|
1107
|
-
continueOnError = true,
|
|
1108
|
-
force = false
|
|
1109
|
-
} = options || {};
|
|
1110
|
-
const targetDirs = getTargetDirs(TNOTES_BASE_DIR, "TNotes.", [EN_WORDS_DIR, TNOTES_CORE_DIR]);
|
|
1111
|
-
logger.info(`\u6B63\u5728\u63A8\u9001 ${targetDirs.length} \u4E2A\u4ED3\u5E93...`);
|
|
1112
|
-
if (force) {
|
|
1113
|
-
logger.warn("\u4F7F\u7528\u5F3A\u5236\u63A8\u9001\u6A21\u5F0F");
|
|
1114
|
-
}
|
|
1115
|
-
const results = [];
|
|
1116
|
-
const pushCmd = force ? "pnpm tn:push --force" : "pnpm tn:push";
|
|
1117
|
-
if (parallel) {
|
|
1118
|
-
const promises = targetDirs.map(async (dir, index) => {
|
|
1119
|
-
try {
|
|
1120
|
-
await runCommand(pushCmd, dir);
|
|
1121
|
-
process.stdout.write(`\r \u8FDB\u5EA6: ~${index + 1}/${targetDirs.length}`);
|
|
1122
|
-
return { dir, success: true };
|
|
1123
|
-
} catch (error) {
|
|
1124
|
-
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
1125
|
-
return { dir, success: false, error: errorMessage };
|
|
1126
|
-
}
|
|
1127
|
-
});
|
|
1128
|
-
results.push(...await Promise.all(promises));
|
|
1129
|
-
console.log();
|
|
1130
|
-
} else {
|
|
1131
|
-
for (let i = 0; i < targetDirs.length; i++) {
|
|
1132
|
-
const dir = targetDirs[i];
|
|
1133
|
-
try {
|
|
1134
|
-
await runCommand(pushCmd, dir);
|
|
1135
|
-
process.stdout.write(`\r \u8FDB\u5EA6: ${i + 1}/${targetDirs.length}`);
|
|
1136
|
-
results.push({ dir, success: true });
|
|
1137
|
-
} catch (error) {
|
|
1138
|
-
process.stdout.write(`\r \u8FDB\u5EA6: ${i + 1}/${targetDirs.length}`);
|
|
1139
|
-
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
1140
|
-
results.push({ dir, success: false, error: errorMessage });
|
|
1141
|
-
if (!continueOnError) {
|
|
1142
|
-
console.log();
|
|
1143
|
-
throw error;
|
|
1144
|
-
}
|
|
1145
|
-
}
|
|
1146
|
-
}
|
|
1147
|
-
console.log();
|
|
1148
|
-
}
|
|
1149
|
-
const successCount = results.filter((r) => r.success).length;
|
|
1150
|
-
const failCount = results.length - successCount;
|
|
1151
|
-
if (failCount === 0) {
|
|
1152
|
-
logger.success(`\u63A8\u9001\u5B8C\u6210: ${successCount}/${results.length} \u4E2A\u4ED3\u5E93\u6210\u529F`);
|
|
1153
|
-
} else {
|
|
1154
|
-
logger.warn(
|
|
1155
|
-
`\u63A8\u9001\u5B8C\u6210: ${successCount} \u6210\u529F, ${failCount} \u5931\u8D25 (\u5171 ${results.length} \u4E2A)`
|
|
1156
|
-
);
|
|
1157
|
-
console.log("\n\u5931\u8D25\u7684\u4ED3\u5E93:");
|
|
1158
|
-
results.filter((r) => !r.success).forEach((r, index) => {
|
|
1159
|
-
const repoName2 = r.dir.split("\\").pop() || r.dir;
|
|
1160
|
-
console.log(` ${index + 1}. ${repoName2}`);
|
|
1161
|
-
console.log(` \u9519\u8BEF: ${r.error}`);
|
|
1162
|
-
});
|
|
1163
|
-
}
|
|
1164
|
-
}
|
|
1165
|
-
async function pullAllRepos(options) {
|
|
1166
|
-
const { parallel = true, continueOnError = true } = options || {};
|
|
1167
|
-
const targetDirs = getTargetDirs(TNOTES_BASE_DIR, "TNotes.", [EN_WORDS_DIR, TNOTES_CORE_DIR]);
|
|
1168
|
-
logger.info(`\u6B63\u5728\u62C9\u53D6 ${targetDirs.length} \u4E2A\u4ED3\u5E93...`);
|
|
1169
|
-
const results = [];
|
|
1170
|
-
if (parallel) {
|
|
1171
|
-
const promises = targetDirs.map(async (dir, index) => {
|
|
1172
|
-
try {
|
|
1173
|
-
await runCommand("pnpm tn:pull", dir);
|
|
1174
|
-
process.stdout.write(`\r \u8FDB\u5EA6: ~${index + 1}/${targetDirs.length}`);
|
|
1175
|
-
return { dir, success: true };
|
|
1176
|
-
} catch (error) {
|
|
1177
|
-
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
1178
|
-
return { dir, success: false, error: errorMessage };
|
|
1179
|
-
}
|
|
1180
|
-
});
|
|
1181
|
-
results.push(...await Promise.all(promises));
|
|
1182
|
-
console.log();
|
|
1183
|
-
} else {
|
|
1184
|
-
for (let i = 0; i < targetDirs.length; i++) {
|
|
1185
|
-
const dir = targetDirs[i];
|
|
1186
|
-
try {
|
|
1187
|
-
await runCommand("pnpm tn:pull", dir);
|
|
1188
|
-
process.stdout.write(`\r \u8FDB\u5EA6: ${i + 1}/${targetDirs.length}`);
|
|
1189
|
-
results.push({ dir, success: true });
|
|
1190
|
-
} catch (error) {
|
|
1191
|
-
process.stdout.write(`\r \u8FDB\u5EA6: ${i + 1}/${targetDirs.length}`);
|
|
1192
|
-
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
1193
|
-
results.push({ dir, success: false, error: errorMessage });
|
|
1194
|
-
if (!continueOnError) {
|
|
1195
|
-
console.log();
|
|
1196
|
-
throw error;
|
|
1197
|
-
}
|
|
1198
|
-
}
|
|
1199
|
-
}
|
|
1200
|
-
console.log();
|
|
1201
|
-
}
|
|
1202
|
-
const successCount = results.filter((r) => r.success).length;
|
|
1203
|
-
const failCount = results.length - successCount;
|
|
1204
|
-
if (failCount === 0) {
|
|
1205
|
-
logger.success(`\u62C9\u53D6\u5B8C\u6210: ${successCount}/${results.length} \u4E2A\u4ED3\u5E93\u6210\u529F`);
|
|
1206
|
-
} else {
|
|
1207
|
-
logger.warn(
|
|
1208
|
-
`\u62C9\u53D6\u5B8C\u6210: ${successCount} \u6210\u529F, ${failCount} \u5931\u8D25 (\u5171 ${results.length} \u4E2A)`
|
|
1209
|
-
);
|
|
1210
|
-
console.log("\n\u5931\u8D25\u7684\u4ED3\u5E93:");
|
|
1211
|
-
results.filter((r) => !r.success).forEach((r, index) => {
|
|
1212
|
-
const repoName2 = r.dir.split("\\").pop() || r.dir;
|
|
1213
|
-
console.log(` ${index + 1}. ${repoName2}`);
|
|
1214
|
-
console.log(` \u9519\u8BEF: ${r.error}`);
|
|
1215
|
-
});
|
|
1216
|
-
}
|
|
1217
|
-
}
|
|
1218
|
-
async function syncAllRepos(options) {
|
|
1219
|
-
const { parallel = true, continueOnError = true } = options || {};
|
|
1220
|
-
const targetDirs = getTargetDirs(TNOTES_BASE_DIR, "TNotes.", [EN_WORDS_DIR, TNOTES_CORE_DIR]);
|
|
1221
|
-
logger.info(`\u6B63\u5728\u540C\u6B65 ${targetDirs.length} \u4E2A\u4ED3\u5E93...`);
|
|
1222
|
-
const results = [];
|
|
1223
|
-
if (parallel) {
|
|
1224
|
-
const promises = targetDirs.map(async (dir, index) => {
|
|
1225
|
-
try {
|
|
1226
|
-
await runCommand("pnpm tn:sync", dir);
|
|
1227
|
-
process.stdout.write(`\r \u8FDB\u5EA6: ~${index + 1}/${targetDirs.length}`);
|
|
1228
|
-
return { dir, success: true };
|
|
1229
|
-
} catch (error) {
|
|
1230
|
-
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
1231
|
-
return { dir, success: false, error: errorMessage };
|
|
1232
|
-
}
|
|
1233
|
-
});
|
|
1234
|
-
results.push(...await Promise.all(promises));
|
|
1235
|
-
} else {
|
|
1236
|
-
for (let i = 0; i < targetDirs.length; i++) {
|
|
1237
|
-
const dir = targetDirs[i];
|
|
1238
|
-
try {
|
|
1239
|
-
await runCommand("pnpm tn:sync", dir);
|
|
1240
|
-
process.stdout.write(`\r \u8FDB\u5EA6: ${i + 1}/${targetDirs.length}`);
|
|
1241
|
-
results.push({ dir, success: true });
|
|
1242
|
-
} catch (error) {
|
|
1243
|
-
process.stdout.write(`\r \u8FDB\u5EA6: ${i + 1}/${targetDirs.length}`);
|
|
1244
|
-
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
1245
|
-
results.push({ dir, success: false, error: errorMessage });
|
|
1246
|
-
if (!continueOnError) {
|
|
1247
|
-
throw error;
|
|
1248
|
-
}
|
|
1249
|
-
}
|
|
1250
|
-
}
|
|
1251
|
-
}
|
|
1252
|
-
console.log();
|
|
1253
|
-
const successCount = results.filter((r) => r.success).length;
|
|
1254
|
-
const failCount = results.length - successCount;
|
|
1255
|
-
if (failCount === 0) {
|
|
1256
|
-
logger.success(`\u540C\u6B65\u5B8C\u6210: ${successCount}/${results.length} \u4E2A\u4ED3\u5E93\u6210\u529F`);
|
|
1257
|
-
} else {
|
|
1258
|
-
logger.warn(
|
|
1259
|
-
`\u540C\u6B65\u5B8C\u6210: ${successCount} \u6210\u529F, ${failCount} \u5931\u8D25 (\u5171 ${results.length} \u4E2A)`
|
|
1260
|
-
);
|
|
1261
|
-
console.log("\n\u5931\u8D25\u7684\u4ED3\u5E93:");
|
|
1262
|
-
results.filter((r) => !r.success).forEach((r, index) => {
|
|
1263
|
-
const repoName2 = r.dir.split("\\").pop() || r.dir;
|
|
1264
|
-
console.log(` ${index + 1}. ${repoName2}`);
|
|
1265
|
-
console.log(` \u9519\u8BEF: ${r.error}`);
|
|
1266
|
-
});
|
|
1267
|
-
}
|
|
1268
|
-
}
|
|
1269
|
-
|
|
1270
1080
|
// utils/validators.ts
|
|
1271
1081
|
var INVALID_FILENAME_CHARS = /[<>:"/\\|?*\x00-\x1F]/;
|
|
1272
1082
|
var WINDOWS_RESERVED_NAMES = /* @__PURE__ */ new Set([
|
|
@@ -1331,7 +1141,7 @@ function validateNoteTitle(title) {
|
|
|
1331
1141
|
}
|
|
1332
1142
|
|
|
1333
1143
|
// core/NoteIndexCache.ts
|
|
1334
|
-
import { join as
|
|
1144
|
+
import { join as join2 } from "path";
|
|
1335
1145
|
var NoteIndexCache = class _NoteIndexCache {
|
|
1336
1146
|
static instance = null;
|
|
1337
1147
|
/** noteIndex -> NoteIndexItem 的映射 */
|
|
@@ -1382,13 +1192,13 @@ var NoteIndexCache = class _NoteIndexCache {
|
|
|
1382
1192
|
toNoteInfoList() {
|
|
1383
1193
|
const result = [];
|
|
1384
1194
|
for (const item of this.byNoteIndex.values()) {
|
|
1385
|
-
const notePath =
|
|
1195
|
+
const notePath = join2(NOTES_PATH, item.folderName);
|
|
1386
1196
|
result.push({
|
|
1387
1197
|
index: item.noteIndex,
|
|
1388
1198
|
path: notePath,
|
|
1389
1199
|
dirName: item.folderName,
|
|
1390
|
-
readmePath:
|
|
1391
|
-
configPath:
|
|
1200
|
+
readmePath: join2(notePath, "README.md"),
|
|
1201
|
+
configPath: join2(notePath, ".tnotes.json"),
|
|
1392
1202
|
config: item.noteConfig
|
|
1393
1203
|
});
|
|
1394
1204
|
}
|
|
@@ -2295,9 +2105,9 @@ async function safeExecute(label, fn, logger2) {
|
|
|
2295
2105
|
}
|
|
2296
2106
|
|
|
2297
2107
|
// services/file-watcher/watchState.ts
|
|
2298
|
-
import { existsSync as existsSync3, readFileSync as readFileSync3, readdirSync as
|
|
2108
|
+
import { existsSync as existsSync3, readFileSync as readFileSync3, readdirSync as readdirSync2, statSync } from "fs";
|
|
2299
2109
|
import { createHash } from "crypto";
|
|
2300
|
-
import { join as
|
|
2110
|
+
import { join as join3 } from "path";
|
|
2301
2111
|
var WatchState = class {
|
|
2302
2112
|
constructor(config2) {
|
|
2303
2113
|
this.config = config2;
|
|
@@ -2377,8 +2187,8 @@ var WatchState = class {
|
|
|
2377
2187
|
* @param noteDirName 笔记目录名称
|
|
2378
2188
|
*/
|
|
2379
2189
|
clearNoteCaches(noteDirName) {
|
|
2380
|
-
const readmePath =
|
|
2381
|
-
const configPath =
|
|
2190
|
+
const readmePath = join3(this.config.notesDir, noteDirName, "README.md");
|
|
2191
|
+
const configPath = join3(this.config.notesDir, noteDirName, ".tnotes.json");
|
|
2382
2192
|
this.fileHashes.delete(readmePath);
|
|
2383
2193
|
this.fileHashes.delete(configPath);
|
|
2384
2194
|
this.configCache.delete(configPath);
|
|
@@ -2431,16 +2241,16 @@ var WatchState = class {
|
|
|
2431
2241
|
*/
|
|
2432
2242
|
initializeFromDisk() {
|
|
2433
2243
|
try {
|
|
2434
|
-
const noteDirs =
|
|
2244
|
+
const noteDirs = readdirSync2(this.config.notesDir);
|
|
2435
2245
|
this.clearAll();
|
|
2436
2246
|
for (const noteDir of noteDirs) {
|
|
2437
|
-
const noteDirPath =
|
|
2247
|
+
const noteDirPath = join3(this.config.notesDir, noteDir);
|
|
2438
2248
|
if (!statSync(noteDirPath).isDirectory()) continue;
|
|
2439
2249
|
this.noteDirCache.add(noteDir);
|
|
2440
|
-
const readmePath =
|
|
2250
|
+
const readmePath = join3(noteDirPath, "README.md");
|
|
2441
2251
|
const readmeHash = this.getFileHash(readmePath);
|
|
2442
2252
|
if (readmeHash) this.fileHashes.set(readmePath, readmeHash);
|
|
2443
|
-
const configPath =
|
|
2253
|
+
const configPath = join3(noteDirPath, ".tnotes.json");
|
|
2444
2254
|
const configHash = this.getFileHash(configPath);
|
|
2445
2255
|
if (configHash) {
|
|
2446
2256
|
this.fileHashes.set(configPath, configHash);
|
|
@@ -2580,7 +2390,7 @@ var EventScheduler = class {
|
|
|
2580
2390
|
|
|
2581
2391
|
// services/file-watcher/renameDetector.ts
|
|
2582
2392
|
import { existsSync as existsSync4 } from "fs";
|
|
2583
|
-
import { join as
|
|
2393
|
+
import { join as join4 } from "path";
|
|
2584
2394
|
var FOLDER_RENAME_DETECT_WINDOW_MS = 500;
|
|
2585
2395
|
var RenameDetector = class {
|
|
2586
2396
|
constructor(config2) {
|
|
@@ -2592,7 +2402,7 @@ var RenameDetector = class {
|
|
|
2592
2402
|
folderRenameTimer = null;
|
|
2593
2403
|
handleFsRename(folderName) {
|
|
2594
2404
|
const { notesDir, dirCache, logger: logger2, onDelete, onRename } = this.config;
|
|
2595
|
-
const folderPath =
|
|
2405
|
+
const folderPath = join4(notesDir, folderName);
|
|
2596
2406
|
const folderExists = existsSync4(folderPath);
|
|
2597
2407
|
const noteIndex = NoteManager.extractNoteIndex(folderName);
|
|
2598
2408
|
if (!noteIndex) {
|
|
@@ -2731,7 +2541,7 @@ var GlobalUpdateCoordinator = class {
|
|
|
2731
2541
|
|
|
2732
2542
|
// services/file-watcher/folderChangeHandler.ts
|
|
2733
2543
|
import { existsSync as existsSync5, promises as fsPromises } from "fs";
|
|
2734
|
-
import { join as
|
|
2544
|
+
import { join as join5 } from "path";
|
|
2735
2545
|
var RENAME_REVERT_DELAY_MS = 2e3;
|
|
2736
2546
|
var DELETE_REINIT_DELAY_MS = 1e3;
|
|
2737
2547
|
var UPDATE_UNLOCK_DELAY_MS = 500;
|
|
@@ -2865,8 +2675,8 @@ var FolderChangeHandler = class {
|
|
|
2865
2675
|
async revertFolderRename(oldName, newName) {
|
|
2866
2676
|
const { notesDir, scheduler, watchState, logger: logger2 } = this.config;
|
|
2867
2677
|
try {
|
|
2868
|
-
const oldPath =
|
|
2869
|
-
const newPath =
|
|
2678
|
+
const oldPath = join5(notesDir, oldName);
|
|
2679
|
+
const newPath = join5(notesDir, newName);
|
|
2870
2680
|
if (existsSync5(newPath)) {
|
|
2871
2681
|
scheduler.setUpdating(true);
|
|
2872
2682
|
await fsPromises.rename(newPath, oldPath);
|
|
@@ -2892,7 +2702,7 @@ var FolderChangeHandler = class {
|
|
|
2892
2702
|
|
|
2893
2703
|
// services/file-watcher/fsWatcherAdapter.ts
|
|
2894
2704
|
import { watch } from "fs";
|
|
2895
|
-
import { basename, dirname, join as
|
|
2705
|
+
import { basename, dirname, join as join6, sep } from "path";
|
|
2896
2706
|
var FsWatcherAdapter = class {
|
|
2897
2707
|
constructor(config2) {
|
|
2898
2708
|
this.config = config2;
|
|
@@ -2935,7 +2745,7 @@ var FsWatcherAdapter = class {
|
|
|
2935
2745
|
if (baseFilename !== "README.md" && baseFilename !== ".tnotes.json") {
|
|
2936
2746
|
return;
|
|
2937
2747
|
}
|
|
2938
|
-
const fullPath =
|
|
2748
|
+
const fullPath = join6(this.config.notesDir, filename);
|
|
2939
2749
|
const event = this.buildWatchEvent(fullPath, filename);
|
|
2940
2750
|
if (!event) {
|
|
2941
2751
|
return;
|
|
@@ -3283,7 +3093,7 @@ var ReadmeService = class _ReadmeService {
|
|
|
3283
3093
|
|
|
3284
3094
|
// services/note/service.ts
|
|
3285
3095
|
import { writeFileSync as writeFileSync4, readFileSync as readFileSync5 } from "fs";
|
|
3286
|
-
import { join as
|
|
3096
|
+
import { join as join7 } from "path";
|
|
3287
3097
|
import { v4 as uuidv4 } from "uuid";
|
|
3288
3098
|
|
|
3289
3099
|
// config/templates.ts
|
|
@@ -3378,13 +3188,13 @@ var NoteService = class _NoteService {
|
|
|
3378
3188
|
} = options;
|
|
3379
3189
|
const noteIndex = this.generateNextNoteIndex(usedIndexes);
|
|
3380
3190
|
const dirName = `${noteIndex}. ${title}`;
|
|
3381
|
-
const notePath =
|
|
3191
|
+
const notePath = join7(NOTES_PATH, dirName);
|
|
3382
3192
|
await ensureDirectory(notePath);
|
|
3383
|
-
const readmePath =
|
|
3193
|
+
const readmePath = join7(notePath, "README.md");
|
|
3384
3194
|
const noteTitle = generateNoteTitle(noteIndex, title, REPO_NOTES_URL);
|
|
3385
3195
|
const readmeContent = noteTitle + "\n" + NEW_NOTES_README_MD_TEMPLATE;
|
|
3386
3196
|
writeFileSync4(readmePath, readmeContent, "utf-8");
|
|
3387
|
-
const configPath =
|
|
3197
|
+
const configPath = join7(notePath, ".tnotes.json");
|
|
3388
3198
|
const now = Date.now();
|
|
3389
3199
|
const config2 = {
|
|
3390
3200
|
id: configId || uuidv4(),
|
|
@@ -3795,139 +3605,15 @@ var GitService = class {
|
|
|
3795
3605
|
}
|
|
3796
3606
|
};
|
|
3797
3607
|
|
|
3798
|
-
// services/sync-core/service.ts
|
|
3799
|
-
import { existsSync as existsSync7 } from "fs";
|
|
3800
|
-
import { join as join9, basename as basename2 } from "path";
|
|
3801
|
-
var SyncCoreService = class {
|
|
3802
|
-
/**
|
|
3803
|
-
* 同步单个仓库的 submodule 到最新版本
|
|
3804
|
-
*/
|
|
3805
|
-
async syncSingleRepo(targetDir) {
|
|
3806
|
-
const repoName2 = basename2(targetDir);
|
|
3807
|
-
const submodulePath = join9(targetDir, ".vitepress", "tnotes");
|
|
3808
|
-
try {
|
|
3809
|
-
if (!existsSync7(join9(targetDir, ".gitmodules"))) {
|
|
3810
|
-
return {
|
|
3811
|
-
dir: targetDir,
|
|
3812
|
-
repoName: repoName2,
|
|
3813
|
-
success: false,
|
|
3814
|
-
updated: false,
|
|
3815
|
-
error: "\u672A\u627E\u5230 .gitmodules\uFF0C\u8BE5\u4ED3\u5E93\u672A\u914D\u7F6E submodule"
|
|
3816
|
-
};
|
|
3817
|
-
}
|
|
3818
|
-
if (!existsSync7(submodulePath)) {
|
|
3819
|
-
await runCommand("git submodule update --init", targetDir);
|
|
3820
|
-
}
|
|
3821
|
-
const beforeHash = (await runCommand("git rev-parse HEAD", submodulePath)).trim();
|
|
3822
|
-
const beforeTime = (await runCommand("git log -1 --format=%ci HEAD", submodulePath)).trim().replace(/ [+-]\d{4}$/, "");
|
|
3823
|
-
await runCommand("git fetch origin", submodulePath);
|
|
3824
|
-
await runCommand("git reset --hard origin/main", submodulePath);
|
|
3825
|
-
const afterHash = (await runCommand("git rev-parse HEAD", submodulePath)).trim();
|
|
3826
|
-
const afterTime = (await runCommand("git log -1 --format=%ci HEAD", submodulePath)).trim().replace(/ [+-]\d{4}$/, "");
|
|
3827
|
-
const updated = beforeHash !== afterHash;
|
|
3828
|
-
if (updated) {
|
|
3829
|
-
await runCommand("git add .vitepress/tnotes", targetDir);
|
|
3830
|
-
await runCommand(
|
|
3831
|
-
'git commit -m "chore: update tnotesjs/core"',
|
|
3832
|
-
targetDir
|
|
3833
|
-
);
|
|
3834
|
-
}
|
|
3835
|
-
return {
|
|
3836
|
-
dir: targetDir,
|
|
3837
|
-
repoName: repoName2,
|
|
3838
|
-
success: true,
|
|
3839
|
-
updated,
|
|
3840
|
-
beforeHash: beforeHash.substring(0, 7),
|
|
3841
|
-
beforeTime,
|
|
3842
|
-
afterHash: afterHash.substring(0, 7),
|
|
3843
|
-
afterTime
|
|
3844
|
-
};
|
|
3845
|
-
} catch (error) {
|
|
3846
|
-
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
3847
|
-
return {
|
|
3848
|
-
dir: targetDir,
|
|
3849
|
-
repoName: repoName2,
|
|
3850
|
-
success: false,
|
|
3851
|
-
updated: false,
|
|
3852
|
-
error: errorMessage
|
|
3853
|
-
};
|
|
3854
|
-
}
|
|
3855
|
-
}
|
|
3856
|
-
/**
|
|
3857
|
-
* 同步所有兄弟仓库的 tnotesjs/core 到最新版本
|
|
3858
|
-
*/
|
|
3859
|
-
async syncToAllRepos() {
|
|
3860
|
-
try {
|
|
3861
|
-
const targetDirs = getTargetDirs(TNOTES_BASE_DIR, "TNotes.", [
|
|
3862
|
-
ROOT_DIR_PATH,
|
|
3863
|
-
TNOTES_CORE_DIR,
|
|
3864
|
-
EN_WORDS_DIR
|
|
3865
|
-
]);
|
|
3866
|
-
if (targetDirs.length === 0) {
|
|
3867
|
-
logger.warn("\u672A\u627E\u5230\u7B26\u5408\u6761\u4EF6\u7684\u76EE\u6807\u76EE\u5F55");
|
|
3868
|
-
return;
|
|
3869
|
-
}
|
|
3870
|
-
logger.info(`\u6B63\u5728\u540C\u6B65 ${targetDirs.length} \u4E2A\u4ED3\u5E93\u7684 tnotesjs/core...`);
|
|
3871
|
-
console.log();
|
|
3872
|
-
const results = [];
|
|
3873
|
-
for (let i = 0; i < targetDirs.length; i++) {
|
|
3874
|
-
const dir = targetDirs[i];
|
|
3875
|
-
const repoName2 = basename2(dir);
|
|
3876
|
-
logger.info(`[${i + 1}/${targetDirs.length}] ${repoName2}`);
|
|
3877
|
-
const result = await this.syncSingleRepo(dir);
|
|
3878
|
-
results.push(result);
|
|
3879
|
-
if (result.success) {
|
|
3880
|
-
if (result.updated) {
|
|
3881
|
-
logger.success(
|
|
3882
|
-
` \u2713 \u5DF2\u66F4\u65B0 ${result.beforeHash}(${result.beforeTime}) \u2192 ${result.afterHash}(${result.afterTime})
|
|
3883
|
-
`
|
|
3884
|
-
);
|
|
3885
|
-
} else {
|
|
3886
|
-
logger.info(
|
|
3887
|
-
` - \u5DF2\u662F\u6700\u65B0 ${result.afterHash}(${result.afterTime})
|
|
3888
|
-
`
|
|
3889
|
-
);
|
|
3890
|
-
}
|
|
3891
|
-
} else {
|
|
3892
|
-
logger.error(` \u2717 \u5931\u8D25: ${result.error}
|
|
3893
|
-
`);
|
|
3894
|
-
}
|
|
3895
|
-
}
|
|
3896
|
-
const successCount = results.filter((r) => r.success).length;
|
|
3897
|
-
const updatedCount = results.filter((r) => r.updated).length;
|
|
3898
|
-
const failCount = results.length - successCount;
|
|
3899
|
-
console.log("\u2501".repeat(50));
|
|
3900
|
-
if (failCount === 0) {
|
|
3901
|
-
logger.success(
|
|
3902
|
-
`\u2728 \u540C\u6B65\u5B8C\u6210: ${updatedCount} \u4E2A\u4ED3\u5E93\u5DF2\u66F4\u65B0, ${successCount - updatedCount} \u4E2A\u5DF2\u662F\u6700\u65B0 (\u5171 ${results.length} \u4E2A)`
|
|
3903
|
-
);
|
|
3904
|
-
} else {
|
|
3905
|
-
logger.warn(
|
|
3906
|
-
`\u26A0\uFE0F \u540C\u6B65\u5B8C\u6210: ${successCount} \u6210\u529F (${updatedCount} \u66F4\u65B0), ${failCount} \u5931\u8D25 (\u5171 ${results.length} \u4E2A)`
|
|
3907
|
-
);
|
|
3908
|
-
console.log("\n\u5931\u8D25\u7684\u4ED3\u5E93:");
|
|
3909
|
-
results.filter((r) => !r.success).forEach((r, index) => {
|
|
3910
|
-
console.log(` ${index + 1}. ${r.repoName}`);
|
|
3911
|
-
console.log(` \u9519\u8BEF: ${r.error}`);
|
|
3912
|
-
});
|
|
3913
|
-
}
|
|
3914
|
-
} catch (error) {
|
|
3915
|
-
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
3916
|
-
logger.error(`tnotesjs/core \u540C\u6B65\u5931\u8D25: ${errorMessage}`);
|
|
3917
|
-
throw error;
|
|
3918
|
-
}
|
|
3919
|
-
}
|
|
3920
|
-
};
|
|
3921
|
-
|
|
3922
3608
|
// services/timestamp/service.ts
|
|
3923
3609
|
import {
|
|
3924
|
-
existsSync as
|
|
3610
|
+
existsSync as existsSync7,
|
|
3925
3611
|
readFileSync as readFileSync6,
|
|
3926
3612
|
writeFileSync as writeFileSync5,
|
|
3927
|
-
readdirSync as
|
|
3613
|
+
readdirSync as readdirSync3,
|
|
3928
3614
|
statSync as statSync2
|
|
3929
3615
|
} from "fs";
|
|
3930
|
-
import { join as
|
|
3616
|
+
import { join as join8 } from "path";
|
|
3931
3617
|
import { execSync as execSync3 } from "child_process";
|
|
3932
3618
|
var BIRTH_DATE = (/* @__PURE__ */ new Date("1999-06-29T00:00:00+08:00")).getTime();
|
|
3933
3619
|
var TimestampService = class {
|
|
@@ -3942,7 +3628,7 @@ var TimestampService = class {
|
|
|
3942
3628
|
*/
|
|
3943
3629
|
getGitTimestamps(noteDirPath) {
|
|
3944
3630
|
try {
|
|
3945
|
-
const readmePath =
|
|
3631
|
+
const readmePath = join8(noteDirPath, "README.md");
|
|
3946
3632
|
const createdAtOutput = execSync3(
|
|
3947
3633
|
`git log --diff-filter=A --follow --format=%ct -- "${readmePath}"`,
|
|
3948
3634
|
{
|
|
@@ -3979,14 +3665,14 @@ var TimestampService = class {
|
|
|
3979
3665
|
* @returns 是否进行了修复
|
|
3980
3666
|
*/
|
|
3981
3667
|
fixNoteTimestamps(noteDir, forceUpdate = false) {
|
|
3982
|
-
const configPath =
|
|
3983
|
-
if (!
|
|
3668
|
+
const configPath = join8(NOTES_DIR_PATH, noteDir, ".tnotes.json");
|
|
3669
|
+
if (!existsSync7(configPath)) {
|
|
3984
3670
|
return false;
|
|
3985
3671
|
}
|
|
3986
3672
|
try {
|
|
3987
3673
|
const configContent = readFileSync6(configPath, "utf-8");
|
|
3988
3674
|
const config2 = JSON.parse(configContent);
|
|
3989
|
-
const noteDirPath =
|
|
3675
|
+
const noteDirPath = join8(NOTES_DIR_PATH, noteDir);
|
|
3990
3676
|
const timestamps = this.getGitTimestamps(noteDirPath);
|
|
3991
3677
|
if (!timestamps) {
|
|
3992
3678
|
return false;
|
|
@@ -4085,12 +3771,12 @@ var TimestampService = class {
|
|
|
4085
3771
|
if (rootConfigFixed) {
|
|
4086
3772
|
logger.success("\u2705 \u6839\u914D\u7F6E\u6587\u4EF6\u65F6\u95F4\u6233\u5DF2\u4FEE\u590D");
|
|
4087
3773
|
}
|
|
4088
|
-
if (!
|
|
3774
|
+
if (!existsSync7(NOTES_DIR_PATH)) {
|
|
4089
3775
|
logger.error("notes \u76EE\u5F55\u4E0D\u5B58\u5728");
|
|
4090
3776
|
return { fixed: 0, skipped: 0, total: 0, rootConfigFixed };
|
|
4091
3777
|
}
|
|
4092
|
-
const noteDirs =
|
|
4093
|
-
const fullPath =
|
|
3778
|
+
const noteDirs = readdirSync3(NOTES_DIR_PATH).filter((name) => {
|
|
3779
|
+
const fullPath = join8(NOTES_DIR_PATH, name);
|
|
4094
3780
|
return statSync2(fullPath).isDirectory() && /^\d{4}\./.test(name);
|
|
4095
3781
|
}).sort();
|
|
4096
3782
|
let fixedCount = 0;
|
|
@@ -4127,8 +3813,8 @@ var TimestampService = class {
|
|
|
4127
3813
|
const now = Date.now();
|
|
4128
3814
|
let updatedCount = 0;
|
|
4129
3815
|
for (const noteDir of noteDirNames) {
|
|
4130
|
-
const configPath =
|
|
4131
|
-
if (!
|
|
3816
|
+
const configPath = join8(NOTES_DIR_PATH, noteDir, ".tnotes.json");
|
|
3817
|
+
if (!existsSync7(configPath)) {
|
|
4132
3818
|
continue;
|
|
4133
3819
|
}
|
|
4134
3820
|
try {
|
|
@@ -4418,8 +4104,8 @@ var UpdateNoteConfigCommand = class extends BaseCommand {
|
|
|
4418
4104
|
};
|
|
4419
4105
|
|
|
4420
4106
|
// commands/note/RenameNoteCommand.ts
|
|
4421
|
-
import { existsSync as
|
|
4422
|
-
import { join as
|
|
4107
|
+
import { existsSync as existsSync8, renameSync, readFileSync as readFileSync7, writeFileSync as writeFileSync6 } from "fs";
|
|
4108
|
+
import { join as join9 } from "path";
|
|
4423
4109
|
var RenameNoteCommand = class extends BaseCommand {
|
|
4424
4110
|
noteService;
|
|
4425
4111
|
readmeService;
|
|
@@ -4456,8 +4142,8 @@ var RenameNoteCommand = class extends BaseCommand {
|
|
|
4456
4142
|
throw new Error(validation.error || "\u6807\u9898\u683C\u5F0F\u65E0\u6548");
|
|
4457
4143
|
}
|
|
4458
4144
|
const newDirName = `${noteIndex}. ${newTitle.trim()}`;
|
|
4459
|
-
const newPath =
|
|
4460
|
-
if (
|
|
4145
|
+
const newPath = join9(NOTES_PATH, newDirName);
|
|
4146
|
+
if (existsSync8(newPath)) {
|
|
4461
4147
|
throw new Error(`\u76EE\u6807\u6587\u4EF6\u5939\u5DF2\u5B58\u5728: ${newDirName}`);
|
|
4462
4148
|
}
|
|
4463
4149
|
try {
|
|
@@ -4472,8 +4158,8 @@ var RenameNoteCommand = class extends BaseCommand {
|
|
|
4472
4158
|
}
|
|
4473
4159
|
try {
|
|
4474
4160
|
this.logger.info("\u6B63\u5728\u66F4\u65B0\u7B14\u8BB0\u5185\u90E8\u6807\u9898...");
|
|
4475
|
-
const readmePath =
|
|
4476
|
-
if (
|
|
4161
|
+
const readmePath = join9(newPath, "README.md");
|
|
4162
|
+
if (existsSync8(readmePath)) {
|
|
4477
4163
|
const content = readFileSync7(readmePath, "utf-8");
|
|
4478
4164
|
const lines = content.split("\n");
|
|
4479
4165
|
let h1Index = -1;
|
|
@@ -4517,27 +4203,19 @@ export {
|
|
|
4517
4203
|
COMMAND_OPTIONS,
|
|
4518
4204
|
handleError,
|
|
4519
4205
|
generateAnchor,
|
|
4520
|
-
getTargetDirs,
|
|
4521
4206
|
logger,
|
|
4522
4207
|
createLogger,
|
|
4523
4208
|
parseArgs,
|
|
4524
4209
|
parseReadmeCompletedNotes,
|
|
4525
|
-
TNOTES_BASE_DIR,
|
|
4526
|
-
EN_WORDS_DIR,
|
|
4527
4210
|
ROOT_DIR_PATH,
|
|
4528
4211
|
ROOT_CONFIG_PATH,
|
|
4529
4212
|
NoteManager,
|
|
4530
|
-
runCommand,
|
|
4531
|
-
pushAllRepos,
|
|
4532
|
-
pullAllRepos,
|
|
4533
|
-
syncAllRepos,
|
|
4534
4213
|
BaseCommand,
|
|
4535
4214
|
NoteIndexCache,
|
|
4536
4215
|
ReadmeService,
|
|
4537
4216
|
NoteService,
|
|
4538
4217
|
FileWatcherService,
|
|
4539
4218
|
GitService,
|
|
4540
|
-
SyncCoreService,
|
|
4541
4219
|
TimestampService,
|
|
4542
4220
|
VitepressService,
|
|
4543
4221
|
UpdateNoteConfigCommand,
|
package/dist/cli/index.js
CHANGED
|
@@ -3,7 +3,6 @@ import {
|
|
|
3
3
|
COMMAND_DESCRIPTIONS,
|
|
4
4
|
COMMAND_NAMES,
|
|
5
5
|
COMMAND_OPTIONS,
|
|
6
|
-
EN_WORDS_DIR,
|
|
7
6
|
FileWatcherService,
|
|
8
7
|
GitService,
|
|
9
8
|
NoteIndexCache,
|
|
@@ -13,22 +12,15 @@ import {
|
|
|
13
12
|
ROOT_DIR_PATH,
|
|
14
13
|
ReadmeService,
|
|
15
14
|
RenameNoteCommand,
|
|
16
|
-
SyncCoreService,
|
|
17
|
-
TNOTES_BASE_DIR,
|
|
18
15
|
TimestampService,
|
|
19
16
|
UpdateNoteConfigCommand,
|
|
20
17
|
VitepressService,
|
|
21
18
|
createLogger,
|
|
22
|
-
getTargetDirs,
|
|
23
19
|
handleError,
|
|
24
20
|
logger,
|
|
25
21
|
parseArgs,
|
|
26
|
-
parseReadmeCompletedNotes
|
|
27
|
-
|
|
28
|
-
pushAllRepos,
|
|
29
|
-
runCommand,
|
|
30
|
-
syncAllRepos
|
|
31
|
-
} from "../chunk-DT6HO7XD.js";
|
|
22
|
+
parseReadmeCompletedNotes
|
|
23
|
+
} from "../chunk-4WE4NND3.js";
|
|
32
24
|
import {
|
|
33
25
|
ConfigManager
|
|
34
26
|
} from "../chunk-NASIL5FY.js";
|
|
@@ -40,7 +32,6 @@ var UpdateCommand = class extends BaseCommand {
|
|
|
40
32
|
readmeService;
|
|
41
33
|
noteService;
|
|
42
34
|
quiet = false;
|
|
43
|
-
updateAll = false;
|
|
44
35
|
constructor() {
|
|
45
36
|
super("update");
|
|
46
37
|
this.readmeService = ReadmeService.getInstance();
|
|
@@ -59,18 +50,8 @@ var UpdateCommand = class extends BaseCommand {
|
|
|
59
50
|
logger.setLevel(1 /* INFO */);
|
|
60
51
|
}
|
|
61
52
|
}
|
|
62
|
-
/**
|
|
63
|
-
* 设置是否更新所有知识库
|
|
64
|
-
*/
|
|
65
|
-
setUpdateAll(updateAll) {
|
|
66
|
-
this.updateAll = updateAll;
|
|
67
|
-
}
|
|
68
53
|
async run() {
|
|
69
|
-
|
|
70
|
-
await this.updateAllRepos();
|
|
71
|
-
} else {
|
|
72
|
-
await this.updateCurrentRepo();
|
|
73
|
-
}
|
|
54
|
+
await this.updateCurrentRepo();
|
|
74
55
|
}
|
|
75
56
|
/**
|
|
76
57
|
* 更新当前知识库
|
|
@@ -94,56 +75,6 @@ var UpdateCommand = class extends BaseCommand {
|
|
|
94
75
|
this.logger.success("\u77E5\u8BC6\u5E93\u66F4\u65B0\u5B8C\u6210");
|
|
95
76
|
}
|
|
96
77
|
}
|
|
97
|
-
/**
|
|
98
|
-
* 更新所有知识库
|
|
99
|
-
*/
|
|
100
|
-
async updateAllRepos() {
|
|
101
|
-
try {
|
|
102
|
-
const targetDirs = getTargetDirs(TNOTES_BASE_DIR, "TNotes.", [
|
|
103
|
-
ROOT_DIR_PATH,
|
|
104
|
-
EN_WORDS_DIR
|
|
105
|
-
]);
|
|
106
|
-
if (targetDirs.length === 0) {
|
|
107
|
-
this.logger.warn("\u672A\u627E\u5230\u7B26\u5408\u6761\u4EF6\u7684\u77E5\u8BC6\u5E93");
|
|
108
|
-
return;
|
|
109
|
-
}
|
|
110
|
-
this.logger.info(`\u6B63\u5728\u66F4\u65B0 ${targetDirs.length} \u4E2A\u77E5\u8BC6\u5E93...`);
|
|
111
|
-
let successCount = 0;
|
|
112
|
-
let failCount = 0;
|
|
113
|
-
for (let i = 0; i < targetDirs.length; i++) {
|
|
114
|
-
const dir = targetDirs[i];
|
|
115
|
-
const repoName = dir.split("/").pop() || dir;
|
|
116
|
-
try {
|
|
117
|
-
process.stdout.write(
|
|
118
|
-
`\r [${i + 1}/${targetDirs.length}] \u6B63\u5728\u66F4\u65B0: ${repoName}...`
|
|
119
|
-
);
|
|
120
|
-
await runCommand("pnpm tn:update --quiet", dir);
|
|
121
|
-
successCount++;
|
|
122
|
-
} catch (error) {
|
|
123
|
-
failCount++;
|
|
124
|
-
console.log();
|
|
125
|
-
this.logger.error(
|
|
126
|
-
`\u66F4\u65B0\u5931\u8D25: ${repoName} - ${error instanceof Error ? error.message : String(error)}`
|
|
127
|
-
);
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
console.log();
|
|
131
|
-
if (failCount === 0) {
|
|
132
|
-
this.logger.success(
|
|
133
|
-
`\u2705 \u6240\u6709\u77E5\u8BC6\u5E93\u66F4\u65B0\u5B8C\u6210: ${successCount}/${targetDirs.length}`
|
|
134
|
-
);
|
|
135
|
-
} else {
|
|
136
|
-
this.logger.warn(
|
|
137
|
-
`\u26A0\uFE0F \u66F4\u65B0\u5B8C\u6210: ${successCount} \u6210\u529F, ${failCount} \u5931\u8D25 (\u5171 ${targetDirs.length} \u4E2A)`
|
|
138
|
-
);
|
|
139
|
-
}
|
|
140
|
-
} catch (error) {
|
|
141
|
-
this.logger.error(
|
|
142
|
-
`\u6279\u91CF\u66F4\u65B0\u5931\u8D25: ${error instanceof Error ? error.message : String(error)}`
|
|
143
|
-
);
|
|
144
|
-
throw error;
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
78
|
/**
|
|
148
79
|
* 更新 root_item 配置
|
|
149
80
|
* 只更新当前月份的完成笔记数量
|
|
@@ -194,22 +125,11 @@ var UpdateCommand = class extends BaseCommand {
|
|
|
194
125
|
import { readFileSync as readFileSync2, writeFileSync as writeFileSync2 } from "fs";
|
|
195
126
|
import { execSync } from "child_process";
|
|
196
127
|
var UpdateCompletedCountCommand = class extends BaseCommand {
|
|
197
|
-
updateAll = false;
|
|
198
128
|
constructor() {
|
|
199
129
|
super("update-completed-count");
|
|
200
130
|
}
|
|
201
|
-
/**
|
|
202
|
-
* 设置是否更新所有知识库
|
|
203
|
-
*/
|
|
204
|
-
setUpdateAll(updateAll) {
|
|
205
|
-
this.updateAll = updateAll;
|
|
206
|
-
}
|
|
207
131
|
async run() {
|
|
208
|
-
|
|
209
|
-
await this.updateAllRepos();
|
|
210
|
-
} else {
|
|
211
|
-
await this.updateCurrentRepo();
|
|
212
|
-
}
|
|
132
|
+
await this.updateCurrentRepo();
|
|
213
133
|
}
|
|
214
134
|
/**
|
|
215
135
|
* 更新当前知识库
|
|
@@ -241,58 +161,6 @@ var UpdateCompletedCountCommand = class extends BaseCommand {
|
|
|
241
161
|
throw error;
|
|
242
162
|
}
|
|
243
163
|
}
|
|
244
|
-
/**
|
|
245
|
-
* 更新所有知识库
|
|
246
|
-
*/
|
|
247
|
-
async updateAllRepos() {
|
|
248
|
-
try {
|
|
249
|
-
const targetDirs = getTargetDirs(TNOTES_BASE_DIR, "TNotes.", [
|
|
250
|
-
ROOT_DIR_PATH,
|
|
251
|
-
EN_WORDS_DIR
|
|
252
|
-
]);
|
|
253
|
-
if (targetDirs.length === 0) {
|
|
254
|
-
this.logger.warn("\u672A\u627E\u5230\u7B26\u5408\u6761\u4EF6\u7684\u77E5\u8BC6\u5E93");
|
|
255
|
-
return;
|
|
256
|
-
}
|
|
257
|
-
this.logger.info(
|
|
258
|
-
`\u6B63\u5728\u66F4\u65B0 ${targetDirs.length} \u4E2A\u77E5\u8BC6\u5E93\u7684\u5B8C\u6210\u6570\u91CF\u5386\u53F2\u8BB0\u5F55...`
|
|
259
|
-
);
|
|
260
|
-
let successCount = 0;
|
|
261
|
-
let failCount = 0;
|
|
262
|
-
for (let i = 0; i < targetDirs.length; i++) {
|
|
263
|
-
const dir = targetDirs[i];
|
|
264
|
-
const repoName = dir.split("/").pop() || dir;
|
|
265
|
-
try {
|
|
266
|
-
process.stdout.write(
|
|
267
|
-
`\r [${i + 1}/${targetDirs.length}] \u6B63\u5728\u66F4\u65B0: ${repoName}...`
|
|
268
|
-
);
|
|
269
|
-
await runCommand("pnpm tn:update-completed-count", dir);
|
|
270
|
-
successCount++;
|
|
271
|
-
} catch (error) {
|
|
272
|
-
failCount++;
|
|
273
|
-
console.log();
|
|
274
|
-
this.logger.error(
|
|
275
|
-
`\u66F4\u65B0\u5931\u8D25: ${repoName} - ${error instanceof Error ? error.message : String(error)}`
|
|
276
|
-
);
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
console.log();
|
|
280
|
-
if (failCount === 0) {
|
|
281
|
-
this.logger.success(
|
|
282
|
-
`\u2705 \u6240\u6709\u77E5\u8BC6\u5E93\u5386\u53F2\u6570\u636E\u66F4\u65B0\u5B8C\u6210: ${successCount}/${targetDirs.length}`
|
|
283
|
-
);
|
|
284
|
-
} else {
|
|
285
|
-
this.logger.warn(
|
|
286
|
-
`\u26A0\uFE0F \u66F4\u65B0\u5B8C\u6210: ${successCount} \u6210\u529F, ${failCount} \u5931\u8D25 (\u5171 ${targetDirs.length} \u4E2A)`
|
|
287
|
-
);
|
|
288
|
-
}
|
|
289
|
-
} catch (error) {
|
|
290
|
-
this.logger.error(
|
|
291
|
-
`\u6279\u91CF\u66F4\u65B0\u5931\u8D25: ${error instanceof Error ? error.message : String(error)}`
|
|
292
|
-
);
|
|
293
|
-
throw error;
|
|
294
|
-
}
|
|
295
|
-
}
|
|
296
164
|
/**
|
|
297
165
|
* 获取历史每个月的 completed_notes_count(最近12个月)
|
|
298
166
|
*
|
|
@@ -395,31 +263,12 @@ var UpdateCompletedCountCommand = class extends BaseCommand {
|
|
|
395
263
|
var PushCommand = class extends BaseCommand {
|
|
396
264
|
gitService;
|
|
397
265
|
timestampService;
|
|
398
|
-
pushAll = false;
|
|
399
266
|
constructor() {
|
|
400
267
|
super("push");
|
|
401
268
|
this.gitService = new GitService();
|
|
402
269
|
this.timestampService = new TimestampService();
|
|
403
270
|
}
|
|
404
|
-
/**
|
|
405
|
-
* 设置是否推送所有仓库
|
|
406
|
-
*/
|
|
407
|
-
setPushAll(value) {
|
|
408
|
-
this.pushAll = value;
|
|
409
|
-
}
|
|
410
271
|
async run() {
|
|
411
|
-
if (this.pushAll) {
|
|
412
|
-
const parallel = process.env.PARALLEL_PUSH === "true";
|
|
413
|
-
const force = this.options.force === true;
|
|
414
|
-
if (parallel) {
|
|
415
|
-
this.logger.info("Parallel push mode enabled");
|
|
416
|
-
}
|
|
417
|
-
if (force) {
|
|
418
|
-
this.logger.warn("\u4F7F\u7528\u5F3A\u5236\u63A8\u9001\u6A21\u5F0F (--force)");
|
|
419
|
-
}
|
|
420
|
-
await pushAllRepos({ parallel, force });
|
|
421
|
-
return;
|
|
422
|
-
}
|
|
423
272
|
try {
|
|
424
273
|
this.logger.info("\u68C0\u67E5\u662F\u5426\u6709\u66F4\u6539...");
|
|
425
274
|
const status = await this.gitService.getStatus();
|
|
@@ -462,63 +311,17 @@ var PushCommand = class extends BaseCommand {
|
|
|
462
311
|
// commands/git/PullCommand.ts
|
|
463
312
|
var PullCommand = class extends BaseCommand {
|
|
464
313
|
gitService;
|
|
465
|
-
pullAll = false;
|
|
466
314
|
constructor() {
|
|
467
315
|
super("pull");
|
|
468
316
|
this.gitService = new GitService();
|
|
469
317
|
}
|
|
470
|
-
/**
|
|
471
|
-
* 设置是否拉取所有仓库
|
|
472
|
-
*/
|
|
473
|
-
setPullAll(value) {
|
|
474
|
-
this.pullAll = value;
|
|
475
|
-
}
|
|
476
318
|
async run() {
|
|
477
|
-
if (this.pullAll) {
|
|
478
|
-
const parallel = process.env.PARALLEL_PULL === "true";
|
|
479
|
-
if (parallel) {
|
|
480
|
-
this.logger.info("Parallel pull mode enabled");
|
|
481
|
-
}
|
|
482
|
-
await pullAllRepos({ parallel });
|
|
483
|
-
return;
|
|
484
|
-
}
|
|
485
319
|
this.logger.info("\u6B63\u5728\u4ECE\u8FDC\u7A0B\u4ED3\u5E93\u62C9\u53D6...");
|
|
486
320
|
await this.gitService.pull();
|
|
487
321
|
this.logger.success("\u62C9\u53D6\u5B8C\u6210");
|
|
488
322
|
}
|
|
489
323
|
};
|
|
490
324
|
|
|
491
|
-
// commands/git/SyncCommand.ts
|
|
492
|
-
var SyncCommand = class extends BaseCommand {
|
|
493
|
-
gitService;
|
|
494
|
-
syncAll = false;
|
|
495
|
-
constructor() {
|
|
496
|
-
super("sync");
|
|
497
|
-
this.gitService = new GitService();
|
|
498
|
-
}
|
|
499
|
-
/**
|
|
500
|
-
* 设置是否同步所有仓库
|
|
501
|
-
*/
|
|
502
|
-
setSyncAll(value) {
|
|
503
|
-
this.syncAll = value;
|
|
504
|
-
}
|
|
505
|
-
async run() {
|
|
506
|
-
if (this.syncAll) {
|
|
507
|
-
await syncAllRepos({ parallel: false });
|
|
508
|
-
return;
|
|
509
|
-
}
|
|
510
|
-
this.logger.info("\u6B63\u5728\u540C\u6B65\u4ED3\u5E93...");
|
|
511
|
-
const hasChanges = await this.gitService.hasChanges();
|
|
512
|
-
if (hasChanges) {
|
|
513
|
-
const message = this.gitService.generateCommitMessage();
|
|
514
|
-
await this.gitService.sync(message);
|
|
515
|
-
} else {
|
|
516
|
-
await this.gitService.sync();
|
|
517
|
-
}
|
|
518
|
-
this.logger.success("\u540C\u6B65\u5B8C\u6210");
|
|
519
|
-
}
|
|
520
|
-
};
|
|
521
|
-
|
|
522
325
|
// commands/dev/DevCommand.ts
|
|
523
326
|
var DevCommand = class extends BaseCommand {
|
|
524
327
|
fileWatcherService;
|
|
@@ -710,18 +513,6 @@ var CreateNoteCommand = class extends BaseCommand {
|
|
|
710
513
|
}
|
|
711
514
|
};
|
|
712
515
|
|
|
713
|
-
// commands/maintenance/SyncCoreCommand.ts
|
|
714
|
-
var SyncCoreCommand = class extends BaseCommand {
|
|
715
|
-
syncCoreService;
|
|
716
|
-
constructor() {
|
|
717
|
-
super("sync-core");
|
|
718
|
-
this.syncCoreService = new SyncCoreService();
|
|
719
|
-
}
|
|
720
|
-
async run() {
|
|
721
|
-
await this.syncCoreService.syncToAllRepos();
|
|
722
|
-
}
|
|
723
|
-
};
|
|
724
|
-
|
|
725
516
|
// commands/maintenance/FixTimestampsCommand.ts
|
|
726
517
|
var FixTimestampsCommand = class extends BaseCommand {
|
|
727
518
|
timestampService;
|
|
@@ -762,18 +553,10 @@ var COMMAND_CATEGORIES = {
|
|
|
762
553
|
COMMAND_NAMES.UPDATE_COMPLETED_COUNT,
|
|
763
554
|
COMMAND_NAMES.CREATE_NOTES
|
|
764
555
|
],
|
|
765
|
-
"Git \u64CD\u4F5C": [COMMAND_NAMES.PUSH, COMMAND_NAMES.PULL
|
|
766
|
-
\u5176\u4ED6: [
|
|
767
|
-
COMMAND_NAMES.SYNC_SCRIPTS,
|
|
768
|
-
COMMAND_NAMES.FIX_TIMESTAMPS,
|
|
769
|
-
COMMAND_NAMES.HELP
|
|
770
|
-
]
|
|
556
|
+
"Git \u64CD\u4F5C": [COMMAND_NAMES.PUSH, COMMAND_NAMES.PULL],
|
|
557
|
+
\u5176\u4ED6: [COMMAND_NAMES.FIX_TIMESTAMPS, COMMAND_NAMES.HELP]
|
|
771
558
|
};
|
|
772
559
|
var COMMAND_OPTIONS_INFO = {
|
|
773
|
-
[COMMAND_OPTIONS.ALL]: {
|
|
774
|
-
description: "\u6279\u91CF\u64CD\u4F5C\u6240\u6709\u77E5\u8BC6\u5E93",
|
|
775
|
-
applicableTo: "update/update-completed-count/push/pull/sync"
|
|
776
|
-
},
|
|
777
560
|
[COMMAND_OPTIONS.QUIET]: {
|
|
778
561
|
description: "\u9759\u9ED8\u6A21\u5F0F",
|
|
779
562
|
applicableTo: "update"
|
|
@@ -814,14 +597,9 @@ var HelpCommand = class extends BaseCommand {
|
|
|
814
597
|
this.logger.info(" pnpm tn:build");
|
|
815
598
|
this.logger.info(" pnpm tn:create-notes # \u6279\u91CF\u521B\u5EFA\u7B14\u8BB0");
|
|
816
599
|
this.logger.info(" pnpm tn:update");
|
|
817
|
-
this.logger.info(" pnpm tn:update --all # \u66F4\u65B0\u6240\u6709\u77E5\u8BC6\u5E93");
|
|
818
600
|
this.logger.info(
|
|
819
601
|
" pnpm tn:update-completed-count # \u751F\u6210\u5F53\u524D\u77E5\u8BC6\u5E93\u6700\u8FD1 12 \u4E2A\u6708\u7684\u5B8C\u6210\u7B14\u8BB0\u6570\u91CF\u7EDF\u8BA1"
|
|
820
602
|
);
|
|
821
|
-
this.logger.info(
|
|
822
|
-
" pnpm tn:update-completed-count --all # \u751F\u6210\u6240\u6709\u77E5\u8BC6\u5E93\u6700\u8FD1 12 \u4E2A\u6708\u7684\u5B8C\u6210\u7B14\u8BB0\u6570\u91CF\u7EDF\u8BA1"
|
|
823
|
-
);
|
|
824
|
-
this.logger.info(" pnpm tn:push --all # \u63A8\u9001\u6240\u6709\u77E5\u8BC6\u5E93");
|
|
825
603
|
this.logger.info("");
|
|
826
604
|
this.logger.info("\u53C2\u6570\uFF1A");
|
|
827
605
|
for (const [option, info] of Object.entries(COMMAND_OPTIONS_INFO)) {
|
|
@@ -848,9 +626,7 @@ var commandFactories = {
|
|
|
848
626
|
"update-completed-count": () => new UpdateCompletedCountCommand(),
|
|
849
627
|
push: () => new PushCommand(),
|
|
850
628
|
pull: () => new PullCommand(),
|
|
851
|
-
sync: () => new SyncCommand(),
|
|
852
629
|
"create-notes": () => new CreateNoteCommand(),
|
|
853
|
-
"sync-core": () => new SyncCoreCommand(),
|
|
854
630
|
"fix-timestamps": () => new FixTimestampsCommand(),
|
|
855
631
|
"update-note-config": () => new UpdateNoteConfigCommand(),
|
|
856
632
|
"rename-note": () => new RenameNoteCommand(),
|
|
@@ -900,20 +676,9 @@ ${"-".repeat(66)}
|
|
|
900
676
|
if (commandName === COMMAND_NAMES.UPDATE) {
|
|
901
677
|
const cmd = command;
|
|
902
678
|
if (args.quiet) cmd.setQuiet(true);
|
|
903
|
-
if (args.all) cmd.setUpdateAll(true);
|
|
904
|
-
} else if (commandName === COMMAND_NAMES.UPDATE_COMPLETED_COUNT) {
|
|
905
|
-
const cmd = command;
|
|
906
|
-
if (args.all) cmd.setUpdateAll(true);
|
|
907
679
|
} else if (commandName === COMMAND_NAMES.PUSH) {
|
|
908
680
|
const cmd = command;
|
|
909
681
|
if (args.force) cmd.setOptions({ force: true });
|
|
910
|
-
if (args.all) cmd.setPushAll(true);
|
|
911
|
-
} else if (commandName === COMMAND_NAMES.PULL) {
|
|
912
|
-
const cmd = command;
|
|
913
|
-
if (args.all) cmd.setPullAll(true);
|
|
914
|
-
} else if (commandName === COMMAND_NAMES.SYNC) {
|
|
915
|
-
const cmd = command;
|
|
916
|
-
if (args.all) cmd.setSyncAll(true);
|
|
917
682
|
}
|
|
918
683
|
await command.execute();
|
|
919
684
|
} catch (error) {
|
package/package.json
CHANGED
package/types/shims.d.ts
ADDED