@aigne/doc-smith 0.9.8-alpha.3 → 0.9.8-alpha.4

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 (257) hide show
  1. package/CLAUDE.md +43 -0
  2. package/README.md +94 -250
  3. package/aigne.yaml +2 -149
  4. package/doc-smith/SKILL.md +117 -0
  5. package/doc-smith/references/changeset_schema.md +118 -0
  6. package/doc-smith/references/document_structure_schema.md +139 -0
  7. package/doc-smith/references/document_update_guide.md +193 -0
  8. package/doc-smith/references/structure_confirmation_guide.md +133 -0
  9. package/doc-smith/references/structure_planning_guide.md +146 -0
  10. package/doc-smith/references/user_intent_guide.md +172 -0
  11. package/doc-smith.yaml +114 -0
  12. package/main-system-prompt.md +56 -0
  13. package/package.json +3 -69
  14. package/scripts/README.md +90 -0
  15. package/scripts/install.sh +86 -0
  16. package/scripts/uninstall.sh +52 -0
  17. package/CHANGELOG.md +0 -994
  18. package/LICENSE +0 -93
  19. package/agentic-agents/common/base-info.md +0 -53
  20. package/agentic-agents/common/completer.md +0 -54
  21. package/agentic-agents/common/planner.md +0 -168
  22. package/agentic-agents/common/worker.md +0 -93
  23. package/agentic-agents/create/index.yaml +0 -129
  24. package/agentic-agents/create/objective.md +0 -44
  25. package/agentic-agents/create/set-custom-prompt.mjs +0 -27
  26. package/agentic-agents/detail/index.yaml +0 -95
  27. package/agentic-agents/detail/objective.md +0 -9
  28. package/agentic-agents/detail/set-custom-prompt.mjs +0 -88
  29. package/agentic-agents/predict-resources/index.yaml +0 -44
  30. package/agentic-agents/predict-resources/instructions.md +0 -61
  31. package/agentic-agents/structure/design-rules.md +0 -39
  32. package/agentic-agents/structure/index.yaml +0 -86
  33. package/agentic-agents/structure/objective.md +0 -14
  34. package/agentic-agents/structure/review-criteria.md +0 -55
  35. package/agentic-agents/structure/set-custom-prompt.mjs +0 -78
  36. package/agentic-agents/utils/init-workspace-cache.mjs +0 -171
  37. package/agentic-agents/utils/load-base-sources.mjs +0 -20
  38. package/agentic-agents/workspace-cache-sharing-design.md +0 -671
  39. package/agents/chat/chat-system.md +0 -38
  40. package/agents/chat/index.mjs +0 -59
  41. package/agents/chat/skills/generate-document.yaml +0 -15
  42. package/agents/chat/skills/list-documents.mjs +0 -15
  43. package/agents/chat/skills/update-document.yaml +0 -24
  44. package/agents/clear/choose-contents.mjs +0 -192
  45. package/agents/clear/clear-auth-tokens.mjs +0 -88
  46. package/agents/clear/clear-deployment-config.mjs +0 -49
  47. package/agents/clear/clear-document-config.mjs +0 -36
  48. package/agents/clear/clear-document-structure.mjs +0 -102
  49. package/agents/clear/clear-generated-docs.mjs +0 -142
  50. package/agents/clear/clear-media-description.mjs +0 -129
  51. package/agents/clear/index.yaml +0 -26
  52. package/agents/create/analyze-diagram-type-llm.yaml +0 -160
  53. package/agents/create/analyze-diagram-type.mjs +0 -297
  54. package/agents/create/check-document-structure.yaml +0 -30
  55. package/agents/create/check-need-generate-structure.mjs +0 -105
  56. package/agents/create/document-structure-tools/add-document.mjs +0 -85
  57. package/agents/create/document-structure-tools/delete-document.mjs +0 -116
  58. package/agents/create/document-structure-tools/move-document.mjs +0 -109
  59. package/agents/create/document-structure-tools/update-document.mjs +0 -84
  60. package/agents/create/generate-diagram-image.yaml +0 -60
  61. package/agents/create/generate-structure.yaml +0 -117
  62. package/agents/create/index.yaml +0 -49
  63. package/agents/create/refine-document-structure.yaml +0 -12
  64. package/agents/create/replace-d2-with-image.mjs +0 -625
  65. package/agents/create/update-document-structure.yaml +0 -54
  66. package/agents/create/user-add-document/add-documents-to-structure.mjs +0 -90
  67. package/agents/create/user-add-document/find-documents-to-add-links.yaml +0 -47
  68. package/agents/create/user-add-document/index.yaml +0 -46
  69. package/agents/create/user-add-document/prepare-documents-to-translate.mjs +0 -22
  70. package/agents/create/user-add-document/print-add-document-summary.mjs +0 -63
  71. package/agents/create/user-add-document/review-documents-with-new-links.mjs +0 -110
  72. package/agents/create/user-remove-document/find-documents-with-invalid-links.mjs +0 -78
  73. package/agents/create/user-remove-document/index.yaml +0 -40
  74. package/agents/create/user-remove-document/prepare-documents-to-translate.mjs +0 -22
  75. package/agents/create/user-remove-document/print-remove-document-summary.mjs +0 -53
  76. package/agents/create/user-remove-document/remove-documents-from-structure.mjs +0 -99
  77. package/agents/create/user-remove-document/review-documents-with-invalid-links.mjs +0 -115
  78. package/agents/create/user-review-document-structure.mjs +0 -140
  79. package/agents/create/utils/init-current-content.mjs +0 -34
  80. package/agents/create/utils/merge-document-structures.mjs +0 -30
  81. package/agents/evaluate/code-snippet.mjs +0 -97
  82. package/agents/evaluate/document-structure.yaml +0 -67
  83. package/agents/evaluate/document.yaml +0 -82
  84. package/agents/evaluate/generate-report.mjs +0 -85
  85. package/agents/evaluate/index.yaml +0 -46
  86. package/agents/history/index.yaml +0 -6
  87. package/agents/history/view.mjs +0 -78
  88. package/agents/init/check.mjs +0 -16
  89. package/agents/init/index.mjs +0 -275
  90. package/agents/init/validate.mjs +0 -16
  91. package/agents/localize/choose-language.mjs +0 -107
  92. package/agents/localize/index.yaml +0 -58
  93. package/agents/localize/record-translation-history.mjs +0 -23
  94. package/agents/localize/translate-document.yaml +0 -24
  95. package/agents/localize/translate-multilingual.yaml +0 -51
  96. package/agents/media/batch-generate-media-description.yaml +0 -46
  97. package/agents/media/generate-media-description.yaml +0 -50
  98. package/agents/media/load-media-description.mjs +0 -256
  99. package/agents/prefs/index.mjs +0 -203
  100. package/agents/publish/index.yaml +0 -26
  101. package/agents/publish/publish-docs.mjs +0 -356
  102. package/agents/publish/translate-meta.mjs +0 -103
  103. package/agents/schema/document-structure-item.yaml +0 -26
  104. package/agents/schema/document-structure-refine-item.yaml +0 -23
  105. package/agents/schema/document-structure.yaml +0 -29
  106. package/agents/update/batch-generate-document.yaml +0 -27
  107. package/agents/update/batch-update-document.yaml +0 -7
  108. package/agents/update/check-diagram-flag.mjs +0 -116
  109. package/agents/update/check-document.mjs +0 -162
  110. package/agents/update/check-generate-diagram.mjs +0 -106
  111. package/agents/update/check-sync-image-flag.mjs +0 -55
  112. package/agents/update/check-update-is-single.mjs +0 -53
  113. package/agents/update/document-tools/update-document-content.mjs +0 -303
  114. package/agents/update/generate-diagram.yaml +0 -63
  115. package/agents/update/generate-document.yaml +0 -70
  116. package/agents/update/handle-document-update.yaml +0 -103
  117. package/agents/update/index.yaml +0 -79
  118. package/agents/update/pre-check-generate-diagram.yaml +0 -44
  119. package/agents/update/save-and-translate-document.mjs +0 -76
  120. package/agents/update/sync-images-and-exit.mjs +0 -148
  121. package/agents/update/update-document-detail.yaml +0 -71
  122. package/agents/update/update-single/update-single-document-detail.mjs +0 -280
  123. package/agents/update/update-single-document.yaml +0 -7
  124. package/agents/update/user-review-document.mjs +0 -272
  125. package/agents/utils/action-success.mjs +0 -16
  126. package/agents/utils/analyze-document-feedback-intent.yaml +0 -32
  127. package/agents/utils/analyze-feedback-intent.mjs +0 -136
  128. package/agents/utils/analyze-structure-feedback-intent.yaml +0 -29
  129. package/agents/utils/check-detail-result.mjs +0 -38
  130. package/agents/utils/check-feedback-refiner.mjs +0 -81
  131. package/agents/utils/choose-docs.mjs +0 -293
  132. package/agents/utils/document-icon-generate.yaml +0 -52
  133. package/agents/utils/document-title-streamline.yaml +0 -48
  134. package/agents/utils/ensure-document-icons.mjs +0 -129
  135. package/agents/utils/exit.mjs +0 -6
  136. package/agents/utils/feedback-refiner.yaml +0 -50
  137. package/agents/utils/find-item-by-path.mjs +0 -114
  138. package/agents/utils/find-user-preferences-by-path.mjs +0 -37
  139. package/agents/utils/format-document-structure.mjs +0 -35
  140. package/agents/utils/generate-document-or-skip.mjs +0 -41
  141. package/agents/utils/handle-diagram-operations.mjs +0 -263
  142. package/agents/utils/load-all-document-content.mjs +0 -30
  143. package/agents/utils/load-document-all-content.mjs +0 -84
  144. package/agents/utils/load-sources.mjs +0 -405
  145. package/agents/utils/map-reasoning-effort-level.mjs +0 -15
  146. package/agents/utils/post-generate.mjs +0 -144
  147. package/agents/utils/read-current-document-content.mjs +0 -46
  148. package/agents/utils/save-doc-translation.mjs +0 -61
  149. package/agents/utils/save-doc.mjs +0 -88
  150. package/agents/utils/save-output.mjs +0 -26
  151. package/agents/utils/save-sidebar.mjs +0 -51
  152. package/agents/utils/skip-if-content-exists.mjs +0 -27
  153. package/agents/utils/streamline-document-titles-if-needed.mjs +0 -88
  154. package/agents/utils/transform-detail-data-sources.mjs +0 -45
  155. package/agents/utils/update-branding.mjs +0 -84
  156. package/assets/report-template/report.html +0 -198
  157. package/docs-mcp/analyze-content-relevance.yaml +0 -50
  158. package/docs-mcp/analyze-docs-relevance.yaml +0 -59
  159. package/docs-mcp/docs-search.yaml +0 -42
  160. package/docs-mcp/get-docs-detail.mjs +0 -41
  161. package/docs-mcp/get-docs-structure.mjs +0 -16
  162. package/docs-mcp/read-doc-content.mjs +0 -119
  163. package/prompts/common/document/content-rules-core.md +0 -20
  164. package/prompts/common/document/markdown-syntax-rules.md +0 -65
  165. package/prompts/common/document/media-file-list-usage-rules.md +0 -18
  166. package/prompts/common/document/openapi-usage-rules.md +0 -189
  167. package/prompts/common/document/role-and-personality.md +0 -16
  168. package/prompts/common/document/user-preferences.md +0 -9
  169. package/prompts/common/document-structure/conflict-resolution-guidance.md +0 -16
  170. package/prompts/common/document-structure/document-icon-generate.md +0 -116
  171. package/prompts/common/document-structure/document-structure-rules.md +0 -43
  172. package/prompts/common/document-structure/document-title-streamline.md +0 -86
  173. package/prompts/common/document-structure/glossary.md +0 -7
  174. package/prompts/common/document-structure/intj-traits.md +0 -5
  175. package/prompts/common/document-structure/openapi-usage-rules.md +0 -28
  176. package/prompts/common/document-structure/output-constraints.md +0 -18
  177. package/prompts/common/document-structure/user-locale-rules.md +0 -10
  178. package/prompts/common/document-structure/user-preferences.md +0 -9
  179. package/prompts/detail/custom/admonition-usage-rules.md +0 -94
  180. package/prompts/detail/custom/code-block-usage-rules.md +0 -163
  181. package/prompts/detail/custom/custom-components/x-card-usage-rules.md +0 -63
  182. package/prompts/detail/custom/custom-components/x-cards-usage-rules.md +0 -83
  183. package/prompts/detail/custom/custom-components/x-field-desc-usage-rules.md +0 -120
  184. package/prompts/detail/custom/custom-components/x-field-group-usage-rules.md +0 -80
  185. package/prompts/detail/custom/custom-components/x-field-usage-rules.md +0 -189
  186. package/prompts/detail/custom/custom-components-usage-rules.md +0 -18
  187. package/prompts/detail/diagram/generate-image-system.md +0 -135
  188. package/prompts/detail/diagram/generate-image-user.md +0 -32
  189. package/prompts/detail/diagram/guide.md +0 -29
  190. package/prompts/detail/diagram/official-examples.md +0 -712
  191. package/prompts/detail/diagram/pre-check.md +0 -23
  192. package/prompts/detail/diagram/role-and-personality.md +0 -2
  193. package/prompts/detail/diagram/rules.md +0 -46
  194. package/prompts/detail/diagram/system-prompt.md +0 -1139
  195. package/prompts/detail/diagram/user-prompt.md +0 -43
  196. package/prompts/detail/generate/detail-example.md +0 -457
  197. package/prompts/detail/generate/document-rules.md +0 -45
  198. package/prompts/detail/generate/system-prompt.md +0 -61
  199. package/prompts/detail/generate/user-prompt.md +0 -99
  200. package/prompts/detail/jsx/rules.md +0 -6
  201. package/prompts/detail/update/system-prompt.md +0 -121
  202. package/prompts/detail/update/user-prompt.md +0 -41
  203. package/prompts/evaluate/document-structure.md +0 -93
  204. package/prompts/evaluate/document.md +0 -149
  205. package/prompts/media/media-description/system-prompt.md +0 -43
  206. package/prompts/media/media-description/user-prompt.md +0 -17
  207. package/prompts/structure/check-document-structure.md +0 -93
  208. package/prompts/structure/document-rules.md +0 -21
  209. package/prompts/structure/find-documents-to-add-links.md +0 -52
  210. package/prompts/structure/generate/system-prompt.md +0 -13
  211. package/prompts/structure/generate/user-prompt.md +0 -137
  212. package/prompts/structure/review/structure-review-system.md +0 -81
  213. package/prompts/structure/structure-example.md +0 -89
  214. package/prompts/structure/structure-getting-started.md +0 -10
  215. package/prompts/structure/update/system-prompt.md +0 -93
  216. package/prompts/structure/update/user-prompt.md +0 -43
  217. package/prompts/translate/admonition.md +0 -20
  218. package/prompts/translate/code-block.md +0 -33
  219. package/prompts/translate/glossary.md +0 -6
  220. package/prompts/translate/translate-document.md +0 -305
  221. package/prompts/utils/analyze-document-feedback-intent.md +0 -54
  222. package/prompts/utils/analyze-structure-feedback-intent.md +0 -43
  223. package/prompts/utils/feedback-refiner.md +0 -105
  224. package/types/document-schema.mjs +0 -55
  225. package/types/document-structure-schema.mjs +0 -261
  226. package/utils/auth-utils.mjs +0 -275
  227. package/utils/blocklet.mjs +0 -104
  228. package/utils/check-document-has-diagram.mjs +0 -95
  229. package/utils/conflict-detector.mjs +0 -149
  230. package/utils/constants/index.mjs +0 -620
  231. package/utils/constants/linter.mjs +0 -102
  232. package/utils/d2-utils.mjs +0 -198
  233. package/utils/debug.mjs +0 -3
  234. package/utils/delete-diagram-images.mjs +0 -99
  235. package/utils/deploy.mjs +0 -86
  236. package/utils/docs-finder-utils.mjs +0 -623
  237. package/utils/evaluate/report-utils.mjs +0 -132
  238. package/utils/extract-api.mjs +0 -32
  239. package/utils/file-utils.mjs +0 -960
  240. package/utils/history-utils.mjs +0 -203
  241. package/utils/icon-map.mjs +0 -26
  242. package/utils/image-compress.mjs +0 -75
  243. package/utils/kroki-utils.mjs +0 -173
  244. package/utils/linter/index.mjs +0 -50
  245. package/utils/load-config.mjs +0 -107
  246. package/utils/markdown/index.mjs +0 -26
  247. package/utils/markdown-checker.mjs +0 -694
  248. package/utils/mermaid-validator.mjs +0 -140
  249. package/utils/mermaid-worker-pool.mjs +0 -250
  250. package/utils/mermaid-worker.mjs +0 -233
  251. package/utils/openapi/index.mjs +0 -28
  252. package/utils/preferences-utils.mjs +0 -175
  253. package/utils/request.mjs +0 -10
  254. package/utils/store/index.mjs +0 -45
  255. package/utils/sync-diagram-to-translations.mjs +0 -262
  256. package/utils/upload-files.mjs +0 -231
  257. package/utils/utils.mjs +0 -1354
@@ -1,102 +0,0 @@
1
- export const LINTER_API_URL = process.env.LINTER_API_URL || "https://linter.abtnet.io";
2
-
3
- export const LINTER_SUPPORTED_FILE = {
4
- biome: [".js", ".jsx", ".ts", ".tsx", ".json"],
5
- eslint: [".js", ".jsx", ".ts", ".tsx", ".vue"],
6
- oxlint: [".js", ".jsx", ".ts", ".tsx"],
7
- prettier: [".js", ".jsx", ".ts", ".tsx", ".json", ".css"],
8
- pylint: [".py"],
9
- flake8: [".py"],
10
- black: [".py"],
11
- isort: [".py"],
12
- mypy: [".py"],
13
- shellcheck: [".sh", ".bash", ".dash", ".ksh"],
14
- "golangci-lint": [".go"],
15
- rubocop: [".rb", ".rake", ".gemfile", "Gemfile"],
16
- hadolint: ["Dockerfile", ".dockerfile"],
17
- yamllint: [".yml", ".yaml"],
18
- stylelint: [".css", ".scss", ".sass"],
19
- };
20
- export const SUFFIX_TO_CODE_LANGUAGE = {
21
- ".js": ["js", "javascript", "node"],
22
- ".jsx": ["jsx"],
23
- ".ts": ["ts", "typescript"],
24
- ".tsx": ["tsx"],
25
- ".json": ["json"],
26
- ".vue": ["vue"],
27
- ".css": ["css"],
28
- ".py": ["python", "python3"],
29
- ".sh": ["shell", "sh", "shell-script", "bash", "zsh"],
30
- ".go": ["go", "golang"],
31
- ".rb": ["ruby", "jruby", "macruby", "rake", "rb", "rbx"],
32
- ".dockerfile": ["dockerfile"],
33
- ".yml": ["yaml", "yml"],
34
- ".sass": ["sass"],
35
- ".scss": ["scss"],
36
- };
37
-
38
- export const CODE_LANGUAGE_MAP_LINTER = {
39
- js: "biome-lint",
40
- javascript: "biome-lint",
41
- node: "biome-lint",
42
- jsx: "biome-lint",
43
- ts: "biome-lint",
44
- typescript: "biome-lint",
45
- tsx: "biome-lint",
46
- json: "biome-lint",
47
- vue: "eslint",
48
- css: "prettier",
49
- python: "flake8",
50
- python3: "flake8",
51
- shell: "shellcheck",
52
- sh: "shellcheck",
53
- "shell-script": "shellcheck",
54
- bash: "shellcheck",
55
- zsh: "shellcheck",
56
- go: "golangci-lint",
57
- golang: "golangci-lint",
58
- ruby: "rubocop",
59
- jruby: "rubocop",
60
- macruby: "rubocop",
61
- rake: "rubocop",
62
- rb: "rubocop",
63
- rbx: "rubocop",
64
- dockerfile: "hadolint",
65
- yaml: "yamllint",
66
- yml: "yamllint",
67
- sass: "stylelint",
68
- scss: "stylelint",
69
- };
70
-
71
- export const CODE_LANGUAGE_MAP_SUFFIX = {
72
- js: ".js",
73
- javascript: ".js",
74
- node: ".js",
75
- jsx: ".jsx",
76
- ts: ".ts",
77
- typescript: ".ts",
78
- tsx: ".tsx",
79
- json: ".json",
80
- vue: ".vue",
81
- css: ".css",
82
- python: ".py",
83
- python3: ".py",
84
- shell: ".sh",
85
- sh: ".sh",
86
- "shell-script": ".sh",
87
- bash: ".sh",
88
- zsh: ".sh",
89
- go: ".go",
90
- golang: ".go",
91
- ruby: ".rb",
92
- jruby: ".rb",
93
- macruby: ".rb",
94
- rake: ".rb",
95
- rb: ".rb",
96
- rbx: ".rb",
97
- dockerfile: ".dockerfile",
98
- yaml: ".yml",
99
- yml: ".yml",
100
- sass: ".sass",
101
- scss: ".scss",
102
- };
@@ -1,198 +0,0 @@
1
- import path from "node:path";
2
-
3
- import fs from "fs-extra";
4
-
5
- import { DOC_SMITH_DIR, TMP_DIR } from "./constants/index.mjs";
6
-
7
- // Note: .* matches title or other text after ```d2 (e.g., ```d2 Vault 驗證流程)
8
- // Export regex for reuse across the codebase to avoid duplication
9
- export const d2CodeBlockRegex = /```d2.*\n([\s\S]*?)```/g;
10
-
11
- export const DIAGRAM_PLACEHOLDER = "DIAGRAM_PLACEHOLDER";
12
-
13
- // Diagram image regex patterns for reuse across the codebase
14
- // Pattern 1: Match only the start marker (for checking existence)
15
- export const diagramImageStartRegex = /<!--\s*DIAGRAM_IMAGE_START:[^>]+-->/g;
16
-
17
- // Pattern 2: Match full diagram image block without capturing image path (for finding/replacing)
18
- export const diagramImageBlockRegex =
19
- /<!--\s*DIAGRAM_IMAGE_START:[^>]+-->\s*[\s\S]*?<!--\s*DIAGRAM_IMAGE_END\s*-->/g;
20
-
21
- // Pattern 3: Match full diagram image block with image path capture (for extracting paths)
22
- export const diagramImageWithPathRegex =
23
- /<!--\s*DIAGRAM_IMAGE_START:[^>]+-->\s*!\[[^\]]*\]\(([^)]+)\)\s*<!--\s*DIAGRAM_IMAGE_END\s*-->/g;
24
-
25
- export async function ensureTmpDir() {
26
- const tmpDir = path.join(DOC_SMITH_DIR, TMP_DIR);
27
- if (!(await fs.pathExists(path.join(tmpDir, ".gitignore")))) {
28
- await fs.ensureDir(tmpDir);
29
- await fs.writeFile(path.join(tmpDir, ".gitignore"), "**/*", { encoding: "utf8" });
30
- }
31
- }
32
-
33
- export function isValidCode(lang) {
34
- return lang?.toLowerCase() === "d2";
35
- }
36
-
37
- export function wrapCode({ content }) {
38
- const matches = Array.from(content.matchAll(d2CodeBlockRegex));
39
- if (matches.length > 0) {
40
- return content;
41
- }
42
-
43
- return `\`\`\`d2\n${content}\n\`\`\``;
44
- }
45
-
46
- /**
47
- * Replaces D2 code block with DIAGRAM_PLACEHOLDER.
48
- * @param {string} content - Document content containing D2 code block
49
- * @returns {Array} - [contentWithPlaceholder, originalCodeBlock]
50
- */
51
- export function replaceD2WithPlaceholder({ content }) {
52
- const [firstMatch] = Array.from(content.matchAll(d2CodeBlockRegex));
53
- if (firstMatch) {
54
- const matchContent = firstMatch[0];
55
- const cleanContent = content.replace(matchContent, DIAGRAM_PLACEHOLDER);
56
- return [cleanContent, matchContent];
57
- }
58
-
59
- return [content, ""];
60
- }
61
-
62
- /**
63
- * Replaces DIAGRAM_PLACEHOLDER with D2 code block, ensuring proper spacing.
64
- * @param {string} content - Document content containing DIAGRAM_PLACEHOLDER
65
- * @param {string} diagramSourceCode - D2 diagram source code (without markdown wrapper)
66
- * @returns {string} - Content with placeholder replaced by code block
67
- */
68
- export function replacePlaceholderWithD2({ content, diagramSourceCode }) {
69
- if (!content || !diagramSourceCode) {
70
- return content;
71
- }
72
-
73
- const placeholderIndex = content.indexOf(DIAGRAM_PLACEHOLDER);
74
- if (placeholderIndex === -1) {
75
- return content;
76
- }
77
-
78
- // Check if placeholder has newlines around it
79
- const beforePlaceholder = content.substring(0, placeholderIndex);
80
- const afterPlaceholder = content.substring(placeholderIndex + DIAGRAM_PLACEHOLDER.length);
81
-
82
- const codeBlock = wrapCode({ content: diagramSourceCode });
83
-
84
- // Add newlines if missing
85
- let replacement = codeBlock;
86
- if (beforePlaceholder && !beforePlaceholder.endsWith("\n")) {
87
- replacement = `\n${replacement}`;
88
- }
89
- if (afterPlaceholder && !afterPlaceholder.startsWith("\n")) {
90
- replacement = `${replacement}\n`;
91
- }
92
-
93
- return content.replace(DIAGRAM_PLACEHOLDER, replacement);
94
- }
95
-
96
- /**
97
- * Replace all diagrams (D2 code blocks and generated images) with DIAGRAM_PLACEHOLDER
98
- * Used for deletion operations to normalize all diagram types to a single placeholder
99
- * @param {string} content - Document content containing diagrams
100
- * @param {number} [diagramIndex] - Optional index of diagram to replace (0-based). If not provided, replaces all diagrams.
101
- * @returns {string} - Content with diagrams replaced by DIAGRAM_PLACEHOLDER
102
- */
103
- export function replaceDiagramsWithPlaceholder({ content, diagramIndex }) {
104
- if (!content) {
105
- return content;
106
- }
107
-
108
- // Use exported regex to find all diagram locations
109
- // We'll use a similar approach to findAllDiagramLocations
110
- const mermaidCodeBlockRegex = /```mermaid.*\n([\s\S]*?)```/g;
111
-
112
- // Find all diagram locations
113
- const locations = [];
114
-
115
- // 1. Find DIAGRAM_PLACEHOLDER (already a placeholder, keep as is)
116
- let placeholderIndex = content.indexOf(DIAGRAM_PLACEHOLDER);
117
- while (placeholderIndex !== -1) {
118
- locations.push({
119
- type: "placeholder",
120
- start: placeholderIndex,
121
- end: placeholderIndex + DIAGRAM_PLACEHOLDER.length,
122
- });
123
- placeholderIndex = content.indexOf(DIAGRAM_PLACEHOLDER, placeholderIndex + 1);
124
- }
125
-
126
- // 2. Find DIAGRAM_IMAGE_START markers (generated images)
127
- const imageMatches = Array.from(content.matchAll(diagramImageBlockRegex));
128
- for (const match of imageMatches) {
129
- locations.push({
130
- type: "image",
131
- start: match.index,
132
- end: match.index + match[0].length,
133
- });
134
- }
135
-
136
- // 3. Find D2 code blocks
137
- const d2Matches = Array.from(content.matchAll(d2CodeBlockRegex));
138
- for (const match of d2Matches) {
139
- locations.push({
140
- type: "d2",
141
- start: match.index,
142
- end: match.index + match[0].length,
143
- });
144
- }
145
-
146
- // 4. Find Mermaid code blocks
147
- const mermaidMatches = Array.from(content.matchAll(mermaidCodeBlockRegex));
148
- for (const match of mermaidMatches) {
149
- locations.push({
150
- type: "mermaid",
151
- start: match.index,
152
- end: match.index + match[0].length,
153
- });
154
- }
155
-
156
- // Sort by position (top to bottom)
157
- locations.sort((a, b) => a.start - b.start);
158
-
159
- if (locations.length === 0) {
160
- return content;
161
- }
162
-
163
- // If diagramIndex is provided, only replace that specific diagram
164
- if (diagramIndex !== undefined && diagramIndex >= 0 && diagramIndex < locations.length) {
165
- const targetLocation = locations[diagramIndex];
166
- const before = content.substring(0, targetLocation.start);
167
- const after = content.substring(targetLocation.end);
168
- // Add newlines if needed
169
- let replacement = DIAGRAM_PLACEHOLDER;
170
- if (before && !before.endsWith("\n")) {
171
- replacement = `\n${replacement}`;
172
- }
173
- if (after && !after.startsWith("\n")) {
174
- replacement = `${replacement}\n`;
175
- }
176
- return before + replacement + after;
177
- }
178
-
179
- // Replace all diagrams with placeholder (for deletion)
180
- // Process from end to start to preserve indices
181
- let result = content;
182
- for (let i = locations.length - 1; i >= 0; i--) {
183
- const location = locations[i];
184
- const before = result.substring(0, location.start);
185
- const after = result.substring(location.end);
186
- // Add newlines if needed
187
- let replacement = DIAGRAM_PLACEHOLDER;
188
- if (before && !before.endsWith("\n")) {
189
- replacement = `\n${replacement}`;
190
- }
191
- if (after && !after.startsWith("\n")) {
192
- replacement = `${replacement}\n`;
193
- }
194
- result = before + replacement + after;
195
- }
196
-
197
- return result;
198
- }
package/utils/debug.mjs DELETED
@@ -1,3 +0,0 @@
1
- import Debug from "debug";
2
-
3
- export const debug = Debug("doc-smith");
@@ -1,99 +0,0 @@
1
- import { unlink } from "node:fs/promises";
2
- import { join, dirname, normalize } from "node:path";
3
- import fs from "fs-extra";
4
- import { debug } from "./debug.mjs";
5
-
6
- /**
7
- * Extract image file paths from markdown content
8
- * Finds all diagram image references and extracts their file paths
9
- * @param {string} content - Markdown content
10
- * @param {string} path - Document path (e.g., "guides/getting-started.md")
11
- * @param {string} docsDir - Documentation directory
12
- * @returns {Promise<Array<string>>} Array of absolute paths to image files
13
- */
14
- export async function extractDiagramImagePaths(content, path, docsDir) {
15
- if (!content || !path || !docsDir) {
16
- return [];
17
- }
18
-
19
- const imagePaths = [];
20
-
21
- // Pattern to match: <!-- DIAGRAM_IMAGE_START:... -->![alt](path)<!-- DIAGRAM_IMAGE_END -->
22
- const { diagramImageWithPathRegex } = await import("./d2-utils.mjs");
23
- const matches = Array.from(content.matchAll(diagramImageWithPathRegex));
24
-
25
- for (const match of matches) {
26
- const imagePath = match[1];
27
-
28
- // Resolve absolute path
29
- // If imagePath is relative, resolve from document location
30
- // If imagePath is absolute or starts with http, skip
31
- if (imagePath.startsWith("http://") || imagePath.startsWith("https://")) {
32
- continue; // Skip remote URLs
33
- }
34
-
35
- // Calculate relative path from document to image
36
- const docDir = dirname(path);
37
- const imageRelativePath = imagePath.startsWith("../")
38
- ? imagePath
39
- : join(docDir, imagePath).replace(/\\/g, "/");
40
-
41
- // Resolve absolute path
42
- const absolutePath = join(process.cwd(), docsDir, imageRelativePath);
43
-
44
- // Normalize path (remove .. and .)
45
- const normalizedPath = normalize(absolutePath);
46
-
47
- if (await fs.pathExists(normalizedPath)) {
48
- imagePaths.push(normalizedPath);
49
- }
50
- }
51
-
52
- return imagePaths;
53
- }
54
-
55
- /**
56
- * Delete diagram image files associated with a document
57
- * @param {string} content - Markdown content (before deletion)
58
- * @param {string} path - Document path
59
- * @param {string} docsDir - Documentation directory
60
- * @returns {Promise<{deleted: number, failed: number}>}
61
- */
62
- export async function deleteDiagramImages(content, path, docsDir) {
63
- if (!content || !path || !docsDir) {
64
- return { deleted: 0, failed: 0 };
65
- }
66
-
67
- try {
68
- const imagePaths = await extractDiagramImagePaths(content, path, docsDir);
69
-
70
- if (imagePaths.length === 0) {
71
- return { deleted: 0, failed: 0 };
72
- }
73
-
74
- let deleted = 0;
75
- let failed = 0;
76
-
77
- for (const imagePath of imagePaths) {
78
- try {
79
- await unlink(imagePath);
80
- debug(`Deleted diagram image: ${imagePath}`);
81
- deleted++;
82
- } catch (error) {
83
- if (error.code !== "ENOENT") {
84
- // File not found is ok, other errors should be logged
85
- console.warn(`Failed to delete diagram image ${imagePath}: ${error.message}`);
86
- failed++;
87
- } else {
88
- // File already doesn't exist, count as deleted
89
- deleted++;
90
- }
91
- }
92
- }
93
-
94
- return { deleted, failed };
95
- } catch (error) {
96
- console.warn(`Error deleting diagram images: ${error.message}`);
97
- return { deleted: 0, failed: 0 };
98
- }
99
- }
package/utils/deploy.mjs DELETED
@@ -1,86 +0,0 @@
1
- import { BrokerClient, STEPS } from "@blocklet/payment-broker-client/node";
2
- import chalk from "chalk";
3
- import open from "open";
4
- import { getOfficialAccessToken } from "./auth-utils.mjs";
5
- import { CLOUD_SERVICE_URL_PROD } from "./constants/index.mjs";
6
- import { saveValueToConfig } from "./utils.mjs";
7
-
8
- const BASE_URL = process.env.DOC_SMITH_BASE_URL || CLOUD_SERVICE_URL_PROD;
9
- const SUCCESS_MESSAGE = {
10
- en: "Congratulations! Your website has been successfully installed. You can now return to the command-line tool to continue.",
11
- zh: "恭喜您,你的网站已安装成功!可以返回命令行工具继续后续操作!",
12
- };
13
-
14
- /**
15
- * Deploys a new Discuss Kit Website and returns the installation URL.
16
- * @param {string} id - The cached checkout ID (optional).
17
- * @param {string} locale - preferred locale
18
- * @returns {Promise<Object>} The deployment result with URLs.
19
- */
20
- export async function deploy(id, locale) {
21
- const authToken = await getOfficialAccessToken(BASE_URL, true, locale);
22
-
23
- if (!authToken) {
24
- throw new Error("Could not get an official access token.");
25
- }
26
-
27
- const client = new BrokerClient({ baseUrl: BASE_URL, authToken });
28
-
29
- console.log(`🚀 Starting deployment...`);
30
-
31
- const result = await client.deploy({
32
- cachedCheckoutId: id,
33
- needShortUrl: true,
34
- pageInfo: { successMessage: SUCCESS_MESSAGE },
35
- hooks: {
36
- [STEPS.PAYMENT_PENDING]: async ({ sessionId, paymentUrl, isResuming }) => {
37
- console.log(`⏳ Step 1/4: Waiting for payment...`);
38
- console.log(`🔗 Payment link: ${chalk.cyan(paymentUrl)}\n`);
39
-
40
- await saveValueToConfig(
41
- "checkoutId",
42
- sessionId,
43
- "Checkout ID for document deployment website",
44
- );
45
-
46
- if (!isResuming) {
47
- await open(paymentUrl);
48
- }
49
- },
50
-
51
- [STEPS.INSTALLATION_STARTING]: () => {
52
- console.log(`📦 Step 2/4: Installing the website...`);
53
- },
54
-
55
- [STEPS.SERVICE_STARTING]: () => {
56
- console.log(`🚀 Step 3/4: Starting the website...`);
57
- },
58
-
59
- [STEPS.ACCESS_PREPARING]: () => {
60
- console.log(`🌐 Step 4/4: Getting the website URL...`);
61
- },
62
-
63
- [STEPS.ACCESS_READY]: async ({ appUrl, homeUrl, subscriptionUrl }) => {
64
- console.log(`\n🔗 Your website is available at: ${chalk.cyan(homeUrl || appUrl)}`);
65
- if (subscriptionUrl) {
66
- console.log(`🔗 Your subscription management URL: ${chalk.cyan(subscriptionUrl)}\n`);
67
- } else {
68
- console.log("");
69
- }
70
- },
71
- },
72
- });
73
-
74
- const { appUrl, homeUrl, subscriptionUrl, dashboardUrl, vendors, sessionId, data } = result;
75
- const token = vendors?.[0]?.token;
76
-
77
- return {
78
- appUrl,
79
- homeUrl,
80
- dashboardUrl,
81
- subscriptionUrl,
82
- token,
83
- sessionId,
84
- data,
85
- };
86
- }