@cyberismo/data-handler 0.0.2

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 (306) hide show
  1. package/LICENSE +702 -0
  2. package/dist/card-metadata-updater.d.ts +33 -0
  3. package/dist/card-metadata-updater.js +121 -0
  4. package/dist/card-metadata-updater.js.map +1 -0
  5. package/dist/command-handler.d.ts +96 -0
  6. package/dist/command-handler.js +557 -0
  7. package/dist/command-handler.js.map +1 -0
  8. package/dist/command-manager.d.ts +43 -0
  9. package/dist/command-manager.js +73 -0
  10. package/dist/command-manager.js.map +1 -0
  11. package/dist/commands/calculate.d.ts +86 -0
  12. package/dist/commands/calculate.js +444 -0
  13. package/dist/commands/calculate.js.map +1 -0
  14. package/dist/commands/create.d.ts +114 -0
  15. package/dist/commands/create.js +389 -0
  16. package/dist/commands/create.js.map +1 -0
  17. package/dist/commands/edit.d.ts +37 -0
  18. package/dist/commands/edit.js +99 -0
  19. package/dist/commands/edit.js.map +1 -0
  20. package/dist/commands/export-site.d.ts +45 -0
  21. package/dist/commands/export-site.js +301 -0
  22. package/dist/commands/export-site.js.map +1 -0
  23. package/dist/commands/export.d.ts +53 -0
  24. package/dist/commands/export.js +251 -0
  25. package/dist/commands/export.js.map +1 -0
  26. package/dist/commands/import.d.ts +53 -0
  27. package/dist/commands/import.js +133 -0
  28. package/dist/commands/import.js.map +1 -0
  29. package/dist/commands/index.d.ts +26 -0
  30. package/dist/commands/index.js +27 -0
  31. package/dist/commands/index.js.map +1 -0
  32. package/dist/commands/move.d.ts +55 -0
  33. package/dist/commands/move.js +341 -0
  34. package/dist/commands/move.js.map +1 -0
  35. package/dist/commands/remove.d.ts +38 -0
  36. package/dist/commands/remove.js +192 -0
  37. package/dist/commands/remove.js.map +1 -0
  38. package/dist/commands/rename.d.ts +46 -0
  39. package/dist/commands/rename.js +289 -0
  40. package/dist/commands/rename.js.map +1 -0
  41. package/dist/commands/show.d.ts +124 -0
  42. package/dist/commands/show.js +345 -0
  43. package/dist/commands/show.js.map +1 -0
  44. package/dist/commands/transition.d.ts +27 -0
  45. package/dist/commands/transition.js +92 -0
  46. package/dist/commands/transition.js.map +1 -0
  47. package/dist/commands/update.d.ts +29 -0
  48. package/dist/commands/update.js +64 -0
  49. package/dist/commands/update.js.map +1 -0
  50. package/dist/commands/validate.d.ts +143 -0
  51. package/dist/commands/validate.js +689 -0
  52. package/dist/commands/validate.js.map +1 -0
  53. package/dist/containers/card-container.d.ts +44 -0
  54. package/dist/containers/card-container.js +282 -0
  55. package/dist/containers/card-container.js.map +1 -0
  56. package/dist/containers/project/project-paths.d.ts +46 -0
  57. package/dist/containers/project/project-paths.js +105 -0
  58. package/dist/containers/project/project-paths.js.map +1 -0
  59. package/dist/containers/project/resource-collector.d.ts +86 -0
  60. package/dist/containers/project/resource-collector.js +331 -0
  61. package/dist/containers/project/resource-collector.js.map +1 -0
  62. package/dist/containers/project.d.ts +351 -0
  63. package/dist/containers/project.js +896 -0
  64. package/dist/containers/project.js.map +1 -0
  65. package/dist/containers/template.d.ts +108 -0
  66. package/dist/containers/template.js +433 -0
  67. package/dist/containers/template.js.map +1 -0
  68. package/dist/exceptions/index.d.ts +19 -0
  69. package/dist/exceptions/index.js +26 -0
  70. package/dist/exceptions/index.js.map +1 -0
  71. package/dist/index.d.ts +16 -0
  72. package/dist/index.js +15 -0
  73. package/dist/index.js.map +1 -0
  74. package/dist/interfaces/adoc.d.ts +12 -0
  75. package/dist/interfaces/adoc.js +13 -0
  76. package/dist/interfaces/adoc.js.map +1 -0
  77. package/dist/interfaces/macros.d.ts +45 -0
  78. package/dist/interfaces/macros.js +13 -0
  79. package/dist/interfaces/macros.js.map +1 -0
  80. package/dist/interfaces/project-interfaces.d.ts +121 -0
  81. package/dist/interfaces/project-interfaces.js +21 -0
  82. package/dist/interfaces/project-interfaces.js.map +1 -0
  83. package/dist/interfaces/request-status-interfaces.d.ts +28 -0
  84. package/dist/interfaces/request-status-interfaces.js +20 -0
  85. package/dist/interfaces/request-status-interfaces.js.map +1 -0
  86. package/dist/interfaces/resource-interfaces.d.ts +117 -0
  87. package/dist/interfaces/resource-interfaces.js +20 -0
  88. package/dist/interfaces/resource-interfaces.js.map +1 -0
  89. package/dist/macros/base-macro.d.ts +31 -0
  90. package/dist/macros/base-macro.js +126 -0
  91. package/dist/macros/base-macro.js.map +1 -0
  92. package/dist/macros/common.d.ts +17 -0
  93. package/dist/macros/common.js +23 -0
  94. package/dist/macros/common.js.map +1 -0
  95. package/dist/macros/createCards/index.d.ts +36 -0
  96. package/dist/macros/createCards/index.js +35 -0
  97. package/dist/macros/createCards/index.js.map +1 -0
  98. package/dist/macros/createCards/metadata.d.ts +14 -0
  99. package/dist/macros/createCards/metadata.js +18 -0
  100. package/dist/macros/createCards/metadata.js.map +1 -0
  101. package/dist/macros/graph/index.d.ts +29 -0
  102. package/dist/macros/graph/index.js +91 -0
  103. package/dist/macros/graph/index.js.map +1 -0
  104. package/dist/macros/graph/metadata.d.ts +14 -0
  105. package/dist/macros/graph/metadata.js +18 -0
  106. package/dist/macros/graph/metadata.js.map +1 -0
  107. package/dist/macros/index.d.ts +93 -0
  108. package/dist/macros/index.js +237 -0
  109. package/dist/macros/index.js.map +1 -0
  110. package/dist/macros/report/index.d.ts +26 -0
  111. package/dist/macros/report/index.js +70 -0
  112. package/dist/macros/report/index.js.map +1 -0
  113. package/dist/macros/report/metadata.d.ts +14 -0
  114. package/dist/macros/report/metadata.js +18 -0
  115. package/dist/macros/report/metadata.js.map +1 -0
  116. package/dist/macros/scoreCard/index.d.ts +30 -0
  117. package/dist/macros/scoreCard/index.js +38 -0
  118. package/dist/macros/scoreCard/index.js.map +1 -0
  119. package/dist/macros/scoreCard/metadata.d.ts +14 -0
  120. package/dist/macros/scoreCard/metadata.js +18 -0
  121. package/dist/macros/scoreCard/metadata.js.map +1 -0
  122. package/dist/macros/task-queue.d.ts +46 -0
  123. package/dist/macros/task-queue.js +69 -0
  124. package/dist/macros/task-queue.js.map +1 -0
  125. package/dist/module-manager.d.ts +62 -0
  126. package/dist/module-manager.js +350 -0
  127. package/dist/module-manager.js.map +1 -0
  128. package/dist/permissions/action-guard.d.ts +28 -0
  129. package/dist/permissions/action-guard.js +61 -0
  130. package/dist/permissions/action-guard.js.map +1 -0
  131. package/dist/project-settings.d.ts +42 -0
  132. package/dist/project-settings.js +120 -0
  133. package/dist/project-settings.js.map +1 -0
  134. package/dist/resources/array-handler.d.ts +28 -0
  135. package/dist/resources/array-handler.js +116 -0
  136. package/dist/resources/array-handler.js.map +1 -0
  137. package/dist/resources/card-type-resource.d.ts +72 -0
  138. package/dist/resources/card-type-resource.js +334 -0
  139. package/dist/resources/card-type-resource.js.map +1 -0
  140. package/dist/resources/create-defaults.d.ts +81 -0
  141. package/dist/resources/create-defaults.js +184 -0
  142. package/dist/resources/create-defaults.js.map +1 -0
  143. package/dist/resources/field-type-resource.d.ts +88 -0
  144. package/dist/resources/field-type-resource.js +411 -0
  145. package/dist/resources/field-type-resource.js.map +1 -0
  146. package/dist/resources/file-resource.d.ts +50 -0
  147. package/dist/resources/file-resource.js +301 -0
  148. package/dist/resources/file-resource.js.map +1 -0
  149. package/dist/resources/folder-resource.d.ts +66 -0
  150. package/dist/resources/folder-resource.js +100 -0
  151. package/dist/resources/folder-resource.js.map +1 -0
  152. package/dist/resources/graph-model-resource.d.ts +78 -0
  153. package/dist/resources/graph-model-resource.js +164 -0
  154. package/dist/resources/graph-model-resource.js.map +1 -0
  155. package/dist/resources/graph-view-resource.d.ts +78 -0
  156. package/dist/resources/graph-view-resource.js +163 -0
  157. package/dist/resources/graph-view-resource.js.map +1 -0
  158. package/dist/resources/link-type-resource.d.ts +62 -0
  159. package/dist/resources/link-type-resource.js +150 -0
  160. package/dist/resources/link-type-resource.js.map +1 -0
  161. package/dist/resources/report-resource.d.ts +77 -0
  162. package/dist/resources/report-resource.js +171 -0
  163. package/dist/resources/report-resource.js.map +1 -0
  164. package/dist/resources/resource-object.d.ts +108 -0
  165. package/dist/resources/resource-object.js +147 -0
  166. package/dist/resources/resource-object.js.map +1 -0
  167. package/dist/resources/template-resource.d.ts +82 -0
  168. package/dist/resources/template-resource.js +173 -0
  169. package/dist/resources/template-resource.js.map +1 -0
  170. package/dist/resources/workflow-resource.d.ts +67 -0
  171. package/dist/resources/workflow-resource.js +156 -0
  172. package/dist/resources/workflow-resource.js.map +1 -0
  173. package/dist/types/queries.d.ts +142 -0
  174. package/dist/types/queries.js +16 -0
  175. package/dist/types/queries.js.map +1 -0
  176. package/dist/utils/card-utils.d.ts +34 -0
  177. package/dist/utils/card-utils.js +78 -0
  178. package/dist/utils/card-utils.js.map +1 -0
  179. package/dist/utils/clingo-fact-builder.d.ts +58 -0
  180. package/dist/utils/clingo-fact-builder.js +126 -0
  181. package/dist/utils/clingo-fact-builder.js.map +1 -0
  182. package/dist/utils/clingo-facts.d.ts +97 -0
  183. package/dist/utils/clingo-facts.js +352 -0
  184. package/dist/utils/clingo-facts.js.map +1 -0
  185. package/dist/utils/clingo-parser.d.ts +59 -0
  186. package/dist/utils/clingo-parser.js +403 -0
  187. package/dist/utils/clingo-parser.js.map +1 -0
  188. package/dist/utils/clingo-program-builder.d.ts +39 -0
  189. package/dist/utils/clingo-program-builder.js +57 -0
  190. package/dist/utils/clingo-program-builder.js.map +1 -0
  191. package/dist/utils/common-utils.d.ts +24 -0
  192. package/dist/utils/common-utils.js +47 -0
  193. package/dist/utils/common-utils.js.map +1 -0
  194. package/dist/utils/constants.d.ts +18 -0
  195. package/dist/utils/constants.js +27 -0
  196. package/dist/utils/constants.js.map +1 -0
  197. package/dist/utils/csv.d.ts +18 -0
  198. package/dist/utils/csv.js +45 -0
  199. package/dist/utils/csv.js.map +1 -0
  200. package/dist/utils/file-utils.d.ts +69 -0
  201. package/dist/utils/file-utils.js +158 -0
  202. package/dist/utils/file-utils.js.map +1 -0
  203. package/dist/utils/json.d.ts +61 -0
  204. package/dist/utils/json.js +108 -0
  205. package/dist/utils/json.js.map +1 -0
  206. package/dist/utils/lexorank.d.ts +59 -0
  207. package/dist/utils/lexorank.js +159 -0
  208. package/dist/utils/lexorank.js.map +1 -0
  209. package/dist/utils/log-utils.d.ts +40 -0
  210. package/dist/utils/log-utils.js +109 -0
  211. package/dist/utils/log-utils.js.map +1 -0
  212. package/dist/utils/random.d.ts +19 -0
  213. package/dist/utils/random.js +34 -0
  214. package/dist/utils/random.js.map +1 -0
  215. package/dist/utils/resource-utils.d.ts +45 -0
  216. package/dist/utils/resource-utils.js +137 -0
  217. package/dist/utils/resource-utils.js.map +1 -0
  218. package/dist/utils/sanitize-svg.d.ts +18 -0
  219. package/dist/utils/sanitize-svg.js +38 -0
  220. package/dist/utils/sanitize-svg.js.map +1 -0
  221. package/dist/utils/user-preferences.d.ts +64 -0
  222. package/dist/utils/user-preferences.js +106 -0
  223. package/dist/utils/user-preferences.js.map +1 -0
  224. package/dist/utils/validate.d.ts +26 -0
  225. package/dist/utils/validate.js +53 -0
  226. package/dist/utils/validate.js.map +1 -0
  227. package/dist/utils/value-utils.d.ts +58 -0
  228. package/dist/utils/value-utils.js +181 -0
  229. package/dist/utils/value-utils.js.map +1 -0
  230. package/package.json +67 -0
  231. package/src/card-metadata-updater.ts +182 -0
  232. package/src/command-handler.ts +686 -0
  233. package/src/command-manager.ts +99 -0
  234. package/src/commands/calculate.ts +591 -0
  235. package/src/commands/create.ts +559 -0
  236. package/src/commands/edit.ts +123 -0
  237. package/src/commands/export-site.ts +356 -0
  238. package/src/commands/export.ts +315 -0
  239. package/src/commands/import.ts +169 -0
  240. package/src/commands/index.ts +42 -0
  241. package/src/commands/move.ts +451 -0
  242. package/src/commands/remove.ts +244 -0
  243. package/src/commands/rename.ts +378 -0
  244. package/src/commands/show.ts +442 -0
  245. package/src/commands/transition.ts +127 -0
  246. package/src/commands/update.ts +76 -0
  247. package/src/commands/validate.ts +962 -0
  248. package/src/containers/card-container.ts +378 -0
  249. package/src/containers/project/project-paths.ts +127 -0
  250. package/src/containers/project/resource-collector.ts +379 -0
  251. package/src/containers/project.ts +1135 -0
  252. package/src/containers/template.ts +573 -0
  253. package/src/exceptions/index.ts +29 -0
  254. package/src/index.ts +33 -0
  255. package/src/interfaces/adoc.ts +18 -0
  256. package/src/interfaces/macros.ts +54 -0
  257. package/src/interfaces/project-interfaces.ts +208 -0
  258. package/src/interfaces/request-status-interfaces.ts +30 -0
  259. package/src/interfaces/resource-interfaces.ts +179 -0
  260. package/src/macros/base-macro.ts +176 -0
  261. package/src/macros/common.ts +24 -0
  262. package/src/macros/createCards/index.ts +57 -0
  263. package/src/macros/createCards/metadata.ts +21 -0
  264. package/src/macros/graph/index.ts +130 -0
  265. package/src/macros/graph/metadata.ts +21 -0
  266. package/src/macros/index.ts +321 -0
  267. package/src/macros/report/index.ts +88 -0
  268. package/src/macros/report/metadata.ts +21 -0
  269. package/src/macros/scoreCard/index.ts +55 -0
  270. package/src/macros/scoreCard/metadata.ts +21 -0
  271. package/src/macros/task-queue.ts +79 -0
  272. package/src/module-manager.ts +443 -0
  273. package/src/permissions/action-guard.ts +77 -0
  274. package/src/project-settings.ts +140 -0
  275. package/src/resources/array-handler.ts +141 -0
  276. package/src/resources/card-type-resource.ts +455 -0
  277. package/src/resources/create-defaults.ts +216 -0
  278. package/src/resources/field-type-resource.ts +533 -0
  279. package/src/resources/file-resource.ts +433 -0
  280. package/src/resources/folder-resource.ts +140 -0
  281. package/src/resources/graph-model-resource.ts +205 -0
  282. package/src/resources/graph-view-resource.ts +199 -0
  283. package/src/resources/link-type-resource.ts +191 -0
  284. package/src/resources/report-resource.ts +224 -0
  285. package/src/resources/resource-object.ts +246 -0
  286. package/src/resources/template-resource.ts +210 -0
  287. package/src/resources/workflow-resource.ts +205 -0
  288. package/src/types/queries.ts +149 -0
  289. package/src/utils/card-utils.ts +83 -0
  290. package/src/utils/clingo-fact-builder.ts +167 -0
  291. package/src/utils/clingo-facts.ts +550 -0
  292. package/src/utils/clingo-parser.ts +519 -0
  293. package/src/utils/clingo-program-builder.ts +71 -0
  294. package/src/utils/common-utils.ts +54 -0
  295. package/src/utils/constants.ts +32 -0
  296. package/src/utils/csv.ts +53 -0
  297. package/src/utils/file-utils.ts +182 -0
  298. package/src/utils/json.ts +118 -0
  299. package/src/utils/lexorank.ts +180 -0
  300. package/src/utils/log-utils.ts +127 -0
  301. package/src/utils/random.ts +37 -0
  302. package/src/utils/resource-utils.ts +180 -0
  303. package/src/utils/sanitize-svg.ts +46 -0
  304. package/src/utils/user-preferences.ts +126 -0
  305. package/src/utils/validate.ts +66 -0
  306. package/src/utils/value-utils.ts +189 -0
@@ -0,0 +1,45 @@
1
+ /**
2
+ Cyberismo
3
+ Copyright © Cyberismo Ltd and contributors 2024
4
+
5
+ This program is free software: you can redistribute it and/or modify it under
6
+ the terms of the GNU Affero General Public License version 3 as published by
7
+ the Free Software Foundation. This program is distributed in the hope that it
8
+ will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
9
+ of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10
+ See the GNU Affero General Public License for more details.
11
+ You should have received a copy of the GNU Affero General Public
12
+ License along with this program. If not, see <https://www.gnu.org/licenses/>.
13
+ */
14
+ import { type Calculate, type Show } from './index.js';
15
+ import { Export } from './export.js';
16
+ import type { Project } from '../containers/project.js';
17
+ interface ExportOptions {
18
+ silent: boolean;
19
+ }
20
+ export declare class ExportSite extends Export {
21
+ private tmpDir;
22
+ private moduleDir;
23
+ private pagesDir;
24
+ private imagesDir;
25
+ private playbookDir;
26
+ private playbookFile;
27
+ private navFile;
28
+ private options;
29
+ constructor(project: Project, calculateCmd: Calculate, showCmd: Show);
30
+ private createCardsIndex;
31
+ private initDirectories;
32
+ private generate;
33
+ private createPlaybook;
34
+ private createDescriptor;
35
+ private initRepo;
36
+ private toAdocDirectoryAsContent;
37
+ private export;
38
+ /**
39
+ * Export the card tree as an Antora site
40
+ * @param destination Path where the site is generated
41
+ * @param cardKey Optional; If defined exports the card tree from underneath this card.
42
+ */
43
+ exportToSite(destination: string, cardKey?: string, options?: ExportOptions): Promise<string>;
44
+ }
45
+ export {};
@@ -0,0 +1,301 @@
1
+ /**
2
+ Cyberismo
3
+ Copyright © Cyberismo Ltd and contributors 2024
4
+
5
+ This program is free software: you can redistribute it and/or modify it under
6
+ the terms of the GNU Affero General Public License version 3 as published by
7
+ the Free Software Foundation. This program is distributed in the hope that it
8
+ will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
9
+ of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10
+ See the GNU Affero General Public License for more details.
11
+ You should have received a copy of the GNU Affero General Public
12
+ License along with this program. If not, see <https://www.gnu.org/licenses/>.
13
+ */
14
+ // node
15
+ import fs from 'node:fs';
16
+ import { platform, tmpdir } from 'node:os';
17
+ import { appendFile, copyFile, mkdir, writeFile } from 'node:fs/promises';
18
+ import { mkdtempSync, writeFileSync } from 'node:fs';
19
+ import { dirname, join, resolve } from 'node:path';
20
+ import { spawnSync } from 'node:child_process';
21
+ import { fileURLToPath } from 'node:url';
22
+ import git from 'isomorphic-git';
23
+ import { dump } from 'js-yaml';
24
+ import { Export } from './export.js';
25
+ import { errorFunction } from '../utils/log-utils.js';
26
+ import { sortItems } from '../utils/lexorank.js';
27
+ import { getStaticDirectoryPath } from '@cyberismocom/resources';
28
+ export class ExportSite extends Export {
29
+ tmpDir = '';
30
+ moduleDir = '';
31
+ pagesDir = '';
32
+ imagesDir = '';
33
+ playbookDir = '';
34
+ playbookFile = '';
35
+ navFile = '';
36
+ options;
37
+ constructor(project, calculateCmd, showCmd) {
38
+ super(project, calculateCmd, showCmd);
39
+ }
40
+ // Writes index.html file into cards folder that just redirects to the first card.
41
+ createCardsIndex(destination, cardKey) {
42
+ const indexFile = join(destination, 'cards', 'index.html');
43
+ const indexContent = `<meta http-equiv="refresh" content="0; url=${cardKey}.html">`;
44
+ try {
45
+ fs.writeFileSync(indexFile, indexContent);
46
+ }
47
+ catch (error) {
48
+ throw new Error(errorFunction(error));
49
+ }
50
+ }
51
+ // todo: change this so that split temp folder creation to its own method.
52
+ // then parallelize this and export() as much as you can.
53
+ async initDirectories() {
54
+ // Create temporary adoc output directory
55
+ try {
56
+ this.tmpDir = mkdtempSync(join(tmpdir(), 'cards-'));
57
+ }
58
+ catch (error) {
59
+ throw new Error(errorFunction(error));
60
+ }
61
+ // Antora requires the content directory to be a Git repository
62
+ await this.initRepo();
63
+ // Create the pages and images directories
64
+ this.moduleDir = join(this.tmpDir, 'modules', 'ROOT');
65
+ this.pagesDir = join(this.moduleDir, 'pages');
66
+ this.imagesDir = join(this.moduleDir, 'assets', 'images');
67
+ this.navFile = join(this.moduleDir, 'nav.adoc');
68
+ const promiseContainer = [];
69
+ promiseContainer.push(mkdir(this.pagesDir, { recursive: true }));
70
+ promiseContainer.push(mkdir(this.imagesDir, { recursive: true }));
71
+ await Promise.all(promiseContainer);
72
+ // Create the playbook directory
73
+ this.playbookDir = mkdtempSync(join(tmpdir(), 'cards-playbook-'));
74
+ }
75
+ // Generate the site from the source files using Antora.
76
+ generate(outputPath) {
77
+ const __filename = fileURLToPath(import.meta.url);
78
+ const __dirname = dirname(__filename);
79
+ const absoluteOutputPath = resolve(process.cwd(), outputPath);
80
+ const additionalArguments = [
81
+ '--to-dir',
82
+ absoluteOutputPath,
83
+ this.playbookFile,
84
+ ];
85
+ if (this.options && this.options?.silent) {
86
+ additionalArguments.unshift('--silent');
87
+ }
88
+ // Use spawnsync to npx execute the program "antora"
89
+ try {
90
+ // Allthough we use pnpm as the package manager, we rather use npx at runtime, because it is shipped with node
91
+ spawnSync('npx', ['antora', ...additionalArguments], {
92
+ stdio: 'inherit',
93
+ shell: platform() === 'win32',
94
+ cwd: __dirname,
95
+ });
96
+ }
97
+ catch (error) {
98
+ throw new Error(errorFunction(error));
99
+ }
100
+ }
101
+ // Create the Antora playbook.
102
+ async createPlaybook(cards) {
103
+ let startPage = '';
104
+ if (cards[0]) {
105
+ startPage = cards[0].key + '.adoc';
106
+ }
107
+ else {
108
+ throw new Error('Cannot create a playbook for an empty card set');
109
+ }
110
+ const playbook = {
111
+ site: {
112
+ title: this.project.configuration.name,
113
+ start_page: `cards:ROOT:${startPage}`,
114
+ },
115
+ content: {
116
+ sources: [
117
+ {
118
+ url: this.tmpDir,
119
+ branches: 'HEAD',
120
+ },
121
+ ],
122
+ },
123
+ urls: {
124
+ html_extension_style: 'default',
125
+ },
126
+ ui: {
127
+ bundle: {
128
+ url: join(await getStaticDirectoryPath(), 'ui-bundle'),
129
+ snapshot: true,
130
+ },
131
+ },
132
+ };
133
+ this.playbookFile = join(this.playbookDir, 'antora-playbook.yml');
134
+ writeFileSync(this.playbookFile, dump(playbook));
135
+ }
136
+ // Create the Antora site descriptor.
137
+ createDescriptor() {
138
+ const projectName = this.project.configuration.name;
139
+ const descriptor = {
140
+ name: 'cards',
141
+ title: projectName,
142
+ version: null,
143
+ nav: ['modules/ROOT/nav.adoc'],
144
+ };
145
+ const descriptorPath = join(this.tmpDir, 'antora.yml');
146
+ try {
147
+ writeFileSync(descriptorPath, dump(descriptor));
148
+ }
149
+ catch (error) {
150
+ throw new Error(errorFunction(error));
151
+ }
152
+ }
153
+ // Initialise the temporary directory as a temporary Git repository.
154
+ async initRepo() {
155
+ try {
156
+ await git.init({ fs, dir: this.tmpDir });
157
+ writeFileSync(join(this.tmpDir, '.gitkeep'), '');
158
+ await git.add({ fs, dir: this.tmpDir, filepath: '.gitkeep' });
159
+ }
160
+ catch (error) {
161
+ throw new Error(errorFunction(error));
162
+ }
163
+ try {
164
+ await git.commit({
165
+ fs,
166
+ dir: this.tmpDir,
167
+ author: {
168
+ name: 'Cyberismo Cards',
169
+ email: 'info@cyberismo.com',
170
+ },
171
+ message: 'Add .gitkeep',
172
+ });
173
+ }
174
+ catch (error) {
175
+ throw new Error(errorFunction(error));
176
+ }
177
+ }
178
+ // Write cards as Antora-compatible AsciiDoc to the given location
179
+ // @param path Directory where the cards should be written
180
+ // @param cards Array of Cards
181
+ // @param depth Navigation depth - this is used in recursion to format the hierarchical menu
182
+ async toAdocDirectoryAsContent(path, cards, depth) {
183
+ depth++;
184
+ // Sort the cards by rank
185
+ cards = sortItems(cards, function (card) {
186
+ return card.metadata?.rank || '1|z';
187
+ });
188
+ // Ensure the target path exists
189
+ await mkdir(path, { recursive: true });
190
+ for (const card of cards) {
191
+ // Construct path for individual card file
192
+ const cardPath = join(path, card.key + '.adoc');
193
+ const cardXRef = cardPath.slice(this.pagesDir.length);
194
+ let navFileContent = '';
195
+ if (card.metadata?.progress) {
196
+ navFileContent =
197
+ '*'.repeat(depth) +
198
+ ` xref:${cardXRef}[${card.metadata?.title} (${card.metadata?.progress}%)]\n`;
199
+ }
200
+ else {
201
+ navFileContent =
202
+ '*'.repeat(depth) + ` xref:${cardXRef}[${card.metadata?.title}]\n`;
203
+ }
204
+ await appendFile(this.navFile, navFileContent);
205
+ let tempContent = '';
206
+ if (card.metadata) {
207
+ const cardTypeForCard = await this.project.resource(card.metadata?.cardType);
208
+ tempContent = '\n= ';
209
+ tempContent += card.metadata?.title
210
+ ? `${card.metadata.title}\n\n`
211
+ : 'Untitled\n\n';
212
+ tempContent += super.metaToAdoc(card, cardTypeForCard);
213
+ }
214
+ if (card.content) {
215
+ tempContent += '\n' + card.content;
216
+ }
217
+ if (tempContent !== '') {
218
+ await writeFile(cardPath, tempContent);
219
+ }
220
+ if (card.children && card.children.length > 0) {
221
+ // Recurse into the child cards
222
+ await this.toAdocDirectoryAsContent(path, card.children, depth);
223
+ }
224
+ if (card.attachments) {
225
+ const promiseContainer = [];
226
+ for (const attachment of card.attachments) {
227
+ const source = join(attachment.path, attachment.fileName);
228
+ const destination = join(this.imagesDir, `${attachment.fileName}`);
229
+ promiseContainer.push(copyFile(source, destination));
230
+ }
231
+ await Promise.all(promiseContainer);
232
+ }
233
+ }
234
+ --depth;
235
+ }
236
+ // Export the cards to the temporary directory as a full HTML site generated by Antora.
237
+ async export(destination, cards) {
238
+ await this.initDirectories();
239
+ this.createDescriptor();
240
+ await this.toAdocDirectoryAsContent(this.pagesDir, cards, 0);
241
+ await this.createPlaybook(cards);
242
+ this.generate(destination);
243
+ }
244
+ /**
245
+ * Export the card tree as an Antora site
246
+ * @param destination Path where the site is generated
247
+ * @param cardKey Optional; If defined exports the card tree from underneath this card.
248
+ */
249
+ async exportToSite(destination, cardKey, options) {
250
+ this.options = options;
251
+ const sourcePath = cardKey
252
+ ? join(this.project.paths.cardRootFolder, this.project.pathToCard(cardKey))
253
+ : this.project.paths.cardRootFolder;
254
+ let cards = [];
255
+ // If doing a partial tree export, put the parent information as it would have already been gathered.
256
+ if (cardKey) {
257
+ const card = await this.project.findSpecificCard(cardKey);
258
+ if (!card) {
259
+ throw new Error(`Input validation error: cannot find card '${cardKey}'`);
260
+ }
261
+ cards.push({
262
+ key: cardKey,
263
+ path: sourcePath,
264
+ children: [],
265
+ attachments: [],
266
+ });
267
+ }
268
+ await this.calculateCmd.generate();
269
+ const tree = await this.calculateCmd.runQuery('tree');
270
+ if (cardKey) {
271
+ const targetCard = this.findCardInTree(tree, cardKey);
272
+ if (!targetCard) {
273
+ throw new Error(`Cannot find card '${cardKey}' in the tree hierarchy`);
274
+ }
275
+ cards = [await this.treeQueryResultToCard(targetCard)];
276
+ }
277
+ else {
278
+ for (const treeQueryResult of tree) {
279
+ cards.push(await this.treeQueryResultToCard(treeQueryResult));
280
+ }
281
+ }
282
+ if (!cards.length) {
283
+ throw new Error('No cards found');
284
+ }
285
+ if (cards.length > 3000) {
286
+ throw new Error(`There are ${cards.length} cards in the project. Exporting to a site only supports maximum of 3000 cards.`);
287
+ }
288
+ if (cards.length > 1000 && cards.length < 3000) {
289
+ console.warn(`Warning: There are ${cards.length} cards in the project. There is a hard limit of 3000 cards that can be exported as a site.`);
290
+ }
291
+ await this.export(destination, cards);
292
+ if (cards.length > 0 && cards.at(0)) {
293
+ const firstCard = cards.at(0);
294
+ if (firstCard && firstCard.key) {
295
+ this.createCardsIndex(destination, firstCard.key);
296
+ }
297
+ }
298
+ return '';
299
+ }
300
+ }
301
+ //# sourceMappingURL=export-site.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"export-site.js","sourceRoot":"","sources":["../../src/commands/export-site.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;EAYE;AAEF,OAAO;AACP,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAC3C,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC1E,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACrD,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACnD,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC/C,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEzC,OAAO,GAAG,MAAM,gBAAgB,CAAC;AACjC,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAG/B,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAGrC,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAEtD,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACjD,OAAO,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAC;AAMjE,MAAM,OAAO,UAAW,SAAQ,MAAM;IAC5B,MAAM,GAAW,EAAE,CAAC;IACpB,SAAS,GAAW,EAAE,CAAC;IACvB,QAAQ,GAAW,EAAE,CAAC;IACtB,SAAS,GAAW,EAAE,CAAC;IACvB,WAAW,GAAW,EAAE,CAAC;IACzB,YAAY,GAAW,EAAE,CAAC;IAC1B,OAAO,GAAW,EAAE,CAAC;IACrB,OAAO,CAA4B;IAE3C,YAAY,OAAgB,EAAE,YAAuB,EAAE,OAAa;QAClE,KAAK,CAAC,OAAO,EAAE,YAAY,EAA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/B,IAAI,CAAC,gBAAgB,CAAC,WAAW,EAAE,SAAS,CAAC,GAAG,CAAC,CAAC;YACpD,CAAC;QACH,CAAC;QACD,OAAO,EAAE,CAAC;IACZ,CAAC;CACF"}
@@ -0,0 +1,53 @@
1
+ /**
2
+ Cyberismo
3
+ Copyright © Cyberismo Ltd and contributors 2024
4
+
5
+ This program is free software: you can redistribute it and/or modify it under
6
+ the terms of the GNU Affero General Public License version 3 as published by
7
+ the Free Software Foundation. This program is distributed in the hope that it
8
+ will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
9
+ of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10
+ See the GNU Affero General Public License for more details.
11
+ You should have received a copy of the GNU Affero General Public
12
+ License along with this program. If not, see <https://www.gnu.org/licenses/>.
13
+ */
14
+ import type { Calculate, Show } from './index.js';
15
+ import type { Card } from '../interfaces/project-interfaces.js';
16
+ import type { CardType } from '../interfaces/resource-interfaces.js';
17
+ import { Project } from '../containers/project.js';
18
+ import type { QueryResult } from '../types/queries.js';
19
+ export declare class Export {
20
+ protected project: Project;
21
+ protected calculateCmd: Calculate;
22
+ protected showCmd: Show;
23
+ constructor(project: Project, calculateCmd: Calculate, showCmd: Show);
24
+ private toAdocFile;
25
+ protected metaToAdoc(card: Card, cardType: CardType | undefined): string;
26
+ private toAdocFileAsContent;
27
+ /**
28
+ * Recursively searches for a card with the specified key in the tree hierarchy.
29
+ * @param treeItems Array of tree query results to search through
30
+ * @param targetKey The key of the card to find
31
+ * @returns The found tree item or null if not found
32
+ */
33
+ protected findCardInTree(treeItems: QueryResult<'tree'>[], targetKey: string): QueryResult<'tree'> | null;
34
+ /**
35
+ * Convert treeQueryResult object into a Card object and add content, metadata & attachments
36
+ * Handles card children recursively
37
+ * @param treeQueryResult tree query result object
38
+ */
39
+ protected treeQueryResultToCard(treeQueryResult: QueryResult<'tree'>): Promise<Card>;
40
+ /**
41
+ * Exports the card(s) to ascii doc.
42
+ * @param destination Path to where the resulting file(s) will be created.
43
+ * @param cardKey If not exporting the whole card tree, card key of parent card.
44
+ * @returns status message
45
+ */
46
+ exportToADoc(destination: string, cardKey?: string): Promise<string>;
47
+ /**
48
+ * Exports the card(s) to HTML and opens the browser.
49
+ * @param destination Path to where the resulting file(s) will be created.
50
+ * @param cardKey Optional; If not exporting the whole card tree, card key of parent card.
51
+ */
52
+ exportToHTML(destination: string, cardKey?: string): Promise<string>;
53
+ }
@@ -0,0 +1,251 @@
1
+ /**
2
+ Cyberismo
3
+ Copyright © Cyberismo Ltd and contributors 2024
4
+
5
+ This program is free software: you can redistribute it and/or modify it under
6
+ the terms of the GNU Affero General Public License version 3 as published by
7
+ the Free Software Foundation. This program is distributed in the hope that it
8
+ will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
9
+ of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10
+ See the GNU Affero General Public License for more details.
11
+ You should have received a copy of the GNU Affero General Public
12
+ License along with this program. If not, see <https://www.gnu.org/licenses/>.
13
+ */
14
+ // node
15
+ import { appendFile, copyFile, mkdir, truncate } from 'node:fs/promises';
16
+ import { dirname, join } from 'node:path';
17
+ // asciidoctor
18
+ import Processor from '@asciidoctor/core';
19
+ import { Project } from '../containers/project.js';
20
+ import { sortItems } from '../utils/lexorank.js';
21
+ const attachmentFolder = 'a';
22
+ export class Export {
23
+ project;
24
+ calculateCmd;
25
+ showCmd;
26
+ constructor(project, calculateCmd, showCmd) {
27
+ this.project = project;
28
+ this.calculateCmd = calculateCmd;
29
+ this.showCmd = showCmd;
30
+ }
31
+ // This file should set the top level items to the adoc.
32
+ async toAdocFile(path, cards) {
33
+ await appendFile(path, `:imagesdir: ./${attachmentFolder}/\n`);
34
+ await this.toAdocFileAsContent(path, cards);
35
+ }
36
+ // Format card metadata to an AsciiDoc table.
37
+ metaToAdoc(card, cardType) {
38
+ let content = '';
39
+ if (card.metadata) {
40
+ content += `[.cyberismo-meta-wrapper]\n`;
41
+ content += '--\n';
42
+ content += `[.cyberismo-meta]\n`;
43
+ content += '[cols="1,1"]\n';
44
+ content += '[frame=none]\n';
45
+ content += '[grid=none]\n';
46
+ content += '|===\n';
47
+ content += `|Card key|${card.key}\n`;
48
+ content += `|Status|${card.metadata.workflowState}\n`;
49
+ content += `|Card type|${card.metadata.cardType}\n`;
50
+ content += `|Labels|${card.metadata.labels?.join(', ') || ''}`;
51
+ for (const [key, value] of Object.entries(card.metadata)) {
52
+ if (cardType?.alwaysVisibleFields.includes(key) ||
53
+ cardType?.optionallyVisibleFields?.includes(key)) {
54
+ const displayName = cardType?.customFields.find((item) => item.name === key)?.displayName;
55
+ let nameToShow = displayName
56
+ ? displayName
57
+ : key[0].toUpperCase() + key.slice(1);
58
+ if (nameToShow === 'WorkflowState') {
59
+ nameToShow = 'Workflow state';
60
+ }
61
+ else if (nameToShow === 'Cardtype') {
62
+ nameToShow = 'Card type';
63
+ }
64
+ // Escape pipe character in cell values
65
+ let escapedValue = 'N/A';
66
+ if (value) {
67
+ escapedValue = value.toString().replaceAll('|', '\\|');
68
+ }
69
+ content += `|${nameToShow}|${escapedValue}\n`;
70
+ }
71
+ }
72
+ content += '|===\n';
73
+ content += '--\n';
74
+ }
75
+ return content;
76
+ }
77
+ async toAdocFileAsContent(path, cards) {
78
+ for (const card of cards) {
79
+ let fileContent = '';
80
+ if (card.metadata?.title) {
81
+ fileContent += `== ${card.metadata.title}\n\n`;
82
+ }
83
+ else {
84
+ fileContent += `== ${card.key}\n\n`;
85
+ }
86
+ if (card.metadata) {
87
+ const cardTypeForCard = await this.project.resource(card.metadata?.cardType);
88
+ const metaDataContent = this.metaToAdoc(card, cardTypeForCard);
89
+ fileContent += metaDataContent;
90
+ }
91
+ if (card.content) {
92
+ fileContent += card.content;
93
+ }
94
+ if (card.attachments) {
95
+ const promiseContainer = [];
96
+ for (const attachment of card.attachments) {
97
+ const destination = join(dirname(path), attachmentFolder, attachment.fileName);
98
+ const source = join(attachment.path, attachment.fileName);
99
+ promiseContainer.push(copyFile(source, destination));
100
+ }
101
+ await Promise.all(promiseContainer);
102
+ }
103
+ // Add separator between cards
104
+ fileContent += '\n\n';
105
+ if (fileContent) {
106
+ await appendFile(path, fileContent);
107
+ }
108
+ if (card.children) {
109
+ await this.toAdocFileAsContent(path, card.children);
110
+ }
111
+ }
112
+ }
113
+ /**
114
+ * Recursively searches for a card with the specified key in the tree hierarchy.
115
+ * @param treeItems Array of tree query results to search through
116
+ * @param targetKey The key of the card to find
117
+ * @returns The found tree item or null if not found
118
+ */
119
+ findCardInTree(treeItems, targetKey) {
120
+ for (const item of treeItems) {
121
+ if (item.key === targetKey) {
122
+ return item;
123
+ }
124
+ if (item.children && item.children.length > 0) {
125
+ const foundInChildren = this.findCardInTree(item.children, targetKey);
126
+ if (foundInChildren) {
127
+ return foundInChildren;
128
+ }
129
+ }
130
+ }
131
+ return null;
132
+ }
133
+ /**
134
+ * Convert treeQueryResult object into a Card object and add content, metadata & attachments
135
+ * Handles card children recursively
136
+ * @param treeQueryResult tree query result object
137
+ */
138
+ async treeQueryResultToCard(treeQueryResult) {
139
+ const card = {
140
+ key: treeQueryResult.key,
141
+ path: '',
142
+ children: [],
143
+ attachments: [],
144
+ };
145
+ // Get content and attachments separately, not included in queries
146
+ const fetchCardDetails = {
147
+ attachments: true,
148
+ children: false,
149
+ content: true,
150
+ contentType: 'adoc',
151
+ metadata: true,
152
+ parent: false,
153
+ };
154
+ const cardDetailsResponse = await this.showCmd.showCardDetails(fetchCardDetails, card.key);
155
+ let asciiDocContent = '';
156
+ const projectPath = this.project.basePath;
157
+ try {
158
+ const { evaluateMacros } = await import('../macros/index.js');
159
+ asciiDocContent = await evaluateMacros(cardDetailsResponse.content || '', {
160
+ mode: 'static',
161
+ projectPath,
162
+ cardKey: card.key,
163
+ });
164
+ }
165
+ catch (error) {
166
+ asciiDocContent = `Macro error: ${error instanceof Error ? error.message : 'Unknown error'}\n\n${asciiDocContent}`;
167
+ }
168
+ card.path = cardDetailsResponse.path;
169
+ card.metadata = cardDetailsResponse.metadata;
170
+ card.metadata.progress = treeQueryResult.progress;
171
+ card.content = asciiDocContent;
172
+ card.attachments = cardDetailsResponse.attachments;
173
+ for (const result of treeQueryResult.children ?? []) {
174
+ card.children.push(await this.treeQueryResultToCard(result));
175
+ }
176
+ return card;
177
+ }
178
+ /**
179
+ * Exports the card(s) to ascii doc.
180
+ * @param destination Path to where the resulting file(s) will be created.
181
+ * @param cardKey If not exporting the whole card tree, card key of parent card.
182
+ * @returns status message
183
+ */
184
+ async exportToADoc(destination, cardKey) {
185
+ const sourcePath = this.project.paths.cardRootFolder;
186
+ let cards = [];
187
+ // If doing a partial tree export, put the parent information as it would have already been gathered.
188
+ if (cardKey) {
189
+ const card = await this.project.findSpecificCard(cardKey);
190
+ if (!card) {
191
+ throw new Error(`Input validation error: cannot find card '${cardKey}'`);
192
+ }
193
+ cards.push({
194
+ key: cardKey,
195
+ path: sourcePath,
196
+ children: [],
197
+ attachments: [],
198
+ });
199
+ }
200
+ await this.calculateCmd.generate();
201
+ const tree = await this.calculateCmd.runQuery('tree');
202
+ if (cardKey) {
203
+ const targetCard = this.findCardInTree(tree, cardKey);
204
+ if (!targetCard) {
205
+ throw new Error(`Cannot find card '${cardKey}' in the tree hierarchy`);
206
+ }
207
+ cards = [await this.treeQueryResultToCard(targetCard)];
208
+ }
209
+ else {
210
+ for (const treeQueryResult of tree) {
211
+ cards.push(await this.treeQueryResultToCard(treeQueryResult));
212
+ }
213
+ }
214
+ // Sort the cards by rank
215
+ cards = sortItems(cards, function (card) {
216
+ return card.metadata?.rank || '1|z';
217
+ });
218
+ await mkdir(join(destination, attachmentFolder), { recursive: true });
219
+ const resultDocumentPath = join(destination, Project.cardContentFile);
220
+ let message = '';
221
+ try {
222
+ await truncate(resultDocumentPath, 0);
223
+ message = `Using existing output file '${resultDocumentPath}'`;
224
+ }
225
+ catch {
226
+ message = `Creating output file '${resultDocumentPath}'`;
227
+ }
228
+ await this.toAdocFile(resultDocumentPath, cards);
229
+ return message;
230
+ }
231
+ /**
232
+ * Exports the card(s) to HTML and opens the browser.
233
+ * @param destination Path to where the resulting file(s) will be created.
234
+ * @param cardKey Optional; If not exporting the whole card tree, card key of parent card.
235
+ */
236
+ async exportToHTML(destination, cardKey) {
237
+ let message = '';
238
+ await this.exportToADoc(destination, cardKey).then((msg) => {
239
+ message = msg;
240
+ const asciiDocProcessor = Processor();
241
+ const adocFile = join(destination, Project.cardContentFile);
242
+ asciiDocProcessor.convertFile(adocFile, {
243
+ safe: 'safe',
244
+ base_dir: '/',
245
+ standalone: true,
246
+ });
247
+ });
248
+ return message;
249
+ }
250
+ }
251
+ //# sourceMappingURL=export.js.map