-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from acro5piano/feature/cli
feat: able to run the CLI without the script file
- Loading branch information
Showing
4 changed files
with
54 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -71,3 +71,27 @@ Commands: | |
time as the version | ||
help [command] display help for command | ||
``` | ||
|
||
# Experimental: CLI without a script file | ||
|
||
Important NOTEs: | ||
|
||
- This is an experimental feature and the behaviour might change in the future. | ||
- Currently it works with Postgres only. | ||
|
||
You can run `kysely-migration-cli` without a script file. | ||
|
||
``` | ||
export DATABASE_URL=postgres://postgres:[email protected]:27253/postgres | ||
npm run kysely-migration-cli | ||
``` | ||
|
||
If you place `.env` file which contains `DATABASE_URL=postgres://...`, the CLI automatically loads it before execution. | ||
|
||
To compile typescript, `kysely-migration-cli` should register Node's hook api. Currently it supports the following transpiers: | ||
|
||
- `esbuild-register` | ||
- `ts-node/register/transpile-only` | ||
- `@swc-node/register` | ||
|
||
If you need more, please create a pull request. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#!/usr/bin/env node | ||
|
||
let registered = false | ||
|
||
const tryRegister = (pkg) => { | ||
try { | ||
require(pkg) | ||
registered = true | ||
console.log(`registered ${pkg}`) | ||
} catch (err) {} | ||
} | ||
|
||
tryRegister('esbuild-register') | ||
tryRegister('ts-node/register/transpile-only') | ||
tryRegister('@swc-node/register') | ||
|
||
if (!registered) { | ||
console.log('Warning: all of supported typescript transpiler registration failed') | ||
} | ||
|
||
require('../dist/cli').main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,9 @@ | |
"repository": "[email protected]:acro5piano/kysely-migration-cli", | ||
"author": "Kay Gosho <[email protected]>", | ||
"license": "MIT", | ||
"bin": { | ||
"kysely-migration-cli": "./bin/kysely-migration-cli.js" | ||
}, | ||
"files": [ | ||
"dist/*.js", | ||
"dist/*.map", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters