Skip to content

Commit 7da5231

Browse files
committed
chore: add cli
chore: adjust description
1 parent 39a1dad commit 7da5231

File tree

7 files changed

+45
-3
lines changed

7 files changed

+45
-3
lines changed

bin/cli.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { log } from '@stacksjs/logging'
2+
import { CAC } from 'cac'
3+
import { version } from '../package.json'
4+
import { config } from '../src/config'
5+
6+
const cli = new CAC('dbtooling')
7+
8+
interface Options {
9+
name: string
10+
}
11+
12+
cli
13+
.command('create:table [name]', 'Create a local DynamoDB Table')
14+
.usage('dbtooling create:table <name> [options]')
15+
.example('dbtooling create:table MyOfflineTable')
16+
.action(async (name: string, options?: Options) => {
17+
name = name ?? config?.defaultTableName
18+
19+
log.info(`Creating a local DynamoDB Table for: ${name}`)
20+
log.debug('Options:', options)
21+
log.success('Table created')
22+
})
23+
24+
cli.version(version)
25+
cli.help()
26+
cli.parse()

build.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import process from 'node:process'
2+
import { $ } from 'bun'
23
import { dts } from 'bun-plugin-dts-auto'
34

45
console.log('Building...')
56

67
const result = await Bun.build({
7-
entrypoints: ['src/index.ts'],
8-
8+
entrypoints: ['src/index.ts', 'bin/cli.ts'],
99
target: 'bun',
1010
outdir: './dist',
1111
sourcemap: 'inline',
@@ -21,5 +21,10 @@ if (!result.success) {
2121
process.exit(1)
2222
}
2323

24+
await $`cp ./dist/src/index.js ./dist/index.js`
25+
await $`rm -rf ./dist/src`
26+
await $`cp ./dist/bin/cli.js ./dist/cli.js`
27+
await $`rm -rf ./dist/bin`
28+
2429
console.log('Build successful!')
2530
process.exit(0)

bun.lockb

384 KB
Binary file not shown.

dbtooling

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/usr/bin/env bun
2+
import('./bin/cli')

dynamodb.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import * as path from 'node:path'
33
import type { Config } from './src/types'
44

55
const config: Config = {
6+
defaultTableName: 'MyOfflineTable',
67
port: 8000,
78
dbPath: '',
89
detached: false,

package.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,15 @@
2323
"import": "./dist/*"
2424
}
2525
},
26+
"bin": {
27+
"dbtooling": "./dist/cli.js"
28+
},
2629
"module": "./dist/index.js",
2730
"types": "./dist/index.d.ts",
2831
"files": ["dist", "src"],
2932
"scripts": {
30-
"build": "bun --bun build.ts",
33+
"build": "bun --bun build.ts && bun --bun run compile",
34+
"compile": "bun build ./bin/cli.ts --compile --minify --outfile dist/dbtooling",
3135
"create-offline-table": "aws dynamodb create-table --table-name=MyOfflineTable --attribute-definitions AttributeName=Artist,AttributeType=S AttributeName=SongTitle,AttributeType=S --key-schema AttributeName=Artist,KeyType=HASH AttributeName=SongTitle,KeyType=RANGE --provisioned-throughput ReadCapacityUnits=5,WriteCapacityUnits=5 --endpoint-url http://localhost:8000 --region us-east-1",
3236
"lint": "biome check .",
3337
"lint:fix": "biome check --fix .",
@@ -43,6 +47,9 @@
4347
"@biomejs/biome": "^1.9.2",
4448
"@commitlint/cli": "^19.5.0",
4549
"@stacksjs/biome-config": "^0.1.5",
50+
"@stacksjs/cli": "^0.64.6",
51+
"@stacksjs/logging": "^0.64.6",
52+
"@stacksjs/storage": "^0.64.6",
4653
"@types/bun": "^1.1.10",
4754
"@types/tar": "^6.1.13",
4855
"bumpp": "^9.5.2",

src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export interface Config {
2+
defaultTableName: string
23
port: number
34
dbPath: string
45
detached: boolean

0 commit comments

Comments
 (0)