Skip to content

Commit

Permalink
chore: generate a test example on netlify for PRs (#4912)
Browse files Browse the repository at this point in the history
  • Loading branch information
gkatsev authored Jan 30, 2018
1 parent 41fd5cb commit 8b54737
Show file tree
Hide file tree
Showing 11 changed files with 67 additions and 11 deletions.
52 changes: 52 additions & 0 deletions build/generate-example.js
Original file line number Diff line number Diff line change
@@ -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));
});
}
2 changes: 0 additions & 2 deletions build/grunt.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -449,7 +448,6 @@ module.exports = function(grunt) {
'cssmin',

'copy:fonts',
'copy:swf',
'copy:ie8',
'vjslanguages'
]);
Expand Down
6 changes: 6 additions & 0 deletions build/netlify-docs.js
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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();
}
}
2 changes: 1 addition & 1 deletion sandbox/combined-tracks.html.example
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<script src="../dist/ie8/videojs-ie8.js"></script>

<!-- Load the source files -->
<link href="../build/temp/video-js.css" rel="stylesheet" type="text/css">
<link href="../dist/video-js.css" rel="stylesheet" type="text/css">
<script src="../dist/video.js"></script>
<script src="../node_modules/videojs-flash/dist/videojs-flash.js"></script>

Expand Down
2 changes: 1 addition & 1 deletion sandbox/descriptions.html.example
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<script src="../dist/ie8/videojs-ie8.js"></script>

<!-- Load the source files -->
<link href="../build/temp/video-js.css" rel="stylesheet" type="text/css">
<link href="../dist/video-js.css" rel="stylesheet" type="text/css">
<script src="../dist/video.js"></script>

<!-- Set the location of the flash SWF -->
Expand Down
4 changes: 2 additions & 2 deletions sandbox/embeds.html.example
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
<script src='../node_modules/es5-shim/es5-shim.js'></script>
<script src='../node_modules/es6-shim/es6-shim.js'></script>

<link href="../build/temp/video-js.css" rel="stylesheet" type="text/css">
<link href="../dist/video-js.css" rel="stylesheet" type="text/css">
<script src="../dist/video.js"></script>

<script src='../node_modules/videojs-flash/dist/videojs-flash.js'></script>
<script src="https://unpkg.com/videojs-contrib-hls@latest/dist/videojs-contrib-hls.js"></script>

<script src="../build/temp/lang/es.js"></script>
<script src="../dist/lang/es.js"></script>

<!-- Set the location of the flash SWF -->
<script>
Expand Down
2 changes: 1 addition & 1 deletion sandbox/flash.html.example
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<script src="../dist/ie8/videojs-ie8.js"></script>

<!-- Load the source files -->
<link href="../build/temp/video-js.css" rel="stylesheet" type="text/css">
<link href="../dist/video-js.css" rel="stylesheet" type="text/css">
<script src="../dist/video.js"></script>
<script src="../node_modules/videojs-flash/dist/videojs-flash.js"></script>

Expand Down
2 changes: 1 addition & 1 deletion sandbox/icons.html.example
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<meta charset="utf-8" />
<title>Video.js Icons Sandbox</title>

<link href="../build/temp/video-js.css" rel="stylesheet" type="text/css">
<link href="../dist/video-js.css" rel="stylesheet" type="text/css">

<style>
.icon-list li span { font-size: 150% }
Expand Down
2 changes: 1 addition & 1 deletion sandbox/index.html.example
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<script src="../dist/ie8/videojs-ie8.js"></script>

<!-- Load the source files -->
<link href="../build/temp/video-js.css" rel="stylesheet" type="text/css">
<link href="../dist/video-js.css" rel="stylesheet" type="text/css">
<script src="../dist/video.js"></script>
<script src="../node_modules/videojs-flash/dist/videojs-flash.js"></script>

Expand Down
2 changes: 1 addition & 1 deletion sandbox/language.html.example
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<script src="../dist/ie8/videojs-ie8.js"></script>

<!-- Load the source files -->
<link href="../build/temp/video-js.css" rel="stylesheet" type="text/css">
<link href="../dist/video-js.css" rel="stylesheet" type="text/css">
<script src="../dist/video.js"></script>

<!-- Set the location of the flash SWF -->
Expand Down
2 changes: 1 addition & 1 deletion sandbox/plugin.html.example
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<script src="../dist/ie8/videojs-ie8.js"></script>

<!-- Load the source files -->
<link href="../build/temp/video-js.css" rel="stylesheet" type="text/css">
<link href="../dist/video-js.css" rel="stylesheet" type="text/css">
<script src="../dist/video.js"></script>

<!-- Set the location of the flash SWF -->
Expand Down

0 comments on commit 8b54737

Please sign in to comment.