@tnotesjs/core 0.6.0 → 0.7.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.
Files changed (42) hide show
  1. package/config/templates.ts +0 -5
  2. package/dist/{chunk-IHFUHB4J.cjs → chunk-7FEANCT6.cjs} +17 -8
  3. package/dist/chunk-AGVER5MX.cjs +1746 -0
  4. package/dist/{chunk-TJ4527KA.cjs → chunk-BL22KD4V.cjs} +324 -950
  5. package/dist/{chunk-UNFSW5C2.js → chunk-GWG75A5M.js} +14 -5
  6. package/dist/{chunk-DUTS75WQ.js → chunk-XNO3PCEH.js} +374 -1000
  7. package/dist/chunk-ZEQS64PE.js +1746 -0
  8. package/dist/cli/index.cjs +76 -155
  9. package/dist/cli/index.js +10 -89
  10. package/dist/markdown/index.cjs +2 -3
  11. package/dist/markdown/index.d.cts +1 -1
  12. package/dist/markdown/index.d.ts +1 -1
  13. package/dist/markdown/index.js +1 -2
  14. package/dist/{types-CwBWwNVv.d.ts → types-C_d0fFeD.d.ts} +8 -1
  15. package/dist/{types-CpsEy8lA.d.cts → types-MRBGgJTX.d.cts} +8 -1
  16. package/dist/vitepress/config/index.cjs +200 -132
  17. package/dist/vitepress/config/index.js +187 -119
  18. package/dist/workspace/index.cjs +4 -1202
  19. package/dist/workspace/index.d.cts +2 -2
  20. package/dist/workspace/index.d.ts +2 -2
  21. package/dist/workspace/index.js +4 -1202
  22. package/package.json +2 -2
  23. package/services/file-watcher/folderChangeHandler.ts +19 -15
  24. package/services/file-watcher/globalUpdateCoordinator.ts +21 -27
  25. package/services/file-watcher/service.ts +1 -6
  26. package/services/index.ts +0 -1
  27. package/services/note/service.ts +4 -6
  28. package/services/readme/service.ts +11 -18
  29. package/services/reconcileToc.ts +20 -0
  30. package/utils/index.ts +0 -9
  31. package/{services/toc → utils}/moveTocInside.test.ts +1 -1
  32. package/vitepress/components/constants.ts +2 -2
  33. package/vitepress/components/sidebar.data.ts +8 -5
  34. package/vitepress/plugins/sidebarStructurePlugin.ts +242 -145
  35. package/dist/chunk-3R7QSABB.cjs +0 -502
  36. package/dist/chunk-CZXRQPFJ.js +0 -11
  37. package/dist/chunk-HXED7KVT.cjs +0 -11
  38. package/dist/chunk-U6IBLREL.js +0 -502
  39. package/services/toc/index.ts +0 -5
  40. package/services/toc/service.ts +0 -759
  41. package/utils/migrateReadmeToToc.test.ts +0 -111
  42. package/utils/migrateReadmeToToc.ts +0 -135
package/dist/cli/index.js CHANGED
@@ -15,11 +15,9 @@ import {
15
15
  NoteService,
16
16
  ROOT_CONFIG_PATH,
17
17
  ROOT_DIR_PATH,
18
- ROOT_README_PATH,
19
18
  ROOT_TOC_PATH,
20
19
  ReadmeService,
21
20
  RenameNoteCommand,
22
- TocService,
23
21
  UpdateNoteConfigCommand,
24
22
  VitepressService,
25
23
  buildInitContext,
@@ -30,26 +28,22 @@ import {
30
28
  handleError,
31
29
  isAlreadyInitialized,
32
30
  logger,
33
- migrateReadmeToToc,
34
31
  parseArgs,
35
32
  parseReadmeCompletedNotes,
33
+ reconcileTocFromFiles,
36
34
  runCommand,
37
35
  validatePort,
38
36
  validateTopic
39
- } from "../chunk-DUTS75WQ.js";
37
+ } from "../chunk-XNO3PCEH.js";
40
38
  import {
41
39
  ConfigManager,
42
40
  getConfigManager,
43
41
  stripDeprecatedRootItemFields
44
42
  } from "../chunk-UJG3UU5X.js";
45
43
  import {
46
- buildFolderTocLine,
47
- buildTocLine,
48
- parseTocCompletedNotes,
49
- processTocEmptyLines,
50
- resolveNoteFromIndex
51
- } from "../chunk-U6IBLREL.js";
52
- import "../chunk-CZXRQPFJ.js";
44
+ parseTocCompletedNotes
45
+ } from "../chunk-ZEQS64PE.js";
46
+ import "../chunk-GWG75A5M.js";
53
47
 
54
48
  // commands/update/UpdateCommand.ts
55
49
  import { existsSync, readFileSync, writeFileSync } from "fs";
@@ -284,15 +278,13 @@ var DevCommand = class extends BaseCommand {
284
278
  this.fileWatcherService = new FileWatcherService();
285
279
  this.noteIndexCache = NoteIndexCache.getInstance();
286
280
  this.noteManager = NoteManager.getInstance();
287
- this.tocService = TocService.getInstance();
288
281
  this.vitepressService = new VitepressService();
289
282
  }
290
283
  async run() {
291
284
  const notes = this.noteManager.scanNotes();
292
285
  this.logger.info(`\u626B\u63CF\u5230 ${notes.length} \u7BC7\u7B14\u8BB0`);
293
286
  this.noteIndexCache.initialize(notes);
294
- this.tocService.ensureTocExists();
295
- await this.tocService.regenerateSidebar(notes);
287
+ await reconcileTocFromFiles(ROOT_DIR_PATH);
296
288
  const result = await this.vitepressService.startServer();
297
289
  if (result) {
298
290
  const versionInfo = result.version ? `\uFF08v${result.version}\uFF09` : "";
@@ -387,11 +379,7 @@ var InitSubRepoCommand = class extends BaseCommand {
387
379
  try {
388
380
  this.logger.info("");
389
381
  this.logger.info("\u6B63\u5728\u89C4\u8303\u5316 TOC.md \u5E76\u751F\u6210 sidebar.json...");
390
- const noteService = NoteService.getInstance();
391
- const tocService = TocService.getInstance();
392
- const notes = noteService.getAllNotes();
393
- await tocService.normalizeToc(notes);
394
- await tocService.regenerateSidebar(notes);
382
+ await reconcileTocFromFiles(ROOT_DIR_PATH);
395
383
  this.logger.success("sidebar.json \u5DF2\u751F\u6210");
396
384
  } catch (error) {
397
385
  this.logger.warn(
@@ -470,68 +458,6 @@ var InitSubRepoCommand = class extends BaseCommand {
470
458
  }
471
459
  };
472
460
 
473
- // commands/init-toc/InitTocCommand.ts
474
- import { existsSync as existsSync2, readFileSync as readFileSync3, writeFileSync as writeFileSync2 } from "fs";
475
- var InitTocCommand = class extends BaseCommand {
476
- constructor() {
477
- super("init-toc");
478
- this.noteManager = NoteManager.getInstance();
479
- this.tocService = TocService.getInstance();
480
- }
481
- async run() {
482
- if (!existsSync2(ROOT_README_PATH)) {
483
- throw new Error(`README.md \u4E0D\u5B58\u5728: ${ROOT_README_PATH}`);
484
- }
485
- const readmeContent = readFileSync3(ROOT_README_PATH, "utf-8");
486
- const notes = this.noteManager.scanNotes();
487
- const { entries, warnings } = migrateReadmeToToc(readmeContent);
488
- for (const warning of warnings) {
489
- this.logger.warn(warning);
490
- }
491
- const lines = [];
492
- let skipped = 0;
493
- for (const entry of entries) {
494
- if (entry.kind === "folder") {
495
- lines.push(buildFolderTocLine(entry.folderTitle, entry.indent));
496
- continue;
497
- }
498
- const note = resolveNoteFromIndex(entry.noteIndex, notes);
499
- if (!note) {
500
- skipped++;
501
- this.logger.warn(
502
- `\u8DF3\u8FC7 README \u4E2D\u5B58\u5728\u4F46 notes/ \u76EE\u5F55\u4E2D\u4E0D\u5B58\u5728\u7684\u7B14\u8BB0: ${entry.noteIndex}`
503
- );
504
- continue;
505
- }
506
- lines.push(buildTocLine(note, entry.indent, entry.completed));
507
- }
508
- if (lines.length === 0) {
509
- throw new Error(
510
- "\u672A\u80FD\u4ECE README.md \u89E3\u6790\u5230\u4EFB\u4F55\u6709\u6548\u7B14\u8BB0\u6761\u76EE\uFF0CTOC.md \u672A\u5199\u5165"
511
- );
512
- }
513
- const content = processTocEmptyLines(lines).join("\n");
514
- writeFileSync2(ROOT_TOC_PATH, content, "utf-8");
515
- await this.tocService.regenerateSidebar(notes);
516
- this.logger.success(
517
- `TOC.md \u5DF2\u4ECE README.md \u521D\u59CB\u5316\uFF08${lines.length} \u6761\u7B14\u8BB0${skipped > 0 ? `\uFF0C\u8DF3\u8FC7 ${skipped} \u6761` : ""}\uFF09`
518
- );
519
- this.logger.info(`\u8F93\u51FA\u8DEF\u5F84: ${ROOT_TOC_PATH}`);
520
- this.logger.info(
521
- "\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"
522
- );
523
- const listedIndexes = new Set(
524
- entries.filter((e) => e.kind === "note").map((e) => e.noteIndex)
525
- );
526
- const missingInReadme = notes.filter((n) => !listedIndexes.has(n.index));
527
- if (missingInReadme.length > 0) {
528
- this.logger.info(
529
- `README \u4E2D\u672A\u5217\u51FA ${missingInReadme.length} \u7BC7\u7B14\u8BB0\uFF0C\u53EF\u6267\u884C pnpm tn:update \u8FFD\u52A0\u5230 TOC.md`
530
- );
531
- }
532
- }
533
- };
534
-
535
461
  // commands/misc/HelpCommand.ts
536
462
  var COMMAND_CATEGORIES = {
537
463
  \u5F00\u53D1\u548C\u6784\u5EFA: [COMMAND_NAMES.DEV, COMMAND_NAMES.BUILD, COMMAND_NAMES.PREVIEW],
@@ -541,7 +467,6 @@ var COMMAND_CATEGORIES = {
541
467
  COMMAND_NAMES.CREATE_NOTES
542
468
  ],
543
469
  "Git \u64CD\u4F5C": [COMMAND_NAMES.PUSH, COMMAND_NAMES.PULL],
544
- "\u8FC1\u79FB\uFF08v0.2.x \u8FC7\u6E21\uFF09": [COMMAND_NAMES.INIT_TOC],
545
470
  \u521D\u59CB\u5316: [COMMAND_NAMES.INIT_SUB_REPO],
546
471
  \u5176\u4ED6: [COMMAND_NAMES.HELP]
547
472
  };
@@ -586,9 +511,6 @@ var HelpCommand = class extends BaseCommand {
586
511
  this.logger.info(" pnpm tn:build");
587
512
  this.logger.info(" pnpm tn:create-notes # \u6279\u91CF\u521B\u5EFA\u7B14\u8BB0");
588
513
  this.logger.info(" pnpm tn:update");
589
- this.logger.info(
590
- " pnpm tn:init-toc # v0.1.x \u2192 v0.2.x\uFF1A\u4ECE README.md \u751F\u6210 TOC.md"
591
- );
592
514
  this.logger.info(
593
515
  " 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"
594
516
  );
@@ -728,7 +650,7 @@ var CreateNoteCommand = class extends BaseCommand {
728
650
 
729
651
  // commands/update-completed-count/UpdateCompletedCountCommand.ts
730
652
  import { execSync } from "child_process";
731
- import { readFileSync as readFileSync4, writeFileSync as writeFileSync3 } from "fs";
653
+ import { readFileSync as readFileSync3, writeFileSync as writeFileSync2 } from "fs";
732
654
  var UpdateCompletedCountCommand = class extends BaseCommand {
733
655
  constructor() {
734
656
  super("update-completed-count");
@@ -742,7 +664,7 @@ var UpdateCompletedCountCommand = class extends BaseCommand {
742
664
  async updateCurrentRepo() {
743
665
  const startTime = Date.now();
744
666
  try {
745
- const configContent = readFileSync4(ROOT_CONFIG_PATH, "utf-8");
667
+ const configContent = readFileSync3(ROOT_CONFIG_PATH, "utf-8");
746
668
  const config = JSON.parse(configContent);
747
669
  this.logger.info("\u5F00\u59CB\u66F4\u65B0\u5B8C\u6210\u7B14\u8BB0\u6570\u91CF\u5386\u53F2\u8BB0\u5F55...");
748
670
  const completedNotesCountHistory = await this.getCompletedNotesCountHistory();
@@ -753,7 +675,7 @@ var UpdateCompletedCountCommand = class extends BaseCommand {
753
675
  stripDeprecatedRootItemFields(
754
676
  config.root_item
755
677
  );
756
- writeFileSync3(ROOT_CONFIG_PATH, JSON.stringify(config, null, 2), "utf-8");
678
+ writeFileSync2(ROOT_CONFIG_PATH, JSON.stringify(config, null, 2), "utf-8");
757
679
  const duration = Date.now() - startTime;
758
680
  const monthKeys = Object.keys(completedNotesCountHistory);
759
681
  const currentKey = monthKeys[monthKeys.length - 1];
@@ -872,7 +794,6 @@ var commandFactories = {
872
794
  "create-notes": () => new CreateNoteCommand(),
873
795
  "dev": () => new DevCommand(),
874
796
  "init-sub-repo": () => new InitSubRepoCommand(),
875
- "init-toc": () => new InitTocCommand(),
876
797
  "help": () => new HelpCommand(),
877
798
  "preview": () => new PreviewCommand(),
878
799
  "pull": () => new PullCommand(),
@@ -2,8 +2,7 @@
2
2
 
3
3
 
4
4
 
5
- var _chunkIHFUHB4Jcjs = require('../chunk-IHFUHB4J.cjs');
6
- require('../chunk-HXED7KVT.cjs');
5
+ var _chunk7FEANCT6cjs = require('../chunk-7FEANCT6.cjs');
7
6
 
8
7
  // markdown/components.ts
9
8
  var TNOTES_COMPONENTS = [
@@ -79,4 +78,4 @@ function findTNotesComponent(name) {
79
78
 
80
79
 
81
80
 
82
- exports.NOTE_TOC_END_TAG = _chunkIHFUHB4Jcjs.NOTE_TOC_END_TAG; exports.NOTE_TOC_START_TAG = _chunkIHFUHB4Jcjs.NOTE_TOC_START_TAG; exports.TNOTES_COMPONENTS = TNOTES_COMPONENTS; exports.findTNotesComponent = findTNotesComponent; exports.formatTNotesNote = _chunkIHFUHB4Jcjs.formatTNotesNote;
81
+ exports.NOTE_TOC_END_TAG = _chunk7FEANCT6cjs.NOTE_TOC_END_TAG; exports.NOTE_TOC_START_TAG = _chunk7FEANCT6cjs.NOTE_TOC_START_TAG; exports.TNOTES_COMPONENTS = TNOTES_COMPONENTS; exports.findTNotesComponent = findTNotesComponent; exports.formatTNotesNote = _chunk7FEANCT6cjs.formatTNotesNote;
@@ -1,4 +1,4 @@
1
- import { m as WorkspaceNoteConfig } from '../types-CpsEy8lA.cjs';
1
+ import { m as WorkspaceNoteConfig } from '../types-MRBGgJTX.cjs';
2
2
  import '../note-oGm44Rw8.cjs';
3
3
 
4
4
  declare const NOTE_TOC_START_TAG = "<!-- region:toc -->";
@@ -1,4 +1,4 @@
1
- import { m as WorkspaceNoteConfig } from '../types-CwBWwNVv.js';
1
+ import { m as WorkspaceNoteConfig } from '../types-C_d0fFeD.js';
2
2
  import '../note-oGm44Rw8.js';
3
3
 
4
4
  declare const NOTE_TOC_START_TAG = "<!-- region:toc -->";
@@ -2,8 +2,7 @@ import {
2
2
  NOTE_TOC_END_TAG,
3
3
  NOTE_TOC_START_TAG,
4
4
  formatTNotesNote
5
- } from "../chunk-UNFSW5C2.js";
6
- import "../chunk-CZXRQPFJ.js";
5
+ } from "../chunk-GWG75A5M.js";
7
6
 
8
7
  // markdown/components.ts
9
8
  var TNOTES_COMPONENTS = [
@@ -86,7 +86,7 @@ interface NoteDocument extends WorkspaceNoteSummary {
86
86
  }
87
87
  interface ChangedFile {
88
88
  path: string;
89
- kind: 'created' | 'updated' | 'deleted' | 'renamed';
89
+ kind: 'created' | 'updated' | 'deleted' | 'renamed' | 'trashed';
90
90
  previousPath?: string;
91
91
  }
92
92
  interface MutationResult<T> {
@@ -211,6 +211,13 @@ interface TNotesWorkspace {
211
211
  previewDelete(entry: TocEntryRef): Promise<DeleteTocEntryPreview>;
212
212
  deleteEntry(input: DeleteTocEntryInput): Promise<MutationResult<KnowledgeBaseSnapshot>>;
213
213
  setDone(input: UpdateNoteConfigInput): Promise<MutationResult<NoteDocument>>;
214
+ /**
215
+ * Align TOC.md + sidebar.json with the filesystem truth (files-first).
216
+ * Valid notes missing from the TOC are appended (root level, by index);
217
+ * note dirs with a missing/invalid config are soft-deleted to
218
+ * notes/.trash/. Idempotent: no changes -> changedFiles = [].
219
+ */
220
+ reconcileFromFiles(): Promise<MutationResult<KnowledgeBaseSnapshot>>;
214
221
  };
215
222
  attachments: {
216
223
  writeLocal(input: WriteAttachmentInput): Promise<MutationResult<AttachmentResult>>;
@@ -86,7 +86,7 @@ interface NoteDocument extends WorkspaceNoteSummary {
86
86
  }
87
87
  interface ChangedFile {
88
88
  path: string;
89
- kind: 'created' | 'updated' | 'deleted' | 'renamed';
89
+ kind: 'created' | 'updated' | 'deleted' | 'renamed' | 'trashed';
90
90
  previousPath?: string;
91
91
  }
92
92
  interface MutationResult<T> {
@@ -211,6 +211,13 @@ interface TNotesWorkspace {
211
211
  previewDelete(entry: TocEntryRef): Promise<DeleteTocEntryPreview>;
212
212
  deleteEntry(input: DeleteTocEntryInput): Promise<MutationResult<KnowledgeBaseSnapshot>>;
213
213
  setDone(input: UpdateNoteConfigInput): Promise<MutationResult<NoteDocument>>;
214
+ /**
215
+ * Align TOC.md + sidebar.json with the filesystem truth (files-first).
216
+ * Valid notes missing from the TOC are appended (root level, by index);
217
+ * note dirs with a missing/invalid config are soft-deleted to
218
+ * notes/.trash/. Idempotent: no changes -> changedFiles = [].
219
+ */
220
+ reconcileFromFiles(): Promise<MutationResult<KnowledgeBaseSnapshot>>;
214
221
  };
215
222
  attachments: {
216
223
  writeLocal(input: WriteAttachmentInput): Promise<MutationResult<AttachmentResult>>;