-
Notifications
You must be signed in to change notification settings - Fork 12
/
index.js
executable file
·44 lines (37 loc) · 1.52 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
#!/usr/bin/env node --harmony
const program = require('commander');
const fs = require('fs');
const path = require('path');
const clc = require('cli-color');
const package = JSON.parse(fs.readFileSync(path.join(__dirname, './package.json')));
program
.version(package.version)
.option('init [type]', 'Create new .mertrc file. Options: global or local')
.option('start [name]', 'Start project by name or by specifying file path (defaults to .mertrc in cwd)')
.option('list', 'List projects defined in ~/.mertrc')
.parse(process.argv);
if (program.init) {
const initializer = require('./lib/initializer.js');
return initializer.init(program.init);
}
if (program.start) {
const launcher = require('./lib/launcher.js')
const configLoader = require('./lib/config-loader.js')
var projectName = program.start === true ? null : program.start;
console.log(clc.green(`Starting ${ projectName || 'local' } project.`));
console.log(clc.green(`Please wait until all panes have initialized!`));
const config = configLoader.load(projectName);
return launcher.launch(config)
}
if (program.list) {
const configLoader = require('./lib/config-loader.js');
const globalConfig = configLoader.loadGlobal();
let list = Object.keys(globalConfig).join('\n');
let localMertrc = path.join(process.cwd(), '.mertrc');
let hasLocalMertrc = fs.existsSync(localMertrc);
if (hasLocalMertrc) {
const localConfig = configLoader.load(localMertrc);
list += '\n' + Object.keys(localConfig).join('\n');
}
return console.log(list)
}