-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
executable file
·77 lines (67 loc) · 2.34 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#! /usr/bin/env node
'use strict';
var execSync = require('child_process').execSync;
var generators = require('./generators');
var path = require('path');
var program = require('commander');
var s = require('underscore.string');
program
.command('new <NAME>')
.description('Generate a new kale app with a default directory structure and configuration')
.action(generators.app);
program
.command('generate <GENERATOR> <NAME>')
.alias('g')
.usage('<controller|model|view|scaffold|migration> <NAME>')
.description('Generate a new model, controller, scaffold, or migration for a Kale.js app')
.option('-e, --empty', 'generate the file, but do not include any content')
.action(function(generator, name, options) {
name = s.underscored(name);
switch (generator) {
case 'controller':
generators.controller(name, options);
break;
case 'model':
generators.model(name, options);
break;
case 'view':
generators.view(name, options);
break;
case 'scaffold':
generators.scaffold(name, options);
break;
case 'migration':
generators.migration(name, options);
break;
default:
console.log(`Unknown generator ${generator}`);
process.exit(1);
}
});
program
.command('migrate')
.action(function() {
var knex = path.join('.', 'node_modules', '.bin', 'knex');
var knexfile = path.join('.', 'db', 'knexfile.js');
console.log(`${knex} migrate:latest --knexfile ${knexfile}`);
var result = execSync(`${knex} migrate:latest --knexfile ${knexfile}`, { encoding: 'utf8' });
console.log(result);
});
program
.command('migrate:rollback')
.action(function() {
var knex = path.join('.', 'node_modules', '.bin', 'knex');
var knexfile = path.join('.', 'db', 'knexfile.js');
console.log(`${knex} migrate:rollback --knexfile ${knexfile}`);
var result = execSync(`${knex} migrate:rollback --knexfile ${knexfile}`, { encoding: 'utf8' });
console.log(result);
});
program
.command('migrate:test')
.action(function() {
var knex = path.join('.', 'node_modules', '.bin', 'knex');
var knexfile = path.join('.', 'db', 'knexfile.js');
var result = execSync(`NODE_ENV=test ${knex} migrate:latest --knexfile ${knexfile}`, { encoding: 'utf8' });
console.log(result);
});
program.parse(process.argv);