@cyberismo/data-handler 0.0.6 → 0.0.7

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 (157) hide show
  1. package/README.md +1 -0
  2. package/dist/card-metadata-updater.d.ts +1 -0
  3. package/dist/card-metadata-updater.js +7 -2
  4. package/dist/card-metadata-updater.js.map +1 -1
  5. package/dist/command-handler.d.ts +6 -1
  6. package/dist/command-handler.js +16 -15
  7. package/dist/command-handler.js.map +1 -1
  8. package/dist/command-manager.d.ts +15 -4
  9. package/dist/command-manager.js +41 -9
  10. package/dist/command-manager.js.map +1 -1
  11. package/dist/commands/calculate.d.ts +4 -10
  12. package/dist/commands/calculate.js +67 -78
  13. package/dist/commands/calculate.js.map +1 -1
  14. package/dist/commands/export.js +3 -3
  15. package/dist/commands/export.js.map +1 -1
  16. package/dist/commands/import.d.ts +3 -8
  17. package/dist/commands/import.js +10 -14
  18. package/dist/commands/import.js.map +1 -1
  19. package/dist/commands/index.d.ts +1 -2
  20. package/dist/commands/index.js +1 -2
  21. package/dist/commands/index.js.map +1 -1
  22. package/dist/commands/remove.js +1 -1
  23. package/dist/commands/remove.js.map +1 -1
  24. package/dist/commands/show.d.ts +6 -3
  25. package/dist/commands/show.js +8 -5
  26. package/dist/commands/show.js.map +1 -1
  27. package/dist/commands/validate.js +6 -4
  28. package/dist/commands/validate.js.map +1 -1
  29. package/dist/containers/project/project-content-watcher.d.ts +28 -0
  30. package/dist/containers/project/project-content-watcher.js +54 -0
  31. package/dist/containers/project/project-content-watcher.js.map +1 -0
  32. package/dist/containers/project/project-paths.js +1 -1
  33. package/dist/containers/project/project-paths.js.map +1 -1
  34. package/dist/containers/project.d.ts +9 -2
  35. package/dist/containers/project.js +49 -1
  36. package/dist/containers/project.js.map +1 -1
  37. package/dist/containers/template.d.ts +1 -0
  38. package/dist/containers/template.js +7 -2
  39. package/dist/containers/template.js.map +1 -1
  40. package/dist/index.d.ts +2 -1
  41. package/dist/index.js.map +1 -1
  42. package/dist/interfaces/macros.d.ts +2 -1
  43. package/dist/interfaces/project-interfaces.d.ts +5 -0
  44. package/dist/interfaces/project-interfaces.js.map +1 -1
  45. package/dist/interfaces/resource-interfaces.d.ts +14 -22
  46. package/dist/interfaces/resource-interfaces.js +10 -9
  47. package/dist/interfaces/resource-interfaces.js.map +1 -1
  48. package/dist/macros/graph/index.d.ts +1 -1
  49. package/dist/macros/graph/index.js +12 -12
  50. package/dist/macros/graph/index.js.map +1 -1
  51. package/dist/macros/index.d.ts +24 -3
  52. package/dist/macros/index.js +11 -4
  53. package/dist/macros/index.js.map +1 -1
  54. package/dist/macros/report/index.d.ts +13 -10
  55. package/dist/macros/report/index.js +26 -38
  56. package/dist/macros/report/index.js.map +1 -1
  57. package/dist/module-manager.d.ts +16 -7
  58. package/dist/module-manager.js +142 -112
  59. package/dist/module-manager.js.map +1 -1
  60. package/dist/project-settings.js +6 -0
  61. package/dist/project-settings.js.map +1 -1
  62. package/dist/resources/array-handler.js +6 -1
  63. package/dist/resources/array-handler.js.map +1 -1
  64. package/dist/resources/card-type-resource.d.ts +13 -9
  65. package/dist/resources/card-type-resource.js +47 -23
  66. package/dist/resources/card-type-resource.js.map +1 -1
  67. package/dist/resources/create-defaults.d.ts +10 -9
  68. package/dist/resources/create-defaults.js +15 -12
  69. package/dist/resources/create-defaults.js.map +1 -1
  70. package/dist/resources/field-type-resource.d.ts +0 -1
  71. package/dist/resources/field-type-resource.js +2 -10
  72. package/dist/resources/field-type-resource.js.map +1 -1
  73. package/dist/resources/file-resource.d.ts +7 -7
  74. package/dist/resources/file-resource.js +32 -7
  75. package/dist/resources/file-resource.js.map +1 -1
  76. package/dist/resources/folder-resource.d.ts +10 -9
  77. package/dist/resources/folder-resource.js +10 -9
  78. package/dist/resources/folder-resource.js.map +1 -1
  79. package/dist/resources/report-resource.d.ts +5 -6
  80. package/dist/resources/report-resource.js +16 -7
  81. package/dist/resources/report-resource.js.map +1 -1
  82. package/dist/resources/template-resource.d.ts +5 -6
  83. package/dist/resources/template-resource.js +7 -6
  84. package/dist/resources/template-resource.js.map +1 -1
  85. package/dist/resources/workflow-resource.d.ts +15 -8
  86. package/dist/resources/workflow-resource.js +124 -8
  87. package/dist/resources/workflow-resource.js.map +1 -1
  88. package/dist/types/queries.d.ts +11 -10
  89. package/dist/types/queries.js +10 -9
  90. package/dist/types/queries.js.map +1 -1
  91. package/dist/utils/clingo-fact-builder.d.ts +1 -0
  92. package/dist/utils/clingo-fact-builder.js +8 -3
  93. package/dist/utils/clingo-fact-builder.js.map +1 -1
  94. package/dist/utils/clingo-facts.js +15 -11
  95. package/dist/utils/clingo-facts.js.map +1 -1
  96. package/dist/utils/constants.d.ts +18 -12
  97. package/dist/utils/constants.js +18 -11
  98. package/dist/utils/constants.js.map +1 -1
  99. package/dist/utils/log-utils.d.ts +15 -2
  100. package/dist/utils/log-utils.js +20 -37
  101. package/dist/utils/log-utils.js.map +1 -1
  102. package/dist/utils/report.d.ts +27 -0
  103. package/dist/utils/report.js +60 -0
  104. package/dist/utils/report.js.map +1 -0
  105. package/dist/utils/resource-utils.js +3 -0
  106. package/dist/utils/resource-utils.js.map +1 -1
  107. package/dist/utils/sanitize-svg.d.ts +3 -4
  108. package/dist/utils/sanitize-svg.js +4 -7
  109. package/dist/utils/sanitize-svg.js.map +1 -1
  110. package/dist/utils/validate.js +2 -1
  111. package/dist/utils/validate.js.map +1 -1
  112. package/package.json +8 -9
  113. package/src/card-metadata-updater.ts +7 -2
  114. package/src/command-handler.ts +23 -13
  115. package/src/command-manager.ts +54 -13
  116. package/src/commands/calculate.ts +90 -106
  117. package/src/commands/export.ts +3 -2
  118. package/src/commands/import.ts +16 -16
  119. package/src/commands/index.ts +0 -2
  120. package/src/commands/remove.ts +1 -1
  121. package/src/commands/show.ts +13 -5
  122. package/src/commands/validate.ts +14 -9
  123. package/src/containers/project/project-content-watcher.ts +65 -0
  124. package/src/containers/project/project-paths.ts +1 -1
  125. package/src/containers/project.ts +60 -1
  126. package/src/containers/template.ts +7 -2
  127. package/src/index.ts +2 -0
  128. package/src/interfaces/macros.ts +2 -1
  129. package/src/interfaces/project-interfaces.ts +8 -0
  130. package/src/interfaces/resource-interfaces.ts +15 -22
  131. package/src/macros/graph/index.ts +17 -12
  132. package/src/macros/index.ts +32 -6
  133. package/src/macros/report/index.ts +32 -42
  134. package/src/module-manager.ts +183 -139
  135. package/src/project-settings.ts +7 -0
  136. package/src/resources/array-handler.ts +7 -2
  137. package/src/resources/card-type-resource.ts +61 -46
  138. package/src/resources/create-defaults.ts +15 -12
  139. package/src/resources/field-type-resource.ts +2 -17
  140. package/src/resources/file-resource.ts +46 -8
  141. package/src/resources/folder-resource.ts +11 -10
  142. package/src/resources/report-resource.ts +19 -7
  143. package/src/resources/template-resource.ts +7 -6
  144. package/src/resources/workflow-resource.ts +155 -8
  145. package/src/types/queries.ts +11 -10
  146. package/src/utils/clingo-fact-builder.ts +8 -3
  147. package/src/utils/clingo-facts.ts +18 -12
  148. package/src/utils/constants.ts +20 -12
  149. package/src/utils/log-utils.ts +24 -45
  150. package/src/utils/report.ts +86 -0
  151. package/src/utils/resource-utils.ts +4 -0
  152. package/src/utils/sanitize-svg.ts +4 -9
  153. package/src/utils/validate.ts +3 -2
  154. package/dist/commands/export-site.d.ts +0 -45
  155. package/dist/commands/export-site.js +0 -301
  156. package/dist/commands/export-site.js.map +0 -1
  157. package/src/commands/export-site.ts +0 -356
@@ -1,301 +0,0 @@
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 '@cyberismo/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
@@ -1 +0,0 @@
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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C;QACD,IAAI,KAAK,CAAC,MAAM,GAAG,IAAI,IAAI,KAAK,CAAC,MAAM,GAAG,IAAI,EAAE,CAAC;YAC/C,OAAO,CAAC,IAAI,CACV,sBAAsB,KAAK,CAAC,MAAM,4FAA4F,CAC/H,CAAC;QACJ,CAAC;QAED,MAAM,IAAI,CAAC,MAAM,CAAC,WAAW,EAAE,KAAK,CAAC,CAAC;QACtC,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,IAAI,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;YACpC,MAAM,SAAS,GAAG,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;YAC9B,IAAI,SAAS,IAAI,SAAS,CAAC,GAAG,EAAE,CAAC;gBAC/B,IAAI,CAAC,gBAAgB,CAAC,WAAW,EAAE,SAAS,CAAC,GAAG,CAAC,CAAC;YACpD,CAAC;QACH,CAAC;QACD,OAAO,EAAE,CAAC;IACZ,CAAC;CACF"}
@@ -1,356 +0,0 @@
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
-
15
- // node
16
- import fs from 'node:fs';
17
- import { platform, tmpdir } from 'node:os';
18
- import { appendFile, copyFile, mkdir, writeFile } from 'node:fs/promises';
19
- import { mkdtempSync, writeFileSync } from 'node:fs';
20
- import { dirname, join, resolve } from 'node:path';
21
- import { spawnSync } from 'node:child_process';
22
- import { fileURLToPath } from 'node:url';
23
-
24
- import git from 'isomorphic-git';
25
- import { dump } from 'js-yaml';
26
-
27
- import { type Calculate, type Show } from './index.js';
28
- import { Export } from './export.js';
29
- import type { Card } from '../interfaces/project-interfaces.js';
30
- import type { CardType } from '../interfaces/resource-interfaces.js';
31
- import { errorFunction } from '../utils/log-utils.js';
32
- import type { Project } from '../containers/project.js';
33
- import { sortItems } from '../utils/lexorank.js';
34
- import { getStaticDirectoryPath } from '@cyberismo/resources';
35
-
36
- interface ExportOptions {
37
- silent: boolean;
38
- }
39
-
40
- export class ExportSite extends Export {
41
- private tmpDir: string = '';
42
- private moduleDir: string = '';
43
- private pagesDir: string = '';
44
- private imagesDir: string = '';
45
- private playbookDir: string = '';
46
- private playbookFile: string = '';
47
- private navFile: string = '';
48
- private options: ExportOptions | undefined;
49
-
50
- constructor(project: Project, calculateCmd: Calculate, showCmd: Show) {
51
- super(project, calculateCmd, showCmd);
52
- }
53
-
54
- // Writes index.html file into cards folder that just redirects to the first card.
55
- private createCardsIndex(destination: string, cardKey: string) {
56
- const indexFile = join(destination, 'cards', 'index.html');
57
- const indexContent = `<meta http-equiv="refresh" content="0; url=${cardKey}.html">`;
58
- try {
59
- fs.writeFileSync(indexFile, indexContent);
60
- } catch (error) {
61
- throw new Error(errorFunction(error));
62
- }
63
- }
64
-
65
- // todo: change this so that split temp folder creation to its own method.
66
- // then parallelize this and export() as much as you can.
67
- private async initDirectories() {
68
- // Create temporary adoc output directory
69
- try {
70
- this.tmpDir = mkdtempSync(join(tmpdir(), 'cards-'));
71
- } catch (error) {
72
- throw new Error(errorFunction(error));
73
- }
74
-
75
- // Antora requires the content directory to be a Git repository
76
- await this.initRepo();
77
-
78
- // Create the pages and images directories
79
- this.moduleDir = join(this.tmpDir, 'modules', 'ROOT');
80
- this.pagesDir = join(this.moduleDir, 'pages');
81
- this.imagesDir = join(this.moduleDir, 'assets', 'images');
82
- this.navFile = join(this.moduleDir, 'nav.adoc');
83
-
84
- const promiseContainer: Promise<string | undefined>[] = [];
85
- promiseContainer.push(mkdir(this.pagesDir, { recursive: true }));
86
- promiseContainer.push(mkdir(this.imagesDir, { recursive: true }));
87
- await Promise.all(promiseContainer);
88
-
89
- // Create the playbook directory
90
- this.playbookDir = mkdtempSync(join(tmpdir(), 'cards-playbook-'));
91
- }
92
-
93
- // Generate the site from the source files using Antora.
94
- private generate(outputPath: string) {
95
- const __filename = fileURLToPath(import.meta.url);
96
- const __dirname = dirname(__filename);
97
-
98
- const absoluteOutputPath = resolve(process.cwd(), outputPath);
99
-
100
- const additionalArguments = [
101
- '--to-dir',
102
- absoluteOutputPath,
103
- this.playbookFile,
104
- ];
105
- if (this.options && this.options?.silent) {
106
- additionalArguments.unshift('--silent');
107
- }
108
- // Use spawnsync to npx execute the program "antora"
109
- try {
110
- // Allthough we use pnpm as the package manager, we rather use npx at runtime, because it is shipped with node
111
- spawnSync('npx', ['antora', ...additionalArguments], {
112
- stdio: 'inherit',
113
- shell: platform() === 'win32',
114
- cwd: __dirname,
115
- });
116
- } catch (error) {
117
- throw new Error(errorFunction(error));
118
- }
119
- }
120
-
121
- // Create the Antora playbook.
122
- private async createPlaybook(cards: Card[]) {
123
- let startPage: string = '';
124
-
125
- if (cards[0]) {
126
- startPage = cards[0].key + '.adoc';
127
- } else {
128
- throw new Error('Cannot create a playbook for an empty card set');
129
- }
130
-
131
- const playbook = {
132
- site: {
133
- title: this.project.configuration.name,
134
- start_page: `cards:ROOT:${startPage}`,
135
- },
136
- content: {
137
- sources: [
138
- {
139
- url: this.tmpDir,
140
- branches: 'HEAD',
141
- },
142
- ],
143
- },
144
- urls: {
145
- html_extension_style: 'default',
146
- },
147
- ui: {
148
- bundle: {
149
- url: join(await getStaticDirectoryPath(), 'ui-bundle'),
150
- snapshot: true,
151
- },
152
- },
153
- };
154
-
155
- this.playbookFile = join(this.playbookDir, 'antora-playbook.yml');
156
- writeFileSync(this.playbookFile, dump(playbook));
157
- }
158
-
159
- // Create the Antora site descriptor.
160
- private createDescriptor() {
161
- const projectName = this.project.configuration.name;
162
- const descriptor = {
163
- name: 'cards',
164
- title: projectName,
165
- version: null,
166
- nav: ['modules/ROOT/nav.adoc'],
167
- };
168
-
169
- const descriptorPath = join(this.tmpDir, 'antora.yml');
170
- try {
171
- writeFileSync(descriptorPath, dump(descriptor));
172
- } catch (error) {
173
- throw new Error(errorFunction(error));
174
- }
175
- }
176
-
177
- // Initialise the temporary directory as a temporary Git repository.
178
- private async initRepo() {
179
- try {
180
- await git.init({ fs, dir: this.tmpDir });
181
- writeFileSync(join(this.tmpDir, '.gitkeep'), '');
182
- await git.add({ fs, dir: this.tmpDir, filepath: '.gitkeep' });
183
- } catch (error) {
184
- throw new Error(errorFunction(error));
185
- }
186
-
187
- try {
188
- await git.commit({
189
- fs,
190
- dir: this.tmpDir,
191
- author: {
192
- name: 'Cyberismo Cards',
193
- email: 'info@cyberismo.com',
194
- },
195
- message: 'Add .gitkeep',
196
- });
197
- } catch (error) {
198
- throw new Error(errorFunction(error));
199
- }
200
- }
201
-
202
- // Write cards as Antora-compatible AsciiDoc to the given location
203
- // @param path Directory where the cards should be written
204
- // @param cards Array of Cards
205
- // @param depth Navigation depth - this is used in recursion to format the hierarchical menu
206
- private async toAdocDirectoryAsContent(
207
- path: string,
208
- cards: Card[],
209
- depth: number,
210
- ) {
211
- depth++;
212
-
213
- // Sort the cards by rank
214
- cards = sortItems(cards, function (card) {
215
- return card.metadata?.rank || '1|z';
216
- });
217
-
218
- // Ensure the target path exists
219
- await mkdir(path, { recursive: true });
220
- for (const card of cards) {
221
- // Construct path for individual card file
222
- const cardPath = join(path, card.key + '.adoc');
223
- const cardXRef = cardPath.slice(this.pagesDir.length);
224
- let navFileContent = '';
225
- if (card.metadata?.progress) {
226
- navFileContent =
227
- '*'.repeat(depth) +
228
- ` xref:${cardXRef}[${card.metadata?.title} (${card.metadata?.progress}%)]\n`;
229
- } else {
230
- navFileContent =
231
- '*'.repeat(depth) + ` xref:${cardXRef}[${card.metadata?.title}]\n`;
232
- }
233
-
234
- await appendFile(this.navFile, navFileContent);
235
-
236
- let tempContent: string = '';
237
- if (card.metadata) {
238
- const cardTypeForCard = await this.project.resource<CardType>(
239
- card.metadata?.cardType,
240
- );
241
- tempContent = '\n= ';
242
- tempContent += card.metadata?.title
243
- ? `${card.metadata.title}\n\n`
244
- : 'Untitled\n\n';
245
- tempContent += super.metaToAdoc(card, cardTypeForCard);
246
- }
247
-
248
- if (card.content) {
249
- tempContent += '\n' + card.content;
250
- }
251
- if (tempContent !== '') {
252
- await writeFile(cardPath, tempContent);
253
- }
254
-
255
- if (card.children && card.children.length > 0) {
256
- // Recurse into the child cards
257
- await this.toAdocDirectoryAsContent(path, card.children, depth);
258
- }
259
-
260
- if (card.attachments) {
261
- const promiseContainer = [];
262
- for (const attachment of card.attachments) {
263
- const source = join(attachment.path, attachment.fileName);
264
- const destination = join(this.imagesDir, `${attachment.fileName}`);
265
- promiseContainer.push(copyFile(source, destination));
266
- }
267
- await Promise.all(promiseContainer);
268
- }
269
- }
270
-
271
- --depth;
272
- }
273
-
274
- // Export the cards to the temporary directory as a full HTML site generated by Antora.
275
- private async export(destination: string, cards: Card[]) {
276
- await this.initDirectories();
277
- this.createDescriptor();
278
- await this.toAdocDirectoryAsContent(this.pagesDir, cards, 0);
279
- await this.createPlaybook(cards);
280
- this.generate(destination);
281
- }
282
-
283
- /**
284
- * Export the card tree as an Antora site
285
- * @param destination Path where the site is generated
286
- * @param cardKey Optional; If defined exports the card tree from underneath this card.
287
- */
288
- public async exportToSite(
289
- destination: string,
290
- cardKey?: string,
291
- options?: ExportOptions,
292
- ): Promise<string> {
293
- this.options = options;
294
- const sourcePath: string = cardKey
295
- ? join(
296
- this.project.paths.cardRootFolder,
297
- this.project.pathToCard(cardKey),
298
- )
299
- : this.project.paths.cardRootFolder;
300
- let cards: Card[] = [];
301
-
302
- // If doing a partial tree export, put the parent information as it would have already been gathered.
303
- if (cardKey) {
304
- const card = await this.project.findSpecificCard(cardKey);
305
- if (!card) {
306
- throw new Error(
307
- `Input validation error: cannot find card '${cardKey}'`,
308
- );
309
- }
310
- cards.push({
311
- key: cardKey,
312
- path: sourcePath,
313
- children: [],
314
- attachments: [],
315
- });
316
- }
317
-
318
- await this.calculateCmd.generate();
319
- const tree = await this.calculateCmd.runQuery('tree');
320
-
321
- if (cardKey) {
322
- const targetCard = this.findCardInTree(tree, cardKey);
323
- if (!targetCard) {
324
- throw new Error(`Cannot find card '${cardKey}' in the tree hierarchy`);
325
- }
326
- cards = [await this.treeQueryResultToCard(targetCard)];
327
- } else {
328
- for (const treeQueryResult of tree) {
329
- cards.push(await this.treeQueryResultToCard(treeQueryResult));
330
- }
331
- }
332
-
333
- if (!cards.length) {
334
- throw new Error('No cards found');
335
- }
336
- if (cards.length > 3000) {
337
- throw new Error(
338
- `There are ${cards.length} cards in the project. Exporting to a site only supports maximum of 3000 cards.`,
339
- );
340
- }
341
- if (cards.length > 1000 && cards.length < 3000) {
342
- console.warn(
343
- `Warning: There are ${cards.length} cards in the project. There is a hard limit of 3000 cards that can be exported as a site.`,
344
- );
345
- }
346
-
347
- await this.export(destination, cards);
348
- if (cards.length > 0 && cards.at(0)) {
349
- const firstCard = cards.at(0);
350
- if (firstCard && firstCard.key) {
351
- this.createCardsIndex(destination, firstCard.key);
352
- }
353
- }
354
- return '';
355
- }
356
- }