-
Notifications
You must be signed in to change notification settings - Fork 11
/
Gruntfile.js
367 lines (308 loc) · 10.8 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
module.exports = function(grunt) {
'use strict';
var moment = require('moment'),
path = require('path');
var os = (function(){
var platform = process.platform;
if (/^win/.test(platform)) { return "windows"; }
if (/^darwin/.test(platform)) { return "mac"; }
if (/^linux/.test(platform)) { return "linux"; }
return null;
})();
//------------------------------------------------------------------------------
// ShellJS
//------------------------------------------------------------------------------
require('shelljs/global');
// shelljs/global makes the following imports:
// cwd, pwd, ls, find, cp, rm, mv, mkdir, test, cat,
// str.to, str.toEnd, sed, grep, which, echo,
// pushd, popd, dirs, ln, exit, env, exec, chmod,
// tempdir, error
var shellconfig = require('shelljs').config;
shellconfig.silent = true; // hide shell cmd output?
shellconfig.fatal = true; // stop if cmd failed?
//------------------------------------------------------------------------------
// Grunt Config
//------------------------------------------------------------------------------
var leinJarUrl = 'https://github.com/technomancy/leiningen/releases/download/2.5.0/leiningen-2.5.0-standalone.jar';
grunt.initConfig({
// LESS conversion
less: {
options: {
compress: true
},
default: {
files: {
'app/css/main.min.css': 'less/main.less'
}
}
},
// watch
watch: {
options: {
atBegin: true
},
less: {
files: "less/*.less",
tasks: "less:default"
}
},
curl: {
// download leiningen jar
'app/bin/lein.jar': leinJarUrl
},
'download-electron': {
version: '0.20.5',
outputDir: 'electron'
}
});
//------------------------------------------------------------------------------
// Third-party tasks
//------------------------------------------------------------------------------
grunt.loadNpmTasks('grunt-contrib-less');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-curl');
grunt.loadNpmTasks('grunt-download-electron');
if (os === "mac") {
grunt.loadNpmTasks('grunt-appdmg');
}
grunt.loadNpmTasks('winresourcer');
//------------------------------------------------------------------------------
// Setup Tasks
//------------------------------------------------------------------------------
grunt.registerTask('setup', [
'curl',
'download-electron',
'ensure-config-exists',
'build-lein-profile-tool'
]);
grunt.registerTask('ensure-config-exists', function() {
pushd("app");
if (!test("-f", "config.json")) {
grunt.log.writeln("Creating default config.json...");
cp("example.config.json", "config.json");
}
popd();
});
grunt.registerTask('build-lein-profile-tool', function() {
pushd("scripts");
if (!test('-d', "add-lein-profile")) {
grunt.log.writeln("Cloning...");
exec("git clone https://github.com/shaunlebron/add-lein-profile.git");
}
else {
pushd("add-lein-profile");
grunt.log.writeln("Updating...");
exec("git pull");
grunt.log.writeln("Cleaning...");
exec("lein clean");
grunt.log.writeln("Creating uberjar...");
exec("lein uberjar");
grunt.log.writeln("Copying to app/bin...");
cp("-f", "target/add-lein-profile-*-standalone.jar", "../../app/bin/add-lein-profile.jar");
popd();
}
popd();
});
//------------------------------------------------------------------------------
// Build/Launch Tasks
//------------------------------------------------------------------------------
grunt.registerTask('fresh-cljsbuild', function() {
grunt.log.writeln("\nCleaning and building ClojureScript files...");
exec("lein cljsbuild clean");
exec("lein cljsbuild once");
});
grunt.registerTask('fresh-build', ['less', 'fresh-cljsbuild']);
grunt.registerTask('launch', function() {
grunt.log.writeln("\nLaunching development version...");
var exe = {
windows: "atom.exe",
mac: "Atom.app/Contents/MacOS/Atom",
linux: "atom"
}[os];
exec(path.join("electron", exe) + " app");
});
//------------------------------------------------------------------------------
// Release
//------------------------------------------------------------------------------
grunt.registerTask('release', function() {
var build = getBuildMeta();
var paths = getReleasePaths(build);
prepRelease( build, paths);
copyAtomAndCuttleToRelease( build, paths);
setReleaseConfig( build, paths);
installNodeDepsToRelease( build, paths);
stampRelease( build, paths);
updateVersionInReadme( build, paths);
switch (os) {
case "mac": finalizeMacRelease( build, paths); break;
case "linux": finalizeLinuxRelease( build, paths); break;
case "windows": finalizeWindowsRelease( build, paths); break;
}
});
grunt.registerTask('fresh-release', ['fresh-build', 'release']);
//------------------------------------------------------------------------------
// Release - config
//------------------------------------------------------------------------------
var atomShell = {
windows: {
exeToRename: "atom.exe",
renamedExe: "Cuttle.exe",
resources: "resources",
installExt: "exe"
},
mac: {
exeToRename: "Atom.app",
renamedExe: "Cuttle.app",
plist: "Atom.app/Contents/Info.plist",
resources: "Atom.app/Contents/Resources",
installExt: "dmg"
},
linux: {
exeToRename: "atom",
renamedExe: "Cuttle",
resources: "resources"
}
}[os];
function getBuildMeta() {
grunt.log.writeln("Getting project metadata...");
var tokens = cat("project.clj").split(" ");
var build = {
name: tokens[1],
version: tokens[2].replace(/"/g, "").trim(),
date: moment().format("YYYY-MM-DD"),
commit: exec("git rev-parse HEAD", {silent:true}).output.trim()
};
build.releaseName = build.name + "-v" + build.version + "-" + os;
grunt.log.writeln("name: "+build.name.cyan);
grunt.log.writeln("version: "+build.version.cyan);
grunt.log.writeln("date: "+build.date.cyan);
grunt.log.writeln("commit: "+build.commit.cyan);
grunt.log.writeln("release: "+build.releaseName.cyan);
return build;
}
function getReleasePaths(build) {
var paths = {
atom: "electron",
builds: "builds",
devApp: "app",
rootPkg: "package.json"
};
paths.release = paths.builds + '/' + build.releaseName;
paths.resources = paths.release + '/' + atomShell.resources;
paths.install = paths.release + "." + atomShell.installExt;
paths.releaseApp = paths.resources + "/" + paths.devApp;
paths.devPkg = paths.devApp + "/package.json";
paths.releasePkg = paths.releaseApp + "/package.json";
paths.releaseCfg = paths.releaseApp + "/config.json";
paths.exeToRename = paths.release + "/" + atomShell.exeToRename;
paths.renamedExe = paths.release + "/" + atomShell.renamedExe;
return paths;
}
//------------------------------------------------------------------------------
// Release - subtasks
//------------------------------------------------------------------------------
function prepRelease(build, paths) {
grunt.log.writeln("\nCleaning previous release...");
mkdir('-p', paths.builds);
rm('-rf', paths.install, paths.release);
}
function copyAtomAndCuttleToRelease(build, paths) {
grunt.log.writeln("\nCopying Atom-Shell and Cuttle to release folder...");
grunt.log.writeln(paths.atom + " ==> " + paths.release.cyan);
grunt.log.writeln(paths.devApp + " ==> " + paths.resources.cyan);
cp('-r', paths.atom+"/", paths.release);
cp('-r', paths.devApp, paths.resources);
}
function setReleaseConfig(build, paths) {
grunt.log.writeln("\nRemoving config to force default release settings...");
rm('-f', paths.releaseCfg);
}
function installNodeDepsToRelease(build, paths) {
grunt.log.writeln("\nCopying node dependencies to release...");
cp('-f', paths.rootPkg, paths.releaseApp);
pushd(paths.releaseApp);
exec('npm install --no-optional --production');
popd();
cp('-f', paths.devPkg, paths.releaseApp);
}
function stampRelease(build, paths) {
grunt.log.writeln("\nStamping release with build metadata...");
var pkg = grunt.file.readJSON(paths.releasePkg);
pkg["version"] = build.version;
pkg["build-commit"] = build.commit;
pkg["build-date"] = build.date;
JSON.stringify(pkg, null, " ").to(paths.releasePkg);
}
function updateVersionInReadme(build, paths) {
grunt.log.writeln("\nUpdating version and download links in readme...");
sed('-i', /v\d+\.\d+/g, "v"+build.version, "README.md");
}
//------------------------------------------------------------------------------
// Release - finalization
//------------------------------------------------------------------------------
function finalizeMacRelease(build, paths) {
grunt.log.writeln("\nChanging atom-shell app icon and bundle name to Cuttle's...");
var plist = __dirname + "/" + paths.release + "/" + atomShell.plist;
exec("defaults write " + plist + " CFBundleIconFile app/img/cuttle-logo.icns");
exec("defaults write " + plist + " CFBundleDisplayName Cuttle");
exec("defaults write " + plist + " CFBundleName Cuttle");
exec("defaults write " + plist + " CFBundleIdentifier org.cuttle");
mv(paths.exeToRename, paths.renamedExe);
var app = paths.renamedExe;
grunt.log.writeln("\nCreating dmg image...");
grunt.config.set("appdmg", {
options: {
"title": "Cuttle",
"background": "scripts/dmg/background.png",
"icon-size": 80,
"contents": [
{ "x": 448, "y": 344, "type": "link", "path": "/Applications" },
{ "x": 192, "y": 344, "type": "file", "path": app }
]
},
target: {
dest: paths.install
}
});
grunt.task.run("appdmg");
}
function finalizeLinuxRelease(build, paths) {
mv(paths.exeToRename, paths.renamedExe);
}
function finalizeWindowsRelease(build, paths) {
grunt.log.writeln("\nChanging atom-shell app icon and bundle name to Cuttle's...");
mv(paths.exeToRename, paths.renamedExe);
var app = paths.renamedExe;
grunt.config.set("winresourcer", {
main: {
operation: "Update",
exeFile: app,
resourceType: "Icongroup",
resourceName: "1",
resourceFile: "app/img/cuttle-logo.ico"
}
});
grunt.task.run("winresourcer");
grunt.config.set("makensis", {
version: build.version,
releaseDir: paths.release,
outFile: paths.install
});
grunt.task.run("makensis");
}
grunt.registerTask('makensis', function() {
grunt.log.writeln("\nCreating installer...");
var config = grunt.config.get("makensis");
exec(["makensis",
"/DPRODUCT_VERSION=" + config.version,
"/DRELEASE_DIR=../" + config.releaseDir,
"/DOUTFILE=../" + config.outFile,
"scripts/build-windows-exe.nsi"].join(" "));
});
//------------------------------------------------------------------------------
// Default Task
//------------------------------------------------------------------------------
grunt.registerTask('default', ['watch']);
// end module.exports
};