@tnotesjs/core 0.1.7 → 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-H2NACWVJ.js → chunk-IGIIUJDF.js} +73 -479
- package/dist/{chunk-UIXF3LPU.js → chunk-NASIL5FY.js} +0 -28
- package/dist/cli/index.js +6 -220
- package/dist/index.js +1 -1
- package/dist/vitepress/config/index.js +10 -108
- package/package.json +4 -3
- package/types/shims.d.ts +10 -0
- package/vitepress/config/index.ts +6 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
ConfigManager,
|
|
3
3
|
getConfigManager
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-NASIL5FY.js";
|
|
5
5
|
|
|
6
6
|
// commands/models.ts
|
|
7
7
|
var COMMAND_NAMES = {
|
|
@@ -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);
|
|
@@ -589,14 +571,14 @@ async function waitForPort(port2, timeout = 5e3) {
|
|
|
589
571
|
if (!isPortInUse(port2)) {
|
|
590
572
|
return true;
|
|
591
573
|
}
|
|
592
|
-
await new Promise((
|
|
574
|
+
await new Promise((resolve2) => setTimeout(resolve2, 100));
|
|
593
575
|
}
|
|
594
576
|
return false;
|
|
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;
|
|
@@ -1088,185 +1067,18 @@ function processEmptyLines(lines) {
|
|
|
1088
1067
|
// utils/runCommand.ts
|
|
1089
1068
|
import { exec } from "child_process";
|
|
1090
1069
|
async function runCommand(command, dir) {
|
|
1091
|
-
return new Promise((
|
|
1070
|
+
return new Promise((resolve2, reject) => {
|
|
1092
1071
|
exec(command, { cwd: dir }, (error, stdout, stderr) => {
|
|
1093
1072
|
if (error) {
|
|
1094
1073
|
console.error(`\u5904\u7406 ${dir} \u65F6\u51FA\u9519\uFF1A${stderr}`);
|
|
1095
1074
|
reject(error);
|
|
1096
1075
|
} else {
|
|
1097
|
-
|
|
1076
|
+
resolve2(stdout.trim());
|
|
1098
1077
|
}
|
|
1099
1078
|
});
|
|
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
|
}
|
|
@@ -1763,8 +1575,6 @@ var ReadmeGenerator = class {
|
|
|
1763
1575
|
};
|
|
1764
1576
|
|
|
1765
1577
|
// core/GitManager.ts
|
|
1766
|
-
import { resolve as resolve2 } from "path";
|
|
1767
|
-
import { existsSync as existsSync3 } from "fs";
|
|
1768
1578
|
var GitManager = class {
|
|
1769
1579
|
logger;
|
|
1770
1580
|
dir;
|
|
@@ -1958,7 +1768,6 @@ var GitManager = class {
|
|
|
1958
1768
|
} else {
|
|
1959
1769
|
this.logger.info("\u5DF2\u662F\u6700\u65B0\uFF0C\u6CA1\u6709\u9700\u8981\u62C9\u53D6\u7684\u66F4\u65B0");
|
|
1960
1770
|
}
|
|
1961
|
-
await this.updateSubmodules();
|
|
1962
1771
|
} catch (error) {
|
|
1963
1772
|
this.logger.error("\u62C9\u53D6\u5931\u8D25");
|
|
1964
1773
|
handleError(error);
|
|
@@ -2032,18 +1841,12 @@ var GitManager = class {
|
|
|
2032
1841
|
return;
|
|
2033
1842
|
}
|
|
2034
1843
|
try {
|
|
2035
|
-
|
|
2036
|
-
|
|
2037
|
-
if (!latestStatus.hasChanges) {
|
|
2038
|
-
this.logger.info("\u6CA1\u6709\u9700\u8981\u63D0\u4EA4\u7684\u66F4\u6539");
|
|
2039
|
-
return;
|
|
2040
|
-
}
|
|
2041
|
-
this.logger.info(`\u6B63\u5728\u63A8\u9001 ${latestStatus.changedFiles} \u4E2A\u6587\u4EF6...`);
|
|
2042
|
-
latestStatus.files.forEach((file, index) => {
|
|
1844
|
+
this.logger.info(`\u6B63\u5728\u63A8\u9001 ${status.changedFiles} \u4E2A\u6587\u4EF6...`);
|
|
1845
|
+
status.files.forEach((file, index) => {
|
|
2043
1846
|
console.log(` ${index + 1}. ${file.path}`);
|
|
2044
1847
|
});
|
|
2045
1848
|
await runCommand("git add .", this.dir);
|
|
2046
|
-
const message = commitMessage || `update: ${
|
|
1849
|
+
const message = commitMessage || `update: ${status.changedFiles} files modified`;
|
|
2047
1850
|
await runCommand(`git commit -m "${message}"`, this.dir);
|
|
2048
1851
|
let cmd = "git push";
|
|
2049
1852
|
if (options?.force) cmd += " --force";
|
|
@@ -2051,10 +1854,10 @@ var GitManager = class {
|
|
|
2051
1854
|
const remoteInfo = await this.getRemoteInfo();
|
|
2052
1855
|
if (remoteInfo) {
|
|
2053
1856
|
this.logger.success(
|
|
2054
|
-
`\u63A8\u9001\u6210\u529F: ${
|
|
1857
|
+
`\u63A8\u9001\u6210\u529F: ${status.changedFiles} \u4E2A\u6587\u4EF6 \u2192 https://github.com/${remoteInfo.owner}/${remoteInfo.repo}`
|
|
2055
1858
|
);
|
|
2056
1859
|
} else {
|
|
2057
|
-
this.logger.success(`\u63A8\u9001\u6210\u529F: ${
|
|
1860
|
+
this.logger.success(`\u63A8\u9001\u6210\u529F: ${status.changedFiles} \u4E2A\u6587\u4EF6`);
|
|
2058
1861
|
}
|
|
2059
1862
|
} catch (error) {
|
|
2060
1863
|
this.logger.error(`\u63A8\u9001\u5931\u8D25`);
|
|
@@ -2076,83 +1879,6 @@ var GitManager = class {
|
|
|
2076
1879
|
throw error;
|
|
2077
1880
|
}
|
|
2078
1881
|
}
|
|
2079
|
-
// ==================== Submodule 操作 ====================
|
|
2080
|
-
/**
|
|
2081
|
-
* 检查仓库是否包含 submodule
|
|
2082
|
-
*/
|
|
2083
|
-
hasSubmodules() {
|
|
2084
|
-
return existsSync3(resolve2(this.dir, ".gitmodules"));
|
|
2085
|
-
}
|
|
2086
|
-
/**
|
|
2087
|
-
* 获取所有 submodule 的路径
|
|
2088
|
-
*/
|
|
2089
|
-
async getSubmodulePaths() {
|
|
2090
|
-
if (!this.hasSubmodules()) return [];
|
|
2091
|
-
try {
|
|
2092
|
-
const output = await runCommand(
|
|
2093
|
-
"git config --file .gitmodules --get-regexp path",
|
|
2094
|
-
this.dir
|
|
2095
|
-
);
|
|
2096
|
-
return output.trim().split("\n").filter((line) => line).map((line) => line.replace(/^submodule\..*\.path\s+/, ""));
|
|
2097
|
-
} catch {
|
|
2098
|
-
return [];
|
|
2099
|
-
}
|
|
2100
|
-
}
|
|
2101
|
-
/**
|
|
2102
|
-
* 推送前处理 submodule:检查未提交/未推送的更改,自动提交并推送
|
|
2103
|
-
*/
|
|
2104
|
-
async pushSubmodules(commitMessage) {
|
|
2105
|
-
const paths = await this.getSubmodulePaths();
|
|
2106
|
-
if (paths.length === 0) return;
|
|
2107
|
-
for (const subPath of paths) {
|
|
2108
|
-
const absPath = resolve2(this.dir, subPath);
|
|
2109
|
-
let hasChanges = false;
|
|
2110
|
-
try {
|
|
2111
|
-
const status = await runCommand("git status --porcelain", absPath);
|
|
2112
|
-
hasChanges = status.trim().length > 0;
|
|
2113
|
-
} catch {
|
|
2114
|
-
continue;
|
|
2115
|
-
}
|
|
2116
|
-
if (hasChanges) {
|
|
2117
|
-
const message = commitMessage || "update";
|
|
2118
|
-
this.logger.info(`Submodule [${subPath}] \u6709\u672A\u63D0\u4EA4\u7684\u66F4\u6539\uFF0C\u6B63\u5728\u63D0\u4EA4...`);
|
|
2119
|
-
await runCommand("git add -A", absPath);
|
|
2120
|
-
await runCommand(`git commit -m "${message}"`, absPath);
|
|
2121
|
-
}
|
|
2122
|
-
let unpushed = 0;
|
|
2123
|
-
try {
|
|
2124
|
-
const output = await runCommand(
|
|
2125
|
-
"git rev-list @{u}..HEAD --count",
|
|
2126
|
-
absPath
|
|
2127
|
-
);
|
|
2128
|
-
unpushed = parseInt(output.trim()) || 0;
|
|
2129
|
-
} catch {
|
|
2130
|
-
unpushed = 1;
|
|
2131
|
-
}
|
|
2132
|
-
if (unpushed > 0) {
|
|
2133
|
-
this.logger.info(
|
|
2134
|
-
`Submodule [${subPath}] \u6709 ${unpushed} \u4E2A\u672A\u63A8\u9001\u7684\u63D0\u4EA4\uFF0C\u6B63\u5728\u63A8\u9001...`
|
|
2135
|
-
);
|
|
2136
|
-
await runCommand("git push", absPath);
|
|
2137
|
-
this.logger.success(`Submodule [${subPath}] \u63A8\u9001\u6210\u529F`);
|
|
2138
|
-
}
|
|
2139
|
-
}
|
|
2140
|
-
}
|
|
2141
|
-
/**
|
|
2142
|
-
* 拉取后更新 submodule 到父仓库指针指向的 commit
|
|
2143
|
-
*/
|
|
2144
|
-
async updateSubmodules() {
|
|
2145
|
-
if (!this.hasSubmodules()) return;
|
|
2146
|
-
try {
|
|
2147
|
-
this.logger.info("\u6B63\u5728\u66F4\u65B0 submodule...");
|
|
2148
|
-
await runCommand("git submodule update --init", this.dir);
|
|
2149
|
-
this.logger.success("Submodule \u5DF2\u540C\u6B65\u5230\u6700\u65B0\u6307\u9488");
|
|
2150
|
-
} catch (error) {
|
|
2151
|
-
this.logger.warn(
|
|
2152
|
-
"Submodule \u66F4\u65B0\u5931\u8D25\uFF0C\u8BF7\u624B\u52A8\u6267\u884C git submodule update --init"
|
|
2153
|
-
);
|
|
2154
|
-
}
|
|
2155
|
-
}
|
|
2156
1882
|
/**
|
|
2157
1883
|
* 显示状态摘要
|
|
2158
1884
|
*/
|
|
@@ -2381,9 +2107,9 @@ async function safeExecute(label, fn, logger2) {
|
|
|
2381
2107
|
}
|
|
2382
2108
|
|
|
2383
2109
|
// services/file-watcher/watchState.ts
|
|
2384
|
-
import { existsSync as
|
|
2110
|
+
import { existsSync as existsSync3, readFileSync as readFileSync3, readdirSync as readdirSync2, statSync } from "fs";
|
|
2385
2111
|
import { createHash } from "crypto";
|
|
2386
|
-
import { join as
|
|
2112
|
+
import { join as join3 } from "path";
|
|
2387
2113
|
var WatchState = class {
|
|
2388
2114
|
constructor(config2) {
|
|
2389
2115
|
this.config = config2;
|
|
@@ -2402,7 +2128,7 @@ var WatchState = class {
|
|
|
2402
2128
|
*/
|
|
2403
2129
|
getFileHash(filePath) {
|
|
2404
2130
|
try {
|
|
2405
|
-
if (!
|
|
2131
|
+
if (!existsSync3(filePath)) return null;
|
|
2406
2132
|
const content = readFileSync3(filePath, "utf-8");
|
|
2407
2133
|
if (content.length === 0) return null;
|
|
2408
2134
|
return createHash("md5").update(content).digest("hex");
|
|
@@ -2463,8 +2189,8 @@ var WatchState = class {
|
|
|
2463
2189
|
* @param noteDirName 笔记目录名称
|
|
2464
2190
|
*/
|
|
2465
2191
|
clearNoteCaches(noteDirName) {
|
|
2466
|
-
const readmePath =
|
|
2467
|
-
const configPath =
|
|
2192
|
+
const readmePath = join3(this.config.notesDir, noteDirName, "README.md");
|
|
2193
|
+
const configPath = join3(this.config.notesDir, noteDirName, ".tnotes.json");
|
|
2468
2194
|
this.fileHashes.delete(readmePath);
|
|
2469
2195
|
this.fileHashes.delete(configPath);
|
|
2470
2196
|
this.configCache.delete(configPath);
|
|
@@ -2497,7 +2223,7 @@ var WatchState = class {
|
|
|
2497
2223
|
*/
|
|
2498
2224
|
readConfigSnapshot(configPath) {
|
|
2499
2225
|
try {
|
|
2500
|
-
if (!
|
|
2226
|
+
if (!existsSync3(configPath)) return null;
|
|
2501
2227
|
const content = readFileSync3(configPath, "utf-8");
|
|
2502
2228
|
const config2 = JSON.parse(content);
|
|
2503
2229
|
return {
|
|
@@ -2517,16 +2243,16 @@ var WatchState = class {
|
|
|
2517
2243
|
*/
|
|
2518
2244
|
initializeFromDisk() {
|
|
2519
2245
|
try {
|
|
2520
|
-
const noteDirs =
|
|
2246
|
+
const noteDirs = readdirSync2(this.config.notesDir);
|
|
2521
2247
|
this.clearAll();
|
|
2522
2248
|
for (const noteDir of noteDirs) {
|
|
2523
|
-
const noteDirPath =
|
|
2249
|
+
const noteDirPath = join3(this.config.notesDir, noteDir);
|
|
2524
2250
|
if (!statSync(noteDirPath).isDirectory()) continue;
|
|
2525
2251
|
this.noteDirCache.add(noteDir);
|
|
2526
|
-
const readmePath =
|
|
2252
|
+
const readmePath = join3(noteDirPath, "README.md");
|
|
2527
2253
|
const readmeHash = this.getFileHash(readmePath);
|
|
2528
2254
|
if (readmeHash) this.fileHashes.set(readmePath, readmeHash);
|
|
2529
|
-
const configPath =
|
|
2255
|
+
const configPath = join3(noteDirPath, ".tnotes.json");
|
|
2530
2256
|
const configHash = this.getFileHash(configPath);
|
|
2531
2257
|
if (configHash) {
|
|
2532
2258
|
this.fileHashes.set(configPath, configHash);
|
|
@@ -2665,8 +2391,8 @@ var EventScheduler = class {
|
|
|
2665
2391
|
};
|
|
2666
2392
|
|
|
2667
2393
|
// services/file-watcher/renameDetector.ts
|
|
2668
|
-
import { existsSync as
|
|
2669
|
-
import { join as
|
|
2394
|
+
import { existsSync as existsSync4 } from "fs";
|
|
2395
|
+
import { join as join4 } from "path";
|
|
2670
2396
|
var FOLDER_RENAME_DETECT_WINDOW_MS = 500;
|
|
2671
2397
|
var RenameDetector = class {
|
|
2672
2398
|
constructor(config2) {
|
|
@@ -2678,8 +2404,8 @@ var RenameDetector = class {
|
|
|
2678
2404
|
folderRenameTimer = null;
|
|
2679
2405
|
handleFsRename(folderName) {
|
|
2680
2406
|
const { notesDir, dirCache, logger: logger2, onDelete, onRename } = this.config;
|
|
2681
|
-
const folderPath =
|
|
2682
|
-
const folderExists =
|
|
2407
|
+
const folderPath = join4(notesDir, folderName);
|
|
2408
|
+
const folderExists = existsSync4(folderPath);
|
|
2683
2409
|
const noteIndex = NoteManager.extractNoteIndex(folderName);
|
|
2684
2410
|
if (!noteIndex) {
|
|
2685
2411
|
logger2.warn(`\u65E0\u6CD5\u4ECE\u6587\u4EF6\u5939\u540D\u79F0\u63D0\u53D6\u7B14\u8BB0\u7D22\u5F15: ${folderName}`);
|
|
@@ -2816,8 +2542,8 @@ var GlobalUpdateCoordinator = class {
|
|
|
2816
2542
|
};
|
|
2817
2543
|
|
|
2818
2544
|
// services/file-watcher/folderChangeHandler.ts
|
|
2819
|
-
import { existsSync as
|
|
2820
|
-
import { join as
|
|
2545
|
+
import { existsSync as existsSync5, promises as fsPromises } from "fs";
|
|
2546
|
+
import { join as join5 } from "path";
|
|
2821
2547
|
var RENAME_REVERT_DELAY_MS = 2e3;
|
|
2822
2548
|
var DELETE_REINIT_DELAY_MS = 1e3;
|
|
2823
2549
|
var UPDATE_UNLOCK_DELAY_MS = 500;
|
|
@@ -2951,9 +2677,9 @@ var FolderChangeHandler = class {
|
|
|
2951
2677
|
async revertFolderRename(oldName, newName) {
|
|
2952
2678
|
const { notesDir, scheduler, watchState, logger: logger2 } = this.config;
|
|
2953
2679
|
try {
|
|
2954
|
-
const oldPath =
|
|
2955
|
-
const newPath =
|
|
2956
|
-
if (
|
|
2680
|
+
const oldPath = join5(notesDir, oldName);
|
|
2681
|
+
const newPath = join5(notesDir, newName);
|
|
2682
|
+
if (existsSync5(newPath)) {
|
|
2957
2683
|
scheduler.setUpdating(true);
|
|
2958
2684
|
await fsPromises.rename(newPath, oldPath);
|
|
2959
2685
|
logger2.warn(`\u6587\u4EF6\u5939\u5DF2\u56DE\u9000: ${newName} \u2192 ${oldName}`);
|
|
@@ -2978,7 +2704,7 @@ var FolderChangeHandler = class {
|
|
|
2978
2704
|
|
|
2979
2705
|
// services/file-watcher/fsWatcherAdapter.ts
|
|
2980
2706
|
import { watch } from "fs";
|
|
2981
|
-
import { basename, dirname, join as
|
|
2707
|
+
import { basename, dirname, join as join6, sep } from "path";
|
|
2982
2708
|
var FsWatcherAdapter = class {
|
|
2983
2709
|
constructor(config2) {
|
|
2984
2710
|
this.config = config2;
|
|
@@ -3021,7 +2747,7 @@ var FsWatcherAdapter = class {
|
|
|
3021
2747
|
if (baseFilename !== "README.md" && baseFilename !== ".tnotes.json") {
|
|
3022
2748
|
return;
|
|
3023
2749
|
}
|
|
3024
|
-
const fullPath =
|
|
2750
|
+
const fullPath = join6(this.config.notesDir, filename);
|
|
3025
2751
|
const event = this.buildWatchEvent(fullPath, filename);
|
|
3026
2752
|
if (!event) {
|
|
3027
2753
|
return;
|
|
@@ -3048,7 +2774,7 @@ var FsWatcherAdapter = class {
|
|
|
3048
2774
|
|
|
3049
2775
|
// services/readme/service.ts
|
|
3050
2776
|
import {
|
|
3051
|
-
existsSync as
|
|
2777
|
+
existsSync as existsSync6,
|
|
3052
2778
|
readFileSync as readFileSync4,
|
|
3053
2779
|
writeFileSync as writeFileSync3,
|
|
3054
2780
|
promises as fsPromises2
|
|
@@ -3183,7 +2909,7 @@ var ReadmeService = class _ReadmeService {
|
|
|
3183
2909
|
* @param notes - 笔记信息数组
|
|
3184
2910
|
*/
|
|
3185
2911
|
async updateSidebar(notes) {
|
|
3186
|
-
if (!
|
|
2912
|
+
if (!existsSync6(ROOT_README_PATH)) {
|
|
3187
2913
|
logger.error("\u672A\u627E\u5230\u9996\u9875 README\uFF0C\u65E0\u6CD5\u751F\u6210\u4FA7\u8FB9\u680F");
|
|
3188
2914
|
return;
|
|
3189
2915
|
}
|
|
@@ -3369,7 +3095,7 @@ var ReadmeService = class _ReadmeService {
|
|
|
3369
3095
|
|
|
3370
3096
|
// services/note/service.ts
|
|
3371
3097
|
import { writeFileSync as writeFileSync4, readFileSync as readFileSync5 } from "fs";
|
|
3372
|
-
import { join as
|
|
3098
|
+
import { join as join7 } from "path";
|
|
3373
3099
|
import { v4 as uuidv4 } from "uuid";
|
|
3374
3100
|
|
|
3375
3101
|
// config/templates.ts
|
|
@@ -3464,13 +3190,13 @@ var NoteService = class _NoteService {
|
|
|
3464
3190
|
} = options;
|
|
3465
3191
|
const noteIndex = this.generateNextNoteIndex(usedIndexes);
|
|
3466
3192
|
const dirName = `${noteIndex}. ${title}`;
|
|
3467
|
-
const notePath =
|
|
3193
|
+
const notePath = join7(NOTES_PATH, dirName);
|
|
3468
3194
|
await ensureDirectory(notePath);
|
|
3469
|
-
const readmePath =
|
|
3195
|
+
const readmePath = join7(notePath, "README.md");
|
|
3470
3196
|
const noteTitle = generateNoteTitle(noteIndex, title, REPO_NOTES_URL);
|
|
3471
3197
|
const readmeContent = noteTitle + "\n" + NEW_NOTES_README_MD_TEMPLATE;
|
|
3472
3198
|
writeFileSync4(readmePath, readmeContent, "utf-8");
|
|
3473
|
-
const configPath =
|
|
3199
|
+
const configPath = join7(notePath, ".tnotes.json");
|
|
3474
3200
|
const now = Date.now();
|
|
3475
3201
|
const config2 = {
|
|
3476
3202
|
id: configId || uuidv4(),
|
|
@@ -3881,139 +3607,15 @@ var GitService = class {
|
|
|
3881
3607
|
}
|
|
3882
3608
|
};
|
|
3883
3609
|
|
|
3884
|
-
// services/sync-core/service.ts
|
|
3885
|
-
import { existsSync as existsSync8 } from "fs";
|
|
3886
|
-
import { join as join9, basename as basename2 } from "path";
|
|
3887
|
-
var SyncCoreService = class {
|
|
3888
|
-
/**
|
|
3889
|
-
* 同步单个仓库的 submodule 到最新版本
|
|
3890
|
-
*/
|
|
3891
|
-
async syncSingleRepo(targetDir) {
|
|
3892
|
-
const repoName2 = basename2(targetDir);
|
|
3893
|
-
const submodulePath = join9(targetDir, ".vitepress", "tnotes");
|
|
3894
|
-
try {
|
|
3895
|
-
if (!existsSync8(join9(targetDir, ".gitmodules"))) {
|
|
3896
|
-
return {
|
|
3897
|
-
dir: targetDir,
|
|
3898
|
-
repoName: repoName2,
|
|
3899
|
-
success: false,
|
|
3900
|
-
updated: false,
|
|
3901
|
-
error: "\u672A\u627E\u5230 .gitmodules\uFF0C\u8BE5\u4ED3\u5E93\u672A\u914D\u7F6E submodule"
|
|
3902
|
-
};
|
|
3903
|
-
}
|
|
3904
|
-
if (!existsSync8(submodulePath)) {
|
|
3905
|
-
await runCommand("git submodule update --init", targetDir);
|
|
3906
|
-
}
|
|
3907
|
-
const beforeHash = (await runCommand("git rev-parse HEAD", submodulePath)).trim();
|
|
3908
|
-
const beforeTime = (await runCommand("git log -1 --format=%ci HEAD", submodulePath)).trim().replace(/ [+-]\d{4}$/, "");
|
|
3909
|
-
await runCommand("git fetch origin", submodulePath);
|
|
3910
|
-
await runCommand("git reset --hard origin/main", submodulePath);
|
|
3911
|
-
const afterHash = (await runCommand("git rev-parse HEAD", submodulePath)).trim();
|
|
3912
|
-
const afterTime = (await runCommand("git log -1 --format=%ci HEAD", submodulePath)).trim().replace(/ [+-]\d{4}$/, "");
|
|
3913
|
-
const updated = beforeHash !== afterHash;
|
|
3914
|
-
if (updated) {
|
|
3915
|
-
await runCommand("git add .vitepress/tnotes", targetDir);
|
|
3916
|
-
await runCommand(
|
|
3917
|
-
'git commit -m "chore: update tnotesjs/core"',
|
|
3918
|
-
targetDir
|
|
3919
|
-
);
|
|
3920
|
-
}
|
|
3921
|
-
return {
|
|
3922
|
-
dir: targetDir,
|
|
3923
|
-
repoName: repoName2,
|
|
3924
|
-
success: true,
|
|
3925
|
-
updated,
|
|
3926
|
-
beforeHash: beforeHash.substring(0, 7),
|
|
3927
|
-
beforeTime,
|
|
3928
|
-
afterHash: afterHash.substring(0, 7),
|
|
3929
|
-
afterTime
|
|
3930
|
-
};
|
|
3931
|
-
} catch (error) {
|
|
3932
|
-
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
3933
|
-
return {
|
|
3934
|
-
dir: targetDir,
|
|
3935
|
-
repoName: repoName2,
|
|
3936
|
-
success: false,
|
|
3937
|
-
updated: false,
|
|
3938
|
-
error: errorMessage
|
|
3939
|
-
};
|
|
3940
|
-
}
|
|
3941
|
-
}
|
|
3942
|
-
/**
|
|
3943
|
-
* 同步所有兄弟仓库的 tnotesjs/core 到最新版本
|
|
3944
|
-
*/
|
|
3945
|
-
async syncToAllRepos() {
|
|
3946
|
-
try {
|
|
3947
|
-
const targetDirs = getTargetDirs(TNOTES_BASE_DIR, "TNotes.", [
|
|
3948
|
-
ROOT_DIR_PATH,
|
|
3949
|
-
TNOTES_CORE_DIR,
|
|
3950
|
-
EN_WORDS_DIR
|
|
3951
|
-
]);
|
|
3952
|
-
if (targetDirs.length === 0) {
|
|
3953
|
-
logger.warn("\u672A\u627E\u5230\u7B26\u5408\u6761\u4EF6\u7684\u76EE\u6807\u76EE\u5F55");
|
|
3954
|
-
return;
|
|
3955
|
-
}
|
|
3956
|
-
logger.info(`\u6B63\u5728\u540C\u6B65 ${targetDirs.length} \u4E2A\u4ED3\u5E93\u7684 tnotesjs/core...`);
|
|
3957
|
-
console.log();
|
|
3958
|
-
const results = [];
|
|
3959
|
-
for (let i = 0; i < targetDirs.length; i++) {
|
|
3960
|
-
const dir = targetDirs[i];
|
|
3961
|
-
const repoName2 = basename2(dir);
|
|
3962
|
-
logger.info(`[${i + 1}/${targetDirs.length}] ${repoName2}`);
|
|
3963
|
-
const result = await this.syncSingleRepo(dir);
|
|
3964
|
-
results.push(result);
|
|
3965
|
-
if (result.success) {
|
|
3966
|
-
if (result.updated) {
|
|
3967
|
-
logger.success(
|
|
3968
|
-
` \u2713 \u5DF2\u66F4\u65B0 ${result.beforeHash}(${result.beforeTime}) \u2192 ${result.afterHash}(${result.afterTime})
|
|
3969
|
-
`
|
|
3970
|
-
);
|
|
3971
|
-
} else {
|
|
3972
|
-
logger.info(
|
|
3973
|
-
` - \u5DF2\u662F\u6700\u65B0 ${result.afterHash}(${result.afterTime})
|
|
3974
|
-
`
|
|
3975
|
-
);
|
|
3976
|
-
}
|
|
3977
|
-
} else {
|
|
3978
|
-
logger.error(` \u2717 \u5931\u8D25: ${result.error}
|
|
3979
|
-
`);
|
|
3980
|
-
}
|
|
3981
|
-
}
|
|
3982
|
-
const successCount = results.filter((r) => r.success).length;
|
|
3983
|
-
const updatedCount = results.filter((r) => r.updated).length;
|
|
3984
|
-
const failCount = results.length - successCount;
|
|
3985
|
-
console.log("\u2501".repeat(50));
|
|
3986
|
-
if (failCount === 0) {
|
|
3987
|
-
logger.success(
|
|
3988
|
-
`\u2728 \u540C\u6B65\u5B8C\u6210: ${updatedCount} \u4E2A\u4ED3\u5E93\u5DF2\u66F4\u65B0, ${successCount - updatedCount} \u4E2A\u5DF2\u662F\u6700\u65B0 (\u5171 ${results.length} \u4E2A)`
|
|
3989
|
-
);
|
|
3990
|
-
} else {
|
|
3991
|
-
logger.warn(
|
|
3992
|
-
`\u26A0\uFE0F \u540C\u6B65\u5B8C\u6210: ${successCount} \u6210\u529F (${updatedCount} \u66F4\u65B0), ${failCount} \u5931\u8D25 (\u5171 ${results.length} \u4E2A)`
|
|
3993
|
-
);
|
|
3994
|
-
console.log("\n\u5931\u8D25\u7684\u4ED3\u5E93:");
|
|
3995
|
-
results.filter((r) => !r.success).forEach((r, index) => {
|
|
3996
|
-
console.log(` ${index + 1}. ${r.repoName}`);
|
|
3997
|
-
console.log(` \u9519\u8BEF: ${r.error}`);
|
|
3998
|
-
});
|
|
3999
|
-
}
|
|
4000
|
-
} catch (error) {
|
|
4001
|
-
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
4002
|
-
logger.error(`tnotesjs/core \u540C\u6B65\u5931\u8D25: ${errorMessage}`);
|
|
4003
|
-
throw error;
|
|
4004
|
-
}
|
|
4005
|
-
}
|
|
4006
|
-
};
|
|
4007
|
-
|
|
4008
3610
|
// services/timestamp/service.ts
|
|
4009
3611
|
import {
|
|
4010
|
-
existsSync as
|
|
3612
|
+
existsSync as existsSync7,
|
|
4011
3613
|
readFileSync as readFileSync6,
|
|
4012
3614
|
writeFileSync as writeFileSync5,
|
|
4013
|
-
readdirSync as
|
|
3615
|
+
readdirSync as readdirSync3,
|
|
4014
3616
|
statSync as statSync2
|
|
4015
3617
|
} from "fs";
|
|
4016
|
-
import { join as
|
|
3618
|
+
import { join as join8 } from "path";
|
|
4017
3619
|
import { execSync as execSync3 } from "child_process";
|
|
4018
3620
|
var BIRTH_DATE = (/* @__PURE__ */ new Date("1999-06-29T00:00:00+08:00")).getTime();
|
|
4019
3621
|
var TimestampService = class {
|
|
@@ -4028,7 +3630,7 @@ var TimestampService = class {
|
|
|
4028
3630
|
*/
|
|
4029
3631
|
getGitTimestamps(noteDirPath) {
|
|
4030
3632
|
try {
|
|
4031
|
-
const readmePath =
|
|
3633
|
+
const readmePath = join8(noteDirPath, "README.md");
|
|
4032
3634
|
const createdAtOutput = execSync3(
|
|
4033
3635
|
`git log --diff-filter=A --follow --format=%ct -- "${readmePath}"`,
|
|
4034
3636
|
{
|
|
@@ -4065,14 +3667,14 @@ var TimestampService = class {
|
|
|
4065
3667
|
* @returns 是否进行了修复
|
|
4066
3668
|
*/
|
|
4067
3669
|
fixNoteTimestamps(noteDir, forceUpdate = false) {
|
|
4068
|
-
const configPath =
|
|
4069
|
-
if (!
|
|
3670
|
+
const configPath = join8(NOTES_DIR_PATH, noteDir, ".tnotes.json");
|
|
3671
|
+
if (!existsSync7(configPath)) {
|
|
4070
3672
|
return false;
|
|
4071
3673
|
}
|
|
4072
3674
|
try {
|
|
4073
3675
|
const configContent = readFileSync6(configPath, "utf-8");
|
|
4074
3676
|
const config2 = JSON.parse(configContent);
|
|
4075
|
-
const noteDirPath =
|
|
3677
|
+
const noteDirPath = join8(NOTES_DIR_PATH, noteDir);
|
|
4076
3678
|
const timestamps = this.getGitTimestamps(noteDirPath);
|
|
4077
3679
|
if (!timestamps) {
|
|
4078
3680
|
return false;
|
|
@@ -4171,12 +3773,12 @@ var TimestampService = class {
|
|
|
4171
3773
|
if (rootConfigFixed) {
|
|
4172
3774
|
logger.success("\u2705 \u6839\u914D\u7F6E\u6587\u4EF6\u65F6\u95F4\u6233\u5DF2\u4FEE\u590D");
|
|
4173
3775
|
}
|
|
4174
|
-
if (!
|
|
3776
|
+
if (!existsSync7(NOTES_DIR_PATH)) {
|
|
4175
3777
|
logger.error("notes \u76EE\u5F55\u4E0D\u5B58\u5728");
|
|
4176
3778
|
return { fixed: 0, skipped: 0, total: 0, rootConfigFixed };
|
|
4177
3779
|
}
|
|
4178
|
-
const noteDirs =
|
|
4179
|
-
const fullPath =
|
|
3780
|
+
const noteDirs = readdirSync3(NOTES_DIR_PATH).filter((name) => {
|
|
3781
|
+
const fullPath = join8(NOTES_DIR_PATH, name);
|
|
4180
3782
|
return statSync2(fullPath).isDirectory() && /^\d{4}\./.test(name);
|
|
4181
3783
|
}).sort();
|
|
4182
3784
|
let fixedCount = 0;
|
|
@@ -4213,8 +3815,8 @@ var TimestampService = class {
|
|
|
4213
3815
|
const now = Date.now();
|
|
4214
3816
|
let updatedCount = 0;
|
|
4215
3817
|
for (const noteDir of noteDirNames) {
|
|
4216
|
-
const configPath =
|
|
4217
|
-
if (!
|
|
3818
|
+
const configPath = join8(NOTES_DIR_PATH, noteDir, ".tnotes.json");
|
|
3819
|
+
if (!existsSync7(configPath)) {
|
|
4218
3820
|
continue;
|
|
4219
3821
|
}
|
|
4220
3822
|
try {
|
|
@@ -4285,7 +3887,7 @@ var VitepressService = class _VitepressService {
|
|
|
4285
3887
|
if (this.processManager.has(processId) && this.processManager.isRunning(processId)) {
|
|
4286
3888
|
this.processManager.kill(processId);
|
|
4287
3889
|
await new Promise(
|
|
4288
|
-
(
|
|
3890
|
+
(resolve2) => setTimeout(resolve2, _VitepressService.PROCESS_CLEANUP_DELAY)
|
|
4289
3891
|
);
|
|
4290
3892
|
}
|
|
4291
3893
|
if (isPortInUse(port2)) {
|
|
@@ -4323,7 +3925,7 @@ var VitepressService = class _VitepressService {
|
|
|
4323
3925
|
* @param childProcess - 子进程
|
|
4324
3926
|
*/
|
|
4325
3927
|
waitForServerReady(childProcess) {
|
|
4326
|
-
return new Promise((
|
|
3928
|
+
return new Promise((resolve2) => {
|
|
4327
3929
|
const startTime = Date.now();
|
|
4328
3930
|
let serverReady = false;
|
|
4329
3931
|
let version = "";
|
|
@@ -4350,7 +3952,7 @@ var VitepressService = class _VitepressService {
|
|
|
4350
3952
|
process.stderr.clearLine?.(0);
|
|
4351
3953
|
process.stderr.cursorTo?.(0);
|
|
4352
3954
|
const elapsed = Date.now() - startTime;
|
|
4353
|
-
setTimeout(() =>
|
|
3955
|
+
setTimeout(() => resolve2({ version, elapsed }), 200);
|
|
4354
3956
|
return;
|
|
4355
3957
|
}
|
|
4356
3958
|
if (!serverReady) {
|
|
@@ -4376,7 +3978,7 @@ var VitepressService = class _VitepressService {
|
|
|
4376
3978
|
process.stderr.clearLine?.(0);
|
|
4377
3979
|
process.stderr.cursorTo?.(0);
|
|
4378
3980
|
logger.warn("\u542F\u52A8\u8D85\u65F6\uFF0C\u8BF7\u68C0\u67E5 VitePress \u8F93\u51FA");
|
|
4379
|
-
|
|
3981
|
+
resolve2({ version, elapsed: _VitepressService.SERVER_STARTUP_TIMEOUT });
|
|
4380
3982
|
}
|
|
4381
3983
|
}, _VitepressService.SERVER_STARTUP_TIMEOUT);
|
|
4382
3984
|
});
|
|
@@ -4385,7 +3987,7 @@ var VitepressService = class _VitepressService {
|
|
|
4385
3987
|
* 构建生产版本
|
|
4386
3988
|
*/
|
|
4387
3989
|
build() {
|
|
4388
|
-
return new Promise((
|
|
3990
|
+
return new Promise((resolve2, reject) => {
|
|
4389
3991
|
const pm = this.configManager.get("packageManager") || _VitepressService.DEFAULT_PACKAGE_MANAGER;
|
|
4390
3992
|
const child = spawn2(pm, ["vitepress", "build"], {
|
|
4391
3993
|
cwd: ROOT_DIR_PATH,
|
|
@@ -4409,7 +4011,7 @@ var VitepressService = class _VitepressService {
|
|
|
4409
4011
|
});
|
|
4410
4012
|
child.on("close", (code) => {
|
|
4411
4013
|
if (code === 0) {
|
|
4412
|
-
|
|
4014
|
+
resolve2();
|
|
4413
4015
|
} else {
|
|
4414
4016
|
reject(new Error(`Command failed with code ${code}`));
|
|
4415
4017
|
}
|
|
@@ -4504,8 +4106,8 @@ var UpdateNoteConfigCommand = class extends BaseCommand {
|
|
|
4504
4106
|
};
|
|
4505
4107
|
|
|
4506
4108
|
// commands/note/RenameNoteCommand.ts
|
|
4507
|
-
import { existsSync as
|
|
4508
|
-
import { join as
|
|
4109
|
+
import { existsSync as existsSync8, renameSync, readFileSync as readFileSync7, writeFileSync as writeFileSync6 } from "fs";
|
|
4110
|
+
import { join as join9 } from "path";
|
|
4509
4111
|
var RenameNoteCommand = class extends BaseCommand {
|
|
4510
4112
|
noteService;
|
|
4511
4113
|
readmeService;
|
|
@@ -4542,8 +4144,8 @@ var RenameNoteCommand = class extends BaseCommand {
|
|
|
4542
4144
|
throw new Error(validation.error || "\u6807\u9898\u683C\u5F0F\u65E0\u6548");
|
|
4543
4145
|
}
|
|
4544
4146
|
const newDirName = `${noteIndex}. ${newTitle.trim()}`;
|
|
4545
|
-
const newPath =
|
|
4546
|
-
if (
|
|
4147
|
+
const newPath = join9(NOTES_PATH, newDirName);
|
|
4148
|
+
if (existsSync8(newPath)) {
|
|
4547
4149
|
throw new Error(`\u76EE\u6807\u6587\u4EF6\u5939\u5DF2\u5B58\u5728: ${newDirName}`);
|
|
4548
4150
|
}
|
|
4549
4151
|
try {
|
|
@@ -4558,8 +4160,8 @@ var RenameNoteCommand = class extends BaseCommand {
|
|
|
4558
4160
|
}
|
|
4559
4161
|
try {
|
|
4560
4162
|
this.logger.info("\u6B63\u5728\u66F4\u65B0\u7B14\u8BB0\u5185\u90E8\u6807\u9898...");
|
|
4561
|
-
const readmePath =
|
|
4562
|
-
if (
|
|
4163
|
+
const readmePath = join9(newPath, "README.md");
|
|
4164
|
+
if (existsSync8(readmePath)) {
|
|
4563
4165
|
const content = readFileSync7(readmePath, "utf-8");
|
|
4564
4166
|
const lines = content.split("\n");
|
|
4565
4167
|
let h1Index = -1;
|
|
@@ -4603,27 +4205,19 @@ export {
|
|
|
4603
4205
|
COMMAND_OPTIONS,
|
|
4604
4206
|
handleError,
|
|
4605
4207
|
generateAnchor,
|
|
4606
|
-
getTargetDirs,
|
|
4607
4208
|
logger,
|
|
4608
4209
|
createLogger,
|
|
4609
4210
|
parseArgs,
|
|
4610
4211
|
parseReadmeCompletedNotes,
|
|
4611
|
-
TNOTES_BASE_DIR,
|
|
4612
|
-
EN_WORDS_DIR,
|
|
4613
4212
|
ROOT_DIR_PATH,
|
|
4614
4213
|
ROOT_CONFIG_PATH,
|
|
4615
4214
|
NoteManager,
|
|
4616
|
-
runCommand,
|
|
4617
|
-
pushAllRepos,
|
|
4618
|
-
pullAllRepos,
|
|
4619
|
-
syncAllRepos,
|
|
4620
4215
|
BaseCommand,
|
|
4621
4216
|
NoteIndexCache,
|
|
4622
4217
|
ReadmeService,
|
|
4623
4218
|
NoteService,
|
|
4624
4219
|
FileWatcherService,
|
|
4625
4220
|
GitService,
|
|
4626
|
-
SyncCoreService,
|
|
4627
4221
|
TimestampService,
|
|
4628
4222
|
VitepressService,
|
|
4629
4223
|
UpdateNoteConfigCommand,
|