@tnotesjs/core 0.4.2 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunk-3R7QSABB.cjs +502 -0
- package/dist/chunk-CZXRQPFJ.js +11 -0
- package/dist/{chunk-XCWFZLER.js → chunk-DUTS75WQ.js} +27 -493
- package/dist/chunk-HXED7KVT.cjs +11 -0
- package/dist/chunk-IHFUHB4J.cjs +176 -0
- package/dist/chunk-MZIXIY2Y.cjs +216 -0
- package/dist/chunk-TJ4527KA.cjs +5264 -0
- package/dist/chunk-U6IBLREL.js +502 -0
- package/dist/chunk-UNFSW5C2.js +176 -0
- package/dist/cli/index.cjs +936 -0
- package/dist/cli/index.d.cts +2 -0
- package/dist/cli/index.d.ts +2 -0
- package/dist/cli/index.js +9 -6
- package/dist/index.cjs +8 -0
- package/dist/index.d.cts +56 -0
- package/dist/index.d.ts +56 -0
- package/dist/markdown/index.cjs +82 -0
- package/dist/markdown/index.d.cts +36 -0
- package/dist/markdown/index.d.ts +36 -0
- package/dist/markdown/index.js +82 -0
- package/dist/note-oGm44Rw8.d.cts +84 -0
- package/dist/note-oGm44Rw8.d.ts +84 -0
- package/dist/types-CpsEy8lA.d.cts +221 -0
- package/dist/types-CwBWwNVv.d.ts +221 -0
- package/dist/vitepress/config/index.cjs +1669 -0
- package/dist/vitepress/config/index.d.cts +12 -0
- package/dist/vitepress/config/index.d.ts +12 -0
- package/dist/vitepress/config/index.js +26 -192
- package/dist/workspace/index.cjs +1207 -0
- package/dist/workspace/index.d.cts +14 -0
- package/dist/workspace/index.d.ts +14 -0
- package/dist/workspace/index.js +1207 -0
- package/package.json +16 -3
- package/vitepress/components/MindmapPreview/MindmapPreview.vue +189 -34
- package/vitepress/components/MindmapPreview/MindmapViewIcon.vue +41 -0
- package/vitepress/components/MindmapPreview/markdown.test.ts +67 -0
- package/vitepress/components/MindmapPreview/markdown.ts +83 -0
- package/vitepress/components/MindmapPreview/wheelInteraction.test.ts +23 -0
- package/vitepress/components/MindmapPreview/wheelInteraction.ts +7 -0
- package/vitepress/components/Settings/Settings.vue +3 -3
- package/vitepress/components/SidebarCard/SidebarCard.vue +3 -3
- package/vitepress/components/constants.ts +0 -5
- package/vitepress/configs/markdown.config.ts +6 -199
- package/vitepress/plugins/localSearchReindexLogic.ts +11 -3
- package/vitepress/theme/index.ts +0 -2
- package/vitepress/components/MindmapPreview/compat.test.ts +0 -93
- package/vitepress/components/MindmapPreview/compat.ts +0 -128
- package/vitepress/components/MindmapPreview/legacyCorpus.test.ts +0 -57
|
@@ -0,0 +1,936 @@
|
|
|
1
|
+
"use strict"; function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
var _chunkTJ4527KAcjs = require('../chunk-TJ4527KA.cjs');
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
var _chunkMZIXIY2Ycjs = require('../chunk-MZIXIY2Y.cjs');
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
var _chunk3R7QSABBcjs = require('../chunk-3R7QSABB.cjs');
|
|
51
|
+
require('../chunk-HXED7KVT.cjs');
|
|
52
|
+
|
|
53
|
+
// commands/update/UpdateCommand.ts
|
|
54
|
+
var _fs = require('fs');
|
|
55
|
+
var UpdateCommand = class extends _chunkTJ4527KAcjs.BaseCommand {
|
|
56
|
+
constructor() {
|
|
57
|
+
super("update");
|
|
58
|
+
this.quiet = false;
|
|
59
|
+
this.readmeService = _chunkTJ4527KAcjs.ReadmeService.getInstance();
|
|
60
|
+
this.noteService = _chunkTJ4527KAcjs.NoteService.getInstance();
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* 设置 quiet 模式
|
|
64
|
+
*
|
|
65
|
+
* 在 quiet 模式下,只显示 WARN 级别以上的日志
|
|
66
|
+
*/
|
|
67
|
+
setQuiet(quiet) {
|
|
68
|
+
this.quiet = quiet;
|
|
69
|
+
if (quiet) {
|
|
70
|
+
_chunkTJ4527KAcjs.logger.setLevel(2 /* WARN */);
|
|
71
|
+
} else {
|
|
72
|
+
_chunkTJ4527KAcjs.logger.setLevel(1 /* INFO */);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
async run() {
|
|
76
|
+
await this.updateCurrentRepo();
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* 更新当前知识库
|
|
80
|
+
*/
|
|
81
|
+
async updateCurrentRepo() {
|
|
82
|
+
const startTime = Date.now();
|
|
83
|
+
const notes = this.noteService.getAllNotes();
|
|
84
|
+
if (!this.quiet) {
|
|
85
|
+
this.logger.info("\u6B63\u5728\u4FEE\u6B63\u7B14\u8BB0\u6807\u9898...");
|
|
86
|
+
}
|
|
87
|
+
const fixedCount = await this.noteService.fixAllNoteTitles(notes);
|
|
88
|
+
if (!this.quiet && fixedCount > 0) {
|
|
89
|
+
this.logger.success(`\u4FEE\u6B63\u4E86 ${fixedCount} \u4E2A\u7B14\u8BB0\u6807\u9898`);
|
|
90
|
+
}
|
|
91
|
+
await this.readmeService.updateAllReadmes({ notes });
|
|
92
|
+
await this.updateRootItem();
|
|
93
|
+
const duration = Date.now() - startTime;
|
|
94
|
+
if (this.quiet) {
|
|
95
|
+
this.logger.success(`\u77E5\u8BC6\u5E93\u66F4\u65B0\u5B8C\u6210 (${duration}ms)`);
|
|
96
|
+
} else {
|
|
97
|
+
this.logger.success("\u77E5\u8BC6\u5E93\u66F4\u65B0\u5B8C\u6210");
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* 更新 root_item 配置
|
|
102
|
+
* 更新当前月份的完成笔记数量,并自动补齐从最后已有月份到当前月份之间的所有缺失月份。
|
|
103
|
+
*/
|
|
104
|
+
async updateRootItem() {
|
|
105
|
+
try {
|
|
106
|
+
const configContent = _fs.readFileSync.call(void 0, _chunkTJ4527KAcjs.ROOT_CONFIG_PATH, "utf-8");
|
|
107
|
+
const config = JSON.parse(configContent);
|
|
108
|
+
if (!_fs.existsSync.call(void 0, _chunkTJ4527KAcjs.ROOT_TOC_PATH)) {
|
|
109
|
+
throw new Error("\u6839\u76EE\u5F55 TOC.md \u4E0D\u5B58\u5728");
|
|
110
|
+
}
|
|
111
|
+
const tocContent = _fs.readFileSync.call(void 0, _chunkTJ4527KAcjs.ROOT_TOC_PATH, "utf-8");
|
|
112
|
+
const { completedCount } = _chunk3R7QSABBcjs.parseTocCompletedNotes.call(void 0, tocContent);
|
|
113
|
+
const now = /* @__PURE__ */ new Date();
|
|
114
|
+
const yearShort = String(now.getFullYear()).slice(-2);
|
|
115
|
+
const monthStr = String(now.getMonth() + 1).padStart(2, "0");
|
|
116
|
+
const currentKey = `${yearShort}.${monthStr}`;
|
|
117
|
+
const existing = { ...config.root_item.completed_notes_count || {} };
|
|
118
|
+
const _countsBeforeFix = Object.keys(existing).length;
|
|
119
|
+
existing[currentKey] = completedCount;
|
|
120
|
+
const fixed = fillMissingMonthGaps(existing, currentKey);
|
|
121
|
+
config.root_item = {
|
|
122
|
+
...config.root_item,
|
|
123
|
+
completed_notes_count: fixed
|
|
124
|
+
};
|
|
125
|
+
delete config.root_item.completed_notes_count_last_month;
|
|
126
|
+
_chunkMZIXIY2Ycjs.stripDeprecatedRootItemFields.call(void 0,
|
|
127
|
+
config.root_item
|
|
128
|
+
);
|
|
129
|
+
_fs.writeFileSync.call(void 0, _chunkTJ4527KAcjs.ROOT_CONFIG_PATH, JSON.stringify(config, null, 2), "utf-8");
|
|
130
|
+
if (!this.quiet) {
|
|
131
|
+
const filledCount = Object.keys(fixed).length - _countsBeforeFix;
|
|
132
|
+
const filledMsg = filledCount > 0 ? `\uFF0C\u8865\u9F50 ${filledCount} \u4E2A\u7F3A\u5931\u6708\u4EFD` : "";
|
|
133
|
+
this.logger.success(
|
|
134
|
+
`root_item \u914D\u7F6E\u5DF2\u66F4\u65B0: ${currentKey} \u6708\u5B8C\u6210 ${completedCount} \u7BC7\u7B14\u8BB0${filledMsg}`
|
|
135
|
+
);
|
|
136
|
+
}
|
|
137
|
+
} catch (error) {
|
|
138
|
+
if (!this.quiet) {
|
|
139
|
+
this.logger.error(
|
|
140
|
+
`\u66F4\u65B0 root_item \u5931\u8D25: ${error instanceof Error ? error.message : String(error)}`
|
|
141
|
+
);
|
|
142
|
+
}
|
|
143
|
+
throw error;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
function fillMissingMonthGaps(counts, currentKey) {
|
|
148
|
+
const existingKeys = Object.keys(counts).sort();
|
|
149
|
+
const result = {};
|
|
150
|
+
const keySet = new Set(existingKeys);
|
|
151
|
+
keySet.add(currentKey);
|
|
152
|
+
const allKeys = Array.from(keySet).sort();
|
|
153
|
+
let prevValue = 0;
|
|
154
|
+
let lastKey = null;
|
|
155
|
+
for (const key of allKeys) {
|
|
156
|
+
if (lastKey !== null) {
|
|
157
|
+
const missing = generateMissingMonthKeys(lastKey, key);
|
|
158
|
+
for (const midKey of missing) {
|
|
159
|
+
result[midKey] = prevValue;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
result[key] = _nullishCoalesce(counts[key], () => ( prevValue));
|
|
163
|
+
prevValue = result[key];
|
|
164
|
+
lastKey = key;
|
|
165
|
+
}
|
|
166
|
+
return result;
|
|
167
|
+
}
|
|
168
|
+
function generateMissingMonthKeys(fromKey, toKey) {
|
|
169
|
+
const parseKey = (key) => {
|
|
170
|
+
const [yy, mm] = key.split(".").map(Number);
|
|
171
|
+
return { year: 2e3 + yy, month: mm };
|
|
172
|
+
};
|
|
173
|
+
const from = parseKey(fromKey);
|
|
174
|
+
const to = parseKey(toKey);
|
|
175
|
+
const missing = [];
|
|
176
|
+
let year = from.year;
|
|
177
|
+
let month = from.month;
|
|
178
|
+
while (true) {
|
|
179
|
+
month++;
|
|
180
|
+
if (month > 12) {
|
|
181
|
+
month = 1;
|
|
182
|
+
year++;
|
|
183
|
+
}
|
|
184
|
+
const shortYear = String(year).slice(-2);
|
|
185
|
+
const paddedMonth = String(month).padStart(2, "0");
|
|
186
|
+
const candidateKey = `${shortYear}.${paddedMonth}`;
|
|
187
|
+
if (candidateKey === toKey) break;
|
|
188
|
+
if (year > to.year || year === to.year && month > to.month) break;
|
|
189
|
+
missing.push(candidateKey);
|
|
190
|
+
}
|
|
191
|
+
return missing;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
// commands/git/PushCommand.ts
|
|
195
|
+
var PushCommand = class extends _chunkTJ4527KAcjs.BaseCommand {
|
|
196
|
+
constructor() {
|
|
197
|
+
super("push");
|
|
198
|
+
this.gitManager = new (0, _chunkTJ4527KAcjs.GitManager)(_chunkTJ4527KAcjs.ROOT_DIR_PATH);
|
|
199
|
+
this.gitService = new (0, _chunkTJ4527KAcjs.GitService)();
|
|
200
|
+
}
|
|
201
|
+
async run() {
|
|
202
|
+
try {
|
|
203
|
+
this.logger.info("\u68C0\u67E5\u662F\u5426\u6709\u66F4\u6539...");
|
|
204
|
+
const status = await this.gitManager.getStatus();
|
|
205
|
+
const hasPendingCommits = (_nullishCoalesce(status.ahead, () => ( 0))) > 0;
|
|
206
|
+
if (!status.hasChanges && !hasPendingCommits) {
|
|
207
|
+
this.logger.info("\u6CA1\u6709\u66F4\u6539\u9700\u8981\u63A8\u9001");
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
210
|
+
const force = this.options.force === true;
|
|
211
|
+
if (force) {
|
|
212
|
+
this.logger.warn("\u4F7F\u7528\u5F3A\u5236\u63A8\u9001\u6A21\u5F0F (--force)");
|
|
213
|
+
}
|
|
214
|
+
if (status.hasChanges) {
|
|
215
|
+
this.logger.info(
|
|
216
|
+
`\u68C0\u6D4B\u5230 ${status.files.length} \u4E2A\u53D8\u66F4\u6587\u4EF6\uFF0C\u6B63\u5728\u63D0\u4EA4...`
|
|
217
|
+
);
|
|
218
|
+
const commitMessage = this.gitService.generateCommitMessage();
|
|
219
|
+
await _chunkTJ4527KAcjs.runCommand.call(void 0, "git add -A", _chunkTJ4527KAcjs.ROOT_DIR_PATH);
|
|
220
|
+
await _chunkTJ4527KAcjs.runCommand.call(void 0, `git commit -m "${commitMessage}"`, _chunkTJ4527KAcjs.ROOT_DIR_PATH);
|
|
221
|
+
} else {
|
|
222
|
+
this.logger.info(`\u68C0\u6D4B\u5230 ${status.ahead} \u4E2A\u672A\u63A8\u9001\u7684\u63D0\u4EA4\uFF0C\u76F4\u63A5\u63A8\u9001...`);
|
|
223
|
+
}
|
|
224
|
+
this.logger.info("\u6B63\u5728\u63A8\u9001\u5230\u8FDC\u7A0B\u4ED3\u5E93...");
|
|
225
|
+
const pushCmd = force ? "git push --force" : "git push";
|
|
226
|
+
await _chunkTJ4527KAcjs.runCommand.call(void 0, pushCmd, _chunkTJ4527KAcjs.ROOT_DIR_PATH);
|
|
227
|
+
this.logger.success("\u63A8\u9001\u5B8C\u6210");
|
|
228
|
+
} catch (error) {
|
|
229
|
+
this.logger.error("\u63A8\u9001\u5931\u8D25:", error);
|
|
230
|
+
throw error;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
};
|
|
234
|
+
|
|
235
|
+
// commands/git/PullCommand.ts
|
|
236
|
+
var PullCommand = class extends _chunkTJ4527KAcjs.BaseCommand {
|
|
237
|
+
constructor() {
|
|
238
|
+
super("pull");
|
|
239
|
+
this.gitService = new (0, _chunkTJ4527KAcjs.GitService)();
|
|
240
|
+
}
|
|
241
|
+
async run() {
|
|
242
|
+
this.logger.info("\u6B63\u5728\u4ECE\u8FDC\u7A0B\u4ED3\u5E93\u62C9\u53D6...");
|
|
243
|
+
await this.gitService.pull();
|
|
244
|
+
this.logger.success("\u62C9\u53D6\u5B8C\u6210");
|
|
245
|
+
}
|
|
246
|
+
};
|
|
247
|
+
|
|
248
|
+
// commands/build/BuildCommand.ts
|
|
249
|
+
var BuildCommand = class extends _chunkTJ4527KAcjs.BaseCommand {
|
|
250
|
+
constructor() {
|
|
251
|
+
super("build");
|
|
252
|
+
this.vitepressService = new (0, _chunkTJ4527KAcjs.VitepressService)();
|
|
253
|
+
}
|
|
254
|
+
async run() {
|
|
255
|
+
this.logger.info("\u5F00\u59CB\u6784\u5EFA\u77E5\u8BC6\u5E93...");
|
|
256
|
+
await this.vitepressService.build();
|
|
257
|
+
this.logger.success("\u77E5\u8BC6\u5E93\u6784\u5EFA\u5B8C\u6210");
|
|
258
|
+
}
|
|
259
|
+
};
|
|
260
|
+
|
|
261
|
+
// commands/build/PreviewCommand.ts
|
|
262
|
+
var PreviewCommand = class extends _chunkTJ4527KAcjs.BaseCommand {
|
|
263
|
+
constructor() {
|
|
264
|
+
super("preview");
|
|
265
|
+
this.vitepressService = new (0, _chunkTJ4527KAcjs.VitepressService)();
|
|
266
|
+
}
|
|
267
|
+
async run() {
|
|
268
|
+
this.logger.info("\u542F\u52A8\u9884\u89C8\u670D\u52A1\u5668...");
|
|
269
|
+
const pid = await this.vitepressService.preview();
|
|
270
|
+
if (pid) {
|
|
271
|
+
this.logger.success(`\u9884\u89C8\u670D\u52A1\u5668\u5DF2\u542F\u52A8 (PID: ${pid})`);
|
|
272
|
+
} else {
|
|
273
|
+
this.logger.error("\u542F\u52A8\u9884\u89C8\u670D\u52A1\u5668\u5931\u8D25");
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
};
|
|
277
|
+
|
|
278
|
+
// commands/dev/DevCommand.ts
|
|
279
|
+
var DevCommand = class extends _chunkTJ4527KAcjs.BaseCommand {
|
|
280
|
+
constructor() {
|
|
281
|
+
super("dev");
|
|
282
|
+
this.configManager = _chunkMZIXIY2Ycjs.ConfigManager.getInstance();
|
|
283
|
+
this.fileWatcherService = new (0, _chunkTJ4527KAcjs.FileWatcherService)();
|
|
284
|
+
this.noteIndexCache = _chunkTJ4527KAcjs.NoteIndexCache.getInstance();
|
|
285
|
+
this.noteManager = _chunkTJ4527KAcjs.NoteManager.getInstance();
|
|
286
|
+
this.tocService = _chunkTJ4527KAcjs.TocService.getInstance();
|
|
287
|
+
this.vitepressService = new (0, _chunkTJ4527KAcjs.VitepressService)();
|
|
288
|
+
}
|
|
289
|
+
async run() {
|
|
290
|
+
const notes = this.noteManager.scanNotes();
|
|
291
|
+
this.logger.info(`\u626B\u63CF\u5230 ${notes.length} \u7BC7\u7B14\u8BB0`);
|
|
292
|
+
this.noteIndexCache.initialize(notes);
|
|
293
|
+
this.tocService.ensureTocExists();
|
|
294
|
+
await this.tocService.regenerateSidebar(notes);
|
|
295
|
+
const result = await this.vitepressService.startServer();
|
|
296
|
+
if (result) {
|
|
297
|
+
const versionInfo = result.version ? `\uFF08v${result.version}\uFF09` : "";
|
|
298
|
+
this.logger.success(
|
|
299
|
+
`VitePress \u670D\u52A1${versionInfo}\u5DF2\u5C31\u7EEA\uFF0C\u8017\u65F6\uFF1A${result.elapsed} ms`
|
|
300
|
+
);
|
|
301
|
+
const watcherStart = Date.now();
|
|
302
|
+
this.fileWatcherService.start();
|
|
303
|
+
const watcherElapsed = Date.now() - watcherStart;
|
|
304
|
+
this.logger.success(`\u6587\u4EF6\u76D1\u542C\u670D\u52A1\u5DF2\u5C31\u7EEA\uFF0C\u8017\u65F6\uFF1A${watcherElapsed} ms`);
|
|
305
|
+
const port2 = this.configManager.get("port") || _chunkTJ4527KAcjs.VitepressService.DEFAULT_DEV_PORT;
|
|
306
|
+
const repoName2 = this.configManager.get("repoName");
|
|
307
|
+
this.logger.info(
|
|
308
|
+
`\u672C\u5730\u5F00\u53D1\u670D\u52A1\u5730\u5740\uFF1Ahttp://localhost:${port2}/${repoName2}/`
|
|
309
|
+
);
|
|
310
|
+
} else {
|
|
311
|
+
this.logger.error("\u542F\u52A8\u670D\u52A1\u5668\u5931\u8D25");
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
};
|
|
315
|
+
|
|
316
|
+
// commands/init-sub-repo/InitSubRepoCommand.ts
|
|
317
|
+
|
|
318
|
+
var _path = require('path');
|
|
319
|
+
var _readline = require('readline');
|
|
320
|
+
var _url = require('url');
|
|
321
|
+
var _uuid = require('uuid');
|
|
322
|
+
function readCoreVersion() {
|
|
323
|
+
const moduleDir = _path.dirname.call(void 0, _url.fileURLToPath.call(void 0, import.meta.url));
|
|
324
|
+
let dir = moduleDir;
|
|
325
|
+
while (dir !== _path.dirname.call(void 0, dir)) {
|
|
326
|
+
const pkgPath = _path.join.call(void 0, dir, "package.json");
|
|
327
|
+
try {
|
|
328
|
+
const pkg = JSON.parse(_fs.readFileSync.call(void 0, pkgPath, "utf-8"));
|
|
329
|
+
if (pkg.name === "@tnotesjs/core" && pkg.version) return pkg.version;
|
|
330
|
+
} catch (e2) {
|
|
331
|
+
}
|
|
332
|
+
dir = _path.dirname.call(void 0, dir);
|
|
333
|
+
}
|
|
334
|
+
return "0.1.28";
|
|
335
|
+
}
|
|
336
|
+
var InitSubRepoCommand = class extends _chunkTJ4527KAcjs.BaseCommand {
|
|
337
|
+
constructor() {
|
|
338
|
+
super("init-sub-repo");
|
|
339
|
+
this.rootPath = process.cwd();
|
|
340
|
+
}
|
|
341
|
+
async run() {
|
|
342
|
+
if (_chunkTJ4527KAcjs.isAlreadyInitialized.call(void 0, this.rootPath)) {
|
|
343
|
+
const configPath = _chunkTJ4527KAcjs.getInitializedConfigPath.call(void 0, this.rootPath);
|
|
344
|
+
this.logger.info(
|
|
345
|
+
`\u68C0\u6D4B\u5230 .tnotes.json \u914D\u7F6E\u6587\u4EF6\uFF1A${configPath}\uFF0C\u5F53\u524D\u4ED3\u5E93\u5DF2\u7ECF\u662F\u4E00\u4E2A TNotes \u77E5\u8BC6\u5E93`
|
|
346
|
+
);
|
|
347
|
+
return;
|
|
348
|
+
}
|
|
349
|
+
this.logger.info("\u521D\u59CB\u5316 TNotes \u5B50\u77E5\u8BC6\u5E93");
|
|
350
|
+
this.logger.info("");
|
|
351
|
+
const input = await this.promptForInput();
|
|
352
|
+
const ctx = _chunkTJ4527KAcjs.buildInitContext.call(void 0, input);
|
|
353
|
+
this.logger.info("");
|
|
354
|
+
this.logger.info("\u5373\u5C06\u521B\u5EFA\u4EE5\u4E0B\u77E5\u8BC6\u5E93\uFF1A");
|
|
355
|
+
this.logger.info(` \u4ED3\u5E93\u540D\uFF1A${ctx.repoName}`);
|
|
356
|
+
this.logger.info(` \u5C55\u793A\u540D\uFF1A${ctx.displayName}`);
|
|
357
|
+
this.logger.info(` \u7AEF\u53E3\uFF1A${ctx.port}`);
|
|
358
|
+
this.logger.info(` \u63CF\u8FF0\uFF1A${ctx.description}`);
|
|
359
|
+
this.logger.info("");
|
|
360
|
+
const confirmed = await this.promptConfirm("\u786E\u8BA4\u521D\u59CB\u5316\uFF1F [Y/n] ");
|
|
361
|
+
if (!confirmed) {
|
|
362
|
+
this.logger.info("\u5DF2\u53D6\u6D88\u521D\u59CB\u5316");
|
|
363
|
+
return;
|
|
364
|
+
}
|
|
365
|
+
const service = _chunkTJ4527KAcjs.InitSubRepoService.fromModuleUrl(import.meta.url, this.rootPath);
|
|
366
|
+
const result = service.writeScaffold(input);
|
|
367
|
+
if (result.created.length > 0) {
|
|
368
|
+
this.logger.success(`\u5DF2\u521B\u5EFA ${result.created.length} \u4E2A\u6587\u4EF6\uFF1A`);
|
|
369
|
+
for (const file of result.created) {
|
|
370
|
+
this.logger.info(` + ${file}`);
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
if (result.updated.length > 0) {
|
|
374
|
+
this.logger.success(`\u5DF2\u66F4\u65B0 ${result.updated.length} \u4E2A\u6587\u4EF6\uFF1A`);
|
|
375
|
+
for (const file of result.updated) {
|
|
376
|
+
this.logger.info(` ~ ${file}`);
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
if (result.skipped.length > 0) {
|
|
380
|
+
this.logger.warn(`\u5DF2\u8DF3\u8FC7 ${result.skipped.length} \u4E2A\u5DF2\u5B58\u5728\u6587\u4EF6\uFF1A`);
|
|
381
|
+
for (const file of result.skipped) {
|
|
382
|
+
this.logger.info(` - ${file}`);
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
_chunkMZIXIY2Ycjs.getConfigManager.call(void 0, ).clearCache();
|
|
386
|
+
try {
|
|
387
|
+
this.logger.info("");
|
|
388
|
+
this.logger.info("\u6B63\u5728\u89C4\u8303\u5316 TOC.md \u5E76\u751F\u6210 sidebar.json...");
|
|
389
|
+
const noteService = _chunkTJ4527KAcjs.NoteService.getInstance();
|
|
390
|
+
const tocService = _chunkTJ4527KAcjs.TocService.getInstance();
|
|
391
|
+
const notes = noteService.getAllNotes();
|
|
392
|
+
await tocService.normalizeToc(notes);
|
|
393
|
+
await tocService.regenerateSidebar(notes);
|
|
394
|
+
this.logger.success("sidebar.json \u5DF2\u751F\u6210");
|
|
395
|
+
} catch (error) {
|
|
396
|
+
this.logger.warn(
|
|
397
|
+
`\u81EA\u52A8 update \u5931\u8D25\uFF08\u53EF\u7A0D\u540E\u624B\u52A8\u6267\u884C pnpm tn:update\uFF09\uFF1A${error instanceof Error ? error.message : String(error)}`
|
|
398
|
+
);
|
|
399
|
+
}
|
|
400
|
+
this.logger.info("");
|
|
401
|
+
this.logger.success("\u5B50\u77E5\u8BC6\u5E93\u521D\u59CB\u5316\u5B8C\u6210\uFF01");
|
|
402
|
+
this.logger.info("");
|
|
403
|
+
this.logger.info("\u8BF7\u624B\u52A8\u5B8C\u6210\u4EE5\u4E0B\u6B65\u9AA4\uFF1A");
|
|
404
|
+
for (const [index, step] of _chunkTJ4527KAcjs.buildManualSteps.call(void 0, ctx).entries()) {
|
|
405
|
+
this.logger.info(` ${index + 1}. ${step}`);
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
async promptForInput() {
|
|
409
|
+
const topic = await this.promptTopic();
|
|
410
|
+
const displayName = await this.promptDisplayName(topic);
|
|
411
|
+
const port2 = await this.promptPort();
|
|
412
|
+
const description = await this.promptDescription();
|
|
413
|
+
return {
|
|
414
|
+
topic,
|
|
415
|
+
displayName,
|
|
416
|
+
port: port2,
|
|
417
|
+
description,
|
|
418
|
+
repoUuid: _uuid.v4.call(void 0, ),
|
|
419
|
+
noteUuid: _uuid.v4.call(void 0, ),
|
|
420
|
+
coreVersion: readCoreVersion()
|
|
421
|
+
};
|
|
422
|
+
}
|
|
423
|
+
async promptTopic() {
|
|
424
|
+
while (true) {
|
|
425
|
+
const answer = await this.ask("\u8BF7\u8F93\u5165 topic\uFF08\u5982 react\uFF0C\u5C06\u751F\u6210 TNotes.react\uFF09: ");
|
|
426
|
+
const error = _chunkTJ4527KAcjs.validateTopic.call(void 0, answer);
|
|
427
|
+
if (error) {
|
|
428
|
+
this.logger.warn(error);
|
|
429
|
+
continue;
|
|
430
|
+
}
|
|
431
|
+
return answer.trim();
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
async promptDisplayName(topic) {
|
|
435
|
+
const fallback = _chunkTJ4527KAcjs.defaultDisplayName.call(void 0, topic);
|
|
436
|
+
const answer = await this.ask(
|
|
437
|
+
`\u8BF7\u8F93\u5165\u5C55\u793A\u540D\uFF08\u7528\u4E8E\u9996\u9875 hero\uFF0C\u9ED8\u8BA4 ${fallback}\uFF09: `
|
|
438
|
+
);
|
|
439
|
+
return answer.trim() || fallback;
|
|
440
|
+
}
|
|
441
|
+
async promptPort() {
|
|
442
|
+
const answer = await this.ask(`\u8BF7\u8F93\u5165 dev \u7AEF\u53E3\uFF08\u9ED8\u8BA4 ${_chunkTJ4527KAcjs.DEFAULT_PORT}\uFF09: `);
|
|
443
|
+
const { port: port2, error } = _chunkTJ4527KAcjs.validatePort.call(void 0, answer);
|
|
444
|
+
if (error) this.logger.warn(error);
|
|
445
|
+
return port2;
|
|
446
|
+
}
|
|
447
|
+
async promptDescription() {
|
|
448
|
+
const answer = await this.ask(
|
|
449
|
+
`\u8BF7\u8F93\u5165\u4ED3\u5E93\u63CF\u8FF0\uFF08\u9ED8\u8BA4\uFF1A${_chunkTJ4527KAcjs.DEFAULT_DESCRIPTION}\uFF09: `
|
|
450
|
+
);
|
|
451
|
+
return answer.trim() || _chunkTJ4527KAcjs.DEFAULT_DESCRIPTION;
|
|
452
|
+
}
|
|
453
|
+
async promptConfirm(question) {
|
|
454
|
+
const answer = await this.ask(question);
|
|
455
|
+
const normalized = answer.trim().toLowerCase();
|
|
456
|
+
return normalized === "" || normalized === "y" || normalized === "yes";
|
|
457
|
+
}
|
|
458
|
+
ask(question) {
|
|
459
|
+
const rl = _readline.createInterface.call(void 0, {
|
|
460
|
+
input: process.stdin,
|
|
461
|
+
output: process.stdout
|
|
462
|
+
});
|
|
463
|
+
return new Promise((resolve) => {
|
|
464
|
+
rl.question(question, (answer) => {
|
|
465
|
+
rl.close();
|
|
466
|
+
resolve(answer);
|
|
467
|
+
});
|
|
468
|
+
});
|
|
469
|
+
}
|
|
470
|
+
};
|
|
471
|
+
|
|
472
|
+
// commands/init-toc/InitTocCommand.ts
|
|
473
|
+
|
|
474
|
+
var InitTocCommand = class extends _chunkTJ4527KAcjs.BaseCommand {
|
|
475
|
+
constructor() {
|
|
476
|
+
super("init-toc");
|
|
477
|
+
this.noteManager = _chunkTJ4527KAcjs.NoteManager.getInstance();
|
|
478
|
+
this.tocService = _chunkTJ4527KAcjs.TocService.getInstance();
|
|
479
|
+
}
|
|
480
|
+
async run() {
|
|
481
|
+
if (!_fs.existsSync.call(void 0, _chunkTJ4527KAcjs.ROOT_README_PATH)) {
|
|
482
|
+
throw new Error(`README.md \u4E0D\u5B58\u5728: ${_chunkTJ4527KAcjs.ROOT_README_PATH}`);
|
|
483
|
+
}
|
|
484
|
+
const readmeContent = _fs.readFileSync.call(void 0, _chunkTJ4527KAcjs.ROOT_README_PATH, "utf-8");
|
|
485
|
+
const notes = this.noteManager.scanNotes();
|
|
486
|
+
const { entries, warnings } = _chunkTJ4527KAcjs.migrateReadmeToToc.call(void 0, readmeContent);
|
|
487
|
+
for (const warning of warnings) {
|
|
488
|
+
this.logger.warn(warning);
|
|
489
|
+
}
|
|
490
|
+
const lines = [];
|
|
491
|
+
let skipped = 0;
|
|
492
|
+
for (const entry of entries) {
|
|
493
|
+
if (entry.kind === "folder") {
|
|
494
|
+
lines.push(_chunk3R7QSABBcjs.buildFolderTocLine.call(void 0, entry.folderTitle, entry.indent));
|
|
495
|
+
continue;
|
|
496
|
+
}
|
|
497
|
+
const note = _chunk3R7QSABBcjs.resolveNoteFromIndex.call(void 0, entry.noteIndex, notes);
|
|
498
|
+
if (!note) {
|
|
499
|
+
skipped++;
|
|
500
|
+
this.logger.warn(
|
|
501
|
+
`\u8DF3\u8FC7 README \u4E2D\u5B58\u5728\u4F46 notes/ \u76EE\u5F55\u4E2D\u4E0D\u5B58\u5728\u7684\u7B14\u8BB0: ${entry.noteIndex}`
|
|
502
|
+
);
|
|
503
|
+
continue;
|
|
504
|
+
}
|
|
505
|
+
lines.push(_chunk3R7QSABBcjs.buildTocLine.call(void 0, note, entry.indent, entry.completed));
|
|
506
|
+
}
|
|
507
|
+
if (lines.length === 0) {
|
|
508
|
+
throw new Error(
|
|
509
|
+
"\u672A\u80FD\u4ECE README.md \u89E3\u6790\u5230\u4EFB\u4F55\u6709\u6548\u7B14\u8BB0\u6761\u76EE\uFF0CTOC.md \u672A\u5199\u5165"
|
|
510
|
+
);
|
|
511
|
+
}
|
|
512
|
+
const content = _chunk3R7QSABBcjs.processTocEmptyLines.call(void 0, lines).join("\n");
|
|
513
|
+
_fs.writeFileSync.call(void 0, _chunkTJ4527KAcjs.ROOT_TOC_PATH, content, "utf-8");
|
|
514
|
+
await this.tocService.regenerateSidebar(notes);
|
|
515
|
+
this.logger.success(
|
|
516
|
+
`TOC.md \u5DF2\u4ECE README.md \u521D\u59CB\u5316\uFF08${lines.length} \u6761\u7B14\u8BB0${skipped > 0 ? `\uFF0C\u8DF3\u8FC7 ${skipped} \u6761` : ""}\uFF09`
|
|
517
|
+
);
|
|
518
|
+
this.logger.info(`\u8F93\u51FA\u8DEF\u5F84: ${_chunkTJ4527KAcjs.ROOT_TOC_PATH}`);
|
|
519
|
+
this.logger.info(
|
|
520
|
+
"\u8FC7\u6E21\u547D\u4EE4 init-toc \u4EC5\u5728 v0.2.x \u63D0\u4F9B\uFF0Cv0.3.x \u5C06\u79FB\u9664\uFF1B\u540E\u7EED\u8BF7\u4F7F\u7528 TOC.md + pnpm tn:update"
|
|
521
|
+
);
|
|
522
|
+
const listedIndexes = new Set(
|
|
523
|
+
entries.filter((e) => e.kind === "note").map((e) => e.noteIndex)
|
|
524
|
+
);
|
|
525
|
+
const missingInReadme = notes.filter((n) => !listedIndexes.has(n.index));
|
|
526
|
+
if (missingInReadme.length > 0) {
|
|
527
|
+
this.logger.info(
|
|
528
|
+
`README \u4E2D\u672A\u5217\u51FA ${missingInReadme.length} \u7BC7\u7B14\u8BB0\uFF0C\u53EF\u6267\u884C pnpm tn:update \u8FFD\u52A0\u5230 TOC.md`
|
|
529
|
+
);
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
};
|
|
533
|
+
|
|
534
|
+
// commands/misc/HelpCommand.ts
|
|
535
|
+
var COMMAND_CATEGORIES = {
|
|
536
|
+
\u5F00\u53D1\u548C\u6784\u5EFA: [_chunkTJ4527KAcjs.COMMAND_NAMES.DEV, _chunkTJ4527KAcjs.COMMAND_NAMES.BUILD, _chunkTJ4527KAcjs.COMMAND_NAMES.PREVIEW],
|
|
537
|
+
\u5185\u5BB9\u7BA1\u7406: [
|
|
538
|
+
_chunkTJ4527KAcjs.COMMAND_NAMES.UPDATE,
|
|
539
|
+
_chunkTJ4527KAcjs.COMMAND_NAMES.UPDATE_COMPLETED_COUNT,
|
|
540
|
+
_chunkTJ4527KAcjs.COMMAND_NAMES.CREATE_NOTES
|
|
541
|
+
],
|
|
542
|
+
"Git \u64CD\u4F5C": [_chunkTJ4527KAcjs.COMMAND_NAMES.PUSH, _chunkTJ4527KAcjs.COMMAND_NAMES.PULL],
|
|
543
|
+
"\u8FC1\u79FB\uFF08v0.2.x \u8FC7\u6E21\uFF09": [_chunkTJ4527KAcjs.COMMAND_NAMES.INIT_TOC],
|
|
544
|
+
\u521D\u59CB\u5316: [_chunkTJ4527KAcjs.COMMAND_NAMES.INIT_SUB_REPO],
|
|
545
|
+
\u5176\u4ED6: [_chunkTJ4527KAcjs.COMMAND_NAMES.HELP]
|
|
546
|
+
};
|
|
547
|
+
var COMMAND_OPTIONS_INFO = {
|
|
548
|
+
[_chunkTJ4527KAcjs.COMMAND_OPTIONS.QUIET]: {
|
|
549
|
+
description: "\u9759\u9ED8\u6A21\u5F0F",
|
|
550
|
+
applicableTo: "update"
|
|
551
|
+
},
|
|
552
|
+
[_chunkTJ4527KAcjs.COMMAND_OPTIONS.FORCE]: {
|
|
553
|
+
description: "\u5F3A\u5236\u63A8\u9001",
|
|
554
|
+
applicableTo: "push"
|
|
555
|
+
}
|
|
556
|
+
};
|
|
557
|
+
var HelpCommand = class extends _chunkTJ4527KAcjs.BaseCommand {
|
|
558
|
+
constructor() {
|
|
559
|
+
super("help");
|
|
560
|
+
this.logger = _chunkTJ4527KAcjs.createLogger.call(void 0, "help", {
|
|
561
|
+
timestamp: false,
|
|
562
|
+
level: process.env.DEBUG ? 0 /* DEBUG */ : 1 /* INFO */
|
|
563
|
+
});
|
|
564
|
+
}
|
|
565
|
+
async run() {
|
|
566
|
+
this.logger.info("TNotes \u547D\u4EE4\u884C\u5DE5\u5177");
|
|
567
|
+
this.logger.info("");
|
|
568
|
+
this.logger.info("\u7528\u6CD5\uFF1Apnpm tn:<command> # \u63A8\u8350");
|
|
569
|
+
this.logger.info("\u6216\u8005\uFF1Anpx tsx ./.vitepress/tnotes/index.ts --<command>");
|
|
570
|
+
this.logger.info("");
|
|
571
|
+
this.logger.info("\u53EF\u7528\u547D\u4EE4\uFF1A");
|
|
572
|
+
this.logger.info("");
|
|
573
|
+
for (const [category, cmdNames] of Object.entries(COMMAND_CATEGORIES)) {
|
|
574
|
+
this.logger.info(` ${category}:`);
|
|
575
|
+
for (const cmdName of cmdNames) {
|
|
576
|
+
const description = _chunkTJ4527KAcjs.COMMAND_DESCRIPTIONS[cmdName];
|
|
577
|
+
const paddingLength = Math.max(25 - cmdName.length, 1);
|
|
578
|
+
const padding = " ".repeat(paddingLength);
|
|
579
|
+
this.logger.info(` --${cmdName}${padding}${description}`);
|
|
580
|
+
}
|
|
581
|
+
this.logger.info("");
|
|
582
|
+
}
|
|
583
|
+
this.logger.info("\u793A\u4F8B\uFF1A");
|
|
584
|
+
this.logger.info(" npx tsx ./.vitepress/tnotes/index.ts --dev");
|
|
585
|
+
this.logger.info(" pnpm tn:build");
|
|
586
|
+
this.logger.info(" pnpm tn:create-notes # \u6279\u91CF\u521B\u5EFA\u7B14\u8BB0");
|
|
587
|
+
this.logger.info(" pnpm tn:update");
|
|
588
|
+
this.logger.info(
|
|
589
|
+
" pnpm tn:init-toc # v0.1.x \u2192 v0.2.x\uFF1A\u4ECE README.md \u751F\u6210 TOC.md"
|
|
590
|
+
);
|
|
591
|
+
this.logger.info(
|
|
592
|
+
" 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"
|
|
593
|
+
);
|
|
594
|
+
this.logger.info("");
|
|
595
|
+
this.logger.info("\u53C2\u6570\uFF1A");
|
|
596
|
+
for (const [option, info] of Object.entries(COMMAND_OPTIONS_INFO)) {
|
|
597
|
+
const paddingLength = Math.max(13 - option.length, 1);
|
|
598
|
+
const padding = " ".repeat(paddingLength);
|
|
599
|
+
this.logger.info(
|
|
600
|
+
` --${option}${padding}${info.description} (\u9002\u7528\u4E8E ${info.applicableTo})`
|
|
601
|
+
);
|
|
602
|
+
}
|
|
603
|
+
this.logger.info("");
|
|
604
|
+
this.logger.info("\u73AF\u5883\u53D8\u91CF\uFF1A");
|
|
605
|
+
this.logger.info(" DEBUG=1 \u542F\u7528\u8C03\u8BD5\u6A21\u5F0F\uFF0C\u663E\u793A\u8BE6\u7EC6\u65E5\u5FD7");
|
|
606
|
+
this.logger.info("");
|
|
607
|
+
this.logger.info("\u66F4\u591A\u4FE1\u606F\u8BF7\u67E5\u770B: .vitepress/tnotes/README.md");
|
|
608
|
+
}
|
|
609
|
+
};
|
|
610
|
+
|
|
611
|
+
// commands/note/CreateNoteCommand.ts
|
|
612
|
+
|
|
613
|
+
|
|
614
|
+
var CreateNoteCommand = class extends _chunkTJ4527KAcjs.BaseCommand {
|
|
615
|
+
constructor() {
|
|
616
|
+
super("create-notes");
|
|
617
|
+
this.noteService = _chunkTJ4527KAcjs.NoteService.getInstance();
|
|
618
|
+
this.readmeService = _chunkTJ4527KAcjs.ReadmeService.getInstance();
|
|
619
|
+
}
|
|
620
|
+
async run() {
|
|
621
|
+
this.logger.info("\u521B\u5EFA\u65B0\u7B14\u8BB0...");
|
|
622
|
+
const count = await this.promptForCount();
|
|
623
|
+
let successCount = 0;
|
|
624
|
+
let failCount = 0;
|
|
625
|
+
const createdNotes = [];
|
|
626
|
+
const existingNotes = this.noteService.getAllNotes();
|
|
627
|
+
const usedIndexes = /* @__PURE__ */ new Set();
|
|
628
|
+
for (const note of existingNotes) {
|
|
629
|
+
const index = parseInt(note.index, 10);
|
|
630
|
+
if (!isNaN(index) && index >= 1 && index <= 9999) {
|
|
631
|
+
usedIndexes.add(index);
|
|
632
|
+
}
|
|
633
|
+
}
|
|
634
|
+
for (let i = 1; i <= count; i++) {
|
|
635
|
+
try {
|
|
636
|
+
let title;
|
|
637
|
+
if (count === 1) {
|
|
638
|
+
title = await this.promptForTitle();
|
|
639
|
+
} else {
|
|
640
|
+
title = `new`;
|
|
641
|
+
this.logger.info(`[${i}/${count}] \u521B\u5EFA\u7B14\u8BB0: ${title}`);
|
|
642
|
+
}
|
|
643
|
+
const configId = _uuid.v4.call(void 0, );
|
|
644
|
+
const note = await this.noteService.createNote({
|
|
645
|
+
title: title || `new`,
|
|
646
|
+
enableDiscussions: false,
|
|
647
|
+
configId,
|
|
648
|
+
// 传递 UUID 作为配置 ID(跨知识库唯一)
|
|
649
|
+
usedIndexes
|
|
650
|
+
// 传入已使用编号集合,避免重复扫描
|
|
651
|
+
});
|
|
652
|
+
const newIndex = parseInt(note.index, 10);
|
|
653
|
+
if (!isNaN(newIndex)) {
|
|
654
|
+
usedIndexes.add(newIndex);
|
|
655
|
+
}
|
|
656
|
+
createdNotes.push(note.dirName);
|
|
657
|
+
successCount++;
|
|
658
|
+
if (count === 1) {
|
|
659
|
+
this.logger.success(`\u7B14\u8BB0\u521B\u5EFA\u6210\u529F: ${note.dirName}`);
|
|
660
|
+
this.logger.info(`\u7B14\u8BB0\u8DEF\u5F84: ${note.path}`);
|
|
661
|
+
this.logger.info(`\u7B14\u8BB0\u7F16\u53F7: ${note.index}`);
|
|
662
|
+
this.logger.info(`\u914D\u7F6EID: ${configId}`);
|
|
663
|
+
} else {
|
|
664
|
+
this.logger.success(`[${i}/${count}] \u521B\u5EFA\u6210\u529F: ${note.dirName}`);
|
|
665
|
+
}
|
|
666
|
+
} catch (error) {
|
|
667
|
+
failCount++;
|
|
668
|
+
this.logger.error(`[${i}/${count}] \u521B\u5EFA\u5931\u8D25`, error);
|
|
669
|
+
}
|
|
670
|
+
}
|
|
671
|
+
if (count > 1) {
|
|
672
|
+
console.log("");
|
|
673
|
+
this.logger.info(
|
|
674
|
+
`\u{1F4CA} \u521B\u5EFA\u5B8C\u6210: \u6210\u529F ${successCount} \u7BC7, \u5931\u8D25 ${failCount} \u7BC7`
|
|
675
|
+
);
|
|
676
|
+
}
|
|
677
|
+
if (successCount > 0) {
|
|
678
|
+
this.logger.info("\u6B63\u5728\u66F4\u65B0\u77E5\u8BC6\u5E93\u7D22\u5F15...");
|
|
679
|
+
await this.readmeService.updateAllReadmes();
|
|
680
|
+
this.logger.success("\u77E5\u8BC6\u5E93\u7D22\u5F15\u66F4\u65B0\u5B8C\u6210");
|
|
681
|
+
}
|
|
682
|
+
}
|
|
683
|
+
/**
|
|
684
|
+
* 提示用户输入要创建的笔记数量
|
|
685
|
+
*/
|
|
686
|
+
async promptForCount() {
|
|
687
|
+
const rl = _readline.createInterface.call(void 0, {
|
|
688
|
+
input: process.stdin,
|
|
689
|
+
output: process.stdout
|
|
690
|
+
});
|
|
691
|
+
return new Promise((resolve) => {
|
|
692
|
+
rl.question("\n\u{1F4DD} \u8BF7\u8F93\u5165\u8981\u521B\u5EFA\u7684\u7B14\u8BB0\u6570\u91CF\uFF08\u9ED8\u8BA4\u4E3A 1\uFF09: ", (answer) => {
|
|
693
|
+
rl.close();
|
|
694
|
+
const trimmed = answer.trim();
|
|
695
|
+
if (!trimmed) {
|
|
696
|
+
this.logger.info("\u4F7F\u7528\u9ED8\u8BA4\u6570\u91CF: 1");
|
|
697
|
+
resolve(1);
|
|
698
|
+
return;
|
|
699
|
+
}
|
|
700
|
+
const num = parseInt(trimmed, 10);
|
|
701
|
+
if (isNaN(num) || num < 1 || !Number.isInteger(num)) {
|
|
702
|
+
this.logger.warn(`\u8F93\u5165 "${trimmed}" \u4E0D\u662F\u6709\u6548\u7684\u6B63\u6574\u6570\uFF0C\u4F7F\u7528\u9ED8\u8BA4\u503C: 1`);
|
|
703
|
+
resolve(1);
|
|
704
|
+
return;
|
|
705
|
+
}
|
|
706
|
+
this.logger.info(`\u5C06\u521B\u5EFA ${num} \u7BC7\u7B14\u8BB0`);
|
|
707
|
+
resolve(num);
|
|
708
|
+
});
|
|
709
|
+
});
|
|
710
|
+
}
|
|
711
|
+
/**
|
|
712
|
+
* 提示用户输入笔记标题
|
|
713
|
+
*/
|
|
714
|
+
async promptForTitle() {
|
|
715
|
+
const rl = _readline.createInterface.call(void 0, {
|
|
716
|
+
input: process.stdin,
|
|
717
|
+
output: process.stdout
|
|
718
|
+
});
|
|
719
|
+
return new Promise((resolve) => {
|
|
720
|
+
rl.question("\u8BF7\u8F93\u5165\u7B14\u8BB0\u6807\u9898: ", (answer) => {
|
|
721
|
+
rl.close();
|
|
722
|
+
resolve(answer.trim());
|
|
723
|
+
});
|
|
724
|
+
});
|
|
725
|
+
}
|
|
726
|
+
};
|
|
727
|
+
|
|
728
|
+
// commands/update-completed-count/UpdateCompletedCountCommand.ts
|
|
729
|
+
var _child_process = require('child_process');
|
|
730
|
+
|
|
731
|
+
var UpdateCompletedCountCommand = class extends _chunkTJ4527KAcjs.BaseCommand {
|
|
732
|
+
constructor() {
|
|
733
|
+
super("update-completed-count");
|
|
734
|
+
}
|
|
735
|
+
async run() {
|
|
736
|
+
await this.updateCurrentRepo();
|
|
737
|
+
}
|
|
738
|
+
/**
|
|
739
|
+
* 更新当前知识库
|
|
740
|
+
*/
|
|
741
|
+
async updateCurrentRepo() {
|
|
742
|
+
const startTime = Date.now();
|
|
743
|
+
try {
|
|
744
|
+
const configContent = _fs.readFileSync.call(void 0, _chunkTJ4527KAcjs.ROOT_CONFIG_PATH, "utf-8");
|
|
745
|
+
const config = JSON.parse(configContent);
|
|
746
|
+
this.logger.info("\u5F00\u59CB\u66F4\u65B0\u5B8C\u6210\u7B14\u8BB0\u6570\u91CF\u5386\u53F2\u8BB0\u5F55...");
|
|
747
|
+
const completedNotesCountHistory = await this.getCompletedNotesCountHistory();
|
|
748
|
+
config.root_item = {
|
|
749
|
+
...config.root_item,
|
|
750
|
+
completed_notes_count: completedNotesCountHistory
|
|
751
|
+
};
|
|
752
|
+
_chunkMZIXIY2Ycjs.stripDeprecatedRootItemFields.call(void 0,
|
|
753
|
+
config.root_item
|
|
754
|
+
);
|
|
755
|
+
_fs.writeFileSync.call(void 0, _chunkTJ4527KAcjs.ROOT_CONFIG_PATH, JSON.stringify(config, null, 2), "utf-8");
|
|
756
|
+
const duration = Date.now() - startTime;
|
|
757
|
+
const monthKeys = Object.keys(completedNotesCountHistory);
|
|
758
|
+
const currentKey = monthKeys[monthKeys.length - 1];
|
|
759
|
+
const currentCount = completedNotesCountHistory[currentKey] || 0;
|
|
760
|
+
this.logger.success(
|
|
761
|
+
`\u5386\u53F2\u6570\u636E\u66F4\u65B0\u5B8C\u6210: \u5171 ${monthKeys.length} \u4E2A\u6708, \u5F53\u524D ${currentKey} \u6708\u5B8C\u6210 ${currentCount} \u7BC7\u7B14\u8BB0 (${duration}ms)`
|
|
762
|
+
);
|
|
763
|
+
} catch (error) {
|
|
764
|
+
this.logger.error(
|
|
765
|
+
`\u66F4\u65B0\u5931\u8D25: ${error instanceof Error ? error.message : String(error)}`
|
|
766
|
+
);
|
|
767
|
+
throw error;
|
|
768
|
+
}
|
|
769
|
+
}
|
|
770
|
+
/**
|
|
771
|
+
* 获取历史每个月的 completed_notes_count(最近12个月)
|
|
772
|
+
*
|
|
773
|
+
* 逻辑:
|
|
774
|
+
* 1. 计算最近12个月的范围(当前月份往前推11个月)
|
|
775
|
+
* 2. 遍历这12个月,从 Git 历史中读取 TOC.md(回退 README.md)
|
|
776
|
+
* 3. 解析获取完成笔记数量
|
|
777
|
+
* 4. 返回对象 { '25.01': 0, '25.02': 1, ..., '25.12': 15 }
|
|
778
|
+
*/
|
|
779
|
+
async getCompletedNotesCountHistory() {
|
|
780
|
+
try {
|
|
781
|
+
const now = /* @__PURE__ */ new Date();
|
|
782
|
+
const currentYear = now.getFullYear();
|
|
783
|
+
const currentMonth = now.getMonth();
|
|
784
|
+
let firstYear = currentYear;
|
|
785
|
+
let firstMonth = currentMonth - 11;
|
|
786
|
+
if (firstMonth < 0) {
|
|
787
|
+
firstYear = currentYear - 1;
|
|
788
|
+
firstMonth = 12 + firstMonth;
|
|
789
|
+
}
|
|
790
|
+
const result = {};
|
|
791
|
+
let prevCount = 0;
|
|
792
|
+
for (let i = 0; i < 12; i++) {
|
|
793
|
+
const targetYear = firstYear + Math.floor((firstMonth + i) / 12);
|
|
794
|
+
const targetMonth = (firstMonth + i) % 12;
|
|
795
|
+
const yearShort = String(targetYear).slice(-2);
|
|
796
|
+
const monthStr = String(targetMonth + 1).padStart(2, "0");
|
|
797
|
+
const key = `${yearShort}.${monthStr}`;
|
|
798
|
+
try {
|
|
799
|
+
const count = await this.getMonthCompletedCount(
|
|
800
|
+
targetYear,
|
|
801
|
+
targetMonth,
|
|
802
|
+
prevCount
|
|
803
|
+
);
|
|
804
|
+
result[key] = count;
|
|
805
|
+
prevCount = count;
|
|
806
|
+
this.logger.info(`\u2713 ${key}: ${count} \u7BC7`);
|
|
807
|
+
} catch (error) {
|
|
808
|
+
result[key] = prevCount;
|
|
809
|
+
this.logger.warn(`${key}: \u65E0\u6570\u636E\uFF0C\u4F7F\u7528 ${prevCount}\uFF08\u4E0A\u6708\u503C\uFF09`);
|
|
810
|
+
}
|
|
811
|
+
}
|
|
812
|
+
return result;
|
|
813
|
+
} catch (error) {
|
|
814
|
+
this.logger.error(
|
|
815
|
+
`\u83B7\u53D6\u5386\u53F2\u6570\u636E\u5931\u8D25: ${error instanceof Error ? error.message : String(error)}`
|
|
816
|
+
);
|
|
817
|
+
return {};
|
|
818
|
+
}
|
|
819
|
+
}
|
|
820
|
+
/**
|
|
821
|
+
* 获取指定月份的完成笔记数量
|
|
822
|
+
* @param year - 年份
|
|
823
|
+
* @param month - 月份 (0-11)
|
|
824
|
+
* @param fallbackCount - 回退值(如果该月没有数据)
|
|
825
|
+
* @returns 完成笔记数量
|
|
826
|
+
*/
|
|
827
|
+
async getMonthCompletedCount(year, month, fallbackCount = 0) {
|
|
828
|
+
const lastDayOfMonth = new Date(year, month + 1, 0, 23, 59, 59);
|
|
829
|
+
const yearStr = lastDayOfMonth.getFullYear();
|
|
830
|
+
const monthStr = String(lastDayOfMonth.getMonth() + 1).padStart(2, "0");
|
|
831
|
+
const dayStr = String(lastDayOfMonth.getDate()).padStart(2, "0");
|
|
832
|
+
const untilDate = `${yearStr}-${monthStr}-${dayStr} 23:59:59 +0800`;
|
|
833
|
+
let commitHash = _child_process.execSync.call(void 0,
|
|
834
|
+
`git log --until="${untilDate}" --format=%H -1 -- TOC.md`,
|
|
835
|
+
{
|
|
836
|
+
cwd: _chunkTJ4527KAcjs.ROOT_DIR_PATH,
|
|
837
|
+
encoding: "utf-8"
|
|
838
|
+
}
|
|
839
|
+
).trim();
|
|
840
|
+
let filePath = "TOC.md";
|
|
841
|
+
if (!commitHash) {
|
|
842
|
+
commitHash = _child_process.execSync.call(void 0,
|
|
843
|
+
`git log --until="${untilDate}" --format=%H -1 -- README.md`,
|
|
844
|
+
{
|
|
845
|
+
cwd: _chunkTJ4527KAcjs.ROOT_DIR_PATH,
|
|
846
|
+
encoding: "utf-8"
|
|
847
|
+
}
|
|
848
|
+
).trim();
|
|
849
|
+
filePath = "README.md";
|
|
850
|
+
}
|
|
851
|
+
if (!commitHash) {
|
|
852
|
+
return fallbackCount;
|
|
853
|
+
}
|
|
854
|
+
let fileContent;
|
|
855
|
+
try {
|
|
856
|
+
fileContent = _child_process.execSync.call(void 0, `git show ${commitHash}:${filePath}`, {
|
|
857
|
+
cwd: _chunkTJ4527KAcjs.ROOT_DIR_PATH,
|
|
858
|
+
encoding: "utf-8"
|
|
859
|
+
});
|
|
860
|
+
} catch (error) {
|
|
861
|
+
return fallbackCount;
|
|
862
|
+
}
|
|
863
|
+
const { completedCount } = filePath === "TOC.md" ? _chunk3R7QSABBcjs.parseTocCompletedNotes.call(void 0, fileContent) : _chunkTJ4527KAcjs.parseReadmeCompletedNotes.call(void 0, fileContent);
|
|
864
|
+
return completedCount;
|
|
865
|
+
}
|
|
866
|
+
};
|
|
867
|
+
|
|
868
|
+
// commands/registry.ts
|
|
869
|
+
var commandFactories = {
|
|
870
|
+
"build": () => new BuildCommand(),
|
|
871
|
+
"create-notes": () => new CreateNoteCommand(),
|
|
872
|
+
"dev": () => new DevCommand(),
|
|
873
|
+
"init-sub-repo": () => new InitSubRepoCommand(),
|
|
874
|
+
"init-toc": () => new InitTocCommand(),
|
|
875
|
+
"help": () => new HelpCommand(),
|
|
876
|
+
"preview": () => new PreviewCommand(),
|
|
877
|
+
"pull": () => new PullCommand(),
|
|
878
|
+
"push": () => new PushCommand(),
|
|
879
|
+
"rename-note": () => new (0, _chunkTJ4527KAcjs.RenameNoteCommand)(),
|
|
880
|
+
"update-completed-count": () => new UpdateCompletedCountCommand(),
|
|
881
|
+
"update-note-config": () => new (0, _chunkTJ4527KAcjs.UpdateNoteConfigCommand)(),
|
|
882
|
+
"update": () => new UpdateCommand()
|
|
883
|
+
};
|
|
884
|
+
var commandCache = /* @__PURE__ */ new Map();
|
|
885
|
+
function getCommand(name) {
|
|
886
|
+
if (!commandFactories[name]) return void 0;
|
|
887
|
+
if (!commandCache.has(name)) commandCache.set(name, commandFactories[name]());
|
|
888
|
+
return commandCache.get(name);
|
|
889
|
+
}
|
|
890
|
+
|
|
891
|
+
// index.ts
|
|
892
|
+
(async () => {
|
|
893
|
+
try {
|
|
894
|
+
const args = _chunkTJ4527KAcjs.parseArgs.call(void 0, process.argv.slice(2));
|
|
895
|
+
const commandName = Object.keys(args).find(
|
|
896
|
+
(key) => key !== "_" && args[key] === true
|
|
897
|
+
);
|
|
898
|
+
const command = commandName ? getCommand(commandName) : null;
|
|
899
|
+
if (!command) {
|
|
900
|
+
const logger2 = _chunkTJ4527KAcjs.createLogger.call(void 0, "command-not-found", {
|
|
901
|
+
timestamp: false
|
|
902
|
+
});
|
|
903
|
+
console.log(`
|
|
904
|
+
${"-".repeat(66)}
|
|
905
|
+
`);
|
|
906
|
+
if (commandName) {
|
|
907
|
+
logger2.warn(`\u672A\u627E\u5230\u547D\u4EE4\uFF1A${commandName}`);
|
|
908
|
+
logger2.info(`\u8BF7\u68C0\u67E5\u547D\u4EE4\u540D\u662F\u5426\u6B63\u786E\uFF01`);
|
|
909
|
+
} else {
|
|
910
|
+
logger2.warn(`\u672A\u68C0\u6D4B\u5230\u547D\u4EE4\u540D\uFF0C\u8BF7\u68C0\u67E5\u547D\u4EE4\u8F93\u5165\u662F\u5426\u6B63\u786E`);
|
|
911
|
+
logger2.info(`\u793A\u4F8B\uFF1A`);
|
|
912
|
+
logger2.info(`pnpm tn:<\u547D\u4EE4\u540D>`);
|
|
913
|
+
logger2.info(`npx tsx ./.vitepress/tnotes/index.ts --<\u547D\u4EE4\u540D>`);
|
|
914
|
+
}
|
|
915
|
+
console.log(`
|
|
916
|
+
${"-".repeat(66)}
|
|
917
|
+
`);
|
|
918
|
+
const helpCommand = getCommand(_chunkTJ4527KAcjs.COMMAND_NAMES.HELP);
|
|
919
|
+
if (helpCommand) {
|
|
920
|
+
console.log("\n\u6B63\u5728\u6267\u884C pnpm tn:help \u6253\u5370\u5E2E\u52A9\u4FE1\u606F...\n");
|
|
921
|
+
await helpCommand.execute();
|
|
922
|
+
}
|
|
923
|
+
return;
|
|
924
|
+
}
|
|
925
|
+
if (commandName === _chunkTJ4527KAcjs.COMMAND_NAMES.UPDATE) {
|
|
926
|
+
const cmd = command;
|
|
927
|
+
if (args.quiet) cmd.setQuiet(true);
|
|
928
|
+
} else if (commandName === _chunkTJ4527KAcjs.COMMAND_NAMES.PUSH) {
|
|
929
|
+
const cmd = command;
|
|
930
|
+
if (args.force) cmd.setOptions({ force: true });
|
|
931
|
+
}
|
|
932
|
+
await command.execute();
|
|
933
|
+
} catch (error) {
|
|
934
|
+
_chunkTJ4527KAcjs.handleError.call(void 0, error, true);
|
|
935
|
+
}
|
|
936
|
+
})();
|