Skip to content

Commit

Permalink
rename bin to get-dtos + remove minification
Browse files Browse the repository at this point in the history
  • Loading branch information
mythz committed Nov 21, 2024
1 parent c89c4b7 commit b7bf551
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 26 deletions.
1 change: 0 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,4 @@ jobs:
- id: build
name: Run build
run: |
bun install -g uglify-js shx
bun run build
2 changes: 1 addition & 1 deletion build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { BuildConfig } from 'bun'
import dts from 'bun-plugin-dts'

const defaultBuildConfig: BuildConfig = {
entrypoints: ['./src/index.ts','./src/bin.ts'],
entrypoints: ['./src/index.ts','./src/get-dtos.ts'],
outdir: './dist'
}

Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@
"type": "git",
"url": "git+https://github.com/ServiceStack/get-dtos.git"
},
"bin": "./dist/bin.js",
"bin": "./dist/get-dtos.js",
"main": "./dist/index.js",
"exports": {
"import": "./dist/index.js"
},
"scripts": {
"build": "bun run build.ts",
"minify": "shx rm -rf ./dist && bun run build && uglifyjs dist/index.js --compress -o dist/index.min.js",
"test": "tsx --test --test-concurrency=1",
"clean": "shx rm -rf ./dist",
"test": "bun test --",
"prepublishOnly": "bun run build",
"release": "bun run minify && bump patch --commit --push --tag && npm publish --access public"
"release": "bun run clean && bun run build && bump patch --commit --push --tag && npm publish --access public"
},
"keywords": [
"apis",
Expand Down
File renamed without changes.
28 changes: 18 additions & 10 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,14 @@ export function parseArgs(...args: string[]) : Command {
return ret
}

function logAnyUnknownCommand(command:Command) {
if (command.unknown?.length) {
console.log(`Unknown Command: ${command.script!.name} ${command.unknown!.join(' ')}\n`)
return -1
}
return 0
}

var VERBOSE = false
export async function cli(args: string[]) {
//var nodeExe = args[0]
Expand Down Expand Up @@ -142,12 +150,15 @@ export async function cli(args: string[]) {
let arg1 = cmdArgs[0] || ""
console.log(arg1, cmdArgs, ' VERBOSE: ', VERBOSE)
}


if (command.unknown?.length) {
return execHelp(command)
}

try {
switch (command.type) {
case "help":
execHelp(command)
return
return execHelp(command)
case "version":
console.log("Version: " + packageConf.version)
return
Expand Down Expand Up @@ -180,12 +191,6 @@ export async function cli(args: string[]) {
} catch (e) {
handleError(e)
}

if (command.unknown?.length) {
console.log("Unknown Command: " + command.script!.name + " " + command.unknown!.join(' ') + "\n")
execHelp(command)
return -1
}
}

function handleError(e:any, msg?:string) {
Expand Down Expand Up @@ -325,7 +330,9 @@ function walk(dir:string) {
}

function execHelp(command:Command) {
const tool = command.script?.name ?? "npx get-dtos"
const exitCode = logAnyUnknownCommand(command)

const tool = command.script?.name ?? "get-dtos"
var USAGE = `
${tool} <lang> Update all ServiceStack References in directory (recursive)
${tool} <file> Update existing ServiceStack Reference (e.g. dtos.cs)
Expand All @@ -352,6 +359,7 @@ This tool collects anonymous usage to determine the most used languages to impro
To disable set SERVICESTACK_TELEMETRY_OPTOUT=1 environment variable to 1 using your favorite shell.
`
console.log(USAGE.trim())
return exitCode
}

function normalizeSwitches(cmd:string) { return cmd.replace(/^-+/, '/') }
Expand Down
6 changes: 6 additions & 0 deletions test/args.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ describe("cli args tests", () => {
expect(parseArgs("")).toEqual({ type:'help' })
})

it ("unknown commands returns help with unknown", () => {
expect(parseArgs("unknown")).toEqual({ type:'help', unknown:['unknown'] })
expect(parseArgs("unknown commands")).toEqual({ type:'help', unknown:['unknown commands'] })
expect(parseArgs("unknown","commands")).toEqual({ type:'help', unknown:['unknown','commands'] })
})

it ("arg with language returns update", () => {
expect(parseArgs("csharp")).toEqual({ type:'update', lang:'csharp' })
expect(parseArgs("typescript")).toEqual({ type:'update', lang:'typescript' })
Expand Down
10 changes: 0 additions & 10 deletions test/basic.test.ts

This file was deleted.

23 changes: 23 additions & 0 deletions test/cli.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { $ } from 'bun'
import { describe, it, expect } from 'bun:test'

describe("Does run cli commands", () => {
it ("empty commands should print help", async () => {
let out = await $`./dist/get-dtos.js`.text()
expect(out).toStartWith('get-dtos <lang>')
})

it ("unknown commands should fail", async () => {
let out = await $`./dist/get-dtos.js unknown`.text()
expect(out).toStartWith('Unknown Command: get-dtos unknown')
})

it ("should print version", async () => {
let out = await $`./dist/get-dtos.js --version`.text()
expect(out).toStartWith('Version: ')
out = await $`./dist/get-dtos.js -version`.text()
expect(out).toStartWith('Version: ')
out = await $`./dist/get-dtos.js -v`.text()
expect(out).toStartWith('Version: ')
})
})

0 comments on commit b7bf551

Please sign in to comment.