Skip to content

Commit

Permalink
--version arg
Browse files Browse the repository at this point in the history
  • Loading branch information
meoyawn committed Nov 28, 2022
1 parent 1c2cc6d commit d481d4e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
1 change: 0 additions & 1 deletion cli/.gitignore

This file was deleted.

10 changes: 7 additions & 3 deletions cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,22 @@
"version": "0.0.1",
"license": "MIT",
"bin": "dist/index.js",
"dependencies": {
"arg": "^5.0.2"
},
"devDependencies": {
"pkg": "^5.8.0"
},
"scripts": {
"build": "esbuild src/index.ts --bundle --platform=node --outfile=dist/index.js --target=node18 --minify && pkg package.json",
"start": "node dist/index.js ../generator/tryout/listenbox.kdl"
"esb": "esbuild src/index.ts --bundle --platform=node --outfile=dist/index.js --target=node18 --minify",
"build": "yarn esb && pkg package.json",
"start": "yarn esb && node dist/index.js"
},
"pkg": {
"targets": [
"node18-macos-arm64",
"node18-macos-x64"
],
"outputPath": "release/"
"outputPath": "dist/"
}
}
16 changes: 13 additions & 3 deletions cli/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,30 @@
import { toOpenApi } from "../../generator/src/openapi/to-open-api"
import { kdlToCore } from "../../generator/src/dsl/kdl/kdl"
import packageJson from "../package.json"
import { readFile } from "fs/promises"
import * as process from "process"
import { parse } from "kdljs"
import arg from "arg"

const die = (s: string): never => {
console.error(s)
return process.exit(1)
}

const main = async () => {
const file = process.argv[process.argv.length - 1]
if (!file.endsWith(".kdl")) {
return die(`expected .kdl file, got ${file}`)
const args = arg({
"--version": Boolean,
})

if (args["--version"]) {
console.log(packageJson.version)
return
}

const file = args._[0]
if (!file) return die("Specify a .kdl file")
if (!file.endsWith(".kdl")) return die(`expected .kdl file, got ${file}`)

const kdl = await readFile(file, "utf8")
const doc = parse(kdl)
if (!doc.output) {
Expand Down

0 comments on commit d481d4e

Please sign in to comment.