Skip to content

Commit

Permalink
Put mustache.version into place by build step
Browse files Browse the repository at this point in the history
Historically we haven't had a build step that did any transformations
on the .js source code, except for one ad-hoc search-n-replace trick;
putting the current version number into the source code, into the
`mustache.version` field.

Now that we've got a proper build step in place with rollup.js, which
transforms the `.mjs` source into `.js | .min.js` versions, we might
as well improve how the version number gets into `mustache.version`
field.

These changes uses rollup-plugin-json plugin to make that happen,
allowing us to `import` our `package.json` to extract what's inside its
`version` field.

The end result is rollup.js inlining that version value into the built
UMD version found in `mustache.js`. Therefore we don't need the old
ad-hoc search-n-replace trick that we've had in a pre-commit hook for
quite some time now.
  • Loading branch information
phillipj committed Oct 17, 2019
1 parent b8f901d commit 01d2cc8
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 4 deletions.
4 changes: 3 additions & 1 deletion mustache.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
(global = global || self, global.Mustache = factory());
}(this, function () { 'use strict';

var version = "3.1.0";

/*!
* mustache.js - Logic-less {{mustache}} templates with JavaScript
* http://github.com/janl/mustache.js
Expand Down Expand Up @@ -651,7 +653,7 @@

var mustache = {
name: 'mustache.js',
version: '3.1.0',
version: version,
tags: [ '{{', '}}' ]
};

Expand Down
2 changes: 1 addition & 1 deletion mustache.min.js

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion mustache.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
* http://github.com/janl/mustache.js
*/

import { version } from './package.json';

var objectToString = Object.prototype.toString;
var isArray = Array.isArray || function isArrayPolyfill (object) {
return objectToString.call(object) === '[object Array]';
Expand Down Expand Up @@ -644,7 +646,7 @@ Writer.prototype.rawValue = function rawValue (token) {

var mustache = {
name: 'mustache.js',
version: '3.1.0',
version: version,
tags: [ '{{', '}}' ]
};

Expand Down
24 changes: 24 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"npm": ">=1.4.0"
},
"scripts": {
"build": "rollup mustache.mjs --file mustache.js --format umd --name Mustache --banner '// This file has been generated from mustache.mjs' && uglifyjs mustache.js > mustache.min.js",
"build": "rollup --config && uglifyjs mustache.js > mustache.min.js",
"pretest": "eslint --parser-options=sourceType:module mustache.mjs test/**/*.js && eslint bin/mustache",
"test": "mocha --reporter spec test/*-test.js",
"test-render": "mocha --reporter spec test/render-test",
Expand All @@ -46,6 +46,7 @@
"jshint": "^2.9.5",
"mocha": "^3.0.2",
"rollup": "^1.23.1",
"rollup-plugin-json": "^4.0.0",
"uglify-js": "^3.4.6",
"zuul": "^3.11.0",
"zuul-ngrok": "nolanlawson/zuul-ngrok#patch-1"
Expand Down
12 changes: 12 additions & 0 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import json from "rollup-plugin-json";

export default {
input: "mustache.mjs",
output: {
file: "mustache.js",
format: "umd",
name: "Mustache",
banner: "// This file has been generated from mustache.mjs"
},
plugins: [json()]
};

0 comments on commit 01d2cc8

Please # to comment.