/
index.js
56 lines (47 loc) · 1.58 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
#!/usr/bin/env node
'use strict';
process.env["SUPPRESS_NO_CONFIG_WARNING"] = true;
process.env["NODE_CONFIG_DIR"] = process.cwd() + "/.codex-data/config/";
const config = require("config");
if(!config.has('server-title')){
console.log('> No configuration file found in \"' + process.env["NODE_CONFIG_DIR"] + '\"');
}
var program = require('vorpal')();
var asDefault = require('vorpal-as-default').default;
var server = require('./server');
var program_helpers = require('./program-helpers');
program.command('default')
.hidden()
.action(function() {
this.log("Run 'codex start' to start the server or 'codex help' for a list of commands");
});
program.command('start')
.description("start codex server with current dir as root folder")
.action(function(args, callback) {
if(config == undefined)
{
this.log("> No configuration found. Run 'codex create config' to create a new configuration file");
} else {
try {
server.start(program, config);
// no callback() is needed so the server stays alive;
} catch (err) {
this.log("> Error starting server, shutting down");
this.log(err);
program.execSync('exit');
}
}
});
program.command('create')
.description("Create files and folder inside codex")
.action(function(args) {
switch (process.argv[1]) {
case 'config':
program_helpers.create_new_config(this);
break;
default:
this.log('No create operation for \"' + process.argv[1] + '\"');
break;
}
});
program.parse(process.argv).use(asDefault, 'default');