Skip to content

Commit

Permalink
feat: process-ide.json (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
lmoesle authored Nov 12, 2022
1 parent ddbaead commit b1de728
Show file tree
Hide file tree
Showing 16 changed files with 265 additions and 126 deletions.
76 changes: 42 additions & 34 deletions apps/miragon-process-ide-cli/src/app/deployment/api.ts
Original file line number Diff line number Diff line change
@@ -1,41 +1,49 @@
import { Command, InvalidArgumentError } from "commander";
import { Deployment } from "./deployment";
import * as colors from "colors";
import { DigiwfLib } from "@miragon-process-ide/digiwf-lib";

const deployment = new Deployment();
export class DeploymentCommand {
private deployment: Deployment;

export function deployFileCommand(): Command {
return new Command()
.command("deploy-file")
.description("deploys an artifact to the target environment")
.requiredOption("-f --file <file>", "specify the file (full path)")
.requiredOption("-t, --target <target>", "specify the target environment")
.requiredOption("--type <type>", "specify the file type")
.option("-p, --project <project>", "specify the project")
.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");
}
})
.action((options) => {
deployment.deployArtifact(options.file, options.type, options.project, options.target)
.then( () => console.log("Deployment was successfully"))
.catch(err => console.log(colors.red.bold("FAILED") + ` with -> ${err}`));
});
}
constructor(digiwfLib: DigiwfLib) {
this.deployment = new Deployment(digiwfLib);
}

public deployFileCommand(): Command {
return new Command()
.command("deploy-file")
.description("deploys an artifact to the target environment")
.requiredOption("-f --file <file>", "specify the file (full path)")
.requiredOption("-t, --target <target>", "specify the target environment")
.requiredOption("--type <type>", "specify the file type")
.option("-p, --project <project>", "specify the project")
.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");
}
})
.action((options) => {
this.deployment.deployArtifact(options.file, options.type, options.project, options.target)
.then( () => console.log("Deployment was successfully"))
.catch(err => console.log(colors.red.bold("FAILED") + ` with -> ${err}`));
});
}

public deployAllFiles(): Command {
return new Command()
.command("deploy-all")
.description("deploys all artifacts to the target environment")
.requiredOption("-d --directory <directory>", "specify the directory of the source files")
.requiredOption("-t, --target <target>", "specify the target environment")
.option("-p, --project <project>", "specify the project")
.action((options) => {
this.deployment.deployAllArtifacts(options.directory, options.project, options.target)
.then( () => console.log(`Project ${options.project} was successfully deployed to environment ${options.target}`))
.catch(err => console.log(colors.red.bold("FAILED") + ` with -> ${err}`));
});
}

export function deployAllFiles(): Command {
return new Command()
.command("deploy-all")
.description("deploys all artifacts to the target environment")
.requiredOption("-d --directory <directory>", "specify the directory of the source files")
.requiredOption("-t, --target <target>", "specify the target environment")
.option("-p, --project <project>", "specify the project")
.action((options) => {
deployment.deployAllArtifacts(options.directory, options.project, options.target)
.then( () => console.log(`Project ${options.project} was successfully deployed to environment ${options.target}`))
.catch(err => console.log(colors.red.bold("FAILED") + ` with -> ${err}`));
});
}
7 changes: 2 additions & 5 deletions apps/miragon-process-ide-cli/src/app/deployment/deployment.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import { DigiwfConfig, DigiwfLib } from "@miragon-process-ide/digiwf-lib";
import { DigiwfLib } from "@miragon-process-ide/digiwf-lib";
import { getFile, getFiles } from "../shared/fs";
import * as colors from "colors";

export class Deployment {
private digiwfLib: DigiwfLib;

constructor(config?: DigiwfConfig) {
this.digiwfLib = new DigiwfLib(config);
}
constructor(private digiwfLib: DigiwfLib) {}

public async deployArtifact(path: string, type: string, project: string | undefined, target: string): Promise<void> {
const file = await getFile(path);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import { Deployment } from "./deployment";
import { Artifact } from "@miragon-process-ide/digiwf-lib";
import { Artifact, createDigiwfLib, DigiWFDeploymentPlugin } from "@miragon-process-ide/digiwf-lib";

const pathToProject = "resources/my-process-automation-project/";
const project = "my-process-automation-project";
const target = "local";

const dryDeploymentPlugin = {
name: "dry",
const dryDeploymentPlugin: DigiWFDeploymentPlugin = {
plugin: "dry",
targetEnvironments: [{name:"local",url:"http://localhost:8080"}],
deploy: function(target: string, artifact: Artifact) {
return Promise.resolve(artifact);
}
};

const deployment = new Deployment({deploymentPlugins: [dryDeploymentPlugin], generatorPlugins: []});
const deployment = new Deployment(createDigiwfLib("0.0.1", "test-project", {}, [dryDeploymentPlugin]));

describe("deployArtifact", () => {
it("should work", async () => {
Expand Down
75 changes: 42 additions & 33 deletions apps/miragon-process-ide-cli/src/app/generate/api.ts
Original file line number Diff line number Diff line change
@@ -1,39 +1,48 @@
import { Command } from "commander";
import { ProjectGenerator } from "./generate";
import { DigiwfLib } from "@miragon-process-ide/digiwf-lib";

const generate = new ProjectGenerator();
export class GenerateCommand {
private generate: ProjectGenerator;

export function generateProject(): Command {
return new Command()
.command("generate-project")
.description("generates a project foundation")
.requiredOption("-n, --name <name>", "specify the project name")
.option("-p, --path <filepath>", "specify the targeted path")
.action((options) => {
generate.generateProject(options.name, options.path)
.then(() => console.log(`Successfully generated project ${options.name}`))
.catch(err => {
console.log(`Project ${options.name} could not be created`);
console.log(err);
});
});
}
constructor(digiwfLib: DigiwfLib) {
this.generate = new ProjectGenerator(digiwfLib);
}

public generateProject(): Command {
return new Command()
.command("generate-project")
.description("generates a project foundation")
.requiredOption("-n, --name <name>", "specify the project name")
.option("-p, --path <filepath>", "specify the targeted path")
.action((options) => {
this.generate.generateProject(options.name, options.path)
.then(() => console.log(`Successfully generated project ${options.name}`))
.catch(err => {
console.log(`Project ${options.name} could not be created`);
console.log(err);
});
});
}

export function generateFile(): Command {
return new Command()
.command("generate-file")
.description("generates a process model")
.requiredOption("-t --type <type>", "specify the file type that is to be generated")
.requiredOption("-n, --name <name>", "specify the name")
.requiredOption("-p, --path <filepath>", "specify the targeted path")
.option("--template <filepath>", "specify a custom template that is to be used")
.option("-d --data <data>", "specify the data that is to be used for your template")
.action((options) => {
generate.generateFile(options.name, options.type, options.path, options.template, options.data)
.then(() => console.log(`Successfully created file ${options.name}`))
.catch(err => {
console.log(`File ${options.name} could not be created`);
console.log(err);
});
});
public generateFile(): Command {
return new Command()
.command("generate-file")
.description("generates a process model")
.requiredOption("-t --type <type>", "specify the file type that is to be generated")
.requiredOption("-n, --name <name>", "specify the name")
.requiredOption("-p, --path <filepath>", "specify the targeted path")
.option("--template <filepath>", "specify a custom template that is to be used")
.option("-d --data <data>", "specify the data that is to be used for your template")
.action((options) => {
this.generate.generateFile(options.name, options.type, options.path, options.template, options.data)
.then(() => console.log(`Successfully created file ${options.name}`))
.catch(err => {
console.log(`File ${options.name} could not be created`);
console.log(err);
});
});
}
}


9 changes: 3 additions & 6 deletions apps/miragon-process-ide-cli/src/app/generate/generate.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import { Artifact, DigiwfConfig, DigiwfLib } from "@miragon-process-ide/digiwf-lib";
import { Artifact, DigiwfLib } from "@miragon-process-ide/digiwf-lib";
import { saveFile } from "../shared/fs";
import * as colors from "colors";

export class ProjectGenerator {
private digiwfLib: DigiwfLib;

constructor(config?: DigiwfConfig) {
this.digiwfLib = new DigiwfLib(config);
}
constructor(private digiwfLib: DigiwfLib) {}

public async generateProject(name: string, path: string): Promise<void> {
const artifacts = await this.digiwfLib.initProject(name);
Expand All @@ -17,7 +14,7 @@ export class ProjectGenerator {
}

public async generateFile(name: string, type: string, path: string, templateBase?: string, additionalData?: object): Promise<void> {
const artifact = await this.digiwfLib.generateArtifact(name, type);
const artifact = await this.digiwfLib.generateArtifact(name, type, "");
await this.generate(artifact, path);
}

Expand Down
37 changes: 29 additions & 8 deletions apps/miragon-process-ide-cli/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { Command } from "commander";
import { deployAllFiles, deployFileCommand } from "./app/deployment/api";
import { generateFile, generateProject } from "./app/generate/api";
import { getFile } from "./app/shared/fs";
import * as colors from "colors";
import { createDigiwfLib, DigiWFDeploymentPlugin, DigiwfDeploymentPluginRest } from "@miragon-process-ide/digiwf-lib";
import { DeploymentCommand } from "./app/deployment/api";
import { GenerateCommand } from "./app/generate/api";


const program = new Command();

program
.name("Miragon Process IDE CLI")
.description(`
Expand All @@ -18,8 +20,27 @@ program
|___/
`)
.version("0.0.1");
program.addCommand(deployFileCommand());
program.addCommand(deployAllFiles());
program.addCommand(generateFile());
program.addCommand(generateProject());
program.parse();

getFile("process-ide.json")
.then(processIdeJson => {
const processIdeConfig = JSON.parse(processIdeJson.content);
const plugins: DigiWFDeploymentPlugin[] = [];
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
processIdeConfig.deployment.forEach(p => {
plugins.push(new DigiwfDeploymentPluginRest(p.plugin, p.targetEnvironments));
});
const digiwf = createDigiwfLib(processIdeConfig.projectVersion, processIdeConfig.name, processIdeConfig.workspace, plugins);
const deployment = new DeploymentCommand(digiwf);
const generate = new GenerateCommand(digiwf)
program.addCommand(deployment.deployFileCommand());
program.addCommand(deployment.deployAllFiles());
program.addCommand(generate.generateFile());
program.addCommand(generate.generateProject());
})
.catch(err => {
console.log(colors.red.bold("ERROR ") + "You are not inside a valid project. Make sure process-ide.json exists.");
})
.finally(() =>{
program.parse()
});
1 change: 1 addition & 0 deletions libs/digiwf-lib/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from "./lib/digiwf-lib";
export * from "./lib/types";
export * from "./lib/deployment/plugins";
export * from "./lib/deployment/rest/digiwf-deployment-plugin-rest";
10 changes: 1 addition & 9 deletions libs/digiwf-lib/src/lib/deployment/plugins.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
import { DigiwfDeploymentPluginRest } from "./rest/digiwf-deployment-plugin-rest";
import { Artifact, DigiWFDeploymentPlugin } from "../types";
import { DigiWFDeploymentPlugin } from "../types";

const dryPlugin = {
name: "dry",
targetEnvironments: [{name:"local",url:"http://localhost:8080"}],
deploy: function(target: string, artifact: Artifact) {
return Promise.resolve(artifact);
}
};
const restPlugin = new DigiwfDeploymentPluginRest("rest", [
{
name: "local",
Expand All @@ -24,6 +17,5 @@ const restPlugin = new DigiwfDeploymentPluginRest("rest", [
]);

export const availableDeploymentPlugins: DigiWFDeploymentPlugin[] = [
dryPlugin,
restPlugin
];
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import { Artifact, DigiWFDeploymentPlugin, DigiWFDeploymentTarget } from "../../


export class DigiwfDeploymentPluginRest implements DigiWFDeploymentPlugin {
name: string;
plugin: string;
targetEnvironments: DigiWFDeploymentTarget[];

constructor(name: string, targetEnvironments: DigiWFDeploymentTarget[]) {
this.name = name;
constructor(plugin: string, targetEnvironments: DigiWFDeploymentTarget[]) {
this.plugin = plugin;
this.targetEnvironments = targetEnvironments;
}

Expand Down
38 changes: 29 additions & 9 deletions libs/digiwf-lib/src/lib/digiwf-lib.spec.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,35 @@
import { DigiwfLib } from "./digiwf-lib";
import { availableDeploymentPlugins } from "./deployment/plugins";
import { DigiwfConfig } from "./types";
import { createDigiwfLib, DigiwfLib } from "./digiwf-lib";
import { Artifact } from "./types";

const target = "local";

const config: DigiwfConfig = {
deploymentPlugins: availableDeploymentPlugins.filter(plugin => plugin.name === "dry"),
generatorPlugins: []
const workspace = {
forms: "forms",
elementTemplates: "element-templates",
processConfigs: "configs"
};

const digiwfLib = new DigiwfLib(config);
const deployment = [
{
plugin: "dry",
targetEnvironments: [
{
name: "local",
url: "http://localhost:8080"
},
{
name: "dev",
url: "http://localhost:8080"
},
{
name: "test",
url: "http://localhost:8080"
}
],
async deploy(target : string, artifact : Artifact) : Promise<Artifact> {
return artifact;
}
}
];
const digiwfLib: DigiwfLib = createDigiwfLib("1.0.0", "my-project", workspace, deployment);

describe("deploy", () => {
it("should work", async () => {
Expand Down
Loading

0 comments on commit b1de728

Please sign in to comment.