@tnotesjs/core 0.1.9 → 0.1.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.
Potentially problematic release.
This version of @tnotesjs/core might be problematic. Click here for more details.
- package/README.md +3 -3
- package/dist/{chunk-DT6HO7XD.js → chunk-IGIIUJDF.js} +50 -370
- package/dist/cli/index.js +5 -219
- 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,7 +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
17
|
SYNC: "sync",
|
|
19
18
|
UPDATE: "update",
|
|
20
19
|
UPDATE_COMPLETED_COUNT: "update-completed-count",
|
|
@@ -27,17 +26,15 @@ var COMMAND_DESCRIPTIONS = {
|
|
|
27
26
|
[COMMAND_NAMES.UPDATE]: "\u6839\u636E\u7B14\u8BB0\u5185\u5BB9\u66F4\u65B0\u77E5\u8BC6\u5E93",
|
|
28
27
|
[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
28
|
[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
|
|
33
|
-
[COMMAND_NAMES.SYNC_CORE]: "\u540C\u6B65\u6240\u6709\u5144\u5F1F\u77E5\u8BC6\u5E93\u7684 tnotesjs/core \u5230\u6700\u65B0\u7248\u672C",
|
|
29
|
+
[COMMAND_NAMES.PUSH]: "\u5C06\u77E5\u8BC6\u5E93\u63A8\u9001\u5230 GitHub",
|
|
30
|
+
[COMMAND_NAMES.PULL]: "\u5C06 GitHub \u7684\u77E5\u8BC6\u5E93\u62C9\u4E0B\u6765",
|
|
31
|
+
[COMMAND_NAMES.SYNC]: "\u540C\u6B65\u672C\u5730\u548C\u8FDC\u7A0B\u7684\u77E5\u8BC6\u5E93\u72B6\u6001",
|
|
34
32
|
[COMMAND_NAMES.FIX_TIMESTAMPS]: "\u4FEE\u590D\u6240\u6709\u7B14\u8BB0\u7684\u65F6\u95F4\u6233\uFF08\u57FA\u4E8E git \u5386\u53F2\uFF09",
|
|
35
33
|
[COMMAND_NAMES.UPDATE_NOTE_CONFIG]: "\u66F4\u65B0\u7B14\u8BB0\u914D\u7F6E\u6587\u4EF6",
|
|
36
34
|
[COMMAND_NAMES.RENAME_NOTE]: "\u91CD\u547D\u540D\u7B14\u8BB0",
|
|
37
35
|
[COMMAND_NAMES.HELP]: "\u663E\u793A\u5E2E\u52A9\u4FE1\u606F"
|
|
38
36
|
};
|
|
39
37
|
var COMMAND_OPTIONS = {
|
|
40
|
-
ALL: "all",
|
|
41
38
|
QUIET: "quiet",
|
|
42
39
|
FORCE: "force"
|
|
43
40
|
};
|
|
@@ -419,21 +416,6 @@ function getChangedIds() {
|
|
|
419
416
|
return new Set(changedIds);
|
|
420
417
|
}
|
|
421
418
|
|
|
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
419
|
// utils/markdown.ts
|
|
438
420
|
function createAddNumberToTitle() {
|
|
439
421
|
const titleNumbers = Array(7).fill(0);
|
|
@@ -595,8 +577,8 @@ async function waitForPort(port2, timeout = 5e3) {
|
|
|
595
577
|
}
|
|
596
578
|
|
|
597
579
|
// core/NoteManager.ts
|
|
598
|
-
import { existsSync, readFileSync, readdirSync
|
|
599
|
-
import { join
|
|
580
|
+
import { existsSync, readFileSync, readdirSync, writeFileSync } from "fs";
|
|
581
|
+
import { join } from "path";
|
|
600
582
|
|
|
601
583
|
// config/constants.ts
|
|
602
584
|
import { resolve } from "path";
|
|
@@ -613,9 +595,6 @@ var {
|
|
|
613
595
|
root_item
|
|
614
596
|
} = config;
|
|
615
597
|
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
598
|
var ROOT_DIR_PATH = rootPath;
|
|
620
599
|
var ROOT_README_PATH = resolve(ROOT_DIR_PATH, "README.md");
|
|
621
600
|
var ROOT_CONFIG_PATH = resolve(ROOT_DIR_PATH, ".tnotes.json");
|
|
@@ -722,7 +701,7 @@ var NoteManager = class _NoteManager {
|
|
|
722
701
|
*/
|
|
723
702
|
getNoteDirs() {
|
|
724
703
|
if (!existsSync(NOTES_PATH)) return [];
|
|
725
|
-
return
|
|
704
|
+
return readdirSync(NOTES_PATH, { withFileTypes: true }).filter(
|
|
726
705
|
(entry) => entry.isDirectory() && !entry.name.startsWith(".") && _NoteManager.NOTE_INDEX_REGEX.test(entry.name)
|
|
727
706
|
).map((entry) => entry.name).sort();
|
|
728
707
|
}
|
|
@@ -731,9 +710,9 @@ var NoteManager = class _NoteManager {
|
|
|
731
710
|
* @returns NoteInfo 或 undefined(README 不存在时)
|
|
732
711
|
*/
|
|
733
712
|
buildNoteInfo(dirName) {
|
|
734
|
-
const notePath =
|
|
735
|
-
const readmePath =
|
|
736
|
-
const configPath =
|
|
713
|
+
const notePath = join(NOTES_PATH, dirName);
|
|
714
|
+
const readmePath = join(notePath, "README.md");
|
|
715
|
+
const configPath = join(notePath, ".tnotes.json");
|
|
737
716
|
if (!existsSync(readmePath)) {
|
|
738
717
|
logger.warn(`README not found in note: ${dirName}`);
|
|
739
718
|
return void 0;
|
|
@@ -1100,173 +1079,6 @@ async function runCommand(command, dir) {
|
|
|
1100
1079
|
});
|
|
1101
1080
|
}
|
|
1102
1081
|
|
|
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
1082
|
// utils/validators.ts
|
|
1271
1083
|
var INVALID_FILENAME_CHARS = /[<>:"/\\|?*\x00-\x1F]/;
|
|
1272
1084
|
var WINDOWS_RESERVED_NAMES = /* @__PURE__ */ new Set([
|
|
@@ -1331,7 +1143,7 @@ function validateNoteTitle(title) {
|
|
|
1331
1143
|
}
|
|
1332
1144
|
|
|
1333
1145
|
// core/NoteIndexCache.ts
|
|
1334
|
-
import { join as
|
|
1146
|
+
import { join as join2 } from "path";
|
|
1335
1147
|
var NoteIndexCache = class _NoteIndexCache {
|
|
1336
1148
|
static instance = null;
|
|
1337
1149
|
/** noteIndex -> NoteIndexItem 的映射 */
|
|
@@ -1382,13 +1194,13 @@ var NoteIndexCache = class _NoteIndexCache {
|
|
|
1382
1194
|
toNoteInfoList() {
|
|
1383
1195
|
const result = [];
|
|
1384
1196
|
for (const item of this.byNoteIndex.values()) {
|
|
1385
|
-
const notePath =
|
|
1197
|
+
const notePath = join2(NOTES_PATH, item.folderName);
|
|
1386
1198
|
result.push({
|
|
1387
1199
|
index: item.noteIndex,
|
|
1388
1200
|
path: notePath,
|
|
1389
1201
|
dirName: item.folderName,
|
|
1390
|
-
readmePath:
|
|
1391
|
-
configPath:
|
|
1202
|
+
readmePath: join2(notePath, "README.md"),
|
|
1203
|
+
configPath: join2(notePath, ".tnotes.json"),
|
|
1392
1204
|
config: item.noteConfig
|
|
1393
1205
|
});
|
|
1394
1206
|
}
|
|
@@ -2295,9 +2107,9 @@ async function safeExecute(label, fn, logger2) {
|
|
|
2295
2107
|
}
|
|
2296
2108
|
|
|
2297
2109
|
// services/file-watcher/watchState.ts
|
|
2298
|
-
import { existsSync as existsSync3, readFileSync as readFileSync3, readdirSync as
|
|
2110
|
+
import { existsSync as existsSync3, readFileSync as readFileSync3, readdirSync as readdirSync2, statSync } from "fs";
|
|
2299
2111
|
import { createHash } from "crypto";
|
|
2300
|
-
import { join as
|
|
2112
|
+
import { join as join3 } from "path";
|
|
2301
2113
|
var WatchState = class {
|
|
2302
2114
|
constructor(config2) {
|
|
2303
2115
|
this.config = config2;
|
|
@@ -2377,8 +2189,8 @@ var WatchState = class {
|
|
|
2377
2189
|
* @param noteDirName 笔记目录名称
|
|
2378
2190
|
*/
|
|
2379
2191
|
clearNoteCaches(noteDirName) {
|
|
2380
|
-
const readmePath =
|
|
2381
|
-
const configPath =
|
|
2192
|
+
const readmePath = join3(this.config.notesDir, noteDirName, "README.md");
|
|
2193
|
+
const configPath = join3(this.config.notesDir, noteDirName, ".tnotes.json");
|
|
2382
2194
|
this.fileHashes.delete(readmePath);
|
|
2383
2195
|
this.fileHashes.delete(configPath);
|
|
2384
2196
|
this.configCache.delete(configPath);
|
|
@@ -2431,16 +2243,16 @@ var WatchState = class {
|
|
|
2431
2243
|
*/
|
|
2432
2244
|
initializeFromDisk() {
|
|
2433
2245
|
try {
|
|
2434
|
-
const noteDirs =
|
|
2246
|
+
const noteDirs = readdirSync2(this.config.notesDir);
|
|
2435
2247
|
this.clearAll();
|
|
2436
2248
|
for (const noteDir of noteDirs) {
|
|
2437
|
-
const noteDirPath =
|
|
2249
|
+
const noteDirPath = join3(this.config.notesDir, noteDir);
|
|
2438
2250
|
if (!statSync(noteDirPath).isDirectory()) continue;
|
|
2439
2251
|
this.noteDirCache.add(noteDir);
|
|
2440
|
-
const readmePath =
|
|
2252
|
+
const readmePath = join3(noteDirPath, "README.md");
|
|
2441
2253
|
const readmeHash = this.getFileHash(readmePath);
|
|
2442
2254
|
if (readmeHash) this.fileHashes.set(readmePath, readmeHash);
|
|
2443
|
-
const configPath =
|
|
2255
|
+
const configPath = join3(noteDirPath, ".tnotes.json");
|
|
2444
2256
|
const configHash = this.getFileHash(configPath);
|
|
2445
2257
|
if (configHash) {
|
|
2446
2258
|
this.fileHashes.set(configPath, configHash);
|
|
@@ -2580,7 +2392,7 @@ var EventScheduler = class {
|
|
|
2580
2392
|
|
|
2581
2393
|
// services/file-watcher/renameDetector.ts
|
|
2582
2394
|
import { existsSync as existsSync4 } from "fs";
|
|
2583
|
-
import { join as
|
|
2395
|
+
import { join as join4 } from "path";
|
|
2584
2396
|
var FOLDER_RENAME_DETECT_WINDOW_MS = 500;
|
|
2585
2397
|
var RenameDetector = class {
|
|
2586
2398
|
constructor(config2) {
|
|
@@ -2592,7 +2404,7 @@ var RenameDetector = class {
|
|
|
2592
2404
|
folderRenameTimer = null;
|
|
2593
2405
|
handleFsRename(folderName) {
|
|
2594
2406
|
const { notesDir, dirCache, logger: logger2, onDelete, onRename } = this.config;
|
|
2595
|
-
const folderPath =
|
|
2407
|
+
const folderPath = join4(notesDir, folderName);
|
|
2596
2408
|
const folderExists = existsSync4(folderPath);
|
|
2597
2409
|
const noteIndex = NoteManager.extractNoteIndex(folderName);
|
|
2598
2410
|
if (!noteIndex) {
|
|
@@ -2731,7 +2543,7 @@ var GlobalUpdateCoordinator = class {
|
|
|
2731
2543
|
|
|
2732
2544
|
// services/file-watcher/folderChangeHandler.ts
|
|
2733
2545
|
import { existsSync as existsSync5, promises as fsPromises } from "fs";
|
|
2734
|
-
import { join as
|
|
2546
|
+
import { join as join5 } from "path";
|
|
2735
2547
|
var RENAME_REVERT_DELAY_MS = 2e3;
|
|
2736
2548
|
var DELETE_REINIT_DELAY_MS = 1e3;
|
|
2737
2549
|
var UPDATE_UNLOCK_DELAY_MS = 500;
|
|
@@ -2865,8 +2677,8 @@ var FolderChangeHandler = class {
|
|
|
2865
2677
|
async revertFolderRename(oldName, newName) {
|
|
2866
2678
|
const { notesDir, scheduler, watchState, logger: logger2 } = this.config;
|
|
2867
2679
|
try {
|
|
2868
|
-
const oldPath =
|
|
2869
|
-
const newPath =
|
|
2680
|
+
const oldPath = join5(notesDir, oldName);
|
|
2681
|
+
const newPath = join5(notesDir, newName);
|
|
2870
2682
|
if (existsSync5(newPath)) {
|
|
2871
2683
|
scheduler.setUpdating(true);
|
|
2872
2684
|
await fsPromises.rename(newPath, oldPath);
|
|
@@ -2892,7 +2704,7 @@ var FolderChangeHandler = class {
|
|
|
2892
2704
|
|
|
2893
2705
|
// services/file-watcher/fsWatcherAdapter.ts
|
|
2894
2706
|
import { watch } from "fs";
|
|
2895
|
-
import { basename, dirname, join as
|
|
2707
|
+
import { basename, dirname, join as join6, sep } from "path";
|
|
2896
2708
|
var FsWatcherAdapter = class {
|
|
2897
2709
|
constructor(config2) {
|
|
2898
2710
|
this.config = config2;
|
|
@@ -2935,7 +2747,7 @@ var FsWatcherAdapter = class {
|
|
|
2935
2747
|
if (baseFilename !== "README.md" && baseFilename !== ".tnotes.json") {
|
|
2936
2748
|
return;
|
|
2937
2749
|
}
|
|
2938
|
-
const fullPath =
|
|
2750
|
+
const fullPath = join6(this.config.notesDir, filename);
|
|
2939
2751
|
const event = this.buildWatchEvent(fullPath, filename);
|
|
2940
2752
|
if (!event) {
|
|
2941
2753
|
return;
|
|
@@ -3283,7 +3095,7 @@ var ReadmeService = class _ReadmeService {
|
|
|
3283
3095
|
|
|
3284
3096
|
// services/note/service.ts
|
|
3285
3097
|
import { writeFileSync as writeFileSync4, readFileSync as readFileSync5 } from "fs";
|
|
3286
|
-
import { join as
|
|
3098
|
+
import { join as join7 } from "path";
|
|
3287
3099
|
import { v4 as uuidv4 } from "uuid";
|
|
3288
3100
|
|
|
3289
3101
|
// config/templates.ts
|
|
@@ -3378,13 +3190,13 @@ var NoteService = class _NoteService {
|
|
|
3378
3190
|
} = options;
|
|
3379
3191
|
const noteIndex = this.generateNextNoteIndex(usedIndexes);
|
|
3380
3192
|
const dirName = `${noteIndex}. ${title}`;
|
|
3381
|
-
const notePath =
|
|
3193
|
+
const notePath = join7(NOTES_PATH, dirName);
|
|
3382
3194
|
await ensureDirectory(notePath);
|
|
3383
|
-
const readmePath =
|
|
3195
|
+
const readmePath = join7(notePath, "README.md");
|
|
3384
3196
|
const noteTitle = generateNoteTitle(noteIndex, title, REPO_NOTES_URL);
|
|
3385
3197
|
const readmeContent = noteTitle + "\n" + NEW_NOTES_README_MD_TEMPLATE;
|
|
3386
3198
|
writeFileSync4(readmePath, readmeContent, "utf-8");
|
|
3387
|
-
const configPath =
|
|
3199
|
+
const configPath = join7(notePath, ".tnotes.json");
|
|
3388
3200
|
const now = Date.now();
|
|
3389
3201
|
const config2 = {
|
|
3390
3202
|
id: configId || uuidv4(),
|
|
@@ -3795,139 +3607,15 @@ var GitService = class {
|
|
|
3795
3607
|
}
|
|
3796
3608
|
};
|
|
3797
3609
|
|
|
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
3610
|
// services/timestamp/service.ts
|
|
3923
3611
|
import {
|
|
3924
|
-
existsSync as
|
|
3612
|
+
existsSync as existsSync7,
|
|
3925
3613
|
readFileSync as readFileSync6,
|
|
3926
3614
|
writeFileSync as writeFileSync5,
|
|
3927
|
-
readdirSync as
|
|
3615
|
+
readdirSync as readdirSync3,
|
|
3928
3616
|
statSync as statSync2
|
|
3929
3617
|
} from "fs";
|
|
3930
|
-
import { join as
|
|
3618
|
+
import { join as join8 } from "path";
|
|
3931
3619
|
import { execSync as execSync3 } from "child_process";
|
|
3932
3620
|
var BIRTH_DATE = (/* @__PURE__ */ new Date("1999-06-29T00:00:00+08:00")).getTime();
|
|
3933
3621
|
var TimestampService = class {
|
|
@@ -3942,7 +3630,7 @@ var TimestampService = class {
|
|
|
3942
3630
|
*/
|
|
3943
3631
|
getGitTimestamps(noteDirPath) {
|
|
3944
3632
|
try {
|
|
3945
|
-
const readmePath =
|
|
3633
|
+
const readmePath = join8(noteDirPath, "README.md");
|
|
3946
3634
|
const createdAtOutput = execSync3(
|
|
3947
3635
|
`git log --diff-filter=A --follow --format=%ct -- "${readmePath}"`,
|
|
3948
3636
|
{
|
|
@@ -3979,14 +3667,14 @@ var TimestampService = class {
|
|
|
3979
3667
|
* @returns 是否进行了修复
|
|
3980
3668
|
*/
|
|
3981
3669
|
fixNoteTimestamps(noteDir, forceUpdate = false) {
|
|
3982
|
-
const configPath =
|
|
3983
|
-
if (!
|
|
3670
|
+
const configPath = join8(NOTES_DIR_PATH, noteDir, ".tnotes.json");
|
|
3671
|
+
if (!existsSync7(configPath)) {
|
|
3984
3672
|
return false;
|
|
3985
3673
|
}
|
|
3986
3674
|
try {
|
|
3987
3675
|
const configContent = readFileSync6(configPath, "utf-8");
|
|
3988
3676
|
const config2 = JSON.parse(configContent);
|
|
3989
|
-
const noteDirPath =
|
|
3677
|
+
const noteDirPath = join8(NOTES_DIR_PATH, noteDir);
|
|
3990
3678
|
const timestamps = this.getGitTimestamps(noteDirPath);
|
|
3991
3679
|
if (!timestamps) {
|
|
3992
3680
|
return false;
|
|
@@ -4085,12 +3773,12 @@ var TimestampService = class {
|
|
|
4085
3773
|
if (rootConfigFixed) {
|
|
4086
3774
|
logger.success("\u2705 \u6839\u914D\u7F6E\u6587\u4EF6\u65F6\u95F4\u6233\u5DF2\u4FEE\u590D");
|
|
4087
3775
|
}
|
|
4088
|
-
if (!
|
|
3776
|
+
if (!existsSync7(NOTES_DIR_PATH)) {
|
|
4089
3777
|
logger.error("notes \u76EE\u5F55\u4E0D\u5B58\u5728");
|
|
4090
3778
|
return { fixed: 0, skipped: 0, total: 0, rootConfigFixed };
|
|
4091
3779
|
}
|
|
4092
|
-
const noteDirs =
|
|
4093
|
-
const fullPath =
|
|
3780
|
+
const noteDirs = readdirSync3(NOTES_DIR_PATH).filter((name) => {
|
|
3781
|
+
const fullPath = join8(NOTES_DIR_PATH, name);
|
|
4094
3782
|
return statSync2(fullPath).isDirectory() && /^\d{4}\./.test(name);
|
|
4095
3783
|
}).sort();
|
|
4096
3784
|
let fixedCount = 0;
|
|
@@ -4127,8 +3815,8 @@ var TimestampService = class {
|
|
|
4127
3815
|
const now = Date.now();
|
|
4128
3816
|
let updatedCount = 0;
|
|
4129
3817
|
for (const noteDir of noteDirNames) {
|
|
4130
|
-
const configPath =
|
|
4131
|
-
if (!
|
|
3818
|
+
const configPath = join8(NOTES_DIR_PATH, noteDir, ".tnotes.json");
|
|
3819
|
+
if (!existsSync7(configPath)) {
|
|
4132
3820
|
continue;
|
|
4133
3821
|
}
|
|
4134
3822
|
try {
|
|
@@ -4418,8 +4106,8 @@ var UpdateNoteConfigCommand = class extends BaseCommand {
|
|
|
4418
4106
|
};
|
|
4419
4107
|
|
|
4420
4108
|
// commands/note/RenameNoteCommand.ts
|
|
4421
|
-
import { existsSync as
|
|
4422
|
-
import { join as
|
|
4109
|
+
import { existsSync as existsSync8, renameSync, readFileSync as readFileSync7, writeFileSync as writeFileSync6 } from "fs";
|
|
4110
|
+
import { join as join9 } from "path";
|
|
4423
4111
|
var RenameNoteCommand = class extends BaseCommand {
|
|
4424
4112
|
noteService;
|
|
4425
4113
|
readmeService;
|
|
@@ -4456,8 +4144,8 @@ var RenameNoteCommand = class extends BaseCommand {
|
|
|
4456
4144
|
throw new Error(validation.error || "\u6807\u9898\u683C\u5F0F\u65E0\u6548");
|
|
4457
4145
|
}
|
|
4458
4146
|
const newDirName = `${noteIndex}. ${newTitle.trim()}`;
|
|
4459
|
-
const newPath =
|
|
4460
|
-
if (
|
|
4147
|
+
const newPath = join9(NOTES_PATH, newDirName);
|
|
4148
|
+
if (existsSync8(newPath)) {
|
|
4461
4149
|
throw new Error(`\u76EE\u6807\u6587\u4EF6\u5939\u5DF2\u5B58\u5728: ${newDirName}`);
|
|
4462
4150
|
}
|
|
4463
4151
|
try {
|
|
@@ -4472,8 +4160,8 @@ var RenameNoteCommand = class extends BaseCommand {
|
|
|
4472
4160
|
}
|
|
4473
4161
|
try {
|
|
4474
4162
|
this.logger.info("\u6B63\u5728\u66F4\u65B0\u7B14\u8BB0\u5185\u90E8\u6807\u9898...");
|
|
4475
|
-
const readmePath =
|
|
4476
|
-
if (
|
|
4163
|
+
const readmePath = join9(newPath, "README.md");
|
|
4164
|
+
if (existsSync8(readmePath)) {
|
|
4477
4165
|
const content = readFileSync7(readmePath, "utf-8");
|
|
4478
4166
|
const lines = content.split("\n");
|
|
4479
4167
|
let h1Index = -1;
|
|
@@ -4517,27 +4205,19 @@ export {
|
|
|
4517
4205
|
COMMAND_OPTIONS,
|
|
4518
4206
|
handleError,
|
|
4519
4207
|
generateAnchor,
|
|
4520
|
-
getTargetDirs,
|
|
4521
4208
|
logger,
|
|
4522
4209
|
createLogger,
|
|
4523
4210
|
parseArgs,
|
|
4524
4211
|
parseReadmeCompletedNotes,
|
|
4525
|
-
TNOTES_BASE_DIR,
|
|
4526
|
-
EN_WORDS_DIR,
|
|
4527
4212
|
ROOT_DIR_PATH,
|
|
4528
4213
|
ROOT_CONFIG_PATH,
|
|
4529
4214
|
NoteManager,
|
|
4530
|
-
runCommand,
|
|
4531
|
-
pushAllRepos,
|
|
4532
|
-
pullAllRepos,
|
|
4533
|
-
syncAllRepos,
|
|
4534
4215
|
BaseCommand,
|
|
4535
4216
|
NoteIndexCache,
|
|
4536
4217
|
ReadmeService,
|
|
4537
4218
|
NoteService,
|
|
4538
4219
|
FileWatcherService,
|
|
4539
4220
|
GitService,
|
|
4540
|
-
SyncCoreService,
|
|
4541
4221
|
TimestampService,
|
|
4542
4222
|
VitepressService,
|
|
4543
4223
|
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-IGIIUJDF.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,26 +311,11 @@ 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");
|
|
@@ -491,22 +325,11 @@ var PullCommand = class extends BaseCommand {
|
|
|
491
325
|
// commands/git/SyncCommand.ts
|
|
492
326
|
var SyncCommand = class extends BaseCommand {
|
|
493
327
|
gitService;
|
|
494
|
-
syncAll = false;
|
|
495
328
|
constructor() {
|
|
496
329
|
super("sync");
|
|
497
330
|
this.gitService = new GitService();
|
|
498
331
|
}
|
|
499
|
-
/**
|
|
500
|
-
* 设置是否同步所有仓库
|
|
501
|
-
*/
|
|
502
|
-
setSyncAll(value) {
|
|
503
|
-
this.syncAll = value;
|
|
504
|
-
}
|
|
505
332
|
async run() {
|
|
506
|
-
if (this.syncAll) {
|
|
507
|
-
await syncAllRepos({ parallel: false });
|
|
508
|
-
return;
|
|
509
|
-
}
|
|
510
333
|
this.logger.info("\u6B63\u5728\u540C\u6B65\u4ED3\u5E93...");
|
|
511
334
|
const hasChanges = await this.gitService.hasChanges();
|
|
512
335
|
if (hasChanges) {
|
|
@@ -710,18 +533,6 @@ var CreateNoteCommand = class extends BaseCommand {
|
|
|
710
533
|
}
|
|
711
534
|
};
|
|
712
535
|
|
|
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
536
|
// commands/maintenance/FixTimestampsCommand.ts
|
|
726
537
|
var FixTimestampsCommand = class extends BaseCommand {
|
|
727
538
|
timestampService;
|
|
@@ -763,17 +574,9 @@ var COMMAND_CATEGORIES = {
|
|
|
763
574
|
COMMAND_NAMES.CREATE_NOTES
|
|
764
575
|
],
|
|
765
576
|
"Git \u64CD\u4F5C": [COMMAND_NAMES.PUSH, COMMAND_NAMES.PULL, COMMAND_NAMES.SYNC],
|
|
766
|
-
\u5176\u4ED6: [
|
|
767
|
-
COMMAND_NAMES.SYNC_SCRIPTS,
|
|
768
|
-
COMMAND_NAMES.FIX_TIMESTAMPS,
|
|
769
|
-
COMMAND_NAMES.HELP
|
|
770
|
-
]
|
|
577
|
+
\u5176\u4ED6: [COMMAND_NAMES.FIX_TIMESTAMPS, COMMAND_NAMES.HELP]
|
|
771
578
|
};
|
|
772
579
|
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
580
|
[COMMAND_OPTIONS.QUIET]: {
|
|
778
581
|
description: "\u9759\u9ED8\u6A21\u5F0F",
|
|
779
582
|
applicableTo: "update"
|
|
@@ -814,14 +617,9 @@ var HelpCommand = class extends BaseCommand {
|
|
|
814
617
|
this.logger.info(" pnpm tn:build");
|
|
815
618
|
this.logger.info(" pnpm tn:create-notes # \u6279\u91CF\u521B\u5EFA\u7B14\u8BB0");
|
|
816
619
|
this.logger.info(" pnpm tn:update");
|
|
817
|
-
this.logger.info(" pnpm tn:update --all # \u66F4\u65B0\u6240\u6709\u77E5\u8BC6\u5E93");
|
|
818
620
|
this.logger.info(
|
|
819
621
|
" 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
622
|
);
|
|
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
623
|
this.logger.info("");
|
|
826
624
|
this.logger.info("\u53C2\u6570\uFF1A");
|
|
827
625
|
for (const [option, info] of Object.entries(COMMAND_OPTIONS_INFO)) {
|
|
@@ -850,7 +648,6 @@ var commandFactories = {
|
|
|
850
648
|
pull: () => new PullCommand(),
|
|
851
649
|
sync: () => new SyncCommand(),
|
|
852
650
|
"create-notes": () => new CreateNoteCommand(),
|
|
853
|
-
"sync-core": () => new SyncCoreCommand(),
|
|
854
651
|
"fix-timestamps": () => new FixTimestampsCommand(),
|
|
855
652
|
"update-note-config": () => new UpdateNoteConfigCommand(),
|
|
856
653
|
"rename-note": () => new RenameNoteCommand(),
|
|
@@ -900,20 +697,9 @@ ${"-".repeat(66)}
|
|
|
900
697
|
if (commandName === COMMAND_NAMES.UPDATE) {
|
|
901
698
|
const cmd = command;
|
|
902
699
|
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
700
|
} else if (commandName === COMMAND_NAMES.PUSH) {
|
|
908
701
|
const cmd = command;
|
|
909
702
|
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
703
|
}
|
|
918
704
|
await command.execute();
|
|
919
705
|
} catch (error) {
|
package/package.json
CHANGED
package/types/shims.d.ts
ADDED