Skip to content

Commit

Permalink
Merge pull request #11 from acro5piano/feature/use-commander-extra-ty…
Browse files Browse the repository at this point in the history
…ping

refactor: use @commander-js/extra-typings for better typing
  • Loading branch information
acro5piano committed Sep 10, 2023
2 parents 39820f9 + 8b5264e commit 7edd3f1
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -23,6 +23,7 @@
"r": "tsc && node dist/index.js"
},
"dependencies": {
"@commander-js/extra-typings": "^11.0.0",
"commander": "^9.1.0"
},
"devDependencies": {
Expand Down
19 changes: 7 additions & 12 deletions src/run.ts
@@ -1,7 +1,7 @@
import fs from 'fs'

import { program } from 'commander'
import {Kysely, MigrationResultSet, Migrator, NO_MIGRATIONS} from 'kysely'
import { program } from '@commander-js/extra-typings'
import { Kysely, MigrationResultSet, Migrator, NO_MIGRATIONS } from 'kysely'

function showResults({ error, results }: MigrationResultSet) {
if (results) {
Expand All @@ -16,11 +16,7 @@ function showResults({ error, results }: MigrationResultSet) {
}
}

export function run(
db: Kysely<any>,
migrator: Migrator,
path: string = './migrations',
) {
export function run(db: Kysely<any>, migrator: Migrator, path: string = './migrations') {
program
.command('up')
.description('Run a pending migration if any')
Expand Down Expand Up @@ -63,7 +59,9 @@ export function run(
program
.command('down-to')
.argument('<migration-name>')
.description('Migrates down to the specified migration name. Specify "NO_MIGRATIONS" to migrate all the way down.')
.description(
'Migrates down to the specified migration name. Specify "NO_MIGRATIONS" to migrate all the way down.',
)
.action(async (name) => {
let results: MigrationResultSet

Expand All @@ -84,10 +82,7 @@ export function run(
'Create a new migration with the given description, and the current time as the version',
)
.action(async (name) => {
const dateStr = new Date()
.toISOString()
.replace(/[-:]/g, '')
.split('.')[0]
const dateStr = new Date().toISOString().replace(/[-:]/g, '').split('.')[0]
const fileName = `${path}/${dateStr}-${name}.ts`
const mkdir = () => fs.mkdirSync(path)
try {
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Expand Up @@ -2,6 +2,11 @@
# yarn lockfile v1


"@commander-js/extra-typings@^11.0.0":
version "11.0.0"
resolved "https://registry.yarnpkg.com/@commander-js/extra-typings/-/extra-typings-11.0.0.tgz#eb922a59550454cad1f319d3d33e675e12e92fa0"
integrity sha512-06ol6Kn5gPjFY6v0vWOZ84nQwyqhZdaeZCHYH3vhwewjpOEjniF1KHZxh18887G3poWiJ8qyq5pb6ANuiddfPQ==

"@types/node@*", "@types/node@^20.2.3":
version "20.2.3"
resolved "https://registry.yarnpkg.com/@types/node/-/node-20.2.3.tgz#b31eb300610c3835ac008d690de6f87e28f9b878"
Expand Down

0 comments on commit 7edd3f1

Please sign in to comment.