Skip to content

Commit

Permalink
chore: make compatible with deno
Browse files Browse the repository at this point in the history
  • Loading branch information
jwulf committed Nov 4, 2024
1 parent 069befe commit 9c6dc9e
Show file tree
Hide file tree
Showing 16 changed files with 226 additions and 31 deletions.
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,6 @@
},
"[typescriptreact]": {
"editor.defaultFormatter": "samverschueren.linter-xo"
}
},
"deno.enable": false
}
7 changes: 7 additions & 0 deletions deno.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"workspace": {
"members": [
"packages/c8cli"
]
}
}
3 changes: 3 additions & 0 deletions packages/c8cli/deno.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"format": "tsconfig"
}
28 changes: 28 additions & 0 deletions packages/c8cli/package.json
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"
}
75 changes: 75 additions & 0 deletions packages/c8cli/source/commands.ts
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;
},
},
};
54 changes: 54 additions & 0 deletions packages/c8cli/source/main.ts
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);
}
26 changes: 26 additions & 0 deletions packages/c8cli/source/parse-arguments.ts
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;
}
1 change: 1 addition & 0 deletions packages/c8cli/tests/parse-arguments.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import { parseArguments } from "../source/parse-arguments.ts";
11 changes: 6 additions & 5 deletions packages/lossless-json/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
"name": "@camunda8/lossless-json",
"version": "1.0.0",
"description": "Lossless JSON parsing with optional Dto mapping",
"main": "dist/index.js",
"main": "distribution/index.js",
"type": "module",
"scripts": {
"test": "jest",
"build": "npm run clean && tsc --project tsconfig.json",
"clean": "rm -rf ./dist && rm -f ./tsconfig.tsbuildinfo",
"lint": "eslint 'src/**/*.{ts,tsx}'",
"format": "prettier --write 'src/**/*.ts'"
"clean": "rm -rf ./distribution && rm -f ./tsconfig.tsbuildinfo",
"lint": "eslint 'source/**/*.{ts,tsx}'",
"format": "prettier --write 'source/**/*.ts'"
},
"repository": {
"type": "git",
Expand Down Expand Up @@ -38,7 +39,7 @@
"^.+\\.(ts|tsx)$": [
"ts-jest",
{
"tsconfig": "src/__tests__/tsconfig.json"
"tsconfig": "source/__tests__/tsconfig.json"
}
]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
LosslessDto,
losslessParse,
losslessStringify,
} from '../'
} from '../index.js'

test('LosslessJsonParser correctly handles nested Dtos', () => {
class DecisionInstanceOutput extends LosslessDto {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,7 @@
"../**/*" // Includes all files in the src directory
],
"compilerOptions": {},
"exclude": ["node_modules"]
"exclude": [
"node_modules"
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
*/

/* eslint-disable @typescript-eslint/no-explicit-any */
import { debug as d } from 'debug'
// import { debug as d } from 'debug'
import {
LosslessNumber,
isLosslessNumber,
Expand All @@ -31,6 +31,7 @@ import {
} from 'lossless-json'
import 'reflect-metadata'

const d = _namespace => (_msg, _data?) => null
const debug = d('lossless-json-parser')

const MetadataKey = {
Expand Down
17 changes: 9 additions & 8 deletions packages/lossless-json/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,20 @@
"compilerOptions": {
"composite": true /* Required because referenced by src/tsconfig.json */,
/* Basic Options */
"target": "es2020" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017','ES2018' or 'ESNEXT'. */,
"module": "commonjs" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */,
"target": "es2022" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017','ES2018' or 'ESNEXT'. */,
"module": "Node16" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */,
"types": [
"jest",
"node"
],
"moduleResolution": "Node16",
"lib": [
"es2020",
"es2022",
],
"declaration": true /* Generates corresponding '.d.ts' file. */,
"sourceMap": true /* Generates corresponding '.map' file. */,
"outDir": "./dist" /* Redirect output structure to the directory. */,
"rootDir": "./src" /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */,
"outDir": "distribution" /* Redirect output structure to the directory. */,
"rootDir": "./source" /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */,
/* Strict Type-Checking Options */
"forceConsistentCasingInFileNames": true,
"strict": true /* Enable all strict type-checking options. */,
Expand All @@ -34,7 +35,7 @@
},
"exclude": [
"node_modules",
"src/__tests__/*",
"dist"
"source/__tests__/*",
"distribution"
]
}
}
1 change: 0 additions & 1 deletion packages/sdk-rest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@
"dependencies": {
"@camunda8/lossless-json": "workspace:*",
"@camunda8/oauth": "workspace:*",
"@types/multiparty": "^4.2.1",
"debug": "^4.3.7",
"eventemitter3": "^5.0.1",
"ky": "^1.7.2",
Expand Down
6 changes: 3 additions & 3 deletions packages/sdk/src/modeler/lib/ModelerAPIClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ export class ModelerApiClient {
async deleteFile(fileId: string): Promise<null> {
const headers = await this.getHeaders()
const rest = await this.rest
return rest(`files/${fileId}`, {
return rest.delete(`files/${fileId}`, {
headers,
}).then(this.decodeResponseOrThrow) as Promise<null>
}
Expand Down Expand Up @@ -241,7 +241,7 @@ export class ModelerApiClient {
): Promise<Dto.FileMetadataDto> {
const headers = await this.getHeaders()
const rest = await this.rest
return rest(`files/${fileId}`, {
return rest.post(`files/${fileId}`, {
headers,
body: JSON.stringify(update),
}).then((res) =>
Expand Down Expand Up @@ -280,7 +280,7 @@ export class ModelerApiClient {
): Promise<Dto.PubSearchResultDtoFileMetadataDto> {
const headers = await this.getHeaders()
const rest = await this.rest
return rest(`files/search`, {
return rest.post(`files/search`, {
headers,
body: JSON.stringify(req),
}).then((res) =>
Expand Down
16 changes: 6 additions & 10 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 9c6dc9e

Please sign in to comment.