From a63e53c13897e48c40497d3a68d8bbd211ce4c25 Mon Sep 17 00:00:00 2001 From: peterhnm Date: Fri, 4 Oct 2024 16:32:35 +0200 Subject: [PATCH] fix: eslint errors --- .eslintrc.json | 2 +- apps/miranum-cli/src/app/deployment/api.ts | 62 +++++--- .../src/app/deployment/deployment.ts | 62 ++++++-- .../src/app/deployment/deployments.spec.ts | 139 ++++++++++++------ apps/miranum-cli/src/app/generate/api.ts | 35 +++-- apps/miranum-cli/src/app/generate/generate.ts | 21 ++- apps/miranum-cli/src/app/shared/fs.spec.ts | 14 +- apps/miranum-cli/src/app/shared/fs.ts | 64 +++++--- apps/miranum-cli/src/main.ts | 6 +- apps/miranum-cli/tests/deploymentApi.spec.ts | 106 ++++++++++--- apps/miranum-cli/tests/generateApi.spec.ts | 3 + apps/miranum-cli/tests/testHelpers.ts | 49 ++++-- .../miranum-config-editor-webview/src/App.vue | 1 - .../src/adapter/adapterIn.ts | 6 +- .../src/adapter/adapterOut.ts | 2 + .../src/application/usecases.ts | 4 +- .../src/app/generate/commands.ts | 6 +- .../src/app/vscode/MiranumTreeDataProvider.ts | 2 +- .../src/App.vue | 1 - .../src/types/diagram-js.d.ts | 8 +- .../src/types/diagram-js.d.ts | 12 +- libs/miranum-core/src/index.ts | 2 +- .../src/lib/deployment/plugins.ts | 12 +- .../miranum-deployment-plugin-rest.spec.ts | 27 +++- .../rest/miranum-deployment-plugin-rest.ts | 16 +- .../src/lib/generate/plugins.spec.ts | 52 +++++-- libs/miranum-core/src/lib/generate/plugins.ts | 122 +++++++++++---- .../miranum-core/src/lib/miranum-core.spec.ts | 85 +++++++---- libs/miranum-core/src/lib/miranum-core.ts | 46 ++++-- libs/miranum-core/src/lib/types.ts | 17 ++- libs/miranum-core/tsconfig.lib.json | 15 +- libs/miranum-core/tsconfig.spec.json | 6 +- 32 files changed, 708 insertions(+), 297 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index 81e69a3d..6d3d4776 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -65,7 +65,7 @@ "plugin:@nx/typescript" ], "rules": { - "@typescript-eslint/no-explicit-any": "error", + "@typescript-eslint/no-explicit-any": "warn", "import/no-extraneous-dependencies": "off" } }, diff --git a/apps/miranum-cli/src/app/deployment/api.ts b/apps/miranum-cli/src/app/deployment/api.ts index 1bb5bcc8..b449ceef 100644 --- a/apps/miranum-cli/src/app/deployment/api.ts +++ b/apps/miranum-cli/src/app/deployment/api.ts @@ -6,7 +6,7 @@ import { mapProcessConfigToDigiwfLib } from "../shared/fs"; /** * This command deploys an artifact to the target environment. * An artefact consists out of a type (string), a project (string), and a file - * The file in itself consist out of a name, an extension, some content, a size, and a path + * The file in itself consists out of a name, an extension, some content, a size, and a path * * @example * ``` bash @@ -16,9 +16,9 @@ import { mapProcessConfigToDigiwfLib } from "../shared/fs"; * @options * ``` bash * # required - * -f or --file : "specify the file in your project" - * -t or --target : "specify the target environment" - * --type : "specify the file type" + * -f or --file : "specify the file in your project" + * -t or --target : "specify the target environment" + * --type : "specify the file type" * ``` */ export function deployFile(): Command { @@ -31,22 +31,34 @@ export function deployFile(): Command { .hook("preAction", (thisCommand) => { // validate inputs before action is called const type = thisCommand.opts().type; - if (!(type === "bpmn" || type === "dmn" || type === "form" || type === "config")) { - throw new InvalidArgumentError("type must be either bpmn, dmn, form or config"); + if ( + !( + type === "bpmn" || + type === "dmn" || + type === "form" || + type === "config" + ) + ) { + throw new InvalidArgumentError( + "type must be either bpmn, dmn, form or config", + ); } }) .action((options) => { - mapProcessConfigToDigiwfLib().then(digiwfLib => { - const deployment = new Deployment(digiwfLib); - deployment.deployArtifact(options.file, options.type, options.target) - .then( () => console.log("Deployment was successfully")) - .catch(err => console.log(colors.red.bold("FAILED") + ` with -> ${err}`)); + mapProcessConfigToDigiwfLib().then((digiwfLib) => { + const deployment = new Deployment(digiwfLib); + deployment + .deployArtifact(options.file, options.type, options.target) + .then(() => console.log("Deployment was successfully")) + .catch((err) => + console.log(colors.red.bold("FAILED") + ` with -> ${err}`), + ); }); }); } /** - * This command deploys all artifact to the target environment. + * This command deploys all artifacts to the target environment. * Therefore, it uses the same deploy method as the deployFileCommand. * * @example @@ -57,22 +69,32 @@ export function deployFile(): Command { * @options * ``` bash * # required - * -d or --directory : "specify the directory of the source files" - * -t or --target : "specify the target environment" + * -d or --directory : "specify the directory of the source files" + * -t or --target : "specify the target environment" * ``` */ export function deployAllFiles(): Command { return new Command() .command("deploy") .description("deploys all artifacts to the target environment") - .requiredOption("-d --directory ", "specify the directory of the source files") + .requiredOption( + "-d --directory ", + "specify the directory of the source files", + ) .requiredOption("-t, --target ", "specify the target environment") .action((options) => { - mapProcessConfigToDigiwfLib(options.directory).then(digiwfLib => { - const deployment = new Deployment(digiwfLib); - deployment.deployAllArtifacts(options.directory, options.target) - .then( () => console.log(`Project ${digiwfLib.projectConfig?.name} was successfully deployed to environment ${options.target}`)) - .catch(err => console.log(colors.red.bold("FAILED") + ` with -> ${err}`)); + mapProcessConfigToDigiwfLib(options.directory).then((digiwfLib) => { + const deployment = new Deployment(digiwfLib); + deployment + .deployAllArtifacts(options.directory, options.target) + .then(() => + console.log( + `Project ${digiwfLib.projectConfig?.name} was successfully deployed to environment ${options.target}`, + ), + ) + .catch((err) => + console.log(colors.red.bold("FAILED") + ` with -> ${err}`), + ); }); }); } diff --git a/apps/miranum-cli/src/app/deployment/deployment.ts b/apps/miranum-cli/src/app/deployment/deployment.ts index a9b10210..1604c08a 100644 --- a/apps/miranum-cli/src/app/deployment/deployment.ts +++ b/apps/miranum-cli/src/app/deployment/deployment.ts @@ -1,29 +1,45 @@ -import { checkIfSupportedType, MiranumCore, FileDetails } from "@miranum-ide/miranum-core"; +import { + checkIfSupportedType, + FileDetails, + MiranumCore, +} from "@miranum-ide/miranum-core"; import { getFile, getFiles } from "../shared/fs"; import * as colors from "colors"; export class Deployment { - constructor(private miranumCore: MiranumCore) {} - public async deployArtifact(path: string, type: string, target: string): Promise { + public async deployArtifact( + path: string, + type: string, + target: string, + ): Promise { const file = await getFile(path); return this.deploy(file, type, target); } public async deployAllArtifacts(path: string, target: string): Promise { - const files: { type: string; file: FileDetails; }[] = []; - if(!this.miranumCore.projectConfig) { + const files: { type: string; file: FileDetails }[] = []; + if (!this.miranumCore.projectConfig) { throw new Error(path + " is not a valid project!"); } for (const workspace of this.miranumCore.projectConfig.workspace) { - if(!checkIfSupportedType(workspace.type)) { + if (!checkIfSupportedType(workspace.type)) { continue; } - try{ - (await getFiles(`${path}/${workspace.path}`.replace("//", "/"), workspace.extension)) - .forEach(f => files.push({type: workspace.type, file: f})); + try { + ( + await getFiles( + `${path}/${workspace.path}`.replace("//", "/"), + workspace.extension, + ) + ).forEach((f) => + files.push({ + type: workspace.type, + file: f, + }), + ); } catch (error) { // continue if workspace is not allocated } @@ -32,22 +48,36 @@ export class Deployment { try { await this.deploy(file.file, file.type, target); } catch (err) { - console.log(colors.red.bold("FAILED ") + `deploying ${file.file.name} with -> ${err}`); + console.log( + colors.red.bold("FAILED ") + + `deploying ${file.file.name} with -> ${err}`, + ); // todo the deployment should continue and fail in the end, not here (Übergangslösung) - return Promise.reject(colors.red.bold("FAILED ") + `deploying Artifacts in ${path}`); + return Promise.reject( + colors.red.bold("FAILED ") + `deploying Artifacts in ${path}`, + ); } } } - private async deploy(file: FileDetails, type: string, target: string): Promise { + private async deploy( + file: FileDetails, + type: string, + target: string, + ): Promise { if (!checkIfSupportedType(type)) { return Promise.reject(`${type} is not supported for deployment`); } const artifact = await this.miranumCore.deploy(target, { - "type": type, - "project": this.miranumCore.projectConfig?.name ?? "", - "file": file + type: type, + project: this.miranumCore.projectConfig?.name ?? "", + file: file, }); - console.log(colors.green.bold("DEPLOYED ") + artifact.file.name + " to environment " + target); + console.log( + colors.green.bold("DEPLOYED ") + + artifact.file.name + + " to environment " + + target, + ); } } diff --git a/apps/miranum-cli/src/app/deployment/deployments.spec.ts b/apps/miranum-cli/src/app/deployment/deployments.spec.ts index 2b05dc04..c82fc6b3 100644 --- a/apps/miranum-cli/src/app/deployment/deployments.spec.ts +++ b/apps/miranum-cli/src/app/deployment/deployments.spec.ts @@ -1,89 +1,132 @@ import { Deployment } from "./deployment"; -import {Artifact, createMiranumCore, MiranumDeploymentPlugin} from "@miranum-ide/miranum-core"; +import { + Artifact, + createMiranumCore, + MiranumDeploymentPlugin, +} from "@miranum-ide/miranum-core"; import * as colors from "colors"; -import {filesToDeploy, pathToProject} from "../../../tests/testHelpers"; +import { filesToDeploy, pathToProject } from "../../../tests/testHelpers"; const sampleTarget = "local"; const dryDeploymentPlugin: MiranumDeploymentPlugin = { plugin: "dry", - targetEnvironments: [{name:"local",url:"http://localhost:8080"}], - deploy: function(target: string, artifact: Artifact) { + targetEnvironments: [{ name: "local", url: "http://localhost:8080" }], + deploy: function (target: string, artifact: Artifact) { return Promise.resolve(artifact); - } + }, }; -const deployment = new Deployment(createMiranumCore( - "0.0.1", - "my-process-automation-project", - [ - { "type": "bpmn", "path": "", "extension": ".bpmn" }, - { "type": "dmn", "path": "", "extension": ".dmn" }, - { "type": "form", "path": "forms", "extension": ".form" }, - { "type": "element-template", "path": "element-templates", "extension": ".json" }, - { "type": "config", "path": "configs", "extension": ".config.json" } - ], - [dryDeploymentPlugin] -)); +const deployment = new Deployment( + createMiranumCore( + "0.0.1", + "my-process-automation-project", + [ + { type: "bpmn", path: "", extension: ".bpmn" }, + { type: "dmn", path: "", extension: ".dmn" }, + { type: "form", path: "forms", extension: ".form" }, + { type: "element-template", path: "element-templates", extension: ".json" }, + { type: "config", path: "configs", extension: ".config.json" }, + ], + [dryDeploymentPlugin], + ), +); // workspace must be the same as the one in miranum.json from my-process-automation-project -const customDeployment = new Deployment(createMiranumCore( - "0.0.1", - "my-process-automation-project", - [ - { "type": "bpmn", "path": "", "extension": ".bpmn" }, - { "type": "dmn", "path": "", "extension": ".dmn" }, - { "type": "form", "path": "forms", "extension": ".form" }, - { "type": "form", "path": "my-other-forms", "extension": ".json" }, - { "type": "element-template", "path": "my-templates", "extension": ".json" }, - { "type": "config", "path": "configs", "extension": ".config.json" } - ], - [dryDeploymentPlugin] -)); +const customDeployment = new Deployment( + createMiranumCore( + "0.0.1", + "my-process-automation-project", + [ + { type: "bpmn", path: "", extension: ".bpmn" }, + { type: "dmn", path: "", extension: ".dmn" }, + { type: "form", path: "forms", extension: ".form" }, + { type: "form", path: "my-other-forms", extension: ".json" }, + { type: "element-template", path: "my-templates", extension: ".json" }, + { type: "config", path: "configs", extension: ".config.json" }, + ], + [dryDeploymentPlugin], + ), +); describe("deployArtifact", () => { - for(const file of filesToDeploy) { + for (const file of filesToDeploy) { it(`${file.type} should work with standard settings`, async () => { const logSpy = jest.spyOn(console, "log"); - await expect(deployment.deployArtifact(file.path, file.type, sampleTarget)) - .resolves.not.toThrow(); - expect(logSpy).toHaveBeenCalledWith(colors.green.bold("DEPLOYED ") + file.nameExt + " to environment " + sampleTarget); + await expect( + deployment.deployArtifact(file.path, file.type, sampleTarget), + ).resolves.not.toThrow(); + expect(logSpy).toHaveBeenCalledWith( + colors.green.bold("DEPLOYED ") + + file.nameExt + + " to environment " + + sampleTarget, + ); }); } it(`should work with custom Artifact`, async () => { - const customForm = {nameExt: "KontrollFormular.json", path: "resources/my-process-automation-project/my-other-forms/KontrollFormular.json", type: "form"}; + const customForm = { + nameExt: "KontrollFormular.json", + path: "resources/my-process-automation-project/my-other-forms/KontrollFormular.json", + type: "form", + }; const logSpy = jest.spyOn(console, "log"); - await expect(customDeployment.deployArtifact(customForm.path, customForm.type, sampleTarget)) - .resolves.not.toThrow(); - expect(logSpy).toHaveBeenCalledWith(colors.green.bold("DEPLOYED ") + customForm.nameExt + " to environment " + sampleTarget); + await expect( + customDeployment.deployArtifact( + customForm.path, + customForm.type, + sampleTarget, + ), + ).resolves.not.toThrow(); + expect(logSpy).toHaveBeenCalledWith( + colors.green.bold("DEPLOYED ") + + customForm.nameExt + + " to environment " + + sampleTarget, + ); }); it(`should not work, due to unsupported type`, async () => { - const eTemplate = {nameExt: "test.json", path: "resources/my-process-automation-project/element-templates/test.json", type: "element-template"}; - return deployment.deployArtifact(eTemplate.path, eTemplate.type, sampleTarget) - .catch(e => expect(e).toBe(`${eTemplate.type} is not supported for deployment`)); + const eTemplate = { + nameExt: "test.json", + path: "resources/my-process-automation-project/element-templates/test.json", + type: "element-template", + }; + return deployment + .deployArtifact(eTemplate.path, eTemplate.type, sampleTarget) + .catch((e) => + expect(e).toBe(`${eTemplate.type} is not supported for deployment`), + ); }); it("should raise an error", async () => { - return deployment.deployArtifact(pathToProject, "BPMN", sampleTarget) - .catch(e => expect(e).not.toBeNull()); + return deployment + .deployArtifact(pathToProject, "BPMN", sampleTarget) + .catch((e) => expect(e).not.toBeNull()); }); }); describe("deployAllArtifacts", () => { it("my-process-automation-project should work", async () => { const logSpy = jest.spyOn(console, "log"); - await expect(customDeployment.deployAllArtifacts(pathToProject, sampleTarget)) - .resolves.not.toThrow(); + await expect( + customDeployment.deployAllArtifacts(pathToProject, sampleTarget), + ).resolves.not.toThrow(); for (const file of filesToDeploy) { - expect(logSpy).toHaveBeenCalledWith(colors.green.bold("DEPLOYED ") + file.nameExt + " to environment " + sampleTarget); + expect(logSpy).toHaveBeenCalledWith( + colors.green.bold("DEPLOYED ") + + file.nameExt + + " to environment " + + sampleTarget, + ); } }); it("should raise an error, due to wrong path", async () => { - return deployment.deployAllArtifacts("/path/does-not/exist", sampleTarget) - .catch(e => expect(e).not.toBeNull()); + return deployment + .deployAllArtifacts("/path/does-not/exist", sampleTarget) + .catch((e) => expect(e).not.toBeNull()); }); }); diff --git a/apps/miranum-cli/src/app/generate/api.ts b/apps/miranum-cli/src/app/generate/api.ts index 118a37e0..70268cb2 100644 --- a/apps/miranum-cli/src/app/generate/api.ts +++ b/apps/miranum-cli/src/app/generate/api.ts @@ -5,8 +5,8 @@ import { mapProcessConfigToDigiwfLib } from "../shared/fs"; /** * This command generates a file for a supported type. - * Supportet types can be found and edited in the miranum.json. - * By default, we support the types: bpmn, dmn, form, config, element-templatet + * Supported types can be found and edited in the miranum.json. + * By default, we support the types: bpmn, dmn, form, config, element-template * * @example * ``` bash @@ -16,24 +16,28 @@ import { mapProcessConfigToDigiwfLib } from "../shared/fs"; * @options * ``` bash * # required - * -t or --type : "specify the file type that is to be generated" - * -n or --name : "specify the name" - * -p or --path : "specify the targeted path" + * -t or --type : "specify the file type that is to be generated" + * -n or --name : "specify the name" + * -p or --path : "specify the targeted path" * ``` */ export function generateFile(): Command { return new Command() .command("generate-file") .description("generates a process artifact") - .requiredOption("-t, --type ", "specify the file type that is to be generated") + .requiredOption( + "-t, --type ", + "specify the file type that is to be generated", + ) .requiredOption("-n, --name ", "specify the name") .requiredOption("-p, --path ", "specify the targeted path") .action((options) => { - mapProcessConfigToDigiwfLib(options.path).then(digiwfLib => { + mapProcessConfigToDigiwfLib(options.path).then((digiwfLib) => { const generate = new ProjectGenerator(digiwfLib); - generate.generateFile(options.name, options.type, options.path) + generate + .generateFile(options.name, options.type, options.path) .then(() => console.log(`Successfully created file ${options.name}`)) - .catch(err => { + .catch((err) => { console.log(`File ${options.name} could not be created`); console.log(err); }); @@ -54,10 +58,10 @@ export function generateFile(): Command { * @options * ``` bash * # required - * -n or --name : "specify the project name" + * -n or --name : "specify the project name" * * # optional - * -p or --path : "specify the targeted path" + * -p or --path : "specify the targeted path" * ``` */ export function generateProject(): Command { @@ -68,9 +72,12 @@ export function generateProject(): Command { .option("-p, --path ", "specify the targeted path") .action((options) => { const generate = new ProjectGenerator(new MiranumCore()); - generate.generateProject(options.name, `${options.path}/${options.name}`) - .then(() => console.log(`Successfully generated project ${options.name}`)) - .catch(err => { + generate + .generateProject(options.name, `${options.path}/${options.name}`) + .then(() => + console.log(`Successfully generated project ${options.name}`), + ) + .catch((err) => { console.log(`Project ${options.name} could not be created`); console.log(err); }); diff --git a/apps/miranum-cli/src/app/generate/generate.ts b/apps/miranum-cli/src/app/generate/generate.ts index 7fd41bce..be64ef54 100644 --- a/apps/miranum-cli/src/app/generate/generate.ts +++ b/apps/miranum-cli/src/app/generate/generate.ts @@ -3,10 +3,9 @@ import { saveFile } from "../shared/fs"; import * as colors from "colors"; export class ProjectGenerator { - constructor(private digiwfLib: MiranumCore) {} - public async generateProject(name: string, path: string): Promise { + public async generateProject(name: string, path: string): Promise { const artifacts = await this.digiwfLib.initProject(name); for (const artifact of artifacts) { await this.generate(artifact, path); @@ -14,7 +13,12 @@ export class ProjectGenerator { } public async generateFile(name: string, type: string, path: string): Promise { - const artifact = await this.digiwfLib.generateArtifact(name, type, this.digiwfLib.projectConfig?.name ?? "", path); + const artifact = await this.digiwfLib.generateArtifact( + name, + type, + this.digiwfLib.projectConfig?.name ?? "", + path, + ); await this.generate(artifact, path); } @@ -28,12 +32,17 @@ export class ProjectGenerator { await saveFile(path, artifact.file.pathInProject, artifact.file.content); let fileName = artifact.file.pathInProject; - fileName = (fileName.charAt(0) === "/") ? fileName.slice(1, fileName.length) : fileName; + fileName = + fileName.charAt(0) === "/" + ? fileName.slice(1, fileName.length) + : fileName; console.log(colors.green.bold("SAVED ") + fileName); } catch (err) { - console.log(colors.red.bold("FAILED ") + ` creating file ${artifact.file.name} with -> ${err}`); + console.log( + colors.red.bold("FAILED ") + + ` creating file ${artifact.file.name} with -> ${err}`, + ); return Promise.reject(err); } } - } diff --git a/apps/miranum-cli/src/app/shared/fs.spec.ts b/apps/miranum-cli/src/app/shared/fs.spec.ts index cf38f8c0..aa7dd848 100644 --- a/apps/miranum-cli/src/app/shared/fs.spec.ts +++ b/apps/miranum-cli/src/app/shared/fs.spec.ts @@ -1,9 +1,9 @@ import { getFile, getFiles } from "./fs"; import { FileDetails } from "@miranum-ide/miranum-core"; -import {pathToProject} from "../../../tests/testHelpers"; +import { pathToProject } from "../../../tests/testHelpers"; function checkFiles(files: FileDetails[], fileExtension: string) { - files.forEach(fileDetails => { + files.forEach((fileDetails) => { expect(fileDetails.name).not.toBeNull(); expect(fileDetails.extension).toEqual(fileExtension); expect(fileDetails.content).not.toBeNull(); @@ -11,7 +11,7 @@ function checkFiles(files: FileDetails[], fileExtension: string) { }); } -describe("getFile",() => { +describe("getFile", () => { it("should work", async () => { const fileDetails = await getFile(`${pathToProject}/my-process.bpmn`); @@ -22,12 +22,11 @@ describe("getFile",() => { }); it("should raise an error", async () => { - return getFile(pathToProject) - .catch(e => expect(e).not.toBeNull()); + return getFile(pathToProject).catch((e) => expect(e).not.toBeNull()); }); }); -describe("getFiles",() => { +describe("getFiles", () => { it("forms should work", async () => { const files = await getFiles(`${pathToProject}/forms`, ".form"); checkFiles(files, ".form"); @@ -49,7 +48,6 @@ describe("getFiles",() => { }); it("should raise an error", async () => { - return getFile(pathToProject) - .catch(e => expect(e).not.toBeNull()); + return getFile(pathToProject).catch((e) => expect(e).not.toBeNull()); }); }); diff --git a/apps/miranum-cli/src/app/shared/fs.ts b/apps/miranum-cli/src/app/shared/fs.ts index 2ccbabc6..c9095016 100644 --- a/apps/miranum-cli/src/app/shared/fs.ts +++ b/apps/miranum-cli/src/app/shared/fs.ts @@ -5,20 +5,34 @@ import { FileDetails, MiranumCore, MiranumDeploymentPlugin, - MiranumDeploymentPluginRest + MiranumDeploymentPluginRest, } from "@miranum-ide/miranum-core"; -export async function mapProcessConfigToDigiwfLib(projectPath?: string): Promise { +export async function mapProcessConfigToDigiwfLib( + projectPath?: string, +): Promise { try { - const p = projectPath ? `${projectPath}/miranum.json`.replace("//", "/") : "miranum.json"; + const p = projectPath + ? `${projectPath}/miranum.json`.replace("//", "/") + : "miranum.json"; const miranumJson = JSON.parse((await getFile(p)).content); const plugins: MiranumDeploymentPlugin[] = []; // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore - miranumJson.deployment.forEach(deployment => { - plugins.push(new MiranumDeploymentPluginRest(deployment.plugin, deployment.targetEnvironments)); + miranumJson.deployment.forEach((deployment) => { + plugins.push( + new MiranumDeploymentPluginRest( + deployment.plugin, + deployment.targetEnvironments, + ), + ); }); - return createMiranumCore(miranumJson.projectVersion, miranumJson.name, miranumJson.workspace, plugins); + return createMiranumCore( + miranumJson.projectVersion, + miranumJson.name, + miranumJson.workspace, + plugins, + ); } catch (error) { return new MiranumCore(); } @@ -33,10 +47,10 @@ export async function getFile(pathToFile: string): Promise { const file = await fs.readFile(pathToFile, { encoding: "utf8" }); return { - "name": name, - "extension": ext, - "content": file.toString(), - "size": size, + name: name, + extension: ext, + content: file.toString(), + size: size, }; } } catch { @@ -45,16 +59,23 @@ export async function getFile(pathToFile: string): Promise { throw new Error(`File not found on path ${pathToFile}`); } -export async function getFiles(pathToDirectory: string, supportedFileExtensions: string): Promise { +export async function getFiles( + pathToDirectory: string, + supportedFileExtensions: string, +): Promise { try { const files: FileDetails[] = []; - const filesInDirectory = (await fs.readdir(pathToDirectory)); + const filesInDirectory = await fs.readdir(pathToDirectory); for (const file of filesInDirectory) { const pathToFile = `${pathToDirectory}/${file}`.replace("//", "/"); const fileStat = await fs.lstat(pathToFile); - // check if file is file and file has supported file extension - if (fileStat.isFile() && file.includes(supportedFileExtensions) && file !== "miranum.json") { + // check if the file is file and file has supported file extension + if ( + fileStat.isFile() && + file.includes(supportedFileExtensions) && + file !== "miranum.json" + ) { files.push(await getFile(pathToFile)); } else if (fileStat.isDirectory()) { // search for files in subdir with recursive call @@ -63,12 +84,16 @@ export async function getFiles(pathToDirectory: string, supportedFileExtensions: // do nothing with unsupported files } return files; - } catch (error) { + } catch (error) { throw new Error(`File not found on path ${pathToDirectory}`); } } -export async function saveFile(projectDir: string, pathInProject: string, fileContent: string): Promise { +export async function saveFile( + projectDir: string, + pathInProject: string, + fileContent: string, +): Promise { const file = `${projectDir}/${pathInProject}`.replace("//", "/"); const projectPath = file.substring(0, file.lastIndexOf("/")); try { @@ -76,6 +101,9 @@ export async function saveFile(projectDir: string, pathInProject: string, fileCo } catch { await fs.mkdir(projectPath, { recursive: true }); } - await fs.writeFile(`${projectDir}/${pathInProject}`.replace("//", "/"), fileContent, { flag: "w+" }); + await fs.writeFile( + `${projectDir}/${pathInProject}`.replace("//", "/"), + fileContent, + { flag: "w+" }, + ); } - diff --git a/apps/miranum-cli/src/main.ts b/apps/miranum-cli/src/main.ts index 600b9071..afc7eaa5 100644 --- a/apps/miranum-cli/src/main.ts +++ b/apps/miranum-cli/src/main.ts @@ -6,7 +6,8 @@ import * as colors from "colors"; const program = new Command(); program .name("Miranum CLI") - .description(colors.green.bold(` + .description( + colors.green.bold(` ███╗ ███╗██╗██████╗ █████╗ ███╗ ██╗██╗ ██╗███╗ ███╗ ████╗ ████║██║██╔══██╗██╔══██╗████╗ ██║██║ ██║████╗ ████║ ██╔████╔██║██║██████╔╝███████║██╔██╗ ██║██║ ██║██╔████╔██║ @@ -20,7 +21,8 @@ program ██║██║ ██║██╔══╝ ██║██████╔╝███████╗ ╚═╝╚═════╝ ╚══════╝ -`)) +`), + ) .version("0.0.1"); program.addCommand(deployFile()); diff --git a/apps/miranum-cli/tests/deploymentApi.spec.ts b/apps/miranum-cli/tests/deploymentApi.spec.ts index 0e55292b..2d3add91 100644 --- a/apps/miranum-cli/tests/deploymentApi.spec.ts +++ b/apps/miranum-cli/tests/deploymentApi.spec.ts @@ -4,7 +4,7 @@ import { filesToDeploy, pathToProject, shouldNotWork, sleep } from "./testHelper // import * as colors from "colors"; const appPath = "dist/apps/miranum-clid/main.js"; -const target = "local" +const target = "local"; jest.setTimeout(30000); // jest.mock("axios"); @@ -16,7 +16,15 @@ describe("deploy all files", () => { it(`deploying my-process-automation-project e2e should work`, async () => { // const logSpy = jest.spyOn(console, "log"); const program = deployAllFiles(); - program.parse(["node", appPath, "deploy", "--directory", pathToProject, "--target", target]); + program.parse([ + "node", + appPath, + "deploy", + "--directory", + pathToProject, + "--target", + target, + ]); await sleep(3000); expect(program.args).toEqual(["deploy"]); @@ -29,27 +37,49 @@ describe("deploy all files", () => { }); it("should not work, due to unknown option", () => { - shouldNotWork(deployAllFiles(), "deploy", - ["node", appPath, "deploy", "--directory", pathToProject, "--target", target, "--randomArgument"], - "error: unknown option '--randomArgument'" + shouldNotWork( + deployAllFiles(), + "deploy", + [ + "node", + appPath, + "deploy", + "--directory", + pathToProject, + "--target", + target, + "--randomArgument", + ], + "error: unknown option '--randomArgument'", ); }); it(`should not work, due to missing argument`, async () => { - shouldNotWork(deployAllFiles(), "deploy", + shouldNotWork( + deployAllFiles(), + "deploy", ["node", appPath, "deploy", "--directory", pathToProject], - "error: required option '-t, --target ' not specified" + "error: required option '-t, --target ' not specified", ); }); }); - describe("deploy files", () => { for (const file of filesToDeploy) { it(`${file.type} should work`, async () => { // const logSpy = jest.spyOn(console, "log"); const program = deployFile(); - program.parse(["node", appPath, "deploy-file", "--file", file.path, "--target", target, "--type", file.type]); + program.parse([ + "node", + appPath, + "deploy-file", + "--file", + file.path, + "--target", + target, + "--type", + file.type, + ]); await sleep(1500); expect(program.args).toEqual(["deploy-file"]); @@ -61,24 +91,62 @@ describe("deploy files", () => { } it(`should not work, due to wrong type`, async () => { - const miranumJson = {path: "resources/my-process-automation-project/miranum.json", type: "json"} - shouldNotWork(deployFile(), "deploy-file", - ["node", appPath, "deploy-file", "--file", miranumJson.path, "--target", target, "--type", miranumJson.type], - "type must be either bpmn, dmn, form or config" + const miranumJson = { + path: "resources/my-process-automation-project/miranum.json", + type: "json", + }; + shouldNotWork( + deployFile(), + "deploy-file", + [ + "node", + appPath, + "deploy-file", + "--file", + miranumJson.path, + "--target", + target, + "--type", + miranumJson.type, + ], + "type must be either bpmn, dmn, form or config", ); }); it("should not work, due to unknown option", () => { - shouldNotWork(deployFile(), "deploy-file", - ["node", appPath, "deploy-file", "--file", filesToDeploy[0].path, "--target", target, "--type", filesToDeploy[0].type, "--randomArgument"], - "error: unknown option '--randomArgument'" + shouldNotWork( + deployFile(), + "deploy-file", + [ + "node", + appPath, + "deploy-file", + "--file", + filesToDeploy[0].path, + "--target", + target, + "--type", + filesToDeploy[0].type, + "--randomArgument", + ], + "error: unknown option '--randomArgument'", ); }); it(`should not work, due to missing argument`, async () => { - shouldNotWork(deployFile(), "deploy-file", - ["node", appPath, "deploy-file", "--file", filesToDeploy[0].path, "--type", filesToDeploy[0].type], - "error: required option '-t, --target ' not specified" + shouldNotWork( + deployFile(), + "deploy-file", + [ + "node", + appPath, + "deploy-file", + "--file", + filesToDeploy[0].path, + "--type", + filesToDeploy[0].type, + ], + "error: required option '-t, --target ' not specified", ); }); }); diff --git a/apps/miranum-cli/tests/generateApi.spec.ts b/apps/miranum-cli/tests/generateApi.spec.ts index a9fe72d0..a191b31f 100644 --- a/apps/miranum-cli/tests/generateApi.spec.ts +++ b/apps/miranum-cli/tests/generateApi.spec.ts @@ -135,6 +135,7 @@ describe("generate file", () => { myGenerations, expectedFilePath, ); + // eslint-disable-next-line @typescript-eslint/no-empty-function fs.rm(expectedFilePath, () => {}); }); @@ -253,6 +254,7 @@ function checkArgsAndPath(program: Command, args: string[], path: string) { function checkExistence(path: string, expectation: boolean) { try { + // eslint-disable-next-line @typescript-eslint/no-empty-function fs.open(path, "r", () => {}); expect(expectation).toBe(true); } catch (e) { @@ -281,5 +283,6 @@ function fileChecks( } function cleanUpDir() { + // eslint-disable-next-line @typescript-eslint/no-empty-function fs.rm(dirPath, { recursive: true }, () => {}); } diff --git a/apps/miranum-cli/tests/testHelpers.ts b/apps/miranum-cli/tests/testHelpers.ts index 9b9a4308..641fed80 100644 --- a/apps/miranum-cli/tests/testHelpers.ts +++ b/apps/miranum-cli/tests/testHelpers.ts @@ -1,4 +1,4 @@ -import {Command} from "commander"; +import { Command } from "commander"; interface FileHelper { nameExt: string; @@ -9,18 +9,49 @@ interface FileHelper { export const pathToProject = "resources/my-process-automation-project"; export const filesToDeploy: FileHelper[] = [ - {nameExt: "my-process.bpmn", path: "resources/my-process-automation-project/my-process.bpmn", type: "bpmn"}, - {nameExt: "dmn-table.dmn", path: "resources/my-process-automation-project/dmn-table.dmn", type: "dmn"}, - {nameExt: "StartFormular.form", path: "resources/my-process-automation-project/forms/StartFormular.form", type: "form"}, - {nameExt: "KontrollFormular.json", path: "resources/my-process-automation-project/my-other-forms/KontrollFormular.json", type: "form"}, - {nameExt: "dev-process.config.json", path: "resources/my-process-automation-project/configs/dev-process.config.json", type: "config"}, + { + nameExt: "my-process.bpmn", + path: "resources/my-process-automation-project/my-process.bpmn", + type: "bpmn", + }, + { + nameExt: "dmn-table.dmn", + path: "resources/my-process-automation-project/dmn-table.dmn", + type: "dmn", + }, + { + nameExt: "StartFormular.form", + path: "resources/my-process-automation-project/forms/StartFormular.form", + type: "form", + }, + { + nameExt: "KontrollFormular.json", + path: "resources/my-process-automation-project/my-other-forms/KontrollFormular.json", + type: "form", + }, + { + nameExt: "dev-process.config.json", + path: "resources/my-process-automation-project/configs/dev-process.config.json", + type: "config", + }, ]; -export function shouldNotWork(program: Command, command: string, argv: readonly string[], error: string) { - program.exitOverride().command(command).action(() => {}); +export function shouldNotWork( + program: Command, + command: string, + argv: readonly string[], + error: string, +) { + program + .exitOverride() + .command(command) + // eslint-disable-next-line @typescript-eslint/no-empty-function + .action(() => {}); // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore - expect(() => {program.parse(argv)}).toThrow(error); + expect(() => { + program.parse(argv); + }).toThrow(error); } export async function sleep(time: number) { diff --git a/apps/miranum-config-editor-webview/src/App.vue b/apps/miranum-config-editor-webview/src/App.vue index ec899173..20ed5935 100644 --- a/apps/miranum-config-editor-webview/src/App.vue +++ b/apps/miranum-config-editor-webview/src/App.vue @@ -24,7 +24,6 @@ import { createResolver } from "./composables/utils"; // declare const process: { env: { NODE_ENV: string } }; -// eslint-disable-next-line react-hooks/rules-of-hooks const theme = useTheme(); const renderers = [...vuetifyRenderers]; diff --git a/apps/miranum-config-editor/src/adapter/adapterIn.ts b/apps/miranum-config-editor/src/adapter/adapterIn.ts index a09537a0..64a74bc5 100644 --- a/apps/miranum-config-editor/src/adapter/adapterIn.ts +++ b/apps/miranum-config-editor/src/adapter/adapterIn.ts @@ -8,6 +8,9 @@ import { TextDocument, Uri, Webview, workspace } from "vscode"; import { inject, injectable } from "tsyringe"; +// prettier-ignore +import { ConfigEditorData, MessageType, VscMessage } from "@miranum-ide/vscode/shared/miranum-config-editor"; + import { EXTENSION_CONTEXT, setUpdateFrom, updateFrom, UpdateFrom } from "../common"; import { InitWebviewCommand, @@ -21,9 +24,8 @@ import { SyncDocumentCommand, SyncDocumentInPort, SyncWebviewCommand, - SyncWebviewInPort + SyncWebviewInPort, } from "../application/portsIn"; -import { ConfigEditorData, MessageType, VscMessage } from "@miranum-ide/vscode/shared/miranum-config-editor"; /** * @class WebviewAdapter diff --git a/apps/miranum-config-editor/src/adapter/adapterOut.ts b/apps/miranum-config-editor/src/adapter/adapterOut.ts index 481c0550..182eebe4 100644 --- a/apps/miranum-config-editor/src/adapter/adapterOut.ts +++ b/apps/miranum-config-editor/src/adapter/adapterOut.ts @@ -10,7 +10,9 @@ import { Range, TextDocument, Uri, Webview, workspace, WorkspaceEdit } from "vscode"; import { Buffer } from "node:buffer"; +// prettier-ignore import { DocumentOutPort, ReaderOutPort, VsCodeConfigOutPort, WebviewOutPort } from "../application/portsOut"; +// prettier-ignore import { ConfigEditorData, VscMessage } from "@miranum-ide/vscode/shared/miranum-config-editor"; /** diff --git a/apps/miranum-config-editor/src/application/usecases.ts b/apps/miranum-config-editor/src/application/usecases.ts index 242e539e..9d9ae765 100644 --- a/apps/miranum-config-editor/src/application/usecases.ts +++ b/apps/miranum-config-editor/src/application/usecases.ts @@ -24,9 +24,11 @@ import { SyncDocumentCommand, SyncDocumentInPort, SyncWebviewCommand, - SyncWebviewInPort + SyncWebviewInPort, } from "./portsIn"; +// prettier-ignore import { DocumentOutPort, ReaderOutPort, VsCodeConfigOutPort, WebviewOutPort } from "./portsOut"; +// prettier-ignore import { ConfigEditorData, MessageType, VscMessage } from "@miranum-ide/vscode/shared/miranum-config-editor"; /** diff --git a/apps/miranum-console/src/app/generate/commands.ts b/apps/miranum-console/src/app/generate/commands.ts index dd95dfb6..f7a4d42a 100644 --- a/apps/miranum-console/src/app/generate/commands.ts +++ b/apps/miranum-console/src/app/generate/commands.ts @@ -2,7 +2,11 @@ import * as vscode from "vscode"; import { Uri } from "vscode"; import { Artifact, MiranumCore } from "@miranum-ide/miranum-core"; import { VscMessage } from "@miranum-ide/vscode/miranum-vscode-webview"; -import { ConsoleData, FileData, MessageType } from "@miranum-ide/vscode/shared/miranum-console"; +import { + ConsoleData, + FileData, + MessageType, +} from "@miranum-ide/vscode/shared/miranum-console"; import { Logger } from "@miranum-ide/vscode/miranum-vscode"; import { saveFile, selectFiles } from "../shared/fs-helpers"; import { showErrorMessage, showInfoMessage } from "../shared/message"; diff --git a/apps/miranum-console/src/app/vscode/MiranumTreeDataProvider.ts b/apps/miranum-console/src/app/vscode/MiranumTreeDataProvider.ts index 90297ec7..b710f627 100644 --- a/apps/miranum-console/src/app/vscode/MiranumTreeDataProvider.ts +++ b/apps/miranum-console/src/app/vscode/MiranumTreeDataProvider.ts @@ -20,7 +20,7 @@ export class MiranumTreeDataProvider implements TreeDataProvider { private readonly workspace?: WorkspaceFolder; private _onDidChangeTreeData: vscode.EventEmitter< - FolderItem | undefined | null | void + FolderItem | undefined | null | void > = new vscode.EventEmitter(); readonly onDidChangeTreeData: vscode.Event = diff --git a/apps/miranum-jsonforms-preview-webview/src/App.vue b/apps/miranum-jsonforms-preview-webview/src/App.vue index a3342bb1..767d11dd 100644 --- a/apps/miranum-jsonforms-preview-webview/src/App.vue +++ b/apps/miranum-jsonforms-preview-webview/src/App.vue @@ -54,7 +54,6 @@ const displayData = ref(undefined); const displayErrors = ref(undefined); let loading = true; -// eslint-disable-next-line react-hooks/rules-of-hooks const theme = useTheme(); let jsonComponentTheme = ref<"light" | "dark">("light"); diff --git a/apps/miranum-modeler-bpmn-webview/src/types/diagram-js.d.ts b/apps/miranum-modeler-bpmn-webview/src/types/diagram-js.d.ts index 9128c8c5..0cf73cca 100644 --- a/apps/miranum-modeler-bpmn-webview/src/types/diagram-js.d.ts +++ b/apps/miranum-modeler-bpmn-webview/src/types/diagram-js.d.ts @@ -8,9 +8,8 @@ declare module "diagram-js/lib/core/EventBus" { data: any, ) => any; - export type EventType = EventMap extends Record - ? E - : InternalEvent; + export type EventType = + EventMap extends Record ? E : InternalEvent; interface EventMap { "commandStack.changed": CommandStackChangedEvent; @@ -19,10 +18,13 @@ declare module "diagram-js/lib/core/EventBus" { export interface InternalEvent { cancelBubble?: boolean; defaultPrevented?: boolean; + [field: string]: any; init(data: any): void; + stopPropagation(): void; + preventDefault(): void; } diff --git a/apps/miranum-modeler-dmn-webview/src/types/diagram-js.d.ts b/apps/miranum-modeler-dmn-webview/src/types/diagram-js.d.ts index 67450f80..0cf73cca 100644 --- a/apps/miranum-modeler-dmn-webview/src/types/diagram-js.d.ts +++ b/apps/miranum-modeler-dmn-webview/src/types/diagram-js.d.ts @@ -5,24 +5,26 @@ declare module "diagram-js/lib/core/EventBus" { export type EventCallback = ( event: EventType, - data: any + data: any, ) => any; - export type EventType = EventMap extends Record - ? E - : InternalEvent; + export type EventType = + EventMap extends Record ? E : InternalEvent; interface EventMap { - "commandStack.changed": CommandStackChangedEvent + "commandStack.changed": CommandStackChangedEvent; } export interface InternalEvent { cancelBubble?: boolean; defaultPrevented?: boolean; + [field: string]: any; init(data: any): void; + stopPropagation(): void; + preventDefault(): void; } diff --git a/libs/miranum-core/src/index.ts b/libs/miranum-core/src/index.ts index 9d8449bc..241a2445 100644 --- a/libs/miranum-core/src/index.ts +++ b/libs/miranum-core/src/index.ts @@ -3,4 +3,4 @@ export * from "./lib/types"; export * from "./lib/deployment/plugins"; export * from "./lib/deployment/rest/miranum-deployment-plugin-rest"; export * from "./lib/deployment/rest/openapi/api"; -export * from "./lib/deployment/rest/openapi/configuration" +export * from "./lib/deployment/rest/openapi/configuration"; diff --git a/libs/miranum-core/src/lib/deployment/plugins.ts b/libs/miranum-core/src/lib/deployment/plugins.ts index 841d7a2b..786be9a7 100644 --- a/libs/miranum-core/src/lib/deployment/plugins.ts +++ b/libs/miranum-core/src/lib/deployment/plugins.ts @@ -4,18 +4,16 @@ import { MiranumDeploymentPlugin } from "../types"; const restPlugin = new MiranumDeploymentPluginRest("rest", [ { name: "local", - url: "http://localhost:8080" + url: "http://localhost:8080", }, { name: "dev", - url: "http://localhost:8080" + url: "http://localhost:8080", }, { name: "test", - url: "http://localhost:8080" - } + url: "http://localhost:8080", + }, ]); -export const availableDeploymentPlugins: MiranumDeploymentPlugin[] = [ - restPlugin -]; +export const availableDeploymentPlugins: MiranumDeploymentPlugin[] = [restPlugin]; diff --git a/libs/miranum-core/src/lib/deployment/rest/miranum-deployment-plugin-rest.spec.ts b/libs/miranum-core/src/lib/deployment/rest/miranum-deployment-plugin-rest.spec.ts index c4a7af86..fc7b8ec7 100644 --- a/libs/miranum-core/src/lib/deployment/rest/miranum-deployment-plugin-rest.spec.ts +++ b/libs/miranum-core/src/lib/deployment/rest/miranum-deployment-plugin-rest.spec.ts @@ -1,14 +1,25 @@ -import {MiranumDeploymentPluginRest} from "./miranum-deployment-plugin-rest"; +import { MiranumDeploymentPluginRest } from "./miranum-deployment-plugin-rest"; describe("deploy", () => { it("should come back as false", async () => { - const mdpr = new MiranumDeploymentPluginRest("test", [{name:"testfail",url:"www.xD.org"}]); - const artifact = {type: "type1", - project: "project1", - file: {name: "name", extension: "extension", content: "content", size: 1, path: "path1"} - }; + const mdpr = new MiranumDeploymentPluginRest("test", [ + { name: "testfail", url: "www.xD.org" }, + ]); - mdpr.deploy("hi", artifact) - .catch(err => expect(err.message).toContain("No target configured for")) + const artifact = { + type: "type1", + project: "project1", + file: { + name: "name", + extension: "extension", + content: "content", + size: 1, + path: "path1", + }, + }; + + mdpr.deploy("hi", artifact).catch((err) => + expect(err.message).toContain("No target configured for"), + ); }); }); diff --git a/libs/miranum-core/src/lib/deployment/rest/miranum-deployment-plugin-rest.ts b/libs/miranum-core/src/lib/deployment/rest/miranum-deployment-plugin-rest.ts index 6c08cb3e..9e4e70c1 100644 --- a/libs/miranum-core/src/lib/deployment/rest/miranum-deployment-plugin-rest.ts +++ b/libs/miranum-core/src/lib/deployment/rest/miranum-deployment-plugin-rest.ts @@ -1,7 +1,6 @@ import { Configuration, DeploymentAPIApi } from "./openapi"; import { Artifact, MiranumDeploymentPlugin, MiranumDeploymentTarget } from "../../types"; - export class MiranumDeploymentPluginRest implements MiranumDeploymentPlugin { plugin: string; @@ -12,8 +11,8 @@ export class MiranumDeploymentPluginRest implements MiranumDeploymentPlugin { this.targetEnvironments = targetEnvironments; } - async deploy(target : string, artifact : Artifact) : Promise { - const targetEnv = this.targetEnvironments.filter(env => env.name === target); + async deploy(target: string, artifact: Artifact): Promise { + const targetEnv = this.targetEnvironments.filter((env) => env.name === target); if (targetEnv.length === 0) { throw new Error(`No target configured for ${target}`); } @@ -22,13 +21,16 @@ export class MiranumDeploymentPluginRest implements MiranumDeploymentPlugin { target: target, artifact: { ...artifact, - } + }, }; - const response = await new DeploymentAPIApi(new Configuration({basePath: targetEnv[0].url})).deployArtifact(deployment); + const response = await new DeploymentAPIApi( + new Configuration({ basePath: targetEnv[0].url }), + ).deployArtifact(deployment); if (!response.data.success) { - throw new Error(`Failed deployment of artifact ${artifact.file.name} to environment ${target}`); + throw new Error( + `Failed deployment of artifact ${artifact.file.name} to environment ${target}`, + ); } return artifact; } - } diff --git a/libs/miranum-core/src/lib/generate/plugins.spec.ts b/libs/miranum-core/src/lib/generate/plugins.spec.ts index cf5ac954..91e0e548 100644 --- a/libs/miranum-core/src/lib/generate/plugins.spec.ts +++ b/libs/miranum-core/src/lib/generate/plugins.spec.ts @@ -1,5 +1,5 @@ import { availableGeneratorPlugins } from "./plugins"; -import {Artifact} from "../types"; +import { Artifact } from "../types"; interface FileHelper { name: string; @@ -9,14 +9,19 @@ interface FileHelper { } const filesToGenerate: FileHelper[] = [ - {name: "my-process", type: "bpmn", extension: ".bpmn", dir: ""}, - {name: "my-decision-table", type: "dmn", extension: ".dmn", dir: ""}, - {name: "my-form", type: "form", extension: ".form", dir: "forms"}, - {name: "my-config", type: "config", extension: ".config.json", dir: "configs"}, - {name: "my-element-template", type: "element-template", extension: ".json", dir: "element-templates"}, - {name: "miranum", type: "miranum.json", extension: ".json", dir: ""}, - {name: "README", type: "README.md", extension: ".md", dir: ""}, - {name: " ", type: ".gitkeep", extension: ".gitkeep", dir: "element-templates"} + { name: "my-process", type: "bpmn", extension: ".bpmn", dir: "" }, + { name: "my-decision-table", type: "dmn", extension: ".dmn", dir: "" }, + { name: "my-form", type: "form", extension: ".form", dir: "forms" }, + { name: "my-config", type: "config", extension: ".config.json", dir: "configs" }, + { + name: "my-element-template", + type: "element-template", + extension: ".json", + dir: "element-templates", + }, + { name: "miranum", type: "miranum.json", extension: ".json", dir: "" }, + { name: "README", type: "README.md", extension: ".md", dir: "" }, + { name: " ", type: ".gitkeep", extension: ".gitkeep", dir: "element-templates" }, ]; describe("generators with miranum-core", () => { @@ -28,18 +33,31 @@ describe("generators with miranum-core", () => { const artifact = await generator.generate(file.name, "test-project"); compareArtifactFile(artifact, file); expect(artifact.project).toEqual("test-project"); - expect(artifact.file.pathInProject).toEqual(`/${file.dir}/${file.name}${file.extension}`.replace("//", "/")); + expect(artifact.file.pathInProject).toEqual( + `/${file.dir}/${file.name}${file.extension}`.replace("//", "/"), + ); }); } it(`generator should work with custom file-extensions`, async () => { - const file: FileHelper = {name: "my-form", type: "form", extension: ".random.extension", dir: "forms"}; + const file: FileHelper = { + name: "my-form", + type: "form", + extension: ".random.extension", + dir: "forms", + }; const generator = getGenerator(file.type); - const artifact = await generator.generate(file.name, "test-project", file.extension); + const artifact = await generator.generate( + file.name, + "test-project", + file.extension, + ); compareArtifactFile(artifact, file); expect(artifact.project).toEqual("test-project"); - expect(artifact.file.pathInProject).toEqual(`/${file.dir}/${file.name}${file.extension}`.replace("//", "/")); + expect(artifact.file.pathInProject).toEqual( + `/${file.dir}/${file.name}${file.extension}`.replace("//", "/"), + ); }); }); @@ -50,10 +68,12 @@ describe("generators without miranum-core", () => { const artifact = await generator.generate(file.name, "", file.extension, ""); compareArtifactFile(artifact, file); - expect(artifact.file.pathInProject).toEqual(`/${file.name}${file.extension}`); + expect(artifact.file.pathInProject).toEqual( + `/${file.name}${file.extension}`, + ); }); } -}) +}); // -------------------------HELPERS------------------------- \\ function getGenerator(type: string) { @@ -67,7 +87,7 @@ function getGenerator(type: string) { return generator; } -function compareArtifactFile(artifact:Artifact, file: FileHelper) { +function compareArtifactFile(artifact: Artifact, file: FileHelper) { expect(artifact.type).toEqual(file.type); expect(artifact.file.name).toEqual(file.name); expect(artifact.file.extension).toEqual(file.extension); diff --git a/libs/miranum-core/src/lib/generate/plugins.ts b/libs/miranum-core/src/lib/generate/plugins.ts index 74c19244..adbc647a 100644 --- a/libs/miranum-core/src/lib/generate/plugins.ts +++ b/libs/miranum-core/src/lib/generate/plugins.ts @@ -3,7 +3,7 @@ import * as Sqrl from "squirrelly"; import { v4 as uuidv4 } from "uuid"; export class MiranumArtifactGenerator implements MiranumGeneratorPlugin { - type : string; + type: string; defaultFileExtension: string; @@ -13,7 +13,13 @@ export class MiranumArtifactGenerator implements MiranumGeneratorPlugin { defaultData: object; - constructor(type: string, defaultFileExtension: string, template: string, defaultData: object, basePath: string) { + constructor( + type: string, + defaultFileExtension: string, + template: string, + defaultData: object, + basePath: string, + ) { this.type = type; this.defaultFileExtension = defaultFileExtension; this.template = template; @@ -21,7 +27,12 @@ export class MiranumArtifactGenerator implements MiranumGeneratorPlugin { this.defaultData = defaultData; } - async generate(name : string, project: string, extension?: string, pathInProject?: string) : Promise { + async generate( + name: string, + project: string, + extension?: string, + pathInProject?: string, + ): Promise { const fileName: string = name.replace(/\.[^/.]+$/, ""); /* eslint-disable @typescript-eslint/no-explicit-any */ const data: any = this.defaultData; @@ -35,20 +46,21 @@ export class MiranumArtifactGenerator implements MiranumGeneratorPlugin { name: fileName, extension: fileExtension, content: fileContent, - pathInProject: `${pathInProject ?? this.basePath}/${name}${fileExtension}` - } + pathInProject: `${pathInProject ?? this.basePath}/${name}${fileExtension}`, + }; return { type: this.type, project: project, - file: fileDetails - } + file: fileDetails, + }; } } - // -----------------------------Generators----------------------------- \\ -const bpmnGenerator = new MiranumArtifactGenerator("bpmn", ".bpmn", +const bpmnGenerator = new MiranumArtifactGenerator( + "bpmn", + ".bpmn", ` @@ -63,9 +75,14 @@ const bpmnGenerator = new MiranumArtifactGenerator("bpmn", ".bpmn", -`, {version: "7.17.0"}, ""); - -const dmnGenerator = new MiranumArtifactGenerator("dmn", ".dmn", +`, + { version: "7.17.0" }, + "", +); + +const dmnGenerator = new MiranumArtifactGenerator( + "dmn", + ".dmn", ` @@ -85,9 +102,15 @@ const dmnGenerator = new MiranumArtifactGenerator("dmn", ".dmn", -`, {version: "7.17.0"}, ""); - -const formGenerator = new MiranumArtifactGenerator("form", ".form", `{ +`, + { version: "7.17.0" }, + "", +); + +const formGenerator = new MiranumArtifactGenerator( + "form", + ".form", + `{ "key": "{{it.name}}", "schema": { "type": "object", @@ -106,9 +129,15 @@ const formGenerator = new MiranumArtifactGenerator("form", ".form", `{ } ] } -}`, {allOfKey: "FORMSECTION_input"}, "/forms"); - -const configGenerator = new MiranumArtifactGenerator("config", ".config.json", `{ +}`, + { allOfKey: "FORMSECTION_input" }, + "/forms", +); + +const configGenerator = new MiranumArtifactGenerator( + "config", + ".config.json", + `{ "key": "{{it.name}}", "statusDokument": "", "statusConfig": [], @@ -118,9 +147,15 @@ const configGenerator = new MiranumArtifactGenerator("config", ".config.json", ` "value": "" } ] -}`, {}, "/configs"); - -const elementTemplateGenerator = new MiranumArtifactGenerator("element-template", ".json", `{ +}`, + {}, + "/configs", +); + +const elementTemplateGenerator = new MiranumArtifactGenerator( + "element-template", + ".json", + `{ "$schema": "https://unpkg.com/@camunda/element-templates-json-schema/resources/schema.json", "name": "{{it.name}}", "id": "{{it.id}}", @@ -128,9 +163,15 @@ const elementTemplateGenerator = new MiranumArtifactGenerator("element-template" "bpmn:ServiceTask" ], "properties": [] -}`, {}, "/element-templates"); - -const miranumJsonGenerator = new MiranumArtifactGenerator("miranum.json", ".json", `{ +}`, + {}, + "/element-templates", +); + +const miranumJsonGenerator = new MiranumArtifactGenerator( + "miranum.json", + ".json", + `{ "projectVersion": "1.0.0", "name": "{{it.projectName}}", "workspace": [ @@ -159,11 +200,22 @@ const miranumJsonGenerator = new MiranumArtifactGenerator("miranum.json", ".jso ] } ] -}`, {}, ""); - -const gitkeepGenerator = new MiranumArtifactGenerator(".gitkeep", ".gitkeep", "{{it.data}}", {data:""}, "/element-templates"); - -const readmeGenerator = new MiranumArtifactGenerator("README.md", ".md", +}`, + {}, + "", +); + +const gitkeepGenerator = new MiranumArtifactGenerator( + ".gitkeep", + ".gitkeep", + "{{it.data}}", + { data: "" }, + "/element-templates", +); + +const readmeGenerator = new MiranumArtifactGenerator( + "README.md", + ".md", `# {{it.projectName}} . @@ -180,9 +232,15 @@ const readmeGenerator = new MiranumArtifactGenerator("README.md", ".md", │ ├── miranum.json └── example-bpmn.bpmn -`, {}, ""); - -export const availableGeneratorPlugins: Map = new Map([ +`, + {}, + "", +); + +export const availableGeneratorPlugins: Map = new Map< + string, + MiranumGeneratorPlugin +>([ [bpmnGenerator.type, bpmnGenerator], [dmnGenerator.type, dmnGenerator], [formGenerator.type, formGenerator], diff --git a/libs/miranum-core/src/lib/miranum-core.spec.ts b/libs/miranum-core/src/lib/miranum-core.spec.ts index 562e56e3..5d7c3bb7 100644 --- a/libs/miranum-core/src/lib/miranum-core.spec.ts +++ b/libs/miranum-core/src/lib/miranum-core.spec.ts @@ -3,11 +3,11 @@ import { Artifact, MiranumWorkspaceItem } from "./types"; const sampleTarget = "local"; const workspace: MiranumWorkspaceItem[] = [ - {type: "bpmn", path: "", extension: ".bpmn" }, - {type: "dmn", path: "", extension: ".dmn" }, - {type: "form", path: "forms", extension: ".form" }, - {type: "element-template", path: "element-templates", extension: ".json" }, - {type:"config", path: "configs", extension: ".config.json" } + { type: "bpmn", path: "", extension: ".bpmn" }, + { type: "dmn", path: "", extension: ".dmn" }, + { type: "form", path: "forms", extension: ".form" }, + { type: "element-template", path: "element-templates", extension: ".json" }, + { type: "config", path: "configs", extension: ".config.json" }, ]; const deploymentPlugin = [ { @@ -15,23 +15,28 @@ const deploymentPlugin = [ targetEnvironments: [ { name: "local", - url: "http://localhost:8080" + url: "http://localhost:8080", }, { name: "dev", - url: "http://localhost:8080" + url: "http://localhost:8080", }, { name: "test", - url: "http://localhost:8080" - } + url: "http://localhost:8080", + }, ], - async deploy(target : string, artifact : Artifact) : Promise { + async deploy(target: string, artifact: Artifact): Promise { return artifact; - } - } + }, + }, ]; -const miranumCore: MiranumCore = createMiranumCore("1.0.0", "my-project", workspace, deploymentPlugin); +const miranumCore: MiranumCore = createMiranumCore( + "1.0.0", + "my-project", + workspace, + deploymentPlugin, +); describe("deploy", () => { it("should work", async () => { @@ -42,9 +47,9 @@ describe("deploy", () => { name: "example.bpmn", extension: ".bpmn", content: "...", - size: 500 - } - } + size: 500, + }, + }; const deployment = await miranumCore.deploy(sampleTarget, exampleArtifact); @@ -59,11 +64,12 @@ describe("deploy", () => { name: "example.bpmn", extension: ".bpmn", content: "...", - size: 500 - } - } - await miranumCore.deploy(sampleTarget, exampleArtifact) - .catch(e => expect(e).not.toBeNull()); + size: 500, + }, + }; + await miranumCore + .deploy(sampleTarget, exampleArtifact) + .catch((e) => expect(e).not.toBeNull()); }); }); @@ -76,26 +82,45 @@ describe("generate", () => { } const filesToGenerate: FileHelper[] = [ - {name: "my-process", type: "bpmn", extension: ".bpmn", dir: ""}, - {name: "my-decision-table", type: "dmn", extension: ".dmn", dir: ""}, - {name: "my-form", type: "form", extension: ".form", dir: "forms"}, - {name: "my-config", type: "config", extension: ".config.json", dir: "configs"}, - {name: "my-element-template", type: "element-template", extension: ".json", dir: "element-templates"}, + { name: "my-process", type: "bpmn", extension: ".bpmn", dir: "" }, + { name: "my-decision-table", type: "dmn", extension: ".dmn", dir: "" }, + { name: "my-form", type: "form", extension: ".form", dir: "forms" }, + { name: "my-config", type: "config", extension: ".config.json", dir: "configs" }, + { + name: "my-element-template", + type: "element-template", + extension: ".json", + dir: "element-templates", + }, ]; for (const file of filesToGenerate) { it(`generate ${file.type} on top-level`, async () => { - const artifact = await miranumCore.generateArtifact(file.name, file.type, "my-project", "imaginary/path/my-project"); + const artifact = await miranumCore.generateArtifact( + file.name, + file.type, + "my-project", + "imaginary/path/my-project", + ); //name, type, and extension are tested in plugisn.spec.ts expect(artifact.project).toEqual("my-project"); - expect(artifact.file.pathInProject).toEqual(`${file.dir}/${file.name}${file.extension}`); + expect(artifact.file.pathInProject).toEqual( + `${file.dir}/${file.name}${file.extension}`, + ); }); it(`generate ${file.type} in subfolder`, async () => { - const artifact = await miranumCore.generateArtifact(file.name, file.type, "my-project", "imaginary/path/my-project/subfolder"); + const artifact = await miranumCore.generateArtifact( + file.name, + file.type, + "my-project", + "imaginary/path/my-project/subfolder", + ); //name, type, and extension are tested in plugisn.spec.ts expect(artifact.project).toEqual("my-project"); - expect(artifact.file.pathInProject).toEqual(`/${file.name}${file.extension}`); + expect(artifact.file.pathInProject).toEqual( + `/${file.name}${file.extension}`, + ); }); } }); diff --git a/libs/miranum-core/src/lib/miranum-core.ts b/libs/miranum-core/src/lib/miranum-core.ts index 8416647c..e7efee28 100644 --- a/libs/miranum-core/src/lib/miranum-core.ts +++ b/libs/miranum-core/src/lib/miranum-core.ts @@ -3,11 +3,16 @@ import { MiranumConfig, MiranumDeploymentPlugin, MiranumGeneratorPlugin, - MiranumWorkspaceItem + MiranumWorkspaceItem, } from "./types"; import { availableGeneratorPlugins } from "./generate/plugins"; -export function createMiranumCore(projectVersion: string, projectName: string, workspace: MiranumWorkspaceItem[], deployment: MiranumDeploymentPlugin[]): MiranumCore { +export function createMiranumCore( + projectVersion: string, + projectName: string, + workspace: MiranumWorkspaceItem[], + deployment: MiranumDeploymentPlugin[], +): MiranumCore { return new MiranumCore({ projectVersion: projectVersion, name: projectName, @@ -29,7 +34,9 @@ export class MiranumCore { public async deploy(target: string, artifact: Artifact): Promise { if (!this.projectConfig) { - throw new Error("Config not available. Please initialize digiwfLib with a valid config"); + throw new Error( + "Config not available. Please initialize digiwfLib with a valid config", + ); } if (!checkIfSupportedType(artifact.type)) { @@ -37,7 +44,9 @@ export class MiranumCore { } await Promise.all( - this.projectConfig.deployment.map(plugin => plugin.deploy(target, artifact)), + this.projectConfig.deployment.map((plugin) => + plugin.deploy(target, artifact), + ), ); return artifact; } @@ -53,14 +62,21 @@ export class MiranumCore { { name: `${projectName}_start`, type: "form" }, { name: `${projectName}_control`, type: "form" }, ]; - const generatedFiles = []; + const generatedFiles: Artifact[] = []; for (const file of filesToGenerate) { - generatedFiles.push(await this.initArtifact(file.name, file.type, projectName)); + generatedFiles.push( + await this.initArtifact(file.name, file.type, projectName), + ); } return generatedFiles; } - public async generateArtifact(artifactName: string, type: string, projectName: string, projectPath: string): Promise { + public async generateArtifact( + artifactName: string, + type: string, + projectName: string, + projectPath: string, + ): Promise { /** First, checks if we have a projectConfig, with a valid workspace for the type && if we are on "root-level" of the project * if true: initialise an artifact with the artifact.pathInProject set as the projectConfig.workspace defines it, * otherwise: initialise the artifact as a standalone artifact @@ -71,7 +87,9 @@ export class MiranumCore { // if project root folder if (this.projectConfig && lastFolder === projectName) { // finds the first item - const miranumWorkspaceItem = this.projectConfig.workspace.find(ws => ws.type === type); + const miranumWorkspaceItem = this.projectConfig.workspace.find( + (ws) => ws.type === type, + ); if (miranumWorkspaceItem) { pathInProject = miranumWorkspaceItem.path; } @@ -86,15 +104,20 @@ export class MiranumCore { * @param pathInProject if undefined, default/base path will be used => should only be undefined to generate a project * @private */ - private async initArtifact(artifactName: string, type: string, project: string, pathInProject?: string): Promise { + private async initArtifact( + artifactName: string, + type: string, + project: string, + pathInProject?: string, + ): Promise { const generator = this.generatorPlugins.get(type); if (!generator) { throw new Error(`File type ${type} is not supported.`); } - let extension = undefined; + let extension = ""; // eslint-disable-next-line array-callback-return - this.projectConfig?.workspace.find( workspace => { + this.projectConfig?.workspace.find((workspace) => { if (workspace.type === type) { extension = workspace.extension; } @@ -104,6 +127,7 @@ export class MiranumCore { } const supportedTypes = ["bpmn", "dmn", "form", "config"]; + /** * If the type is supported for deployment the function returns true * @param type type of the artifact that is to be deployed diff --git a/libs/miranum-core/src/lib/types.ts b/libs/miranum-core/src/lib/types.ts index e49c722a..a536e1d0 100644 --- a/libs/miranum-core/src/lib/types.ts +++ b/libs/miranum-core/src/lib/types.ts @@ -1,7 +1,7 @@ export interface Artifact { - type: string, - project: string, - file: FileDetails + type: string; + project: string; + file: FileDetails; } export interface FileDetails { @@ -13,7 +13,7 @@ export interface FileDetails { } export interface MiranumConfig { - projectVersion: string, + projectVersion: string; name: string; workspace: MiranumWorkspaceItem[]; deployment: MiranumDeploymentPlugin[]; @@ -28,6 +28,7 @@ export interface MiranumWorkspaceItem { export interface MiranumDeploymentPlugin { plugin: string; targetEnvironments: MiranumDeploymentTarget[]; + deploy(target: string, artifact: Artifact): Promise; } @@ -37,7 +38,13 @@ export interface MiranumGeneratorPlugin { template: string; basePath: string | undefined; defaultData: object; - generate(name: string, project: string, extension?: string, pathInProject?: string): Promise + + generate( + name: string, + project: string, + extension?: string, + pathInProject?: string, + ): Promise; } export interface MiranumDeploymentTarget { diff --git a/libs/miranum-core/tsconfig.lib.json b/libs/miranum-core/tsconfig.lib.json index 0e2a172a..2c629c93 100644 --- a/libs/miranum-core/tsconfig.lib.json +++ b/libs/miranum-core/tsconfig.lib.json @@ -4,8 +4,17 @@ "module": "commonjs", "outDir": "../../dist/out-tsc", "declaration": true, - "types": ["node"] + "types": [ + "node" + ], + "noImplicitAny": false }, - "exclude": ["jest.config.ts", "**/*.spec.ts", "**/*.test.ts"], - "include": ["**/*.ts"] + "exclude": [ + "jest.config.ts", + "**/*.spec.ts", + "**/*.test.ts" + ], + "include": [ + "**/*.ts" + ] } diff --git a/libs/miranum-core/tsconfig.spec.json b/libs/miranum-core/tsconfig.spec.json index ff08addd..6c585dee 100644 --- a/libs/miranum-core/tsconfig.spec.json +++ b/libs/miranum-core/tsconfig.spec.json @@ -3,7 +3,11 @@ "compilerOptions": { "outDir": "../../dist/out-tsc", "module": "commonjs", - "types": ["jest", "node"] + "types": [ + "jest", + "node" + ], + "noImplicitAny": false }, "include": [ "jest.config.ts",