-
-
Notifications
You must be signed in to change notification settings - Fork 14
/
bin.js
50 lines (43 loc) · 1.61 KB
/
bin.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/env node
const sade = require('sade');
const pkg = require('./package.json');
const { toConfig } = require('./lib/util');
const $ = require('./lib/log');
const ley = require('.');
function wrap(act) {
const done = $.done.bind($, act);
return async (opts, tmp) => {
if (tmp = await toConfig(opts.config, opts.cwd)) {
$.info('Loading configuration');
opts.config = await (typeof tmp === 'function' ? tmp() : tmp)
}
await ley[act](opts).then(done).catch($.bail);
};
}
sade('ley')
.version(pkg.version)
.option('-C, --cwd', 'The current directory to resolve from', '.')
.option('-d, --dir', 'The directory of migration files to run', 'migrations')
.option('-c, --config', 'Path to `ley` config file', 'ley.config.js')
.option('-D, --driver', 'The name of a database client driver')
.option('-r, --require', 'Additional module(s) to preload')
.command('up')
.describe('Run "up" migration(s). Applies all outstanding items.')
.option('-s, --single', 'Only run a single migraton')
.action(wrap('up'))
.command('down')
.describe('Run "down" migration(s). Defaults to one at a time.')
.option('-a, --all', 'Run all "down" migrations')
.action(wrap('down'))
.command('status')
.describe('Check for migration status. Counts unapplied migrations.')
.action(wrap('status'))
.command('new <filename>')
.describe('Create a new migration file.')
.option('-t, --timestamp', 'Prefix the filename with a timestamp')
.option('-l, --length', 'The length of prefix, if not timestamp', 5)
.action((filename, opts) => {
opts.filename = filename;
return wrap('new')(opts);
})
.parse(process.argv);