@tnotesjs/core 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +84 -0
- package/dist/chunk-CSSIRO3I.js +4288 -0
- package/dist/chunk-NASIL5FY.js +203 -0
- package/dist/cli/index.js +694 -0
- package/dist/index.js +8 -0
- package/dist/vitepress/config/index.js +904 -0
- package/package.json +77 -0
- package/types/config.ts +61 -0
- package/types/index.ts +11 -0
- package/types/note.ts +33 -0
- package/types/shims.d.ts +10 -0
- package/vitepress/assets/icons/icon__check.svg +3 -0
- package/vitepress/assets/icons/icon__clipboard.svg +8 -0
- package/vitepress/assets/icons/icon__close.svg +1 -0
- package/vitepress/assets/icons/icon__collapse.svg +1 -0
- package/vitepress/assets/icons/icon__confirm.svg +1 -0
- package/vitepress/assets/icons/icon__copy.svg +4 -0
- package/vitepress/assets/icons/icon__focus.svg +1 -0
- package/vitepress/assets/icons/icon__fold.svg +3 -0
- package/vitepress/assets/icons/icon__folder.svg +1 -0
- package/vitepress/assets/icons/icon__fullscreen.svg +1 -0
- package/vitepress/assets/icons/icon__fullscreen_exit.svg +1 -0
- package/vitepress/assets/icons/icon__github.svg +4 -0
- package/vitepress/assets/icons/icon__mindmap.svg +1 -0
- package/vitepress/assets/icons/icon__next.svg +1 -0
- package/vitepress/assets/icons/icon__number_gray.svg +1 -0
- package/vitepress/assets/icons/icon__number_purple.svg +1 -0
- package/vitepress/assets/icons/icon__prev.svg +1 -0
- package/vitepress/assets/icons/icon__restore.svg +1 -0
- package/vitepress/assets/icons/icon__rotate.svg +4 -0
- package/vitepress/assets/icons/icon__search.svg +1 -0
- package/vitepress/assets/icons/icon__sidebar_collapsed.svg +1 -0
- package/vitepress/assets/icons/icon__sidebar_opened.svg +1 -0
- package/vitepress/assets/icons/icon__totop.svg +6 -0
- package/vitepress/assets/icons/icon__vscode.svg +6 -0
- package/vitepress/assets/icons/icon__zoom_fit.svg +1 -0
- package/vitepress/assets/icons/icon__zoom_in.svg +1 -0
- package/vitepress/assets/icons/icon__zoom_out.svg +1 -0
- package/vitepress/assets/icons/icon__zoom_reset.svg +1 -0
- package/vitepress/assets/icons/index.ts +38 -0
- package/vitepress/components/BilibiliOutsidePlayer/BilibiliOutsidePlayer.vue +20 -0
- package/vitepress/components/CodeBlockFullscreen/CodeBlockFullscreen.vue +373 -0
- package/vitepress/components/CodeBlockFullscreen/index.ts +115 -0
- package/vitepress/components/CodeBlockFullscreen/styles.css +64 -0
- package/vitepress/components/Discussions/Discussions.module.scss +32 -0
- package/vitepress/components/Discussions/Discussions.vue +211 -0
- package/vitepress/components/EnWordList/EnWordList.module.scss +124 -0
- package/vitepress/components/EnWordList/EnWordList.vue +543 -0
- package/vitepress/components/EnWordList/RightClickMenu.module.scss +22 -0
- package/vitepress/components/EnWordList/RightClickMenu.vue +66 -0
- package/vitepress/components/Footprints/Footprints.module.scss +93 -0
- package/vitepress/components/Footprints/Footprints.vue +377 -0
- package/vitepress/components/Layout/AboutModal.module.scss +233 -0
- package/vitepress/components/Layout/AboutModal.vue +105 -0
- package/vitepress/components/Layout/AboutPanel.vue +266 -0
- package/vitepress/components/Layout/ContentCollapse.vue +603 -0
- package/vitepress/components/Layout/CustomSidebar.vue +605 -0
- package/vitepress/components/Layout/DocBeforeControls.vue +139 -0
- package/vitepress/components/Layout/DocFooter.vue +225 -0
- package/vitepress/components/Layout/ImagePreview.module.scss +201 -0
- package/vitepress/components/Layout/ImagePreview.vue +281 -0
- package/vitepress/components/Layout/Layout.module.scss +661 -0
- package/vitepress/components/Layout/Layout.vue +542 -0
- package/vitepress/components/Layout/NoteStatus.vue +140 -0
- package/vitepress/components/Layout/SidebarItems.vue +263 -0
- package/vitepress/components/Layout/SidebarNavBefore.vue +92 -0
- package/vitepress/components/Layout/Swiper.vue +167 -0
- package/vitepress/components/Layout/ToggleFullContent.module.scss +11 -0
- package/vitepress/components/Layout/ToggleFullContent.vue +34 -0
- package/vitepress/components/Layout/ToggleSidebar.module.scss +11 -0
- package/vitepress/components/Layout/ToggleSidebar.vue +35 -0
- package/vitepress/components/Layout/composables/useCollapseControl.ts +88 -0
- package/vitepress/components/Layout/composables/useNoteConfig.ts +121 -0
- package/vitepress/components/Layout/composables/useNoteSave.ts +173 -0
- package/vitepress/components/Layout/composables/useNoteValidation.ts +85 -0
- package/vitepress/components/Layout/composables/useRedirect.ts +110 -0
- package/vitepress/components/Layout/composables/useVSCodeIntegration.ts +85 -0
- package/vitepress/components/Layout/homeReadme.data.ts +124 -0
- package/vitepress/components/LoadingPage/LoadingPage.vue +192 -0
- package/vitepress/components/MarkMap/MarkMap.module.scss +159 -0
- package/vitepress/components/MarkMap/MarkMap.vue +404 -0
- package/vitepress/components/Mermaid/Mermaid.module.scss +275 -0
- package/vitepress/components/Mermaid/Mermaid.vue +364 -0
- package/vitepress/components/NotesTable/NotesTable.module.scss +77 -0
- package/vitepress/components/NotesTable/NotesTable.vue +98 -0
- package/vitepress/components/NotesTable/README.md +67 -0
- package/vitepress/components/Settings/Settings.module.scss +433 -0
- package/vitepress/components/Settings/Settings.vue +306 -0
- package/vitepress/components/SidebarCard/MindMapView.vue +483 -0
- package/vitepress/components/SidebarCard/NotesTrendChart.vue +108 -0
- package/vitepress/components/SidebarCard/SidebarCard.vue +948 -0
- package/vitepress/components/Tooltip/Tooltip.vue +70 -0
- package/vitepress/components/constants.ts +91 -0
- package/vitepress/components/notesConfig.data.ts +73 -0
- package/vitepress/components/sidebar.data.ts +59 -0
- package/vitepress/components/tnotes-config.data.ts +21 -0
- package/vitepress/components/utils.ts +26 -0
- package/vitepress/config/index.ts +141 -0
- package/vitepress/configs/constants.ts +26 -0
- package/vitepress/configs/head.config.ts +25 -0
- package/vitepress/configs/index.ts +9 -0
- package/vitepress/configs/markdown-it.d.ts +23 -0
- package/vitepress/configs/markdown.config.ts +366 -0
- package/vitepress/configs/theme.config.ts +108 -0
- package/vitepress/plugins/buildProgressPlugin.ts +390 -0
- package/vitepress/plugins/getNoteByConfigIdPlugin.ts +107 -0
- package/vitepress/plugins/renameNotePlugin.ts +60 -0
- package/vitepress/plugins/updateConfigPlugin.ts +63 -0
- package/vitepress/theme/index.ts +95 -0
- package/vitepress/theme/styles/base.scss +50 -0
- package/vitepress/theme/styles/components/404.scss +31 -0
- package/vitepress/theme/styles/components/collapse.scss +175 -0
- package/vitepress/theme/styles/components/markmap.scss +101 -0
- package/vitepress/theme/styles/components/swiper.scss +255 -0
- package/vitepress/theme/styles/index.scss +25 -0
- package/vitepress/theme/styles/layout.scss +62 -0
- package/vitepress/theme/styles/utilities.scss +39 -0
- package/vitepress/theme/styles/vitepress-override.scss +25 -0
|
@@ -0,0 +1,694 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
BaseCommand,
|
|
4
|
+
COMMAND_DESCRIPTIONS,
|
|
5
|
+
COMMAND_NAMES,
|
|
6
|
+
COMMAND_OPTIONS,
|
|
7
|
+
FileWatcherService,
|
|
8
|
+
GitService,
|
|
9
|
+
NoteIndexCache,
|
|
10
|
+
NoteManager,
|
|
11
|
+
NoteService,
|
|
12
|
+
ROOT_CONFIG_PATH,
|
|
13
|
+
ROOT_DIR_PATH,
|
|
14
|
+
ReadmeService,
|
|
15
|
+
RenameNoteCommand,
|
|
16
|
+
TimestampService,
|
|
17
|
+
UpdateNoteConfigCommand,
|
|
18
|
+
VitepressService,
|
|
19
|
+
createLogger,
|
|
20
|
+
handleError,
|
|
21
|
+
logger,
|
|
22
|
+
parseArgs,
|
|
23
|
+
parseReadmeCompletedNotes,
|
|
24
|
+
runCommand
|
|
25
|
+
} from "../chunk-CSSIRO3I.js";
|
|
26
|
+
import {
|
|
27
|
+
ConfigManager
|
|
28
|
+
} from "../chunk-NASIL5FY.js";
|
|
29
|
+
|
|
30
|
+
// commands/update/UpdateCommand.ts
|
|
31
|
+
import { existsSync, readFileSync, writeFileSync } from "fs";
|
|
32
|
+
import { resolve } from "path";
|
|
33
|
+
var UpdateCommand = class extends BaseCommand {
|
|
34
|
+
readmeService;
|
|
35
|
+
noteService;
|
|
36
|
+
quiet = false;
|
|
37
|
+
constructor() {
|
|
38
|
+
super("update");
|
|
39
|
+
this.readmeService = ReadmeService.getInstance();
|
|
40
|
+
this.noteService = NoteService.getInstance();
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* 设置 quiet 模式
|
|
44
|
+
*
|
|
45
|
+
* 在 quiet 模式下,只显示 WARN 级别以上的日志
|
|
46
|
+
*/
|
|
47
|
+
setQuiet(quiet) {
|
|
48
|
+
this.quiet = quiet;
|
|
49
|
+
if (quiet) {
|
|
50
|
+
logger.setLevel(2 /* WARN */);
|
|
51
|
+
} else {
|
|
52
|
+
logger.setLevel(1 /* INFO */);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
async run() {
|
|
56
|
+
await this.updateCurrentRepo();
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* 更新当前知识库
|
|
60
|
+
*/
|
|
61
|
+
async updateCurrentRepo() {
|
|
62
|
+
const startTime = Date.now();
|
|
63
|
+
const notes = this.noteService.getAllNotes();
|
|
64
|
+
if (!this.quiet) {
|
|
65
|
+
this.logger.info("\u6B63\u5728\u4FEE\u6B63\u7B14\u8BB0\u6807\u9898...");
|
|
66
|
+
}
|
|
67
|
+
const fixedCount = await this.noteService.fixAllNoteTitles(notes);
|
|
68
|
+
if (!this.quiet && fixedCount > 0) {
|
|
69
|
+
this.logger.success(`\u4FEE\u6B63\u4E86 ${fixedCount} \u4E2A\u7B14\u8BB0\u6807\u9898`);
|
|
70
|
+
}
|
|
71
|
+
await this.readmeService.updateAllReadmes({ notes });
|
|
72
|
+
await this.updateRootItem();
|
|
73
|
+
const duration = Date.now() - startTime;
|
|
74
|
+
if (this.quiet) {
|
|
75
|
+
this.logger.success(`\u77E5\u8BC6\u5E93\u66F4\u65B0\u5B8C\u6210 (${duration}ms)`);
|
|
76
|
+
} else {
|
|
77
|
+
this.logger.success("\u77E5\u8BC6\u5E93\u66F4\u65B0\u5B8C\u6210");
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* 更新 root_item 配置
|
|
82
|
+
* 只更新当前月份的完成笔记数量
|
|
83
|
+
*/
|
|
84
|
+
async updateRootItem() {
|
|
85
|
+
try {
|
|
86
|
+
const configContent = readFileSync(ROOT_CONFIG_PATH, "utf-8");
|
|
87
|
+
const config = JSON.parse(configContent);
|
|
88
|
+
const readmePath = resolve(ROOT_DIR_PATH, "README.md");
|
|
89
|
+
if (!existsSync(readmePath)) {
|
|
90
|
+
throw new Error("\u6839\u76EE\u5F55 README.md \u4E0D\u5B58\u5728");
|
|
91
|
+
}
|
|
92
|
+
const readmeContent = readFileSync(readmePath, "utf-8");
|
|
93
|
+
const { completedCount } = parseReadmeCompletedNotes(readmeContent);
|
|
94
|
+
const now = /* @__PURE__ */ new Date();
|
|
95
|
+
const yearShort = String(now.getFullYear()).slice(-2);
|
|
96
|
+
const monthStr = String(now.getMonth() + 1).padStart(2, "0");
|
|
97
|
+
const currentKey = `${yearShort}.${monthStr}`;
|
|
98
|
+
const completedNotesCount = {
|
|
99
|
+
...config.root_item.completed_notes_count || {},
|
|
100
|
+
[currentKey]: completedCount
|
|
101
|
+
};
|
|
102
|
+
config.root_item = {
|
|
103
|
+
...config.root_item,
|
|
104
|
+
completed_notes_count: completedNotesCount
|
|
105
|
+
};
|
|
106
|
+
delete config.root_item.completed_notes_count_last_month;
|
|
107
|
+
writeFileSync(ROOT_CONFIG_PATH, JSON.stringify(config, null, 2), "utf-8");
|
|
108
|
+
if (!this.quiet) {
|
|
109
|
+
this.logger.success(
|
|
110
|
+
`root_item \u914D\u7F6E\u5DF2\u66F4\u65B0: ${currentKey} \u6708\u5B8C\u6210 ${completedCount} \u7BC7\u7B14\u8BB0`
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
} catch (error) {
|
|
114
|
+
if (!this.quiet) {
|
|
115
|
+
this.logger.error(
|
|
116
|
+
`\u66F4\u65B0 root_item \u5931\u8D25: ${error instanceof Error ? error.message : String(error)}`
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
throw error;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
// commands/update-completed-count/UpdateCompletedCountCommand.ts
|
|
125
|
+
import { readFileSync as readFileSync2, writeFileSync as writeFileSync2 } from "fs";
|
|
126
|
+
import { execSync } from "child_process";
|
|
127
|
+
var UpdateCompletedCountCommand = class extends BaseCommand {
|
|
128
|
+
constructor() {
|
|
129
|
+
super("update-completed-count");
|
|
130
|
+
}
|
|
131
|
+
async run() {
|
|
132
|
+
await this.updateCurrentRepo();
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* 更新当前知识库
|
|
136
|
+
*/
|
|
137
|
+
async updateCurrentRepo() {
|
|
138
|
+
const startTime = Date.now();
|
|
139
|
+
try {
|
|
140
|
+
const configContent = readFileSync2(ROOT_CONFIG_PATH, "utf-8");
|
|
141
|
+
const config = JSON.parse(configContent);
|
|
142
|
+
this.logger.info("\u5F00\u59CB\u66F4\u65B0\u5B8C\u6210\u7B14\u8BB0\u6570\u91CF\u5386\u53F2\u8BB0\u5F55...");
|
|
143
|
+
const completedNotesCountHistory = await this.getCompletedNotesCountHistory(
|
|
144
|
+
config.root_item.created_at ?? Date.now()
|
|
145
|
+
);
|
|
146
|
+
config.root_item = {
|
|
147
|
+
...config.root_item,
|
|
148
|
+
completed_notes_count: completedNotesCountHistory
|
|
149
|
+
};
|
|
150
|
+
writeFileSync2(ROOT_CONFIG_PATH, JSON.stringify(config, null, 2), "utf-8");
|
|
151
|
+
const duration = Date.now() - startTime;
|
|
152
|
+
const monthKeys = Object.keys(completedNotesCountHistory);
|
|
153
|
+
const currentKey = monthKeys[monthKeys.length - 1];
|
|
154
|
+
const currentCount = completedNotesCountHistory[currentKey] || 0;
|
|
155
|
+
this.logger.success(
|
|
156
|
+
`\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)`
|
|
157
|
+
);
|
|
158
|
+
} catch (error) {
|
|
159
|
+
this.logger.error(
|
|
160
|
+
`\u66F4\u65B0\u5931\u8D25: ${error instanceof Error ? error.message : String(error)}`
|
|
161
|
+
);
|
|
162
|
+
throw error;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* 获取历史每个月的 completed_notes_count(最近12个月)
|
|
167
|
+
*
|
|
168
|
+
* 逻辑:
|
|
169
|
+
* 1. 计算最近12个月的范围(当前月份往前推11个月)
|
|
170
|
+
* 2. 遍历这12个月,从 Git 历史中读取 README.md
|
|
171
|
+
* 3. 解析 README.md 获取完成笔记数量
|
|
172
|
+
* 4. 如果知识库创建时间在这12个月内,之前的月份补0
|
|
173
|
+
* 5. 返回对象 { '25.01': 0, '25.02': 1, ..., '25.12': 15 }
|
|
174
|
+
*/
|
|
175
|
+
async getCompletedNotesCountHistory(createdAt) {
|
|
176
|
+
try {
|
|
177
|
+
const now = /* @__PURE__ */ new Date();
|
|
178
|
+
const currentYear = now.getFullYear();
|
|
179
|
+
const currentMonth = now.getMonth();
|
|
180
|
+
let firstYear = currentYear;
|
|
181
|
+
let firstMonth = currentMonth - 11;
|
|
182
|
+
if (firstMonth < 0) {
|
|
183
|
+
firstYear = currentYear - 1;
|
|
184
|
+
firstMonth = 12 + firstMonth;
|
|
185
|
+
}
|
|
186
|
+
const createdDate = new Date(createdAt);
|
|
187
|
+
const createdYear = createdDate.getFullYear();
|
|
188
|
+
const createdMonth = createdDate.getMonth();
|
|
189
|
+
const result = {};
|
|
190
|
+
let prevCount = 0;
|
|
191
|
+
for (let i = 0; i < 12; i++) {
|
|
192
|
+
const targetYear = firstYear + Math.floor((firstMonth + i) / 12);
|
|
193
|
+
const targetMonth = (firstMonth + i) % 12;
|
|
194
|
+
const yearShort = String(targetYear).slice(-2);
|
|
195
|
+
const monthStr = String(targetMonth + 1).padStart(2, "0");
|
|
196
|
+
const key = `${yearShort}.${monthStr}`;
|
|
197
|
+
const isBeforeCreation = targetYear < createdYear || targetYear === createdYear && targetMonth < createdMonth;
|
|
198
|
+
if (isBeforeCreation) {
|
|
199
|
+
result[key] = 0;
|
|
200
|
+
prevCount = 0;
|
|
201
|
+
this.logger.info(`\u2713 ${key}: 0 \u7BC7\uFF08\u65E9\u4E8E\u521B\u5EFA\u65F6\u95F4\uFF09`);
|
|
202
|
+
} else {
|
|
203
|
+
try {
|
|
204
|
+
const count = await this.getMonthCompletedCount(
|
|
205
|
+
targetYear,
|
|
206
|
+
targetMonth,
|
|
207
|
+
prevCount
|
|
208
|
+
);
|
|
209
|
+
result[key] = count;
|
|
210
|
+
prevCount = count;
|
|
211
|
+
this.logger.info(`\u2713 ${key}: ${count} \u7BC7`);
|
|
212
|
+
} catch (error) {
|
|
213
|
+
result[key] = prevCount;
|
|
214
|
+
this.logger.warn(`${key}: \u65E0\u6570\u636E\uFF0C\u4F7F\u7528 ${prevCount}\uFF08\u4E0A\u6708\u503C\uFF09`);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
return result;
|
|
219
|
+
} catch (error) {
|
|
220
|
+
this.logger.error(
|
|
221
|
+
`\u83B7\u53D6\u5386\u53F2\u6570\u636E\u5931\u8D25: ${error instanceof Error ? error.message : String(error)}`
|
|
222
|
+
);
|
|
223
|
+
return {};
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* 获取指定月份的完成笔记数量
|
|
228
|
+
* @param year - 年份
|
|
229
|
+
* @param month - 月份 (0-11)
|
|
230
|
+
* @param fallbackCount - 回退值(如果该月没有数据)
|
|
231
|
+
* @returns 完成笔记数量
|
|
232
|
+
*/
|
|
233
|
+
async getMonthCompletedCount(year, month, fallbackCount = 0) {
|
|
234
|
+
const lastDayOfMonth = new Date(year, month + 1, 0, 23, 59, 59);
|
|
235
|
+
const yearStr = lastDayOfMonth.getFullYear();
|
|
236
|
+
const monthStr = String(lastDayOfMonth.getMonth() + 1).padStart(2, "0");
|
|
237
|
+
const dayStr = String(lastDayOfMonth.getDate()).padStart(2, "0");
|
|
238
|
+
const untilDate = `${yearStr}-${monthStr}-${dayStr} 23:59:59 +0800`;
|
|
239
|
+
const commitHash = execSync(
|
|
240
|
+
`git log --until="${untilDate}" --format=%H -1 -- README.md`,
|
|
241
|
+
{
|
|
242
|
+
cwd: ROOT_DIR_PATH,
|
|
243
|
+
encoding: "utf-8"
|
|
244
|
+
}
|
|
245
|
+
).trim();
|
|
246
|
+
if (!commitHash) {
|
|
247
|
+
return fallbackCount;
|
|
248
|
+
}
|
|
249
|
+
let readmeContent;
|
|
250
|
+
try {
|
|
251
|
+
readmeContent = execSync(`git show ${commitHash}:README.md`, {
|
|
252
|
+
cwd: ROOT_DIR_PATH,
|
|
253
|
+
encoding: "utf-8"
|
|
254
|
+
});
|
|
255
|
+
} catch (error) {
|
|
256
|
+
return fallbackCount;
|
|
257
|
+
}
|
|
258
|
+
const { completedCount } = parseReadmeCompletedNotes(readmeContent);
|
|
259
|
+
return completedCount;
|
|
260
|
+
}
|
|
261
|
+
};
|
|
262
|
+
|
|
263
|
+
// commands/git/PushCommand.ts
|
|
264
|
+
var PushCommand = class extends BaseCommand {
|
|
265
|
+
gitService;
|
|
266
|
+
timestampService;
|
|
267
|
+
constructor() {
|
|
268
|
+
super("push");
|
|
269
|
+
this.gitService = new GitService();
|
|
270
|
+
this.timestampService = new TimestampService();
|
|
271
|
+
}
|
|
272
|
+
async run() {
|
|
273
|
+
try {
|
|
274
|
+
this.logger.info("\u68C0\u67E5\u662F\u5426\u6709\u66F4\u6539...");
|
|
275
|
+
const status = await this.gitService.getStatus();
|
|
276
|
+
const hasPendingCommits = (status.ahead ?? 0) > 0;
|
|
277
|
+
if (!status.hasChanges && !hasPendingCommits) {
|
|
278
|
+
this.logger.info("\u6CA1\u6709\u66F4\u6539\u9700\u8981\u63A8\u9001");
|
|
279
|
+
return;
|
|
280
|
+
}
|
|
281
|
+
const force = this.options.force === true;
|
|
282
|
+
if (force) {
|
|
283
|
+
this.logger.warn("\u4F7F\u7528\u5F3A\u5236\u63A8\u9001\u6A21\u5F0F (--force)");
|
|
284
|
+
}
|
|
285
|
+
if (status.hasChanges) {
|
|
286
|
+
this.logger.info(
|
|
287
|
+
`\u68C0\u6D4B\u5230 ${status.files.length} \u4E2A\u53D8\u66F4\u6587\u4EF6\uFF0C\u6B63\u5728\u63D0\u4EA4...`
|
|
288
|
+
);
|
|
289
|
+
const commitMessage = this.gitService.generateCommitMessage();
|
|
290
|
+
await runCommand("git add -A", ROOT_DIR_PATH);
|
|
291
|
+
await runCommand(`git commit -m "${commitMessage}"`, ROOT_DIR_PATH);
|
|
292
|
+
this.logger.info("\u4FEE\u590D\u7B14\u8BB0\u65F6\u95F4\u6233...");
|
|
293
|
+
await this.timestampService.fixAllTimestamps(false);
|
|
294
|
+
const afterFixStatus = await runCommand(
|
|
295
|
+
"git -c core.quotePath=false status --porcelain",
|
|
296
|
+
ROOT_DIR_PATH
|
|
297
|
+
);
|
|
298
|
+
const hasTimestampChanges = afterFixStatus.split(/\r?\n/).filter(Boolean).some((line) => line.includes(".tnotes.json"));
|
|
299
|
+
if (hasTimestampChanges) {
|
|
300
|
+
this.logger.info("\u5C06\u65F6\u95F4\u6233\u53D8\u66F4\u5408\u5E76\u5230 commit...");
|
|
301
|
+
await runCommand("git add -u", ROOT_DIR_PATH);
|
|
302
|
+
await runCommand("git commit --amend --no-edit", ROOT_DIR_PATH);
|
|
303
|
+
}
|
|
304
|
+
} else {
|
|
305
|
+
this.logger.info(`\u68C0\u6D4B\u5230 ${status.ahead} \u4E2A\u672A\u63A8\u9001\u7684\u63D0\u4EA4\uFF0C\u76F4\u63A5\u63A8\u9001...`);
|
|
306
|
+
}
|
|
307
|
+
this.logger.info("\u6B63\u5728\u63A8\u9001\u5230\u8FDC\u7A0B\u4ED3\u5E93...");
|
|
308
|
+
const pushCmd = force ? "git push --force" : "git push";
|
|
309
|
+
await runCommand(pushCmd, ROOT_DIR_PATH);
|
|
310
|
+
this.logger.success("\u63A8\u9001\u5B8C\u6210");
|
|
311
|
+
} catch (error) {
|
|
312
|
+
this.logger.error("\u63A8\u9001\u5931\u8D25:", error);
|
|
313
|
+
throw error;
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
};
|
|
317
|
+
|
|
318
|
+
// commands/git/PullCommand.ts
|
|
319
|
+
var PullCommand = class extends BaseCommand {
|
|
320
|
+
gitService;
|
|
321
|
+
constructor() {
|
|
322
|
+
super("pull");
|
|
323
|
+
this.gitService = new GitService();
|
|
324
|
+
}
|
|
325
|
+
async run() {
|
|
326
|
+
this.logger.info("\u6B63\u5728\u4ECE\u8FDC\u7A0B\u4ED3\u5E93\u62C9\u53D6...");
|
|
327
|
+
await this.gitService.pull();
|
|
328
|
+
this.logger.success("\u62C9\u53D6\u5B8C\u6210");
|
|
329
|
+
}
|
|
330
|
+
};
|
|
331
|
+
|
|
332
|
+
// commands/dev/DevCommand.ts
|
|
333
|
+
var DevCommand = class extends BaseCommand {
|
|
334
|
+
fileWatcherService;
|
|
335
|
+
vitepressService;
|
|
336
|
+
noteManager;
|
|
337
|
+
noteIndexCache;
|
|
338
|
+
configManager;
|
|
339
|
+
constructor() {
|
|
340
|
+
super("dev");
|
|
341
|
+
this.fileWatcherService = new FileWatcherService();
|
|
342
|
+
this.vitepressService = new VitepressService();
|
|
343
|
+
this.noteManager = NoteManager.getInstance();
|
|
344
|
+
this.noteIndexCache = NoteIndexCache.getInstance();
|
|
345
|
+
this.configManager = ConfigManager.getInstance();
|
|
346
|
+
}
|
|
347
|
+
async run() {
|
|
348
|
+
const notes = this.noteManager.scanNotes();
|
|
349
|
+
this.logger.info(`\u626B\u63CF\u5230 ${notes.length} \u7BC7\u7B14\u8BB0`);
|
|
350
|
+
this.noteIndexCache.initialize(notes);
|
|
351
|
+
const result = await this.vitepressService.startServer();
|
|
352
|
+
if (result) {
|
|
353
|
+
const versionInfo = result.version ? `\uFF08v${result.version}\uFF09` : "";
|
|
354
|
+
this.logger.success(
|
|
355
|
+
`VitePress \u670D\u52A1${versionInfo}\u5DF2\u5C31\u7EEA\uFF0C\u8017\u65F6\uFF1A${result.elapsed} ms`
|
|
356
|
+
);
|
|
357
|
+
const watcherStart = Date.now();
|
|
358
|
+
this.fileWatcherService.start();
|
|
359
|
+
const watcherElapsed = Date.now() - watcherStart;
|
|
360
|
+
this.logger.success(`\u6587\u4EF6\u76D1\u542C\u670D\u52A1\u5DF2\u5C31\u7EEA\uFF0C\u8017\u65F6\uFF1A${watcherElapsed} ms`);
|
|
361
|
+
const port = this.configManager.get("port") || VitepressService.DEFAULT_DEV_PORT;
|
|
362
|
+
const repoName = this.configManager.get("repoName");
|
|
363
|
+
this.logger.info(
|
|
364
|
+
`\u672C\u5730\u5F00\u53D1\u670D\u52A1\u5730\u5740\uFF1Ahttp://localhost:${port}/${repoName}/`
|
|
365
|
+
);
|
|
366
|
+
} else {
|
|
367
|
+
this.logger.error("\u542F\u52A8\u670D\u52A1\u5668\u5931\u8D25");
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
};
|
|
371
|
+
|
|
372
|
+
// commands/build/BuildCommand.ts
|
|
373
|
+
var BuildCommand = class extends BaseCommand {
|
|
374
|
+
vitepressService;
|
|
375
|
+
constructor() {
|
|
376
|
+
super("build");
|
|
377
|
+
this.vitepressService = new VitepressService();
|
|
378
|
+
}
|
|
379
|
+
async run() {
|
|
380
|
+
this.logger.info("\u5F00\u59CB\u6784\u5EFA\u77E5\u8BC6\u5E93...");
|
|
381
|
+
await this.vitepressService.build();
|
|
382
|
+
this.logger.success("\u77E5\u8BC6\u5E93\u6784\u5EFA\u5B8C\u6210");
|
|
383
|
+
}
|
|
384
|
+
};
|
|
385
|
+
|
|
386
|
+
// commands/build/PreviewCommand.ts
|
|
387
|
+
var PreviewCommand = class extends BaseCommand {
|
|
388
|
+
vitepressService;
|
|
389
|
+
constructor() {
|
|
390
|
+
super("preview");
|
|
391
|
+
this.vitepressService = new VitepressService();
|
|
392
|
+
}
|
|
393
|
+
async run() {
|
|
394
|
+
this.logger.info("\u542F\u52A8\u9884\u89C8\u670D\u52A1\u5668...");
|
|
395
|
+
const pid = await this.vitepressService.preview();
|
|
396
|
+
if (pid) {
|
|
397
|
+
this.logger.success(`\u9884\u89C8\u670D\u52A1\u5668\u5DF2\u542F\u52A8 (PID: ${pid})`);
|
|
398
|
+
} else {
|
|
399
|
+
this.logger.error("\u542F\u52A8\u9884\u89C8\u670D\u52A1\u5668\u5931\u8D25");
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
};
|
|
403
|
+
|
|
404
|
+
// commands/note/CreateNoteCommand.ts
|
|
405
|
+
import { createInterface } from "readline";
|
|
406
|
+
import { v4 as uuidv4 } from "uuid";
|
|
407
|
+
var CreateNoteCommand = class extends BaseCommand {
|
|
408
|
+
noteService;
|
|
409
|
+
readmeService;
|
|
410
|
+
constructor() {
|
|
411
|
+
super("create-notes");
|
|
412
|
+
this.noteService = NoteService.getInstance();
|
|
413
|
+
this.readmeService = ReadmeService.getInstance();
|
|
414
|
+
}
|
|
415
|
+
async run() {
|
|
416
|
+
this.logger.info("\u521B\u5EFA\u65B0\u7B14\u8BB0...");
|
|
417
|
+
const count = await this.promptForCount();
|
|
418
|
+
let successCount = 0;
|
|
419
|
+
let failCount = 0;
|
|
420
|
+
const createdNotes = [];
|
|
421
|
+
const existingNotes = this.noteService.getAllNotes();
|
|
422
|
+
const usedIndexes = /* @__PURE__ */ new Set();
|
|
423
|
+
for (const note of existingNotes) {
|
|
424
|
+
const index = parseInt(note.index, 10);
|
|
425
|
+
if (!isNaN(index) && index >= 1 && index <= 9999) {
|
|
426
|
+
usedIndexes.add(index);
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
for (let i = 1; i <= count; i++) {
|
|
430
|
+
try {
|
|
431
|
+
let title;
|
|
432
|
+
if (count === 1) {
|
|
433
|
+
title = await this.promptForTitle();
|
|
434
|
+
} else {
|
|
435
|
+
title = `new`;
|
|
436
|
+
this.logger.info(`[${i}/${count}] \u521B\u5EFA\u7B14\u8BB0: ${title}`);
|
|
437
|
+
}
|
|
438
|
+
const configId = uuidv4();
|
|
439
|
+
const note = await this.noteService.createNote({
|
|
440
|
+
title: title || `new`,
|
|
441
|
+
enableDiscussions: false,
|
|
442
|
+
configId,
|
|
443
|
+
// 传递 UUID 作为配置 ID(跨知识库唯一)
|
|
444
|
+
usedIndexes
|
|
445
|
+
// 传入已使用编号集合,避免重复扫描
|
|
446
|
+
});
|
|
447
|
+
const newIndex = parseInt(note.index, 10);
|
|
448
|
+
if (!isNaN(newIndex)) {
|
|
449
|
+
usedIndexes.add(newIndex);
|
|
450
|
+
}
|
|
451
|
+
createdNotes.push(note.dirName);
|
|
452
|
+
successCount++;
|
|
453
|
+
if (count === 1) {
|
|
454
|
+
this.logger.success(`\u7B14\u8BB0\u521B\u5EFA\u6210\u529F: ${note.dirName}`);
|
|
455
|
+
this.logger.info(`\u7B14\u8BB0\u8DEF\u5F84: ${note.path}`);
|
|
456
|
+
this.logger.info(`\u7B14\u8BB0\u7F16\u53F7: ${note.index}`);
|
|
457
|
+
this.logger.info(`\u914D\u7F6EID: ${configId}`);
|
|
458
|
+
} else {
|
|
459
|
+
this.logger.success(`[${i}/${count}] \u521B\u5EFA\u6210\u529F: ${note.dirName}`);
|
|
460
|
+
}
|
|
461
|
+
} catch (error) {
|
|
462
|
+
failCount++;
|
|
463
|
+
this.logger.error(`[${i}/${count}] \u521B\u5EFA\u5931\u8D25`, error);
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
if (count > 1) {
|
|
467
|
+
console.log("");
|
|
468
|
+
this.logger.info(
|
|
469
|
+
`\u{1F4CA} \u521B\u5EFA\u5B8C\u6210: \u6210\u529F ${successCount} \u7BC7, \u5931\u8D25 ${failCount} \u7BC7`
|
|
470
|
+
);
|
|
471
|
+
}
|
|
472
|
+
if (successCount > 0) {
|
|
473
|
+
this.logger.info("\u6B63\u5728\u66F4\u65B0\u77E5\u8BC6\u5E93\u7D22\u5F15...");
|
|
474
|
+
await this.readmeService.updateAllReadmes();
|
|
475
|
+
this.logger.success("\u77E5\u8BC6\u5E93\u7D22\u5F15\u66F4\u65B0\u5B8C\u6210");
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
/**
|
|
479
|
+
* 提示用户输入要创建的笔记数量
|
|
480
|
+
*/
|
|
481
|
+
async promptForCount() {
|
|
482
|
+
const rl = createInterface({
|
|
483
|
+
input: process.stdin,
|
|
484
|
+
output: process.stdout
|
|
485
|
+
});
|
|
486
|
+
return new Promise((resolve2) => {
|
|
487
|
+
rl.question("\n\u{1F4DD} \u8BF7\u8F93\u5165\u8981\u521B\u5EFA\u7684\u7B14\u8BB0\u6570\u91CF\uFF08\u9ED8\u8BA4\u4E3A 1\uFF09: ", (answer) => {
|
|
488
|
+
rl.close();
|
|
489
|
+
const trimmed = answer.trim();
|
|
490
|
+
if (!trimmed) {
|
|
491
|
+
this.logger.info("\u4F7F\u7528\u9ED8\u8BA4\u6570\u91CF: 1");
|
|
492
|
+
resolve2(1);
|
|
493
|
+
return;
|
|
494
|
+
}
|
|
495
|
+
const num = parseInt(trimmed, 10);
|
|
496
|
+
if (isNaN(num) || num < 1 || !Number.isInteger(num)) {
|
|
497
|
+
this.logger.warn(`\u8F93\u5165 "${trimmed}" \u4E0D\u662F\u6709\u6548\u7684\u6B63\u6574\u6570\uFF0C\u4F7F\u7528\u9ED8\u8BA4\u503C: 1`);
|
|
498
|
+
resolve2(1);
|
|
499
|
+
return;
|
|
500
|
+
}
|
|
501
|
+
this.logger.info(`\u5C06\u521B\u5EFA ${num} \u7BC7\u7B14\u8BB0`);
|
|
502
|
+
resolve2(num);
|
|
503
|
+
});
|
|
504
|
+
});
|
|
505
|
+
}
|
|
506
|
+
/**
|
|
507
|
+
* 提示用户输入笔记标题
|
|
508
|
+
*/
|
|
509
|
+
async promptForTitle() {
|
|
510
|
+
const rl = createInterface({
|
|
511
|
+
input: process.stdin,
|
|
512
|
+
output: process.stdout
|
|
513
|
+
});
|
|
514
|
+
return new Promise((resolve2) => {
|
|
515
|
+
rl.question("\u8BF7\u8F93\u5165\u7B14\u8BB0\u6807\u9898: ", (answer) => {
|
|
516
|
+
rl.close();
|
|
517
|
+
resolve2(answer.trim());
|
|
518
|
+
});
|
|
519
|
+
});
|
|
520
|
+
}
|
|
521
|
+
};
|
|
522
|
+
|
|
523
|
+
// commands/maintenance/FixTimestampsCommand.ts
|
|
524
|
+
var FixTimestampsCommand = class extends BaseCommand {
|
|
525
|
+
timestampService;
|
|
526
|
+
constructor() {
|
|
527
|
+
super("fix-timestamps");
|
|
528
|
+
this.timestampService = new TimestampService();
|
|
529
|
+
}
|
|
530
|
+
async run() {
|
|
531
|
+
this.logger.info("\u5F00\u59CB\u4FEE\u590D\u6240\u6709\u7B14\u8BB0\u7684\u65F6\u95F4\u6233...");
|
|
532
|
+
this.logger.info("\u{1F4CC} \u6B64\u64CD\u4F5C\u4F1A\u5C06\u6240\u6709\u65F6\u95F4\u6233\u66F4\u65B0\u4E3A git \u771F\u5B9E\u65F6\u95F4");
|
|
533
|
+
this.logger.info("");
|
|
534
|
+
const result = await this.timestampService.fixAllTimestamps(true);
|
|
535
|
+
this.logger.info("");
|
|
536
|
+
this.logger.info("\u{1F4CA} \u4FEE\u590D\u7EDF\u8BA1:");
|
|
537
|
+
this.logger.info(
|
|
538
|
+
` - \u6839\u914D\u7F6E\u6587\u4EF6: ${result.rootConfigFixed ? "\u5DF2\u4FEE\u590D" : "\u65E0\u9700\u4FEE\u590D"}`
|
|
539
|
+
);
|
|
540
|
+
this.logger.info(` - \u603B\u7B14\u8BB0\u6570: ${result.total}`);
|
|
541
|
+
this.logger.info(` - \u5DF2\u4FEE\u590D: ${result.fixed}`);
|
|
542
|
+
this.logger.info(` - \u8DF3\u8FC7: ${result.skipped}`);
|
|
543
|
+
this.logger.info("");
|
|
544
|
+
if (result.fixed > 0 || result.rootConfigFixed) {
|
|
545
|
+
this.logger.success(
|
|
546
|
+
`\u2705 \u6210\u529F\u4FEE\u590D ${result.fixed} \u4E2A\u7B14\u8BB0${result.rootConfigFixed ? " + \u6839\u914D\u7F6E\u6587\u4EF6" : ""}\u7684\u65F6\u95F4\u6233\uFF01`
|
|
547
|
+
);
|
|
548
|
+
this.logger.info("\u{1F4A1} \u63D0\u793A: \u8FD0\u884C pnpm tn:push \u63D0\u4EA4\u66F4\u6539");
|
|
549
|
+
} else {
|
|
550
|
+
this.logger.success("\u2705 \u6240\u6709\u65F6\u95F4\u6233\u5747\u5DF2\u6B63\u786E\uFF01");
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
};
|
|
554
|
+
|
|
555
|
+
// commands/misc/HelpCommand.ts
|
|
556
|
+
var COMMAND_CATEGORIES = {
|
|
557
|
+
\u5F00\u53D1\u548C\u6784\u5EFA: [COMMAND_NAMES.DEV, COMMAND_NAMES.BUILD, COMMAND_NAMES.PREVIEW],
|
|
558
|
+
\u5185\u5BB9\u7BA1\u7406: [
|
|
559
|
+
COMMAND_NAMES.UPDATE,
|
|
560
|
+
COMMAND_NAMES.UPDATE_COMPLETED_COUNT,
|
|
561
|
+
COMMAND_NAMES.CREATE_NOTES
|
|
562
|
+
],
|
|
563
|
+
"Git \u64CD\u4F5C": [COMMAND_NAMES.PUSH, COMMAND_NAMES.PULL],
|
|
564
|
+
\u5176\u4ED6: [COMMAND_NAMES.FIX_TIMESTAMPS, COMMAND_NAMES.HELP]
|
|
565
|
+
};
|
|
566
|
+
var COMMAND_OPTIONS_INFO = {
|
|
567
|
+
[COMMAND_OPTIONS.QUIET]: {
|
|
568
|
+
description: "\u9759\u9ED8\u6A21\u5F0F",
|
|
569
|
+
applicableTo: "update"
|
|
570
|
+
},
|
|
571
|
+
[COMMAND_OPTIONS.FORCE]: {
|
|
572
|
+
description: "\u5F3A\u5236\u63A8\u9001",
|
|
573
|
+
applicableTo: "push"
|
|
574
|
+
}
|
|
575
|
+
};
|
|
576
|
+
var HelpCommand = class extends BaseCommand {
|
|
577
|
+
constructor() {
|
|
578
|
+
super("help");
|
|
579
|
+
this.logger = createLogger("help", {
|
|
580
|
+
timestamp: false,
|
|
581
|
+
level: process.env.DEBUG ? 0 /* DEBUG */ : 1 /* INFO */
|
|
582
|
+
});
|
|
583
|
+
}
|
|
584
|
+
async run() {
|
|
585
|
+
this.logger.info("TNotes \u547D\u4EE4\u884C\u5DE5\u5177");
|
|
586
|
+
this.logger.info("");
|
|
587
|
+
this.logger.info("\u7528\u6CD5\uFF1Apnpm tn:<command> # \u63A8\u8350");
|
|
588
|
+
this.logger.info("\u6216\u8005\uFF1Anpx tsx ./.vitepress/tnotes/index.ts --<command>");
|
|
589
|
+
this.logger.info("");
|
|
590
|
+
this.logger.info("\u53EF\u7528\u547D\u4EE4\uFF1A");
|
|
591
|
+
this.logger.info("");
|
|
592
|
+
for (const [category, cmdNames] of Object.entries(COMMAND_CATEGORIES)) {
|
|
593
|
+
this.logger.info(` ${category}:`);
|
|
594
|
+
for (const cmdName of cmdNames) {
|
|
595
|
+
const description = COMMAND_DESCRIPTIONS[cmdName];
|
|
596
|
+
const paddingLength = Math.max(25 - cmdName.length, 1);
|
|
597
|
+
const padding = " ".repeat(paddingLength);
|
|
598
|
+
this.logger.info(` --${cmdName}${padding}${description}`);
|
|
599
|
+
}
|
|
600
|
+
this.logger.info("");
|
|
601
|
+
}
|
|
602
|
+
this.logger.info("\u793A\u4F8B\uFF1A");
|
|
603
|
+
this.logger.info(" npx tsx ./.vitepress/tnotes/index.ts --dev");
|
|
604
|
+
this.logger.info(" pnpm tn:build");
|
|
605
|
+
this.logger.info(" pnpm tn:create-notes # \u6279\u91CF\u521B\u5EFA\u7B14\u8BB0");
|
|
606
|
+
this.logger.info(" pnpm tn:update");
|
|
607
|
+
this.logger.info(
|
|
608
|
+
" 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"
|
|
609
|
+
);
|
|
610
|
+
this.logger.info("");
|
|
611
|
+
this.logger.info("\u53C2\u6570\uFF1A");
|
|
612
|
+
for (const [option, info] of Object.entries(COMMAND_OPTIONS_INFO)) {
|
|
613
|
+
const paddingLength = Math.max(13 - option.length, 1);
|
|
614
|
+
const padding = " ".repeat(paddingLength);
|
|
615
|
+
this.logger.info(
|
|
616
|
+
` --${option}${padding}${info.description} (\u9002\u7528\u4E8E ${info.applicableTo})`
|
|
617
|
+
);
|
|
618
|
+
}
|
|
619
|
+
this.logger.info("");
|
|
620
|
+
this.logger.info("\u73AF\u5883\u53D8\u91CF\uFF1A");
|
|
621
|
+
this.logger.info(" DEBUG=1 \u542F\u7528\u8C03\u8BD5\u6A21\u5F0F\uFF0C\u663E\u793A\u8BE6\u7EC6\u65E5\u5FD7");
|
|
622
|
+
this.logger.info("");
|
|
623
|
+
this.logger.info("\u66F4\u591A\u4FE1\u606F\u8BF7\u67E5\u770B: .vitepress/tnotes/README.md");
|
|
624
|
+
}
|
|
625
|
+
};
|
|
626
|
+
|
|
627
|
+
// commands/registry.ts
|
|
628
|
+
var commandFactories = {
|
|
629
|
+
dev: () => new DevCommand(),
|
|
630
|
+
build: () => new BuildCommand(),
|
|
631
|
+
preview: () => new PreviewCommand(),
|
|
632
|
+
update: () => new UpdateCommand(),
|
|
633
|
+
"update-completed-count": () => new UpdateCompletedCountCommand(),
|
|
634
|
+
push: () => new PushCommand(),
|
|
635
|
+
pull: () => new PullCommand(),
|
|
636
|
+
"create-notes": () => new CreateNoteCommand(),
|
|
637
|
+
"fix-timestamps": () => new FixTimestampsCommand(),
|
|
638
|
+
"update-note-config": () => new UpdateNoteConfigCommand(),
|
|
639
|
+
"rename-note": () => new RenameNoteCommand(),
|
|
640
|
+
help: () => new HelpCommand()
|
|
641
|
+
};
|
|
642
|
+
var commandCache = /* @__PURE__ */ new Map();
|
|
643
|
+
function getCommand(name) {
|
|
644
|
+
if (!commandFactories[name]) return void 0;
|
|
645
|
+
if (!commandCache.has(name)) commandCache.set(name, commandFactories[name]());
|
|
646
|
+
return commandCache.get(name);
|
|
647
|
+
}
|
|
648
|
+
|
|
649
|
+
// index.ts
|
|
650
|
+
(async () => {
|
|
651
|
+
try {
|
|
652
|
+
const args = parseArgs(process.argv.slice(2));
|
|
653
|
+
const commandName = Object.keys(args).find(
|
|
654
|
+
(key) => key !== "_" && args[key] === true
|
|
655
|
+
);
|
|
656
|
+
const command = commandName ? getCommand(commandName) : null;
|
|
657
|
+
if (!command) {
|
|
658
|
+
const logger2 = createLogger("command-not-found", {
|
|
659
|
+
timestamp: false
|
|
660
|
+
});
|
|
661
|
+
console.log(`
|
|
662
|
+
${"-".repeat(66)}
|
|
663
|
+
`);
|
|
664
|
+
if (commandName) {
|
|
665
|
+
logger2.warn(`\u672A\u627E\u5230\u547D\u4EE4\uFF1A${commandName}`);
|
|
666
|
+
logger2.info(`\u8BF7\u68C0\u67E5\u547D\u4EE4\u540D\u662F\u5426\u6B63\u786E\uFF01`);
|
|
667
|
+
} else {
|
|
668
|
+
logger2.warn(`\u672A\u68C0\u6D4B\u5230\u547D\u4EE4\u540D\uFF0C\u8BF7\u68C0\u67E5\u547D\u4EE4\u8F93\u5165\u662F\u5426\u6B63\u786E`);
|
|
669
|
+
logger2.info(`\u793A\u4F8B\uFF1A`);
|
|
670
|
+
logger2.info(`pnpm tn:<\u547D\u4EE4\u540D>`);
|
|
671
|
+
logger2.info(`npx tsx ./.vitepress/tnotes/index.ts --<\u547D\u4EE4\u540D>`);
|
|
672
|
+
}
|
|
673
|
+
console.log(`
|
|
674
|
+
${"-".repeat(66)}
|
|
675
|
+
`);
|
|
676
|
+
const helpCommand = getCommand(COMMAND_NAMES.HELP);
|
|
677
|
+
if (helpCommand) {
|
|
678
|
+
console.log("\n\u6B63\u5728\u6267\u884C pnpm tn:help \u6253\u5370\u5E2E\u52A9\u4FE1\u606F...\n");
|
|
679
|
+
await helpCommand.execute();
|
|
680
|
+
}
|
|
681
|
+
return;
|
|
682
|
+
}
|
|
683
|
+
if (commandName === COMMAND_NAMES.UPDATE) {
|
|
684
|
+
const cmd = command;
|
|
685
|
+
if (args.quiet) cmd.setQuiet(true);
|
|
686
|
+
} else if (commandName === COMMAND_NAMES.PUSH) {
|
|
687
|
+
const cmd = command;
|
|
688
|
+
if (args.force) cmd.setOptions({ force: true });
|
|
689
|
+
}
|
|
690
|
+
await command.execute();
|
|
691
|
+
} catch (error) {
|
|
692
|
+
handleError(error, true);
|
|
693
|
+
}
|
|
694
|
+
})();
|