-
Notifications
You must be signed in to change notification settings - Fork 5
/
main.js
96 lines (81 loc) · 2.39 KB
/
main.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
var program = require('commander');
var updateNotifier = require('update-notifier');
var path = require('path');
var logger = require('./core/console.js');
var endedWith = require('./core/util/ended_with.js');
// TODO: remove global
var __root = global.__root = require('./root.js'); // eslint-disable-line no-unused-vars
// commands
var run = require('./core/commands/run.js');
var addApp = require('./core/commands/add_app.js');
var removeApp = require('./core/commands/remove_app.js');
var pkg = require('./package.json');
var notifier;
var lastArgv;
// if the environment variable is set to 1,
// this will log the file and line that outputs
// to the terminalr
if (process.env.TRACE_CONSOLE) {
['log', 'warn'].forEach(function (method) {
var old = console[method];
console[method] = function () {
var stack = (new Error()).stack.split(/\n/);
var args;
// Chrome includes a single "Error" line, FF doesn't.
if (stack[0].indexOf('Error') === 0) {
stack = stack.slice(1);
}
args = [].slice.apply(arguments)
.concat([stack[1].trim()]);
return old.apply(console, args);
};
});
}
// update notification
notifier = updateNotifier({
pkg: {
name: pkg.name,
version: pkg.version
},
updateCheckInterval: 1000 * 60 * 60 * 6, // check every 6 hours
defer: false
});
notifier.notify();
process.title = 'Silk GUI';
program
.version(pkg.version)
.option('-r, --remote', 'Remotely access Silk')
.option('-d, --dev', 'Show debug messages')
.option('-o, --open', 'Open Silk in a window');
program
.command('run')
.description('Starts silk. Default command.')
.action(run);
program
.command('add-app [path]')
.description('add app')
.action(addApp);
program
.command('remove-app [path]')
.description('remove app')
.action(removeApp);
program
.parse(process.argv);
lastArgv = process.argv[process.argv.length - 1];
if (lastArgv === 'help' || lastArgv === 'help') {
// silk help or npm start help was run.
program.help();
process.exit(0);
}
// Silk was run with no command, so we do the default
// Setting a default command appears to be broken in commander.js
// so we implement it ourselves.
console.log(lastArgv);
if (lastArgv === 'silk') {
run();
} else if (endedWith(lastArgv, 'main.js')) {
run();
} else if (endedWith(lastArgv, path.sep + 'bin' + path.sep + 'silk')) {
run();
}
logger.logLevel(program.dev ? 0 : 1);