forked from FredrikNoren/ungit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGruntfile.js
338 lines (320 loc) · 11 KB
/
Gruntfile.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
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
var childProcess = require('child_process');
var phantomjs = require('phantomjs');
var path = require('path');
var fs = require('fs');
var npm = require('npm');
var semver = require('semver');
var async = require('async');
var ungitMain = path.resolve('./public/source/main.js');
module.exports = function(grunt) {
var packageJson = grunt.file.readJSON('package.json');
grunt.initConfig({
pkg: packageJson,
less: {
production: {
files: {
"public/css/styles.css": ["public/less/styles.less", "public/vendor/css/animate.css"],
"components/commit/commit.css": ["components/commit/commit.less"],
"components/commitdiff/commitdiff.css": ["components/commitdiff/commitdiff.less"],
"components/graph/graph.css": ["components/graph/graph.less"],
"components/header/header.css": ["components/header/header.less"],
"components/home/home.css": ["components/home/home.less"],
"components/imagediff/imagediff.css": ["components/imagediff/imagediff.less"],
"components/repository/repository.css": ["components/repository/repository.less"],
"components/staging/staging.css": ["components/staging/staging.less"],
"components/textdiff/textdiff.css": ["components/textdiff/textdiff.less"],
"components/stash/stash.css": ["components/stash/stash.less"],
"components/sidebysidediff/sidebysidediff.css": ["components/sidebysidediff/sidebysidediff.less"],
"components/refreshButton/refreshButton.css": ["components/refreshButton/refreshButton.less"],
}
}
},
browserify: {
common: {
options: {
browserifyOptions: {
noParse: ['public/vendor/js/superagent.js'],
},
debug: true,
// Make these globally requireable, for use in plugins
alias: [
'./public/source/components.js:ungit-components',
'./public/source/program-events.js:ungit-program-events',
'./public/source/navigation.js:ungit-navigation',
ungitMain + ':ungit-main',
// './public/source/main.js:ungit-main',
'./source/utils/vector2.js:ungit-vector2',
'./source/address-parser.js:ungit-address-parser',
'knockout:knockout',
'lodash:lodash',
'hasher:hasher',
'crossroads:crossroads',
'async:async',
'moment:moment',
'blueimp-md5:blueimp-md5',
'color:color',
'signals:signals',
'util:util',
'path:path',
'diff2html:diff2html'
]
},
files: {
'public/js/ungit.js': ['public/source/main.js'],
'public/js/devStyling.js': ['public/devStyling/devStyling.js']
}
},
components: {
options: {
browserifyOptions: {
bundleExternal: false
},
external: [
'ungit-components',
'ungit-program-events',
'ungit-navigation',
'ungit-main',
'ungit-vector2',
'ungit-address-parser',
'knockout',
'lodash',
'hasher',
'crossroads',
'async',
'moment',
'blueimp-md5',
],
debug: true
},
files: (function() {
var files = {};
fs.readdirSync('components').forEach(function(component) {
files['components/' + component + '/' + component + '.bundle.js'] = ['components/' + component + '/' + component + '.js'];
});
return files;
})()
}
},
watch: {
scripts: {
files: ['public/source/**/*.js', 'source/**/*.js', 'components/**/*.js'],
tasks: ['browserify'],
options: {
spawn: false,
},
},
less: {
files: ['public/less/*.less', 'public/styles/*.less', 'components/**/*.less'],
tasks: ['less:production'],
options: {
spawn: false,
},
}
},
lineending: {
// Debian won't accept bin files with the wrong line ending
production: {
options: {
eol: 'lf'
},
files: {
'./bin/ungit': ['./bin/ungit'],
'./bin/credentials-helper': ['./bin/credentials-helper']
}
},
},
release: {
options: {
commitMessage: 'Release <%= version %>',
}
},
// Run mocha tests
mochaTest: {
options: {
reporter: 'spec'
},
src: 'test/*.js'
},
// Plato code analysis
plato: {
all: {
files: {
'report': ['source/**/*.js', 'public/source/**/*.js'],
}
},
},
// Minify images (basically just lossless compression)
imagemin: {
default: {
options: {
optimizationLevel: 3
},
files: [{
expand: true,
cwd: 'assets/client/images/',
src: ['**/*.png'],
dest: 'public/images/'
}]
}
},
// Embed images in css
imageEmbed: {
default: {
files: {
"public/css/styles.css": [ "public/css/styles.css" ],
"components/graph/graph.css": ["components/graph/graph.css"],
"components/header/header.css": ["components/header/header.css"],
"components/staging/staging.css": ["components/staging/staging.css"],
},
options: {
deleteAfterEncoding: false
}
}
},
jshint: {
options: {
undef: true, // check for usage of undefined variables
indent: 2,
'-W033': true, // ignore Missing semicolon
'-W041': true, // ignore Use '===' to compare with '0'
'-W065': true, // ignore Missing radix parameter
'-W069': true, // ignore ['HEAD'] is better written in dot notation
},
web: {
options: {
node: true,
browser: true,
globals: {
'ungit': true,
'io': true,
'Keen': true,
'Raven': true
}
},
files: [
{
src: ['public/source/**/*.js', 'components/**/*.js'],
// Filter out the "compiled" components files; see the browserify task for components
filter: function(src) { return src.indexOf('bundle.js') == -1; }
}
]
},
phantomjs: {
options: {
phantom: true,
browser: true,
globals: {
'$': true,
'module': true,
}
},
src: ['clicktests/**/*.js']
},
node: {
options: {
node: true
},
src: [
'Gruntfile.js',
'bin/*',
'source/**/*.js',
]
},
mocha: {
options: {
node: true,
globals: {
'it': true,
'describe': true,
'before': true,
'after': true,
'window': true,
'document': true,
'navigator': true
}
},
src: [
'test/**/*.js',
]
}
}
});
grunt.registerTask('clicktest', 'Run clicktests.', function() {
var done = this.async();
grunt.log.writeln('Running clicktests...');
var child = childProcess.execFile(phantomjs.path, [path.join(__dirname, 'clicktests', 'test.all.js')], { maxBuffer: 10*1024*1024});
child.stdout.on('data', function(data) {
grunt.log.write(data);
});
child.stderr.on('data', function(data) {
grunt.log.error(data);
})
child.on('exit', function(code) {
grunt.log.writeln('Clicktests exited with code ' + code);
done(code == 0);
});
});
function bumpDependency(packageJson, dependencyType, packageName, callback) {
var currentVersion = packageJson[dependencyType][packageName];
if (currentVersion[0] == '~' || currentVersion[0] == '^') currentVersion = currentVersion.slice(1);
npm.commands.show([packageName, 'versions'], true, function(err, data) {
if(err) return callback(err);
var versions = data[Object.keys(data)[0]].versions.filter(function(v) {
return v.indexOf('alpha') == -1;
});
var latestVersion = versions[versions.length - 1];
if (semver.gt(latestVersion, currentVersion)) {
packageJson[dependencyType][packageName] = '~' + latestVersion;
}
callback();
});
}
grunt.registerTask('bumpdependencies', 'Bump dependencies to their latest versions.', function() {
var done = this.async();
grunt.log.writeln('Bumping dependencies...');
npm.load(function() {
var tempPackageJson = JSON.parse(JSON.stringify(packageJson));
async.parallel([
async.map.bind(null, Object.keys(tempPackageJson.dependencies), function(dep, callback) {
// Keep forever-monitor at 1.1.0 until https://github.com/nodejitsu/forever-monitor/issues/38 is fixed
if (dep == 'forever-monitor') return callback();
// Socket.io 1.0.0-pre didn't work with phantomjs, so keep it at 0.9.16 for now
if (dep == 'socket.io') return callback();
// Superagent 1.x has a new api, need to upgrade to that if we want to bump
if (dep == 'superagent') return callback();
bumpDependency(tempPackageJson, 'dependencies', dep, callback);
}),
async.map.bind(null, Object.keys(tempPackageJson.devDependencies), function(dep, callback) {
// Same with imagemin, something with 0.5.0 doesn't work on mac
if (dep == 'grunt-contrib-imagemin') return callback();
// For some reason supertest > 0.10 doesn't work with the tests. Haven't investigated why yet.
if (dep == 'supertest') return callback();
bumpDependency(tempPackageJson, 'devDependencies', dep, callback);
})
], function() {
fs.writeFileSync('package.json', JSON.stringify(tempPackageJson, null, 2) + '\n');
grunt.log.writeln('Dependencies bumped, run npm install to install latest versions.');
done();
});
});
});
grunt.loadNpmTasks('grunt-contrib-less');
grunt.loadNpmTasks('grunt-browserify');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-lineending');
grunt.loadNpmTasks('grunt-release');
grunt.loadNpmTasks('grunt-mocha-test');
grunt.loadNpmTasks('grunt-plato');
grunt.loadNpmTasks('grunt-contrib-imagemin');
grunt.loadNpmTasks('grunt-image-embed');
grunt.loadNpmTasks('grunt-contrib-jshint');
// Default task, builds everything needed
grunt.registerTask('default', ['less:production', 'jshint', 'browserify', 'lineending:production', 'imagemin:default', 'imageEmbed:default']);
// Run tests
grunt.registerTask('unittest', ['mochaTest']);
grunt.registerTask('test', ['unittest', 'clicktest']);
// Builds, and then creates a release (bump patch version, create a commit & tag, publish to npm)
grunt.registerTask('publish', ['default', 'test', 'release:patch']);
// Same as publish but for minor version
grunt.registerTask('publishminor', ['default', 'test', 'release:minor']);
};