diff --git a/build/generate-example.js b/build/generate-example.js new file mode 100644 index 0000000000..b1f5f32961 --- /dev/null +++ b/build/generate-example.js @@ -0,0 +1,52 @@ +import path from 'path'; +import fs from 'fs'; +import sh from 'shelljs'; +import klawSync from 'klaw-sync'; +import pkg from '../package.json'; + +const dest = 'docs/api/'; +const vjsFlash = 'node_modules/videojs-flash'; +const vjsSwf = 'node_modules/videojs-swf/'; +const distDest = path.join(dest, 'dist'); +const exampleDest = path.join(dest, 'test-example'); +const vjsFlashDest = path.join(dest, vjsFlash, 'dist'); +const swfDest = path.join(dest, vjsFlash, vjsSwf, 'dist'); + +export function cleanupExample() { + sh.rm('-rf', distDest); + sh.rm('-rf', exampleDest); + sh.rm('-rf', path.join(dest, 'node_modules')); +} + +export default function generateExample({skipBuild} = {}) { + // run the build + if (!skipBuild) { + sh.exec('npm run build'); + } + + // make sure that the example, flash, and swf dests are available + sh.mkdir('-p', exampleDest); + sh.mkdir('-p', vjsFlashDest); + sh.mkdir('-p', swfDest); + + // copy the `dist` dir + sh.cp('-R', 'dist', path.join(dest, 'dist')); + sh.rm(path.join(dest, 'dist', `video-js-${pkg.version}.zip`)); + + // copy videojs-flash + sh.cp(path.join(vjsFlash, 'dist', 'videojs-flash.js'), vjsFlashDest); + // copy videojs-swf + if (fs.existsSync(path.join(vjsFlash, vjsSwf, 'dist', 'video-js.swf'))) { + sh.cp(path.join(vjsFlash, vjsSwf, 'dist', 'video-js.swf'), swfDest); + } else { + sh.cp(path.join(vjsSwf, 'dist', 'video-js.swf'), swfDest); + } + + const files = klawSync('sandbox/').filter((file) => path.extname(file.path) === '.example'); + + // copy the sandbox example files + files.forEach(function(file) { + const p = path.parse(file.path); + sh.cp(file.path, path.join(exampleDest, p.name)); + }); +} diff --git a/build/grunt.js b/build/grunt.js index 0e6d61f7fe..b98cc0969b 100644 --- a/build/grunt.js +++ b/build/grunt.js @@ -151,7 +151,6 @@ module.exports = function(grunt) { ] }, fonts: { cwd: 'node_modules/videojs-font/fonts/', src: ['*'], dest: 'build/temp/font/', expand: true, filter: 'isFile' }, - swf: { cwd: 'node_modules/videojs-swf/dist/', src: 'video-js.swf', dest: 'build/temp/', expand: true, filter: 'isFile' }, ie8: { cwd: 'node_modules/videojs-ie8/dist/', src: ['**/**'], dest: 'build/temp/ie8/', expand: true, filter: 'isFile' }, dist: { cwd: 'build/temp/', src: ['**/**', '!test*'], dest: 'dist/', expand: true, filter: 'isFile' }, a11y: { src: 'sandbox/descriptions.html.example', dest: 'sandbox/descriptions.test-a11y.html' }, // Can only test a file with a .html or .htm extension @@ -449,7 +448,6 @@ module.exports = function(grunt) { 'cssmin', 'copy:fonts', - 'copy:swf', 'copy:ie8', 'vjslanguages' ]); diff --git a/build/netlify-docs.js b/build/netlify-docs.js index 8d81cb16b2..c5c1444d03 100644 --- a/build/netlify-docs.js +++ b/build/netlify-docs.js @@ -1,5 +1,6 @@ const sh = require('shelljs'); const semver = require('semver'); +const generateExample = require('./generate-example.js').default; const GIT_LOG = `git log --format=%B -n 1 ${process.env.COMMIT_REF}`; const output = sh.exec(GIT_LOG, {async: false, silent:true}).stdout; @@ -16,4 +17,9 @@ if (process.env.BRANCH === 'master' && semver.valid(output.trim()) === null) { // copy the legacy docs over sh.cp('-R', 'docs/legacy-docs', 'docs/api/docs'); + + if (process.env.BRANCH !== 'master') { + // generate the example + generateExample(); + } } diff --git a/sandbox/combined-tracks.html.example b/sandbox/combined-tracks.html.example index 8d9140b9fd..9982ebb8c7 100644 --- a/sandbox/combined-tracks.html.example +++ b/sandbox/combined-tracks.html.example @@ -8,7 +8,7 @@ - + diff --git a/sandbox/descriptions.html.example b/sandbox/descriptions.html.example index 904fe19254..86eae47464 100644 --- a/sandbox/descriptions.html.example +++ b/sandbox/descriptions.html.example @@ -8,7 +8,7 @@ - + diff --git a/sandbox/embeds.html.example b/sandbox/embeds.html.example index e89d5193ea..ac12f4806b 100644 --- a/sandbox/embeds.html.example +++ b/sandbox/embeds.html.example @@ -6,13 +6,13 @@ - + - + - + diff --git a/sandbox/icons.html.example b/sandbox/icons.html.example index a8a7a9e02e..f0675593c2 100644 --- a/sandbox/icons.html.example +++ b/sandbox/icons.html.example @@ -4,7 +4,7 @@