Removing prettier for now. Adding CLI option and making it bundle before release to decrease startup time.

This commit is contained in:
K35 2022-01-01 01:08:05 +00:00
parent 7da1cf0841
commit d64518627d
7 changed files with 8174 additions and 14 deletions

43
README.md Normal file
View File

@ -0,0 +1,43 @@
# JSON-RPC 2.0 Code-Gen
Type/Service definition language and code generator for json-rpc 2.0. Currently generating code for NodeJS, Deno and the Web. Other targets are possible, but not implemented yet.
| Name | Description |
| ------- | --------------------------------- |
| ts-node | Typescript for NodeJS |
| ts-esm | Typescript in ESM format for Deno |
## Usage
Create a definition file like `test.jrpc`:
```jrpc
enum TestEnum {
VAL1,
VAL2,
VAL10 = 10,
VAL11,
VAL12
}
type Test {
testen: TestEnum;
someString: string;
someNumber: number;
array: string[];
map: {number, TestEnum};
}
service TestService {
AddNumbers(v1: number, v2: number): number;
notification SendTest(test: Test);
}
```
Then run the generator like this `jrpc compile test.jrpc -o=ts-node:output/`.
This will generate the Client and Server code in the specified folder.
//TODO: Make Documentation better

7913
lib/jrpc.js Executable file

File diff suppressed because it is too large Load Diff

View File

@ -1,25 +1,36 @@
{ {
"name": "@hibas123/jrpcgen", "name": "@hibas123/jrpcgen",
"version": "1.0.0", "version": "1.0.1",
"main": "lib/index.js", "main": "lib/index.js",
"license": "MIT", "license": "MIT",
"packageManager": "yarn@3.1.1", "packageManager": "yarn@3.1.1",
"scripts": { "scripts": {
"start": "ts-node src/index.ts", "start": "ts-node src/index.ts",
"test": "npm run start -- compile examples/example.jrpc -o=ts-node:examples/out && ts-node examples/test.ts" "test": "npm run start -- compile examples/example.jrpc -o=ts-node:examples/out && ts-node examples/test.ts",
"build": "esbuild src/index.ts --bundle --platform=node --target=node14 --outfile=lib/jrpc.js",
"prepublishOnly": "npm run build"
}, },
"bin": {
"jrpc": "./lib/jrpc.js"
},
"files": [
"lib/jrpc.js",
"templates/**",
"examples/**",
"src/**",
"tsconfig.json"
],
"devDependencies": { "devDependencies": {
"@types/debug": "^4.1.7", "@types/debug": "^4.1.7",
"@types/node": "^17.0.5", "@types/node": "^17.0.5",
"@types/prettier": "^2.4.2", "@types/prettier": "^2.4.2",
"@types/yargs": "^17.0.8", "@types/yargs": "^17.0.8",
"ts-node": "^10.4.0",
"typescript": "^4.5.4"
},
"dependencies": {
"chalk": "4", "chalk": "4",
"debug": "^4.3.3", "debug": "^4.3.3",
"esbuild": "^0.14.10",
"prettier": "^2.5.1", "prettier": "^2.5.1",
"ts-node": "^10.4.0",
"typescript": "^4.5.4",
"yargs": "^17.3.1" "yargs": "^17.3.1"
} }
} }

View File

@ -1,3 +1,5 @@
#!/usr/bin/env node
import yargs from "yargs"; import yargs from "yargs";
import { hideBin } from "yargs/helpers"; import { hideBin } from "yargs/helpers";
import startCompile, { Target } from "./process"; import startCompile, { Target } from "./process";

View File

@ -7,7 +7,7 @@ import {
} from "../ir"; } from "../ir";
import { CompileTarget } from "../compile"; import { CompileTarget } from "../compile";
import * as prettier from "prettier"; // import * as prettier from "prettier";
type lineAppender = (ind: number, line: string | string[]) => void; type lineAppender = (ind: number, line: string | string[]) => void;
@ -51,13 +51,13 @@ export class TypescriptTarget extends CompileTarget {
} }
private writeFormattedFile(file: string, code: string) { private writeFormattedFile(file: string, code: string) {
// this.writeFile(file, code); this.writeFile(file, code);
const formatted = prettier.format(code, { // const formatted = prettier.format(code, {
parser: "typescript", // parser: "typescript",
tabWidth: 3, // tabWidth: 3,
}); // });
this.writeFile(file, formatted); // this.writeFile(file, formatted);
} }
generateType(def: TypeDefinition) { generateType(def: TypeDefinition) {

View File

@ -3,7 +3,6 @@
"target": "ESNext", "target": "ESNext",
"module": "CommonJS", "module": "CommonJS",
"moduleResolution": "node", "moduleResolution": "node",
"outDir": "examples/out",
"esModuleInterop": true, "esModuleInterop": true,
"forceConsistentCasingInFileNames": true, "forceConsistentCasingInFileNames": true,
"skipLibCheck": true "skipLibCheck": true

192
yarn.lock
View File

@ -31,6 +31,7 @@ __metadata:
"@types/yargs": ^17.0.8 "@types/yargs": ^17.0.8
chalk: 4 chalk: 4
debug: ^4.3.3 debug: ^4.3.3
esbuild: ^0.14.10
prettier: ^2.5.1 prettier: ^2.5.1
ts-node: ^10.4.0 ts-node: ^10.4.0
typescript: ^4.5.4 typescript: ^4.5.4
@ -221,6 +222,197 @@ __metadata:
languageName: node languageName: node
linkType: hard linkType: hard
"esbuild-android-arm64@npm:0.14.10":
version: 0.14.10
resolution: "esbuild-android-arm64@npm:0.14.10"
conditions: os=android & cpu=arm64
languageName: node
linkType: hard
"esbuild-darwin-64@npm:0.14.10":
version: 0.14.10
resolution: "esbuild-darwin-64@npm:0.14.10"
conditions: os=darwin & cpu=x64
languageName: node
linkType: hard
"esbuild-darwin-arm64@npm:0.14.10":
version: 0.14.10
resolution: "esbuild-darwin-arm64@npm:0.14.10"
conditions: os=darwin & cpu=arm64
languageName: node
linkType: hard
"esbuild-freebsd-64@npm:0.14.10":
version: 0.14.10
resolution: "esbuild-freebsd-64@npm:0.14.10"
conditions: os=freebsd & cpu=x64
languageName: node
linkType: hard
"esbuild-freebsd-arm64@npm:0.14.10":
version: 0.14.10
resolution: "esbuild-freebsd-arm64@npm:0.14.10"
conditions: os=freebsd & cpu=arm64
languageName: node
linkType: hard
"esbuild-linux-32@npm:0.14.10":
version: 0.14.10
resolution: "esbuild-linux-32@npm:0.14.10"
conditions: os=linux & cpu=ia32
languageName: node
linkType: hard
"esbuild-linux-64@npm:0.14.10":
version: 0.14.10
resolution: "esbuild-linux-64@npm:0.14.10"
conditions: os=linux & cpu=x64
languageName: node
linkType: hard
"esbuild-linux-arm64@npm:0.14.10":
version: 0.14.10
resolution: "esbuild-linux-arm64@npm:0.14.10"
conditions: os=linux & cpu=arm64
languageName: node
linkType: hard
"esbuild-linux-arm@npm:0.14.10":
version: 0.14.10
resolution: "esbuild-linux-arm@npm:0.14.10"
conditions: os=linux & cpu=arm
languageName: node
linkType: hard
"esbuild-linux-mips64le@npm:0.14.10":
version: 0.14.10
resolution: "esbuild-linux-mips64le@npm:0.14.10"
conditions: os=linux & cpu=mips64el
languageName: node
linkType: hard
"esbuild-linux-ppc64le@npm:0.14.10":
version: 0.14.10
resolution: "esbuild-linux-ppc64le@npm:0.14.10"
conditions: os=linux & cpu=ppc64
languageName: node
linkType: hard
"esbuild-linux-s390x@npm:0.14.10":
version: 0.14.10
resolution: "esbuild-linux-s390x@npm:0.14.10"
conditions: os=linux & cpu=s390x
languageName: node
linkType: hard
"esbuild-netbsd-64@npm:0.14.10":
version: 0.14.10
resolution: "esbuild-netbsd-64@npm:0.14.10"
conditions: os=netbsd & cpu=x64
languageName: node
linkType: hard
"esbuild-openbsd-64@npm:0.14.10":
version: 0.14.10
resolution: "esbuild-openbsd-64@npm:0.14.10"
conditions: os=openbsd & cpu=x64
languageName: node
linkType: hard
"esbuild-sunos-64@npm:0.14.10":
version: 0.14.10
resolution: "esbuild-sunos-64@npm:0.14.10"
conditions: os=sunos & cpu=x64
languageName: node
linkType: hard
"esbuild-windows-32@npm:0.14.10":
version: 0.14.10
resolution: "esbuild-windows-32@npm:0.14.10"
conditions: os=win32 & cpu=ia32
languageName: node
linkType: hard
"esbuild-windows-64@npm:0.14.10":
version: 0.14.10
resolution: "esbuild-windows-64@npm:0.14.10"
conditions: os=win32 & cpu=x64
languageName: node
linkType: hard
"esbuild-windows-arm64@npm:0.14.10":
version: 0.14.10
resolution: "esbuild-windows-arm64@npm:0.14.10"
conditions: os=win32 & cpu=arm64
languageName: node
linkType: hard
"esbuild@npm:^0.14.10":
version: 0.14.10
resolution: "esbuild@npm:0.14.10"
dependencies:
esbuild-android-arm64: 0.14.10
esbuild-darwin-64: 0.14.10
esbuild-darwin-arm64: 0.14.10
esbuild-freebsd-64: 0.14.10
esbuild-freebsd-arm64: 0.14.10
esbuild-linux-32: 0.14.10
esbuild-linux-64: 0.14.10
esbuild-linux-arm: 0.14.10
esbuild-linux-arm64: 0.14.10
esbuild-linux-mips64le: 0.14.10
esbuild-linux-ppc64le: 0.14.10
esbuild-linux-s390x: 0.14.10
esbuild-netbsd-64: 0.14.10
esbuild-openbsd-64: 0.14.10
esbuild-sunos-64: 0.14.10
esbuild-windows-32: 0.14.10
esbuild-windows-64: 0.14.10
esbuild-windows-arm64: 0.14.10
dependenciesMeta:
esbuild-android-arm64:
optional: true
esbuild-darwin-64:
optional: true
esbuild-darwin-arm64:
optional: true
esbuild-freebsd-64:
optional: true
esbuild-freebsd-arm64:
optional: true
esbuild-linux-32:
optional: true
esbuild-linux-64:
optional: true
esbuild-linux-arm:
optional: true
esbuild-linux-arm64:
optional: true
esbuild-linux-mips64le:
optional: true
esbuild-linux-ppc64le:
optional: true
esbuild-linux-s390x:
optional: true
esbuild-netbsd-64:
optional: true
esbuild-openbsd-64:
optional: true
esbuild-sunos-64:
optional: true
esbuild-windows-32:
optional: true
esbuild-windows-64:
optional: true
esbuild-windows-arm64:
optional: true
bin:
esbuild: bin/esbuild
checksum: 0e42a74afa79f8f096d338415b6661410fb656ce0d8ea6f48ccbd943d383e01d946dc9124e366db7dc9deb02b924c6788a68d690a1aa28365e891102450e8ae5
languageName: node
linkType: hard
"escalade@npm:^3.1.1": "escalade@npm:^3.1.1":
version: 3.1.1 version: 3.1.1
resolution: "escalade@npm:3.1.1" resolution: "escalade@npm:3.1.1"