This repository has been archived by the owner on May 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 75
/
Copy pathGruntfile.js
executable file
·496 lines (436 loc) · 13.2 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
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
var rimraf = require("rimraf");
var targz = require('tar.gz');
var fs = require("fs-extra");
var util = require("util");
util._extend({
encoding: "utf8",
timeout: 0,
maxBuffer: false,
killSignal: "SIGTERM",
cwd: null,
env: null
});
var parseBuildPlatforms = function(argumentPlatform) {
// this will make it build no platform when the platform option is specified
// without a value which makes argumentPlatform into a boolean
var inputPlatforms = argumentPlatform || process.platform + ";" + process.arch;
// Do some scrubbing to make it easier to match in the regexes bellow
inputPlatforms = inputPlatforms.replace("darwin", "mac");
inputPlatforms = inputPlatforms.replace(/;ia|;x|;arm/, "");
var buildAll = /^all$/.test(inputPlatforms);
var buildPlatforms = {
mac: /mac/.test(inputPlatforms) || buildAll,
win: /win/.test(inputPlatforms) || buildAll,
linux32: /linux32/.test(inputPlatforms) || buildAll,
linux64: /linux64/.test(inputPlatforms) || buildAll
};
return buildPlatforms;
};
module.exports = function(grunt) {
"use strict";
var buildPlatforms = parseBuildPlatforms(grunt.option("platforms"));
var currentVersion = grunt.file.readJSON("package.json").version;
// buildPlatforms = parseBuildPlatforms(grunt.option("platforms"))
var packageJson = grunt.file.readJSON("package.json");
var _VERSION = packageJson.version;
grunt.log.writeln("Building " + packageJson.version);
grunt.initConfig({
// Wipe out previous builds and test reporting.
clean: {
all: [
"build/komanda-source",
"build/releases/**",
"node_modules",
"vendor"
],
some: [
"build/komanda-source",
"build/releases/**"
]
},
handlebars: {
compile: {
options: {
amd: true,
namespace: "Templates",
partialsUseNamespace: true,
processName: function(filePath) {
var file = filePath.replace(/.*\/(\w+)\.hbs/, "$1");
return file;
}
},
files: {
"app/templates.js": ["app/templates/*.hbs"]
}
}
},
// Run your source code through JSHint"s defaults.
jshint: {
jshintrc: ".jshint",
options: {
smarttabs: true,
proto: true,
eqnull: true,
quotmark: "double"
},
all: [
"app/**/*.js",
"!app/templates.js",
"!app/lib/deps/**/*.js"
]
},
// This task uses James Burke"s excellent r.js AMD builder to take all
// modules and concatenate them into a single file.
requirejs: {
release: {
options: {
mainConfigFile: "app/config.js",
generateSourceMaps: false,
include: ["main"],
out: "build/komanda-source/komanda.js",
optimize: "uglify2",
// Since we bootstrap with nested `require` calls this option allows
// R.js to find them.
findNestedDependencies: true,
// Include a minimal AMD implementation shim.
name: "almond",
// Setting the base url to the distribution directory allows the
// Uglify minification process to correctly map paths for Source
// Maps.
baseUrl: "build/komanda-source/app",
// Wrap everything in an IIFE.
wrap: true,
// Do not preserve any license comments when working with source
// maps. These options are incompatible.
preserveLicenseComments: false
}
}
},
// This task simplifies working with CSS inside Backbone Boilerplate
// projects. Instead of manually specifying your stylesheets inside the
// HTML, you can use `@imports` and this task will concatenate only those
// paths.
styles: {
// Out the concatenated contents of the following styles into the below
// development file path.
"build/komanda-source/komanda.css": {
// Point this to where your `index.css` file is location.
src: "app/styles/index.css",
// The relative path to use for the @imports.
paths: ["app/styles"],
// Rewrite image paths during release to be relative to the `img`
// directory.
// forceRelative: [ "/app/images/", "/app/fonts" ]
}
},
// Minify the distribution CSS.
cssmin: {
release: {
files: {
"build/komanda-source/komanda.css": ["build/komanda-source/komanda.css"]
}
}
},
server: {
options: {
host: "0.0.0.0",
port: 8000
},
development: {},
release: {
options: {
prefix: "build/komanda-source"
}
},
test: {
options: {
forever: false,
port: 8001
}
}
},
processhtml: {
release: {
files: {
"build/komanda-source/index.html": ["index.html"]
}
}
},
// Move vendor and app logic during a build.
copy: {
release: {
files: [
{
src: "package.json",
dest: "build/komanda-source/package.json"
},
{
src: ["app/**"],
dest: "build/komanda-source/"
},
{
src: "vendor/**",
dest: "build/komanda-source/"
},
{
src: "themes/**",
dest: "build/komanda-source/"
}
]
}
},
compress: {
release: {
options: {
archive: "build/komanda-source/komanda.js.gz"
},
files: ["build/komanda-source/komanda.js"]
}
},
nodewebkit: {
options: {
version: "0.12.1",
appName: "Komanda",
appVersion: "1.0.0.beta",
buildDir: "./build",
cacheDir: "./build/cache",
platforms: ["osx", "win", "linux32", "linux64"],
macIcns: "app/styles/images/logo/komanda.icns",
macCredits: "credits.html",
// winIco: "app/styles/images/logo/komanda.ico"
winIco: null
},
// src: ["./**/*"],
src: [
"./build/komanda-source/**/*",
// "./node_modules/irc/**/*",
]
},
exec: {
win: {
cmd: '"build/cache/<%= nodewebkit.options.version %>/win/nw.exe" .'
},
mac: {
cmd: "build/cache/<%= nodewebkit.options.version %>/osx/node-webkit.app/Contents/MacOS/node-webkit ."
},
linux32: {
cmd: "build/cache/<%= nodewebkit.options.version %>/linux32/nw ."
},
linux64: {
cmd: "build/cache/<%= nodewebkit.options.version %>/linux64/nw ."
},
createDmg: {
cmd: "dist/mac/yoursway-create-dmg/create-dmg --volname \"Komanda " + currentVersion + "\" --background ./dist/mac/background.png --window-size 480 540 --icon-size 128 --app-drop-link 240 370 --icon \"Komanda\" 240 110 ./build/releases/Komanda/osx/Komanda-" + currentVersion + "-Mac.dmg ./build/releases/Komanda/osx/"
},
createWinInstall: {
cmd: "makensis dist/windows/installer.nsi"
},
createWinUpdate: {
cmd: "makensis dist/windows/updater.nsi"
}
},
shell: {
npm: {
options: {
stdout: false,
stderr: false,
stdin: false
},
command: "npm install"
},
runnw: {
options: {
stdout: false,
stderr: false,
stdin: false
},
command: "./build/cache/0.10.2/osx/node-webkit.app/Contents/MacOS/node-webkit . > /dev/null 2>&1"
},
linux64: {
options: {
stdout: false,
stderr: false,
stdin: false,
},
command: "./build/cache/0.10.2/linux64/nw ./build/komanda-source/"
},
linux32: {
options: {
stdout: false,
stderr: false,
stdin: false,
},
command: "./build/cache/0.10.2/linux32/nw ./build/komanda-source/"
},
create_dmg: {
options: {
stdout: true
},
command: "./dist/mac/yoursway-create-dmg/create-dmg --volname \"Komanda " + _VERSION + "\" --background ./dist/mac/background.png --window-size 480 540 --icon-size 128 --app-drop-link 240 370 --icon \"Komanda\" 240 110 ./build/releases/Komanda/osx/Komanda-" + _VERSION + ".dmg ./build/releases/Komanda/osx/"
}
},
revision: {
options: {
property: "revision",
ref: "HEAD",
short: true
}
},
replace: {
revision: {
options: {
patterns: [{
match: "GIT_REVISION",
replacement: "<%= revision %>"
}]
},
files: [{
src: "build/komanda-source/app/main.js",
dest: "build/komanda-source/app/main.js"
}]
}
}
});
grunt.registerTask("cleanBuildDir", "remove unneeded files from the build dir.", function() {
fs.mkdirSync("build/komanda-source/images");
fs.mkdirSync("build/komanda-source/fonts");
fs.copySync("build/komanda-source/app/styles/images", "build/komanda-source/images");
fs.copySync("build/komanda-source/app/styles/fonts", "build/komanda-source/fonts");
fs.copySync("build/komanda-source/app/sounds", "build/komanda-source/sounds");
fs.copySync("build/komanda-source/vendor/bower/octicons/octicons", "build/komanda-source/fonts/octicons/");
fs.copySync("node_modules/irc/", "build/komanda-source/node_modules/irc/");
fs.copySync("node_modules/gitter-marked/", "build/komanda-source/node_modules/gitter-marked/");
fs.copySync("node_modules/highlight.js/", "build/komanda-source/node_modules/highlight.js/");
rimraf.sync("build/komanda-source/app", function(error) {
console.log(error);
});
rimraf.sync("build/komanda-source/vendor", function(error) {
console.log(error);
});
});
// Grunt contribution tasks.
grunt.loadNpmTasks("grunt-contrib-clean");
grunt.loadNpmTasks("grunt-contrib-jshint");
grunt.loadNpmTasks("grunt-contrib-cssmin");
grunt.loadNpmTasks("grunt-contrib-copy");
grunt.loadNpmTasks("grunt-contrib-compress");
// Third-party tasks.
grunt.loadNpmTasks("grunt-exec");
grunt.loadNpmTasks("grunt-npm-install");
grunt.loadNpmTasks("grunt-open");
grunt.loadNpmTasks("grunt-node-webkit-builder");
grunt.loadNpmTasks("grunt-bbb-server");
grunt.loadNpmTasks("grunt-processhtml");
grunt.loadNpmTasks("grunt-contrib-handlebars");
grunt.loadNpmTasks("grunt-contrib-requirejs");
grunt.loadNpmTasks("grunt-bbb-styles");
grunt.loadNpmTasks("grunt-shell");
grunt.loadNpmTasks("grunt-git-revision");
grunt.loadNpmTasks("grunt-replace");
grunt.registerTask("default", []);
grunt.registerTask("build", function(platforms) {
var targetPlatforms = parseBuildPlatforms(platforms);
// Overwrite initial nodewebkit.options.platforms array with the
// platforms returned by parseBuildPlatforms
var targetPlatformsArray = [];
Object.keys(targetPlatforms).forEach(function(target) {
if (targetPlatforms[target]) {
// grunt-node-webkit-builder doesn't understand `mac`,
// so map it to `osx` before adding it to the array
if (target === "mac") {
target = "osx";
}
targetPlatformsArray.push(target);
}
});
grunt.config.set("nodewebkit.options.platforms", targetPlatformsArray);
grunt.task.run([
"clean:some",
//"npm-install",
"jshint",
"processhtml",
"copy",
"revision",
"replace:revision",
"requirejs",
"styles",
"cssmin",
"cleanBuildDir",
"nodewebkit",
"komanda-package"
]);
});
grunt.registerTask("komanda-package", function(platforms) {
try {
fs.mkdirSync("package/");
} catch(e) {
}
var done = this.async();
var builds = {
"linux32": "komanda-linux-32-current.tar.gz",
"linux64": "komanda-linux-64-current.tar.gz",
"osx32": "komanda-osx32-current.tar.gz",
"osx64": "komanda-osx64-current.tar.gz",
"win32": "komanda-win32-current.tar.gz",
"win64": "komanda-win64-current.tar.gz"
}
var i
for (i in builds) {
var b = builds[i];
var compress = new targz().compress('build/Komanda/' + i, 'package/' + b, function(err) {
if (err) {
done(err)
}
done()
});
}
});
grunt.registerTask("build-all", function(platforms) {
grunt.task.run([
"clean:some",
//"npm-install",
"jshint",
"processhtml",
"copy",
"revision",
"replace:revision",
"requirejs",
"styles",
"cssmin",
"cleanBuildDir",
"nodewebkit"
]);
});
grunt.registerTask("run", function() {
var start = parseBuildPlatforms();
if (start.win) {
grunt.task.run("run:win");
} else if (start.mac) {
grunt.task.run("run:mac");
} else if (start.linux32) {
grunt.task.run("run:linux32");
} else if (start.linux64) {
grunt.task.run("run:linux64");
} else {
grunt.log.writeln("OS not supported.");
}
});
grunt.registerTask("run:mac", [
"default",
"shell:runnw"
]);
grunt.registerTask("run:win", [
"default",
"exec:win"
]);
grunt.registerTask("run:linux32", [
"default",
"copy",
"exec:linux32"
]);
grunt.registerTask("run:linux64", [
"default",
"copy",
"exec:linux64"
]);
};