@cyberismo/data-handler 0.0.7 → 0.0.9

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 (265) hide show
  1. package/dist/command-handler.d.ts +11 -2
  2. package/dist/command-handler.js +61 -18
  3. package/dist/command-handler.js.map +1 -1
  4. package/dist/command-manager.js +8 -8
  5. package/dist/command-manager.js.map +1 -1
  6. package/dist/commands/calculate.d.ts +7 -44
  7. package/dist/commands/calculate.js +8 -389
  8. package/dist/commands/calculate.js.map +1 -1
  9. package/dist/commands/create.d.ts +7 -4
  10. package/dist/commands/create.js +42 -15
  11. package/dist/commands/create.js.map +1 -1
  12. package/dist/commands/edit.d.ts +9 -3
  13. package/dist/commands/edit.js +33 -9
  14. package/dist/commands/edit.js.map +1 -1
  15. package/dist/commands/export.d.ts +13 -11
  16. package/dist/commands/export.js +80 -28
  17. package/dist/commands/export.js.map +1 -1
  18. package/dist/commands/import.d.ts +7 -0
  19. package/dist/commands/import.js +21 -2
  20. package/dist/commands/import.js.map +1 -1
  21. package/dist/commands/move.d.ts +11 -12
  22. package/dist/commands/move.js +12 -13
  23. package/dist/commands/move.js.map +1 -1
  24. package/dist/commands/remove.d.ts +2 -4
  25. package/dist/commands/remove.js +8 -16
  26. package/dist/commands/remove.js.map +1 -1
  27. package/dist/commands/rename.d.ts +1 -3
  28. package/dist/commands/rename.js +3 -6
  29. package/dist/commands/rename.js.map +1 -1
  30. package/dist/commands/show.d.ts +37 -5
  31. package/dist/commands/show.js +85 -7
  32. package/dist/commands/show.js.map +1 -1
  33. package/dist/commands/transition.d.ts +1 -3
  34. package/dist/commands/transition.js +3 -5
  35. package/dist/commands/transition.js.map +1 -1
  36. package/dist/commands/update.d.ts +5 -1
  37. package/dist/commands/update.js +7 -1
  38. package/dist/commands/update.js.map +1 -1
  39. package/dist/commands/validate.d.ts +7 -8
  40. package/dist/commands/validate.js +30 -35
  41. package/dist/commands/validate.js.map +1 -1
  42. package/dist/containers/card-container.d.ts +6 -0
  43. package/dist/containers/card-container.js +61 -0
  44. package/dist/containers/card-container.js.map +1 -1
  45. package/dist/containers/project/calculation-engine.d.ts +90 -0
  46. package/dist/containers/project/calculation-engine.js +402 -0
  47. package/dist/containers/project/calculation-engine.js.map +1 -0
  48. package/dist/containers/project/resource-collector.d.ts +2 -1
  49. package/dist/containers/project/resource-collector.js +41 -33
  50. package/dist/containers/project/resource-collector.js.map +1 -1
  51. package/dist/containers/project.d.ts +18 -6
  52. package/dist/containers/project.js +37 -72
  53. package/dist/containers/project.js.map +1 -1
  54. package/dist/containers/template.d.ts +5 -0
  55. package/dist/containers/template.js +9 -0
  56. package/dist/containers/template.js.map +1 -1
  57. package/dist/exceptions/index.d.ts +20 -0
  58. package/dist/exceptions/index.js +16 -0
  59. package/dist/exceptions/index.js.map +1 -1
  60. package/dist/index.d.ts +5 -2
  61. package/dist/index.js +5 -1
  62. package/dist/index.js.map +1 -1
  63. package/dist/interfaces/macros.d.ts +7 -2
  64. package/dist/interfaces/project-interfaces.d.ts +21 -0
  65. package/dist/interfaces/project-interfaces.js +4 -0
  66. package/dist/interfaces/project-interfaces.js.map +1 -1
  67. package/dist/interfaces/resource-interfaces.d.ts +1 -1
  68. package/dist/interfaces/resource-interfaces.js.map +1 -1
  69. package/dist/macros/base-macro.d.ts +2 -0
  70. package/dist/macros/base-macro.js +66 -19
  71. package/dist/macros/base-macro.js.map +1 -1
  72. package/dist/macros/common.d.ts +16 -9
  73. package/dist/macros/common.js +22 -9
  74. package/dist/macros/common.js.map +1 -1
  75. package/dist/macros/createCards/index.d.ts +1 -2
  76. package/dist/macros/createCards/index.js.map +1 -1
  77. package/dist/macros/graph/index.d.ts +1 -3
  78. package/dist/macros/graph/index.js +11 -9
  79. package/dist/macros/graph/index.js.map +1 -1
  80. package/dist/macros/image/index.d.ts +39 -0
  81. package/dist/macros/image/index.js +78 -0
  82. package/dist/macros/image/index.js.map +1 -0
  83. package/dist/macros/image/metadata.d.ts +18 -0
  84. package/dist/macros/image/metadata.js +22 -0
  85. package/dist/macros/image/metadata.js.map +1 -0
  86. package/dist/macros/include/index.d.ts +32 -0
  87. package/dist/macros/include/index.js +97 -0
  88. package/dist/macros/include/index.js.map +1 -0
  89. package/dist/macros/include/metadata.d.ts +15 -0
  90. package/dist/macros/include/metadata.js +19 -0
  91. package/dist/macros/include/metadata.js.map +1 -0
  92. package/dist/macros/index.d.ts +39 -31
  93. package/dist/macros/index.js +167 -73
  94. package/dist/macros/index.js.map +1 -1
  95. package/dist/macros/percentage/index.d.ts +29 -0
  96. package/dist/macros/percentage/index.js +36 -0
  97. package/dist/macros/percentage/index.js.map +1 -0
  98. package/dist/macros/percentage/metadata.d.ts +15 -0
  99. package/dist/macros/percentage/metadata.js +19 -0
  100. package/dist/macros/percentage/metadata.js.map +1 -0
  101. package/dist/macros/report/index.d.ts +2 -5
  102. package/dist/macros/report/index.js +20 -12
  103. package/dist/macros/report/index.js.map +1 -1
  104. package/dist/macros/scoreCard/index.d.ts +15 -15
  105. package/dist/macros/scoreCard/index.js +16 -17
  106. package/dist/macros/scoreCard/index.js.map +1 -1
  107. package/dist/macros/vega/index.d.ts +28 -0
  108. package/dist/macros/vega/index.js +27 -0
  109. package/dist/macros/vega/index.js.map +1 -0
  110. package/dist/macros/vega/metadata.d.ts +15 -0
  111. package/dist/macros/vega/metadata.js +7 -0
  112. package/dist/macros/vega/metadata.js.map +1 -0
  113. package/dist/macros/vegalite/index.d.ts +27 -0
  114. package/dist/macros/vegalite/index.js +27 -0
  115. package/dist/macros/vegalite/index.js.map +1 -0
  116. package/dist/macros/vegalite/metadata.d.ts +15 -0
  117. package/dist/macros/vegalite/metadata.js +7 -0
  118. package/dist/macros/vegalite/metadata.js.map +1 -0
  119. package/dist/macros/xref/index.d.ts +26 -0
  120. package/dist/macros/xref/index.js +53 -0
  121. package/dist/macros/xref/index.js.map +1 -0
  122. package/dist/macros/xref/metadata.d.ts +15 -0
  123. package/dist/macros/xref/metadata.js +19 -0
  124. package/dist/macros/xref/metadata.js.map +1 -0
  125. package/dist/module-manager.d.ts +17 -4
  126. package/dist/module-manager.js +192 -58
  127. package/dist/module-manager.js.map +1 -1
  128. package/dist/permissions/action-guard.d.ts +2 -2
  129. package/dist/permissions/action-guard.js +1 -1
  130. package/dist/permissions/action-guard.js.map +1 -1
  131. package/dist/project-settings.js +2 -8
  132. package/dist/project-settings.js.map +1 -1
  133. package/dist/resources/card-type-resource.d.ts +2 -0
  134. package/dist/resources/card-type-resource.js +63 -0
  135. package/dist/resources/card-type-resource.js.map +1 -1
  136. package/dist/resources/file-resource.d.ts +2 -0
  137. package/dist/resources/file-resource.js +12 -4
  138. package/dist/resources/file-resource.js.map +1 -1
  139. package/dist/resources/folder-resource.d.ts +19 -0
  140. package/dist/resources/folder-resource.js +51 -2
  141. package/dist/resources/folder-resource.js.map +1 -1
  142. package/dist/resources/graph-model-resource.js +1 -1
  143. package/dist/resources/graph-model-resource.js.map +1 -1
  144. package/dist/resources/graph-view-resource.js +1 -1
  145. package/dist/resources/graph-view-resource.js.map +1 -1
  146. package/dist/resources/report-resource.js +1 -1
  147. package/dist/resources/report-resource.js.map +1 -1
  148. package/dist/resources/resource-object.d.ts +8 -0
  149. package/dist/resources/resource-object.js +9 -0
  150. package/dist/resources/resource-object.js.map +1 -1
  151. package/dist/resources/template-resource.js +1 -1
  152. package/dist/resources/template-resource.js.map +1 -1
  153. package/dist/resources/workflow-resource.d.ts +2 -0
  154. package/dist/resources/workflow-resource.js +53 -9
  155. package/dist/resources/workflow-resource.js.map +1 -1
  156. package/dist/svg/index.d.ts +15 -0
  157. package/dist/svg/index.js +16 -0
  158. package/dist/svg/index.js.map +1 -0
  159. package/dist/svg/lib.d.ts +9 -0
  160. package/dist/svg/lib.js +26 -0
  161. package/dist/svg/lib.js.map +1 -0
  162. package/dist/svg/percentage.d.ts +25 -0
  163. package/dist/svg/percentage.js +90 -0
  164. package/dist/svg/percentage.js.map +1 -0
  165. package/dist/svg/scoreCard.d.ts +19 -0
  166. package/dist/svg/scoreCard.js +55 -0
  167. package/dist/svg/scoreCard.js.map +1 -0
  168. package/dist/types/queries.d.ts +8 -7
  169. package/dist/types/queries.js.map +1 -1
  170. package/dist/utils/card-utils.d.ts +6 -0
  171. package/dist/utils/card-utils.js +12 -0
  172. package/dist/utils/card-utils.js.map +1 -1
  173. package/dist/utils/clingo-facts.d.ts +2 -1
  174. package/dist/utils/clingo-facts.js +19 -2
  175. package/dist/utils/clingo-facts.js.map +1 -1
  176. package/dist/utils/clingo-parser.d.ts +1 -0
  177. package/dist/utils/clingo-parser.js +22 -100
  178. package/dist/utils/clingo-parser.js.map +1 -1
  179. package/dist/utils/constants.d.ts +7 -0
  180. package/dist/utils/constants.js +14 -0
  181. package/dist/utils/constants.js.map +1 -1
  182. package/dist/utils/csv.js.map +1 -1
  183. package/dist/utils/report.d.ts +17 -3
  184. package/dist/utils/report.js +38 -2
  185. package/dist/utils/report.js.map +1 -1
  186. package/dist/utils/resource-utils.d.ts +1 -0
  187. package/dist/utils/resource-utils.js +9 -0
  188. package/dist/utils/resource-utils.js.map +1 -1
  189. package/dist/utils/user-preferences.d.ts +1 -11
  190. package/dist/utils/user-preferences.js +30 -13
  191. package/dist/utils/user-preferences.js.map +1 -1
  192. package/dist/utils/validate.d.ts +2 -3
  193. package/dist/utils/validate.js +2 -2
  194. package/dist/utils/validate.js.map +1 -1
  195. package/package.json +8 -6
  196. package/src/command-handler.ts +96 -17
  197. package/src/command-manager.ts +8 -8
  198. package/src/commands/calculate.ts +11 -525
  199. package/src/commands/create.ts +53 -16
  200. package/src/commands/edit.ts +53 -11
  201. package/src/commands/export.ts +108 -34
  202. package/src/commands/import.ts +31 -2
  203. package/src/commands/move.ts +12 -15
  204. package/src/commands/remove.ts +10 -19
  205. package/src/commands/rename.ts +3 -12
  206. package/src/commands/show.ts +121 -8
  207. package/src/commands/transition.ts +3 -7
  208. package/src/commands/update.ts +6 -0
  209. package/src/commands/validate.ts +39 -47
  210. package/src/containers/card-container.ts +74 -0
  211. package/src/containers/project/calculation-engine.ts +535 -0
  212. package/src/containers/project/resource-collector.ts +45 -26
  213. package/src/containers/project.ts +66 -84
  214. package/src/containers/template.ts +16 -0
  215. package/src/exceptions/index.ts +36 -0
  216. package/src/index.ts +13 -2
  217. package/src/interfaces/macros.ts +7 -1
  218. package/src/interfaces/project-interfaces.ts +27 -0
  219. package/src/interfaces/resource-interfaces.ts +1 -0
  220. package/src/macros/base-macro.ts +89 -25
  221. package/src/macros/common.ts +22 -9
  222. package/src/macros/createCards/index.ts +1 -2
  223. package/src/macros/graph/index.ts +17 -12
  224. package/src/macros/image/index.ts +121 -0
  225. package/src/macros/image/metadata.ts +25 -0
  226. package/src/macros/include/index.ts +147 -0
  227. package/src/macros/include/metadata.ts +22 -0
  228. package/src/macros/index.ts +179 -100
  229. package/src/macros/percentage/index.ts +54 -0
  230. package/src/macros/percentage/metadata.ts +22 -0
  231. package/src/macros/report/index.ts +22 -17
  232. package/src/macros/scoreCard/index.ts +23 -23
  233. package/src/macros/vega/index.ts +55 -0
  234. package/src/macros/vega/metadata.ts +21 -0
  235. package/src/macros/vegalite/index.ts +50 -0
  236. package/src/macros/vegalite/metadata.ts +21 -0
  237. package/src/macros/xref/index.ts +73 -0
  238. package/src/macros/xref/metadata.ts +22 -0
  239. package/src/module-manager.ts +241 -69
  240. package/src/permissions/action-guard.ts +3 -3
  241. package/src/project-settings.ts +2 -11
  242. package/src/resources/card-type-resource.ts +100 -0
  243. package/src/resources/file-resource.ts +16 -4
  244. package/src/resources/folder-resource.ts +59 -2
  245. package/src/resources/graph-model-resource.ts +1 -1
  246. package/src/resources/graph-view-resource.ts +1 -1
  247. package/src/resources/report-resource.ts +1 -1
  248. package/src/resources/resource-object.ts +14 -0
  249. package/src/resources/template-resource.ts +1 -1
  250. package/src/resources/workflow-resource.ts +68 -13
  251. package/src/svg/index.ts +15 -0
  252. package/src/svg/lib.ts +31 -0
  253. package/src/svg/percentage.ts +97 -0
  254. package/src/svg/scoreCard.ts +88 -0
  255. package/src/types/queries.ts +8 -7
  256. package/src/types/string-pixel-width.d.ts +23 -0
  257. package/src/utils/card-utils.ts +13 -0
  258. package/src/utils/clingo-facts.ts +65 -3
  259. package/src/utils/clingo-parser.ts +31 -144
  260. package/src/utils/constants.ts +16 -0
  261. package/src/utils/csv.ts +1 -1
  262. package/src/utils/report.ts +45 -4
  263. package/src/utils/resource-utils.ts +9 -0
  264. package/src/utils/user-preferences.ts +32 -14
  265. package/src/utils/validate.ts +3 -3
@@ -16,18 +16,23 @@ import { homedir } from 'node:os';
16
16
  import { spawnSync } from 'node:child_process';
17
17
 
18
18
  import { ActionGuard } from '../permissions/action-guard.js';
19
- import type { Calculate } from './index.js';
20
- import type { MetadataContent } from '../interfaces/project-interfaces.js';
19
+ import type {
20
+ MetadataContent,
21
+ ResourceFolderType,
22
+ } from '../interfaces/project-interfaces.js';
21
23
  import { Project } from '../containers/project.js';
22
24
  import { UserPreferences } from '../utils/user-preferences.js';
25
+ import {
26
+ type ResourceName,
27
+ resourceNameToString,
28
+ } from '../utils/resource-utils.js';
29
+ import { FolderResource } from '../resources/folder-resource.js';
23
30
 
24
31
  export class Edit {
25
32
  private project: Project;
26
- private calculateCmd: Calculate;
27
33
 
28
- constructor(project: Project, calculateCmd: Calculate) {
34
+ constructor(project: Project) {
29
35
  this.project = project;
30
- this.calculateCmd = calculateCmd;
31
36
  }
32
37
 
33
38
  /**
@@ -83,13 +88,16 @@ export class Edit {
83
88
  * @param changedContent New content for the card.
84
89
  */
85
90
  public async editCardContent(cardKey: string, changedContent: string) {
86
- // Determine the card path
91
+ const isTemplateCard = await this.project.isTemplateCard(cardKey);
92
+ if (isTemplateCard) {
93
+ return this.project.updateCardContent(cardKey, changedContent);
94
+ }
87
95
  const cardPath = this.project.pathToCard(cardKey);
88
96
  if (!cardPath) {
89
97
  throw new Error(`Card '${cardKey}' does not exist in the project`);
90
98
  }
91
99
 
92
- const actionGuard = new ActionGuard(this.calculateCmd);
100
+ const actionGuard = new ActionGuard(this.project.calculationEngine);
93
101
  await actionGuard.checkPermission('editContent', cardKey);
94
102
 
95
103
  await this.project.updateCardContent(cardKey, changedContent);
@@ -106,18 +114,52 @@ export class Edit {
106
114
  changedKey: string,
107
115
  newValue: MetadataContent,
108
116
  ) {
117
+ if (!changedKey) {
118
+ throw new Error(`Changed key cannot be empty`);
119
+ }
120
+ const isTemplateCard = await this.project.isTemplateCard(cardKey);
121
+ if (isTemplateCard) {
122
+ return this.project.updateCardMetadataKey(cardKey, changedKey, newValue);
123
+ }
124
+
109
125
  // Determine the card path
110
126
  const cardPath = this.project.pathToCard(cardKey);
111
127
  if (!cardPath) {
112
128
  throw new Error(`Card '${cardKey}' does not exist in the project`);
113
129
  }
114
- if (!changedKey) {
115
- throw new Error(`Changed key cannot be empty`);
116
- }
117
130
 
118
131
  // check for editing rights
119
- const actionGuard = new ActionGuard(this.calculateCmd);
132
+ const actionGuard = new ActionGuard(this.project.calculationEngine);
120
133
  await actionGuard.checkPermission('editField', cardKey, changedKey);
121
134
  await this.project.updateCardMetadataKey(cardKey, changedKey, newValue);
122
135
  }
136
+
137
+ /**
138
+ * Update a file of a folder resource. Cannot be used to create a new file.
139
+ * @param resourceName The name of the resource to update.
140
+ * @param fileName The name of the file to update.
141
+ * @param changedContent The new content for the file.
142
+ */
143
+ public async editResourceContent(
144
+ resourceName: ResourceName,
145
+ fileName: string,
146
+ changedContent: string,
147
+ ) {
148
+ const resourceNameStr = resourceNameToString(resourceName);
149
+ if (
150
+ !(await this.project.resourceExists(
151
+ resourceName.type as ResourceFolderType,
152
+ resourceNameStr,
153
+ ))
154
+ ) {
155
+ throw new Error(
156
+ `Resource '${resourceNameStr}' does not exist in the project`,
157
+ );
158
+ }
159
+ const resource = Project.resourceObject(this.project, resourceName);
160
+ if (!(resource instanceof FolderResource)) {
161
+ throw new Error(`Resource '${resourceNameStr}' is not a folder resource`);
162
+ }
163
+ return resource.updateFile(fileName, changedContent);
164
+ }
123
165
  }
@@ -13,27 +13,36 @@
13
13
  */
14
14
 
15
15
  // node
16
- import { appendFile, copyFile, mkdir, truncate } from 'node:fs/promises';
16
+ import {
17
+ appendFile,
18
+ copyFile,
19
+ mkdir,
20
+ truncate,
21
+ writeFile,
22
+ } from 'node:fs/promises';
17
23
  import { dirname, join } from 'node:path';
18
24
 
19
- // asciidoctor
20
- import Processor from '@asciidoctor/core';
21
- import type { Calculate, Show } from './index.js';
25
+ import { Project } from '../containers/project.js';
26
+ import { sortItems } from '../utils/lexorank.js';
27
+
22
28
  import type {
23
29
  Card,
24
30
  FetchCardDetails,
25
31
  } from '../interfaces/project-interfaces.js';
26
- import type { CardType } from '../interfaces/resource-interfaces.js';
27
- import { Project } from '../containers/project.js';
28
32
  import type { QueryResult } from '../types/queries.js';
29
- import { sortItems } from '../utils/lexorank.js';
33
+ import type { CardType } from '../interfaces/resource-interfaces.js';
34
+ import type { Show } from './index.js';
35
+ import { generateReportContent } from '../utils/report.js';
36
+ import { getStaticDirectoryPath, pdfReport } from '@cyberismo/assets';
37
+ import { spawn } from 'node:child_process';
38
+ import { evaluateMacros } from '../macros/index.js';
39
+ import type { ExportPdfOptions } from '../interfaces/project-interfaces.js';
30
40
 
31
41
  const attachmentFolder: string = 'a';
32
42
 
33
43
  export class Export {
34
44
  constructor(
35
45
  protected project: Project,
36
- protected calculateCmd: Calculate,
37
46
  protected showCmd: Show,
38
47
  ) {}
39
48
 
@@ -202,11 +211,11 @@ export class Export {
202
211
  asciiDocContent = await evaluateMacros(
203
212
  cardDetailsResponse.content || '',
204
213
  {
214
+ context: 'exportedDocument',
205
215
  mode: 'static',
206
216
  project,
207
217
  cardKey: card.key,
208
218
  },
209
- this.calculateCmd,
210
219
  );
211
220
  } catch (error) {
212
221
  asciiDocContent = `Macro error: ${error instanceof Error ? error.message : 'Unknown error'}\n\n${asciiDocContent}`;
@@ -225,6 +234,91 @@ export class Export {
225
234
  return card;
226
235
  }
227
236
 
237
+ private async runAsciidoctorPdf(content: string): Promise<Buffer> {
238
+ const staticRootDir = await getStaticDirectoryPath();
239
+ const proc = spawn(
240
+ 'asciidoctor-pdf',
241
+ [
242
+ '-a',
243
+ 'pdf-theme=cyberismo',
244
+ '-a',
245
+ `pdf-themesdir=${join(staticRootDir, 'pdf-themes')}`,
246
+ '-a',
247
+ `pdf-fontsdir=${join(staticRootDir, 'pdf-themes', 'fonts')};GEM_FONTS_DIR`,
248
+ '-',
249
+ ],
250
+ {
251
+ timeout: 100000,
252
+ shell: process.platform === 'win32',
253
+ },
254
+ );
255
+ proc.stdin.end(content);
256
+ const result = await new Promise<Buffer>((resolve, reject) => {
257
+ const chunks: Buffer[] = [];
258
+ proc.stdout.on('data', (chunk) => {
259
+ chunks.push(chunk);
260
+ });
261
+ proc.stderr.on('data', (chunk) => {
262
+ process.stderr.write(chunk);
263
+ });
264
+ proc.on('error', (error) => {
265
+ if ('code' in error && error.code === 'ENOENT') {
266
+ reject(
267
+ new Error(
268
+ 'Asciidoctor-pdf not found. Please install asciidoctor-pdf to use this feature.',
269
+ ),
270
+ );
271
+ }
272
+ reject(error);
273
+ });
274
+ proc.on('close', (code) => {
275
+ if (code === 0) {
276
+ resolve(Buffer.concat(chunks));
277
+ } else {
278
+ reject(new Error(`Asciidoctor-pdf failed with code ${code}`));
279
+ }
280
+ });
281
+ });
282
+ return result;
283
+ }
284
+
285
+ /**
286
+ * Exports the card(s) to pdf.
287
+ * @param destination Path to where the resulting file(s) will be created.
288
+ * @param options Export options.
289
+ * @returns status message
290
+ */
291
+ public async exportPdf(
292
+ destination: string,
293
+ options: ExportPdfOptions,
294
+ ): Promise<string> {
295
+ const opts = {
296
+ ...options,
297
+ date: options.date?.toISOString().split('T')[0],
298
+ recursive: options.recursive ?? false,
299
+ };
300
+
301
+ await this.project.calculationEngine.generate();
302
+
303
+ const result = await generateReportContent({
304
+ calculate: this.project.calculationEngine,
305
+ contentTemplate: pdfReport.content,
306
+ queryTemplate: pdfReport.query,
307
+ context: 'exportedDocument',
308
+ options: opts,
309
+ });
310
+
311
+ const evaluated = await evaluateMacros(result, {
312
+ context: 'exportedDocument',
313
+ mode: 'static',
314
+ project: this.project,
315
+ cardKey: '', // top level report does not contain any macros that use cardKey
316
+ });
317
+ const pdf = await this.runAsciidoctorPdf(evaluated);
318
+ await writeFile(destination, pdf);
319
+ return `Content exported as PDF to ${destination}`;
320
+ }
321
+
228
322
  /**
229
323
  * Exports the card(s) to ascii doc.
230
324
  * @param destination Path to where the resulting file(s) will be created.
@@ -254,8 +348,11 @@ export class Export {
254
348
  });
255
349
  }
256
350
 
257
- await this.calculateCmd.generate();
258
- const tree = await this.calculateCmd.runQuery('tree');
351
+ await this.project.calculationEngine.generate();
352
+ const tree = await this.project.calculationEngine.runQuery(
353
+ 'tree',
354
+ 'exportedDocument',
355
+ );
259
356
 
260
357
  if (cardKey) {
261
358
  const targetCard = this.findCardInTree(tree, cardKey);
@@ -290,27 +387,4 @@ export class Export {
290
387
  await this.toAdocFile(resultDocumentPath, cards);
291
388
  return message;
292
389
  }
293
-
294
- /**
295
- * Exports the card(s) to HTML and opens the browser.
296
- * @param destination Path to where the resulting file(s) will be created.
297
- * @param cardKey Optional; If not exporting the whole card tree, card key of parent card.
298
- */
299
- public async exportToHTML(
300
- destination: string,
301
- cardKey?: string,
302
- ): Promise<string> {
303
- let message = '';
304
- await this.exportToADoc(destination, cardKey).then((msg) => {
305
- message = msg;
306
- const asciiDocProcessor = Processor();
307
- const adocFile = join(destination, Project.cardContentFile);
308
- asciiDocProcessor.convertFile(adocFile, {
309
- safe: 'safe',
310
- base_dir: '/',
311
- standalone: true,
312
- });
313
- });
314
- return message;
315
- }
316
390
  }
@@ -134,7 +134,10 @@ export class Import {
134
134
  destination?: string,
135
135
  options?: ModuleSettingOptions,
136
136
  ) {
137
- const gitModule = source.startsWith('https');
137
+ const beforeImportValidateErrors = await Validate.getInstance().validate(
138
+ this.project.basePath,
139
+ );
140
+ const gitModule = source.startsWith('https') || source.startsWith('git@');
138
141
  const modulePrefix = gitModule
139
142
  ? await this.moduleManager.importGitModule(source, options)
140
143
  : await this.moduleManager.importFileModule(source, destination);
@@ -156,7 +159,33 @@ export class Import {
156
159
  await this.moduleManager.updateModule(moduleSettings, options?.credentials);
157
160
 
158
161
  // Add module as a dependency.
159
- return this.project.importModule(moduleSettings);
162
+ await this.project.importModule(moduleSettings);
163
+
164
+ // Validate the project after module has been imported
165
+ const afterImportValidateErrors = await Validate.getInstance().validate(
166
+ this.project.basePath,
167
+ );
168
+ if (afterImportValidateErrors.length > beforeImportValidateErrors.length) {
169
+ console.error(
170
+ `There are new validations errors after importing the module. Check the project`,
171
+ );
172
+ }
173
+ }
174
+
175
+ /**
176
+ * Updates a specific imported module.
177
+ * @param moduleName Name (prefix) of module to update.
178
+ * @param credentials Optional credentials for a private module.
179
+ * @throws if module is not part of the project
180
+ */
181
+ public async updateModule(moduleName: string, credentials?: Credentials) {
182
+ const module = this.project.configuration.modules.find(
183
+ (item) => item.name === moduleName,
184
+ );
185
+ if (!module) {
186
+ throw new Error(`Module '${moduleName}' is not part of the project`);
187
+ }
188
+ return this.moduleManager.updateModule(module, credentials);
160
189
  }
161
190
 
162
191
  /**
@@ -1,13 +1,14 @@
1
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 the terms of the GNU Affero General Public License version 3 as published by the Free Software Foundation.
6
-
7
- This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
8
-
9
- You should have received a copy of the GNU Affero General Public
10
- License along with this program. If not, see <https://www.gnu.org/licenses/>.
2
+ Cyberismo
3
+ Copyright © Cyberismo Ltd and contributors 2024
4
+ This program is free software: you can redistribute it and/or modify it under
5
+ the terms of the GNU Affero General Public License version 3 as published by
6
+ the Free Software Foundation.
7
+ This program is distributed in the hope that it will be useful, but WITHOUT
8
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
9
+ FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
10
+ details. You should have received a copy of the GNU Affero General Public
11
+ License along with this program. If not, see <https://www.gnu.org/licenses/>.
11
12
  */
12
13
 
13
14
  // node
@@ -15,7 +16,6 @@ import { join, sep } from 'node:path';
15
16
 
16
17
  import { ActionGuard } from '../permissions/action-guard.js';
17
18
  import { copyDir, deleteDir } from '../utils/file-utils.js';
18
- import type { Calculate } from './index.js';
19
19
  import type {
20
20
  Card,
21
21
  FetchCardDetails,
@@ -37,10 +37,7 @@ import { TemplateResource } from '../resources/template-resource.js';
37
37
  const ROOT: string = 'root';
38
38
 
39
39
  export class Move {
40
- constructor(
41
- private project: Project,
42
- private calculateCmd: Calculate,
43
- ) {}
40
+ constructor(private project: Project) {}
44
41
 
45
42
  // Fetches a card (either template or project card).
46
43
  private async getCard(cardKey: string, options: FetchCardDetails) {
@@ -192,7 +189,7 @@ export class Move {
192
189
  }
193
190
 
194
191
  // if both are project cards, make sure source card can be moved
195
- const actionGuard = new ActionGuard(this.calculateCmd);
192
+ const actionGuard = new ActionGuard(this.project.calculationEngine);
196
193
  await actionGuard.checkPermission('move', source);
197
194
 
198
195
  // rerank the card in the new location
@@ -15,8 +15,8 @@
15
15
  import { join, sep } from 'node:path';
16
16
 
17
17
  import { ActionGuard } from '../permissions/action-guard.js';
18
- import type { Calculate } from './index.js';
19
18
  import { deleteDir, deleteFile } from '../utils/file-utils.js';
19
+ import { ModuleManager } from '../module-manager.js';
20
20
  import { Project } from '../containers/project.js';
21
21
  import type { RemovableResourceTypes } from '../interfaces/project-interfaces.js';
22
22
  import { resourceName } from '../utils/resource-utils.js';
@@ -27,10 +27,10 @@ const MODULES_PATH = `${sep}modules${sep}`;
27
27
  * Remove command.
28
28
  */
29
29
  export class Remove {
30
- constructor(
31
- private project: Project,
32
- private calculateCmd: Calculate,
33
- ) {}
30
+ private moduleManager: ModuleManager;
31
+ constructor(private project: Project) {
32
+ this.moduleManager = new ModuleManager(this.project);
33
+ }
34
34
 
35
35
  // True, if resource is a project resource
36
36
  private projectResource(type: RemovableResourceTypes): boolean {
@@ -83,7 +83,7 @@ export class Remove {
83
83
 
84
84
  // Make sure card can be removed if it's a project card
85
85
  if (!(await this.project.isTemplateCard(cardKey))) {
86
- const actionGuard = new ActionGuard(this.calculateCmd);
86
+ const actionGuard = new ActionGuard(this.project.calculationEngine);
87
87
  await actionGuard.checkPermission('delete', cardKey);
88
88
  }
89
89
 
@@ -111,10 +111,10 @@ export class Remove {
111
111
  content: false,
112
112
  parent: false,
113
113
  });
114
+ await deleteDir(cardFolder);
114
115
  if (card) {
115
- await this.calculateCmd.handleDeleteCard(card);
116
+ await this.project.handleDeleteCard(card);
116
117
  }
117
- await deleteDir(cardFolder);
118
118
  }
119
119
 
120
120
  // removes label from project
@@ -182,16 +182,6 @@ export class Remove {
182
182
  await this.project.updateCardMetadataKey(sourceCardKey, 'links', newLinks);
183
183
  }
184
184
 
185
- // Removes modules from project
186
- private async removeModule(moduleName: string) {
187
- const module = await this.project.module(moduleName);
188
- if (!module) {
189
- throw new Error(`Module '${moduleName}' not found`);
190
- }
191
- await this.project.removeModule(moduleName);
192
- await deleteDir(module.path);
193
- }
194
-
195
185
  /**
196
186
  * Removes either attachment, card, imported module, link or resource from project.
197
187
  * @param type Type of resource
@@ -236,7 +226,8 @@ export class Remove {
236
226
  else if (type == 'card') return this.removeCard(targetName);
237
227
  else if (type == 'link')
238
228
  return this.removeLink(targetName, rest[0], rest[1], rest.at(2));
239
- else if (type == 'module') return this.removeModule(targetName);
229
+ else if (type == 'module')
230
+ return this.moduleManager.removeModule(targetName);
240
231
  else if (type == 'label') return this.removeLabel(targetName, rest[0]);
241
232
  }
242
233
  throw new Error(`Unknown resource type '${type}'`);
@@ -16,7 +16,6 @@ import { assert } from 'node:console';
16
16
  import { join } from 'node:path';
17
17
  import { rename, readdir, readFile, writeFile } from 'node:fs/promises';
18
18
 
19
- import type { Calculate } from './index.js';
20
19
  import type { Card } from '../interfaces/project-interfaces.js';
21
20
  import { isTemplateCard } from '../utils/card-utils.js';
22
21
  import { type Project, ResourcesFrom } from '../containers/project.js';
@@ -41,10 +40,7 @@ export class Rename {
41
40
  private from: string = '';
42
41
  private to: string = '';
43
42
 
44
- constructor(
45
- private project: Project,
46
- private calculateCmd: Calculate,
47
- ) {}
43
+ constructor(private project: Project) {}
48
44
 
49
45
  // Renames a card and all of its attachments (if it is a project card).
50
46
  private async renameCard(re: RegExp, card: Card): Promise<void> {
@@ -110,12 +106,7 @@ export class Rename {
110
106
  join(attachment.path, attachment.fileName),
111
107
  join(attachment.path, newAttachmentFileName),
112
108
  );
113
-
114
- const attachmentRe = new RegExp(`image::${attachment.fileName}`, 'g');
115
- card.content = card.content?.replace(
116
- attachmentRe,
117
- `image::${newAttachmentFileName}`,
118
- );
109
+ // NOTE: content is renamed by updateFiles method
119
110
  }),
120
111
  );
121
112
  }
@@ -373,6 +364,6 @@ export class Rename {
373
364
  this.project.collectLocalResources();
374
365
  console.info('Collected renamed resources');
375
366
 
376
- return this.calculateCmd.generate();
367
+ return this.project.calculationEngine.generate();
377
368
  }
378
369
  }