Skip to content

Commit

Permalink
Use landlubber for examples
Browse files Browse the repository at this point in the history
  • Loading branch information
razor-x committed Jan 29, 2023
1 parent 07162b3 commit 66537c2
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 87 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Bootstrap a new TypeScript module in five minutes or less.
- Strongly typed JavaScript with [TypeScript].
- [Node.js]'s [npm] package structure.
- Package management with [npm].
- Examples with configurable options and arguments powered by [yargs].
- Examples with configurable options and arguments powered by [yargs] with [landlubber].
- Linting with the [JavaScript Standard Style] using [ESLint].
- [Prettier] code.
- Futuristic debuggable unit testing with [AVA].
Expand All @@ -31,6 +31,7 @@ Bootstrap a new TypeScript module in five minutes or less.
[Istanbul]: https://istanbul.js.org/
[JavaScript Standard Style]: https://standardjs.com/
[Keep a CHANGELOG]: https://keepachangelog.com/
[landlubber]: https://github.com/razor-x/landlubber
[Node.js]: https://nodejs.org/
[Prettier]: https://prettier.io/
[Shields.io]: https://shields.io/
Expand Down
30 changes: 2 additions & 28 deletions examples/index.ts
Original file line number Diff line number Diff line change
@@ -1,35 +1,9 @@
#!/usr/bin/env tsx

import process from 'node:process'

import { pino } from 'pino'
import yargs, { type MiddlewareFunction } from 'yargs'
import landlubber from 'landlubber'

import * as todo from './todo.js'

const commands = [todo]

const createLogger: MiddlewareFunction = (argv) => {
argv['logger'] = pino({
transport: {
target: 'pino-pretty'
}
})
}

const middleware = [createLogger]

// UPSTREAM: https://github.com/yargs/yargs/issues/1005
const availableCommands = `
Available commands:
${commands.map(({ command }) => command).join('\n ')}
`

await yargs(process.argv.slice(2))
.middleware(middleware)
// @ts-expect-error UPSTREAM: https://github.com/yargs/yargs/issues/2211
.command(commands)
.demandCommand(1, 1, availableCommands.trim())
.recommendCommands()
.strict()
.parse()
await landlubber(commands).parse()
10 changes: 7 additions & 3 deletions examples/todo.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
import { todo } from 'index.js'
import type { Builder, Command, Describe, Handler } from 'landlubber'

import type { Builder, Command, Handler } from './types.js'
import { todo } from 'index.js'

interface Options {
x: string
}

export const command: Command = 'todo x'

export const describe: Describe = 'TODO'

export const builder: Builder = {
x: {
type: 'string'
type: 'string',
default: 'TODO',
describe: 'TODO'
}
}

Expand Down
14 changes: 0 additions & 14 deletions examples/types.ts

This file was deleted.

2 changes: 1 addition & 1 deletion makenew.sh
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ makenew () {
read -p '> GitHub user or organization name (my-user): ' mk_user
read -p '> GitHub repository name (my-repo): ' mk_repo

sed_delete README.md '10,101d'
sed_delete README.md '10,102d'
sed_insert README.md '10i' 'TODO'

find_replace "s/^ \"version\": \".*\"/ \"version\": \"0.0.0\"/g"
Expand Down
63 changes: 28 additions & 35 deletions package-lock.json

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

7 changes: 2 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,16 @@
},
"devDependencies": {
"@types/node": "^18.11.18",
"@types/yargs": "^17.0.19",
"ava": "^5.0.1",
"c8": "^7.11.0",
"del-cli": "^5.0.0",
"eslint": "^8.9.0",
"eslint-config-prettier": "^8.4.0",
"eslint-config-standard-with-typescript": "^33.0.0",
"pino": "^8.8.0",
"pino-pretty": "^9.1.1",
"landlubber": "^0.1.0",
"prettier": "^2.3.0",
"tsc-alias": "^1.8.2",
"tsx": "^3.12.1",
"typescript": "^4.9.4",
"yargs": "^17.6.2"
"typescript": "^4.9.4"
}
}

0 comments on commit 66537c2

Please sign in to comment.