-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathGruntfile.js
executable file
·1344 lines (1240 loc) · 63.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
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
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*!
+---------------------------------------------------------------------+
| |
| ____ _ _ _ _ |
| | _ \ ___ __ _ __| | | __ (_) |_ |
| | |_) / _ \/ _` |/ _` | |/ / | | __| |
| | _ < __/ (_| | (_| | < _| | |_ |
| |_| \_\___|\__,_|\__,_|_|\_(_)_|\__| |
| |
| URL: |
| VERSION: 0.0.1 |
| GITHUB: |
| AUTHOR: Jason Darwin (@nzmebooks) |
| LICENSE: MIT |
| http://opensource.org/licenses/MIT |
| |
| To create a production readkit (optimised js): |
| > grunt |
| |
| To create a development readkit (source js): |
| > grunt dev |
| |
+---------------------------------------------------------------------+
*/
/*global module:false*/
module.exports = function(grunt) {
var globals = {
identifier: [],
identifier_client_scripts_to_build: [],
identifier_mixin_client_config: [],
path: [],
oebps_path_src: []
};
function processManifestDev(err, stdout, stderr, cb) {
generateDynamicTasks(runDynamicTasks, 'dev', cb);
}
function processManifestProd(err, stdout, stderr, cb) {
var config = grunt.file.read('readk.it/js/app/config.js');
if (/lite\:\s*true/.test(config)) {
// prod_lite is a version of Readk.it that is smaller, as it foregoes:
// * Drag and drop (not needed for mobile)
// * Modernizr / Detectizr
generateDynamicTasks(runDynamicTasks, 'prod_lite', cb);
} else {
generateDynamicTasks(runDynamicTasks, 'prod', cb);
}
}
// Project configuration.
grunt.initConfig({
// Metadata.
pkg: grunt.file.readJSON('package.json'),
epub_src: 'readkit.epub',
readkit_src: 'readk.it', // readk.it source
banner: '/*! <%= pkg.title || pkg.name %> - v<%= pkg.version %> - ' +
'<%= grunt.template.today("yyyy-mm-dd") %>\n' +
'<%= pkg.homepage ? "* " + pkg.homepage + "\\n" : "" %>' +
'* Copyright (c) <%= grunt.template.today("yyyy") %> <%= pkg.author.name %>;' +
' Licensed <%= _.pluck(pkg.licenses, "type").join(", ") %> */\n',
// Task configuration.
clean: {
// Before generating any new files, remove any previously-created files.
before: [
'dist',
'build',
'.sass-cache'
],
build_readkit: [
'build/readkit'
],
build_readkit_js: [
'build/readkit.js'
],
// Now that we've finished, remove the build directories.
after: [
'build',
'.sass-cache'
]
},
readkit_dom_munger: {
index_reader: {
// Update our index.html to point to the built readkit,
// remove unnecessary data attributes, and add tags for bake.
options: {
callback: function($) {
$('.readkit-library').removeAttr('data-library');
$('#readkit-entry').removeAttr('data-main');
$('head link').remove();
$('head meta[name="apple-mobile-web-app-capable"]').before('<style><!--(bake css/screen.css)--></style>');
$('head meta[name="apple-mobile-web-app-capable"]').remove();
$('head meta[name="apple-mobile-web-app-status-bar-style"]').remove();
$('script#readkit-client').removeAttr('src').append('<!--(bake js/client.config.js)-->');
$('script#readkit-entry').removeAttr('src').append('<!--(bake ../readkit.js)-->');
}
},
src: ['build/readkit/index.html']
},
index_library: {
// Update our index.html to point to the built readkit,
// and remove unnecessary data attributes.
options: {
update: {selector: '#readkit-entry', attribute: 'src', value: 'js/readkit.js'},
callback: function($) {
$('#readkit-client').attr('src', 'library/js/library.client.config.js');
$('#readkit-entry').removeAttr('data-main');
}
},
src: ['dist/readkit.library/index.html']
},
library: {
// Remove unnecessary data attributes.
options: {
update: {selector: '#library-entry', attribute: 'src', value: 'js/main.compiled.js'},
callback: function($) {
$('#library-entry').removeAttr('data-main');
}
},
src: ['dist/readkit.library/library/library.html']
}
// Others set dynamically
},
bake: {
reader: {
options: {
},
files: {
// Remember, bake specifies dest: src
'dist/readkit.reader/readkit.reader.html': 'build/readkit/index.html'
}
}
},
readkit_data_uri: {
solo: {
// src file
src: ['build/readkit/index.html'],
// output dir
dest: 'build/readkit',
options: {
// which files do we wish to encode to data uris?
target: ['build/readkit/images/*.*', 'build/readkit/favicon.ico'],
type: 'html'
}
}
},
jshint: {
// Check our js
readkit: {
options: {
'-W061': true, // W061: eval can be harmful.
'-W083': true, // W083: Don't make functions within a loop.
'-W098': true, // W098: 'e' is defined but never used.
'-W117': true, // W117: 'client' is not defined.
curly: true,
eqeqeq: true,
immed: true,
latedef: true,
newcap: true,
noarg: true,
sub: true,
undef: true,
unused: true,
boss: true,
eqnull: true,
browser: true,
globals: {
enquire: true,
jQuery: true,
Modernizr: true,
screenfull: true,
document: true,
navigator: true
},
ignores: ['<%= readkit_src %>/js/lib/*.js', '<%= readkit_src %>/js/lib/**/*.js', '<%= readkit_src %>/js/test/qunit/*.js', '<%= readkit_src %>/library/js/lib/*.js', '<%= readkit_src %>/library/js/lib/**/*.js']
},
files: {
src: ['Gruntfile.js', '<%= readkit_src %>/**/*.js']
}
}
},
compass: {
readkit: {
options: {
config: '<%= readkit_src %>/sass/config.rb',
basePath: '<%= readkit_src %>/sass'
}
},
library: {
options: {
config: '<%= readkit_src %>/library/sass/config.rb',
basePath: '<%= readkit_src %>/library/sass'
}
}
// Set dynamically
},
cssmin: {
readkit: {
expand: true,
cwd: '<%= readkit_src %>/css/',
src: ['*.css', '!*.min.css'],
dest: 'build/readkit/css/',
ext: '.css'
},
library: {
expand: true,
cwd: '<%= readkit_src %>/library/css/',
src: ['*.css', '!*.min.css'],
dest: 'build/readkit/library/css/',
ext: '.css'
}
},
concat: {
options: {
separator: '',
},
readkit: {
src: ['build/readkit/css/*.css', 'build/readkit/fonts/fontello/css/*.css'],
dest: 'build/readkit/css/screen.css',
},
library: {
src: ['build/readkit/library/css/*.css', 'build/readkit/library/fonts/fontello/css/*.css'],
dest: 'build/readkit/library/css/screen.css',
}
},
imageEmbed: {
build: {
src: [ "build/readkit/css/screen.css"],
dest: "build/readkit/css/screen.css",
options: {
maxImageSize: 0,
deleteAfterEncoding : false
}
}
},
//nodeunit: {
// files: ['test/**/*_test.js']
//},
copy: {
content_js_to_build: {
// Copy the default (empty) content.js to the build directory
options: {
},
files: [
{expand: true, cwd: '<%= readkit_src %>', src: ['index.html'],
dest: 'build/readkit'},
{expand: true, cwd: '<%= readkit_src %>/js/app', src: ['content.js'],
dest: 'build/readkit/js/app'}
]
},
readkit_prod_to_build: {
// Copy prod Readk.it to the build directory
options: {
},
files: [
{expand: true, cwd: '<%= readkit_src %>/', src: ['**'],
dest: 'build/readkit/'}
]
},
readkit_prodlite_to_build: {
// For our prod lite version, copy Readk.it to the build directory, replacing libs with stubs
options: {
},
files: [
{expand: true, cwd: '<%= readkit_src %>/', src: ['**'],
dest: 'build/readkit/'},
{expand: true, cwd: '<%= readkit_src %>/js/stubs', src: ['**'],
dest: 'build/readkit/js'}
]
},
reader_dev_to_dist: {
options: {
processContentExclude: ['<%= readkit_src %>/.gitignore']
},
files: [
{expand: true, cwd: '<%= readkit_src %>', src: ['*'],
dest: 'dist/readkit.reader', filter: 'isFile'},
{expand: true, cwd: '<%= readkit_src %>/js', src: ['**'],
dest: 'dist/readkit.reader/js'},
{expand: true, cwd: 'readk.it/css', src: ['**'],
dest: 'dist/readkit.reader/css', filter: 'isFile'},
{expand: true, cwd: '<%= readkit_src %>/', src: ['images/**'],
dest: 'dist/readkit.reader'},
{expand: true, cwd: '<%= readkit_src %>/', src: [
'fonts/fontello/css/**',
'fonts/fontello/font/**',
'fonts/Lora/**',
'fonts/SourceSansPro/**'],
dest: 'dist/readkit.reader'}
]
},
library_prod_to_build: {
// Copy Readk.it to the build directory for the library
options: {
},
files: [
{expand: true, cwd: 'build', src: ['readkit.js'],
dest: 'dist/readkit.library/js'},
{expand: true, cwd: '<%= readkit_src %>/library/js', src: ['**'],
dest: 'build/readkit/library/js'}
]
},
library_prod_to_dist: {
options: {
},
files: [
{expand: true, cwd: 'build/readkit/css', src: ['**'],
dest: 'dist/readkit.library/css', filter: 'isFile'},
{expand: true, cwd: 'build/readkit', src: ['js/lib/zip/inflate.js', 'js/app/config.js'],
dest: 'dist/readkit.library'},
{expand: true, cwd: 'build/readkit/library/css', src: ['**', '!screen.css'],
dest: 'dist/readkit.library/library/css', filter: 'isFile'}
]
},
library_dev_to_dist: {
options: {
},
files: [
{expand: true, cwd: '<%= readkit_src %>/js', src: ['**'],
dest: 'dist/readkit.library/js'},
{expand: true, cwd: 'readk.it/css', src: ['**'],
dest: 'dist/readkit.library/css', filter: 'isFile'},
{expand: true, cwd: 'readk.it/library/css', src: ['**'],
dest: 'dist/readkit.library/library/css', filter: 'isFile'},
{expand: true, cwd: '<%= readkit_src %>/library/js', src: ['**'],
dest: 'dist/readkit.library/library/js'}
]
},
library_assets_to_dist: {
options: {
processContentExclude: ['<%= readkit_src %>/.gitignore']
},
files: [
{expand: true, cwd: '<%= readkit_src %>/js', src: ['test/**'],
dest: 'dist/readkit.library/js'},
{expand: true, cwd: '<%= readkit_src %>', src: ['*', '!**/*.appcache'],
dest: 'dist/readkit.library', filter: 'isFile'},
{expand: true, cwd: '<%= readkit_src %>/', src: ['images/**'],
dest: 'dist/readkit.library'},
{expand: true, cwd: '<%= readkit_src %>/', src: [
'fonts/fontello/css/**',
'fonts/fontello/font/**',
'fonts/Lora/**',
'fonts/SourceSansPro/**'],
dest: 'dist/readkit.library'},
{expand: true, cwd: '<%= readkit_src %>/library', src: ['fonts/**', 'images/**', 'library.html'],
dest: 'dist/readkit.library/library'},
{expand: true, cwd: '<%= readkit_src %>', src: ['readkit.appcache'],
dest: 'dist/readkit.library/library/solo'},
]
},
library_manifest_to_dist: {
options: {
},
files: [
{expand: true, cwd: '<%= epub_src %>', src: ['manifest.json'],
dest: 'dist/readkit.library/library', filter: 'isFile'}
]
},
library_epubs_to_dist: {
options: {
},
files: [
{expand: true, cwd: '<%= epub_src %>', src: ['**', '!manifest.json', '!manifest.maker.py'],
dest: 'dist/readkit.library/library'}
]
},
// Copy the client config across if there is one
library_client_config_to_dist: {
options: {
},
files: [
{expand: true, cwd: '<%= readkit_src %>/library/js', src: ['library.client.config.js', 'script.js'],
dest: 'dist/readkit.library/library/js', filter: 'isFile'}
]
}
// Others set dynamically
},
readkit_datauris: {
// Set dynamically
},
shell: {
make_manifest: {
command: [
'cd <%= epub_src %>',
'python manifest.maker.py > manifest.json',
'echo Created manifest: manifest.json'
].join('&&'),
options: {
stdout: true,
stderr: true
}
},
make_manifest_prod: {
// Create our manifest describing the EPUB files
command: [
'cd <%= epub_src %>',
'python manifest.maker.py > manifest.json',
'echo Created manifest: manifest.json'
].join('&&'),
options: {
stdout: true,
stderr: true,
callback: processManifestProd
}
},
make_manifest_dev: {
// Create our manifest describing the EPUB files
command: [
'cd <%= epub_src %>',
'python manifest.maker.py > manifest.json',
'echo Created manifest: manifest.json'
].join('&&'),
options: {
stdout: true,
stderr: true,
callback: processManifestDev
}
},
dir: {
command: [
'dir',
].join('&&'),
options: {
stdout: true,
stderr: true,
failOnError: true
}
},
// Others set dynamically
},
requirejs: {
compile_readkit: {
// Compile down our Readkit js to a single file.
options: {
baseUrl: 'build/readkit/js/lib',
waitSeconds: 0,
paths: {
requireLib: 'require',
app: '../app'
},
name: '../readkit',
include: [
'requireLib',
'jquery',
'text',
'app/controller',
'app/config',
'app/content',
'add-to-homescreen/src/add2home',
],
out: 'build/readkit.js',
map: {
'*': {
'css': 'require-css/css'
}
},
shim: {
// Shim in any files that aren't AMD modules
'jquery.storage': ['jquery'],
'jquery.ba-urlinternal': ['jquery'],
'jquery.ba-resize': ['jquery'],
'jquery.hotkeys': ['jquery'],
// Make certain non-AMD modules available globally
'modernizr': {deps: ['jquery'], exports: 'Modernizr'},
'detectizr': {deps: ['jquery', 'modernizr'], exports: 'Detectizr'},
'iscroll': {exports: 'iScroll'},
'zip/zip': {exports: 'zip'},
'zip/inflate': {exports: 'inflate'},
}
}
},
compile_library: {
// Compile down our library js to a single file.
options: {
baseUrl: 'build/readkit/library/js/lib',
paths: {
requireLib: 'require',
app: '../app',
underscore: 'underscore-min.amd',
client_js: '../'
},
name: '../main',
include: [
'requireLib',
'jquery',
'app/controller',
'app/config',
'add-to-homescreen/src/add2home',
'client_js/script'
],
out: 'dist/readkit.library/library/js/main.compiled.js',
shim: {
// Shim in our jQuery plugins etc, as they aren't AMD modules
'sly': ['jquery']
}
}
}
},
});
// Load our grunt plugins.
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-cssmin');
grunt.loadNpmTasks('grunt-contrib-compass');
/* grunt.loadNpmTasks('grunt-contrib-nodeunit'); */
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-shell');
grunt.loadNpmTasks('grunt-readkit-dom-munger');
grunt.loadNpmTasks('grunt-readkit-datauris');
grunt.loadNpmTasks('grunt-contrib-requirejs');
grunt.loadNpmTasks("grunt-image-embed");
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-bake');
grunt.loadNpmTasks('grunt-readkit-data-uri');
// We have to create many of our grunt tasks dynamically, as we don't
// knowwhich or how many EPUBs we'll be processing ahead of time.
// This page helped a lot: https://gist.github.com/brianfeister/4294776
function generateDynamicTasks(callback, target, cb){
var manifest = grunt.file.readJSON('readkit.epub/manifest.json');
// Each entry in the manifest describes a particular EPUB file
for (var entry in manifest) {
// Certain characters found in the EPUB id cause problems for grunt
var identifier = manifest[entry].identifier.replace(/\:|\./g, '_');
var name = manifest[entry].name.replace(/[^a-z\d]/gi, '_').toLowerCase();
var path = manifest[entry].path;
var cover = manifest[entry].cover;
globals.identifier.push(identifier);
globals.path[identifier] = manifest[entry].path;
// Determine the location of the opf file
grunt.config('readkit_dom_munger.' + identifier + '_metaInf', {
options: {
read: {selector: 'container rootfiles rootfile', attribute: 'full-path', writeto: 'metaInfRef', isPath:false}
},
src: '<%= epub_src %>/' + path + 'META-INF/container.xml'
});
var opf_path_src = '<%= epub_src %>/' + path + '<%= readkit_dom_munger.data.metaInfRef %>';
var opf_path_dest = 'dist/readkit.epub/' + path + '<%= readkit_dom_munger.data.metaInfRef %>';
// Determine the location of the OEBPS directory
grunt.config('readkit_dom_munger.' + identifier + '_oebps', {
options: {
read: {selector: 'container rootfiles rootfile', attribute: 'full-path', replace: '\/?[^\/]*$', replacewith: '', writeto: 'oebpsRef', isPath:false},
callback: function($) {
var regexp = new RegExp('\/.*$');
// Store the OEBPS path for the publication
var identifier = globals.identifier.shift();
globals.oebps_path_src[identifier] = grunt.template.process('<%= epub_src %>/') + globals.path[identifier] + $('container rootfiles rootfile').attr('full-path').replace(regexp, '');
}
},
src: '<%= epub_src %>/' + path + 'META-INF/container.xml'
});
var oebps = '<%= readkit_dom_munger.data.oebpsRef %>';
var oebps_path_src = '<%= epub_src %>/' + path + '<%= readkit_dom_munger.data.oebpsRef %>';
var oebps_path_dest = 'dist/readkit.epub/' + path + '<%= readkit_dom_munger.data.oebpsRef %>';
var solo_path_dest = 'dist/readkit.solo/<%= epub_src %>/' + path;
// Read the manifest entries from the opf file
grunt.config('readkit_dom_munger.' + identifier + '_opf', {
options: {
read: {selector: 'manifest item', attribute: 'href', writeto: 'manifestRefs', isPath:true}
},
src: [opf_path_src]
});
// Read the manifest html entries from the opf file
grunt.config('readkit_dom_munger.' + identifier + '_opf_html', {
options: {
read: {selector: 'manifest item[media-type="application/xhtml+xml"]', attribute: 'href', writeto: 'manifestHtmlRefs', isPath:true}
},
src: [opf_path_src]
});
// Read the client scripts from the html files
grunt.config('readkit_dom_munger.' + identifier + '_client_scripts', {
options: {
read: {selector: 'script', attribute: 'src', writeto: 'clientScriptRefs', isPath:false, concatenate: true},
},
src: ['<%= readkit_dom_munger.data.manifestHtmlRefs %>']
});
// Copy our client script files to the build directory
grunt.config('copy.' + identifier + '_client_scripts_to_build', {
options: {
},
files: [
{expand: true, src: ['<%= readkit_dom_munger.data.clientScriptRefs %>'], cwd: oebps_path_src, dest: 'build/readkit/', filter: 'isFile'}
]
});
// Copy our EPUB files to the dist directory
grunt.config('copy.' + identifier + '_epub_to_dist', {
options: {
processContentExclude: [oebps + '/sass/**']
},
files: [
{expand: true, src: ['<%= epub_src %>/' + path + 'mimetype'], dest: 'dist/'},
{expand: true, src: ['<%= epub_src %>/' + path + 'META-INF/**'], dest: 'dist/'}, // includes files in path and its subdirs
{expand: true, src: ['<%= readkit_dom_munger.data.manifestRefs %>', opf_path_src], dest: 'dist/', filter: 'isFile'}
]
});
// Copy production Readk.it to the dist directory
grunt.config('copy.' + identifier + '_readkit_prod_to_dist', {
options: {
},
files: [
{expand: true, cwd: 'build', src: ['readkit.js'],
dest: oebps_path_dest + '/readk.it/js', filter: 'isFile'},
{expand: true, cwd: 'build/readkit', src: ['js/lib/zip/inflate.js'],
dest: oebps_path_dest + '/readk.it'},
{expand: true, cwd: 'build/readkit/css', src: ['**', '!screen.css'],
dest: oebps_path_dest + '/readk.it/css', filter: 'isFile'}
]
});
// Copy development Readk.it to the dist directory
grunt.config('copy.' + identifier + '_readkit_dev_to_dist', {
options: {
},
files: [
{expand: true, cwd: 'readk.it/js', src: ['**'],
dest: oebps_path_dest + '/readk.it/js', filter: 'isFile'},
{expand: true, cwd: 'readk.it/css', src: ['**'],
dest: oebps_path_dest + '/readk.it/css', filter: 'isFile'}
]
});
// Copy development Readk.it to the solo directory
grunt.config('copy.' + identifier + '_readkit_dev_to_solo', {
options: {
},
files: [
{expand: true, cwd: 'readk.it/js', src: ['**'],
dest: solo_path_dest + '/readk.it/js', filter: 'isFile'},
{expand: true, cwd: 'build/readkit/js', src: ['content.js'],
dest: solo_path_dest + '/readk.it/js', filter: 'isFile'}
]
});
// Copy the index.html for this publication to the solo directory
grunt.config('copy.' + identifier + '_solo_index_to_dist', {
files: [
{
src: ['build/readkit/index.html'],
dest: 'dist/readkit.solo/' + identifier + '_' + name + '.html'
}
]
});
// Copy the index.html for this publication to the library directory
grunt.config('copy.' + identifier + '_solo_index_to_library', {
files: [
{
src: ['build/readkit/index.html'],
dest: 'dist/readkit.library/library/solo/' + identifier + '_' + name + '.html'
},
{
cwd: 'build/readkit/images/',
expand: true,
src: ['*.png'],
dest: 'dist/readkit.library/library/solo/images/'
}
]
});
// Copy the cover for this publication to the library directory
grunt.config('copy.' + identifier + '_cover_to_library', {
files: [
{expand: true, cwd: '<%= epub_src %>',
src: [cover],
dest: 'dist/readkit.library/library/',
filter: 'isFile'
}
]
});
// Copy Readk.it assets to the dist directory
grunt.config('copy.' + identifier + '_readkit_assets_to_dist', {
options: {
processContentExclude: ['<%= readkit_src %>/.gitignore']
},
files: [
{expand: true, cwd: '<%= readkit_src %>', src: ['*'],
dest: oebps_path_dest + '/readk.it', filter: 'isFile'},
{expand: true, cwd: '<%= readkit_src %>/', src: ['images/**', 'js/client.config.js'],
dest: oebps_path_dest + '/readk.it'},
{expand: true, cwd: '<%= readkit_src %>/', src: [
'fonts/fontello/css/**',
'fonts/fontello/font/**',
'fonts/Lora/**',
'fonts/SourceSansPro/**'],
dest: oebps_path_dest + '/readk.it'}
]
});
// Copy the client config across if there is one
grunt.config('copy.' + identifier + '_client_config_to_dist', {
options: {
},
files: [
{expand: true, cwd: oebps_path_src + '/readk.it/js/',
src: ['client.config.js'],
dest: oebps_path_dest + '/readk.it/js', filter: 'isFile'}
]
});
grunt.config('copy.' + identifier + '_client_config_to_build', {
options: {
},
files: [
{expand: true, cwd: oebps_path_src + '/readk.it/js/',
src: ['client.config.js'],
dest: 'build/readkit/js', filter: 'isFile'}
]
});
// Update our production index.html to point to the built readkit,
// and remove the now unnecessary data-main attribute.
grunt.config('readkit_dom_munger.' + identifier + '_readkit_index', {
options: {
update: {selector: '#readkit-entry', attribute: 'src', value: 'js/readkit.js'},
callback: function($) {
$('.readkit-library').removeAttr('data-library');
$('#readkit-client').attr('src', 'js/client.config.js');
$('#readkit-entry').removeAttr('data-main');
}
},
src: [oebps_path_dest + '/readk.it/index.html']
});
// Update our solo production index.html to point to the built readkit,
// and remove the now unnecessary data-main attribute.
grunt.config('readkit_dom_munger.' + identifier + '_solo_index', {
options: {
callback: function($) {
$('html').attr('manifest', 'readkit.appcache');
$('.library_link').attr('href', '../library.html');
$('#readkit-entry').removeAttr('data-main');
// $('head link').remove();
$('head link[rel="stylesheet"]').remove();
$('head meta[name="apple-mobile-web-app-capable"]').before('<style><!--(bake css/screen.css)--></style>');
$('script#readkit-client').remove();
$('script#readkit-entry').removeAttr('src').append('<!--(bake ../readkit.js)-->');
}
},
src: ['build/readkit/index.html']
});
grunt.config('readkit_dom_munger.' + identifier + '_solo_index_remove_library', {
options: {
callback: function($) {
$('.readkit-library').removeAttr('data-library');
// $('head meta[name="apple-mobile-web-app-capable"]').remove();
// $('head meta[name="apple-mobile-web-app-status-bar-style"]').remove();
}
},
src: ['build/readkit/index.html']
});
grunt.config('bake.' + identifier + '_solo', {
options: {
},
files: {
'build/readkit/index.html': 'build/readkit/index.html'
}
});
// Mixin the prod readkit mainfest entries to the opf file.
// We use text/plain for css as otherwise epubcheck throws spurious errors.
// We use a useful technique here to wrap a multi-line string temporarily in a comment.
grunt.config('readkit_dom_munger.' + identifier + '_opf_mixin_prod', {
options: {
xmlMode: true,
append: {selector: 'manifest', html: function () {/*
<!-- './readk.it' -->
<item id="readk_it_favicon_ico" href="readk.it/favicon.ico" media-type="image/vnd.microsoft.icon"></item>
<item id="readk_it_index_html" href="readk.it/index.html" media-type="text/plain"></item>
<item id="readk_it_offline_manifest" href="readk.it/offline.manifest" media-type="text/plain"></item>
<!-- './readk.it/css' -->
<item id="readk_it_css_fontello_css" href="readk.it/css/fontello.css" media-type="text/plain"></item>
<item id="readk_it_css_screen_css" href="readk.it/css/readkit-screen.css" media-type="text/plain"></item>
<item id="readk_it_css_drag_and_drop_css" href="readk.it/css/drag_and_drop.css" media-type="text/plain"></item>
<item id="readk_it_css_add-to-homescreen_style_add2home_css" href="readk.it/css/add2home.css" media-type="text/plain"></item>
<!-- './readk.it/fonts' -->
<!-- './readk.it/fonts/fontello' -->
<!-- './readk.it/fonts/fontello/font' -->
<item id="readk_it_fonts_fontello_font_fontello_ttf" href="readk.it/fonts/fontello/font/fontello.ttf" media-type="application/vnd.ms-opentype"></item>
<item id="readk_it_fonts_fontello_font_fontello_woff" href="readk.it/fonts/fontello/font/fontello.woff" media-type="application/vnd.ms-opentype"></item>
<!-- './readk.it/fonts/Lora' -->
<item id="readk_it_fonts_Lora_Lora-Bold_woff" href="readk.it/fonts/Lora/Lora-Bold.woff" media-type="application/vnd.ms-opentype"></item>
<item id="readk_it_fonts_Lora_Lora-BoldItalic_woff" href="readk.it/fonts/Lora/Lora-BoldItalic.woff" media-type="application/vnd.ms-opentype"></item>
<item id="readk_it_fonts_Lora_Lora-Italic_woff" href="readk.it/fonts/Lora/Lora-Italic.woff" media-type="application/vnd.ms-opentype"></item>
<item id="readk_it_fonts_Lora_Lora_woff" href="readk.it/fonts/Lora/Lora.woff" media-type="application/vnd.ms-opentype"></item>
<!-- './readk.it/fonts/SourceSansPro' -->
<item id="readk_it_fonts_SourceSansPro_SourceSansPro-Bold_woff" href="readk.it/fonts/SourceSansPro/SourceSansPro-Bold.woff" media-type="application/vnd.ms-opentype"></item>
<item id="readk_it_fonts_SourceSansPro_SourceSansPro-BoldIt_woff" href="readk.it/fonts/SourceSansPro/SourceSansPro-BoldIt.woff" media-type="application/vnd.ms-opentype"></item>
<item id="readk_it_fonts_SourceSansPro_SourceSansPro-It_woff" href="readk.it/fonts/SourceSansPro/SourceSansPro-It.woff" media-type="application/vnd.ms-opentype"></item>
<item id="readk_it_fonts_SourceSansPro_SourceSansPro-Regular_woff" href="readk.it/fonts/SourceSansPro/SourceSansPro-Regular.woff" media-type="application/vnd.ms-opentype"></item>
<!-- './readk.it/images' -->
<item id="readk_it_images_apple-touch-icon-114x114_png" href="readk.it/images/apple-touch-icon-114x114.png" media-type="image/png"></item>
<item id="readk_it_images_apple-touch-icon-144x144_png" href="readk.it/images/apple-touch-icon-144x144.png" media-type="image/png"></item>
<item id="readk_it_images_apple-touch-icon-57x57_png" href="readk.it/images/apple-touch-icon-57x57.png" media-type="image/png"></item>
<item id="readk_it_images_apple-touch-icon-72x72_png" href="readk.it/images/apple-touch-icon-72x72.png" media-type="image/png"></item>
<item id="readk_it_images_site_preloader_gif" href="readk.it/images/site_preloader.gif" media-type="image/gif"></item>
<item id="readk_it_images_spinner_gif" href="readk.it/images/spinner.gif" media-type="image/gif"></item>
<item id="readk_it_images_apple-touch-startup-image-320x460_png" href="readk.it/images/apple-touch-startup-image-320x460.png" media-type="image/png"></item>
<item id="readk_it_images_apple-touch-startup-image-640x920_png" href="readk.it/images/apple-touch-startup-image-640x920.png" media-type="image/png"></item>
<item id="readk_it_images_apple-touch-startup-image-640x1096_png" href="readk.it/images/apple-touch-startup-image-640x1096.png" media-type="image/png"></item>
<item id="readk_it_images_apple-touch-startup-image-748x1024_png" href="readk.it/images/apple-touch-startup-image-748x1024.png" media-type="image/png"></item>
<item id="readk_it_images_apple-touch-startup-image-768x1004_png" href="readk.it/images/apple-touch-startup-image-768x1004.png" media-type="image/png"></item>
<item id="readk_it_images_apple-touch-startup-image-1536x2008_png" href="readk.it/images/apple-touch-startup-image-1536x2008.png" media-type="image/png"></item>
<item id="readk_it_images_apple-touch-startup-image-2048x1496_png" href="readk.it/images/apple-touch-startup-image-2048x1496.png" media-type="image/png"></item>
<!-- './readk.it/js' -->
<item id="readk_it_js_client_config_js" href="readk.it/js/client.config.js" media-type="text/javascript"></item>
<item id="readk_it_js_readkit_js" href="readk.it/js/readkit.js" media-type="text/javascript"></item>
<!-- './readk.it/js/lib/zip' -->
<item id='readk_it_js_lib_zip_inflate_js' href='readk.it/js/lib/zip/inflate.js' media-type='text/javascript' />
*/}.toString().match(/[^]*\/\*([^]*)\*\/\}$/)[1]
}
},
src: [opf_path_dest]
});
// Mixin the dev readkit mainfest entries to the opf file.
// We use text/plain for css as otherwise epubcheck throws spurious errors.
// We use a useful technique here to wrap a multi-line string temporarily in a comment.
grunt.config('readkit_dom_munger.' + identifier + '_opf_mixin_dev', {
options: {
xmlMode: true,
append: {selector: 'manifest', html: function () {/*
<!-- './readk.it' -->
<item id='readk_it_favicon_ico' href='readk.it/favicon.ico' media-type='image/vnd.microsoft.icon' />
<item id='readk_it_index_html' href='readk.it/index.html' media-type='text/plain' />
<item id="readk_it_offline_manifest" href="readk.it/offline.manifest" media-type="text/plain"></item>
<!-- './readk.it/css' -->
<item id="readk_it_css_fontello_css" href="readk.it/css/fontello.css" media-type="text/plain"></item>
<item id='readk_it_css_add2home_css' href='readk.it/css/add2home.css' media-type='text/plain' />
<item id='readk_it_css_drag_and_drop_css' href='readk.it/css/drag_and_drop.css' media-type='text/plain' />
<item id='readk_it_css_readkit-screen_css' href='readk.it/css/readkit-screen.css' media-type='text/plain' />
<!-- './readk.it/fonts' -->
<!-- './readk.it/fonts/fontello' -->
<!-- './readk.it/fonts/fontello/font' -->
<item id='readk_it_fonts_fontello_font_fontello_ttf' href='readk.it/fonts/fontello/font/fontello.ttf' media-type='application/vnd.ms-opentype' />
<item id='readk_it_fonts_fontello_font_fontello_woff' href='readk.it/fonts/fontello/font/fontello.woff' media-type='application/vnd.ms-opentype' />
<!-- './readk.it/fonts/Lora' -->
<item id='readk_it_fonts_Lora_Lora-Bold_woff' href='readk.it/fonts/Lora/Lora-Bold.woff' media-type='application/vnd.ms-opentype' />
<item id='readk_it_fonts_Lora_Lora-BoldItalic_woff' href='readk.it/fonts/Lora/Lora-BoldItalic.woff' media-type='application/vnd.ms-opentype' />
<item id='readk_it_fonts_Lora_Lora-Italic_woff' href='readk.it/fonts/Lora/Lora-Italic.woff' media-type='application/vnd.ms-opentype' />
<item id='readk_it_fonts_Lora_Lora_woff' href='readk.it/fonts/Lora/Lora.woff' media-type='application/vnd.ms-opentype' />
<!-- './readk.it/fonts/SourceSansPro' -->
<item id='readk_it_fonts_SourceSansPro_SourceSansPro-Bold_woff' href='readk.it/fonts/SourceSansPro/SourceSansPro-Bold.woff' media-type='application/vnd.ms-
opentype' />
<item id='readk_it_fonts_SourceSansPro_SourceSansPro-BoldIt_woff' href='readk.it/fonts/SourceSansPro/SourceSansPro-BoldIt.woff' media-type='application/vnd
.ms-opentype' />
<item id='readk_it_fonts_SourceSansPro_SourceSansPro-It_woff' href='readk.it/fonts/SourceSansPro/SourceSansPro-It.woff' media-type='application/vnd.ms-open
type' />
<item id='readk_it_fonts_SourceSansPro_SourceSansPro-Regular_woff' href='readk.it/fonts/SourceSansPro/SourceSansPro-Regular.woff' media-type='application/v
nd.ms-opentype' />
<!-- './readk.it/images' -->
<item id='readk_it_images_apple-touch-icon-114x114_png' href='readk.it/images/apple-touch-icon-114x114.png' media-type='image/png' />
<item id="readk_it_images_apple-touch-icon-144x144_png" href="readk.it/images/apple-touch-icon-144x144.png" media-type="image/png"></item>
<item id='readk_it_images_apple-touch-icon-57x57_png' href='readk.it/images/apple-touch-icon-57x57.png' media-type='image/png' />
<item id='readk_it_images_apple-touch-icon-72x72_png' href='readk.it/images/apple-touch-icon-72x72.png' media-type='image/png' />
<item id='readk_it_images_site_preloader_gif' href='readk.it/images/site_preloader.gif' media-type='image/gif' />
<item id='readk_it_images_spinner_gif' href='readk.it/images/spinner.gif' media-type='image/gif' />
<item id="readk_it_images_apple-touch-startup-image-320x460_png" href="readk.it/images/apple-touch-startup-image-320x460.png" media-type="image/png"></item>
<item id="readk_it_images_apple-touch-startup-image-640x920_png" href="readk.it/images/apple-touch-startup-image-640x920.png" media-type="image/png"></item>
<item id="readk_it_images_apple-touch-startup-image-640x1096_png" href="readk.it/images/apple-touch-startup-image-640x1096.png" media-type="image/png"></item>
<item id="readk_it_images_apple-touch-startup-image-748x1024_png" href="readk.it/images/apple-touch-startup-image-748x1024.png" media-type="image/png"></item>
<item id="readk_it_images_apple-touch-startup-image-768x1004_png" href="readk.it/images/apple-touch-startup-image-768x1004.png" media-type="image/png"></item>
<item id="readk_it_images_apple-touch-startup-image-1536x2008_png" href="readk.it/images/apple-touch-startup-image-1536x2008.png" media-type="image/png"></item>
<item id="readk_it_images_apple-touch-startup-image-2048x1496_png" href="readk.it/images/apple-touch-startup-image-2048x1496.png" media-type="image/png"></item>
<!-- './readk.it/js' -->
<item id='readk_it_js_client_config_js' href='readk.it/js/client.config.js' media-type='text/javascript' />
<item id='readk_it_js_readkit_js' href='readk.it/js/readkit.js' media-type='text/javascript' />
<!-- './readk.it/js/app' -->
<item id='readk_it_js_app_chrome_js' href='readk.it/js/app/chrome.js' media-type='text/javascript' />
<item id='readk_it_js_app_config_js' href='readk.it/js/app/config.js' media-type='text/javascript' />
<item id='readk_it_js_app_content_js' href='readk.it/js/app/content.js' media-type='text/javascript' />
<item id='readk_it_js_app_controller_js' href='readk.it/js/app/controller.js' media-type='text/javascript' />
<item id='readk_it_js_app_epub_js' href='readk.it/js/app/epub.js' media-type='text/javascript' />
<item id='readk_it_js_app_layout_js' href='readk.it/js/app/layout.js' media-type='text/javascript' />
<item id='readk_it_js_app_utility_js' href='readk.it/js/app/utility.js' media-type='text/javascript' />
<!-- './readk.it/js/lib' -->
<item id='readk_it_js_lib_detectizr_js' href='readk.it/js/lib/detectizr.js' media-type='text/javascript' />
<item id='readk_it_js_lib_iscroll-mit-license_txt' href='readk.it/js/lib/iscroll-mit-license.txt' media-type='text/plain' />
<item id='readk_it_js_lib_iscroll_js' href='readk.it/js/lib/iscroll.js' media-type='text/javascript' />
<item id='readk_it_js_lib_jquery_ba-resize_js' href='readk.it/js/lib/jquery.ba-resize.js' media-type='text/javascript' />
<item id='readk_it_js_lib_jquery_ba-urlinternal_js' href='readk.it/js/lib/jquery.ba-urlinternal.js' media-type='text/javascript' />
<item id='readk_it_js_lib_jquery_hotkeys_js' href='readk.it/js/lib/jquery.hotkeys.js' media-type='text/javascript' />
<item id='readk_it_js_lib_jquery_js' href='readk.it/js/lib/jquery.js' media-type='text/javascript' />
<item id='readk_it_js_lib_jquery_storage_js' href='readk.it/js/lib/jquery.storage.js' media-type='text/javascript' />
<item id='readk_it_js_lib_lodash_js' href='readk.it/js/lib/lodash.js' media-type='text/javascript' />
<item id='readk_it_js_lib_modernizr_js' href='readk.it/js/lib/modernizr.js' media-type='text/javascript' />
<item id='readk_it_js_lib_require_js' href='readk.it/js/lib/require.js' media-type='text/javascript' />
<item id='readk_it_js_lib_text_js' href='readk.it/js/lib/text.js' media-type='text/javascript' />
<item id='readk_it_js_lib_tinytim_js' href='readk.it/js/lib/tinytim.js' media-type='text/javascript' />
<!-- './readk.it/js/lib/add-to-homescreen' -->
<!-- './readk.it/js/lib/add-to-homescreen/src' -->
<item id='readk_it_js_lib_add-to-homescreen_src_add2home_js' href='readk.it/js/lib/add-to-homescreen/src/add2home.js' media-type='text/javascript' />
<!-- './readk.it/js/lib/add-to-homescreen/style' -->
<item id='readk_it_js_lib_add-to-homescreen_style_add2home_css' href='readk.it/js/lib/add-to-homescreen/style/add2home.css' media-type='text/plain' />
<!-- './readk.it/js/lib/require-css' -->
<item id='readk_it_js_lib_require-css_css_js' href='readk.it/js/lib/require-css/css.js' media-type='text/javascript' />
<item id='readk_it_js_lib_require-css_LICENSE_txt' href='readk.it/js/lib/require-css/LICENSE.txt' media-type='text/plain' />
<item id='readk_it_js_lib_require-css_normalize_js' href='readk.it/js/lib/require-css/normalize.js' media-type='text/javascript' />
<!-- './readk.it/js/lib/zip' -->
<item id='readk_it_js_lib_zip_deflate_js' href='readk.it/js/lib/zip/deflate.js' media-type='text/javascript' />
<item id='readk_it_js_lib_zip_inflate_js' href='readk.it/js/lib/zip/inflate.js' media-type='text/javascript' />
<item id='readk_it_js_lib_zip_mime-types_js' href='readk.it/js/lib/zip/mime-types.js' media-type='text/javascript' />
<item id='readk_it_js_lib_zip_zip-ext_js' href='readk.it/js/lib/zip/zip-ext.js' media-type='text/javascript' />
<item id='readk_it_js_lib_zip_zip-fs_js' href='readk.it/js/lib/zip/zip-fs.js' media-type='text/javascript' />
<item id='readk_it_js_lib_zip_zip_js' href='readk.it/js/lib/zip/zip.js' media-type='text/javascript' />
<!-- './readk.it/js/test' -->
<item id='readk_it_js_test_index_html' href='readk.it/js/test/index.html' media-type='text/html' />
<item id='readk_it_js_test_testsuite_js' href='readk.it/js/test/testsuite.js' media-type='text/javascript' />
<!-- './readk.it/js/test/app' -->
<item id='readk_it_js_test_app_epub_test_js' href='readk.it/js/test/app/epub.test.js' media-type='text/javascript' />
<!-- './readk.it/js/test/qunit' -->
<item id='readk_it_js_test_qunit_qunit_css' href='readk.it/js/test/qunit/qunit.css' media-type='text/plain' />
<item id='readk_it_js_test_qunit_qunit_js' href='readk.it/js/test/qunit/qunit.js' media-type='text/javascript' />
*/}.toString().match(/[^]*\/\*([^]*)\*\/\}$/)[1]
}
},
src: [opf_path_dest]
});
// Assemble data URIs for use in the solo version
grunt.config('readkit_datauris.' + identifier, {
options: {
base: '<%= epub_src %>/' + path
},
src: ['<%= epub_src %>/' + path + 'META-INF/container.xml', opf_path_src, '<%= readkit_dom_munger.data.manifestRefs %>'],
dest: 'build/readkit/js/app/content.js'
});
// Zip up our EPUB assets into an EPUB file.
grunt.config('shell.' + identifier + '_zip', {
command: [
'echo Zipping ' + identifier + '_' + name + '.epub to <%= grunt.config(\'shell.' + identifier + '_set_pwd.pwd\') %>/dist',
'cd dist/readkit.epub/' + path,
'echo Zipping ' + identifier + '_' + name + '.epub...',
'zip -X0 ' + identifier + '_' + name + '.epub mimetype -x ._',
'zip -rDX9 ' + identifier + '_' + name + '.epub META-INF -x *.DS_Store -x ._*',
'zip -rDX9 ' + identifier + '_' + name + '.epub ' + oebps + ' -x *.DS_Store -x ._*',
].join('&&'),
options: {
stdout: true,
stderr: true
}
});
// Move the EPUB file to the top level of the readkit.epub directory.
grunt.config('shell.' + identifier + '_mv', {
command: [
'mv dist/readkit.epub/' + path + identifier + '_' + name + '.epub dist/readkit.epub',
'echo Zipped ' + identifier + '_' + name + '.epub to dist'
].join('&&'),
options: {
stdout: true,
stderr: true
}
});
// Zip up our solo file.
grunt.config('shell.' + identifier + '_zip_solo', {
command: [
'echo Zipping ' + identifier + '_' + name + '.html...',
'cd dist/readkit.solo/',
'zip -DX9 ' + identifier + '_' + name + '.zip ' + identifier + '_' + name + '.html',
].join('&&'),
options: {