forked from joewalker/gcli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgcli.js
93 lines (83 loc) · 3.02 KB
/
gcli.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
#!/usr/bin/env node
/*
* Copyright 2012, Mozilla Foundation and contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
exports.gcliHome = __dirname;
/**
* There are 2 options for loading GCLI CommonJS modules:
* 1. Use Require's r.js
* 2. Convert the modules to CommonJS format on the fly.
*
* The former feels less hacky, the latter allows us to use 'cover' test
* coverage. Neither are complex so we've left them both in so they can fight
* it out.
*/
exports.useUnamd = false;
// Setup the exports.require function to use either:
// - requirejs (through r.js) or
// - node's require (via unamd)
if (exports.useUnamd) {
var unamd = require('./lib/server/unamd');
[ 'gcli', 'gclitest', 'test' ].forEach(function(packageName) {
var srcDir = exports.gcliHome + '/lib/' + packageName;
var destDir = exports.gcliHome + '/node_modules/' + packageName;
unamd.unamdize(srcDir, destDir);
});
exports.require = require;
}
else {
// It's tempting to use RequireJS from npm, however that would break
// running GCLI in Firefox just by opening index.html
var requirejs = require('./scripts/r.js');
requirejs.config({
nodeRequire: require,
paths: { 'text': 'scripts/text', 'i18n': 'scripts/i18n' },
packagePaths: {
'lib': [
{ name: 'gcli', main: 'index', lib: '.' },
{ name: 'test', main: 'index', lib: '.' },
{ name: 'gclitest', main: 'index', lib: '.' },
{ name: 'demo', main: 'index', lib: '.' },
{ name: 'server', main: 'index', lib: '.' }
]
}
});
exports.require = requirejs;
}
exports.require('gcli/index');
// Load the commands defined in Node modules
require('./lib/server/commands/unamd').startup();
require('./lib/server/commands/firefox').startup();
// require('./lib/server/commands/git').startup();
require('./lib/server/commands/make').startup();
require('./lib/server/commands/standard').startup();
require('./lib/server/commands/test').startup();
// Load the commands defined in CommonJS modules
var help = exports.require('gcli/commands/help');
help.startup();
exports.require('gcli/commands/pref').startup();
var fs = require('fs');
help.helpManHtml = fs.readFileSync(exports.gcliHome + '/lib/server/commands/help_man.txt', 'utf8');
help.helpListHtml = fs.readFileSync(exports.gcliHome + '/lib/server/commands/help_list.txt', 'utf8');
// Serve or execute
var server = require('./lib/server/index');
if (process.argv.length < 3) {
server.serve();
}
else {
var command = process.argv.slice(2).join(' ');
var reply = server.exec(command);
console.log(reply);
}