-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
140 lines (126 loc) · 2.77 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
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
'use strict';
const config = require('./src/config');
const colors = require('./src/colors');
const build = require('./src/build');
const setBranch = require('./src/branch');
const commitChanges = require('./src/commit-changes');
const mergeOriginal = require('./src/merge');
let branch = null,
commit = false,
publish = false;
// Get arguments. Complex function because of possibility to add more options
if (process.argv.length > 2) {
let args = process.argv.slice(2),
skipNextArg = false,
ignoreNext = false,
branchNext = false;
args.forEach((cmd, index) => {
if (skipNextArg) {
skipNextArg = false;
return;
}
if (cmd.slice(0, 1) === '-') {
// noinspection FallThroughInSwitchStatementJS
branchNext = false;
switch (cmd) {
case '--branch':
branchNext = true;
break;
case '--commit':
commit = true;
break;
case '--publish':
commit = true;
publish = true;
break;
case '--no-clone':
config.clone = false;
break;
default:
throw new Error('Unknown command: ' + cmd);
}
return;
}
if (branchNext) {
branch = cmd;
}
});
}
// Do stuff
if (branch === null) {
let merged = false,
changed;
// Parse all branches
if (!commit) {
console.error(
colors.error +
'[error]' +
colors.reset +
': Cannot parse all branches without committing changes. Add --publish or --commit'
);
return;
}
// Parse original branch
build('original')
.then(res => {
changed = res;
if (changed.changed) {
if (changed.changed) {
console.log('Updated:', changed.updated, '\nAdded:', changed.added);
}
return commitChanges(
'original',
changed.added,
changed.updated,
publish
);
}
})
.then(() => {
// Change branch
return setBranch('master');
})
.then(() => {
// Merge changes
if (changed.changed) {
merged = true;
return mergeOriginal();
}
})
.then(() => {
// Build master branch
return build('master');
})
.then(res => {
changed = res;
if (changed.changed) {
console.log('Updated:', changed.updated, '\nAdded:', changed.added);
}
if (changed.changed || merged) {
return commitChanges('master', changed.added, changed.updated, publish);
}
})
.catch(err => {
console.error(colors.error + '[error]' + colors.reset + ':', err);
});
} else {
let changed;
// Parse one branch
build(branch)
.then(res => {
changed = res;
if (changed.changed) {
console.log('Updated:', changed.updated, '\nAdded:', changed.added);
if (commit) {
// Commit changes
return commitChanges(branch, changed.added, changed.updated, publish);
}
}
})
.then(() => {
// Done
})
.catch(err => {
console.error(colors.error + '[error]' + colors.reset + ':', err);
});
}