@cyberismo/data-handler 0.0.2
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/LICENSE +702 -0
- package/dist/card-metadata-updater.d.ts +33 -0
- package/dist/card-metadata-updater.js +121 -0
- package/dist/card-metadata-updater.js.map +1 -0
- package/dist/command-handler.d.ts +96 -0
- package/dist/command-handler.js +557 -0
- package/dist/command-handler.js.map +1 -0
- package/dist/command-manager.d.ts +43 -0
- package/dist/command-manager.js +73 -0
- package/dist/command-manager.js.map +1 -0
- package/dist/commands/calculate.d.ts +86 -0
- package/dist/commands/calculate.js +444 -0
- package/dist/commands/calculate.js.map +1 -0
- package/dist/commands/create.d.ts +114 -0
- package/dist/commands/create.js +389 -0
- package/dist/commands/create.js.map +1 -0
- package/dist/commands/edit.d.ts +37 -0
- package/dist/commands/edit.js +99 -0
- package/dist/commands/edit.js.map +1 -0
- package/dist/commands/export-site.d.ts +45 -0
- package/dist/commands/export-site.js +301 -0
- package/dist/commands/export-site.js.map +1 -0
- package/dist/commands/export.d.ts +53 -0
- package/dist/commands/export.js +251 -0
- package/dist/commands/export.js.map +1 -0
- package/dist/commands/import.d.ts +53 -0
- package/dist/commands/import.js +133 -0
- package/dist/commands/import.js.map +1 -0
- package/dist/commands/index.d.ts +26 -0
- package/dist/commands/index.js +27 -0
- package/dist/commands/index.js.map +1 -0
- package/dist/commands/move.d.ts +55 -0
- package/dist/commands/move.js +341 -0
- package/dist/commands/move.js.map +1 -0
- package/dist/commands/remove.d.ts +38 -0
- package/dist/commands/remove.js +192 -0
- package/dist/commands/remove.js.map +1 -0
- package/dist/commands/rename.d.ts +46 -0
- package/dist/commands/rename.js +289 -0
- package/dist/commands/rename.js.map +1 -0
- package/dist/commands/show.d.ts +124 -0
- package/dist/commands/show.js +345 -0
- package/dist/commands/show.js.map +1 -0
- package/dist/commands/transition.d.ts +27 -0
- package/dist/commands/transition.js +92 -0
- package/dist/commands/transition.js.map +1 -0
- package/dist/commands/update.d.ts +29 -0
- package/dist/commands/update.js +64 -0
- package/dist/commands/update.js.map +1 -0
- package/dist/commands/validate.d.ts +143 -0
- package/dist/commands/validate.js +689 -0
- package/dist/commands/validate.js.map +1 -0
- package/dist/containers/card-container.d.ts +44 -0
- package/dist/containers/card-container.js +282 -0
- package/dist/containers/card-container.js.map +1 -0
- package/dist/containers/project/project-paths.d.ts +46 -0
- package/dist/containers/project/project-paths.js +105 -0
- package/dist/containers/project/project-paths.js.map +1 -0
- package/dist/containers/project/resource-collector.d.ts +86 -0
- package/dist/containers/project/resource-collector.js +331 -0
- package/dist/containers/project/resource-collector.js.map +1 -0
- package/dist/containers/project.d.ts +351 -0
- package/dist/containers/project.js +896 -0
- package/dist/containers/project.js.map +1 -0
- package/dist/containers/template.d.ts +108 -0
- package/dist/containers/template.js +433 -0
- package/dist/containers/template.js.map +1 -0
- package/dist/exceptions/index.d.ts +19 -0
- package/dist/exceptions/index.js +26 -0
- package/dist/exceptions/index.js.map +1 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.js +15 -0
- package/dist/index.js.map +1 -0
- package/dist/interfaces/adoc.d.ts +12 -0
- package/dist/interfaces/adoc.js +13 -0
- package/dist/interfaces/adoc.js.map +1 -0
- package/dist/interfaces/macros.d.ts +45 -0
- package/dist/interfaces/macros.js +13 -0
- package/dist/interfaces/macros.js.map +1 -0
- package/dist/interfaces/project-interfaces.d.ts +121 -0
- package/dist/interfaces/project-interfaces.js +21 -0
- package/dist/interfaces/project-interfaces.js.map +1 -0
- package/dist/interfaces/request-status-interfaces.d.ts +28 -0
- package/dist/interfaces/request-status-interfaces.js +20 -0
- package/dist/interfaces/request-status-interfaces.js.map +1 -0
- package/dist/interfaces/resource-interfaces.d.ts +117 -0
- package/dist/interfaces/resource-interfaces.js +20 -0
- package/dist/interfaces/resource-interfaces.js.map +1 -0
- package/dist/macros/base-macro.d.ts +31 -0
- package/dist/macros/base-macro.js +126 -0
- package/dist/macros/base-macro.js.map +1 -0
- package/dist/macros/common.d.ts +17 -0
- package/dist/macros/common.js +23 -0
- package/dist/macros/common.js.map +1 -0
- package/dist/macros/createCards/index.d.ts +36 -0
- package/dist/macros/createCards/index.js +35 -0
- package/dist/macros/createCards/index.js.map +1 -0
- package/dist/macros/createCards/metadata.d.ts +14 -0
- package/dist/macros/createCards/metadata.js +18 -0
- package/dist/macros/createCards/metadata.js.map +1 -0
- package/dist/macros/graph/index.d.ts +29 -0
- package/dist/macros/graph/index.js +91 -0
- package/dist/macros/graph/index.js.map +1 -0
- package/dist/macros/graph/metadata.d.ts +14 -0
- package/dist/macros/graph/metadata.js +18 -0
- package/dist/macros/graph/metadata.js.map +1 -0
- package/dist/macros/index.d.ts +93 -0
- package/dist/macros/index.js +237 -0
- package/dist/macros/index.js.map +1 -0
- package/dist/macros/report/index.d.ts +26 -0
- package/dist/macros/report/index.js +70 -0
- package/dist/macros/report/index.js.map +1 -0
- package/dist/macros/report/metadata.d.ts +14 -0
- package/dist/macros/report/metadata.js +18 -0
- package/dist/macros/report/metadata.js.map +1 -0
- package/dist/macros/scoreCard/index.d.ts +30 -0
- package/dist/macros/scoreCard/index.js +38 -0
- package/dist/macros/scoreCard/index.js.map +1 -0
- package/dist/macros/scoreCard/metadata.d.ts +14 -0
- package/dist/macros/scoreCard/metadata.js +18 -0
- package/dist/macros/scoreCard/metadata.js.map +1 -0
- package/dist/macros/task-queue.d.ts +46 -0
- package/dist/macros/task-queue.js +69 -0
- package/dist/macros/task-queue.js.map +1 -0
- package/dist/module-manager.d.ts +62 -0
- package/dist/module-manager.js +350 -0
- package/dist/module-manager.js.map +1 -0
- package/dist/permissions/action-guard.d.ts +28 -0
- package/dist/permissions/action-guard.js +61 -0
- package/dist/permissions/action-guard.js.map +1 -0
- package/dist/project-settings.d.ts +42 -0
- package/dist/project-settings.js +120 -0
- package/dist/project-settings.js.map +1 -0
- package/dist/resources/array-handler.d.ts +28 -0
- package/dist/resources/array-handler.js +116 -0
- package/dist/resources/array-handler.js.map +1 -0
- package/dist/resources/card-type-resource.d.ts +72 -0
- package/dist/resources/card-type-resource.js +334 -0
- package/dist/resources/card-type-resource.js.map +1 -0
- package/dist/resources/create-defaults.d.ts +81 -0
- package/dist/resources/create-defaults.js +184 -0
- package/dist/resources/create-defaults.js.map +1 -0
- package/dist/resources/field-type-resource.d.ts +88 -0
- package/dist/resources/field-type-resource.js +411 -0
- package/dist/resources/field-type-resource.js.map +1 -0
- package/dist/resources/file-resource.d.ts +50 -0
- package/dist/resources/file-resource.js +301 -0
- package/dist/resources/file-resource.js.map +1 -0
- package/dist/resources/folder-resource.d.ts +66 -0
- package/dist/resources/folder-resource.js +100 -0
- package/dist/resources/folder-resource.js.map +1 -0
- package/dist/resources/graph-model-resource.d.ts +78 -0
- package/dist/resources/graph-model-resource.js +164 -0
- package/dist/resources/graph-model-resource.js.map +1 -0
- package/dist/resources/graph-view-resource.d.ts +78 -0
- package/dist/resources/graph-view-resource.js +163 -0
- package/dist/resources/graph-view-resource.js.map +1 -0
- package/dist/resources/link-type-resource.d.ts +62 -0
- package/dist/resources/link-type-resource.js +150 -0
- package/dist/resources/link-type-resource.js.map +1 -0
- package/dist/resources/report-resource.d.ts +77 -0
- package/dist/resources/report-resource.js +171 -0
- package/dist/resources/report-resource.js.map +1 -0
- package/dist/resources/resource-object.d.ts +108 -0
- package/dist/resources/resource-object.js +147 -0
- package/dist/resources/resource-object.js.map +1 -0
- package/dist/resources/template-resource.d.ts +82 -0
- package/dist/resources/template-resource.js +173 -0
- package/dist/resources/template-resource.js.map +1 -0
- package/dist/resources/workflow-resource.d.ts +67 -0
- package/dist/resources/workflow-resource.js +156 -0
- package/dist/resources/workflow-resource.js.map +1 -0
- package/dist/types/queries.d.ts +142 -0
- package/dist/types/queries.js +16 -0
- package/dist/types/queries.js.map +1 -0
- package/dist/utils/card-utils.d.ts +34 -0
- package/dist/utils/card-utils.js +78 -0
- package/dist/utils/card-utils.js.map +1 -0
- package/dist/utils/clingo-fact-builder.d.ts +58 -0
- package/dist/utils/clingo-fact-builder.js +126 -0
- package/dist/utils/clingo-fact-builder.js.map +1 -0
- package/dist/utils/clingo-facts.d.ts +97 -0
- package/dist/utils/clingo-facts.js +352 -0
- package/dist/utils/clingo-facts.js.map +1 -0
- package/dist/utils/clingo-parser.d.ts +59 -0
- package/dist/utils/clingo-parser.js +403 -0
- package/dist/utils/clingo-parser.js.map +1 -0
- package/dist/utils/clingo-program-builder.d.ts +39 -0
- package/dist/utils/clingo-program-builder.js +57 -0
- package/dist/utils/clingo-program-builder.js.map +1 -0
- package/dist/utils/common-utils.d.ts +24 -0
- package/dist/utils/common-utils.js +47 -0
- package/dist/utils/common-utils.js.map +1 -0
- package/dist/utils/constants.d.ts +18 -0
- package/dist/utils/constants.js +27 -0
- package/dist/utils/constants.js.map +1 -0
- package/dist/utils/csv.d.ts +18 -0
- package/dist/utils/csv.js +45 -0
- package/dist/utils/csv.js.map +1 -0
- package/dist/utils/file-utils.d.ts +69 -0
- package/dist/utils/file-utils.js +158 -0
- package/dist/utils/file-utils.js.map +1 -0
- package/dist/utils/json.d.ts +61 -0
- package/dist/utils/json.js +108 -0
- package/dist/utils/json.js.map +1 -0
- package/dist/utils/lexorank.d.ts +59 -0
- package/dist/utils/lexorank.js +159 -0
- package/dist/utils/lexorank.js.map +1 -0
- package/dist/utils/log-utils.d.ts +40 -0
- package/dist/utils/log-utils.js +109 -0
- package/dist/utils/log-utils.js.map +1 -0
- package/dist/utils/random.d.ts +19 -0
- package/dist/utils/random.js +34 -0
- package/dist/utils/random.js.map +1 -0
- package/dist/utils/resource-utils.d.ts +45 -0
- package/dist/utils/resource-utils.js +137 -0
- package/dist/utils/resource-utils.js.map +1 -0
- package/dist/utils/sanitize-svg.d.ts +18 -0
- package/dist/utils/sanitize-svg.js +38 -0
- package/dist/utils/sanitize-svg.js.map +1 -0
- package/dist/utils/user-preferences.d.ts +64 -0
- package/dist/utils/user-preferences.js +106 -0
- package/dist/utils/user-preferences.js.map +1 -0
- package/dist/utils/validate.d.ts +26 -0
- package/dist/utils/validate.js +53 -0
- package/dist/utils/validate.js.map +1 -0
- package/dist/utils/value-utils.d.ts +58 -0
- package/dist/utils/value-utils.js +181 -0
- package/dist/utils/value-utils.js.map +1 -0
- package/package.json +67 -0
- package/src/card-metadata-updater.ts +182 -0
- package/src/command-handler.ts +686 -0
- package/src/command-manager.ts +99 -0
- package/src/commands/calculate.ts +591 -0
- package/src/commands/create.ts +559 -0
- package/src/commands/edit.ts +123 -0
- package/src/commands/export-site.ts +356 -0
- package/src/commands/export.ts +315 -0
- package/src/commands/import.ts +169 -0
- package/src/commands/index.ts +42 -0
- package/src/commands/move.ts +451 -0
- package/src/commands/remove.ts +244 -0
- package/src/commands/rename.ts +378 -0
- package/src/commands/show.ts +442 -0
- package/src/commands/transition.ts +127 -0
- package/src/commands/update.ts +76 -0
- package/src/commands/validate.ts +962 -0
- package/src/containers/card-container.ts +378 -0
- package/src/containers/project/project-paths.ts +127 -0
- package/src/containers/project/resource-collector.ts +379 -0
- package/src/containers/project.ts +1135 -0
- package/src/containers/template.ts +573 -0
- package/src/exceptions/index.ts +29 -0
- package/src/index.ts +33 -0
- package/src/interfaces/adoc.ts +18 -0
- package/src/interfaces/macros.ts +54 -0
- package/src/interfaces/project-interfaces.ts +208 -0
- package/src/interfaces/request-status-interfaces.ts +30 -0
- package/src/interfaces/resource-interfaces.ts +179 -0
- package/src/macros/base-macro.ts +176 -0
- package/src/macros/common.ts +24 -0
- package/src/macros/createCards/index.ts +57 -0
- package/src/macros/createCards/metadata.ts +21 -0
- package/src/macros/graph/index.ts +130 -0
- package/src/macros/graph/metadata.ts +21 -0
- package/src/macros/index.ts +321 -0
- package/src/macros/report/index.ts +88 -0
- package/src/macros/report/metadata.ts +21 -0
- package/src/macros/scoreCard/index.ts +55 -0
- package/src/macros/scoreCard/metadata.ts +21 -0
- package/src/macros/task-queue.ts +79 -0
- package/src/module-manager.ts +443 -0
- package/src/permissions/action-guard.ts +77 -0
- package/src/project-settings.ts +140 -0
- package/src/resources/array-handler.ts +141 -0
- package/src/resources/card-type-resource.ts +455 -0
- package/src/resources/create-defaults.ts +216 -0
- package/src/resources/field-type-resource.ts +533 -0
- package/src/resources/file-resource.ts +433 -0
- package/src/resources/folder-resource.ts +140 -0
- package/src/resources/graph-model-resource.ts +205 -0
- package/src/resources/graph-view-resource.ts +199 -0
- package/src/resources/link-type-resource.ts +191 -0
- package/src/resources/report-resource.ts +224 -0
- package/src/resources/resource-object.ts +246 -0
- package/src/resources/template-resource.ts +210 -0
- package/src/resources/workflow-resource.ts +205 -0
- package/src/types/queries.ts +149 -0
- package/src/utils/card-utils.ts +83 -0
- package/src/utils/clingo-fact-builder.ts +167 -0
- package/src/utils/clingo-facts.ts +550 -0
- package/src/utils/clingo-parser.ts +519 -0
- package/src/utils/clingo-program-builder.ts +71 -0
- package/src/utils/common-utils.ts +54 -0
- package/src/utils/constants.ts +32 -0
- package/src/utils/csv.ts +53 -0
- package/src/utils/file-utils.ts +182 -0
- package/src/utils/json.ts +118 -0
- package/src/utils/lexorank.ts +180 -0
- package/src/utils/log-utils.ts +127 -0
- package/src/utils/random.ts +37 -0
- package/src/utils/resource-utils.ts +180 -0
- package/src/utils/sanitize-svg.ts +46 -0
- package/src/utils/user-preferences.ts +126 -0
- package/src/utils/validate.ts +66 -0
- package/src/utils/value-utils.ts +189 -0
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
Cyberismo
|
|
3
|
+
Copyright © Cyberismo Ltd and contributors 2025
|
|
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. This program is distributed in the hope that it
|
|
7
|
+
will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
|
|
8
|
+
of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
9
|
+
See the GNU Affero General Public License for more details.
|
|
10
|
+
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/>.
|
|
12
|
+
*/
|
|
13
|
+
import type { Import } from './commands/index.js';
|
|
14
|
+
import type { ModuleSettingOptions } from './interfaces/project-interfaces.js';
|
|
15
|
+
import { Project } from './containers/project.js';
|
|
16
|
+
/**
|
|
17
|
+
* Class that handles module updates and imports.
|
|
18
|
+
*/
|
|
19
|
+
export declare class ModuleManager {
|
|
20
|
+
private project;
|
|
21
|
+
private importCmd;
|
|
22
|
+
private modules;
|
|
23
|
+
private tempModulesDir;
|
|
24
|
+
constructor(project: Project, importCmd: Import);
|
|
25
|
+
private addFileContents;
|
|
26
|
+
private branch;
|
|
27
|
+
private clone;
|
|
28
|
+
private collectModulePrefixes;
|
|
29
|
+
private configuration;
|
|
30
|
+
private doCollectModulePrefix;
|
|
31
|
+
private handleFileModule;
|
|
32
|
+
private handleGitModule;
|
|
33
|
+
private handleModule;
|
|
34
|
+
private importFromFolder;
|
|
35
|
+
private importFromTemp;
|
|
36
|
+
private isFileModule;
|
|
37
|
+
private prepare;
|
|
38
|
+
private protocol;
|
|
39
|
+
private remove;
|
|
40
|
+
private removeModuleFiles;
|
|
41
|
+
private removeProtocolFromLocation;
|
|
42
|
+
private removeDuplicates;
|
|
43
|
+
private repositoryName;
|
|
44
|
+
private validatePrefix;
|
|
45
|
+
/**
|
|
46
|
+
* Imports module from local file path.
|
|
47
|
+
* @param source Path to import from.
|
|
48
|
+
* @param destination is this really needed???
|
|
49
|
+
*/
|
|
50
|
+
importFileModule(source: string, destination?: string): Promise<string>;
|
|
51
|
+
/**
|
|
52
|
+
* Imports module from gitUrl.
|
|
53
|
+
* @param source Git URL to import from.
|
|
54
|
+
* @param options Modules setting options.
|
|
55
|
+
* @returns module prefix as defined in its CardsConfig.json
|
|
56
|
+
*/
|
|
57
|
+
importGitModule(source: string, options?: ModuleSettingOptions): Promise<string>;
|
|
58
|
+
/**
|
|
59
|
+
* Updates all imported modules.
|
|
60
|
+
*/
|
|
61
|
+
update(): Promise<void>;
|
|
62
|
+
}
|
|
@@ -0,0 +1,350 @@
|
|
|
1
|
+
/**
|
|
2
|
+
Cyberismo
|
|
3
|
+
Copyright © Cyberismo Ltd and contributors 2025
|
|
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. This program is distributed in the hope that it
|
|
7
|
+
will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
|
|
8
|
+
of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
9
|
+
See the GNU Affero General Public License for more details.
|
|
10
|
+
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/>.
|
|
12
|
+
*/
|
|
13
|
+
import fs from 'node:fs';
|
|
14
|
+
import { join } from 'node:path';
|
|
15
|
+
import { mkdir, readdir, rm } from 'node:fs/promises';
|
|
16
|
+
import git from 'isomorphic-git';
|
|
17
|
+
import http from 'isomorphic-git/http/node/index.js';
|
|
18
|
+
import { copyDir, deleteDir, pathExists } from './utils/file-utils.js';
|
|
19
|
+
import { Project } from './containers/project.js';
|
|
20
|
+
import { ProjectPaths } from './containers/project/project-paths.js';
|
|
21
|
+
import { readJsonFile } from './utils/json.js';
|
|
22
|
+
import { Validate } from './commands/index.js';
|
|
23
|
+
const FILE_PROTOCOL = 'file:';
|
|
24
|
+
// todo: add support for git's default branch.
|
|
25
|
+
const MAIN_BRANCH = 'main';
|
|
26
|
+
/**
|
|
27
|
+
* Class that handles module updates and imports.
|
|
28
|
+
*/
|
|
29
|
+
export class ModuleManager {
|
|
30
|
+
project;
|
|
31
|
+
importCmd;
|
|
32
|
+
modules = [];
|
|
33
|
+
tempModulesDir = '';
|
|
34
|
+
constructor(project, importCmd) {
|
|
35
|
+
this.project = project;
|
|
36
|
+
this.importCmd = importCmd;
|
|
37
|
+
this.tempModulesDir = join(this.project.paths.tempFolder, 'modules');
|
|
38
|
+
}
|
|
39
|
+
// Copies module files into project directories.
|
|
40
|
+
async addFileContents(sourcePath, destinationPath) {
|
|
41
|
+
// Copy files.
|
|
42
|
+
await copyDir(sourcePath, destinationPath);
|
|
43
|
+
// Update the resources.
|
|
44
|
+
await this.project.collectModuleResources();
|
|
45
|
+
}
|
|
46
|
+
// Handles a branch of a repository.
|
|
47
|
+
async branch(module) {
|
|
48
|
+
if (module.branch === MAIN_BRANCH || module.branch === '' || !module.branch)
|
|
49
|
+
return;
|
|
50
|
+
await git.checkout({
|
|
51
|
+
fs,
|
|
52
|
+
dir: join(this.tempModulesDir, module.name),
|
|
53
|
+
ref: module.branch,
|
|
54
|
+
});
|
|
55
|
+
console.error(`... Switched to '${module.branch}' branch for module '${module.name}'`);
|
|
56
|
+
}
|
|
57
|
+
// Handles cloning of a repository.
|
|
58
|
+
async clone(module, verbose = true) {
|
|
59
|
+
if (!module.name || module.name === '') {
|
|
60
|
+
module.name = this.repositoryName(module.location);
|
|
61
|
+
}
|
|
62
|
+
let repoUrl;
|
|
63
|
+
try {
|
|
64
|
+
repoUrl = new URL(module.location);
|
|
65
|
+
}
|
|
66
|
+
catch {
|
|
67
|
+
throw new Error(`Invalid repository URL: ${module.location}`);
|
|
68
|
+
}
|
|
69
|
+
if (process.env.CYBERISMO_GIT_USER &&
|
|
70
|
+
process.env.CYBERISMO_GIT_TOKEN &&
|
|
71
|
+
module.private) {
|
|
72
|
+
if (verbose) {
|
|
73
|
+
console.log(`... Using credentials '${process.env.CYBERISMO_GIT_USER}' for cloning '${module.name}'`);
|
|
74
|
+
}
|
|
75
|
+
repoUrl.username = process.env.CYBERISMO_GIT_USER;
|
|
76
|
+
repoUrl.password = process.env.CYBERISMO_GIT_TOKEN;
|
|
77
|
+
}
|
|
78
|
+
await git.clone({
|
|
79
|
+
fs,
|
|
80
|
+
http,
|
|
81
|
+
dir: join(this.tempModulesDir, module.name),
|
|
82
|
+
url: repoUrl.toString(),
|
|
83
|
+
depth: 1,
|
|
84
|
+
onAuth: () => {
|
|
85
|
+
// Turn credentials 'off' when they are not available
|
|
86
|
+
if (!process.env.CYBERISMO_GIT_USER ||
|
|
87
|
+
!process.env.CYBERISMO_GIT_TOKEN) {
|
|
88
|
+
return undefined;
|
|
89
|
+
}
|
|
90
|
+
// Turn credentials 'off' for public repos
|
|
91
|
+
if (!module.private) {
|
|
92
|
+
return undefined;
|
|
93
|
+
}
|
|
94
|
+
return {
|
|
95
|
+
username: process.env.CYBERISMO_GIT_USER,
|
|
96
|
+
password: process.env.CYBERISMO_GIT_TOKEN,
|
|
97
|
+
};
|
|
98
|
+
},
|
|
99
|
+
});
|
|
100
|
+
if (verbose) {
|
|
101
|
+
console.log(`... Cloned '${module.name}' to a temporary folder`);
|
|
102
|
+
}
|
|
103
|
+
return module.name;
|
|
104
|
+
}
|
|
105
|
+
// Collects all module prefixes from module hierarchy into 'this.modules'.
|
|
106
|
+
// Note that collected result can contain duplicates.
|
|
107
|
+
async collectModulePrefixes(modules) {
|
|
108
|
+
if (modules) {
|
|
109
|
+
for (const module of modules) {
|
|
110
|
+
await this.doCollectModulePrefix(module);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
// Read project configuration JSON file from 'path'.
|
|
115
|
+
async configuration(path) {
|
|
116
|
+
try {
|
|
117
|
+
const paths = new ProjectPaths(path);
|
|
118
|
+
return readJsonFile(paths.configurationFile);
|
|
119
|
+
}
|
|
120
|
+
catch {
|
|
121
|
+
throw new Error(`Module not found from '${path}'`);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
// Collects one module's dependency prefixes to 'this.modules'.
|
|
125
|
+
// Note that there can be duplicate entries.
|
|
126
|
+
async doCollectModulePrefix(module) {
|
|
127
|
+
let moduleRoot = '';
|
|
128
|
+
if (this.isFileModule(module)) {
|
|
129
|
+
const urlStart = FILE_PROTOCOL.length;
|
|
130
|
+
// Remove 'file:' from location
|
|
131
|
+
moduleRoot = module.location.substring(urlStart, module.location.length);
|
|
132
|
+
}
|
|
133
|
+
else {
|
|
134
|
+
await this.clone(module, false);
|
|
135
|
+
moduleRoot = join(this.tempModulesDir, module.name);
|
|
136
|
+
}
|
|
137
|
+
this.modules.push(module);
|
|
138
|
+
const configuration = await this.configuration(moduleRoot);
|
|
139
|
+
await this.collectModulePrefixes(configuration.modules);
|
|
140
|
+
}
|
|
141
|
+
// Updates one module that is read from local file system.
|
|
142
|
+
async handleFileModule(module) {
|
|
143
|
+
this.removeProtocolFromLocation(module);
|
|
144
|
+
await this.remove(module);
|
|
145
|
+
await this.importFromFolder(module);
|
|
146
|
+
}
|
|
147
|
+
// Updates one module that is received from Git.
|
|
148
|
+
async handleGitModule(module) {
|
|
149
|
+
await this.clone(module);
|
|
150
|
+
await this.branch(module);
|
|
151
|
+
await this.remove(module);
|
|
152
|
+
await this.importFromTemp(module);
|
|
153
|
+
}
|
|
154
|
+
// Updates one module.
|
|
155
|
+
async handleModule(module) {
|
|
156
|
+
return this.isFileModule(module)
|
|
157
|
+
? this.handleFileModule(module)
|
|
158
|
+
: this.handleGitModule(module);
|
|
159
|
+
}
|
|
160
|
+
// Handles importing a module from module settings 'location'
|
|
161
|
+
async importFromFolder(module) {
|
|
162
|
+
await this.importCmd.updateExistingModule(module.location);
|
|
163
|
+
console.log(`... Imported module '${module.name}' to '${this.project.configuration.name}'`);
|
|
164
|
+
}
|
|
165
|
+
// Handles importing a module from '.temp' folder
|
|
166
|
+
async importFromTemp(module) {
|
|
167
|
+
await this.importCmd.updateExistingModule(join(this.tempModulesDir, module.name));
|
|
168
|
+
console.log(`... Imported module '${module.name}' to '${this.project.configuration.name}'`);
|
|
169
|
+
}
|
|
170
|
+
// Returns true if module is imported from file-system.
|
|
171
|
+
isFileModule(module) {
|
|
172
|
+
if (!module.location)
|
|
173
|
+
return false;
|
|
174
|
+
return module.location.startsWith('file:');
|
|
175
|
+
}
|
|
176
|
+
// Prepares '.temp/modules' for cloning
|
|
177
|
+
async prepare() {
|
|
178
|
+
await mkdir(this.tempModulesDir, { recursive: true });
|
|
179
|
+
for (const file of await readdir(this.tempModulesDir)) {
|
|
180
|
+
await rm(join(this.tempModulesDir, file), {
|
|
181
|
+
force: true,
|
|
182
|
+
recursive: true,
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
// Returns whether to use git or file system for handling the module.
|
|
187
|
+
protocol(module) {
|
|
188
|
+
return this.isFileModule(module) ? 'file' : 'git';
|
|
189
|
+
}
|
|
190
|
+
// Handles removing an imported module.
|
|
191
|
+
async remove(module) {
|
|
192
|
+
try {
|
|
193
|
+
await this.removeModuleFiles(module.name);
|
|
194
|
+
console.log(`... Removed imported module '${module.name}'`);
|
|
195
|
+
}
|
|
196
|
+
catch (error) {
|
|
197
|
+
if (error instanceof Error)
|
|
198
|
+
console.error(`... New imported module '${module.name}', skipping remove`);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
// Remove module files.
|
|
202
|
+
async removeModuleFiles(moduleName) {
|
|
203
|
+
const module = await this.project.module(moduleName);
|
|
204
|
+
if (!module) {
|
|
205
|
+
throw new Error(`Module '${moduleName}' not found`);
|
|
206
|
+
}
|
|
207
|
+
await deleteDir(module.path);
|
|
208
|
+
}
|
|
209
|
+
// Updates module's 'location' not to have 'protocol:' in the beginning (only for "file:" needed).
|
|
210
|
+
removeProtocolFromLocation(module) {
|
|
211
|
+
const protocol = this.protocol(module);
|
|
212
|
+
module.location = module.location.substring(protocol.length + 1, module.location.length);
|
|
213
|
+
}
|
|
214
|
+
// Checks for duplicate ModuleSetting entries and throws an error if modules
|
|
215
|
+
// with the same name have different branches or locations.
|
|
216
|
+
// Treats undefined branch, empty string branch, and "main" branch as equivalent.
|
|
217
|
+
// Returns an array with duplicate entries removed
|
|
218
|
+
removeDuplicates(modules) {
|
|
219
|
+
const moduleMap = new Map();
|
|
220
|
+
// Assume that empty, or missing branch means 'main'
|
|
221
|
+
const normalizeBranch = (branch) => {
|
|
222
|
+
if (!branch || branch === '' || branch === MAIN_BRANCH) {
|
|
223
|
+
return MAIN_BRANCH;
|
|
224
|
+
}
|
|
225
|
+
return branch;
|
|
226
|
+
};
|
|
227
|
+
for (const module of modules) {
|
|
228
|
+
const existingModule = moduleMap.get(module.name);
|
|
229
|
+
if (existingModule) {
|
|
230
|
+
if (existingModule.private !== module.private) {
|
|
231
|
+
throw new Error(`Module conflict: '${module.name}' has different access:\n` +
|
|
232
|
+
` - ${existingModule.private || 'undefined'}\n` +
|
|
233
|
+
` - ${module.private || 'undefined'}`);
|
|
234
|
+
}
|
|
235
|
+
if (existingModule.location !== module.location) {
|
|
236
|
+
throw new Error(`Module conflict: '${module.name}' has different locations:\n` +
|
|
237
|
+
` - ${existingModule.location}\n` +
|
|
238
|
+
` - ${module.location}`);
|
|
239
|
+
}
|
|
240
|
+
const existingBranch = normalizeBranch(existingModule.branch);
|
|
241
|
+
const newBranch = normalizeBranch(module.branch);
|
|
242
|
+
if (existingBranch !== newBranch) {
|
|
243
|
+
throw new Error(`Module conflict: '${module.name}' has different branches:\n` +
|
|
244
|
+
` - ${existingModule.branch || 'undefined'}\n` +
|
|
245
|
+
` - ${module.branch || 'undefined'}`);
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
else {
|
|
249
|
+
moduleMap.set(module.name, module);
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
return Array.from(moduleMap.values());
|
|
253
|
+
}
|
|
254
|
+
// Gets repository name from gitUrl
|
|
255
|
+
repositoryName(gitUrl) {
|
|
256
|
+
const last = gitUrl.lastIndexOf('/');
|
|
257
|
+
const repoName = gitUrl.substring(last + 1, gitUrl.length - 4); //remove trailing ".git"
|
|
258
|
+
return repoName;
|
|
259
|
+
}
|
|
260
|
+
// Checks that module prefix is not in use in the project
|
|
261
|
+
async validatePrefix(modulePrefix) {
|
|
262
|
+
// Do not allow modules with same prefixes.
|
|
263
|
+
const currentlyUsedPrefixes = await this.project.projectPrefixes();
|
|
264
|
+
if (currentlyUsedPrefixes.includes(modulePrefix)) {
|
|
265
|
+
throw new Error(`Imported project has a prefix '${modulePrefix}' that is already used in the project. Cannot import from module.`);
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
/**
|
|
269
|
+
* Imports module from local file path.
|
|
270
|
+
* @param source Path to import from.
|
|
271
|
+
* @param destination is this really needed???
|
|
272
|
+
*/
|
|
273
|
+
async importFileModule(source, destination) {
|
|
274
|
+
if (!Validate.validateFolder(source)) {
|
|
275
|
+
throw new Error(`Input validation error: folder name is invalid '${source}'`);
|
|
276
|
+
}
|
|
277
|
+
if (!pathExists(source)) {
|
|
278
|
+
throw new Error(`Input validation error: cannot find project '${source}'`);
|
|
279
|
+
}
|
|
280
|
+
if (destination && !pathExists(destination)) {
|
|
281
|
+
throw new Error(`Input validation error: destination does not exist '${destination}'`);
|
|
282
|
+
}
|
|
283
|
+
const sourceProject = new Project(source);
|
|
284
|
+
const modulePrefix = sourceProject.projectPrefix;
|
|
285
|
+
const destinationPath = join(this.project.paths.modulesFolder, modulePrefix);
|
|
286
|
+
const sourcePath = sourceProject.paths.resourcesFolder;
|
|
287
|
+
await this.validatePrefix(modulePrefix);
|
|
288
|
+
// Copy files.
|
|
289
|
+
await this.addFileContents(sourcePath, destinationPath);
|
|
290
|
+
return modulePrefix;
|
|
291
|
+
}
|
|
292
|
+
/**
|
|
293
|
+
* Imports module from gitUrl.
|
|
294
|
+
* @param source Git URL to import from.
|
|
295
|
+
* @param options Modules setting options.
|
|
296
|
+
* @returns module prefix as defined in its CardsConfig.json
|
|
297
|
+
*/
|
|
298
|
+
async importGitModule(source, options) {
|
|
299
|
+
const repoName = await this.clone({
|
|
300
|
+
name: '',
|
|
301
|
+
location: source,
|
|
302
|
+
...options,
|
|
303
|
+
});
|
|
304
|
+
await this.branch({ name: repoName, location: source, ...options });
|
|
305
|
+
const clonePath = join(this.project.paths.tempFolder, 'modules', repoName);
|
|
306
|
+
const modulePrefix = (await this.configuration(clonePath)).cardKeyPrefix;
|
|
307
|
+
await this.validatePrefix(modulePrefix);
|
|
308
|
+
const sourcePath = new ProjectPaths(clonePath).resourcesFolder;
|
|
309
|
+
const destinationPath = join(this.project.paths.modulesFolder, modulePrefix);
|
|
310
|
+
await this.addFileContents(sourcePath, destinationPath);
|
|
311
|
+
return modulePrefix;
|
|
312
|
+
}
|
|
313
|
+
/**
|
|
314
|
+
* Updates all imported modules.
|
|
315
|
+
*/
|
|
316
|
+
async update() {
|
|
317
|
+
// Prints dots every half second so that user knows that something is ongoing
|
|
318
|
+
function start() {
|
|
319
|
+
console.log('... Collecting unique modules. This takes a moment.');
|
|
320
|
+
return setInterval(() => process.stdout.write(`.`), 500);
|
|
321
|
+
}
|
|
322
|
+
// Stops the above, and shows results
|
|
323
|
+
function finished(interval, modules) {
|
|
324
|
+
clearInterval(interval);
|
|
325
|
+
console.log(`\n... Found modules: ${modules.join(', ')}`);
|
|
326
|
+
}
|
|
327
|
+
await this.prepare();
|
|
328
|
+
const modules = this.project.configuration.modules;
|
|
329
|
+
if (modules.length === 0) {
|
|
330
|
+
throw new Error(`No modules in the project!`);
|
|
331
|
+
}
|
|
332
|
+
const dotInterval = start();
|
|
333
|
+
// Collect prefixes from project's dependency modules.
|
|
334
|
+
await this.collectModulePrefixes(modules);
|
|
335
|
+
let uniqueModules = [];
|
|
336
|
+
try {
|
|
337
|
+
uniqueModules = this.removeDuplicates(this.modules);
|
|
338
|
+
}
|
|
339
|
+
finally {
|
|
340
|
+
finished(dotInterval, uniqueModules.map((item) => item.name));
|
|
341
|
+
// Update modules parallel.
|
|
342
|
+
const promises = [];
|
|
343
|
+
uniqueModules.forEach((module) => promises.push(this.handleModule(module)));
|
|
344
|
+
await Promise.all(promises);
|
|
345
|
+
await deleteDir(this.tempModulesDir);
|
|
346
|
+
await this.project.collectModuleResources();
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
//# sourceMappingURL=module-manager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"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M,WAAW,GAAG,KAAK,EAAE,CAAC;QAE5B,sDAAsD;QACtD,MAAM,IAAI,CAAC,qBAAqB,CAAC,OAAO,CAAC,CAAC;QAE1C,IAAI,aAAa,GAAoB,EAAE,CAAC;QACxC,IAAI,CAAC;YACH,aAAa,GAAG,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACtD,CAAC;gBAAS,CAAC;YACT,QAAQ,CACN,WAAW,EACX,aAAa,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,CACvC,CAAC;YAEF,2BAA2B;YAC3B,MAAM,QAAQ,GAAoB,EAAE,CAAC;YACrC,aAAa,CAAC,OAAO,CAAC,CAAC,MAAM,EAAE,EAAE,CAC/B,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC,CACzC,CAAC;YACF,MAAM,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;YAE5B,MAAM,SAAS,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;YACrC,MAAM,IAAI,CAAC,OAAO,CAAC,sBAAsB,EAAE,CAAC;QAC9C,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
Cyberismo
|
|
3
|
+
Copyright © Cyberismo Ltd and contributors 2024
|
|
4
|
+
|
|
5
|
+
This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License version 3 as published by the Free Software Foundation.
|
|
6
|
+
|
|
7
|
+
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
|
|
8
|
+
|
|
9
|
+
You should have received a copy of the GNU Affero General Public
|
|
10
|
+
License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
11
|
+
*/
|
|
12
|
+
import type { Calculate } from '../commands/index.js';
|
|
13
|
+
import type { DeniedOperationCollection } from '../types/queries.js';
|
|
14
|
+
export type Action = keyof DeniedOperationCollection;
|
|
15
|
+
/**
|
|
16
|
+
* This class is used to guard actions from being used without permissions
|
|
17
|
+
*/
|
|
18
|
+
export declare class ActionGuard {
|
|
19
|
+
private calculate;
|
|
20
|
+
constructor(calculate: Calculate);
|
|
21
|
+
/**
|
|
22
|
+
* Checks whether an action can be done
|
|
23
|
+
* @param action Action that will be done
|
|
24
|
+
* @param cardKey Key of the card being targeted
|
|
25
|
+
* @param param Required or not used param depending on the action
|
|
26
|
+
*/
|
|
27
|
+
checkPermission(action: Action, cardKey: string, param?: string): Promise<void>;
|
|
28
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
Cyberismo
|
|
3
|
+
Copyright © Cyberismo Ltd and contributors 2024
|
|
4
|
+
|
|
5
|
+
This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License version 3 as published by the Free Software Foundation.
|
|
6
|
+
|
|
7
|
+
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
|
|
8
|
+
|
|
9
|
+
You should have received a copy of the GNU Affero General Public
|
|
10
|
+
License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
11
|
+
*/
|
|
12
|
+
function checkOperation(data) {
|
|
13
|
+
if (data.length > 0) {
|
|
14
|
+
throw new Error(data.map((value) => value.errorMessage).join('; '));
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* This class is used to guard actions from being used without permissions
|
|
19
|
+
*/
|
|
20
|
+
export class ActionGuard {
|
|
21
|
+
calculate;
|
|
22
|
+
constructor(calculate) {
|
|
23
|
+
this.calculate = calculate;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Checks whether an action can be done
|
|
27
|
+
* @param action Action that will be done
|
|
28
|
+
* @param cardKey Key of the card being targeted
|
|
29
|
+
* @param param Required or not used param depending on the action
|
|
30
|
+
*/
|
|
31
|
+
async checkPermission(action, cardKey, param) {
|
|
32
|
+
await this.calculate.generate();
|
|
33
|
+
const cards = await this.calculate.runQuery('card', {
|
|
34
|
+
cardKey,
|
|
35
|
+
});
|
|
36
|
+
if (cards.length === 0) {
|
|
37
|
+
throw new Error("Card query didn't return results");
|
|
38
|
+
}
|
|
39
|
+
if (cards.length !== 1) {
|
|
40
|
+
throw new Error('Card query returned multiple cards');
|
|
41
|
+
}
|
|
42
|
+
const res = cards[0];
|
|
43
|
+
if (action === 'editContent') {
|
|
44
|
+
return checkOperation(res.deniedOperations.editContent);
|
|
45
|
+
}
|
|
46
|
+
if (action === 'transition') {
|
|
47
|
+
return checkOperation(res.deniedOperations.transition.filter((value) => value.transitionName === param));
|
|
48
|
+
}
|
|
49
|
+
if (action === 'delete') {
|
|
50
|
+
return checkOperation(res.deniedOperations.delete);
|
|
51
|
+
}
|
|
52
|
+
if (action === 'editField') {
|
|
53
|
+
return checkOperation(res.deniedOperations.editField.filter((value) => value.fieldName === param));
|
|
54
|
+
}
|
|
55
|
+
if (action === 'move') {
|
|
56
|
+
return checkOperation(res.deniedOperations.move);
|
|
57
|
+
}
|
|
58
|
+
throw new Error(`Action: ${action} does not support checking permissions`);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=action-guard.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"action-guard.js","sourceRoot":"","sources":["../../src/permissions/action-guard.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;EAUE;AAOF,SAAS,cAAc,CAAqC,IAAc;IACxE,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACpB,MAAM,IAAI,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC,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SAAS,CAAC,MAAM,CACnC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,SAAS,KAAK,KAAK,CACrC,CACF,CAAC;QACJ,CAAC;QACD,IAAI,MAAM,KAAK,MAAM,EAAE,CAAC;YACtB,OAAO,cAAc,CAAC,GAAG,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAC;QACnD,CAAC;QACD,MAAM,IAAI,KAAK,CAAC,WAAW,MAAM,wCAAwC,CAAC,CAAC;IAC7E,CAAC;CACF"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
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/>.
|
|
12
|
+
*/
|
|
13
|
+
import type { ModuleSetting, ProjectSettings } from './interfaces/project-interfaces.js';
|
|
14
|
+
/**
|
|
15
|
+
* Represents Project's cardsConfig.json file.
|
|
16
|
+
*/
|
|
17
|
+
export declare class ProjectConfiguration implements ProjectSettings {
|
|
18
|
+
private static instance;
|
|
19
|
+
name: string;
|
|
20
|
+
cardKeyPrefix: string;
|
|
21
|
+
modules: ModuleSetting[];
|
|
22
|
+
private settingPath;
|
|
23
|
+
constructor(path: string);
|
|
24
|
+
save(): Promise<void>;
|
|
25
|
+
private readSettings;
|
|
26
|
+
private toJSON;
|
|
27
|
+
/**
|
|
28
|
+
* Adds new module to imported modules property.
|
|
29
|
+
* @param module Module to add as dependency
|
|
30
|
+
*/
|
|
31
|
+
addModule(module: ModuleSetting): Promise<void>;
|
|
32
|
+
/**
|
|
33
|
+
* Removes module from imported modules property.
|
|
34
|
+
* @param moduleName Name of the module to remove.
|
|
35
|
+
*/
|
|
36
|
+
removeModule(moduleName: string): Promise<void>;
|
|
37
|
+
/**
|
|
38
|
+
* Changes project prefix.
|
|
39
|
+
* @param newPrefix New prefix to use in the project
|
|
40
|
+
*/
|
|
41
|
+
setCardPrefix(newPrefix: string): Promise<void>;
|
|
42
|
+
}
|