-
Notifications
You must be signed in to change notification settings - Fork 52
/
make.js
229 lines (188 loc) · 6.29 KB
/
make.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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
require('shelljs/make');
var fs = require('fs');
var path = require('path');
var spawn = require('child_process').spawn;
var _ = require('lodash');
var shell = require('shelljs');
var meteor_bin = process.platform == 'win32' ? 'meteor.bat' : 'meteor';
var node_bin = process.platform == 'win32' ? 'node.exe' : 'node';
var NODE_MODS = path.join(__dirname, 'node_modules');
var ISTANBUL = path.join(NODE_MODS, 'istanbul', 'lib', 'cli.js');
var _MOCHA = path.join(NODE_MODS, 'mocha', 'bin', '_mocha');
var _MOCHA = path.join(NODE_MODS, 'mocha', 'bin', '_mocha');
var NPMCHECK = path.join(NODE_MODS, 'npm-check', 'lib', 'cli.js');
// setup local env with local symlinks and proper configs
target.setup = function() {
log('setting up everything for development');
// list folder paths
var parent = path.join(__dirname, '..');
var leaderboard = path.join(parent, 'leaderboard');
var packages_dir = path.join(leaderboard, 'packages');
// reset folders
shell.exec('npm link');
shell.rm('-rf', leaderboard);
// create sample test app in parent dir
spawn(meteor_bin, ['create', '--example', 'leaderboard'], {
stdio: 'inherit',
cwd: parent
}).on('exit', function(){
// links arboleya:electrify inside meteor
shell.mkdir('-p', packages_dir);
shell.ln('-s', __dirname, path.join(packages_dir, 'arboleya-electrify'));
// removes mobile platforms
spawn(meteor_bin, ['remove-platform', 'ios', 'android'], {
stdio: 'inherit',
cwd: leaderboard
}).on('exit', function(){
// adding electrify meteor package
spawn(meteor_bin, ['add', 'arboleya:electrify'], {
stdio: 'inherit',
cwd: leaderboard,
// modify env var so electrify package will know how to proceed,
// fetching the npm package locally or from remote npm registry
env: _.extend({
DEVELECTRIFY: true,
LOGELECTRIFY: 'ALL'
}, process.env)
// finish
}).on('exit', function(){
process.exit();
});
});
});
};
// start test app in dev mode
target.dev = function(action){
var leaderboard = path.join(__dirname, '..', 'leaderboard');
var leaderboard_electrify = path.join(leaderboard, '.electrify');
log('starting in dev mode');
if(~'reset'.indexOf(action))
shell.rm('-rf', leaderboard_electrify);
spawn('node', [path.join(__dirname, 'bin', 'cli.js')], {
cwd: leaderboard,
stdio: 'inherit',
env: _.extend(_.clone(process.env), {
DEVELECTRIFY: true,
LOGELECTRIFY: 'ALL'
})
});
};
// tests
target.test = function() {
spawn(node_bin, [_MOCHA, 'test'], {
stdio: 'inherit',
env: _.extend({
DEVELECTRIFY: true,
LOGELECTRIFY: 'ALL',
TESTELECTRIFY: true
}, process.env)
});
};
target['test.cover'] = function(done){
spawn(node_bin, [ISTANBUL, 'cover', _MOCHA], {
stdio: 'inherit',
env: _.extend({
DEVELECTRIFY: true,
LOGELECTRIFY: 'ALL',
TESTELECTRIFY: true
}, process.env)
}).on('exit', function(){
if(done) done();
});
};
target['test.cover.preview'] = function(){
target['test.cover'](function(){
if(!fs.existsSync('./coverage/lcov-report')) return;
spawn('python', ['-m', 'SimpleHTTPServer', '8080'], {
cwd: './coverage/lcov-report',
stdio: 'inherit',
env: _.extend({
DEVELECTRIFY: true,
LOGELECTRIFY: 'ALL',
TESTELECTRIFY: true
}, process.env)
});
console.log('preview coverage at: http://localhost:8080');
});
};
target['test.cover.send'] = function() {
var repo_token = process.env.CODECLIMATE_REPO_TOKEN;
if(repo_token === undefined || repo_token.trim() === '') {
console.error('No CODECLIMATE_REPO_TOKEN found.');
process.exit(1);
}
target['test.cover'](function(){
// reads lcov data
var lcov_path = path.join(__dirname, 'coverage', 'lcov.info');
var lcov = fs.readFileSync(lcov_path, 'utf-8');
var node_mods = path.join(
__dirname,
'node_modules',
'codeclimate-test-reporter'
);
var Formatter = require(path.join(node_mods, 'formatter'));
var client = require(path.join(node_mods, 'http_client'));
var formatter = new Formatter();
formatter.format(lcov, function(err, json) {
if (err)
console.error("A problem occurred parsing the lcov data", err);
else {
json.repo_token = repo_token;
client.postJson(json);
console.log('coverage sent to codeclimate');
}
});
});
};
target['update.version'] = function(version) {
var filepath, content, replacement;
// package.js
replacement = '$1'+ version[0] + "'";
filepath = path.join(__dirname, 'package.js');
content = fs.readFileSync(filepath, 'utf-8');
content = content.replace(/(^var VERSION = ')[0-9\.]+'/i, replacement);
fs.writeFileSync(filepath, content);
// package.json
replacement = '"version": "'+ version[0];
filepath = path.join(__dirname, 'package.json');
content = fs.readFileSync(filepath, 'utf-8');
content = content.replace(/"version":\s*"[0-9\.]+/i, replacement);
fs.writeFileSync(filepath, content);
// lib/env.js
replacement = 'this.version = \''+ version[0];
filepath = path.join(__dirname, 'lib', 'env.js');
content = fs.readFileSync(filepath, 'utf-8');
content = content.replace(/this.version = '[0-9\.]+/i, replacement);
fs.writeFileSync(filepath, content);
//HISTORY.md
replacement = 'this.version = \''+ version[0];
filepath = path.join(__dirname, 'HISTORY.md');
content = fs.readFileSync(filepath, 'utf-8');
fs.writeFileSync(filepath, [
version[0] + ' / {{DATE..}}',
'===================',
' * {{TOPIC...}}\n',
content
].join('\n'));
};
target['deps.check'] = function(){
spawn(node_bin, [NPMCHECK], {
stdio: 'inherit'
});
};
target['deps.upgrade'] = function(){
spawn(node_bin, [NPMCHECK, '-u'], {
stdio: 'inherit'
});
};
target.publish = function(){
var version = require('./package.json').version;
shell.exec('git tag -a '+ version +' -m "Releasing '+ version +'"');
shell.exec('git push origin master --tags');
shell.exec('npm publish');
shell.exec('meteor publish');
};
function log(){
var args = Array.prototype.slice.call(arguments);
console.log.apply(null, ['electrify: '].concat(args));
}