1
0
mirror of https://github.com/videojs/video.js.git synced 2025-03-25 22:01:11 +02:00

chore: package json cleanup (#5649)

This commit is contained in:
Brandon Casey 2019-08-30 14:14:53 -04:00 committed by Gary Katsevman
parent bd58039c78
commit 85ad44e13e
17 changed files with 484 additions and 641 deletions

View File

@ -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 path = require('path');
const sh = require('shelljs');
const files = klawSync('dist/', {
ignore: ['examples', 'lang', 'font', '*.zip', '*.gz'],
nodir: true
});
// 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));
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) {
// 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);
resolve([file, gzStat]);
fs.unlinkSync(filepath + '.gz');
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'],
@ -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);
});

View File

@ -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;

View File

@ -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');
};

View File

@ -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: '#'},
@ -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,

View File

@ -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 path = require('path');
const fs = require('fs');
const sh = require('shelljs');
const pkg = require('../package.json');
const dest = 'docs/api/';
const vjsFlash = 'node_modules/videojs-flash';
const vjsSwf = 'node_modules/videojs-swf/';
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');
@ -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
};

View File

@ -1,24 +1,14 @@
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,
@ -26,10 +16,22 @@ var options = {
}
};
var tuple = safeParse(process.env.npm_config_argv);
var npmargs = tuple[0] ? [] : tuple[1].cooked;
let i = process.argv.length;
if (args.prerelease || npmargs.some(function(arg) { return /next/.test(arg); })) {
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 (npmargs.some(function(arg) {
return /next/.test(arg);
})) {
options.prerelease = true;
}

View File

@ -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: {},
@ -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');

View File

@ -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

View File

@ -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);
});
@ -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');
}

View File

@ -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);
});

View File

@ -1,25 +1,28 @@
/* eslint-disable no-console */
const fs = require('fs');
const path = require('path');
const klawSync = require('klaw-sync');
const sh = require('shelljs');
const source = require('../lang/en.json');
const table = require('markdown-table');
const tableRegex = /(<!-- START langtable -->)(.|\n)*(<!-- END langtable -->)/;
let doc = fs.readFileSync('docs/translations-needed.md', 'utf8');
let tableData = [['Language file', 'Missing translations']];
let doc = fs.readFileSync(path.join(__dirname, '..', 'docs', 'translations-needed.md'), 'utf8');
const tableData = [['Language file', 'Missing translations']];
const files = klawSync('lang');
const filepaths = sh.find(path.join(__dirname, '..', 'lang', '**', '!(zh-Hans|zh-Hant)*.json'));
files.forEach((file) => {
const filename = path.basename(file.path);
filepaths.forEach((filepath) => {
const filename = path.basename(filepath);
if (filename === 'en.json') {
return;
}
const target = require(file.path);
let missing = [];
const target = require(filepath);
const missing = [];
for (const string in source) {
if (!target[string]) {
console.log(`${filename} missing "${string}"`);
@ -29,7 +32,7 @@ files.forEach((file) => {
if (missing.length > 0) {
console.error(`${filename} is missing ${missing.length} translations.`);
tableData.push([`${filename} (missing ${missing.length})`, missing[0]]);
for (var i = 1; i < missing.length; i++) {
for (let i = 1; i < missing.length; i++) {
tableData.push(['', missing[i]]);
}
} else {
@ -38,5 +41,5 @@ files.forEach((file) => {
}
});
doc = doc.replace(tableRegex, `$1\n` + table(tableData) + `\n$3`);
fs.writeFileSync('docs/translations-needed.md', doc, 'utf8');
doc = doc.replace(tableRegex, '$1\n' + table(tableData) + '\n$3');
fs.writeFileSync(path.join(__dirname, '..', 'docs', 'translations-needed.md'), doc, 'utf8');

View File

@ -1,19 +0,0 @@
var safeParse = require("safe-json-parse/tuple");
var tuple = safeParse(process.env.npm_config_argv);
var npm_config_argv = tuple[1]
if (tuple[0]) {
process.exit(1);
}
var sh = require('shelljs');
var prereleaseType = npm_config_argv['remain'][0];
var approvedTypes = {
'major': 1,
'minor': 1,
'patch': 1
}
if (prereleaseType in approvedTypes) {
sh.exec('npm run changelog');
}

View File

@ -13,6 +13,7 @@ This default value is hardcoded as a default to the localize method in the SeekB
## Status of translations
<!-- START langtable -->
| Language file | Missing translations |
| ----------------------- | ----------------------------------------------------------------------------------- |
| ar.json (missing 53) | Audio Player |
@ -1052,7 +1053,6 @@ This default value is hardcoded as a default to the localize method in the SeekB
| | Seek to live, currently playing live |
| | {1} is loading. |
| zh-CN.json (Complete) | |
| zh-Hans.json (Complete) | |
| zh-Hant.json (Complete) | |
| zh-TW.json (Complete) | |
<!-- END langtable -->

782
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -44,7 +44,7 @@
"build:lang": "vjslang --dir dist/lang",
"postbuild:lang": "shx cp -R lang/* dist/lang/",
"minify": "npm-run-all minify:*",
"minify:js": "babel-node build/minify.js",
"minify:js": "node build/minify.js",
"minify:css": "npm-run-all minify:css:*",
"minify:css:cdn": "cleancss dist/alt/video-js-cdn.css -o dist/alt/video-js-cdn.min.css",
"minify:css:default": "cleancss dist/video-js.css -o dist/video-js.min.css",
@ -69,10 +69,10 @@
"docs:lint": "remark -- './{,!(node_modules)/**/}!(CHANGELOG)*.md'",
"docs:fix": "remark --output -- './{,!(node_modules)/**/}!(CHANGELOG)*.md'",
"docs:lang": "node build/translations.js",
"netlify": "babel-node ./build/netlify-docs.js",
"netlify": "node ./build/netlify-docs.js",
"prepublishOnly": "run-p build",
"publish": "node build/gh-release.js",
"version": "node build/version.js && git add CHANGELOG.md",
"version": "is-prerelease || npm run changelog && git add CHANGELOG.md",
"zip": "cd dist && cross-env bestzip \"./video-js-${npm_package_version}.zip\" * && cd .."
},
"repository": {
@ -90,18 +90,14 @@
"@videojs/xhr": "2.5.1"
},
"devDependencies": {
"@babel/cli": "^7.4.4",
"@babel/core": "^7.4.5",
"@babel/node": "^7.4.5",
"@babel/plugin-transform-object-assign": "^7.2.0",
"@babel/plugin-transform-runtime": "^7.5.5",
"@babel/preset-env": "^7.4.5",
"@babel/register": "^7.4.4",
"access-sniff": "^3.2.0",
"autoprefixer": "^9.6.0",
"babelify": "^10.0.0",
"bestzip": "^2.1.4",
"bluebird": "^3.5.5",
"browserify": "^16.2.3",
"browserify-istanbul": "^3.0.1",
"chokidar-cli": "^1.2.2",
@ -119,11 +115,10 @@
"jsdoc": "^3.6.2",
"karma": "^4.1.0",
"karma-browserify": "^5.3.0",
"klaw-sync": "^6.0.0",
"lint-staged": "^8.2.0",
"markdown-table": "^1.1.3",
"maxmin": "^2.1.0",
"minimist": "^1.2.0",
"not-prerelease": "^1.0.1",
"npm-merge-driver-install": "^1.1.1",
"npm-run-all": "^4.1.5",
"postcss-cli": "^6.1.2",
@ -156,22 +151,16 @@
"videojs-generate-karma-config": "~5.2.1",
"videojs-languages": "^2.0.0",
"videojs-standard": "^8.0.3",
"watchify": "^3.11.1",
"watchify": "^3.11.0",
"webpack": "^1.15.0"
},
"vjsstandard": {
"ignore": [
"**/es5/**",
"**/build/**",
"!build/rollup.js",
"core.js",
"**/dist/**",
"**/docs/**",
"**/lang/**",
"**/sandbox/**",
"**/test/api/**",
"**/test/dist/coverage/**",
"**/test/karma.conf.js"
"dist",
"docs",
"test/dist",
"test/api",
"core.js"
]
},
"greenkeeper": {
@ -188,6 +177,14 @@
"*.js": [
"vjsstandard --fix",
"git add"
],
"!(CHANGELOG)*.md": [
"remark --output --",
"git add"
],
"lang/**/!(zh-Hans|zh-Hant)*.json": [
"node build/translations.js",
"git add docs/translations-needed.md"
]
}
}

View File

@ -78,8 +78,7 @@ const globals = {
const moduleExternals = [
'global',
'xhr',
'tsml',
'@videojs/xhr',
'safe-json-parse',
'videojs-vtt.js',
'url-toolkit',

View File

@ -1,8 +1,9 @@
const generate = require('videojs-generate-karma-config');
module.exports = function(config) {
const coverageFlag = process.env.npm_config_coverage;
const reportCoverage = false; // process.env.TRAVIS || coverageFlag || false;
// const coverageFlag = process.env.npm_config_coverage;
// process.env.TRAVIS || coverageFlag || false;
const reportCoverage = false;
// see https://github.com/videojs/videojs-generate-karma-config
// for options
@ -14,7 +15,7 @@ module.exports = function(config) {
serverBrowsers(defaults) {
return [];
},
coverage: reportCoverage,
coverage: reportCoverage
};
config = generate(config, options);
@ -44,7 +45,7 @@ module.exports = function(config) {
debug: true,
plugin: ['proxyquireify/plugin'],
transform: [
['babelify', {"presets": [["@babel/preset-env", {"loose": true}]]}],
['babelify', {presets: [['@babel/preset-env', {loose: true}]]}]
]
};
@ -52,14 +53,15 @@ module.exports = function(config) {
config.browserify.transform.push('browserify-istanbul');
}
config.preprocessors = {
'test/globals-shim.js': ['browserify'],
'test/unit/**/*.js': ['browserify'],
'test/unit/**/*.js': ['browserify']
};
// pin Browserstack Firefox version to 64
/* eslint-disable camelcase */
config.customLaunchers.bsFirefox.browser_version = '64.0';
/* eslint-enable camelcase */
// uncomment the section below to re-enable all browserstack video recording
// it is off by default because it slows the build
@ -70,4 +72,9 @@ module.exports = function(config) {
}
});
*/
/* eslint-disable no-console */
console.log(JSON.stringify(config, null, 2));
/* eslint-enable no-console */
};