Skip to content

Commit

Permalink
Switch to CLI option
Browse files Browse the repository at this point in the history
  • Loading branch information
karlhorky committed Sep 4, 2024
1 parent 4ffb7e6 commit 390396d
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 7 deletions.
1 change: 1 addition & 0 deletions bin.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ 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('-f, --fileRegex', 'A regular expression used to match files in the migrations', '\.[cm]?[tj]s$')
.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')
Expand Down
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ async function parse(opts) {
$.isDriver(driver); // throws validation error(s)
}

const migrations = await $.glob(dir, opts.config.fileRegex);
const migrations = await $.glob(dir, opts.fileRegex);

return { driver, migrations };
}
Expand Down Expand Up @@ -108,7 +108,7 @@ exports.new = async function (opts={}) {

let str = '';
await mkdir(dir);

if (opts.esm) {
str += 'export async function up(client) {\n\n}\n\n';
str += 'export async function down(client) {\n\n}\n';
Expand Down
3 changes: 2 additions & 1 deletion lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ const { existsSync } = require('fs');
const { totalist } = require('totalist');
const { resolve } = require('path');

exports.glob = async function (dir, rgx = /\.[cm]?[tj]s$/) {
exports.glob = async function (dir, fileRegex = '\.[cm]?[tj]s$') {
const output = [];
const rgx = new RegExp(fileRegex);
await totalist(dir, (name, abs) => rgx.test(name) && output.push({ name, abs }));
return output.sort((a, b) => a.name.localeCompare(b.name, undefined, { numeric:true })); // ~rand order
}
Expand Down
6 changes: 3 additions & 3 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -397,10 +397,10 @@ Default: `migrations`
The directory (relative to `opts.cwd`) to find migration files.

#### opts.fileRegex
Type: `RegExp`<br>
Default: `/\.[cm]?[tj]s$/`
Type: `string`<br>
Default: `\.[cm]?[tj]s$`

The file regex used to find migration files in `opts.dir`.
The file RegExp string used to find migration files in `opts.dir`.

#### opts.driver
Type: `string` or `Driver`<br>
Expand Down
2 changes: 1 addition & 1 deletion test/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ glob('usage', async ctx => {
});

glob('fileRegex option', async ctx => {
const out = await $.glob(ctx.dir, /00[123]\.js/);
const out = await $.glob(ctx.dir, '00[123]\.js$');
assert.ok(Array.isArray(out), 'returns Promise<Array>');
assert.is(out.length, 3, '~> has 3 items');

Expand Down

0 comments on commit 390396d

Please sign in to comment.