forked from wymeditor/wymeditor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGruntfile.js
595 lines (582 loc) · 20.4 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
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
/*jslint node: true, es3: false, maxlen: 88 */
'use strict';
var mountFolder = function (connect, dir) {
return connect.static(require('path').resolve(dir));
};
module.exports = function (grunt) {
// show elapsed time at the end
require('time-grunt')(grunt);
var humanName = 'WYMeditor',
projectPage = "https://github.com/wymeditor/wymeditor/",
releaseArchive = projectPage +
'releases/download/v<%= pkg.version %>/<%= pkg.name %>' +
'-<%= pkg.version %>' + '.tag.gz',
sourceArchive = projectPage + 'archive/v<%= pkg.version %>.zip',
// Oldest supported version of jQuery is used by default
jqueryVersion = grunt.option("jquery") || "1.4.4",
yeomanConfig = {
app: 'src',
dist: 'dist'
},
unitTestPort = 9001,
editorFiles = ['{.tmp,<%= yeoman.app %>}/wymeditor/{,*/}*.js'],
stylesFiles = ['.tmp/styles/{,*/}*.css'],
examplesFiles = ['{.tmp,<%= yeoman.app %>}/examples/{,*/}*.{js,html}'],
readmePath = 'README.rst',
jekyllDir = '<%= yeoman.app %>/jekyll',
jekyllFiles = [jekyllDir + '/**'],
jekyllDevServeDir = '<%= yeoman.app %>/website',
jekyllDevServeFiles = [jekyllDevServeDir + '/*'];
grunt.initConfig({
pkg: grunt.file.readJSON("package.json"),
yeoman: yeomanConfig,
meta: {
banner: "/*!\n" +
"WYMeditor - v<%= pkg.version %>\n\n" +
"Home page: <%= pkg.homepage %>\n\n" +
"Copyright (c) <%= grunt.template.today('yyyy') %> " +
"<%= pkg.author.name %>;\n" +
"Licensed <%= _.pluck(pkg.licenses, 'type').join(', ') %>\n" +
"*/\n\n"
},
// Some targets run concurrently because watch is blocking and we
// have different watches.
watch: {
options: {
// Don't spawn a child process. Virtualbox's NFS share is
// slow enough already.
spawn: false
},
// Rebuilds the website on changes
jekyll: {
files: [].concat(
jekyllFiles,
[readmePath]
),
tasks: [
'shell:convertReadmeToHomePage',
'jekyll:dev'
]
},
// Convenience. LiveReload must be only in one concurrent
// watch because you can't have more than one at the same time,
// running.
livereload: {
options: {
livereload: true
},
files: [].concat(
editorFiles,
stylesFiles,
examplesFiles,
jekyllDevServeFiles
)
},
dist: {
options: {
livereload: true
},
files: [].concat(
stylesFiles,
examplesFiles,
editorFiles,
jekyllFiles,
[readmePath]
),
tasks: ['build']
}
},
// This runs the watches concurrently.
concurrent: {
watchDev: {
tasks: [
'watch:jekyll',
'watch:livereload'
],
options: {
// Limit by default is set according to CPU specs.
limit: 2,
logConcurrentOutput: true
}
}
},
connect: {
options: {
port: 9000,
// change this to '0.0.0.0' to access the server from outside
hostname: '0.0.0.0'
},
dev: {
options: {
middleware: function (connect) {
return [
mountFolder(connect, '.tmp'),
mountFolder(connect, yeomanConfig.app)
];
}
}
},
test: {
options: {
port: unitTestPort,
middleware: function (connect) {
return [
mountFolder(connect, '.tmp'),
mountFolder(connect, 'test'),
mountFolder(connect, yeomanConfig.app)
];
}
}
},
dist: {
options: {
middleware: function (connect) {
return [
mountFolder(connect, yeomanConfig.dist)
];
}
}
}
},
clean: {
dist: {
files: [{
dot: true,
src: [
'.tmp',
'<%= yeoman.dist %>/*',
'!<%= yeoman.dist %>/.git*'
]
}]
},
server: '.tmp',
jekyll: jekyllDevServeFiles,
lib: '<%= yeoman.app %>/lib/**/*'
},
jshint: {
options: {
jshintrc: '.jshintrc'
},
all: [
'Gruntfile.js',
'<%= yeoman.app %>/wymeditor/{,*/}*.js',
'<%= yeoman.app %>/wymeditor/plugins/{,*/}*.js',
'<%= yeoman.app %>/wymeditor/skins/{,*/}*.js',
'<%= yeoman.app %>/test/unit/{,*/}*.js',
'<%= yeoman.app %>/jekyll/website-media/javascripts/main.js'
]
},
qunit: {
all: {
options: {
timeout: 25000,
urls: [
[""
, "http://localhost:"
, unitTestPort
, "/test/unit/index.html"
, "?inPhantomjs=true&jquery="
, jqueryVersion
].join("")
]
}
}
},
browserify: {
// This task Browserifies an NPM CommonJS module that will be
// bundled in the build.
options: {
browserifyOptions: {
debug: true
}
},
objectHistory: {
// This file is the entry point for the browserification of
// this module. It assigns the module's CommonJS export to a
// browser window global.
src: ['<%= yeoman.app %>/wymeditor/editor/' +
'object-history-browserify.js'],
dest: '<%= yeoman.app %>/lib/object-history.js'
}
},
useminPrepare: {
options: {
dest: '<%= yeoman.dist %>'
},
html: [
'<%= yeoman.app %>/wymeditor/iframe/{,*/}*.html'
]
},
usemin: {
options: {
dirs: ['<%= yeoman.dist %>']
},
html: [
'<%= yeoman.dist %>/examples/{,*/}*.html',
'<%= yeoman.dist %>/wymeditor/iframe/{,*/}*.html'
],
css: [
'<%= yeoman.dist %>/examples/{,*/}*.css',
'<%= yeoman.dist %>/wymeditor/plugins/{,*/}*.css',
'<%= yeoman.dist %>/wymeditor/skins/{,*/}*.css'
]
},
replace: {
dist: {
options: {
variables: {
"VERSION": "<%= pkg.version %>"
}
},
files: [
{
expand: true,
cwd: '<%= yeoman.dist %>/wymeditor',
src: [
'*.js'
],
dest: '<%= yeoman.dist %>/wymeditor'
}
]
}
},
concat: {
dist: {
src: [
"<%= yeoman.app %>/lib/jquery.browser.js",
"<%= yeoman.app %>/wymeditor/core.js",
"<%= yeoman.app %>/wymeditor/editor/base.js",
"<%= yeoman.app %>/wymeditor/editor/" +
"document-structure-manager.js",
"<%= yeoman.app %>/wymeditor/editor/gecko.js",
"<%= yeoman.app %>/wymeditor/editor/webkit.js",
"<%= yeoman.app %>/wymeditor/editor/trident-pre-7.js",
"<%= yeoman.app %>/wymeditor/editor/trident-7.js",
"<%= yeoman.app %>/lib/object-history.js",
"<%= yeoman.app %>/wymeditor/editor/undo-redo.js",
"<%= yeoman.app %>/wymeditor/parser/*.js",
// TODO: For custom builds, will need to change this.
"<%= yeoman.app %>/wymeditor/lang/*.js",
"<%= yeoman.app %>/wymeditor/rangy/rangy-core.js",
"<%= yeoman.app %>/wymeditor/rangy/" +
"rangy-selectionsaverestore.js",
// TODO: For custom builds, will need to change this.
'<%= yeoman.app %>/wymeditor/skins/{,*/}skin.js'
],
dest: "<%= yeoman.dist %>/wymeditor/jquery.wymeditor.js"
}
},
uglify: {
options: {
banner: "<%= meta.banner %>"
},
all: {
files: {
"<%= yeoman.dist %>/wymeditor/jquery.wymeditor.min.js": [
"<%= yeoman.dist %>/wymeditor/jquery.wymeditor.js"
]
}
}
},
// All of the files not handled by other tasks that need to make it to
// the distribution
copy: {
dist: {
files: [
// Misc project files
{
expand: true,
dot: true,
cwd: '<%= yeoman.app %>/..',
dest: '<%= yeoman.dist %>',
src: [
"README.md",
"CHANGELOG.md",
"AUTHORS",
"MIT-license.txt",
"GPL-license.txt",
"package.json"
]
},
// Examples
{
expand: true,
dot: true,
cwd: '<%= yeoman.app %>',
dest: '<%= yeoman.dist %>',
src: [
"examples/{,*/}*.{html,js,css,png,jpg,jpeg,gif}"
]
},
// Plugins
{
expand: true,
dot: true,
cwd: '<%= yeoman.app %>/wymeditor',
dest: '<%= yeoman.dist %>/wymeditor',
src: [
"plugins/{,*/}*.{js,css,png,jpg,jpeg,gif}"
]
},
// Iframes
{
expand: true,
dot: true,
cwd: '<%= yeoman.app %>/wymeditor',
dest: '<%= yeoman.dist %>/wymeditor',
src: [
"iframe/{,*/}*.{html,js,css,png,jpg,jpeg,gif,eot,ttf,woff}"
]
},
// Non-Javascript skin components
// The javascript is included in jquery.wymeditor.js
{
expand: true,
dot: true,
cwd: '<%= yeoman.app %>/wymeditor',
dest: '<%= yeoman.dist %>/wymeditor',
src: [
"skins/{,*/}*.{css,png,jpg,jpeg,gif}",
"skins/{,*/}images/{,*/}*.{png,jpg,jpeg,gif}"
]
},
// Already-built Sphinx documentation
{
expand: true,
dot: true,
cwd: '<%= yeoman.app %>/docs/.build/html',
dest: '<%= yeoman.dist %>/docs',
src: [
"**",
]
}
]
},
styles: {
expand: true,
dot: true,
cwd: '<%= yeoman.app %>/styles',
dest: '.tmp/styles/',
src: '{,*/}*.css'
}
},
compress: {
tgz: {
options: {
mode: "tgz",
archive: "<%= yeoman.dist %>/wymeditor-<%= pkg.version %>" +
".tar.gz"
},
expand: true,
cwd: "<%= yeoman.dist %>",
src: ["./**"]
}
},
jekyll: {
options: {
src: jekyllDir,
raw: 'name: ' + humanName + '\n' +
'projectPage: ' + projectPage + '\n' +
'releaseArchive: ' + releaseArchive + '\n' +
'sourceArchive: ' + sourceArchive + '\n'
},
dev: {
options: {
dest: jekyllDevServeDir
}
},
dist: {
options: {
dest: '<%= yeoman.dist %>/website'
}
}
},
// This task installs the Bower components, as configured in
// `bower.json`.
'bower-install-simple': {
options: {
color: true,
cwd: process.cwd(),
forceLatest: false,
production: false,
interactive: true,
directory: "src/bower_components"
}
},
'bower-linker': {
// This task links the libraries that are required by WYMeditor
// for use in the development environment. It links the specific
// files that are required, from the Bower installation directory,
// into the development environment.
dev: {
options: {
copy: false,
cwd: "<%= yeoman.app %>",
force: false,
map: {
'require.js': '/',
'jquery.js': '/',
'jquery.browser.js': '/',
'es5-shim.js': '/',
// Originates from js-beautify
'beautify-html.js': '/',
// following two also originate from js-beautify and we
// don't use them so tuck them away nicely.
'beautify.js': '/redundant/',
'beautify-css.js': '/redundant/'
},
offline: true,
root: "<%= yeoman.app %>/lib",
vendor: false
}
},
'dist-examples': {
options: {
copy: true,
cwd: "<%= yeoman.app %>",
force: false,
map: {
'jquery.js': '/jquery/',
'jquery.browser.js': '/',
'require.js': '/redundant/',
'beautify-html.js': '/redundant/',
'beautify.js': '/redundant/',
'beautify-css.js': '/redundant/'
},
offline: true,
root: "<%= yeoman.dist %>/examples/vendor",
vendor: false
}
}
},
shell: {
convertReadmeToHomePage: {
command: [
'rst2html',
'--template ' + jekyllDir + '/_index.template',
'--no-doc-title',
readmePath,
jekyllDir + '/index.html'
].join(' ')
},
docsMakeHtml: {
options: {
stdout: true,
stderr: true,
stdin: false,
failOnError: true,
execOptions: {
cwd: 'docs'
}
},
command: 'make html'
},
docsOpenHtml: {
options: {
stdout: true,
stderr: true,
stdin: false,
failOnError: true
},
command: 'xdg-open docs/.build/html/index.html'
},
// Unlike the ES5 shims, the shams file is not linked by default,
// by the bower-linker task, because it is not in the `main`
// of its Bower package. So we link it manually, with this `shell`
// task.
linkES5Sham: {
options: {
stdout: true,
stderr: true,
stdin: false,
failOnError: true
},
command: 'ln -sf ../bower_components/es5-shim/es5-sham.js ' +
'src/lib/es5-sham.js'
}
}
});
grunt.registerTask('server', function (target) {
if (target === 'dist') {
return grunt.task.run([
'build',
'connect:dist',
'watch:dist'
]);
}
grunt.task.run([
'bower',
'browserify:objectHistory',
'clean:server',
'jekyllDev',
'connect:dev',
'concurrent:watchDev'
]);
});
grunt.registerTask('test', [
'bower',
'browserify:objectHistory',
'clean:server',
'connect:test',
'qunit'
]);
grunt.registerTask('build', [
'clean:dist',
'useminPrepare',
'bower-install-simple',
'bower-linker:dist-examples',
'browserify:objectHistory',
'concat',
'uglify',
'copy:dist',
'usemin',
'replace',
'compress',
'jekyllDist'
]);
grunt.registerTask('default', [
'jshint',
'test',
'build'
]);
// This task combines the installation of Bower components and the copying
// of the library files for use in the development environment.
grunt.registerTask('bower', [
'bower-install-simple',
'bower-linker:dev',
'shell:linkES5Sham'
]);
grunt.registerTask('jekyllDev', [
'shell:convertReadmeToHomePage',
'jekyll:dev'
]);
grunt.registerTask('jekyllDist', [
'shell:convertReadmeToHomePage',
'jekyll:dist'
]);
grunt.registerTask('docsMakeHtml', ['shell:docsMakeHtml']);
grunt.registerTask('docsMake', ['docsMakeHtml']);
grunt.registerTask('docsOpenHtml', ['shell:docsOpenHtml']);
grunt.registerTask('docsOpen', ['docsOpenHtml']);
grunt.registerTask('docs', [
'docsMake',
'docsOpen'
]);
grunt.loadNpmTasks("grunt-contrib-uglify");
grunt.loadNpmTasks("grunt-contrib-copy");
grunt.loadNpmTasks("grunt-contrib-concat");
grunt.loadNpmTasks("grunt-contrib-compress");
grunt.loadNpmTasks("grunt-contrib-connect");
grunt.loadNpmTasks("grunt-contrib-jshint");
grunt.loadNpmTasks("grunt-contrib-watch");
grunt.loadNpmTasks("grunt-contrib-clean");
grunt.loadNpmTasks("grunt-contrib-qunit");
grunt.loadNpmTasks("grunt-replace");
grunt.loadNpmTasks("grunt-usemin");
grunt.loadNpmTasks("grunt-bower-install-simple");
grunt.loadNpmTasks("grunt-bower-linker");
grunt.loadNpmTasks("grunt-jekyll");
grunt.loadNpmTasks("grunt-concurrent");
grunt.loadNpmTasks("grunt-shell");
grunt.loadNpmTasks("grunt-browserify");
};