@cyberismo/data-handler 0.0.8 → 0.0.10
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.d.ts +11 -2
- package/dist/command-handler.js +61 -18
- package/dist/command-handler.js.map +1 -1
- package/dist/command-manager.js +8 -8
- package/dist/command-manager.js.map +1 -1
- package/dist/commands/calculate.d.ts +7 -44
- package/dist/commands/calculate.js +8 -389
- package/dist/commands/calculate.js.map +1 -1
- package/dist/commands/create.d.ts +6 -3
- package/dist/commands/create.js +27 -5
- package/dist/commands/create.js.map +1 -1
- package/dist/commands/edit.d.ts +15 -3
- package/dist/commands/edit.js +52 -9
- package/dist/commands/edit.js.map +1 -1
- package/dist/commands/export.d.ts +11 -9
- package/dist/commands/export.js +80 -28
- package/dist/commands/export.js.map +1 -1
- package/dist/commands/import.d.ts +7 -0
- package/dist/commands/import.js +13 -0
- package/dist/commands/import.js.map +1 -1
- package/dist/commands/move.d.ts +11 -12
- package/dist/commands/move.js +12 -13
- package/dist/commands/move.js.map +1 -1
- package/dist/commands/remove.d.ts +1 -3
- package/dist/commands/remove.js +4 -6
- package/dist/commands/remove.js.map +1 -1
- package/dist/commands/rename.d.ts +1 -3
- package/dist/commands/rename.js +3 -6
- package/dist/commands/rename.js.map +1 -1
- package/dist/commands/show.d.ts +37 -5
- package/dist/commands/show.js +89 -8
- package/dist/commands/show.js.map +1 -1
- package/dist/commands/transition.d.ts +1 -3
- package/dist/commands/transition.js +3 -5
- package/dist/commands/transition.js.map +1 -1
- package/dist/commands/update.d.ts +5 -1
- package/dist/commands/update.js +7 -1
- package/dist/commands/update.js.map +1 -1
- package/dist/commands/validate.d.ts +7 -0
- package/dist/commands/validate.js +31 -4
- package/dist/commands/validate.js.map +1 -1
- package/dist/containers/card-container.d.ts +6 -0
- package/dist/containers/card-container.js +61 -0
- package/dist/containers/card-container.js.map +1 -1
- package/dist/containers/project/calculation-engine.d.ts +90 -0
- package/dist/containers/project/calculation-engine.js +402 -0
- package/dist/containers/project/calculation-engine.js.map +1 -0
- package/dist/containers/project/resource-collector.js +9 -13
- package/dist/containers/project/resource-collector.js.map +1 -1
- package/dist/containers/project.d.ts +18 -1
- package/dist/containers/project.js +28 -55
- package/dist/containers/project.js.map +1 -1
- package/dist/containers/template.d.ts +5 -0
- package/dist/containers/template.js +9 -0
- package/dist/containers/template.js.map +1 -1
- package/dist/index.d.ts +5 -2
- package/dist/index.js +5 -1
- package/dist/index.js.map +1 -1
- package/dist/interfaces/macros.d.ts +4 -2
- package/dist/interfaces/project-interfaces.d.ts +21 -0
- package/dist/interfaces/project-interfaces.js +4 -0
- package/dist/interfaces/project-interfaces.js.map +1 -1
- package/dist/interfaces/resource-interfaces.d.ts +4 -2
- package/dist/interfaces/resource-interfaces.js.map +1 -1
- package/dist/macros/base-macro.d.ts +2 -1
- package/dist/macros/base-macro.js +14 -2
- package/dist/macros/base-macro.js.map +1 -1
- package/dist/macros/common.d.ts +16 -9
- package/dist/macros/common.js +22 -9
- package/dist/macros/common.js.map +1 -1
- package/dist/macros/createCards/index.d.ts +2 -2
- package/dist/macros/createCards/index.js +4 -0
- package/dist/macros/createCards/index.js.map +1 -1
- package/dist/macros/graph/index.d.ts +1 -3
- package/dist/macros/graph/index.js +1 -6
- package/dist/macros/graph/index.js.map +1 -1
- package/dist/macros/image/index.d.ts +39 -0
- package/dist/macros/image/index.js +82 -0
- package/dist/macros/image/index.js.map +1 -0
- package/dist/macros/image/metadata.d.ts +18 -0
- package/dist/macros/image/metadata.js +22 -0
- package/dist/macros/image/metadata.js.map +1 -0
- package/dist/macros/include/index.d.ts +31 -0
- package/dist/macros/include/index.js +94 -0
- package/dist/macros/include/index.js.map +1 -0
- package/dist/macros/include/metadata.d.ts +15 -0
- package/dist/macros/include/metadata.js +19 -0
- package/dist/macros/include/metadata.js.map +1 -0
- package/dist/macros/index.d.ts +33 -31
- package/dist/macros/index.js +142 -71
- package/dist/macros/index.js.map +1 -1
- package/dist/macros/percentage/index.d.ts +28 -0
- package/dist/macros/percentage/index.js +33 -0
- package/dist/macros/percentage/index.js.map +1 -0
- package/dist/macros/percentage/metadata.d.ts +15 -0
- package/dist/macros/percentage/metadata.js +19 -0
- package/dist/macros/percentage/metadata.js.map +1 -0
- package/dist/macros/report/index.d.ts +2 -6
- package/dist/macros/report/index.js +3 -7
- package/dist/macros/report/index.js.map +1 -1
- package/dist/macros/scoreCard/index.d.ts +14 -15
- package/dist/macros/scoreCard/index.js +14 -18
- package/dist/macros/scoreCard/index.js.map +1 -1
- package/dist/macros/vega/index.d.ts +28 -0
- package/dist/macros/vega/index.js +27 -0
- package/dist/macros/vega/index.js.map +1 -0
- package/dist/macros/vega/metadata.d.ts +15 -0
- package/dist/macros/vega/metadata.js +7 -0
- package/dist/macros/vega/metadata.js.map +1 -0
- package/dist/macros/vegalite/index.d.ts +26 -0
- package/dist/macros/vegalite/index.js +24 -0
- package/dist/macros/vegalite/index.js.map +1 -0
- package/dist/macros/vegalite/metadata.d.ts +15 -0
- package/dist/macros/vegalite/metadata.js +7 -0
- package/dist/macros/vegalite/metadata.js.map +1 -0
- package/dist/macros/xref/index.d.ts +26 -0
- package/dist/macros/xref/index.js +53 -0
- package/dist/macros/xref/index.js.map +1 -0
- package/dist/macros/xref/metadata.d.ts +15 -0
- package/dist/macros/xref/metadata.js +19 -0
- package/dist/macros/xref/metadata.js.map +1 -0
- package/dist/module-manager.d.ts +1 -0
- package/dist/module-manager.js +14 -4
- package/dist/module-manager.js.map +1 -1
- package/dist/permissions/action-guard.d.ts +2 -2
- package/dist/permissions/action-guard.js +1 -1
- package/dist/permissions/action-guard.js.map +1 -1
- package/dist/resources/card-type-resource.d.ts +2 -0
- package/dist/resources/card-type-resource.js +63 -0
- package/dist/resources/card-type-resource.js.map +1 -1
- package/dist/resources/file-resource.d.ts +2 -0
- package/dist/resources/file-resource.js +12 -4
- package/dist/resources/file-resource.js.map +1 -1
- package/dist/resources/folder-resource.d.ts +19 -0
- package/dist/resources/folder-resource.js +51 -2
- package/dist/resources/folder-resource.js.map +1 -1
- package/dist/resources/graph-model-resource.js +1 -1
- package/dist/resources/graph-model-resource.js.map +1 -1
- package/dist/resources/graph-view-resource.js +1 -1
- package/dist/resources/graph-view-resource.js.map +1 -1
- package/dist/resources/report-resource.js +1 -1
- package/dist/resources/report-resource.js.map +1 -1
- package/dist/resources/resource-object.d.ts +8 -0
- package/dist/resources/resource-object.js +10 -1
- package/dist/resources/resource-object.js.map +1 -1
- package/dist/resources/template-resource.js +1 -1
- package/dist/resources/template-resource.js.map +1 -1
- package/dist/resources/workflow-resource.d.ts +2 -0
- package/dist/resources/workflow-resource.js +53 -9
- package/dist/resources/workflow-resource.js.map +1 -1
- package/dist/svg/index.d.ts +15 -0
- package/dist/svg/index.js +16 -0
- package/dist/svg/index.js.map +1 -0
- package/dist/svg/lib.d.ts +9 -0
- package/dist/svg/lib.js +26 -0
- package/dist/svg/lib.js.map +1 -0
- package/dist/svg/percentage.d.ts +25 -0
- package/dist/svg/percentage.js +90 -0
- package/dist/svg/percentage.js.map +1 -0
- package/dist/svg/scoreCard.d.ts +19 -0
- package/dist/svg/scoreCard.js +55 -0
- package/dist/svg/scoreCard.js.map +1 -0
- package/dist/types/queries.d.ts +8 -7
- package/dist/types/queries.js.map +1 -1
- package/dist/utils/card-utils.d.ts +6 -0
- package/dist/utils/card-utils.js +12 -0
- package/dist/utils/card-utils.js.map +1 -1
- package/dist/utils/clingo-facts.d.ts +2 -1
- package/dist/utils/clingo-facts.js +19 -2
- package/dist/utils/clingo-facts.js.map +1 -1
- package/dist/utils/clingo-parser.d.ts +1 -0
- package/dist/utils/clingo-parser.js +22 -100
- package/dist/utils/clingo-parser.js.map +1 -1
- package/dist/utils/constants.d.ts +7 -0
- package/dist/utils/constants.js +14 -0
- package/dist/utils/constants.js.map +1 -1
- package/dist/utils/csv.js.map +1 -1
- package/dist/utils/report.d.ts +17 -3
- package/dist/utils/report.js +38 -2
- package/dist/utils/report.js.map +1 -1
- package/dist/utils/resource-utils.d.ts +2 -1
- package/dist/utils/resource-utils.js +12 -3
- package/dist/utils/resource-utils.js.map +1 -1
- package/dist/utils/user-preferences.d.ts +1 -11
- package/dist/utils/user-preferences.js +30 -13
- package/dist/utils/user-preferences.js.map +1 -1
- package/dist/utils/validate.d.ts +2 -3
- package/dist/utils/validate.js +2 -2
- package/dist/utils/validate.js.map +1 -1
- package/package.json +8 -6
- package/src/command-handler.ts +96 -17
- package/src/command-manager.ts +8 -8
- package/src/commands/calculate.ts +11 -525
- package/src/commands/create.ts +35 -6
- package/src/commands/edit.ts +94 -11
- package/src/commands/export.ts +104 -31
- package/src/commands/import.ts +16 -0
- package/src/commands/move.ts +12 -15
- package/src/commands/remove.ts +4 -8
- package/src/commands/rename.ts +3 -12
- package/src/commands/show.ts +126 -9
- package/src/commands/transition.ts +3 -7
- package/src/commands/update.ts +6 -0
- package/src/commands/validate.ts +41 -13
- package/src/containers/card-container.ts +74 -0
- package/src/containers/project/calculation-engine.ts +535 -0
- package/src/containers/project/resource-collector.ts +13 -15
- package/src/containers/project.ts +30 -66
- package/src/containers/template.ts +16 -0
- package/src/index.ts +13 -2
- package/src/interfaces/macros.ts +4 -1
- package/src/interfaces/project-interfaces.ts +27 -0
- package/src/interfaces/resource-interfaces.ts +5 -2
- package/src/macros/base-macro.ts +19 -4
- package/src/macros/common.ts +22 -9
- package/src/macros/createCards/index.ts +6 -2
- package/src/macros/graph/index.ts +6 -10
- package/src/macros/image/index.ts +128 -0
- package/src/macros/image/metadata.ts +25 -0
- package/src/macros/include/index.ts +143 -0
- package/src/macros/include/metadata.ts +22 -0
- package/src/macros/index.ts +150 -98
- package/src/macros/percentage/index.ts +50 -0
- package/src/macros/percentage/metadata.ts +22 -0
- package/src/macros/report/index.ts +4 -12
- package/src/macros/scoreCard/index.ts +21 -25
- package/src/macros/vega/index.ts +55 -0
- package/src/macros/vega/metadata.ts +21 -0
- package/src/macros/vegalite/index.ts +46 -0
- package/src/macros/vegalite/metadata.ts +21 -0
- package/src/macros/xref/index.ts +73 -0
- package/src/macros/xref/metadata.ts +22 -0
- package/src/module-manager.ts +15 -5
- package/src/permissions/action-guard.ts +3 -3
- package/src/resources/card-type-resource.ts +100 -0
- package/src/resources/file-resource.ts +16 -4
- package/src/resources/folder-resource.ts +59 -2
- package/src/resources/graph-model-resource.ts +1 -1
- package/src/resources/graph-view-resource.ts +1 -1
- package/src/resources/report-resource.ts +1 -1
- package/src/resources/resource-object.ts +19 -1
- package/src/resources/template-resource.ts +1 -1
- package/src/resources/workflow-resource.ts +68 -13
- package/src/svg/index.ts +15 -0
- package/src/svg/lib.ts +31 -0
- package/src/svg/percentage.ts +97 -0
- package/src/svg/scoreCard.ts +88 -0
- package/src/types/queries.ts +8 -7
- package/src/types/string-pixel-width.d.ts +23 -0
- package/src/utils/card-utils.ts +13 -0
- package/src/utils/clingo-facts.ts +65 -3
- package/src/utils/clingo-parser.ts +31 -144
- package/src/utils/constants.ts +16 -0
- package/src/utils/csv.ts +1 -1
- package/src/utils/report.ts +45 -4
- package/src/utils/resource-utils.ts +12 -2
- package/src/utils/user-preferences.ts +32 -14
- package/src/utils/validate.ts +3 -3
package/src/commands/edit.ts
CHANGED
|
@@ -16,18 +16,62 @@ 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 {
|
|
20
|
-
|
|
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';
|
|
30
|
+
import { writeFile } from 'node:fs/promises';
|
|
23
31
|
|
|
24
32
|
export class Edit {
|
|
25
33
|
private project: Project;
|
|
26
|
-
private calculateCmd: Calculate;
|
|
27
34
|
|
|
28
|
-
constructor(project: Project
|
|
35
|
+
constructor(project: Project) {
|
|
29
36
|
this.project = project;
|
|
30
|
-
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Updates a calculation file.
|
|
41
|
+
* @param resourceName The name of the resource to update.
|
|
42
|
+
* @param changedContent The new content for the calculation.
|
|
43
|
+
*/
|
|
44
|
+
public async editCalculation(
|
|
45
|
+
resourceName: ResourceName,
|
|
46
|
+
changedContent: string,
|
|
47
|
+
) {
|
|
48
|
+
if (resourceName.prefix !== this.project.projectPrefix) {
|
|
49
|
+
throw new Error(
|
|
50
|
+
`Resource '${resourceName.identifier}' is not a local resource`,
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
const resourceNameString = resourceNameToString(resourceName);
|
|
54
|
+
if (
|
|
55
|
+
!(await this.project.resourceExists(
|
|
56
|
+
resourceName.type as ResourceFolderType,
|
|
57
|
+
resourceNameString,
|
|
58
|
+
))
|
|
59
|
+
) {
|
|
60
|
+
throw new Error(
|
|
61
|
+
`Resource '${resourceNameString}' does not exist in the project`,
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
await writeFile(
|
|
65
|
+
join(
|
|
66
|
+
this.project.paths.calculationProjectFolder,
|
|
67
|
+
resourceName.identifier + '.lp',
|
|
68
|
+
),
|
|
69
|
+
changedContent,
|
|
70
|
+
{
|
|
71
|
+
encoding: 'utf-8',
|
|
72
|
+
flag: 'r+',
|
|
73
|
+
},
|
|
74
|
+
);
|
|
31
75
|
}
|
|
32
76
|
|
|
33
77
|
/**
|
|
@@ -83,13 +127,16 @@ export class Edit {
|
|
|
83
127
|
* @param changedContent New content for the card.
|
|
84
128
|
*/
|
|
85
129
|
public async editCardContent(cardKey: string, changedContent: string) {
|
|
86
|
-
|
|
130
|
+
const isTemplateCard = await this.project.isTemplateCard(cardKey);
|
|
131
|
+
if (isTemplateCard) {
|
|
132
|
+
return this.project.updateCardContent(cardKey, changedContent);
|
|
133
|
+
}
|
|
87
134
|
const cardPath = this.project.pathToCard(cardKey);
|
|
88
135
|
if (!cardPath) {
|
|
89
136
|
throw new Error(`Card '${cardKey}' does not exist in the project`);
|
|
90
137
|
}
|
|
91
138
|
|
|
92
|
-
const actionGuard = new ActionGuard(this.
|
|
139
|
+
const actionGuard = new ActionGuard(this.project.calculationEngine);
|
|
93
140
|
await actionGuard.checkPermission('editContent', cardKey);
|
|
94
141
|
|
|
95
142
|
await this.project.updateCardContent(cardKey, changedContent);
|
|
@@ -106,18 +153,54 @@ export class Edit {
|
|
|
106
153
|
changedKey: string,
|
|
107
154
|
newValue: MetadataContent,
|
|
108
155
|
) {
|
|
156
|
+
if (!changedKey) {
|
|
157
|
+
throw new Error(`Changed key cannot be empty`);
|
|
158
|
+
}
|
|
159
|
+
const isTemplateCard = await this.project.isTemplateCard(cardKey);
|
|
160
|
+
if (isTemplateCard) {
|
|
161
|
+
return this.project.updateCardMetadataKey(cardKey, changedKey, newValue);
|
|
162
|
+
}
|
|
163
|
+
|
|
109
164
|
// Determine the card path
|
|
110
165
|
const cardPath = this.project.pathToCard(cardKey);
|
|
111
166
|
if (!cardPath) {
|
|
112
167
|
throw new Error(`Card '${cardKey}' does not exist in the project`);
|
|
113
168
|
}
|
|
114
|
-
if (!changedKey) {
|
|
115
|
-
throw new Error(`Changed key cannot be empty`);
|
|
116
|
-
}
|
|
117
169
|
|
|
118
170
|
// check for editing rights
|
|
119
|
-
const actionGuard = new ActionGuard(this.
|
|
171
|
+
const actionGuard = new ActionGuard(this.project.calculationEngine);
|
|
120
172
|
await actionGuard.checkPermission('editField', cardKey, changedKey);
|
|
121
173
|
await this.project.updateCardMetadataKey(cardKey, changedKey, newValue);
|
|
122
174
|
}
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* Update a file of a folder resource. Cannot be used to create a new file.
|
|
178
|
+
* @param resourceName The name of the resource to update.
|
|
179
|
+
* @param fileName The name of the file to update.
|
|
180
|
+
* @param changedContent The new content for the file.
|
|
181
|
+
*/
|
|
182
|
+
public async editResourceContent(
|
|
183
|
+
resourceName: ResourceName,
|
|
184
|
+
fileName: string,
|
|
185
|
+
changedContent: string,
|
|
186
|
+
) {
|
|
187
|
+
const resourceNameString = resourceNameToString(resourceName);
|
|
188
|
+
if (
|
|
189
|
+
!(await this.project.resourceExists(
|
|
190
|
+
resourceName.type as ResourceFolderType,
|
|
191
|
+
resourceNameString,
|
|
192
|
+
))
|
|
193
|
+
) {
|
|
194
|
+
throw new Error(
|
|
195
|
+
`Resource '${resourceNameString}' does not exist in the project`,
|
|
196
|
+
);
|
|
197
|
+
}
|
|
198
|
+
const resource = Project.resourceObject(this.project, resourceName);
|
|
199
|
+
if (!(resource instanceof FolderResource)) {
|
|
200
|
+
throw new Error(
|
|
201
|
+
`Resource '${resourceNameString}' is not a folder resource`,
|
|
202
|
+
);
|
|
203
|
+
}
|
|
204
|
+
return resource.updateFile(fileName, changedContent);
|
|
205
|
+
}
|
|
123
206
|
}
|
package/src/commands/export.ts
CHANGED
|
@@ -13,19 +13,28 @@
|
|
|
13
13
|
*/
|
|
14
14
|
|
|
15
15
|
// node
|
|
16
|
-
import {
|
|
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';
|
|
24
|
+
import { spawn } from 'node:child_process';
|
|
18
25
|
|
|
19
|
-
// asciidoctor
|
|
20
|
-
import Processor from '@asciidoctor/core';
|
|
21
|
-
import type { Calculate, Show } from './index.js';
|
|
22
26
|
import type {
|
|
23
27
|
Card,
|
|
24
28
|
FetchCardDetails,
|
|
25
29
|
} from '../interfaces/project-interfaces.js';
|
|
26
30
|
import type { CardType } from '../interfaces/resource-interfaces.js';
|
|
31
|
+
import { evaluateMacros } from '../macros/index.js';
|
|
32
|
+
import type { ExportPdfOptions } from '../interfaces/project-interfaces.js';
|
|
33
|
+
import { generateReportContent } from '../utils/report.js';
|
|
34
|
+
import { getStaticDirectoryPath, pdfReport } from '@cyberismo/assets';
|
|
27
35
|
import { Project } from '../containers/project.js';
|
|
28
36
|
import type { QueryResult } from '../types/queries.js';
|
|
37
|
+
import type { Show } from './index.js';
|
|
29
38
|
import { sortItems } from '../utils/lexorank.js';
|
|
30
39
|
|
|
31
40
|
const attachmentFolder: string = 'a';
|
|
@@ -33,7 +42,6 @@ const attachmentFolder: string = 'a';
|
|
|
33
42
|
export class Export {
|
|
34
43
|
constructor(
|
|
35
44
|
protected project: Project,
|
|
36
|
-
protected calculateCmd: Calculate,
|
|
37
45
|
protected showCmd: Show,
|
|
38
46
|
) {}
|
|
39
47
|
|
|
@@ -202,11 +210,11 @@ export class Export {
|
|
|
202
210
|
asciiDocContent = await evaluateMacros(
|
|
203
211
|
cardDetailsResponse.content || '',
|
|
204
212
|
{
|
|
213
|
+
context: 'exportedDocument',
|
|
205
214
|
mode: 'static',
|
|
206
215
|
project,
|
|
207
216
|
cardKey: card.key,
|
|
208
217
|
},
|
|
209
|
-
this.calculateCmd,
|
|
210
218
|
);
|
|
211
219
|
} catch (error) {
|
|
212
220
|
asciiDocContent = `Macro error: ${error instanceof Error ? error.message : 'Unknown error'}\n\n${asciiDocContent}`;
|
|
@@ -225,6 +233,91 @@ export class Export {
|
|
|
225
233
|
return card;
|
|
226
234
|
}
|
|
227
235
|
|
|
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
|
+
/**
|
|
285
|
+
* Exports the card(s) to pdf.
|
|
286
|
+
* @param destination Path to where the resulting file(s) will be created.
|
|
287
|
+
* @param options Export options.
|
|
288
|
+
* @returns status message
|
|
289
|
+
*/
|
|
290
|
+
public async exportPdf(
|
|
291
|
+
destination: string,
|
|
292
|
+
options: ExportPdfOptions,
|
|
293
|
+
): Promise<string> {
|
|
294
|
+
const opts = {
|
|
295
|
+
...options,
|
|
296
|
+
date: options.date?.toISOString().split('T')[0],
|
|
297
|
+
recursive: options.recursive ?? false,
|
|
298
|
+
};
|
|
299
|
+
|
|
300
|
+
await this.project.calculationEngine.generate();
|
|
301
|
+
|
|
302
|
+
const result = await generateReportContent({
|
|
303
|
+
calculate: this.project.calculationEngine,
|
|
304
|
+
contentTemplate: pdfReport.content,
|
|
305
|
+
queryTemplate: pdfReport.query,
|
|
306
|
+
context: 'exportedDocument',
|
|
307
|
+
options: opts,
|
|
308
|
+
});
|
|
309
|
+
|
|
310
|
+
const evaluated = await evaluateMacros(result, {
|
|
311
|
+
context: 'exportedDocument',
|
|
312
|
+
mode: 'static',
|
|
313
|
+
project: this.project,
|
|
314
|
+
cardKey: '', // top level report does not contain any macros that use cardKey
|
|
315
|
+
});
|
|
316
|
+
const pdf = await this.runAsciidoctorPdf(evaluated);
|
|
317
|
+
await writeFile(destination, pdf);
|
|
318
|
+
return `Content exported as PDF to ${destination}`;
|
|
319
|
+
}
|
|
320
|
+
|
|
228
321
|
/**
|
|
229
322
|
* Exports the card(s) to ascii doc.
|
|
230
323
|
* @param destination Path to where the resulting file(s) will be created.
|
|
@@ -254,8 +347,11 @@ export class Export {
|
|
|
254
347
|
});
|
|
255
348
|
}
|
|
256
349
|
|
|
257
|
-
await this.
|
|
258
|
-
const tree = await this.
|
|
350
|
+
await this.project.calculationEngine.generate();
|
|
351
|
+
const tree = await this.project.calculationEngine.runQuery(
|
|
352
|
+
'tree',
|
|
353
|
+
'exportedDocument',
|
|
354
|
+
);
|
|
259
355
|
|
|
260
356
|
if (cardKey) {
|
|
261
357
|
const targetCard = this.findCardInTree(tree, cardKey);
|
|
@@ -290,27 +386,4 @@ export class Export {
|
|
|
290
386
|
await this.toAdocFile(resultDocumentPath, cards);
|
|
291
387
|
return message;
|
|
292
388
|
}
|
|
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
389
|
}
|
package/src/commands/import.ts
CHANGED
|
@@ -172,6 +172,22 @@ export class Import {
|
|
|
172
172
|
}
|
|
173
173
|
}
|
|
174
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);
|
|
189
|
+
}
|
|
190
|
+
|
|
175
191
|
/**
|
|
176
192
|
* Updates all imported modules.
|
|
177
193
|
* @param credentials Optional credentials for private modules.
|
package/src/commands/move.ts
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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.
|
|
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
|
package/src/commands/remove.ts
CHANGED
|
@@ -15,7 +15,6 @@
|
|
|
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';
|
|
20
19
|
import { ModuleManager } from '../module-manager.js';
|
|
21
20
|
import { Project } from '../containers/project.js';
|
|
@@ -29,10 +28,7 @@ const MODULES_PATH = `${sep}modules${sep}`;
|
|
|
29
28
|
*/
|
|
30
29
|
export class Remove {
|
|
31
30
|
private moduleManager: ModuleManager;
|
|
32
|
-
constructor(
|
|
33
|
-
private project: Project,
|
|
34
|
-
private calculateCmd: Calculate,
|
|
35
|
-
) {
|
|
31
|
+
constructor(private project: Project) {
|
|
36
32
|
this.moduleManager = new ModuleManager(this.project);
|
|
37
33
|
}
|
|
38
34
|
|
|
@@ -87,7 +83,7 @@ export class Remove {
|
|
|
87
83
|
|
|
88
84
|
// Make sure card can be removed if it's a project card
|
|
89
85
|
if (!(await this.project.isTemplateCard(cardKey))) {
|
|
90
|
-
const actionGuard = new ActionGuard(this.
|
|
86
|
+
const actionGuard = new ActionGuard(this.project.calculationEngine);
|
|
91
87
|
await actionGuard.checkPermission('delete', cardKey);
|
|
92
88
|
}
|
|
93
89
|
|
|
@@ -115,10 +111,10 @@ export class Remove {
|
|
|
115
111
|
content: false,
|
|
116
112
|
parent: false,
|
|
117
113
|
});
|
|
114
|
+
await deleteDir(cardFolder);
|
|
118
115
|
if (card) {
|
|
119
|
-
await this.
|
|
116
|
+
await this.project.handleDeleteCard(card);
|
|
120
117
|
}
|
|
121
|
-
await deleteDir(cardFolder);
|
|
122
118
|
}
|
|
123
119
|
|
|
124
120
|
// removes label from project
|
package/src/commands/rename.ts
CHANGED
|
@@ -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.
|
|
367
|
+
return this.project.calculationEngine.generate();
|
|
377
368
|
}
|
|
378
369
|
}
|