From 8b5264e4d043b5620ba84897d94afead5a8f5d7f Mon Sep 17 00:00:00 2001 From: Kay Gosho Date: Mon, 11 Sep 2023 00:58:30 +0900 Subject: [PATCH] refactor: use @commander-js/extra-typings for better typing --- package.json | 1 + src/run.ts | 19 +++++++------------ yarn.lock | 5 +++++ 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/package.json b/package.json index f3a862c..d057ce8 100644 --- a/package.json +++ b/package.json @@ -23,6 +23,7 @@ "r": "tsc && node dist/index.js" }, "dependencies": { + "@commander-js/extra-typings": "^11.0.0", "commander": "^9.1.0" }, "devDependencies": { diff --git a/src/run.ts b/src/run.ts index 5d12e5a..a63e6ca 100644 --- a/src/run.ts +++ b/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) { @@ -16,11 +16,7 @@ function showResults({ error, results }: MigrationResultSet) { } } -export function run( - db: Kysely, - migrator: Migrator, - path: string = './migrations', -) { +export function run(db: Kysely, migrator: Migrator, path: string = './migrations') { program .command('up') .description('Run a pending migration if any') @@ -63,7 +59,9 @@ export function run( program .command('down-to') .argument('') - .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 @@ -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 { diff --git a/yarn.lock b/yarn.lock index 95f5efc..14ab426 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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"