forked from Nekocoder3/chappe
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
1790 lines (1519 loc) Β· 40.8 KB
/
gulpfile.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
/*
* chappe
*
* Copyright 2021, Crisp IM SAS
* Author: Valerian Saliou <valerian@valeriansaliou.name>
*/
var fs = require("fs");
var path = require("path");
var lodash = require("lodash");
var del = require("del");
var glob = require("glob");
var merge = require("merge-stream");
var compass_importer = require("compass-importer");
var marked = require("marked").marked;
var remove_markdown = require("@tommoor/remove-markdown");
var MiniSearch = require("minisearch");
var Feed = require("feed").Feed;
var gulp = require("gulp");
var gulp_connect = require("gulp-connect");
var gulp_file = require("gulp-file");
var gulp_bower = require("gulp-bower");
var gulp_jade = require("gulp-jade");
var gulp_sass = require("gulp-sass")(require("node-sass"));
var gulp_inline_image = require("gulp-inline-image");
var gulp_ogimage = require("gulp-ogimage");
var gulp_sass_variables = require("gulp-sass-variables");
var gulp_concat = require("gulp-concat");
var gulp_babel = require("gulp-babel");
var gulp_cssmin = require("gulp-cssmin");
var gulp_uglify = require("gulp-uglify");
var gulp_rename = require("gulp-rename");
var gulp_replace = require("gulp-replace");
var gulp_header = require("gulp-header");
var gulp_pug_lint = require("gulp-pug-lint");
var gulp_sass_lint = require("gulp-sass-lint");
var gulp_jshint = require("gulp-jshint");
var gulp_jscs = require("gulp-jscs");
var gulp_sizereport = require("gulp-sizereport");
var gulp_sitemap = require("gulp-sitemap");
var gulp_notify = require("gulp-notify");
var gulp_noop = require("gulp-noop");
var package = require("./package.json");
var gulp_jade_templates = require("./res/plugins/gulp/jade-templates");
var gulp_minisearch = require("./res/plugins/gulp/minisearch");
var marked_renderers = {
heading : require("./res/plugins/marked/renderers/heading"),
code : require("./res/plugins/marked/renderers/code")
};
var marked_extensions = {
navigation : require("./res/plugins/marked/extensions/navigation"),
navigation_item : require("./res/plugins/marked/extensions/navigation-item"),
emphasis : require("./res/plugins/marked/extensions/emphasis"),
figcaption : require("./res/plugins/marked/extensions/figcaption"),
embed : require("./res/plugins/marked/extensions/embed")
};
// Global context
var PARENT_CONTEXT = (
(typeof global.CONTEXT !== "undefined") ? global.CONTEXT : {}
);
var CONTEXT = {
// Data
CONFIG : {},
SEARCH_INDEX : null,
// Configurations
PATH_CONFIG : (
PARENT_CONTEXT.config ? PARENT_CONTEXT.config.split(",") : null
),
PATH_ASSETS : (PARENT_CONTEXT.assets || null),
PATH_DATA : (PARENT_CONTEXT.data || null),
PATH_TEMP : (PARENT_CONTEXT.temp || null),
PATH_DIST : (PARENT_CONTEXT.dist || null),
SERVE_HOST : (PARENT_CONTEXT.host || null),
SERVE_PORT : (PARENT_CONTEXT.port || null),
PATH_CHAPPE : null,
PATH_SOURCES : null,
PATH_LIBRARIES : null,
PATH_BUILD_PAGES : null,
PATH_BUILD_ASSETS : null,
IS_PRODUCTION : ((PARENT_CONTEXT.env === "production") ? true : false),
IS_WATCH : false
};
// Initializers
marked.use({
renderer : {
heading : marked_renderers.heading,
code : marked_renderers.code
},
extensions : [
marked_extensions.navigation,
marked_extensions.navigation_item,
marked_extensions.emphasis,
marked_extensions.figcaption,
marked_extensions.embed
]
});
// Tasks
/*
Acquires the configuration
*/
var get_configuration = function(next) {
// Assert that all paths are set
if (CONTEXT.PATH_CONFIG === null || CONTEXT.PATH_ASSETS === null ||
CONTEXT.PATH_DATA === null || CONTEXT.PATH_TEMP === null ||
CONTEXT.PATH_DIST === null) {
throw new Error(
"A build path was not passed properly, please pass them as globals"
);
}
// Make sure that the config and data paths exist
// Notice: do not check the 'temp' and 'dist' path, as they will get \
// auto-created.
if (fs.existsSync(CONTEXT.PATH_ASSETS) !== true) {
throw new Error("The assets path provided does not exist!");
}
if (fs.existsSync(CONTEXT.PATH_DATA) !== true) {
throw new Error("The data path provided does not exist!");
}
CONTEXT.PATH_CONFIG.forEach(function(config_path) {
if (fs.existsSync(config_path) !== true) {
throw new Error(
"One of the configuration path provided does not exist!"
);
}
});
// Initialize final source paths
CONTEXT.PATH_CHAPPE = __dirname;
CONTEXT.PATH_SOURCES = path.join(CONTEXT.PATH_CHAPPE, "./src");
CONTEXT.PATH_LIBRARIES = path.join(CONTEXT.PATH_TEMP, "./lib");
// Initialize final build paths
CONTEXT.PATH_BUILD_PAGES = CONTEXT.PATH_DIST;
CONTEXT.PATH_BUILD_ASSETS = (CONTEXT.PATH_DIST + "/static");
// Read atomic configurations (merge them together)
var _merge_pipeline = [
// #1: Common configuration (project static)
require("./res/config/common.json"),
// #2: Site configuration (project defaults)
{
SITE : require("./res/config/user.json")
}
];
// Read vector configurations
CONTEXT.PATH_CONFIG.forEach(function(config_path) {
// #3: Site configuration (user-provided)
_merge_pipeline.push({
SITE : require(config_path)
});
});
// Unwind merge pipeline
_merge_pipeline.forEach(function(merge_object) {
CONTEXT.CONFIG = lodash.merge(CONTEXT.CONFIG, merge_object);
});
// Assign contextual values
CONTEXT.CONFIG.ENVIRONMENT = (
(CONTEXT.IS_PRODUCTION === true) ? "production" : "development"
);
CONTEXT.CONFIG.REVISION = (
"v" + (package.version || "0.0.0")
);
next();
};
/*
Installs bower packages
*/
var bower = function() {
return gulp_bower({
directory : CONTEXT.PATH_LIBRARIES,
cwd : CONTEXT.PATH_CHAPPE,
verbosity : 1
});
};
/*
Copies all user assets
*/
var copy_user_assets = function() {
return gulp.src(
CONTEXT.PATH_ASSETS + "/**/*"
)
.pipe(
gulp.dest(
CONTEXT.PATH_BUILD_ASSETS + "/user"
)
);
};
/*
Copies images (base images)
*/
var copy_images_base = function() {
return gulp.src(
CONTEXT.PATH_SOURCES + "/images/**/*"
)
.pipe(
gulp.dest(
CONTEXT.PATH_BUILD_ASSETS + "/images"
)
)
.pipe(
gulp_connect.reload()
);
};
/*
Copies images (guides images)
*/
var copy_images_guides = function() {
return gulp.src(
CONTEXT.PATH_DATA + "/guides/**/*.{jpg,jpeg,png,gif}"
)
.pipe(
gulp.dest(
CONTEXT.PATH_BUILD_ASSETS + "/images/guides/content"
)
)
.pipe(
gulp_connect.reload()
);
};
/*
Copies all images (shell task to aggregate sub-tasks)
*/
var copy_images_all = function() {
return gulp.parallel(
copy_images_base,
copy_images_guides
);
}();
/*
Copies fonts
*/
var copy_fonts = function() {
return gulp.src(
CONTEXT.PATH_SOURCES + "/fonts/**/*"
)
.pipe(
gulp.dest(
CONTEXT.PATH_BUILD_ASSETS + "/fonts"
)
)
.pipe(
gulp_connect.reload()
);
};
/*
Concats javascript libraries
*/
var concat_libraries_javascripts = function() {
// Acquire targets
// Notice: append user-defined syntaxes for code coloring (from 'prism.js')
var _targets = CONTEXT.CONFIG.LIBRARIES.JAVASCRIPTS.map(function(library) {
return (CONTEXT.PATH_LIBRARIES + "/" + library);
});
CONTEXT.CONFIG.SITE.plugins.code.syntaxes.forEach(function(syntax) {
var _syntax_path = (
CONTEXT.PATH_LIBRARIES + "/prism.js/components/prism-" + syntax + ".js"
);
if (fs.existsSync(_syntax_path) !== true) {
throw new Error(
"Unsupported code syntax plugin provided: " + syntax + " at path: " +
_syntax_path
);
}
_targets.push(_syntax_path);
});
return gulp.src(_targets)
.pipe(
gulp_concat("common/libs.js")
)
.pipe(
gulp_replace(
"manual: _self.Prism && _self.Prism.manual,", "manual: true,"
)
)
.pipe(
gulp.dest(
CONTEXT.PATH_BUILD_ASSETS + "/javascripts"
)
);
};
/*
Concats stylesheet libraries
*/
var concat_libraries_stylesheets = function() {
return gulp.src(
CONTEXT.CONFIG.LIBRARIES.STYLESHEETS.map(function(library) {
return (CONTEXT.PATH_LIBRARIES + "/" + library);
})
)
.pipe(
gulp_concat("common/libs.css")
)
.pipe(
gulp.dest(
CONTEXT.PATH_BUILD_ASSETS + "/stylesheets"
)
);
};
/*
Prepares Minisearch search index (before it gets populated)
*/
var minisearch_prepare = function(next) {
// Initialize search index
CONTEXT.SEARCH_INDEX = new MiniSearch(
CONTEXT.CONFIG.SEARCH.OPTIONS.BASE
);
next();
};
/*
Consolidates Minisearch search index (after it was populated)
*/
var minisearch_consolidate = function() {
// Generate search index data
return gulp_file(
("./" + CONTEXT.CONFIG.SEARCH.INDEX),
JSON.stringify(CONTEXT.SEARCH_INDEX),
{
src : true
}
)
.pipe(
gulp.dest(
CONTEXT.PATH_BUILD_ASSETS + "/data"
)
);
};
/*
Compiles Jade templates (base templates)
*/
var jade_templates_base = function() {
var _stream = merge();
gulp_jade_templates.list_config_locales(CONTEXT, package, marked)
.forEach(function(jade_data) {
_stream.add(
gulp_jade_templates.pipe_commons(CONTEXT, jade_data.locale, function() {
return gulp.src(
CONTEXT.CONFIG.SOURCES.TEMPLATES.map(function(template) {
return (CONTEXT.PATH_SOURCES + "/templates/" + template);
}),
{
base : (CONTEXT.PATH_SOURCES + "/templates")
}
)
.pipe(
gulp_jade(jade_data.config)
);
})
.pipe(
gulp.dest(
CONTEXT.PATH_BUILD_PAGES
)
)
.pipe(
gulp_connect.reload()
)
);
});
return _stream;
};
/*
Compiles Jade templates (guides templates)
*/
var jade_templates_guides = function() {
var _stream = merge();
// Acquire the guides meta-data
// Format: { \
// segments<array>, id<string>, title<string>, index<int>, links<array>, \
// updated<date>, markdown<string>, parent<object>, subtrees<array> \
// }
// Output: [tree<array>, linear<array>]
var _guide_meta_data = (
gulp_jade_templates.traverse_guides_tree(CONTEXT.PATH_DATA + "/guides")
);
var _guide_meta_tree = _guide_meta_data[0],
_guide_meta_linear = _guide_meta_data[1];
// Append all guides to search index
var _categories = _guide_meta_tree[0];
if (_categories) {
gulp_minisearch.insert_categories(
CONTEXT, "guides", [_categories.title], (_categories.subtrees || [])
);
}
// Compile all guide pages
gulp_jade_templates.list_config_locales(CONTEXT, package, marked)
.forEach(function(jade_data) {
_guide_meta_linear.forEach(function(guide_level) {
// Generate current guide data (for locale)
var jade_level_config = lodash.cloneDeep(jade_data.config);
jade_level_config.data.guides = _guide_meta_tree;
jade_level_config.data.guide = guide_level;
// Forbid indexing? (if any entry segment starts with an underscore)
var _segment_private_index = guide_level.segments.findIndex(
function(segment) {
return ((segment[0] === "_") ? true : false);
}
);
if (_segment_private_index !== -1) {
jade_level_config.data.INDEXING = false;
}
_stream.add(
gulp_jade_templates.pipe_commons(
CONTEXT, jade_data.locale, function() {
return gulp.src(
(CONTEXT.PATH_SOURCES + "/templates/guides/index.jade"),
{
base : (CONTEXT.PATH_SOURCES + "/templates")
}
)
.pipe(
gulp_jade(jade_level_config)
)
.pipe(
gulp_rename(function(file_path) {
file_path.basename = path.join.apply(this, [].concat(
guide_level.segments, ["index"]
));
})
);
}
)
.pipe(
gulp.dest(
CONTEXT.PATH_BUILD_PAGES
)
)
);
});
});
return _stream;
};
/*
Compiles Jade templates (references templates)
*/
var jade_templates_references = function() {
var _stream = merge();
// Acquire the parsed references content
// Format: {segments<array>, type<string>, data<object>}
// Output: linear<array>
var _reference_meta_data = (
gulp_jade_templates.traverse_references_linear(
CONTEXT, (CONTEXT.PATH_DATA + "/references")
)
);
gulp_jade_templates.list_config_locales(CONTEXT, package, marked)
.forEach(function(jade_data) {
_reference_meta_data.forEach(function(reference_entry) {
// Generate current reference data (for locale)
var jade_entry_config = lodash.cloneDeep(jade_data.config);
jade_entry_config.data.reference = reference_entry;
// Forbid indexing? (if any entry segment starts with an underscore)
var _segment_private_index = reference_entry.segments.findIndex(
function(segment) {
return ((segment[0] === "_") ? true : false);
}
);
if (_segment_private_index !== -1) {
jade_entry_config.data.INDEXING = false;
}
// Append all reference anchors to search index
// Important: only if reference indexing is not forbidden
if (reference_entry.categories &&
jade_entry_config.data.INDEXING !== false) {
// Acquire reference path, as well as reference path title (with \
// its common suffix extracted)
// Notice: 'REST API Reference (V1)' becomes 'REST API' + 'V1'
var _reference_path = ["References"],
_title_split_regex = /^(.+) Reference \(([^\(\)]+)\)$/;
var _title_matcher = (
reference_entry.title.match(_title_split_regex)
);
var _reference_title_path = (
(_title_matcher && _title_matcher[1] && _title_matcher[2]) ?
[_title_matcher[1], _title_matcher[2]] : [reference_entry.title]
);
// Insert reference base
gulp_minisearch.insert_categories(
CONTEXT, "references", _reference_path, [reference_entry]
);
// Insert reference sub-categories
gulp_minisearch.insert_categories(
CONTEXT, "references",
[].concat(_reference_path, _reference_title_path),
reference_entry.categories, reference_entry.segments
);
}
_stream.add(
gulp_jade_templates.pipe_commons(
CONTEXT, jade_data.locale, function() {
return gulp.src(
(CONTEXT.PATH_SOURCES + "/templates/references/index.jade"),
{
base : (CONTEXT.PATH_SOURCES + "/templates")
}
)
.pipe(
gulp_jade(jade_entry_config)
)
.pipe(
gulp_rename(function(file_path) {
file_path.basename = path.join.apply(this, [].concat(
reference_entry.segments, ["index"]
));
})
);
}
)
.pipe(
gulp.dest(
CONTEXT.PATH_BUILD_PAGES
)
)
.pipe(
gulp_connect.reload()
)
);
});
});
return _stream;
};
/*
Compiles Jade templates (changes templates)
*/
var jade_templates_changes = function() {
var _stream = merge();
// Acquire the change years data
// Format: [year<int>, data<object>] (ordered by most recent year first)
var _change_years = (
glob.sync(
(CONTEXT.PATH_DATA + "/changes/*.json")
)
.sort()
.reverse()
.map(function(file_path) {
var _file_path_parts = path.parse(file_path);
return [
parseInt(_file_path_parts.name, 10),
JSON.parse(fs.readFileSync(file_path))
];
})
.map(function(year_data) {
// Classify each change in its month (in an orderly manner)
// Notice: the Map object is used as it retains natural ordering, \
// where last months come first.
var _year_months = new Map();
year_data[1].forEach(function(entry) {
// Validate entry data
if (!entry.group || !entry.type || !entry.date || !entry.text) {
throw new Error(
"Invalid entry data in changes for year: " + year_data[0]
);
}
// Acquire entry date
var _entry_date = (new Date(entry.date));
if (!_entry_date || isNaN(_entry_date.getTime())) {
throw new Error(
"Invalid date in changes for year: " + year_data[0]
);
}
// Acquire entry month key
var _entry_month_key = ("" + (_entry_date.getMonth() + 1));
if (_entry_month_key.length === 1) {
_entry_month_key = ("0" + _entry_month_key);
}
// Make sure entries object for month is initialized
if (_year_months.has(_entry_month_key) === false) {
_year_months.set(_entry_month_key, []);
}
// Append entry to month entries object
_year_months.get(_entry_month_key).push(entry);
});
// Assign new per-month data
// Important: convert back all ordered map entries to an array, which \
// we can iterate on right away from templates.
year_data[1] = Array.from(
_year_months.entries()
);
return year_data;
})
);
// Map available change years (as bare numbers)
// Important: before prepending latest year data
var _available_bare_years = _change_years.map(function(change_year) {
return change_year[0];
});
// Prepend list of years with the 'latest' year (ie. corresponding to the \
// 'index'), and push only the first 3 months (ie. latest)
var _first_change_year = (_change_years[0] || []);
_change_years.unshift([
(_first_change_year[0] || -1),
(_first_change_year[1] || []).slice(0, 3),
"index"
]);
gulp_jade_templates.list_config_locales(CONTEXT, package, marked)
.forEach(function(jade_data) {
_change_years.forEach(function(change_year) {
// Generate current year data (for locale)
var jade_year_config = lodash.cloneDeep(jade_data.config);
jade_year_config.data.years = _available_bare_years;
jade_year_config.data.changes = {
year : change_year[0],
current : (
(change_year[2] === "index") ? "latest" : change_year[0]
),
timeline : change_year[1]
};
_stream.add(
gulp_jade_templates.pipe_commons(
CONTEXT, jade_data.locale, function() {
return gulp.src(
(CONTEXT.PATH_SOURCES + "/templates/changes/index.jade"),
{
base : (CONTEXT.PATH_SOURCES + "/templates")
}
)
.pipe(
gulp_jade(jade_year_config)
)
.pipe(
gulp_rename(function(file_path) {
file_path.basename = (
change_year[2] ? change_year[2] : (
path.join(("" + change_year[0]), "index")
)
);
})
);
}
)
.pipe(
gulp.dest(
CONTEXT.PATH_BUILD_PAGES
)
)
.pipe(
gulp_connect.reload()
)
);
});
});
return _stream;
};
/*
Compiles all Jade templates (shell task to aggregate sub-tasks)
*/
var jade_templates_all = function() {
return gulp.parallel(
jade_templates_base,
jade_templates_guides,
jade_templates_references,
jade_templates_changes
);
}();
/*
Compiles SASS stylesheets
*/
var sass = function() {
return gulp.src(
CONTEXT.CONFIG.SOURCES.STYLESHEETS.map(function(stylesheet) {
return (CONTEXT.PATH_SOURCES + "/stylesheets/" + stylesheet);
}),
{
base : (CONTEXT.PATH_SOURCES + "/stylesheets")
}
)
.pipe(
gulp_sass_variables({
"$with-inline-images" : CONTEXT.IS_PRODUCTION,
"$cache-buster-hash" : CONTEXT.CONFIG.REVISION
})
)
.pipe(
gulp_sass({
outputStyle : "expanded",
importer : compass_importer
})
)
.on("error", gulp_notify.onError({
title : "sass",
message : "Error compiling",
emitError : true
}))
.on("error", function(error) {
if (CONTEXT.IS_WATCH === true) {
// Handle compile errors (used for development ease w/ `gulp watch`)
console.error(error.toString());
} else {
throw error;
}
})
.pipe(
gulp.dest(
CONTEXT.PATH_BUILD_ASSETS + "/stylesheets"
)
);
};
/*
Imports inline images in stylesheets
*/
var css_inline_images = function() {
return gulp.src((
CONTEXT.PATH_BUILD_ASSETS + "/stylesheets/**/*.css"
), {
base : (CONTEXT.PATH_BUILD_ASSETS + "/images")
})
.pipe(
gulp_inline_image()
)
.pipe(
gulp.dest(
CONTEXT.PATH_BUILD_ASSETS + "/stylesheets"
)
)
.pipe(
gulp_connect.reload()
);
};
/*
Compiles Babel templates
*/
var babel = function() {
return gulp.src(
CONTEXT.CONFIG.SOURCES.JAVASCRIPTS.map(function(javascript) {
return (CONTEXT.PATH_SOURCES + "/javascripts/" + javascript);
}),
{
base : (CONTEXT.PATH_SOURCES + "/javascripts")
}
)
.pipe(
gulp_babel()
)
.on("error", gulp_notify.onError({
title : "babel",
message : "Error compiling",
emitError : true
}))
.on("error", function(error) {
if (CONTEXT.IS_WATCH === true) {
// Handle compile errors (used for development ease w/ `gulp watch`)
console.error(error.toString());
} else {
throw error;
}
})
.pipe(
gulp.dest(
CONTEXT.PATH_BUILD_ASSETS + "/javascripts"
)
);
};
/*
Replaces values from template files (guides templates)
*/
var replace_templates_guides = function() {
return gulp.src(
CONTEXT.PATH_BUILD_PAGES + "/guides/**/*.html"
)
.pipe(
gulp_replace(
/src="(?:\.\/)?([^\.\/"']+\.(?:jpg|jpeg|png|gif))"/g,
function(_, file_name) {
// Acquire base path segments
var _image_base_segments = this.file.relative.split("/");
_image_base_segments.pop();
// Build final path segments
var _image_final_segments = (
[].concat(
["", "static", "images", "guides", "content"],
_image_base_segments,
[file_name]
)
);
// Replace with final path to image file within static assets
return (
"src=\"" + _image_final_segments.join("/") + "\""
);
}
)
)
.pipe(
gulp.dest(
CONTEXT.PATH_BUILD_PAGES + "/guides"
)
)
.pipe(
gulp_connect.reload()
);
};
/*
Replaces values from javascript files
*/
var replace_javascripts = function() {
return gulp.src(
CONTEXT.PATH_BUILD_ASSETS + "/javascripts/**/*.js"
)
.pipe(
gulp_replace(
"@:revision", CONTEXT.CONFIG.REVISION
)
)
.pipe(
gulp_replace(
"\"@:url_status\"",
JSON.stringify({
provider : (
CONTEXT.CONFIG.SITE.urls.vigil ? "vigil" : (
CONTEXT.CONFIG.SITE.urls.crisp_status ? "crisp" : null
)
),
target : (
CONTEXT.CONFIG.SITE.urls.vigil ||
CONTEXT.CONFIG.SITE.urls.crisp_status || null
)
})
)
)
.pipe(
gulp_replace(
"@:search_index", CONTEXT.CONFIG.SEARCH.INDEX
)
)
.pipe(
gulp_replace(
"\"@:search_options_base\"",
JSON.stringify(CONTEXT.CONFIG.SEARCH.OPTIONS.BASE)
)
)
.pipe(
gulp_replace(
"\"@:search_options_query\"",
JSON.stringify(CONTEXT.CONFIG.SEARCH.OPTIONS.QUERY)
)
)
.pipe(
gulp.dest(
CONTEXT.PATH_BUILD_ASSETS + "/javascripts"
)
)
.pipe(
gulp_connect.reload()
);
};
/*
Compiles feeds (changes templates)
*/
var feed_changes = function() {
var _title_maximum_length = 80;
// Acquire paths for the last 3 years (sort by last year first)
var _feed_years_back = 3;
var _last_year_paths = glob.sync(
(CONTEXT.PATH_DATA + "/changes/*.json")
)
.sort()
.reverse()
.splice(0, _feed_years_back);
// Acquire the change years data
var _change_years = (
_last_year_paths.map(function(file_path) {
return JSON.parse(
fs.readFileSync(file_path)