Skip to content

Commit

Permalink
chore: package json cleanup (#5649)
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonocasey authored and gkatsev committed Aug 30, 2019
1 parent bd58039 commit 85ad44e
Show file tree
Hide file tree
Showing 17 changed files with 487 additions and 644 deletions.
75 changes: 29 additions & 46 deletions build/assets.js
Original file line number Diff line number Diff line change
@@ -1,57 +1,37 @@
/* eslint-disable no-console */
const fs = require('fs');
const zlib = require('zlib');
const Promise = require('bluebird');
const klawSync = require('klaw-sync');
const filesize = require('filesize');
const Table = require('cli-table');

const files = klawSync('dist/', {
ignore: ['examples', 'lang', 'font', '*.zip', '*.gz'],
nodir: true
});

Promise.all(files.map(gzipAndStat))
.then(mapFiles)
.then(function(files) {
logTable(files);

return files;
})
.then(cleanup)
.catch(function(err) {
console.error(err.stack);
});

function cleanup(files) {
files.forEach(function(file) {
fs.unlinkSync('dist/' + file[0] + '.gz');
});
}

function mapFiles(files) {
return files.map(function(file) {
const path = file[0].path;
const fileStat = file[0].stats;
const gzStat = file[1];
return [file[0].path.split('dist/')[1], filesize(fileStat.size), filesize(gzStat.size)];
});
}

function gzipAndStat(file) {
const path = require('path');
const sh = require('shelljs');

// find all js/css files in the dist dir
// but ignore any files in lang, example, or font directories
const filepaths = sh
.find(path.join(__dirname, '..', 'dist', '**', '*.{js,css}'))
.filter((filepath) => !(/\/(lang|example|font)\//).test(filepath));

// map all files that we found into an array of
// table entries the filepath, file size, and gzip size.
Promise.all(filepaths.map(function(filepath) {
return new Promise(function(resolve, reject) {
const readStream = fs.createReadStream(file.path);
const writeStream = fs.createWriteStream(file.path + '.gz');
const readStream = fs.createReadStream(filepath);
const writeStream = fs.createWriteStream(filepath + '.gz');
const gzip = zlib.createGzip();

readStream.pipe(gzip).pipe(writeStream).on('close', function() {
const gzStat = fs.statSync(file.path + '.gz');
const gzStat = fs.statSync(filepath + '.gz');
const fileStat = fs.statSync(filepath);

fs.unlinkSync(filepath + '.gz');

resolve([file, gzStat]);
resolve([filepath.split('dist/')[1], filesize(fileStat.size), filesize(gzStat.size)]);
})
.on('error', reject);
.on('error', reject);
});
}

function logTable(files) {
})).then(function(lines) {
// log all the files and there sizes using a cli table
const table = new Table({
head: ['filename', 'size', 'gzipped'],
colAligns: ['left', 'right', 'right'],
Expand All @@ -60,6 +40,9 @@ function logTable(files) {
}
});

table.push.apply(table, files);
table.push.apply(table, lines);
console.log(table.toString());
}

}).catch(function(err) {
console.error(err.stack);
});
24 changes: 13 additions & 11 deletions build/current-changelog.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
var unified = require('unified');
var markdown = require('remark-parse');
var stringify = require('remark-stringify');
var fs = require('fs');
/* eslint-disable no-console */

const unified = require('unified');
const markdown = require('remark-parse');
const stringify = require('remark-stringify');
const fs = require('fs');

module.exports = function() {
var processor = unified()
.use(markdown, {commonmark: true})
.use(stringify);
const processor = unified()
.use(markdown, {commonmark: true})
.use(stringify);

var ast = processor.parse(fs.readFileSync('./CHANGELOG.md'));
const ast = processor.parse(fs.readFileSync('./CHANGELOG.md'));
const changelog = [];

var changelog = [];
changelog.push(processor.stringify(ast.children[0]));

// start at 1 so we get the first anchor tag
// and can break on the second
for (var i = 1; i < ast.children.length; i++) {
var item = processor.stringify(ast.children[i]);
for (let i = 1; i < ast.children.length; i++) {
let item = processor.stringify(ast.children[i]);

if (/^<a name="/.test(item)) {
break;
Expand Down
10 changes: 5 additions & 5 deletions build/docs-only.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import sh from 'shelljs';
import path from 'path';
const sh = require('shelljs');
const path = require('path');


export default function(commit, commitRange) {
module.exports = function(commit, commitRange) {
const SINGLE_COMMIT = `git diff-tree --no-commit-id --name-only -r ${commit}`;
const COMMIT_RANGE = `git diff --name-only ${commitRange}`;

let command = SINGLE_COMMIT;

if (commitRange) {
command = COMMIT_RANGE
command = COMMIT_RANGE;
}

const output = sh.exec(command, {async: false, silent: true}).stdout;

const files = output.split('\n').filter(Boolean);

return files.every((file) => file.startsWith('docs') || path.extname(file) === '.md');
};
17 changes: 8 additions & 9 deletions build/fix-api-docs.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
var replace = require("replace");
var path = require('path')
var apiPath = path.join(__dirname, '..', 'docs', 'api');
const replace = require('replace');
const path = require('path');
const apiPath = path.join(__dirname, '..', 'docs', 'api');

var replacements = [
const replacements = [
{find: /\/docs\/guides\/(.+)\.md/g, replace: 'tutorial-$1.html'},
{find: /tutorial-tech.html/g, replace: 'tutorial-tech_.html'},
{find: /\/docs\/guides\//g, replace: '#'},
Expand All @@ -21,18 +21,17 @@ var replacements = [
{find: '<h3 id="videojs-(audio|video)track">', replace: '<h3 id="videojs$1track">'},
{find: '<h3 id="text-tracks">', replace: '<h3 id="text-tracks-1">'},
{find: '<h2 id="q-how-can-i-hide-the-links-to-my-video-subtitles-audio-tracks">',
replace: '<h2 id="q-how-can-i-hide-the-links-to-my-videosubtitlesaudiotracks">'},
replace: '<h2 id="q-how-can-i-hide-the-links-to-my-videosubtitlesaudiotracks">'},
{find: '<h3 id="dispose-http-docs-videojs-com-player-html-dispose">',
replace: '<h3 id="dispose">'},
replace: '<h3 id="dispose">'},
{find: '<h4 id="effect-on-player-width-and-player-height">',
replace: '<h4 id="effect-on-playerwidth-and-playerheight">'},
replace: '<h4 id="effect-on-playerwidth-and-playerheight">'},
{find: '<h4 id="i-want-to-have-a-single-source-and-dont-care-about-live-adaptive-streaming">',
replace: '<h4 id="i-want-to-have-a-single-source-and-dont-care-about-liveadaptive-streaming">'},
replace: '<h4 id="i-want-to-have-a-single-source-and-dont-care-about-liveadaptive-streaming">'},
{find: '<h2 id="api-docs-api">', replace: '<h2 id="api-docs">'},
{find: '<h2 id="guides-docs-guides">', replace: '<h2 id="guides">'}
];


replacements.forEach(function(obj) {
replace({
regex: obj.find,
Expand Down
40 changes: 23 additions & 17 deletions build/generate-example.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
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 path = require('path');
const fs = require('fs');
const sh = require('shelljs');
const pkg = require('../package.json');

const dest = path.join(__dirname, '..', 'docs', 'api');
const vjsFlash = path.join(__dirname, '..', 'node_modules', 'videojs-flash');
const vjsSwf = path.join('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() {
const cleanupExample = function() {
sh.rm('-rf', distDest);
sh.rm('-rf', exampleDest);
sh.rm('-rf', path.join(dest, 'node_modules'));
}
};

export default function generateExample({skipBuild} = {}) {
const generateExample = function({skipBuild} = {}) {
// run the build
if (!skipBuild) {
sh.exec('npm run build');
Expand All @@ -42,11 +41,18 @@ export default function generateExample({skipBuild} = {}) {
sh.cp(path.join(vjsSwf, 'dist', 'video-js.swf'), swfDest);
}

const files = klawSync('sandbox/').filter((file) => path.extname(file.path) === '.example');
const filepaths = sh.find(path.join(__dirname, '..', 'sandbox', '**', '*.*'))
.filter((filepath) => path.extname(filepath) === '.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));
filepaths.forEach(function(filepath) {
const p = path.parse(filepath);

sh.cp(filepath, path.join(exampleDest, p.name));
});
}
};

module.exports = {
cleanupExample,
generateExample
};
42 changes: 22 additions & 20 deletions build/gh-release.js
Original file line number Diff line number Diff line change
@@ -1,35 +1,37 @@
var ghrelease = require('gh-release');
var currentChangelog = require('./current-changelog.js');
var safeParse = require('safe-json-parse/tuple');
var pkg = require('../package.json')
var minimist = require('minimist');
/* eslint-disable no-console */

var args = minimist(process.argv.slice(2), {
boolean: ['prerelease'],
default: {
prerelease: false
},
alias: {
p: 'prerelease'
}
});

var options = {
const ghrelease = require('gh-release');
const currentChangelog = require('./current-changelog.js');
const safeParse = require('safe-json-parse/tuple');
const pkg = require('../package.json');
const options = {
owner: 'videojs',
repo: 'video.js',
body: currentChangelog(),
assets: ['./dist/video-js-'+pkg.version+'.zip'],
assets: ['./dist/video-js-' + pkg.version + '.zip'],
endpoint: 'https://api.github.com',
auth: {
username: process.env.VJS_GITHUB_USER,
password: process.env.VJS_GITHUB_TOKEN
}
};

var tuple = safeParse(process.env.npm_config_argv);
var npmargs = tuple[0] ? [] : tuple[1].cooked;
let i = process.argv.length;

while (i--) {
const arg = process.argv[i];

if (arg === '-p' || arg === '--prerelease') {
options.prerelease = true;
}
}

const tuple = safeParse(process.env.npm_config_argv);
const npmargs = tuple[0] ? [] : tuple[1].cooked;

if (args.prerelease || npmargs.some(function(arg) { return /next/.test(arg); })) {
if (npmargs.some(function(arg) {
return /next/.test(arg);
})) {
options.prerelease = true;
}

Expand Down
10 changes: 6 additions & 4 deletions build/minify.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import fs from 'fs';
import uglify from 'uglify-js';
import maxmin from 'maxmin';
/* eslint-disable no-console, camelcase */

const fs = require('fs');
const uglify = require('uglify-js');
const maxmin = require('maxmin');

const options = {
nameCache: {},
Expand Down Expand Up @@ -38,7 +40,7 @@ const minify = (file, dest) => {
console.log('File', dest, 'created:', maxmin(code, minified.code, true));
};

console.log('Minifying files\n');
console.log('Minifying files\n');

minify('dist/video.js', 'dist/video.min.js');
minify('dist/alt/video.novtt.js', 'dist/alt/video.novtt.min.js');
Expand Down
4 changes: 2 additions & 2 deletions build/netlify-docs.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
const sh = require('shelljs');
const semver = require('semver');
const generateExample = require('./generate-example.js').default;
const generateExample = require('./generate-example.js').generateExample;

const GIT_LOG = `git log --format=%B -n 1 ${process.env.COMMIT_REF}`;
const output = sh.exec(GIT_LOG, {async: false, silent:true}).stdout;
const output = sh.exec(GIT_LOG, {async: false, silent: true}).stdout;

// if we're on master branch and not on a tagged commit,
// error the build so it doesn't redeploy the docs
Expand Down
15 changes: 9 additions & 6 deletions build/sandbox.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
/* eslint-disable no-console */

const fs = require('fs');
const path = require('path');
const klawSync = require('klaw-sync');
const sh = require('shelljs');

const files = klawSync('sandbox/').filter((file) => path.extname(file.path) === '.example');
const files = sh.find(path.join(__dirname, '..', 'sandbox', '**', '*.*'))
.filter((filepath) => path.extname(filepath) === '.example');

const changes = files.map(function(file) {
const p = path.parse(file.path);
const nonExample = path.join(p.dir, p.name);

return {
file: file.path,
copy: nonExample
};
})
.filter(function(change) {
}).filter(function(change) {
return !fs.existsSync(change.copy);
});

Expand All @@ -21,8 +24,8 @@ changes.forEach(function(change) {
});

if (changes.length) {
console.log("Updated Sandbox files for:");
console.log('Updated Sandbox files for:');
console.log('\t' + changes.map((chg) => chg.copy).join('\n\t'));
} else {
console.log("No sandbox updates necessary");
console.log('No sandbox updates necessary');
}
3 changes: 2 additions & 1 deletion build/test-a11y.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ const options = {

AccessSniff.default(testFiles, options).then(function(report) {
AccessSniff.report(report);
}).catch(function(error) {
}).catch(function() {

// there were errors, which are already reported, exit with an error
process.exit(1);
});
Loading

0 comments on commit 85ad44e

Please sign in to comment.