-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
53 lines (44 loc) · 1.44 KB
/
index.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
51
52
53
// registering Promise implementation in global object for any library using `any-promise` (like promise-map and promise-filter)
// (to bring support in olders versions of node)
global.Promise = require('pinkie-promise');
/* eslint-disable no-console */
import requireDir from 'require-dir';
import chalk from 'chalk';
import inquirer from 'inquirer';
const migrations = requireDir('./migrations');
const migrationChoices = Object.keys(migrations).map((migrationName) => {
const currentMigration = migrations[migrationName];
return {
name: `${currentMigration.migrationName} -> ${currentMigration.description}`,
value: currentMigration
};
});
export default function(workingDir) {
const currentBasePath = workingDir || process.cwd();
inquirer.prompt([{
type: 'list',
name: 'migration',
message: 'Select a migration script to run',
choices: migrationChoices
}], (selected) => {
console.log(
chalk.yellow(
`runnning ${chalk.magenta.bold(selected.migration.migrationName)} migration script`
)
);
selected.migration(currentBasePath).then(() => {
console.log(
chalk.yellow(
`migration ${chalk.magenta.bold(selected.migration.migrationName)} finished`
)
);
}).catch((err) => {
console.error(err);
console.log(
chalk.yellow(
`migration ${chalk.magenta.bold(selected.migration.migrationName)} finished`
)
);
});
});
}