@cyberismo/data-handler 0.0.21 → 0.0.22

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 (166) hide show
  1. package/dist/command-handler.js +13 -24
  2. package/dist/command-handler.js.map +1 -1
  3. package/dist/command-manager.d.ts +21 -6
  4. package/dist/command-manager.js +34 -32
  5. package/dist/command-manager.js.map +1 -1
  6. package/dist/commands/calculate.js +101 -46
  7. package/dist/commands/calculate.js.map +1 -1
  8. package/dist/commands/create.js +417 -328
  9. package/dist/commands/create.js.map +1 -1
  10. package/dist/commands/edit.js +117 -68
  11. package/dist/commands/edit.js.map +1 -1
  12. package/dist/commands/export.js +301 -252
  13. package/dist/commands/export.js.map +1 -1
  14. package/dist/commands/fetch.js +205 -156
  15. package/dist/commands/fetch.js.map +1 -1
  16. package/dist/commands/import.js +189 -134
  17. package/dist/commands/import.js.map +1 -1
  18. package/dist/commands/migrate.js +91 -45
  19. package/dist/commands/migrate.js.map +1 -1
  20. package/dist/commands/move.js +347 -267
  21. package/dist/commands/move.js.map +1 -1
  22. package/dist/commands/remove.d.ts +1 -0
  23. package/dist/commands/remove.js +202 -135
  24. package/dist/commands/remove.js.map +1 -1
  25. package/dist/commands/rename.js +233 -187
  26. package/dist/commands/rename.js.map +1 -1
  27. package/dist/commands/show.d.ts +8 -8
  28. package/dist/commands/show.js +477 -372
  29. package/dist/commands/show.js.map +1 -1
  30. package/dist/commands/transition.js +119 -73
  31. package/dist/commands/transition.js.map +1 -1
  32. package/dist/commands/update.js +8 -3
  33. package/dist/commands/update.js.map +1 -1
  34. package/dist/commands/validate.js +1 -1
  35. package/dist/commands/validate.js.map +1 -1
  36. package/dist/containers/project/calculation-engine.js +0 -1
  37. package/dist/containers/project/calculation-engine.js.map +1 -1
  38. package/dist/containers/project/card-cache.js +1 -1
  39. package/dist/containers/project/card-cache.js.map +1 -1
  40. package/dist/containers/project.d.ts +16 -0
  41. package/dist/containers/project.js +59 -1
  42. package/dist/containers/project.js.map +1 -1
  43. package/dist/containers/template.js +1 -1
  44. package/dist/containers/template.js.map +1 -1
  45. package/dist/interfaces/command-options.d.ts +1 -0
  46. package/dist/interfaces/resource-interfaces.d.ts +5 -12
  47. package/dist/interfaces/resource-interfaces.js.map +1 -1
  48. package/dist/macros/base-macro.js +1 -1
  49. package/dist/macros/base-macro.js.map +1 -1
  50. package/dist/macros/graph/index.js +3 -1
  51. package/dist/macros/graph/index.js.map +1 -1
  52. package/dist/macros/index.js +3 -1
  53. package/dist/macros/index.js.map +1 -1
  54. package/dist/macros/report/index.js +1 -1
  55. package/dist/macros/report/index.js.map +1 -1
  56. package/dist/module-manager.js +5 -3
  57. package/dist/module-manager.js.map +1 -1
  58. package/dist/project-settings.js +2 -2
  59. package/dist/project-settings.js.map +1 -1
  60. package/dist/resources/card-type-resource.js +1 -1
  61. package/dist/resources/card-type-resource.js.map +1 -1
  62. package/dist/resources/create-defaults.js +0 -1
  63. package/dist/resources/create-defaults.js.map +1 -1
  64. package/dist/resources/field-type-resource.js +2 -5
  65. package/dist/resources/field-type-resource.js.map +1 -1
  66. package/dist/resources/file-resource.js +4 -1
  67. package/dist/resources/file-resource.js.map +1 -1
  68. package/dist/resources/folder-resource.d.ts +1 -1
  69. package/dist/resources/folder-resource.js +4 -1
  70. package/dist/resources/folder-resource.js.map +1 -1
  71. package/dist/resources/graph-model-resource.d.ts +1 -8
  72. package/dist/resources/graph-model-resource.js +0 -14
  73. package/dist/resources/graph-model-resource.js.map +1 -1
  74. package/dist/resources/graph-view-resource.d.ts +1 -8
  75. package/dist/resources/graph-view-resource.js +0 -14
  76. package/dist/resources/graph-view-resource.js.map +1 -1
  77. package/dist/resources/link-type-resource.js +1 -1
  78. package/dist/resources/link-type-resource.js.map +1 -1
  79. package/dist/resources/report-resource.d.ts +1 -8
  80. package/dist/resources/report-resource.js +0 -14
  81. package/dist/resources/report-resource.js.map +1 -1
  82. package/dist/resources/resource-object.d.ts +11 -1
  83. package/dist/resources/resource-object.js +19 -2
  84. package/dist/resources/resource-object.js.map +1 -1
  85. package/dist/resources/template-resource.d.ts +1 -9
  86. package/dist/resources/template-resource.js +0 -15
  87. package/dist/resources/template-resource.js.map +1 -1
  88. package/dist/resources/workflow-resource.js +1 -1
  89. package/dist/resources/workflow-resource.js.map +1 -1
  90. package/dist/utils/card-utils.js +1 -1
  91. package/dist/utils/card-utils.js.map +1 -1
  92. package/dist/utils/commit-context.d.ts +23 -0
  93. package/dist/utils/commit-context.js +30 -0
  94. package/dist/utils/commit-context.js.map +1 -0
  95. package/dist/utils/file-utils.js +3 -1
  96. package/dist/utils/file-utils.js.map +1 -1
  97. package/dist/utils/git-manager.d.ts +29 -0
  98. package/dist/utils/git-manager.js +76 -0
  99. package/dist/utils/git-manager.js.map +1 -0
  100. package/dist/utils/handlebars-helpers.d.ts +22 -0
  101. package/dist/utils/handlebars-helpers.js +78 -0
  102. package/dist/utils/handlebars-helpers.js.map +1 -0
  103. package/dist/utils/json.js +6 -2
  104. package/dist/utils/json.js.map +1 -1
  105. package/dist/utils/log-utils.d.ts +7 -2
  106. package/dist/utils/log-utils.js +28 -3
  107. package/dist/utils/log-utils.js.map +1 -1
  108. package/dist/utils/report.d.ts +0 -19
  109. package/dist/utils/report.js +4 -67
  110. package/dist/utils/report.js.map +1 -1
  111. package/dist/utils/rw-lock.d.ts +71 -0
  112. package/dist/utils/rw-lock.js +220 -0
  113. package/dist/utils/rw-lock.js.map +1 -0
  114. package/dist/utils/user-preferences.js +3 -3
  115. package/dist/utils/user-preferences.js.map +1 -1
  116. package/package.json +5 -5
  117. package/src/command-handler.ts +14 -22
  118. package/src/command-manager.ts +43 -37
  119. package/src/commands/calculate.ts +8 -1
  120. package/src/commands/create.ts +24 -1
  121. package/src/commands/edit.ts +3 -0
  122. package/src/commands/export.ts +8 -2
  123. package/src/commands/fetch.ts +3 -0
  124. package/src/commands/import.ts +5 -0
  125. package/src/commands/migrate.ts +2 -0
  126. package/src/commands/move.ts +34 -0
  127. package/src/commands/remove.ts +24 -2
  128. package/src/commands/rename.ts +2 -0
  129. package/src/commands/show.ts +63 -34
  130. package/src/commands/transition.ts +2 -0
  131. package/src/commands/update.ts +9 -3
  132. package/src/commands/validate.ts +1 -1
  133. package/src/containers/project/calculation-engine.ts +0 -1
  134. package/src/containers/project/card-cache.ts +1 -0
  135. package/src/containers/project.ts +75 -1
  136. package/src/containers/template.ts +1 -1
  137. package/src/interfaces/command-options.ts +1 -0
  138. package/src/interfaces/resource-interfaces.ts +5 -12
  139. package/src/macros/base-macro.ts +1 -1
  140. package/src/macros/graph/index.ts +3 -0
  141. package/src/macros/index.ts +3 -1
  142. package/src/macros/report/index.ts +1 -0
  143. package/src/module-manager.ts +5 -2
  144. package/src/project-settings.ts +2 -1
  145. package/src/resources/card-type-resource.ts +1 -1
  146. package/src/resources/create-defaults.ts +0 -1
  147. package/src/resources/field-type-resource.ts +2 -4
  148. package/src/resources/file-resource.ts +3 -1
  149. package/src/resources/folder-resource.ts +7 -2
  150. package/src/resources/graph-model-resource.ts +1 -25
  151. package/src/resources/graph-view-resource.ts +1 -25
  152. package/src/resources/link-type-resource.ts +1 -1
  153. package/src/resources/report-resource.ts +1 -25
  154. package/src/resources/resource-object.ts +22 -1
  155. package/src/resources/template-resource.ts +0 -23
  156. package/src/resources/workflow-resource.ts +1 -1
  157. package/src/utils/card-utils.ts +1 -1
  158. package/src/utils/commit-context.ts +45 -0
  159. package/src/utils/file-utils.ts +3 -1
  160. package/src/utils/git-manager.ts +87 -0
  161. package/src/utils/handlebars-helpers.ts +95 -0
  162. package/src/utils/json.ts +6 -2
  163. package/src/utils/log-utils.ts +33 -4
  164. package/src/utils/report.ts +8 -78
  165. package/src/utils/rw-lock.ts +279 -0
  166. package/src/utils/user-preferences.ts +3 -0
@@ -11,6 +11,40 @@
11
11
  You should have received a copy of the GNU Affero General Public
12
12
  License along with this program. If not, see <https://www.gnu.org/licenses/>.
13
13
  */
14
+ var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
15
+ var useValue = arguments.length > 2;
16
+ for (var i = 0; i < initializers.length; i++) {
17
+ value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
18
+ }
19
+ return useValue ? value : void 0;
20
+ };
21
+ var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
22
+ function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
23
+ var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
24
+ var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
25
+ var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
26
+ var _, done = false;
27
+ for (var i = decorators.length - 1; i >= 0; i--) {
28
+ var context = {};
29
+ for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
30
+ for (var p in contextIn.access) context.access[p] = contextIn.access[p];
31
+ context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
32
+ var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
33
+ if (kind === "accessor") {
34
+ if (result === void 0) continue;
35
+ if (result === null || typeof result !== "object") throw new TypeError("Object expected");
36
+ if (_ = accept(result.get)) descriptor.get = _;
37
+ if (_ = accept(result.set)) descriptor.set = _;
38
+ if (_ = accept(result.init)) initializers.unshift(_);
39
+ }
40
+ else if (_ = accept(result)) {
41
+ if (kind === "field") initializers.unshift(_);
42
+ else descriptor[key] = _;
43
+ }
44
+ }
45
+ if (target) Object.defineProperty(target, contextIn.name, descriptor);
46
+ done = true;
47
+ };
14
48
  // node
15
49
  import { appendFile, copyFile, mkdir, truncate, writeFile, } from 'node:fs/promises';
16
50
  import { dirname, join } from 'node:path';
@@ -19,285 +53,300 @@ import { evaluateMacros } from '../macros/index.js';
19
53
  import { generateReportContent } from '../utils/report.js';
20
54
  import { getStaticDirectoryPath, pdfReport } from '@cyberismo/assets';
21
55
  import { Project } from '../containers/project.js';
56
+ import { read } from '../utils/rw-lock.js';
22
57
  import { sortItems } from '../utils/lexorank.js';
23
58
  const attachmentFolder = 'a';
24
59
  /**
25
60
  * Handles all export commands.
26
61
  */
27
- export class Export {
28
- project;
29
- showCmd;
30
- /**
31
- * Creates an instance of export.
32
- * @param project Project to use
33
- * @param showCmd Instance of Export command to use.
34
- */
35
- constructor(project, showCmd) {
36
- this.project = project;
37
- this.showCmd = showCmd;
38
- }
39
- // This file should set the top level items to the adoc.
40
- async toAdocFile(path, cards) {
41
- await appendFile(path, `:imagesdir: ./${attachmentFolder}/\n`);
42
- await this.toAdocFileAsContent(path, cards);
43
- }
44
- // Format card metadata to an AsciiDoc table.
45
- metaToAdoc(card, cardType) {
46
- let content = '';
47
- if (card.metadata) {
48
- content += `[.cyberismo-meta-wrapper]\n`;
49
- content += '--\n';
50
- content += `[.cyberismo-meta]\n`;
51
- content += '[cols="1,1"]\n';
52
- content += '[frame=none]\n';
53
- content += '[grid=none]\n';
54
- content += '|===\n';
55
- content += `|Card key|${card.key}\n`;
56
- content += `|Status|${card.metadata.workflowState}\n`;
57
- content += `|Card type|${card.metadata.cardType}\n`;
58
- content += `|Labels|${card.metadata.labels?.join(', ') || ''}`;
59
- for (const [key, value] of Object.entries(card.metadata)) {
60
- if (cardType?.alwaysVisibleFields.includes(key) ||
61
- cardType?.optionallyVisibleFields?.includes(key)) {
62
- const displayName = cardType?.customFields.find((item) => item.name === key)?.displayName;
63
- let nameToShow = displayName
64
- ? displayName
65
- : key[0].toUpperCase() + key.slice(1);
66
- if (nameToShow === 'WorkflowState') {
67
- nameToShow = 'Workflow state';
68
- }
69
- else if (nameToShow === 'Cardtype') {
70
- nameToShow = 'Card type';
71
- }
72
- // Escape pipe character in cell values
73
- let escapedValue = 'N/A';
74
- if (value) {
75
- escapedValue = value.toString().replaceAll('|', '\\|');
62
+ let Export = (() => {
63
+ let _instanceExtraInitializers = [];
64
+ let _exportPdf_decorators;
65
+ let _exportToADoc_decorators;
66
+ return class Export {
67
+ static {
68
+ const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
69
+ _exportPdf_decorators = [read];
70
+ _exportToADoc_decorators = [read];
71
+ __esDecorate(this, null, _exportPdf_decorators, { kind: "method", name: "exportPdf", static: false, private: false, access: { has: obj => "exportPdf" in obj, get: obj => obj.exportPdf }, metadata: _metadata }, null, _instanceExtraInitializers);
72
+ __esDecorate(this, null, _exportToADoc_decorators, { kind: "method", name: "exportToADoc", static: false, private: false, access: { has: obj => "exportToADoc" in obj, get: obj => obj.exportToADoc }, metadata: _metadata }, null, _instanceExtraInitializers);
73
+ if (_metadata) Object.defineProperty(this, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
74
+ }
75
+ project = __runInitializers(this, _instanceExtraInitializers);
76
+ showCmd;
77
+ /**
78
+ * Creates an instance of export.
79
+ * @param project Project to use
80
+ * @param showCmd Instance of Export command to use.
81
+ */
82
+ constructor(project, showCmd) {
83
+ this.project = project;
84
+ this.showCmd = showCmd;
85
+ }
86
+ // This file should set the top level items to the adoc.
87
+ async toAdocFile(path, cards) {
88
+ await appendFile(path, `:imagesdir: ./${attachmentFolder}/\n`);
89
+ await this.toAdocFileAsContent(path, cards);
90
+ }
91
+ // Format card metadata to an AsciiDoc table.
92
+ metaToAdoc(card, cardType) {
93
+ let content = '';
94
+ if (card.metadata) {
95
+ content += `[.cyberismo-meta-wrapper]\n`;
96
+ content += '--\n';
97
+ content += `[.cyberismo-meta]\n`;
98
+ content += '[cols="1,1"]\n';
99
+ content += '[frame=none]\n';
100
+ content += '[grid=none]\n';
101
+ content += '|===\n';
102
+ content += `|Card key|${card.key}\n`;
103
+ content += `|Status|${card.metadata.workflowState}\n`;
104
+ content += `|Card type|${card.metadata.cardType}\n`;
105
+ content += `|Labels|${card.metadata.labels?.join(', ') || ''}`;
106
+ for (const [key, value] of Object.entries(card.metadata)) {
107
+ if (cardType?.alwaysVisibleFields.includes(key) ||
108
+ cardType?.optionallyVisibleFields?.includes(key)) {
109
+ const displayName = cardType?.customFields.find((item) => item.name === key)?.displayName;
110
+ let nameToShow = displayName
111
+ ? displayName
112
+ : key[0].toUpperCase() + key.slice(1);
113
+ if (nameToShow === 'WorkflowState') {
114
+ nameToShow = 'Workflow state';
115
+ }
116
+ else if (nameToShow === 'Cardtype') {
117
+ nameToShow = 'Card type';
118
+ }
119
+ // Escape pipe character in cell values
120
+ let escapedValue = 'N/A';
121
+ if (value) {
122
+ escapedValue = value.toString().replaceAll('|', '\\|');
123
+ }
124
+ content += `|${nameToShow}|${escapedValue}\n`;
76
125
  }
77
- content += `|${nameToShow}|${escapedValue}\n`;
78
126
  }
127
+ content += '|===\n';
128
+ content += '--\n';
79
129
  }
80
- content += '|===\n';
81
- content += '--\n';
130
+ return content;
82
131
  }
83
- return content;
84
- }
85
- // Runs Ascii Doctor converter --> to PDF
86
- async runAsciidoctorPdf(content) {
87
- const staticRootDir = await getStaticDirectoryPath();
88
- const proc = spawn('asciidoctor-pdf', [
89
- '-a',
90
- 'pdf-theme=cyberismo',
91
- '-a',
92
- `pdf-themesdir=${join(staticRootDir, 'pdf-themes')}`,
93
- '-a',
94
- `pdf-fontsdir=${join(staticRootDir, 'pdf-themes', 'fonts')};GEM_FONTS_DIR`,
95
- '-',
96
- ], {
97
- timeout: 100000,
98
- shell: process.platform === 'win32',
99
- });
100
- proc.stdin.end(content);
101
- const result = await new Promise((resolve, reject) => {
102
- const chunks = [];
103
- proc.stdout.on('data', (chunk) => {
104
- chunks.push(chunk);
105
- });
106
- proc.stderr.on('data', (chunk) => {
107
- process.stderr.write(chunk);
132
+ // Runs Ascii Doctor converter --> to PDF
133
+ async runAsciidoctorPdf(content) {
134
+ const staticRootDir = await getStaticDirectoryPath();
135
+ const proc = spawn('asciidoctor-pdf', [
136
+ '-a',
137
+ 'pdf-theme=cyberismo',
138
+ '-a',
139
+ `pdf-themesdir=${join(staticRootDir, 'pdf-themes')}`,
140
+ '-a',
141
+ `pdf-fontsdir=${join(staticRootDir, 'pdf-themes', 'fonts')};GEM_FONTS_DIR`,
142
+ '-',
143
+ ], {
144
+ timeout: 100000,
145
+ shell: process.platform === 'win32',
108
146
  });
109
- proc.on('error', (error) => {
110
- if ('code' in error && error.code === 'ENOENT') {
111
- reject(new Error('Asciidoctor-pdf not found. Please install asciidoctor-pdf to use this feature.'));
112
- }
113
- reject(error);
147
+ proc.stdin.end(content);
148
+ const result = await new Promise((resolve, reject) => {
149
+ const chunks = [];
150
+ proc.stdout.on('data', (chunk) => {
151
+ chunks.push(chunk);
152
+ });
153
+ proc.stderr.on('data', (chunk) => {
154
+ process.stderr.write(chunk);
155
+ });
156
+ proc.on('error', (error) => {
157
+ if ('code' in error && error.code === 'ENOENT') {
158
+ reject(new Error('Asciidoctor-pdf not found. Please install asciidoctor-pdf to use this feature.'));
159
+ }
160
+ reject(error);
161
+ });
162
+ proc.on('close', (code) => {
163
+ if (code === 0) {
164
+ resolve(Buffer.concat(chunks));
165
+ }
166
+ else {
167
+ reject(new Error(`Asciidoctor-pdf failed with code ${code}`));
168
+ }
169
+ });
114
170
  });
115
- proc.on('close', (code) => {
116
- if (code === 0) {
117
- resolve(Buffer.concat(chunks));
171
+ return result;
172
+ }
173
+ // Adds cards to an ADOC file as additional content.
174
+ async toAdocFileAsContent(path, cards) {
175
+ for (const card of cards) {
176
+ let fileContent = '';
177
+ if (card.metadata?.title) {
178
+ fileContent += `== ${card.metadata.title}\n\n`;
118
179
  }
119
180
  else {
120
- reject(new Error(`Asciidoctor-pdf failed with code ${code}`));
181
+ fileContent += `== ${card.key}\n\n`;
121
182
  }
122
- });
123
- });
124
- return result;
125
- }
126
- // Adds cards to an ADOC file as additional content.
127
- async toAdocFileAsContent(path, cards) {
128
- for (const card of cards) {
129
- let fileContent = '';
130
- if (card.metadata?.title) {
131
- fileContent += `== ${card.metadata.title}\n\n`;
132
- }
133
- else {
134
- fileContent += `== ${card.key}\n\n`;
135
- }
136
- if (card.metadata) {
137
- const cardTypeForCard = this.project.resources
138
- .byType(card.metadata?.cardType, 'cardTypes')
139
- .show();
140
- const metaDataContent = this.metaToAdoc(card, cardTypeForCard);
141
- fileContent += metaDataContent;
142
- }
143
- if (card.content) {
144
- fileContent += card.content;
145
- }
146
- if (card.attachments) {
147
- const promiseContainer = [];
148
- for (const attachment of card.attachments) {
149
- const destination = join(dirname(path), attachmentFolder, attachment.fileName);
150
- const source = join(attachment.path, attachment.fileName);
151
- promiseContainer.push(copyFile(source, destination));
183
+ if (card.metadata) {
184
+ const cardTypeForCard = this.project.resources
185
+ .byType(card.metadata?.cardType, 'cardTypes')
186
+ .show();
187
+ const metaDataContent = this.metaToAdoc(card, cardTypeForCard);
188
+ fileContent += metaDataContent;
189
+ }
190
+ if (card.content) {
191
+ fileContent += card.content;
192
+ }
193
+ if (card.attachments) {
194
+ const promiseContainer = [];
195
+ for (const attachment of card.attachments) {
196
+ const destination = join(dirname(path), attachmentFolder, attachment.fileName);
197
+ const source = join(attachment.path, attachment.fileName);
198
+ promiseContainer.push(copyFile(source, destination));
199
+ }
200
+ await Promise.all(promiseContainer);
201
+ }
202
+ // Add separator between cards
203
+ fileContent += '\n\n';
204
+ if (fileContent) {
205
+ await appendFile(path, fileContent);
206
+ }
207
+ if (card.children) {
208
+ await this.toAdocFileAsContent(path, this.project.cardKeysToCards(card.children));
152
209
  }
153
- await Promise.all(promiseContainer);
154
- }
155
- // Add separator between cards
156
- fileContent += '\n\n';
157
- if (fileContent) {
158
- await appendFile(path, fileContent);
159
210
  }
160
- if (card.children) {
161
- await this.toAdocFileAsContent(path, this.project.cardKeysToCards(card.children));
211
+ }
212
+ /**
213
+ * Recursively searches for a card with the specified key in the tree hierarchy.
214
+ * @param treeItems Array of tree query results to search through
215
+ * @param targetKey The key of the card to find
216
+ * @returns The found tree item or null if not found
217
+ */
218
+ findCardInTree(treeItems, targetKey) {
219
+ for (const item of treeItems) {
220
+ if (item.key === targetKey) {
221
+ return item;
222
+ }
223
+ if (item.children && item.children.length > 0) {
224
+ const foundInChildren = this.findCardInTree(item.children, targetKey);
225
+ if (foundInChildren) {
226
+ return foundInChildren;
227
+ }
228
+ }
162
229
  }
230
+ return null;
163
231
  }
164
- }
165
- /**
166
- * Recursively searches for a card with the specified key in the tree hierarchy.
167
- * @param treeItems Array of tree query results to search through
168
- * @param targetKey The key of the card to find
169
- * @returns The found tree item or null if not found
170
- */
171
- findCardInTree(treeItems, targetKey) {
172
- for (const item of treeItems) {
173
- if (item.key === targetKey) {
174
- return item;
232
+ /**
233
+ * Convert treeQueryResult object into a Card object and add content, metadata & attachments
234
+ * Handles card children recursively
235
+ * @param treeQueryResult tree query result object
236
+ * @returns Tree query result as a Card.
237
+ */
238
+ async treeQueryResultToCard(treeQueryResult) {
239
+ const card = {
240
+ key: treeQueryResult.key,
241
+ path: '',
242
+ children: [],
243
+ attachments: [],
244
+ };
245
+ const cardDetailsResponse = await this.showCmd.showCardDetails(card.key, 'adoc');
246
+ let asciiDocContent = '';
247
+ const project = this.project;
248
+ try {
249
+ const { evaluateMacros } = await import('../macros/index.js');
250
+ asciiDocContent = await evaluateMacros(cardDetailsResponse.content || '', {
251
+ context: 'exportedDocument',
252
+ mode: 'static',
253
+ project,
254
+ cardKey: card.key,
255
+ });
175
256
  }
176
- if (item.children && item.children.length > 0) {
177
- const foundInChildren = this.findCardInTree(item.children, targetKey);
178
- if (foundInChildren) {
179
- return foundInChildren;
180
- }
257
+ catch (error) {
258
+ asciiDocContent = `Macro error: ${error instanceof Error ? error.message : 'Unknown error'}\n\n${asciiDocContent}`;
181
259
  }
260
+ card.path = cardDetailsResponse.path;
261
+ card.metadata = cardDetailsResponse.metadata;
262
+ card.metadata.progress = treeQueryResult.progress;
263
+ card.content = asciiDocContent;
264
+ card.attachments = cardDetailsResponse.attachments;
265
+ for (const result of treeQueryResult.children ?? []) {
266
+ card.children.push((await this.treeQueryResultToCard(result)).key);
267
+ }
268
+ return card;
182
269
  }
183
- return null;
184
- }
185
- /**
186
- * Convert treeQueryResult object into a Card object and add content, metadata & attachments
187
- * Handles card children recursively
188
- * @param treeQueryResult tree query result object
189
- * @returns Tree query result as a Card.
190
- */
191
- async treeQueryResultToCard(treeQueryResult) {
192
- const card = {
193
- key: treeQueryResult.key,
194
- path: '',
195
- children: [],
196
- attachments: [],
197
- };
198
- const cardDetailsResponse = this.showCmd.showCardDetails(card.key, 'adoc');
199
- let asciiDocContent = '';
200
- const project = this.project;
201
- try {
202
- const { evaluateMacros } = await import('../macros/index.js');
203
- asciiDocContent = await evaluateMacros(cardDetailsResponse.content || '', {
270
+ /**
271
+ * Exports the card(s) to pdf.
272
+ * @param destination Path to where the resulting file(s) will be created.
273
+ * @param options Export options.
274
+ * @returns status message
275
+ */
276
+ async exportPdf(destination, options) {
277
+ const opts = {
278
+ ...options,
279
+ date: options.date?.toISOString().split('T')[0],
280
+ recursive: options.recursive ?? false,
281
+ };
282
+ await this.project.calculationEngine.generate();
283
+ const result = await generateReportContent({
284
+ calculate: this.project.calculationEngine,
285
+ contentTemplate: pdfReport.content,
286
+ queryTemplate: pdfReport.query,
287
+ context: 'exportedDocument',
288
+ options: opts,
289
+ });
290
+ const evaluated = await evaluateMacros(result, {
204
291
  context: 'exportedDocument',
205
292
  mode: 'static',
206
- project,
207
- cardKey: card.key,
293
+ project: this.project,
294
+ cardKey: '', // top level report does not contain any macros that use cardKey
208
295
  });
296
+ const pdf = await this.runAsciidoctorPdf(evaluated);
297
+ await writeFile(destination, pdf);
298
+ return `Content exported as PDF to ${destination}`;
209
299
  }
210
- catch (error) {
211
- asciiDocContent = `Macro error: ${error instanceof Error ? error.message : 'Unknown error'}\n\n${asciiDocContent}`;
212
- }
213
- card.path = cardDetailsResponse.path;
214
- card.metadata = cardDetailsResponse.metadata;
215
- card.metadata.progress = treeQueryResult.progress;
216
- card.content = asciiDocContent;
217
- card.attachments = cardDetailsResponse.attachments;
218
- for (const result of treeQueryResult.children ?? []) {
219
- card.children.push((await this.treeQueryResultToCard(result)).key);
220
- }
221
- return card;
222
- }
223
- /**
224
- * Exports the card(s) to pdf.
225
- * @param destination Path to where the resulting file(s) will be created.
226
- * @param options Export options.
227
- * @returns status message
228
- */
229
- async exportPdf(destination, options) {
230
- const opts = {
231
- ...options,
232
- date: options.date?.toISOString().split('T')[0],
233
- recursive: options.recursive ?? false,
234
- };
235
- await this.project.calculationEngine.generate();
236
- const result = await generateReportContent({
237
- calculate: this.project.calculationEngine,
238
- contentTemplate: pdfReport.content,
239
- queryTemplate: pdfReport.query,
240
- context: 'exportedDocument',
241
- options: opts,
242
- });
243
- const evaluated = await evaluateMacros(result, {
244
- context: 'exportedDocument',
245
- mode: 'static',
246
- project: this.project,
247
- cardKey: '', // top level report does not contain any macros that use cardKey
248
- });
249
- const pdf = await this.runAsciidoctorPdf(evaluated);
250
- await writeFile(destination, pdf);
251
- return `Content exported as PDF to ${destination}`;
252
- }
253
- /**
254
- * Exports the card(s) to ascii doc.
255
- * @param destination Path to where the resulting file(s) will be created.
256
- * @param cardKey If not exporting the whole card tree, card key of parent card.
257
- * @returns status message
258
- */
259
- async exportToADoc(destination, cardKey) {
260
- const sourcePath = this.project.paths.cardRootFolder;
261
- let cards = [];
262
- // If doing a partial tree export, put the parent information as it would have already been gathered.
263
- if (cardKey && this.project.findCard(cardKey)) {
264
- cards.push({
265
- key: cardKey,
266
- path: sourcePath,
267
- children: [],
268
- attachments: [],
300
+ /**
301
+ * Exports the card(s) to ascii doc.
302
+ * @param destination Path to where the resulting file(s) will be created.
303
+ * @param cardKey If not exporting the whole card tree, card key of parent card.
304
+ * @returns status message
305
+ */
306
+ async exportToADoc(destination, cardKey) {
307
+ const sourcePath = this.project.paths.cardRootFolder;
308
+ let cards = [];
309
+ // If doing a partial tree export, put the parent information as it would have already been gathered.
310
+ if (cardKey && this.project.findCard(cardKey)) {
311
+ cards.push({
312
+ key: cardKey,
313
+ path: sourcePath,
314
+ children: [],
315
+ attachments: [],
316
+ });
317
+ }
318
+ await this.project.calculationEngine.generate();
319
+ const tree = await this.project.calculationEngine.runQuery('tree', 'exportedDocument');
320
+ if (cardKey) {
321
+ const targetCard = this.findCardInTree(tree, cardKey);
322
+ if (!targetCard) {
323
+ throw new Error(`Cannot find card '${cardKey}' in the tree hierarchy`);
324
+ }
325
+ cards = [await this.treeQueryResultToCard(targetCard)];
326
+ }
327
+ else {
328
+ for (const treeQueryResult of tree) {
329
+ cards.push(await this.treeQueryResultToCard(treeQueryResult));
330
+ }
331
+ }
332
+ // Sort the cards by rank
333
+ cards = sortItems(cards, function (card) {
334
+ return card.metadata?.rank || '1|z';
269
335
  });
270
- }
271
- await this.project.calculationEngine.generate();
272
- const tree = await this.project.calculationEngine.runQuery('tree', 'exportedDocument');
273
- if (cardKey) {
274
- const targetCard = this.findCardInTree(tree, cardKey);
275
- if (!targetCard) {
276
- throw new Error(`Cannot find card '${cardKey}' in the tree hierarchy`);
336
+ await mkdir(join(destination, attachmentFolder), { recursive: true });
337
+ const resultDocumentPath = join(destination, Project.cardContentFile);
338
+ let message;
339
+ try {
340
+ await truncate(resultDocumentPath, 0);
341
+ message = `Using existing output file '${resultDocumentPath}'`;
277
342
  }
278
- cards = [await this.treeQueryResultToCard(targetCard)];
279
- }
280
- else {
281
- for (const treeQueryResult of tree) {
282
- cards.push(await this.treeQueryResultToCard(treeQueryResult));
343
+ catch {
344
+ message = `Creating output file '${resultDocumentPath}'`;
283
345
  }
346
+ await this.toAdocFile(resultDocumentPath, cards);
347
+ return message;
284
348
  }
285
- // Sort the cards by rank
286
- cards = sortItems(cards, function (card) {
287
- return card.metadata?.rank || '1|z';
288
- });
289
- await mkdir(join(destination, attachmentFolder), { recursive: true });
290
- const resultDocumentPath = join(destination, Project.cardContentFile);
291
- let message = '';
292
- try {
293
- await truncate(resultDocumentPath, 0);
294
- message = `Using existing output file '${resultDocumentPath}'`;
295
- }
296
- catch {
297
- message = `Creating output file '${resultDocumentPath}'`;
298
- }
299
- await this.toAdocFile(resultDocumentPath, cards);
300
- return message;
301
- }
302
- }
349
+ };
350
+ })();
351
+ export { Export };
303
352
  //# sourceMappingURL=export.js.map