Commit 3abaf68dd4be44331d40955ca296bf22b6b0e4ff

mAAdhaTTah 2019-03-24T14:35:05

Add command to generate CHANGELOG This forms the basis of the CHANGELOG, but the commits need to be formatted with the linkify command and sorted into the various sections.

diff --git a/gulpfile.js b/gulpfile.js
index 7f39ee9..0b5752e 100644
--- a/gulpfile.js
+++ b/gulpfile.js
@@ -8,6 +8,7 @@ const replace = require('gulp-replace');
 const pump = require('pump');
 const fs = require('fs');
 const simpleGit = require('simple-git');
+const shelljs = require('shelljs');
 
 const paths = {
 	componentsFile: 'components.json',
@@ -185,13 +186,13 @@ function languagePlugins(cb) {
 	});
 }
 
-function changelog(cb) {
+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(
-			/#(\d+)(?![\d\]])/g,
-			'[#$1](https://github.com/PrismJS/prism/issues/$1)'
-		),
+		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)')
@@ -200,6 +201,44 @@ function changelog(cb) {
 	], 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);
 
@@ -221,6 +260,6 @@ function gitChanges(cb) {
 
 exports.watch = watchComponentsAndPlugins;
 exports.default = parallel(components, plugins, componentsJsonToJs, build);
-exports.changelog = changelog;
-
 exports.premerge = gitChanges;
+exports.linkify = linkify;
+exports.changes = changes;
diff --git a/package-lock.json b/package-lock.json
index b82f822..e682769 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -4233,6 +4233,17 @@
       "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 aee18db..b2c17e5 100755
--- a/package.json
+++ b/package.json
@@ -36,6 +36,7 @@
     "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"
   },