forked from piskelapp/piskel
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Gruntfile.js
376 lines (339 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
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
module.exports = function(grunt) {
// Update this variable if you don't want or can't serve on localhost
var hostname = 'localhost';
var PORT = {
PROD : 9001,
DEV : 9901,
TEST : 9991
};
// create a version based on the build timestamp
var { format } = require('date-fns');
var version = `-${format(new Date(), "yyyy-MM-dd-HH-mm")}`;
var releaseVersion = require('./package.json').version;
/**
* Helper to prefix all strings in provided array with the provided path
*/
var prefixPaths = function (paths, prefix) {
return paths.map(function (path) {
return prefix + path;
});
};
// get the list of scripts paths to include
var scriptPaths = require('./src/piskel-script-list.js').scripts;
var piskelScripts = prefixPaths(scriptPaths, "src/").filter(function (path) {
return path.indexOf('devtools') === -1;
});
// get the list of styles paths to include
var stylePaths = require('./src/piskel-style-list.js').styles;
var piskelStyles = prefixPaths(stylePaths, "src/");
// Casper JS tests
var casperjsOptions = [
'--baseUrl=http://' + hostname + ':' + PORT.TEST,
'--mode=?debug',
'--verbose=false',
'--includes=test/casperjs/integration/include.js',
'--log-level=info',
'--print-command=false',
'--print-file-paths=true',
];
var integrationTestPaths = require('./test/casperjs/integration/IntegrationSuite.js').tests;
var integrationTests = prefixPaths(integrationTestPaths, "test/casperjs/integration/");
var getConnectConfig = function (base, port, host, open, livereload = false) {
return {
options: {
port: port,
hostname : host,
base: base,
open: open,
livereload: livereload,
}
};
};
// load all grunt tasks
require('load-grunt-tasks')(grunt);
grunt.initConfig({
clean: {
all: ['dest', 'src/img/icons.png', 'src/css/icons.css'],
prod: ['dest/prod', 'dest/tmp'],
desktop: ['dest/desktop', 'dest/tmp'],
dev: ['dest/dev', 'dest/tmp']
},
/**
* STYLE CHECKS
*/
leadingIndent : {
options: {
indentation : "spaces"
},
css : ['src/css/**/*.css']
},
eslint: {
files: [
// Includes
'src/js/**/*.js',
// Exludes
// TODO: remove this (for now we still get warnings from the lib folder)
'!src/js/**/lib/**/*.js'
],
options: {
fix: grunt.option('fix') // this will get params from the flags
}
},
/**
* SERVERS, BROWSER LAUNCHERS
*/
connect: {
prod: getConnectConfig('dest/prod', PORT.PROD, hostname, true),
test: getConnectConfig(['dest/dev', 'test'], PORT.TEST, hostname, false),
dev: getConnectConfig(['dest/dev', 'test'], PORT.DEV, hostname, 'http://' + hostname + ':' + PORT.DEV + '/?debug', true)
},
watch: {
prod: {
files: ['src/**/*.*'],
tasks: ['build'],
options: {
spawn: false
}
},
dev: {
files: ['src/**/*.*'],
tasks: ['build-dev'],
options: {
spawn: false,
host: hostname,
livereload: true,
}
}
},
/**
* BUILD STEPS
*/
sprite:{
all : {
src: 'src/img/icons/**/*.png',
retinaSrcFilter: 'src/img/icons/**/*@2x.png',
dest: 'src/img/icons.png',
retinaDest: 'src/img/[email protected]',
destCss: 'src/css/icons.css'
}
},
concat : {
js : {
options : {
separator : ';'
},
src : piskelScripts,
dest : 'dest/prod/js/piskel-packaged' + version + '.js'
},
css : {
src : piskelStyles,
dest : 'dest/tmp/css/piskel-style-packaged' + version + '.css'
}
},
uglify : {
options : {
mangle : true
},
js : {
files : {
'dest/tmp/js/piskel-packaged-min.js' : ['dest/prod/js/piskel-packaged' + version + '.js']
}
}
},
includereplace: {
all: {
src: 'src/index.html',
dest: 'dest/tmp/index.html',
options : {
globals : {
'version' : version,
'releaseVersion' : releaseVersion
}
}
}
},
replace: {
// main-partial.html is used when embedded in piskelapp.com
mainPartial: {
options: {
patterns: [{
match: /^(.|[\r\n])*<!--body-main-start-->/,
replacement: "{% raw %}",
description : "Remove everything before body-main-start comment"
},{
match: /<!--body-main-end-->(.|[\r\n])*$/,
replacement: "{% endraw %}",
description : "Remove everything after body-main-end comment"
},{
match: /([\r\n]) /g,
replacement: "$1",
description : "Decrease indentation by one"
}
]
},
files: [
// src/index.html should already have been moved by the includereplace task
{src: ['dest/tmp/index.html'], dest: 'dest/prod/piskelapp-partials/main-partial.html'}
]
},
css: {
options: {
patterns: [{
match: /var\(--highlight-color\)/g,
replacement: "gold",
}]
},
files: [{
src: ['dest/tmp/css/piskel-style-packaged' + version + '.css'],
dest: 'dest/prod/css/piskel-style-packaged' + version + '.css'
}]
}
},
copy: {
prod: {
files: [
// dest/js/piskel-packaged-min.js should have been created by the uglify task
{src: ['dest/tmp/js/piskel-packaged-min.js'], dest: 'dest/prod/js/piskel-packaged-min' + version + '.js'},
{src: ['dest/tmp/index.html'], dest: 'dest/prod/index.html'},
{src: ['src/logo.png'], dest: 'dest/prod/logo.png'},
{src: ['src/js/lib/gif/gif.ie.worker.js'], dest: 'dest/prod/js/lib/gif/gif.ie.worker.js'},
{expand: true, src: ['img/**'], cwd: 'src/', dest: 'dest/prod/', filter: 'isFile'},
{expand: true, src: ['css/fonts/**'], cwd: 'src/', dest: 'dest/prod/', filter: 'isFile'}
]
},
dev: {
files: [
// in dev copy everything to dest/dev
{src: ['dest/tmp/index.html'], dest: 'dest/dev/index.html'},
{src: ['src/piskel-script-list.js'], dest: 'dest/dev/piskel-script-list.js'},
{src: ['src/piskel-style-list.js'], dest: 'dest/dev/piskel-style-list.js'},
{expand: true, src: ['js/**'], cwd: 'src/', dest: 'dest/dev/', filter: 'isFile'},
{expand: true, src: ['css/**'], cwd: 'src/', dest: 'dest/dev/', filter: 'isFile'},
{expand: true, src: ['img/**'], cwd: 'src/', dest: 'dest/dev/', filter: 'isFile'},
]
}
},
/**
* TESTING
*/
karma: {
unit: {
configFile: 'karma.conf.js'
}
},
casperjs : {
drawing : {
files : {
src: ['test/casperjs/DrawingTest.js']
},
options : {
casperjsOptions: casperjsOptions
}
},
integration : {
files : {
src: integrationTests
},
options : {
casperjsOptions: casperjsOptions
}
}
},
/**
* DESKTOP BUILDS
*/
nwjs: {
win_x64 : {
options: {
mode: "build",
flavor: "normal",
platform: "win",
arch: "x64",
cacheDir: './node_modules/nw',
outDir: './dest/desktop/',
managedManifest: './package.nw.json',
},
src: ['./dest/prod/**/*', "./package.json", "!./dest/desktop/"]
},
linux_x64 : {
options: {
mode: "build",
flavor: "sdk",
platform: "linux",
arch: "x64",
cacheDir: './node_modules/nw',
outDir: './dest/desktop/',
managedManifest: './package.nw.json',
},
src: ['./dest/prod/**/*', "./package.json", "!./dest/desktop/"]
},
osx_x64 : {
options: {
mode: "build",
flavor: "normal",
platform: "osx",
arch: "x64",
cacheDir: './node_modules/nw',
outDir: './dest/desktop/',
managedManifest: './package.nw.json',
app: {
icon: './piskel.icns'
}
},
src: ['./dest/prod/**/*', "./package.json", "!./dest/desktop/"]
},
osx_arm : {
options: {
mode: "build",
flavor: "normal",
platform: "osx",
arch: "arm64",
cacheDir: './node_modules/nw',
outDir: './dest/desktop/',
managedManifest: './package.nw.json',
app: {
icon: './piskel.icns'
}
},
src: ['./dest/prod/**/*', "./package.json", "!./dest/desktop/"]
}
}
});
// TEST TASKS
// Run linting
grunt.registerTask('lint', ['eslint', 'leadingIndent:css']);
// Run unit-tests
grunt.registerTask('unit-test', ['karma']);
// Run integration tests
grunt.registerTask('integration-test', ['build-dev', 'connect:test', 'casperjs:integration']);
// Run drawing tests
grunt.registerTask('casper-drawing-test', ['build-dev', 'connect:test', 'casperjs:drawing']);
// Run drawing tests and integration tests
grunt.registerTask('casper-integration-test', ['build-dev', 'connect:test', 'casperjs:integration']);
// Run the tests, even if the linting fails
grunt.registerTask('test-nolint', ['unit-test', 'build-dev', 'connect:test', 'casperjs:drawing', 'casperjs:integration']);
// Used by optional precommit hook
grunt.registerTask('precommit', ['test']);
// BUILD TASKS
grunt.registerTask('build-index.html', ['includereplace']);
grunt.registerTask('merge-statics', ['concat:js', 'concat:css', 'uglify']);
grunt.registerTask('build', ['clean:prod', 'sprite', 'merge-statics', 'build-index.html', 'replace:mainPartial', 'replace:css', 'copy:prod']);
grunt.registerTask('build-dev', ['clean:dev', 'sprite', 'build-index.html', 'copy:dev']);
grunt.registerTask('desktop', ['clean:desktop', 'default', 'nwjs:macos', 'nwjs:windows', 'nwjs:linux']);
grunt.registerTask('desktop-win-x64', ['clean:desktop', 'default', 'nwjs:win_x64']);
grunt.registerTask('desktop-linux-x64', ['clean:desktop', 'default', 'nwjs:linux_x64']);
grunt.registerTask('desktop-osx-x64', ['clean:desktop', 'default', 'nwjs:osx_x64']);
grunt.registerTask('desktop-osx-arm', ['clean:desktop', 'default', 'nwjs:osx_arm']);
// SERVER TASKS
// Start webserver and watch for changes
grunt.registerTask('serve', ['build', 'connect:prod', 'watch:prod']);
// Start webserver on src folder, in debug mode
grunt.registerTask('play', ['build-dev', 'connect:dev', 'watch:dev']);
// ALIASES, kept for backward compatibility
grunt.registerTask('serve-debug', ['play']);
grunt.registerTask('serve-dev', ['play']);
grunt.registerTask('test-travis', ['test']);
grunt.registerTask('test-local', ['test']);
// Default task
grunt.registerTask('default', ['build']);
};