@cyberismo/data-handler 0.0.14 → 0.0.16
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/card-metadata-updater.js +8 -4
- package/dist/card-metadata-updater.js.map +1 -1
- package/dist/command-handler.d.ts +4 -0
- package/dist/command-handler.js +29 -19
- package/dist/command-handler.js.map +1 -1
- package/dist/command-manager.d.ts +25 -2
- package/dist/command-manager.js +30 -5
- package/dist/command-manager.js.map +1 -1
- package/dist/commands/create.d.ts +1 -1
- package/dist/commands/create.js +45 -93
- package/dist/commands/create.js.map +1 -1
- package/dist/commands/edit.d.ts +1 -15
- package/dist/commands/edit.js +15 -89
- package/dist/commands/edit.js.map +1 -1
- package/dist/commands/export.d.ts +11 -2
- package/dist/commands/export.js +58 -58
- package/dist/commands/export.js.map +1 -1
- package/dist/commands/import.d.ts +9 -1
- package/dist/commands/import.js +17 -11
- package/dist/commands/import.js.map +1 -1
- package/dist/commands/move.d.ts +1 -2
- package/dist/commands/move.js +107 -146
- package/dist/commands/move.js.map +1 -1
- package/dist/commands/remove.d.ts +8 -1
- package/dist/commands/remove.js +17 -48
- package/dist/commands/remove.js.map +1 -1
- package/dist/commands/rename.d.ts +4 -9
- package/dist/commands/rename.js +34 -108
- package/dist/commands/rename.js.map +1 -1
- package/dist/commands/show.d.ts +22 -34
- package/dist/commands/show.js +103 -151
- package/dist/commands/show.js.map +1 -1
- package/dist/commands/transition.d.ts +9 -2
- package/dist/commands/transition.js +49 -44
- package/dist/commands/transition.js.map +1 -1
- package/dist/commands/update.d.ts +18 -12
- package/dist/commands/update.js +34 -18
- package/dist/commands/update.js.map +1 -1
- package/dist/commands/validate.d.ts +18 -10
- package/dist/commands/validate.js +101 -47
- package/dist/commands/validate.js.map +1 -1
- package/dist/containers/card-container.d.ts +87 -24
- package/dist/containers/card-container.js +183 -279
- package/dist/containers/card-container.js.map +1 -1
- package/dist/containers/project/calculation-engine.d.ts +13 -4
- package/dist/containers/project/calculation-engine.js +79 -77
- package/dist/containers/project/calculation-engine.js.map +1 -1
- package/dist/containers/project/card-cache.d.ts +146 -0
- package/dist/containers/project/card-cache.js +411 -0
- package/dist/containers/project/card-cache.js.map +1 -0
- package/dist/containers/project/project-paths.d.ts +5 -4
- package/dist/containers/project/project-paths.js +16 -12
- package/dist/containers/project/project-paths.js.map +1 -1
- package/dist/containers/project/resource-cache.d.ts +169 -0
- package/dist/containers/project/resource-cache.js +507 -0
- package/dist/containers/project/resource-cache.js.map +1 -0
- package/dist/containers/project/resource-handler.d.ts +129 -0
- package/dist/containers/project/resource-handler.js +206 -0
- package/dist/containers/project/resource-handler.js.map +1 -0
- package/dist/containers/project.d.ts +114 -195
- package/dist/containers/project.js +425 -535
- package/dist/containers/project.js.map +1 -1
- package/dist/containers/template.d.ts +22 -32
- package/dist/containers/template.js +113 -115
- package/dist/containers/template.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/interfaces/folder-content-interfaces.d.ts +7 -4
- package/dist/interfaces/folder-content-interfaces.js +3 -3
- package/dist/interfaces/folder-content-interfaces.js.map +1 -1
- package/dist/interfaces/macros.d.ts +1 -0
- package/dist/interfaces/macros.js +1 -1
- package/dist/interfaces/macros.js.map +1 -1
- package/dist/interfaces/project-interfaces.d.ts +7 -5
- package/dist/interfaces/project-interfaces.js.map +1 -1
- package/dist/interfaces/resource-interfaces.d.ts +25 -22
- package/dist/interfaces/resource-interfaces.js +3 -0
- package/dist/interfaces/resource-interfaces.js.map +1 -1
- package/dist/macros/common.d.ts +10 -10
- package/dist/macros/createCards/index.d.ts +0 -13
- package/dist/macros/createCards/index.js.map +1 -1
- package/dist/macros/createCards/types.d.ts +44 -0
- package/dist/macros/createCards/types.js +15 -0
- package/dist/macros/createCards/types.js.map +1 -0
- package/dist/macros/graph/index.d.ts +2 -6
- package/dist/macros/graph/index.js +14 -28
- package/dist/macros/graph/index.js.map +1 -1
- package/dist/macros/graph/types.d.ts +23 -0
- package/dist/macros/graph/types.js +15 -0
- package/dist/macros/graph/types.js.map +1 -0
- package/dist/macros/image/index.d.ts +8 -16
- package/dist/macros/image/index.js +36 -33
- package/dist/macros/image/index.js.map +1 -1
- package/dist/macros/image/types.d.ts +38 -0
- package/dist/macros/image/types.js +15 -0
- package/dist/macros/image/types.js.map +1 -0
- package/dist/macros/include/index.d.ts +1 -6
- package/dist/macros/include/index.js +4 -7
- package/dist/macros/include/index.js.map +1 -1
- package/dist/macros/include/types.d.ts +31 -0
- package/dist/macros/include/types.js +15 -0
- package/dist/macros/include/types.js.map +1 -0
- package/dist/macros/index.d.ts +1 -1
- package/dist/macros/index.js +2 -2
- package/dist/macros/index.js.map +1 -1
- package/dist/macros/percentage/index.d.ts +0 -6
- package/dist/macros/percentage/index.js.map +1 -1
- package/dist/macros/percentage/types.d.ts +31 -0
- package/dist/macros/percentage/types.js +15 -0
- package/dist/macros/percentage/types.js.map +1 -0
- package/dist/macros/report/index.d.ts +0 -3
- package/dist/macros/report/index.js +3 -6
- package/dist/macros/report/index.js.map +1 -1
- package/dist/macros/report/types.d.ts +19 -0
- package/dist/macros/report/types.js +15 -0
- package/dist/macros/report/types.js.map +1 -0
- package/dist/macros/scoreCard/index.d.ts +0 -6
- package/dist/macros/scoreCard/index.js.map +1 -1
- package/dist/macros/scoreCard/types.d.ts +31 -0
- package/dist/macros/scoreCard/types.js +15 -0
- package/dist/macros/scoreCard/types.js.map +1 -0
- package/dist/macros/types.d.ts +25 -0
- package/dist/macros/types.js +2 -0
- package/dist/macros/types.js.map +1 -0
- package/dist/macros/vega/index.d.ts +0 -4
- package/dist/macros/vega/index.js.map +1 -1
- package/dist/macros/vega/types.d.ts +20 -0
- package/dist/macros/vega/types.js +2 -0
- package/dist/macros/vega/types.js.map +1 -0
- package/dist/macros/vegalite/index.d.ts +0 -4
- package/dist/macros/vegalite/index.js.map +1 -1
- package/dist/macros/vegalite/types.d.ts +20 -0
- package/dist/macros/vegalite/types.js +15 -0
- package/dist/macros/vegalite/types.js.map +1 -0
- package/dist/macros/xref/index.d.ts +0 -3
- package/dist/macros/xref/index.js +5 -14
- package/dist/macros/xref/index.js.map +1 -1
- package/dist/macros/xref/types.d.ts +19 -0
- package/dist/macros/xref/types.js +15 -0
- package/dist/macros/xref/types.js.map +1 -0
- package/dist/module-manager.d.ts +16 -3
- package/dist/module-manager.js +55 -23
- package/dist/module-manager.js.map +1 -1
- package/dist/project-settings.d.ts +16 -3
- package/dist/project-settings.js +79 -14
- package/dist/project-settings.js.map +1 -1
- package/dist/resources/calculation-resource.d.ts +6 -33
- package/dist/resources/calculation-resource.js +11 -60
- package/dist/resources/calculation-resource.js.map +1 -1
- package/dist/resources/card-type-resource.d.ts +10 -22
- package/dist/resources/card-type-resource.js +46 -66
- package/dist/resources/card-type-resource.js.map +1 -1
- package/dist/resources/create-defaults.d.ts +3 -2
- package/dist/resources/create-defaults.js +3 -2
- package/dist/resources/create-defaults.js.map +1 -1
- package/dist/resources/field-type-resource.d.ts +8 -22
- package/dist/resources/field-type-resource.js +35 -60
- package/dist/resources/field-type-resource.js.map +1 -1
- package/dist/resources/file-resource.d.ts +14 -35
- package/dist/resources/file-resource.js +22 -301
- package/dist/resources/file-resource.js.map +1 -1
- package/dist/resources/folder-resource.d.ts +44 -66
- package/dist/resources/folder-resource.js +102 -149
- package/dist/resources/folder-resource.js.map +1 -1
- package/dist/resources/graph-model-resource.d.ts +9 -34
- package/dist/resources/graph-model-resource.js +18 -64
- package/dist/resources/graph-model-resource.js.map +1 -1
- package/dist/resources/graph-view-resource.d.ts +9 -29
- package/dist/resources/graph-view-resource.js +13 -48
- package/dist/resources/graph-view-resource.js.map +1 -1
- package/dist/resources/link-type-resource.d.ts +9 -23
- package/dist/resources/link-type-resource.js +11 -33
- package/dist/resources/link-type-resource.js.map +1 -1
- package/dist/resources/report-resource.d.ts +10 -23
- package/dist/resources/report-resource.js +20 -67
- package/dist/resources/report-resource.js.map +1 -1
- package/dist/resources/resource-object.d.ts +143 -23
- package/dist/resources/resource-object.js +369 -48
- package/dist/resources/resource-object.js.map +1 -1
- package/dist/resources/template-resource.d.ts +10 -17
- package/dist/resources/template-resource.js +19 -27
- package/dist/resources/template-resource.js.map +1 -1
- package/dist/resources/workflow-resource.d.ts +9 -25
- package/dist/resources/workflow-resource.js +25 -55
- package/dist/resources/workflow-resource.js.map +1 -1
- package/dist/utils/card-utils.d.ts +69 -19
- package/dist/utils/card-utils.js +179 -30
- package/dist/utils/card-utils.js.map +1 -1
- package/dist/utils/clingo-fact-builder.d.ts +25 -14
- package/dist/utils/clingo-fact-builder.js +27 -5
- package/dist/utils/clingo-fact-builder.js.map +1 -1
- package/dist/utils/clingo-facts.js +14 -7
- package/dist/utils/clingo-facts.js.map +1 -1
- package/dist/utils/clingo-parser.js +1 -1
- package/dist/utils/clingo-parser.js.map +1 -1
- package/dist/utils/constants.d.ts +2 -0
- package/dist/utils/constants.js +4 -0
- package/dist/utils/constants.js.map +1 -1
- package/dist/utils/csv.js +1 -1
- package/dist/utils/csv.js.map +1 -1
- package/dist/utils/resource-utils.d.ts +1 -0
- package/dist/utils/resource-utils.js +2 -1
- package/dist/utils/resource-utils.js.map +1 -1
- package/package.json +11 -11
- package/src/card-metadata-updater.ts +9 -7
- package/src/command-handler.ts +35 -23
- package/src/command-manager.ts +32 -19
- package/src/commands/create.ts +59 -160
- package/src/commands/edit.ts +16 -132
- package/src/commands/export.ts +71 -81
- package/src/commands/import.ts +26 -18
- package/src/commands/move.ts +143 -179
- package/src/commands/remove.ts +20 -59
- package/src/commands/rename.ts +45 -156
- package/src/commands/show.ts +153 -211
- package/src/commands/transition.ts +53 -58
- package/src/commands/update.ts +44 -23
- package/src/commands/validate.ts +108 -82
- package/src/containers/card-container.ts +200 -360
- package/src/containers/project/calculation-engine.ts +81 -105
- package/src/containers/project/card-cache.ts +497 -0
- package/src/containers/project/project-paths.ts +21 -13
- package/src/containers/project/resource-cache.ts +648 -0
- package/src/containers/project/resource-handler.ts +265 -0
- package/src/containers/project.ts +551 -693
- package/src/containers/template.ts +129 -142
- package/src/index.ts +1 -0
- package/src/interfaces/folder-content-interfaces.ts +14 -7
- package/src/interfaces/macros.ts +2 -0
- package/src/interfaces/project-interfaces.ts +14 -7
- package/src/interfaces/resource-interfaces.ts +30 -27
- package/src/macros/createCards/index.ts +1 -12
- package/src/macros/createCards/types.ts +46 -0
- package/src/macros/graph/index.ts +27 -52
- package/src/macros/graph/types.ts +24 -0
- package/src/macros/image/index.ts +50 -61
- package/src/macros/image/types.ts +39 -0
- package/src/macros/include/index.ts +6 -15
- package/src/macros/include/types.ts +32 -0
- package/src/macros/index.ts +2 -2
- package/src/macros/percentage/index.ts +1 -7
- package/src/macros/percentage/types.ts +32 -0
- package/src/macros/report/index.ts +4 -13
- package/src/macros/report/types.ts +20 -0
- package/src/macros/scoreCard/index.ts +1 -7
- package/src/macros/scoreCard/types.ts +32 -0
- package/src/macros/types.ts +48 -0
- package/src/macros/vega/index.ts +1 -4
- package/src/macros/vega/types.ts +21 -0
- package/src/macros/vegalite/index.ts +1 -4
- package/src/macros/vegalite/types.ts +22 -0
- package/src/macros/xref/index.ts +6 -20
- package/src/macros/xref/types.ts +20 -0
- package/src/module-manager.ts +79 -22
- package/src/project-settings.ts +84 -15
- package/src/resources/calculation-resource.ts +21 -91
- package/src/resources/card-type-resource.ts +74 -109
- package/src/resources/create-defaults.ts +3 -2
- package/src/resources/field-type-resource.ts +61 -104
- package/src/resources/file-resource.ts +33 -441
- package/src/resources/folder-resource.ts +130 -207
- package/src/resources/graph-model-resource.ts +36 -95
- package/src/resources/graph-view-resource.ts +28 -70
- package/src/resources/link-type-resource.ts +23 -53
- package/src/resources/report-resource.ts +34 -96
- package/src/resources/resource-object.ts +511 -66
- package/src/resources/template-resource.ts +32 -44
- package/src/resources/workflow-resource.ts +42 -85
- package/src/utils/card-utils.ts +217 -31
- package/src/utils/clingo-fact-builder.ts +28 -16
- package/src/utils/clingo-facts.ts +16 -7
- package/src/utils/clingo-parser.ts +1 -1
- package/src/utils/constants.ts +6 -0
- package/src/utils/csv.ts +1 -1
- package/src/utils/resource-utils.ts +2 -1
- package/dist/containers/project/resource-collector.d.ts +0 -87
- package/dist/containers/project/resource-collector.js +0 -337
- package/dist/containers/project/resource-collector.js.map +0 -1
- package/src/containers/project/resource-collector.ts +0 -396
package/src/commands/export.ts
CHANGED
|
@@ -23,10 +23,7 @@ import {
|
|
|
23
23
|
import { dirname, join } from 'node:path';
|
|
24
24
|
import { spawn } from 'node:child_process';
|
|
25
25
|
|
|
26
|
-
import type {
|
|
27
|
-
Card,
|
|
28
|
-
FetchCardDetails,
|
|
29
|
-
} from '../interfaces/project-interfaces.js';
|
|
26
|
+
import type { Card } from '../interfaces/project-interfaces.js';
|
|
30
27
|
import type { CardType } from '../interfaces/resource-interfaces.js';
|
|
31
28
|
import { evaluateMacros } from '../macros/index.js';
|
|
32
29
|
import type { ExportPdfOptions } from '../interfaces/project-interfaces.js';
|
|
@@ -34,12 +31,20 @@ import { generateReportContent } from '../utils/report.js';
|
|
|
34
31
|
import { getStaticDirectoryPath, pdfReport } from '@cyberismo/assets';
|
|
35
32
|
import { Project } from '../containers/project.js';
|
|
36
33
|
import type { QueryResult } from '../types/queries.js';
|
|
37
|
-
import type { Show } from './
|
|
34
|
+
import type { Show } from './show.js';
|
|
38
35
|
import { sortItems } from '../utils/lexorank.js';
|
|
39
36
|
|
|
40
37
|
const attachmentFolder: string = 'a';
|
|
41
38
|
|
|
39
|
+
/**
|
|
40
|
+
* Handles all export commands.
|
|
41
|
+
*/
|
|
42
42
|
export class Export {
|
|
43
|
+
/**
|
|
44
|
+
* Creates an instance of export.
|
|
45
|
+
* @param project Project to use
|
|
46
|
+
* @param showCmd Instance of Export command to use.
|
|
47
|
+
*/
|
|
43
48
|
constructor(
|
|
44
49
|
protected project: Project,
|
|
45
50
|
protected showCmd: Show,
|
|
@@ -100,6 +105,56 @@ export class Export {
|
|
|
100
105
|
return content;
|
|
101
106
|
}
|
|
102
107
|
|
|
108
|
+
// Runs Ascii Doctor converter --> to PDF
|
|
109
|
+
private async runAsciidoctorPdf(content: string): Promise<Buffer> {
|
|
110
|
+
const staticRootDir = await getStaticDirectoryPath();
|
|
111
|
+
const proc = spawn(
|
|
112
|
+
'asciidoctor-pdf',
|
|
113
|
+
[
|
|
114
|
+
'-a',
|
|
115
|
+
'pdf-theme=cyberismo',
|
|
116
|
+
'-a',
|
|
117
|
+
`pdf-themesdir=${join(staticRootDir, 'pdf-themes')}`,
|
|
118
|
+
'-a',
|
|
119
|
+
`pdf-fontsdir=${join(staticRootDir, 'pdf-themes', 'fonts')};GEM_FONTS_DIR`,
|
|
120
|
+
'-',
|
|
121
|
+
],
|
|
122
|
+
{
|
|
123
|
+
timeout: 100000,
|
|
124
|
+
shell: process.platform === 'win32',
|
|
125
|
+
},
|
|
126
|
+
);
|
|
127
|
+
proc.stdin.end(content);
|
|
128
|
+
const result = await new Promise<Buffer>((resolve, reject) => {
|
|
129
|
+
const chunks: Buffer[] = [];
|
|
130
|
+
proc.stdout.on('data', (chunk) => {
|
|
131
|
+
chunks.push(chunk);
|
|
132
|
+
});
|
|
133
|
+
proc.stderr.on('data', (chunk) => {
|
|
134
|
+
process.stderr.write(chunk);
|
|
135
|
+
});
|
|
136
|
+
proc.on('error', (error) => {
|
|
137
|
+
if ('code' in error && error.code === 'ENOENT') {
|
|
138
|
+
reject(
|
|
139
|
+
new Error(
|
|
140
|
+
'Asciidoctor-pdf not found. Please install asciidoctor-pdf to use this feature.',
|
|
141
|
+
),
|
|
142
|
+
);
|
|
143
|
+
}
|
|
144
|
+
reject(error);
|
|
145
|
+
});
|
|
146
|
+
proc.on('close', (code) => {
|
|
147
|
+
if (code === 0) {
|
|
148
|
+
resolve(Buffer.concat(chunks));
|
|
149
|
+
} else {
|
|
150
|
+
reject(new Error(`Asciidoctor-pdf failed with code ${code}`));
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
});
|
|
154
|
+
return result;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
// Adds cards to an ADOC file as additional content.
|
|
103
158
|
private async toAdocFileAsContent(path: string, cards: Card[]) {
|
|
104
159
|
for (const card of cards) {
|
|
105
160
|
let fileContent = '';
|
|
@@ -111,9 +166,9 @@ export class Export {
|
|
|
111
166
|
}
|
|
112
167
|
|
|
113
168
|
if (card.metadata) {
|
|
114
|
-
const cardTypeForCard =
|
|
115
|
-
card.metadata?.cardType,
|
|
116
|
-
|
|
169
|
+
const cardTypeForCard = this.project.resources
|
|
170
|
+
.byType(card.metadata?.cardType, 'cardTypes')
|
|
171
|
+
.show();
|
|
117
172
|
const metaDataContent = this.metaToAdoc(card, cardTypeForCard);
|
|
118
173
|
fileContent += metaDataContent;
|
|
119
174
|
}
|
|
@@ -144,7 +199,10 @@ export class Export {
|
|
|
144
199
|
}
|
|
145
200
|
|
|
146
201
|
if (card.children) {
|
|
147
|
-
await this.toAdocFileAsContent(
|
|
202
|
+
await this.toAdocFileAsContent(
|
|
203
|
+
path,
|
|
204
|
+
this.project.cardKeysToCards(card.children),
|
|
205
|
+
);
|
|
148
206
|
}
|
|
149
207
|
}
|
|
150
208
|
}
|
|
@@ -177,6 +235,7 @@ export class Export {
|
|
|
177
235
|
* Convert treeQueryResult object into a Card object and add content, metadata & attachments
|
|
178
236
|
* Handles card children recursively
|
|
179
237
|
* @param treeQueryResult tree query result object
|
|
238
|
+
* @returns Tree query result as a Card.
|
|
180
239
|
*/
|
|
181
240
|
protected async treeQueryResultToCard(
|
|
182
241
|
treeQueryResult: QueryResult<'tree'>,
|
|
@@ -187,22 +246,7 @@ export class Export {
|
|
|
187
246
|
children: [],
|
|
188
247
|
attachments: [],
|
|
189
248
|
};
|
|
190
|
-
|
|
191
|
-
// Get content and attachments separately, not included in queries
|
|
192
|
-
const fetchCardDetails: FetchCardDetails = {
|
|
193
|
-
attachments: true,
|
|
194
|
-
children: false,
|
|
195
|
-
content: true,
|
|
196
|
-
contentType: 'adoc',
|
|
197
|
-
metadata: true,
|
|
198
|
-
parent: false,
|
|
199
|
-
};
|
|
200
|
-
|
|
201
|
-
const cardDetailsResponse = await this.showCmd.showCardDetails(
|
|
202
|
-
fetchCardDetails,
|
|
203
|
-
card.key,
|
|
204
|
-
);
|
|
205
|
-
|
|
249
|
+
const cardDetailsResponse = this.showCmd.showCardDetails(card.key, 'adoc');
|
|
206
250
|
let asciiDocContent = '';
|
|
207
251
|
const project = this.project;
|
|
208
252
|
try {
|
|
@@ -227,60 +271,12 @@ export class Export {
|
|
|
227
271
|
card.attachments = cardDetailsResponse.attachments;
|
|
228
272
|
|
|
229
273
|
for (const result of treeQueryResult.children ?? []) {
|
|
230
|
-
card.children!.push(await this.treeQueryResultToCard(result));
|
|
274
|
+
card.children!.push((await this.treeQueryResultToCard(result)).key);
|
|
231
275
|
}
|
|
232
276
|
|
|
233
277
|
return card;
|
|
234
278
|
}
|
|
235
279
|
|
|
236
|
-
private async runAsciidoctorPdf(content: string): Promise<Buffer> {
|
|
237
|
-
const staticRootDir = await getStaticDirectoryPath();
|
|
238
|
-
const proc = spawn(
|
|
239
|
-
'asciidoctor-pdf',
|
|
240
|
-
[
|
|
241
|
-
'-a',
|
|
242
|
-
'pdf-theme=cyberismo',
|
|
243
|
-
'-a',
|
|
244
|
-
`pdf-themesdir=${join(staticRootDir, 'pdf-themes')}`,
|
|
245
|
-
'-a',
|
|
246
|
-
`pdf-fontsdir=${join(staticRootDir, 'pdf-themes', 'fonts')};GEM_FONTS_DIR`,
|
|
247
|
-
'-',
|
|
248
|
-
],
|
|
249
|
-
{
|
|
250
|
-
timeout: 100000,
|
|
251
|
-
shell: process.platform === 'win32',
|
|
252
|
-
},
|
|
253
|
-
);
|
|
254
|
-
proc.stdin.end(content);
|
|
255
|
-
const result = await new Promise<Buffer>((resolve, reject) => {
|
|
256
|
-
const chunks: Buffer[] = [];
|
|
257
|
-
proc.stdout.on('data', (chunk) => {
|
|
258
|
-
chunks.push(chunk);
|
|
259
|
-
});
|
|
260
|
-
proc.stderr.on('data', (chunk) => {
|
|
261
|
-
process.stderr.write(chunk);
|
|
262
|
-
});
|
|
263
|
-
proc.on('error', (error) => {
|
|
264
|
-
if ('code' in error && error.code === 'ENOENT') {
|
|
265
|
-
reject(
|
|
266
|
-
new Error(
|
|
267
|
-
'Asciidoctor-pdf not found. Please install asciidoctor-pdf to use this feature.',
|
|
268
|
-
),
|
|
269
|
-
);
|
|
270
|
-
}
|
|
271
|
-
reject(error);
|
|
272
|
-
});
|
|
273
|
-
proc.on('close', (code) => {
|
|
274
|
-
if (code === 0) {
|
|
275
|
-
resolve(Buffer.concat(chunks));
|
|
276
|
-
} else {
|
|
277
|
-
reject(new Error(`Asciidoctor-pdf failed with code ${code}`));
|
|
278
|
-
}
|
|
279
|
-
});
|
|
280
|
-
});
|
|
281
|
-
return result;
|
|
282
|
-
}
|
|
283
|
-
|
|
284
280
|
/**
|
|
285
281
|
* Exports the card(s) to pdf.
|
|
286
282
|
* @param destination Path to where the resulting file(s) will be created.
|
|
@@ -332,13 +328,7 @@ export class Export {
|
|
|
332
328
|
let cards: Card[] = [];
|
|
333
329
|
|
|
334
330
|
// If doing a partial tree export, put the parent information as it would have already been gathered.
|
|
335
|
-
if (cardKey) {
|
|
336
|
-
const card = await this.project.findSpecificCard(cardKey);
|
|
337
|
-
if (!card) {
|
|
338
|
-
throw new Error(
|
|
339
|
-
`Input validation error: cannot find card '${cardKey}'`,
|
|
340
|
-
);
|
|
341
|
-
}
|
|
331
|
+
if (cardKey && this.project.findCard(cardKey)) {
|
|
342
332
|
cards.push({
|
|
343
333
|
key: cardKey,
|
|
344
334
|
path: sourcePath,
|
package/src/commands/import.ts
CHANGED
|
@@ -11,20 +11,28 @@
|
|
|
11
11
|
License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
12
12
|
*/
|
|
13
13
|
|
|
14
|
-
import type { CardType } from '../interfaces/resource-interfaces.js';
|
|
15
|
-
import { type Create, Validate } from './index.js';
|
|
16
14
|
import { ModuleManager } from '../module-manager.js';
|
|
15
|
+
import { readCsvFile } from '../utils/csv.js';
|
|
16
|
+
import { Validate } from './validate.js';
|
|
17
|
+
|
|
18
|
+
import type { Create } from './create.js';
|
|
17
19
|
import type {
|
|
18
20
|
Credentials,
|
|
19
21
|
ModuleSettingOptions,
|
|
20
22
|
} from '../interfaces/project-interfaces.js';
|
|
21
23
|
import type { Project } from '../containers/project.js';
|
|
22
|
-
import { readCsvFile } from '../utils/csv.js';
|
|
23
|
-
import { resourceName } from '../utils/resource-utils.js';
|
|
24
|
-
import { TemplateResource } from '../resources/template-resource.js';
|
|
25
24
|
|
|
25
|
+
/**
|
|
26
|
+
* Handles all import commands.
|
|
27
|
+
*/
|
|
26
28
|
export class Import {
|
|
27
29
|
private moduleManager: ModuleManager;
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Creates an instance of Import.
|
|
33
|
+
* @param project Project to use.
|
|
34
|
+
* @param createCmd Instance of Create to use.
|
|
35
|
+
*/
|
|
28
36
|
constructor(
|
|
29
37
|
private project: Project,
|
|
30
38
|
private createCmd: Create,
|
|
@@ -53,16 +61,16 @@ export class Import {
|
|
|
53
61
|
|
|
54
62
|
for (const row of csv) {
|
|
55
63
|
const { title, template, description, labels, ...customFields } = row;
|
|
56
|
-
const templateResource =
|
|
57
|
-
|
|
58
|
-
|
|
64
|
+
const templateResource = this.project.resources.byType(
|
|
65
|
+
template,
|
|
66
|
+
'templates',
|
|
59
67
|
);
|
|
60
68
|
const templateObject = templateResource.templateObject();
|
|
61
69
|
if (!templateObject) {
|
|
62
70
|
throw new Error(`Template '${template}' not found`);
|
|
63
71
|
}
|
|
64
72
|
|
|
65
|
-
const templateCards =
|
|
73
|
+
const templateCards = templateObject.cards();
|
|
66
74
|
if (templateCards.length !== 1) {
|
|
67
75
|
console.warn(
|
|
68
76
|
`Template '${template}' for card '${title}' does not have exactly one card. Skipping row.`,
|
|
@@ -77,16 +85,13 @@ export class Import {
|
|
|
77
85
|
throw new Error('Card not created');
|
|
78
86
|
}
|
|
79
87
|
const cardKey = cards[0].key;
|
|
80
|
-
const card =
|
|
81
|
-
|
|
82
|
-
});
|
|
83
|
-
const cardType = await this.project.resource<CardType>(
|
|
84
|
-
card?.metadata?.cardType || '',
|
|
85
|
-
);
|
|
86
|
-
|
|
87
|
-
if (!cardType) {
|
|
88
|
+
const card = this.project.findCard(cardKey);
|
|
89
|
+
if (!card.metadata?.cardType) {
|
|
88
90
|
throw new Error(`Card type not found for card ${cardKey}`);
|
|
89
91
|
}
|
|
92
|
+
const cardType = this.project.resources
|
|
93
|
+
.byType(card.metadata?.cardType, 'cardTypes')
|
|
94
|
+
.show();
|
|
90
95
|
|
|
91
96
|
if (description) {
|
|
92
97
|
await this.project.updateCardContent(cardKey, description);
|
|
@@ -157,7 +162,10 @@ export class Import {
|
|
|
157
162
|
};
|
|
158
163
|
|
|
159
164
|
// Fetch module dependencies.
|
|
160
|
-
await this.moduleManager.
|
|
165
|
+
await this.moduleManager.updateDependencies(
|
|
166
|
+
moduleSettings,
|
|
167
|
+
options?.credentials,
|
|
168
|
+
);
|
|
161
169
|
|
|
162
170
|
// Add module as a dependency.
|
|
163
171
|
await this.project.importModule(moduleSettings);
|