forked from voidlabs/mosaico
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gruntfile.js
373 lines (342 loc) · 12.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
"use strict";
var path = require('path');
module.exports = function(grunt) {
require('load-grunt-tasks')(grunt);
grunt.loadTasks('tasks');
var pkg = grunt.file.readJSON("package.json");
grunt.initConfig({
pkg: pkg,
pkgVersion: "<%= pkg.version %>",
combineKOTemplates: {
main: {
src: "src/tmpl/*.tmpl.html",
dest: "build/templates.js"
}
},
jshint: {
all: [
'Gruntfile.js',
'src/**/*.js',
],
options: {
reporter: require('jshint-stylish'),
sub: true,
jshintrc: true,
browserify: true
}
},
less: {
options: {
sourceMap: true,
sourceMapRootpath: '../',
/* sourceMapFilename: 'build/mosaico.css.map' */
sourceMapFileInline: true
},
css: {
files: {
"build/mosaico.css": "src/css/app_standalone.less",
"build/mosaico-material.css": "src/css/app_standalone_material.less"
}
}
},
postcss: {
options: {
map: {
inline: false /* , prev: 'build/app.css.map' */
},
diff: false,
processors: [
require('autoprefixer')(),
require('csswring')()
]
},
dist: {
src: 'build/mosaico.css',
dest: 'dist/rs/mosaico.min.css'
},
material: {
src: 'build/mosaico-material.css',
dest: 'dist/rs/mosaico-material.min.css'
}
},
browserify: {
main: {
options: {
browserifyOptions: {
debug: true,
fullPaths: false,
standalone: 'Mosaico'
},
// transforms are declared in the package.json ("aliasify", "browserify-versionify" are executed because declared there).
// We only redeclare browserify-shim so to be able to pass the global argument to strip down depedencies.
// We used to do run uglifyify transform as part of browserify but this now breaks sourcemapping
// transform: [['browserify-shim', {global: true}], ['uglifyify', {global: true}]],
transform: [ ['browserify-shim', {global: true}] ],
cacheFile: 'build/main-incremental.bin',
banner: '/** \n'+
' * <%= pkg.description %> - v<%= pkg.version %> - <%= grunt.template.today("yyyy-mm-dd") %> \n'+
' * Licensed under the <%= pkg.license %> (<%= pkg.licenseurl %>)\n'+
' * \n'+
' * Copyright (c) <%= grunt.template.today("yyyy") %> <%= pkg.author %> \n'+
' */',
},
files: {
'build/mosaico.inlinesourcemap.js': ['./src/js/app.js', './build/templates.js']
}
}
},
// We use exorcise before uglify because uglify doesn't correctly handle inline sourcemaps.
exorcise: {
main: {
options: {
bundleDest: 'build/mosaico.js'
},
files: {
'build/mosaico.js.map': ['build/mosaico.inlinesourcemap.js'],
}
}
},
watch: {
// for each set of files we have to define the whole execution steps (recursion not supported)
css: {
files: ['src/css/*.less', 'src/**/*.css'],
tasks: ['less', 'postcss']
},
tmpl: {
files: ['src/tmpl/*.tmpl.html'],
tasks: ['combineKOTemplates', 'browserify', 'exorcise', 'uglify:min']
},
browserify: {
files: ['src/js/**/*.js', 'build/templates.js'],
tasks: ['newer:jshint', 'browserify', 'exorcise', 'uglify:min']
},
htmls: {
files: ['src/html/*.html'],
tasks: ['copy:htmls']
},
web: {
options: {
livereload: true
},
files: ['dist/*.html', 'dist/**/*.js', 'dist/**/*.css'],
},
},
express: {
dev: {
options: {
script: 'backend/main.js',
background: true,
port: 9006,
}
}
},
googlefonts: {
noto: {
options: {
fontPath: './dist/rs/notoregular/',
httpPath: './notoregular/',
cssFile: './build/notoregular.css',
formats: { eot: true, woff: true, svg: false, ttf: true, woff2: false },
fonts: [
{
family: 'Noto Sans',
styles: [ 400 ],
subsets: [ 'latin' ]
}
]
}
}
},
copy: {
res: {
expand: true,
cwd: 'res',
src: '**',
dest: 'dist/rs/'
},
root: {
src: 'favicon.ico',
dest: 'dist/'
},
htmls: {
expand: true,
cwd: 'src/html',
src: '*.html',
dest: 'dist/',
options: {
process: function (content, srcpath) {
return content.replace(/__VERSION__/g, pkg.version);
},
},
},
fontawesome: {
expand: true,
cwd: 'node_modules/font-awesome/fonts',
src: 'fontawesome-webfont.*',
dest: 'dist/rs/fontawesome/'
},
},
cssmin: {
deps: {
files: {
'dist/rs/<%= pkg.name %>-libs-and-tinymce.min.css': [
/* 'node_modules/jquery-ui-package/jquery-ui.css', */
'build/notoregular.css',
/*
'res/vendor/skins/gray-flat/skin.min.css',
'res/vendor/skins/gray-flat/content.inline.min.css'
*/
]
}
}
},
uglify: {
min: {
options: {
sourceMap: {
includeSources: true
},
sourceMapIn: 'build/mosaico.js.map',
},
files: {
'dist/rs/mosaico.min.js': [ 'build/mosaico.js' ]
}
},
deps: {
options: {
comments: 'some',
sourceMap: {
includeSources: true
},
banner: '/*! \n'+
' * Bundle package for the following libraries:\n'+
' * jQuery | (c) JS Foundation and other contributors | jquery.org/license\n'+
' * jQuery Migrate v3.0.1 | (c) jQuery Foundation and other contributors | jquery.org/license\n'+
' * Knockout | (c) The Knockout.js team | License: MIT (http://www.opensource.org/licenses/mit-license.php)\n'+
' * jQuery UI | Copyright 2015 jQuery Foundation and other contributors; Licensed MIT\n'+
' * jQuery UI Touch Punch | Copyright 2011-2014, Dave Furfero | Dual licensed under the MIT or GPL Version 2 licenses.\n'+
' * jQuery File Upload Plugin + dependencies | Copyright 2010, Sebastian Tschan | Licensed under the MIT license: https://opensource.org/licenses/MIT\n'+
' * knockout-jqueryui | Copyright (c) 2016 Vas Gabor <gvas.munka@gmail.com> Licensed MIT\n'+
' * TinyMCE + Plugins | Copyright (c) 1999-2017 Ephox Corp. | Released under LGPL License. http://www.tinymce.com/license\n'+
' */'
},
/* This is named "*and-tinymce.min.js" by purpose otherwise Tinymce on IE11 is unable to find its own skin */
files: {
'dist/rs/<%= pkg.name %>-libs-and-tinymce.min.js': [
'node_modules/jquery/dist/jquery.js',
// NOTE: use minimized version because non-min uses console to write migration warnings
'node_modules/jquery-migrate/dist/jquery-migrate.min.js',
'node_modules/knockout/build/output/knockout-latest.js',
'node_modules/jquery-ui-package/jquery-ui.js',
'node_modules/jquery-ui-touch-punch/jquery.ui.touch-punch.js',
'node_modules/default-passive-events/dist/index.js',
// NOTE: include these 2 BEFORE the fileupload libs
// using npm5 we can get sub-dependencies from nested paths, but npm3 does flatten them, so let's depend on them explicitly.
// 'node_modules/blueimp-file-upload/node_modules/blueimp-canvas-to-blob/js/canvas-to-blob.js',
// 'node_modules/blueimp-file-upload/node_modules/blueimp-load-image/js/load-image.all.min.js',
'node_modules/blueimp-canvas-to-blob/js/canvas-to-blob.js',
'node_modules/blueimp-load-image/js/load-image.all.min.js',
// 'node_modules/blueimp-file-upload/js/jquery.iframe-transport.js',
'node_modules/blueimp-file-upload/js/jquery.fileupload.js',
'node_modules/blueimp-file-upload/js/jquery.fileupload-process.js',
'node_modules/blueimp-file-upload/js/jquery.fileupload-image.js',
'node_modules/blueimp-file-upload/js/jquery.fileupload-validate.js',
'node_modules/knockout-jqueryui/dist/knockout-jqueryui.js',
'node_modules/tinymce/tinymce.js',
'node_modules/tinymce/themes/modern/theme.js',
'node_modules/tinymce/plugins/link/plugin.js',
'node_modules/tinymce/plugins/hr/plugin.js',
'node_modules/tinymce/plugins/paste/plugin.js',
'node_modules/tinymce/plugins/lists/plugin.js',
'node_modules/tinymce/plugins/textcolor/plugin.js',
'node_modules/tinymce/plugins/code/plugin.js',
],
}
}
},
jasmine_node: {
main: {
options: {
coverage: {
reportDir: 'build/coverage',
},
forceExit: true,
captureExceptions: true,
jasmine: {
reporters: {
spec: {},
junitXml: {
report: false,
savePath: './build/jasmine/',
useDotNotation: true,
consolidate: true
}
}
}
},
src: ['src/**/*.js']
}
},
clean: {
build: ['build/'],
dist: ['dist/']
},
check_licenses: {
main: {
exclude: 'MIT, ISC, BSD, Apache-2.0, BSD-3-Clause, BSD-2-Clause, CC0-1.0, Unlicense, Public Domain',
whitelist: {
/* SELF */
'mosaico': 'GPL-3.0', // SELF
/* MIT with bad license declarations */
'expand-template': 'MIT', // Say "WTFPL" but on github project says "All code, unless stated otherwise, is dual-licensed under WTFPL and MIT."
'font-awesome': 'MIT', // (OFL-1.1 AND MIT)
'jshint': 'MIT', // (MIT AND JSON)
'pako': 'MIT', // (MIT AND Zlib)
'xmldom': 'MIT', // MIT or LGPL (https://github.com/jindw/xmldom/blob/master/LICENSE)
'spdx-expression-parse': 'MIT', // (MIT AND CC-BY-3.0)
'spdx-expression-validate': 'MIT', // (MIT AND CC-BY-3.0)
/* Optional runtime dependency */
'tinymce': 'LGPL-2.1', // LGPL-2.1, optional runtime dependency
/* CC-BY licensed */
'caniuse-lite': 'CC-BY-4.0', // Not bundled, used at build time
'spdx-exceptions': 'CC-BY-3.0', // Not bundled, used at build time
'spdx-ranges': 'CC-BY-3.0', // Not bundled, used at build time
'node-releases': 'CC-BY-4.0', // Not bundled, used at build time
}
}
},
compress: {
dist: {
options: {
archive: 'release/<%= pkg.name %>-<%= pkg.version %>-dist.zip'
},
files: [
{ expand: true, cwd: 'dist', src: ['**'], dest: '/' },
{ src: ['templates/versafix-1/**', 'README.md', 'NOTICE.txt', 'LICENSE'], dest: '/' }
]
}
},
release: {
options: {
additionalFiles: ['package-lock.json'],
tagName: 'v<%= version %>',
// the release 0.14.0 plugin is buggy and they are all done BEFORE the tagging, so we stick to 0.13.1 until a new proper release is done.
beforeRelease: ['clean', 'build'],
afterRelease: ['compress'],
npm: false,
github: {
repo: 'voidlabs/mosaico',
accessTokenVar: 'GITHUB_ACCESS_TOKEN',
}
},
},
});
grunt.registerTask('js', ['combineKOTemplates', 'browserify', 'exorcise', 'uglify:min']);
grunt.registerTask('css', ['less', 'postcss']);
grunt.registerTask('server', ['express', 'watch', 'keepalive']);
grunt.registerTask('deps', ['copy', 'uglify:deps', 'cssmin']);
grunt.registerTask('build', ['googlefonts', 'deps', 'jshint', 'js', 'css']);
grunt.registerTask('default', ['build', 'server']);
grunt.registerTask('test', ['jasmine_node']);
grunt.registerTask('dist', ['check_licenses', 'build', 'test', 'compress']);
};