-
-
Notifications
You must be signed in to change notification settings - Fork 530
/
Copy pathinit.js
64 lines (52 loc) · 1.45 KB
/
init.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
54
55
56
57
58
59
60
61
62
63
64
import process from 'process';
import { _baseOptions } from '../core/yargs';
import helpers from '../helpers';
exports.builder = (yargs) =>
_baseOptions(yargs).option('force', {
describe: 'Will drop the existing config folder and re-create it',
type: 'boolean',
default: false,
}).argv;
exports.handler = async function (argv) {
const command = argv._[0];
switch (command) {
case 'init':
await initConfig(argv);
await initModels(argv);
await initMigrations(argv);
await initSeeders(argv);
break;
case 'init:config':
await initConfig(argv);
break;
case 'init:models':
await initModels(argv);
break;
case 'init:migrations':
await initMigrations(argv);
break;
case 'init:seeders':
await initSeeders(argv);
break;
}
process.exit(0);
};
function initConfig(args) {
if (!helpers.config.configFileExists() || !!args.force) {
helpers.config.writeDefaultConfig();
helpers.view.log('Created "' + helpers.config.relativeConfigFile() + '"');
} else {
helpers.view.notifyAboutExistingFile(helpers.config.relativeConfigFile());
process.exit(1);
}
}
function initModels(args) {
helpers.init.createModelsFolder(!!args.force);
helpers.init.createConnectionFile(!!args.force);
}
function initMigrations(args) {
helpers.init.createMigrationsFolder(!!args.force);
}
function initSeeders(args) {
helpers.init.createSeedersFolder(!!args.force);
}