diff --git a/CHANGELOG.md b/CHANGELOG.md index 887e7a11f..f2a93c101 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ CHANGELOG ========= ## HEAD (Unreleased) -_(none)_ +* @gkatsev updated options customizer and github-release options ([view](https://github.com/videojs/video.js/pull/2903)) -------------------- diff --git a/build/grunt.js b/build/grunt.js index 75d0e40ed..a42b91259 100644 --- a/build/grunt.js +++ b/build/grunt.js @@ -1,3 +1,4 @@ +import {gruntCustomizer, gruntOptionsMaker} from './options-customizer.js'; module.exports = function(grunt) { require('time-grunt')(grunt); @@ -41,6 +42,19 @@ module.exports = function(grunt) { ] }; + const githubReleaseDefaults = { + options: { + release: { + tag_name: 'v'+ version.full, + name: version.full, + body: require('chg').find(version.full).changesRaw + }, + }, + files: { + src: [`dist/video-js-${version.full}.zip`] // Files that you want to attach to Release + } + }; + /** * Customizes _.merge behavior in `browserifyGruntOptions` to concatenate * arrays. This can be overridden on a per-call basis to @@ -52,11 +66,7 @@ module.exports = function(grunt) { * @param {Mixed} sourceValue * @return {Object} */ - function browserifyGruntCustomizer(objectValue, sourceValue) { - if (Array.isArray(objectValue)) { - return objectValue.concat(sourceValue); - } - } + const browserifyGruntCustomizer = gruntCustomizer; /** * Creates a unique object of Browserify Grunt task options. @@ -70,9 +80,10 @@ module.exports = function(grunt) { * * @return {Object} */ - function browserifyGruntOptions(options = null, customizer = browserifyGruntCustomizer) { - return _.merge({}, browserifyGruntDefaults, options, customizer); - } + const browserifyGruntOptions = gruntOptionsMaker(browserifyGruntDefaults, browserifyGruntCustomizer); + + const githubReleaseCustomizer = gruntCustomizer; + const githubReleaseOptions = gruntOptionsMaker(githubReleaseDefaults, githubReleaseCustomizer); /** * Creates processor functions for license banners. @@ -296,28 +307,14 @@ module.exports = function(grunt) { password: process.env.VJS_GITHUB_TOKEN } }, - release: { + release: githubReleaseOptions(), + prerelease: githubReleaseOptions({ options: { release: { - tag_name: 'v'+ version.full, - name: version.full, - body: require('chg').find(version.full).changesRaw - } - } - }, - prerelease: { - options: { - release: { - tag_name: 'v'+ version.full, - name: version.full, - body: require('chg').find(version.full).changesRaw, prerelease: true } } - }, - files: { - src: [`dist/video-js-${version.full}.zip`] // Files that you want to attach to Release - } + }) }, browserify: { options: browserifyGruntOptions(), diff --git a/build/options-customizer.js b/build/options-customizer.js new file mode 100644 index 000000000..5257e73d6 --- /dev/null +++ b/build/options-customizer.js @@ -0,0 +1,49 @@ +import _ from 'lodash-compat'; +/** + * Customizes _.merge behavior in `gruntOptions` to concatenate + * arrays. This can be overridden on a per-call basis to + * + * @see https://lodash.com/docs#merge + * @function GruntCustomizer + * @private + * @param {Mixed} objectValue + * @param {Mixed} sourceValue + * @return {Object} + */ +function gruntCustomizer(objectValue, sourceValue) { + if (Array.isArray(objectValue)) { + return objectValue.concat(sourceValue); + } +} + +/** + * Creates a gruntOptions instance for the specific defaultOptions and gruntCustomizer + * + * @function browserifyGruntOptions + * @private + * @param {Object} [options] + * @param {Function} [customizer=gruntCustomizer] + * If the default array-concatenation behavior is not desireable, + * pass _.noop or a unique customizer (https://lodash.com/docs#merge). + * + * @return {Function} + */ +function gruntOptionsMaker(defaultOptions, gruntCustomizer) { + /** + * Creates a unique object of Browserify Grunt task options. + * + * @function gruntOptions + * @private + * @param {Object} [options] + * @param {Function} [customizer=browserifyGruntCustomizer] + * If the default array-concatenation behavior is not desireable, + * pass _.noop or a unique customizer (https://lodash.com/docs#merge). + * + * @return {Object} + */ + return function gruntOptions(options = null, customizer = gruntCustomizer) { + return _.merge({}, defaultOptions, options, customizer); + } +}; + +export { gruntCustomizer, gruntOptionsMaker };