Commit 033c5ad868e33e9f655dfc6c3934774cefbefb6e

Michael Schmidt 2019-07-19T16:20:45

gulp: Split gulpfile.js and expanded `changes` task (#1835) This splits the `gulpfile.js` files into multiple files and expands the `changes` tasks to generate a commit-based changelog.

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
diff --git a/gulpfile.js b/gulpfile.js
deleted file mode 100644
index 9c09a76..0000000
--- a/gulpfile.js
+++ /dev/null
@@ -1,272 +0,0 @@
-const { src, dest, series, parallel, watch } = require('gulp');
-
-const rename = require('gulp-rename');
-const uglify = require('gulp-uglify');
-const header = require('gulp-header');
-const concat = require('gulp-concat');
-const replace = require('gulp-replace');
-const pump = require('pump');
-const util = require('util');
-const fs = require('fs');
-const simpleGit = require('simple-git');
-const shelljs = require('shelljs');
-
-const paths = {
-	componentsFile: 'components.json',
-	componentsFileJS: 'components.js',
-	components: ['components/**/*.js', '!components/index.js', '!components/**/*.min.js'],
-	main: [
-		'components/prism-core.js',
-		'components/prism-markup.js',
-		'components/prism-css.js',
-		'components/prism-clike.js',
-		'components/prism-javascript.js',
-		'plugins/file-highlight/prism-file-highlight.js'
-	],
-	plugins: ['plugins/**/*.js', '!plugins/**/*.min.js'],
-	showLanguagePlugin: 'plugins/show-language/prism-show-language.js',
-	autoloaderPlugin: 'plugins/autoloader/prism-autoloader.js',
-	changelog: 'CHANGELOG.md'
-};
-
-const componentsPromise = new Promise((resolve, reject) => {
-	fs.readFile(paths.componentsFile, {
-		encoding: 'utf-8'
-	}, (err, data) => {
-		if (!err) {
-			resolve(JSON.parse(data));
-		} else {
-			reject(err);
-		}
-	});
-});
-
-function inlineRegexSource() {
-	return replace(
-		/\/((?:[^\n\r[\\\/]|\\.|\[(?:[^\n\r\\\]]|\\.)*\])*)\/\.source\b/g,
-		(m, source) => {
-			// escape backslashes
-			source = source.replace(/\\/g, '\\\\');
-			// escape single quotes
-			source = source.replace(/'/g, "\\'");
-			// unescape characters like \\n and \\t to \n and \t
-			source = source.replace(/(^|[^\\])\\\\([nrt0])/g, '$1\\$2');
-			// wrap source in single quotes
-			return "'" + source + "'";
-		}
-	);
-}
-
-function minifyJS() {
-	return [
-		inlineRegexSource(),
-		uglify()
-	];
-}
-
-
-function minifyComponents(cb) {
-	pump([src(paths.components), ...minifyJS(), rename({ suffix: '.min' }), dest('components')], cb);
-}
-function minifyPlugins(cb) {
-	pump([src(paths.plugins), ...minifyJS(), rename({ suffix: '.min' }), dest('plugins')], cb);
-}
-function build(cb) {
-	pump([src(paths.main), header(`
-/* **********************************************
-     Begin <%= file.relative %>
-********************************************** */
-
-`), concat('prism.js'), dest('./')], cb);
-}
-
-async function componentsJsonToJs() {
-	const data = await componentsPromise;
-	const js = `var components = ${JSON.stringify(data)};
-if (typeof module !== 'undefined' && module.exports) { module.exports = components; }`;
-	return util.promisify(fs.writeFile)(paths.componentsFileJS, js);
-}
-
-function watchComponentsAndPlugins() {
-	watch(paths.components, parallel(minifyComponents, build));
-	watch(paths.plugins, parallel(minifyPlugins, build));
-}
-
-async function languagePlugins() {
-	const data = await componentsPromise;
-	const languagesMap = {};
-	const dependenciesMap = {};
-	const aliasMap = {};
-
-	/**
-	 * Tries to guess the name of a language given its id.
-	 *
-	 * From `prism-show-language.js`.
-	 *
-	 * @param {string} id The language id.
-	 * @returns {string}
-	 */
-	function guessTitle(id) {
-		if (!id) {
-			return id;
-		}
-		return (id.substring(0, 1).toUpperCase() + id.substring(1)).replace(/s(?=cript)/, 'S');
-	}
-
-	/**
-	 * @param {string} key
-	 * @param {string} title
-	 */
-	function addLanguageTitle(key, title) {
-		if (!languagesMap[key] && guessTitle(key) !== title) {
-			languagesMap[key] = title;
-		}
-	}
-
-	for (const id in data.languages) {
-		if (id !== 'meta') {
-			const language = data.languages[id];
-			const title = language.displayTitle || language.title;
-
-			addLanguageTitle(id, title);
-
-			for (const name in language.aliasTitles) {
-				addLanguageTitle(name, language.aliasTitles[name]);
-			}
-
-			if (language.alias) {
-				if (typeof language.alias === 'string') {
-					aliasMap[language.alias] = id;
-					addLanguageTitle(language.alias, title);
-				} else {
-					language.alias.forEach(function (alias) {
-						aliasMap[alias] = id;
-						addLanguageTitle(alias, title);
-					});
-				}
-			}
-
-			if (language.require) {
-				dependenciesMap[id] = language.require;
-			}
-		}
-	}
-
-	function formattedStringify(json) {
-		return JSON.stringify(json, null, '\t').replace(/\n/g, '\n\t');
-	}
-
-	const jsonLanguagesMap = formattedStringify(languagesMap);
-	const jsonDependenciesMap = formattedStringify(dependenciesMap);
-	const jsonAliasMap = formattedStringify(aliasMap);
-
-	const tasks = [
-		{
-			plugin: paths.showLanguagePlugin,
-			maps: { languages: jsonLanguagesMap}
-		},
-		{
-			plugin: paths.autoloaderPlugin,
-			maps: { aliases: jsonAliasMap, dependencies: jsonDependenciesMap }
-		}
-	];
-
-	// TODO: Use `Promise.allSettled` (https://github.com/tc39/proposal-promise-allSettled)
-	const taskResults = await Promise.all(tasks.map(task => new Promise((resolve, reject) => {
-		const stream = src(task.plugin)
-			.pipe(replace(
-				/\/\*(\w+)_placeholder\[\*\/[\s\S]*?\/\*\]\*\//g,
-				(m, mapName) => `/*${mapName}_placeholder[*/${task.maps[mapName]}/*]*/`
-			))
-			.pipe(dest(task.plugin.substring(0, task.plugin.lastIndexOf('/'))));
-
-		stream.on('error', reject);
-		stream.on('end', resolve);
-	}).then(
-		/** @type {<T>(value: T) => {status: 'fulfilled', value: T}} */ value => ({status: 'fulfilled', value}),
-		/** @type {<T>(error: T) => {status: 'rejected', reason: T}} */ error => ({status: 'rejected', reason: error}),
-	)));
-
-	const rejectedTasks = taskResults.filter(/** @return {r is {status: 'rejected', reason: any}} */ r => r.status === 'rejected');
-	if (rejectedTasks.length > 0) {
-		throw rejectedTasks.map(r => r.reason);
-	}
-}
-
-const ISSUE_RE = /#(\d+)(?![\d\]])/g;
-const ISSUE_SUB = '[#$1](https://github.com/PrismJS/prism/issues/$1)';
-
-function linkify(cb) {
-	return pump([
-		src(paths.changelog),
-		replace(ISSUE_RE, ISSUE_SUB),
-		replace(
-			/\[[\da-f]+(?:, *[\da-f]+)*\]/g,
-			m => m.replace(/([\da-f]{7})[\da-f]*/g, '[`$1`](https://github.com/PrismJS/prism/commit/$1)')
-		),
-		dest('.')
-	], cb);
-}
-
-const COMMIT_RE = /^([\da-z]{8})\s(.*)/;
-
-function changes(cb) {
-	const tag = shelljs.exec('git describe --abbrev=0 --tags', { silent: true }).stdout;
-	const commits = shelljs
-		.exec(
-			`git log ${tag.trim()}..HEAD --oneline`,
-			{ silent: true }
-		)
-		.stdout.split('\n')
-		.map(line => line.trim())
-		.filter(line => line !== '')
-		.map(line => {
-			const [,hash, msg] = COMMIT_RE.exec(line);
-			return `* ${msg.replace(ISSUE_RE, ISSUE_SUB)} [\`${hash}\`](https://github.com/PrismJS/prism/commit/${hash})`
-		})
-		.join('\n');
-
-	const changes = `## Unreleased
-
-${commits}
-
-### New components
-
-### Updated components
-
-### Updated plugins
-
-### Updated themes
-
-### Other changes
-
-* __Website__`;
-
-	console.log(changes);
-	cb();
-}
-
-const components = minifyComponents;
-const plugins = series(languagePlugins, minifyPlugins);
-
-function gitChanges(cb) {
-	const git = simpleGit(__dirname);
-
-	git.status((err, res) => {
-		if (err) {
-			cb(new Error(`Something went wrong!\n${err}`));
-		} else if (res.files.length > 0) {
-			console.log(res);
-			cb(new Error('There are changes in the file system. Did you forget to run gulp?'));
-		} else {
-			cb();
-		}
-	});
-}
-
-
-exports.watch = watchComponentsAndPlugins;
-exports.default = parallel(components, plugins, componentsJsonToJs, build);
-exports.premerge = gitChanges;
-exports.linkify = linkify;
-exports.changes = changes;
diff --git a/gulpfile.js/changelog.js b/gulpfile.js/changelog.js
new file mode 100644
index 0000000..1fb9fe1
--- /dev/null
+++ b/gulpfile.js/changelog.js
@@ -0,0 +1,381 @@
+"use strict";
+
+const { src, dest } = require('gulp');
+
+const replace = require('gulp-replace');
+const pump = require('pump');
+const git = require('simple-git/promise')(__dirname);
+
+const { changelog } = require('./paths');
+
+
+const ISSUE_RE = /#(\d+)(?![\d\]])/g;
+const ISSUE_SUB = '[#$1](https://github.com/PrismJS/prism/issues/$1)';
+
+function linkify(cb) {
+	return pump([
+		src(changelog),
+		replace(ISSUE_RE, ISSUE_SUB),
+		replace(
+			/\[[\da-f]+(?:, *[\da-f]+)*\]/g,
+			m => m.replace(/([\da-f]{7})[\da-f]*/g, '[`$1`](https://github.com/PrismJS/prism/commit/$1)')
+		),
+		dest('.')
+	], cb);
+}
+
+/**
+ * Creates an array which iterates its items in the order given by `compareFn`.
+ *
+ * The array may not be sorted at all times.
+ *
+ * @param {(a: T, b: T) => number} compareFn
+ * @returns {T[]}
+ * @template T
+ */
+function createSortedArray(compareFn) {
+	/** @type {T[]} */
+	const a = [];
+
+	a['sort'] = function () {
+		return Array.prototype.sort.call(this, compareFn);
+	};
+	a[Symbol.iterator] = function () {
+		return this.slice().sort(compareFn)[Symbol.iterator]();
+	};
+
+	return a;
+}
+
+/**
+ * Parses the given log line and adds the list of the changed files to the output.
+ *
+ * @param {string} line A one-liner log line consisting of the commit hash and the commit message.
+ * @returns {Promise<CommitInfo>}
+ *
+ * @typedef {{ message: string, hash: string, changes: CommitChange[] }} CommitInfo
+ * @typedef {{ file: string, mode: ChangeMode }} CommitChange
+ * @typedef {"A" | "C" | "D" | "M" | "R" | "T" | "U" | "X" | "B"} ChangeMode
+ */
+async function getCommitInfo(line) {
+	const [, hash, message] = /^([a-f\d]+)\s+(.*)$/i.exec(line);
+
+	/* The output looks like this:
+	 *
+	 * M       components.js
+	 * M       components.json
+	 *
+	 * or nothing for e.g. reverts.
+	 */
+	const output = await git.raw(['diff-tree', '--no-commit-id', '--name-status', '-r', hash]);
+
+	const changes = !output ? [] : output.trim().split(/\n/g).map(line => {
+		const [, mode, file] = /(\w)\s+(.+)/.exec(line);
+		return { mode: /** @type {ChangeMode} */ (mode), file };
+	});
+
+	return { hash, message, changes };
+}
+
+/**
+ * Parses the output of `git log` with the given revision range.
+ *
+ * @param {string | Promise<string>} range The revision range in which the log will be parsed.
+ * @returns {Promise<CommitInfo[]>}
+ */
+async function getLog(range) {
+	/* The output looks like this:
+	*
+	* bfbe4464 Invoke `callback` after `after-highlight` hook (#1588)
+	* b41fb8f1 Fixes regex for JS examples (#1591)
+	*/
+	const output = await git.raw(['log', await Promise.resolve(range), '--oneline']);
+
+	if (output) {
+		const commits = output.trim().split(/\n/g);
+		return Promise.all(commits.map(getCommitInfo));
+	} else {
+		return [];
+	}
+}
+
+const revisionRanges = {
+	nextRelease: git.raw(['describe', '--abbrev=0', '--tags']).then(res => `${res.trim()}..HEAD`)
+};
+const strCompare = (a, b) => a.localeCompare(b, 'en');
+
+async function changes() {
+	const { languages, plugins } = require('../components');
+
+	const infos = await getLog(revisionRanges.nextRelease);
+
+	const entries = {
+		'TODO:': {},
+		'New components': {
+			['']: createSortedArray(strCompare)
+		},
+		'Updated components': {},
+		'Updated plugins': {},
+		'Updated themes': {},
+		'Other': {},
+	};
+	/**
+	 *
+	 * @param {string} category
+	 * @param {string | { message: string, hash: string }} info
+	 */
+	function addEntry(category, info) {
+		const path = category.split(/\s*>>\s*/g);
+		if (path[path.length - 1] !== '') {
+			path.push('');
+		}
+
+		let current = entries;
+		for (const key of path) {
+			if (key) {
+				current = current[key] = current[key] || {};
+			} else {
+				(current[key] = current[key] || []).push(info);
+			}
+		}
+	}
+
+
+	/** @param {CommitChange} change */
+	function notGenerated(change) {
+		return !change.file.endsWith('.min.js') && ['prism.js', 'components.js', 'package-lock.json'].indexOf(change.file) === -1;
+	}
+	/** @param {CommitChange} change */
+	function notPartlyGenerated(change) {
+		return change.file !== 'plugins/autoloader/prism-autoloader.js' &&
+			change.file !== 'plugins/show-language/prism-show-language.js';
+	}
+	/** @param {CommitChange} change */
+	function notTests(change) {
+		return !/^tests\//.test(change.file);
+	}
+	/** @param {CommitChange} change */
+	function notExamples(change) {
+		return !/^examples\//.test(change.file);
+	}
+	/** @param {CommitChange} change */
+	function notFailures(change) {
+		return !/^known-failures.html$/.test(change.file);
+	}
+	/** @param {CommitChange} change */
+	function notComponentsJSON(change) {
+		return change.file !== 'components.json';
+	}
+
+	/**
+	 * @param {((e: T, index: number) => boolean)[]} filters
+	 * @returns {(e: T, index: number) => boolean}
+	 * @template T
+	 */
+	function and(...filters) {
+		return (e, index) => {
+			for (let i = 0, l = filters.length; i < l; i++) {
+				if (!filters[i](e, index)) {
+					return false;
+				}
+			}
+			return true;
+		};
+	}
+
+	/**
+	 * Some commit message have the format `component changed: actual message`.
+	 * This function can be used to remove this prefix.
+	 *
+	 * @param {string} prefix
+	 * @param {CommitInfo} info
+	 * @returns {{ message: string, hash: string }}
+	 */
+	function removeMessagePrefix(prefix, info) {
+		const source = String.raw`^${prefix.replace(/([^-\w\s])/g, '\\$1').replace(/[-\s]/g, '[-\\s]')}:\s*`;
+		const patter = RegExp(source, 'i');
+		return {
+			message: info.message.replace(patter, ''),
+			hash: info.hash
+		};
+	}
+
+
+	/**
+	 * @type {((info: CommitInfo) => boolean)[]}
+	 */
+	const commitSorters = [
+
+		function rebuild(info) {
+			if (info.changes.length > 0 && info.changes.filter(notGenerated).length === 0) {
+				console.log('Rebuild found: ' + info.message);
+				return true;
+			}
+		},
+
+		function addedComponent(info) {
+			let relevantChanges = info.changes.filter(and(notGenerated, notTests, notExamples, notFailures));
+
+			// `components.json` has to be modified
+			if (relevantChanges.some(c => c.file === 'components.json')) {
+				relevantChanges = relevantChanges.filter(and(notComponentsJSON, notPartlyGenerated));
+
+				// now, only the newly added JS should be left
+				if (relevantChanges.length === 1) {
+					const change = relevantChanges[0];
+					if (change.mode === 'A' && change.file.startsWith('components/prism-')) {
+						const lang = change.file.match(/prism-([\w-]+)\.js$/)[1];
+						const titles = [languages[lang].title];
+						if (languages[lang].aliasTitles) {
+							titles.push(...Object.values(languages[lang].aliasTitles));
+						}
+						addEntry('New components', `__${titles.join('__ & __')}__: ${infoToString(info)}`);
+						return true;
+					}
+				}
+			}
+		},
+
+		function changedComponentOrCore(info) {
+			let relevantChanges = info.changes.filter(and(notGenerated, notTests, notExamples, notFailures));
+
+			// if `components.json` changed, then autoloader and show-language also change
+			if (relevantChanges.some(c => c.file === 'components.json')) {
+				relevantChanges = relevantChanges.filter(and(notComponentsJSON, notPartlyGenerated));
+			}
+
+			if (relevantChanges.length === 1) {
+				const change = relevantChanges[0];
+				if (change.mode === 'M' && change.file.startsWith('components/prism-')) {
+					const lang = change.file.match(/prism-([\w-]+)\.js$/)[1];
+					if (lang === 'core') {
+						addEntry('Other >> Core', removeMessagePrefix('Core', info));
+					} else {
+						const title = languages[lang].title;
+						addEntry('Updated components >> ' + title, removeMessagePrefix(title, info));
+					}
+					return true;
+				}
+			}
+		},
+
+		function changedPlugin(info) {
+			let relevantChanges = info.changes.filter(and(notGenerated, notTests, notExamples, c => !/\.(?:html|css)$/.test(c.file)));
+
+			if (relevantChanges.length > 0 &&
+				relevantChanges.every(c => c.mode === 'M' && /^plugins\/.*\.js$/.test(c.file))) {
+
+				if (relevantChanges.length === 1) {
+					const change = relevantChanges[0];
+					const id = change.file.match(/\/prism-([\w-]+)\.js/)[1];
+					const title = plugins[id].title || plugins[id];
+					addEntry('Updated plugins >> ' + title, removeMessagePrefix(title, info));
+				} else {
+					addEntry('Updated plugins', info);
+				}
+				return true;
+			}
+		},
+
+		function changedTheme(info) {
+			if (info.changes.length > 0 && info.changes.every(c => {
+				return /themes\/.*\.css/.test(c.file) && c.mode === 'M';
+			})) {
+				if (info.changes.length === 1) {
+					const change = info.changes[0];
+					let name = (change.file.match(/prism-(\w+)\.css$/) || [, 'Default'])[1];
+					name = name[0].toUpperCase() + name.substr(1);
+					addEntry('Updated themes >> ' + name, removeMessagePrefix(name, info));
+				} else {
+					addEntry('Updated themes', info);
+				}
+				return true;
+			}
+		},
+
+		function changedInfrastructure(info) {
+			if (info.changes.length > 0 && info.changes.every(c => {
+				if (c.file.startsWith('gulpfile.js')) {
+					return true;
+				}
+				if (/^\.[\w.]+$/.test(c.file)) {
+					return true;
+				}
+				return ['CNAME', 'composer.json', 'package.json', 'package-lock.json'].indexOf(c.file) >= 0;
+			})) {
+				addEntry('Other >> Infrastructure', info);
+				return true;
+			}
+		},
+
+		function changedWebsite(info) {
+			if (info.changes.length > 0 && info.changes.every(c => {
+				if (/[\w-]+\.(?:html|svg)$/.test(c.file)) {
+					return true;
+				}
+				if (/^scripts(?:\/[\w-]+)*\/[\w-]+\.js$/.test(c.file)) {
+					return true;
+				}
+				return ['style.css'].indexOf(c.file) >= 0;
+			})) {
+				addEntry('Other >> Website', info);
+				return true;
+			}
+		},
+
+		function otherChanges(info) {
+			// detect changes of the Github setup
+			// This assumes that .md files are related to GitHub
+			if (info.changes.length > 0 && info.changes.every(c => /\.md$/i.test(c.file))) {
+				addEntry('Other', info);
+				return true;
+			}
+		},
+
+	];
+
+	for (const info of infos) {
+		if (!commitSorters.some(sorter => sorter(info))) {
+			addEntry('TODO:', info);
+		}
+	}
+
+
+	/**
+	 * Stringifies the given commit info.
+	 *
+	 * @param {string | CommitInfo} info
+	 * @returns {string}
+	 */
+	function infoToString(info) {
+		if (typeof info === 'string') {
+			return info;
+		}
+		return `${info.message} [\`${info.hash}\`](https://github.com/PrismJS/prism/commit/${info.hash})`;
+	}
+	function printCategory(category, indentation = '') {
+		for (const subCategory of Object.keys(category).sort(strCompare)) {
+			if (subCategory) {
+				md += `${indentation}* __${subCategory}__\n`;
+				printCategory(category[subCategory], indentation + '    ')
+			} else {
+				for (const info of category['']) {
+					md += `${indentation}* ${infoToString(info)}\n`;
+				}
+			}
+		}
+	}
+
+	let md = '';
+	for (const category of Object.keys(entries)) {
+		md += `\n### ${category}\n\n`;
+		printCategory(entries[category]);
+	}
+	console.log(md);
+}
+
+
+module.exports = {
+	linkify,
+	changes
+};
diff --git a/gulpfile.js/index.js b/gulpfile.js/index.js
new file mode 100644
index 0000000..14e8a19
--- /dev/null
+++ b/gulpfile.js/index.js
@@ -0,0 +1,197 @@
+"use strict";
+
+const { src, dest, series, parallel, watch } = require('gulp');
+
+const rename = require('gulp-rename');
+const uglify = require('gulp-uglify');
+const header = require('gulp-header');
+const concat = require('gulp-concat');
+const replace = require('gulp-replace');
+const pump = require('pump');
+const util = require('util');
+const fs = require('fs');
+
+const paths = require('./paths');
+const { premerge } = require('./premerge');
+const { changes, linkify } = require('./changelog');
+
+
+const componentsPromise = new Promise((resolve, reject) => {
+	fs.readFile(paths.componentsFile, {
+		encoding: 'utf-8'
+	}, (err, data) => {
+		if (!err) {
+			resolve(JSON.parse(data));
+		} else {
+			reject(err);
+		}
+	});
+});
+
+function inlineRegexSource() {
+	return replace(
+		/\/((?:[^\n\r[\\\/]|\\.|\[(?:[^\n\r\\\]]|\\.)*\])*)\/\.source\b/g,
+		(m, source) => {
+			// escape backslashes
+			source = source.replace(/\\/g, '\\\\');
+			// escape single quotes
+			source = source.replace(/'/g, "\\'");
+			// unescape characters like \\n and \\t to \n and \t
+			source = source.replace(/(^|[^\\])\\\\([nrt0])/g, '$1\\$2');
+			// wrap source in single quotes
+			return "'" + source + "'";
+		}
+	);
+}
+
+function minifyJS() {
+	return [
+		inlineRegexSource(),
+		uglify()
+	];
+}
+
+
+function minifyComponents(cb) {
+	pump([src(paths.components), ...minifyJS(), rename({ suffix: '.min' }), dest('components')], cb);
+}
+function minifyPlugins(cb) {
+	pump([src(paths.plugins), ...minifyJS(), rename({ suffix: '.min' }), dest('plugins')], cb);
+}
+function build(cb) {
+	pump([src(paths.main), header(`
+/* **********************************************
+     Begin <%= file.relative %>
+********************************************** */
+
+`), concat('prism.js'), dest('./')], cb);
+}
+
+async function componentsJsonToJs() {
+	const data = await componentsPromise;
+	const js = `var components = ${JSON.stringify(data)};
+if (typeof module !== 'undefined' && module.exports) { module.exports = components; }`;
+	return util.promisify(fs.writeFile)(paths.componentsFileJS, js);
+}
+
+function watchComponentsAndPlugins() {
+	watch(paths.components, parallel(minifyComponents, build));
+	watch(paths.plugins, parallel(minifyPlugins, build));
+}
+
+async function languagePlugins() {
+	const data = await componentsPromise;
+	const languagesMap = {};
+	const dependenciesMap = {};
+	const aliasMap = {};
+
+	/**
+	 * Tries to guess the name of a language given its id.
+	 *
+	 * From `prism-show-language.js`.
+	 *
+	 * @param {string} id The language id.
+	 * @returns {string}
+	 */
+	function guessTitle(id) {
+		if (!id) {
+			return id;
+		}
+		return (id.substring(0, 1).toUpperCase() + id.substring(1)).replace(/s(?=cript)/, 'S');
+	}
+
+	/**
+	 * @param {string} key
+	 * @param {string} title
+	 */
+	function addLanguageTitle(key, title) {
+		if (!languagesMap[key] && guessTitle(key) !== title) {
+			languagesMap[key] = title;
+		}
+	}
+
+	for (const id in data.languages) {
+		if (id !== 'meta') {
+			const language = data.languages[id];
+			const title = language.displayTitle || language.title;
+
+			addLanguageTitle(id, title);
+
+			for (const name in language.aliasTitles) {
+				addLanguageTitle(name, language.aliasTitles[name]);
+			}
+
+			if (language.alias) {
+				if (typeof language.alias === 'string') {
+					aliasMap[language.alias] = id;
+					addLanguageTitle(language.alias, title);
+				} else {
+					language.alias.forEach(function (alias) {
+						aliasMap[alias] = id;
+						addLanguageTitle(alias, title);
+					});
+				}
+			}
+
+			if (language.require) {
+				dependenciesMap[id] = language.require;
+			}
+		}
+	}
+
+	function formattedStringify(json) {
+		return JSON.stringify(json, null, '\t').replace(/\n/g, '\n\t');
+	}
+
+	const jsonLanguagesMap = formattedStringify(languagesMap);
+	const jsonDependenciesMap = formattedStringify(dependenciesMap);
+	const jsonAliasMap = formattedStringify(aliasMap);
+
+	const tasks = [
+		{
+			plugin: paths.showLanguagePlugin,
+			maps: { languages: jsonLanguagesMap }
+		},
+		{
+			plugin: paths.autoloaderPlugin,
+			maps: { aliases: jsonAliasMap, dependencies: jsonDependenciesMap }
+		}
+	];
+
+	// TODO: Use `Promise.allSettled` (https://github.com/tc39/proposal-promise-allSettled)
+	const taskResults = await Promise.all(tasks.map(async task => {
+		try {
+			const value = await new Promise((resolve, reject) => {
+				const stream = src(task.plugin)
+					.pipe(replace(
+						/\/\*(\w+)_placeholder\[\*\/[\s\S]*?\/\*\]\*\//g,
+						(m, mapName) => `/*${mapName}_placeholder[*/${task.maps[mapName]}/*]*/`
+					))
+					.pipe(dest(task.plugin.substring(0, task.plugin.lastIndexOf('/'))));
+
+				stream.on('error', reject);
+				stream.on('end', resolve);
+			});
+			return { status: 'fulfilled', value };
+		} catch (error) {
+			return { status: 'rejected', reason: error };
+		}
+	}));
+
+	const rejectedTasks = taskResults.filter(/** @return {r is {status: 'rejected', reason: any}} */ r => r.status === 'rejected');
+	if (rejectedTasks.length > 0) {
+		throw rejectedTasks.map(r => r.reason);
+	}
+}
+
+const components = minifyComponents;
+const plugins = series(languagePlugins, minifyPlugins);
+
+
+module.exports = {
+	watch: watchComponentsAndPlugins,
+	default: parallel(components, plugins, componentsJsonToJs, build),
+	premerge,
+	linkify,
+	changes
+};
diff --git a/gulpfile.js/paths.js b/gulpfile.js/paths.js
new file mode 100644
index 0000000..1d5b7a3
--- /dev/null
+++ b/gulpfile.js/paths.js
@@ -0,0 +1,19 @@
+"use strict";
+
+module.exports = {
+	componentsFile: 'components.json',
+	componentsFileJS: 'components.js',
+	components: ['components/**/*.js', '!components/index.js', '!components/**/*.min.js'],
+	main: [
+		'components/prism-core.js',
+		'components/prism-markup.js',
+		'components/prism-css.js',
+		'components/prism-clike.js',
+		'components/prism-javascript.js',
+		'plugins/file-highlight/prism-file-highlight.js'
+	],
+	plugins: ['plugins/**/*.js', '!plugins/**/*.min.js'],
+	showLanguagePlugin: 'plugins/show-language/prism-show-language.js',
+	autoloaderPlugin: 'plugins/autoloader/prism-autoloader.js',
+	changelog: 'CHANGELOG.md'
+};
diff --git a/gulpfile.js/premerge.js b/gulpfile.js/premerge.js
new file mode 100644
index 0000000..a78c21b
--- /dev/null
+++ b/gulpfile.js/premerge.js
@@ -0,0 +1,18 @@
+"use strict";
+
+const git = require('simple-git/promise')(__dirname);
+
+
+function gitChanges() {
+	return git.status().then(res => {
+		if (res.files.length > 0) {
+			console.log(res);
+			throw new Error('There are changes in the file system. Did you forget to run gulp?');
+		}
+	});
+}
+
+
+module.exports = {
+	premerge: gitChanges
+};
diff --git a/package-lock.json b/package-lock.json
index bb2538c..2f042d7 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -4252,17 +4252,6 @@
       "integrity": "sha1-2kL0l0DAtC2yypcoVxyxkMmO/qM=",
       "dev": true
     },
-    "shelljs": {
-      "version": "0.8.3",
-      "resolved": "https://registry.npmjs.org/shelljs/-/shelljs-0.8.3.tgz",
-      "integrity": "sha512-fc0BKlAWiLpwZljmOvAOTE/gXawtCoNrP5oaY7KIaQbbyHeQVg01pSEuEGvGh3HEdBU4baCD7wQBwADmM/7f7A==",
-      "dev": true,
-      "requires": {
-        "glob": "^7.0.0",
-        "interpret": "^1.0.0",
-        "rechoir": "^0.6.2"
-      }
-    },
     "signal-exit": {
       "version": "3.0.2",
       "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.2.tgz",
diff --git a/package.json b/package.json
index 1a3fcb6..ddb65e3 100755
--- a/package.json
+++ b/package.json
@@ -37,7 +37,6 @@
     "jsdom": "^13.0.0",
     "mocha": "^6.0.0",
     "pump": "^3.0.0",
-    "shelljs": "^0.8.3",
     "simple-git": "^1.107.0",
     "yargs": "^13.2.2"
   },