@cyberismo/data-handler 0.0.20 → 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.
- package/dist/command-handler.js +13 -24
- package/dist/command-handler.js.map +1 -1
- package/dist/command-manager.d.ts +21 -6
- package/dist/command-manager.js +34 -32
- package/dist/command-manager.js.map +1 -1
- package/dist/commands/calculate.js +101 -46
- package/dist/commands/calculate.js.map +1 -1
- package/dist/commands/create.js +420 -320
- package/dist/commands/create.js.map +1 -1
- package/dist/commands/edit.js +117 -68
- package/dist/commands/edit.js.map +1 -1
- package/dist/commands/export.js +301 -252
- package/dist/commands/export.js.map +1 -1
- package/dist/commands/fetch.js +205 -156
- package/dist/commands/fetch.js.map +1 -1
- package/dist/commands/import.js +189 -134
- package/dist/commands/import.js.map +1 -1
- package/dist/commands/migrate.js +91 -45
- package/dist/commands/migrate.js.map +1 -1
- package/dist/commands/move.js +347 -267
- package/dist/commands/move.js.map +1 -1
- package/dist/commands/remove.d.ts +1 -0
- package/dist/commands/remove.js +202 -135
- package/dist/commands/remove.js.map +1 -1
- package/dist/commands/rename.js +233 -187
- package/dist/commands/rename.js.map +1 -1
- package/dist/commands/show.d.ts +8 -8
- package/dist/commands/show.js +477 -372
- package/dist/commands/show.js.map +1 -1
- package/dist/commands/transition.js +119 -73
- package/dist/commands/transition.js.map +1 -1
- package/dist/commands/update.js +8 -3
- package/dist/commands/update.js.map +1 -1
- package/dist/commands/validate.js +1 -1
- package/dist/commands/validate.js.map +1 -1
- package/dist/containers/project/calculation-engine.js +0 -1
- package/dist/containers/project/calculation-engine.js.map +1 -1
- package/dist/containers/project/card-cache.js +1 -1
- package/dist/containers/project/card-cache.js.map +1 -1
- package/dist/containers/project.d.ts +16 -0
- package/dist/containers/project.js +59 -1
- package/dist/containers/project.js.map +1 -1
- package/dist/containers/template.js +1 -1
- package/dist/containers/template.js.map +1 -1
- package/dist/interfaces/command-options.d.ts +1 -0
- package/dist/interfaces/resource-interfaces.d.ts +5 -12
- package/dist/interfaces/resource-interfaces.js.map +1 -1
- package/dist/macros/base-macro.js +1 -1
- package/dist/macros/base-macro.js.map +1 -1
- package/dist/macros/graph/index.js +3 -1
- package/dist/macros/graph/index.js.map +1 -1
- package/dist/macros/include/index.js +16 -1
- package/dist/macros/include/index.js.map +1 -1
- package/dist/macros/include/types.d.ts +15 -12
- package/dist/macros/index.js +4 -1
- package/dist/macros/index.js.map +1 -1
- package/dist/macros/report/index.js +1 -1
- package/dist/macros/report/index.js.map +1 -1
- package/dist/module-manager.js +5 -3
- package/dist/module-manager.js.map +1 -1
- package/dist/project-settings.js +2 -2
- package/dist/project-settings.js.map +1 -1
- package/dist/resources/card-type-resource.js +1 -1
- package/dist/resources/card-type-resource.js.map +1 -1
- package/dist/resources/create-defaults.js +0 -1
- package/dist/resources/create-defaults.js.map +1 -1
- package/dist/resources/field-type-resource.js +2 -5
- package/dist/resources/field-type-resource.js.map +1 -1
- package/dist/resources/file-resource.js +4 -1
- package/dist/resources/file-resource.js.map +1 -1
- package/dist/resources/folder-resource.d.ts +1 -1
- package/dist/resources/folder-resource.js +4 -1
- package/dist/resources/folder-resource.js.map +1 -1
- package/dist/resources/graph-model-resource.d.ts +1 -8
- package/dist/resources/graph-model-resource.js +0 -14
- package/dist/resources/graph-model-resource.js.map +1 -1
- package/dist/resources/graph-view-resource.d.ts +1 -8
- package/dist/resources/graph-view-resource.js +0 -14
- package/dist/resources/graph-view-resource.js.map +1 -1
- package/dist/resources/link-type-resource.js +1 -1
- package/dist/resources/link-type-resource.js.map +1 -1
- package/dist/resources/report-resource.d.ts +1 -8
- package/dist/resources/report-resource.js +0 -14
- package/dist/resources/report-resource.js.map +1 -1
- package/dist/resources/resource-object.d.ts +11 -1
- package/dist/resources/resource-object.js +19 -2
- package/dist/resources/resource-object.js.map +1 -1
- package/dist/resources/template-resource.d.ts +1 -9
- package/dist/resources/template-resource.js +0 -15
- package/dist/resources/template-resource.js.map +1 -1
- package/dist/resources/workflow-resource.d.ts +6 -0
- package/dist/resources/workflow-resource.js +29 -13
- package/dist/resources/workflow-resource.js.map +1 -1
- package/dist/utils/card-utils.js +1 -1
- package/dist/utils/card-utils.js.map +1 -1
- package/dist/utils/commit-context.d.ts +23 -0
- package/dist/utils/commit-context.js +30 -0
- package/dist/utils/commit-context.js.map +1 -0
- package/dist/utils/csv.d.ts +8 -0
- package/dist/utils/csv.js +11 -0
- package/dist/utils/csv.js.map +1 -1
- package/dist/utils/file-utils.js +3 -1
- package/dist/utils/file-utils.js.map +1 -1
- package/dist/utils/git-manager.d.ts +29 -0
- package/dist/utils/git-manager.js +76 -0
- package/dist/utils/git-manager.js.map +1 -0
- package/dist/utils/handlebars-helpers.d.ts +22 -0
- package/dist/utils/handlebars-helpers.js +78 -0
- package/dist/utils/handlebars-helpers.js.map +1 -0
- package/dist/utils/json.d.ts +17 -10
- package/dist/utils/json.js +27 -14
- package/dist/utils/json.js.map +1 -1
- package/dist/utils/log-utils.d.ts +7 -2
- package/dist/utils/log-utils.js +28 -3
- package/dist/utils/log-utils.js.map +1 -1
- package/dist/utils/report.d.ts +0 -19
- package/dist/utils/report.js +4 -63
- package/dist/utils/report.js.map +1 -1
- package/dist/utils/rw-lock.d.ts +71 -0
- package/dist/utils/rw-lock.js +220 -0
- package/dist/utils/rw-lock.js.map +1 -0
- package/dist/utils/user-preferences.js +3 -3
- package/dist/utils/user-preferences.js.map +1 -1
- package/package.json +10 -10
- package/src/command-handler.ts +14 -22
- package/src/command-manager.ts +43 -37
- package/src/commands/calculate.ts +8 -1
- package/src/commands/create.ts +39 -6
- package/src/commands/edit.ts +3 -0
- package/src/commands/export.ts +8 -2
- package/src/commands/fetch.ts +3 -0
- package/src/commands/import.ts +5 -0
- package/src/commands/migrate.ts +2 -0
- package/src/commands/move.ts +34 -0
- package/src/commands/remove.ts +24 -2
- package/src/commands/rename.ts +2 -0
- package/src/commands/show.ts +63 -34
- package/src/commands/transition.ts +2 -0
- package/src/commands/update.ts +9 -3
- package/src/commands/validate.ts +1 -1
- package/src/containers/project/calculation-engine.ts +0 -1
- package/src/containers/project/card-cache.ts +1 -0
- package/src/containers/project.ts +75 -1
- package/src/containers/template.ts +1 -1
- package/src/interfaces/command-options.ts +1 -0
- package/src/interfaces/resource-interfaces.ts +5 -12
- package/src/macros/base-macro.ts +1 -1
- package/src/macros/graph/index.ts +3 -0
- package/src/macros/include/index.ts +19 -1
- package/src/macros/include/types.ts +15 -12
- package/src/macros/index.ts +4 -1
- package/src/macros/report/index.ts +1 -0
- package/src/module-manager.ts +5 -2
- package/src/project-settings.ts +2 -1
- package/src/resources/card-type-resource.ts +1 -1
- package/src/resources/create-defaults.ts +0 -1
- package/src/resources/field-type-resource.ts +2 -4
- package/src/resources/file-resource.ts +3 -1
- package/src/resources/folder-resource.ts +7 -2
- package/src/resources/graph-model-resource.ts +1 -25
- package/src/resources/graph-view-resource.ts +1 -25
- package/src/resources/link-type-resource.ts +1 -1
- package/src/resources/report-resource.ts +1 -25
- package/src/resources/resource-object.ts +22 -1
- package/src/resources/template-resource.ts +0 -23
- package/src/resources/workflow-resource.ts +45 -16
- package/src/utils/card-utils.ts +1 -1
- package/src/utils/commit-context.ts +45 -0
- package/src/utils/csv.ts +12 -0
- package/src/utils/file-utils.ts +3 -1
- package/src/utils/git-manager.ts +87 -0
- package/src/utils/handlebars-helpers.ts +95 -0
- package/src/utils/json.ts +29 -15
- package/src/utils/log-utils.ts +33 -4
- package/src/utils/report.ts +8 -74
- package/src/utils/rw-lock.ts +279 -0
- package/src/utils/user-preferences.ts +3 -0
package/dist/commands/export.js
CHANGED
|
@@ -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
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
content
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
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
|
|
81
|
-
content += '--\n';
|
|
130
|
+
return content;
|
|
82
131
|
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
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.
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
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
|
-
|
|
116
|
-
|
|
117
|
-
|
|
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
|
-
|
|
181
|
+
fileContent += `== ${card.key}\n\n`;
|
|
121
182
|
}
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
.
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
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
|
-
|
|
161
|
-
|
|
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
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
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
|
-
|
|
177
|
-
|
|
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
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
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:
|
|
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
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
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
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
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
|
-
|
|
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
|
-
|
|
286
|
-
|
|
287
|
-
|
|
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
|