Skip to content

Commit

Permalink
Add Vex.Flow.VERSION and Vex.Flow.BUILD via webpack.DefinePlugin.
Browse files Browse the repository at this point in the history
Add banner with version, build timestamp, and git hash via webpack.BannerPlugin.
  • Loading branch information
ronyeh committed Jun 28, 2021
1 parent 605b9a7 commit fd1b856
Showing 1 changed file with 21 additions and 11 deletions.
32 changes: 21 additions & 11 deletions Gruntfile.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
/* global module, __dirname, process, require */

const path = require('path');
const webpack = require('webpack');
const child_process = require('child_process');

module.exports = (grunt) => {
const BANNER = [
'/**!',
' * VexFlow <%= pkg.version %> built on <%= grunt.template.today("yyyy-mm-dd") %>.',
' * Copyright (c) 2010 Mohit Muthanna Cheppudira <mohit@muthanna.com>',
' *',
' * http://www.vexflow.com http://github.com/0xfe/vexflow',
' */',
].join('\n');
const BASE_DIR = __dirname;
const BUILD_DIR = path.join(BASE_DIR, 'build');
const RELEASE_DIR = path.join(BASE_DIR, 'releases');
Expand All @@ -21,6 +15,14 @@ module.exports = (grunt) => {
const TARGET_MIN = 'vexflow-min.js';
const TARGET_TESTS = 'vexflow-tests.js';

// Get current build information from git and package.json.
const GIT_COMMIT_HASH = child_process.execSync('git rev-parse HEAD').toString().trim();
const packageJSON = grunt.file.readJSON('package.json');
const BANNER =
`VexFlow ${packageJSON.version} ${new Date().toISOString()} ${GIT_COMMIT_HASH}\n` +
`Copyright (c) 2010 Mohit Muthanna Cheppudira <mohit@muthanna.com>\n` +
`http://www.vexflow.com http://github.com/0xfe/vexflow`;

// Used for eslint
const SOURCES = ['./src/*.ts', './src/*.js', '!./src/header.js'];

Expand Down Expand Up @@ -53,6 +55,13 @@ module.exports = (grunt) => {
},
],
},
plugins: [
new webpack.DefinePlugin({
_VEXFLOW_VERSION_: JSON.stringify(packageJSON.version),
_VEXFLOW_BUILD_: JSON.stringify(GIT_COMMIT_HASH),
}),
new webpack.BannerPlugin(BANNER),
],
};
}

Expand All @@ -61,7 +70,7 @@ module.exports = (grunt) => {
const webpackTest = webpackConfig(TARGET_TESTS, MODULE_ENTRY_TESTS, 'development', 'VFTests');

grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
pkg: packageJSON,
webpack: {
build: webpackProd,
buildDev: webpackDev,
Expand Down Expand Up @@ -156,7 +165,6 @@ module.exports = (grunt) => {
clean: [BUILD_DIR],
});

// Load the plugin that provides the "uglify" task.
grunt.loadNpmTasks('grunt-contrib-qunit');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-contrib-clean');
Expand All @@ -168,7 +176,7 @@ module.exports = (grunt) => {
grunt.loadNpmTasks('grunt-webpack');
grunt.loadNpmTasks('grunt-concurrent');

// Default task(s).
// Default tasks that run when you type `grunt`.
grunt.registerTask('default', [
'clean',
'eslint',
Expand All @@ -177,7 +185,9 @@ module.exports = (grunt) => {
'webpack:buildTest',
'typedoc',
]);

grunt.registerTask('watch', 'Watch src/ and tests/ concurrently', ['clean', 'eslint', 'concurrent']);

grunt.registerTask('test', 'Run qunit tests.', [
'clean',
'webpack:build',
Expand Down

0 comments on commit fd1b856

Please sign in to comment.