-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
226 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,5 +26,6 @@ | |
}, | ||
"[typescriptreact]": { | ||
"editor.defaultFormatter": "samverschueren.linter-xo" | ||
} | ||
}, | ||
"deno.enable": false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"workspace": { | ||
"members": [ | ||
"packages/c8cli" | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"format": "tsconfig" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{ | ||
"name": "@camunda8/c8cli", | ||
"version": "1.0.0", | ||
"description": "Cross-platform Camunda 8 CLI", | ||
"main": "run.ts", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1", | ||
"clean": "rm -rf distribution", | ||
"mkdirs": "mkdir -p distribution/linux-x86_64 && mkdir -p distribution/linux-arm64 && mkdir -p distribution/windows-x86_64 && mkdir -p distribution/darwin-x86_64 && mkdir -p distribution/darwin-arm64", | ||
"build": "pnpm run clean && pnpm run mkdirs && pnpm run build:linux-x86_64 && pnpm run build:linux-arm64 && pnpm run build:windows-x86_64 && pnpm run build:darwin-x86_64 && pnpm run build:darwin-arm64", | ||
"build:linux-x86_64": "deno compile --allow-all --target x86_64-unknown-linux-gnu --output distribution/linux-x86_64/c8cli source/main.ts", | ||
"build:linux-arm64": "deno compile --allow-all --target aarch64-unknown-linux-gnu --output distribution/linux-arm64/c8cli source/main.ts", | ||
"build:windows-x86_64": "deno compile --allow-all --target x86_64-pc-windows-msvc --output distribution/windows_x86_64/c8cli.exe source/main.ts", | ||
"build:darwin-x86_64": "deno compile --allow-all --target x86_64-apple-darwin --output distribution/darwin-x86_64/c8cli source/main.ts", | ||
"build:darwin-arm64": "deno compile --allow-all --node-modules-dir=auto --target aarch64-apple-darwin --output distribution/darwin-arm64/c8cli source/main.ts" | ||
}, | ||
"dependencies": { | ||
"@camunda8/sdk-rest": "workspace:*" | ||
}, | ||
"keywords": [ | ||
"Camunda 8", | ||
"Camunda", | ||
"cli" | ||
], | ||
"engine": "deno", | ||
"author": "Josh Wulf <[email protected]>", | ||
"license": "ISC" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import { CamundaRestClient } from "@camunda8/sdk-rest"; | ||
import type { ParsedArguments } from "./parse-arguments.ts"; | ||
|
||
type CliCommandExecutor = ( | ||
camunda: CamundaRestClient, | ||
args: ParsedArguments, | ||
) => Promise<number>; | ||
|
||
type CliArgs = { | ||
required: string[]; | ||
optional: string[]; | ||
}; | ||
|
||
export type CliCommand = { | ||
description: string; | ||
usage: string; | ||
args: CliArgs; | ||
run: CliCommandExecutor; | ||
}; | ||
|
||
export function emitCommandHelp(command: CliCommand) { | ||
console.log(`\nDescription: ${command.description}`); | ||
console.log(`Usage: ${command.usage}`); | ||
console.log(`Required Arguments: `, command.args.required.join(", ")); | ||
console.log(`Optional Arguments: `, command.args.optional.join(", ")); | ||
} | ||
|
||
export const commands: { | ||
[key: string]: CliCommand; | ||
} = { | ||
"topology": { | ||
description: "Get the Camunda 8 cluster topology", | ||
usage: "c8cli topology", | ||
args: { | ||
required: [], | ||
optional: [], | ||
}, | ||
run: async (camunda: CamundaRestClient) => { | ||
const topology = await camunda.getTopology(); | ||
console.log(topology); | ||
return 0; | ||
}, | ||
}, | ||
"license": { | ||
description: "Get the Camunda 8 cluster license status", | ||
usage: "c8cli license", | ||
args: { | ||
required: [], | ||
optional: [], | ||
}, | ||
run: async (camunda: CamundaRestClient) => { | ||
const status = await camunda.getLicenseStatus(); | ||
console.log(status); | ||
return 0; | ||
}, | ||
}, | ||
"deploy-resource": { | ||
description: | ||
"Deploy a resource (BPMN | DMN | Form) from a file to a Camunda 8 cluster", | ||
usage: "c8cli deploy-resource --file <filename> --tenantId <tenantId>", | ||
args: { | ||
required: ["file"], | ||
optional: ["tenantId"], | ||
}, | ||
run: async (camunda: CamundaRestClient, args: ParsedArguments) => { | ||
const content = Deno.readFileSync(args.file as string); | ||
const response = await camunda.deployResources({ | ||
resources: { content, name: args.file }, | ||
tenantId: args.tenantId, | ||
}); | ||
console.log(response); | ||
return 0; | ||
}, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { CamundaRestClient } from "@camunda8/sdk-rest"; | ||
import { commands, emitCommandHelp } from "./commands.ts"; | ||
import { parseArguments } from "./parse-arguments.ts"; | ||
|
||
const command = Deno.args[0]; | ||
|
||
const noCommand = !command; | ||
const unknownCommand = !Object.keys(commands).includes(command); | ||
const helpCommand = Deno.args[0] === "--help"; | ||
|
||
if (noCommand || unknownCommand || helpCommand) { | ||
console.log("\nCamunda 8 CLI\n"); | ||
console.log("Usage:"); | ||
for (const key of Object.keys(commands)) { | ||
console.log(`c8cli ${key}\t - ${commands[key].description}`); | ||
} | ||
console.log(`\n`); | ||
Deno.exit(0); | ||
} | ||
|
||
const commandToRun = commands[command]; | ||
|
||
const firstArg = Deno.args[1]; | ||
|
||
const helpRequested = firstArg === "--help"; | ||
|
||
if (helpRequested) { | ||
emitCommandHelp(commandToRun); | ||
exit(0); | ||
} else { | ||
const args = parseArguments(); | ||
const missingRequiredArgs = commandToRun.args.required.filter((key) => | ||
!(key in args) | ||
); | ||
if (missingRequiredArgs.length > 0) { | ||
console.log( | ||
`\nERROR: Missing required argument(s): ${ | ||
missingRequiredArgs.join(", ") | ||
}`, | ||
); | ||
emitCommandHelp(commandToRun); | ||
exit(1); | ||
} | ||
// TODO - unknown argument(s) passed | ||
// TODO - "One of" arguments | ||
const exitCode = await commandToRun.run(new CamundaRestClient(), args); | ||
console.log("\n"); | ||
exit(exitCode); | ||
} | ||
|
||
function exit(code: number) { | ||
console.log("\n"); | ||
Deno.exit(code); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
const args = Deno.args; | ||
export type ParsedArguments = { [key: string]: string | boolean }; | ||
const parsedArgs: ParsedArguments = {}; | ||
|
||
export function parseArguments() { | ||
for (let i = 1; i < args.length; i++) { | ||
const arg = args[i]; | ||
|
||
if (arg.startsWith("--")) { | ||
const key = arg.replace("--", ""); | ||
// Check for the next argument | ||
if (i + 1 < args.length) { | ||
const nextArg = args[i + 1]; | ||
if (nextArg.startsWith("--")) { | ||
parsedArgs[key] = true; | ||
} else { | ||
parsedArgs[key] = nextArg; | ||
i++; | ||
} | ||
} else { | ||
parsedArgs[key] = ""; | ||
} | ||
} | ||
} | ||
return parsedArgs; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
import { parseArguments } from "../source/parse-arguments.ts"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.