UNPKG

2.23 kBJavaScriptView Raw
1#!/usr/bin/env node
2
3/*
4
5 This file is a part of node-on-train project.
6
7 Copyright (C) Thanh D. Dang <thanhdd.it@gmail.com>
8
9 node-on-train is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
13
14 node-on-train is distributed in the hope that it will be useful, but
15 WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>.
21
22*/
23
24
25var path = require('path');
26var fs = require('fs');
27var Fiber = require('fibers');
28
29TRAINJS_LIB_PATH = path.join(path.dirname(fs.realpathSync(__filename)), '../');
30var info_param = {};
31
32// Check trainjs, nodejs, livescript version
33function checkinfo () {
34 info_param.trainjs_version = require(TRAINJS_LIB_PATH + 'package.json').version;
35 info_param.node_version = process.version.substr(1);
36}
37
38Fiber(function() {
39 checkinfo();
40 if (process.argv[2] == "server" || process.argv[2] == "s") {
41 require('./train_server.js')();
42 } else if (process.argv[2] == "new") {
43 require('./train_new.js')(info_param);
44 } else if (process.argv[2] == "-h" || process.argv[2] == "--help") {
45 fs.readFile(path.dirname(fs.realpathSync(__filename)) + '/train_help', function (err, data) {
46 if (err) throw err;
47 console.log(data.toString());
48 });
49 } else if (process.argv[2] == "-v" || process.argv[2] == "--version") {
50 console.log("trainjs " + info_param.trainjs_version);
51 } else if (process.argv[2] == "generate" || process.argv[2] == "g") {
52 if (process.argv[3] == "scaffold")
53 require('./train_generate_scaffold.js')();
54 else if (process.argv[3] == "controller")
55 require('./train_generate_controller.js')();
56 else if (process.argv[3] == "model")
57 require('./train_generate_model.js')();
58 else if (process.argv[3] == "database")
59 require('./train_generate_database.js')();
60 else if (process.argv[3] == "service")
61 require('./train_generate_service.js')();
62 }
63}).run();