-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathindex.js
45 lines (39 loc) · 1.28 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
#!/usr/bin/env node
var path = require('path');
var fs = require('fs');
var colors = require('colors');
var shell = require('./lib/shell');
var subtree = require('./lib/subtree');
var args = process.argv.slice(2);
if (args.length > 0) {
// Check if it's project root
try {
var gitroot = path.join(process.cwd(), ".git")
fs.readdirSync(gitroot);
} catch (error) {
console.error('Run this script from the root of the repository.'.red);
process.exit(1);
}
// Check if config file exists
try {
var subtrees = path.join(process.cwd(), "subtrees.json")
fs.readFileSync(subtrees);
} catch (error) {
console.error('Missing subtrees.json configuration file'.red);
process.exit(1);
}
subtree.run(args, function(err, result) {
if (err) {
console.error(('ERROR: ' + err).red);
process.exit(1);
}
});
} else {
console.log('usage: gitsbt <command>\n');
console.log('Commands:');
console.log('init\tInitialize project subtrees');
console.log('add\tCreate remote, fetch and add subtree folder');
console.log('pull\tPull changes from subtree');
console.log('push\tPush changes to subtree');
console.log('commit\tCommit subtree folder changes');
}