From 3a2d4828bfc71e71c60013eeb19701ef2d0fd213 Mon Sep 17 00:00:00 2001 From: brandonocasey Date: Tue, 12 Jun 2018 16:20:20 -0400 Subject: [PATCH] update generator --- .gitignore | 1 + package.json | 24 +++++----- scripts/karma.conf.js | 37 ++------------- scripts/postcss.config.js | 10 ++--- scripts/primed-rollup-plugins.js | 77 -------------------------------- scripts/rollup-replace.js | 51 +++++++++++++++++++++ scripts/rollup.config.js | 68 ++++++++++++++++++++++++---- 7 files changed, 134 insertions(+), 134 deletions(-) delete mode 100644 scripts/primed-rollup-plugins.js create mode 100644 scripts/rollup-replace.js diff --git a/.gitignore b/.gitignore index 6349436c..4c4d6736 100644 --- a/.gitignore +++ b/.gitignore @@ -28,3 +28,4 @@ node_modules/ # Build-related directories dist/ docs/api/ +test/dist/ diff --git a/package.json b/package.json index 7653d041..6d4082ca 100644 --- a/package.json +++ b/package.json @@ -28,7 +28,7 @@ "main": "dist/videojs-vr.cjs.js", "module": "dist/videojs-vr.es.js", "generator-videojs-plugin": { - "version": "6.0.5" + "version": "6.0.8" }, "scripts": { "prebuild": "npm run clean", @@ -36,21 +36,21 @@ "build:css": "postcss --verbose -o dist/videojs-vr.css --config scripts/postcss.config.js src/plugin.css", "build:js": "rollup -c scripts/rollup.config.js", "build:lang": "vjslang --dir dist/lang", - "clean": "rimraf dist", - "postclean": "mkdirp dist", + "clean": "rimraf dist test/dist", + "postclean": "mkdirp dist test/dist", "docs": "npm-run-all docs:*", "docs:api": "jsdoc src -r -c scripts/jsdoc.json -d docs/api", "docs:toc": "doctoc README.md", "lint": "vjsstandard", "server": "karma start scripts/karma.conf.js --singleRun=false --auto-watch --no-browsers", "start": "npm-run-all -p server watch", - "pretest": "npm-run-all lint clean build:css build:lang", + "pretest": "npm-run-all lint build", "test": "karma start scripts/karma.conf.js", "preversion": "npm test", "version": "node scripts/version.js", "watch": "npm-run-all -p watch:*", - "watch:js": "npm run build:js -- -w", "watch:css": "npm run build:css -- -w", + "watch:js": "npm run build:js -- -w", "prepublish": "not-in-install && npm run build || in-install", "prepush": "npm run lint", "precommit": "npm run docs:toc && git add README.md" @@ -62,7 +62,8 @@ "vjsstandard": { "ignore": [ "dist", - "docs" + "docs", + "test/dist" ] }, "files": [ @@ -99,7 +100,6 @@ "karma-firefox-launcher": "^1.1.0", "karma-ie-launcher": "^1.0.0", "karma-qunit": "^2.0.0", - "karma-rollup-preprocessor": "^6.0.0", "karma-safari-launcher": "^1.0.0", "mkdirp": "^0.5.1", "npm-run-all": "^4.1.2", @@ -108,7 +108,7 @@ "postcss-import": "^11.1.0", "postcss-preset-env": "^5.1.0", "qunit": "^2.5.1", - "rimraf": "^2.6.2", + "rimraf": "^2.6.1", "rollup": "^0.60.1", "rollup-plugin-babel": "^3.0.4", "rollup-plugin-commonjs": "^9.1.3", @@ -117,11 +117,15 @@ "rollup-plugin-node-resolve": "^3.0.0", "rollup-plugin-re": "^1.0.6", "rollup-plugin-uglify": "^4.0.0", - "semver": "^5.4.1", + "semver": "^5.1.0", "serve-static": "^1.13.2", "sinon": "^5.1.0", "uglify-es": "^3.3.9", "videojs-languages": "^1.0.0", "videojs-standard": "^6.0.0" - } + }, + "browserslist": [ + "defaults", + "ie 11" + ] } diff --git a/scripts/karma.conf.js b/scripts/karma.conf.js index ebbdac0a..49f417b6 100644 --- a/scripts/karma.conf.js +++ b/scripts/karma.conf.js @@ -1,19 +1,10 @@ /* eslint-disable no-console */ -const rollupPlugins = require('./primed-rollup-plugins'); -const path = require('path'); const serveStatic = require('serve-static'); +const path = require('path'); const serve = serveStatic( path.join(__dirname, '..'), {index: ['index.html', 'index.htm']} ); -const testGlobals = { - 'qunit': 'QUnit', - 'qunitjs': 'QUnit', - 'sinon': 'sinon', - 'video.js': 'videojs' -}; -const testExternals = Object.keys(testGlobals).concat([ -]); const StaticMiddlewareFactory = function(config) { console.log(`**** Dev server started at http://${config.listenAddress}:${config.port}/ *****`); @@ -49,10 +40,7 @@ module.exports = function(config) { 'dist/videojs-vr.css', 'node_modules/sinon/pkg/sinon.js', 'node_modules/video.js/dist/video.js', - {included: false, pattern: 'src/**/*.js', watched: true}, - // Make sure to disable Karma’s file watcher - // because the preprocessor will use its own. - {pattern: 'test/**/*.test.js', watched: false} + 'test/dist/bundle.js' ], customLaunchers: { travisChrome: { @@ -79,25 +67,6 @@ module.exports = function(config) { colors: true, autoWatch: false, singleRun: true, - concurrency: Infinity, - preprocessors: { - 'test/**/*.test.js': ['rollup'] - }, - rollupPreprocessor: { - output: { - format: 'iife', - name: 'videojsVrTest', - globals: testGlobals - }, - external: testExternals, - plugins: [ - rollupPlugins.multiEntry, - rollupPlugins.resolve, - rollupPlugins.json, - rollupPlugins.replace, - rollupPlugins.commonjs, - rollupPlugins.babel - ] - } + concurrency: Infinity }); }; diff --git a/scripts/postcss.config.js b/scripts/postcss.config.js index 9107ee6a..55a2acd1 100644 --- a/scripts/postcss.config.js +++ b/scripts/postcss.config.js @@ -1,8 +1,8 @@ /* eslint-disable no-console */ -const banner = require('./banner').string; const postcss = require('postcss'); const path = require('path'); -const browsersList = require('./browserslist'); +const pkg = require('../package.json'); +const banner = `@name ${pkg.name} @version ${pkg.version} @license ${pkg.license}`; /** * by default there is no way to print that file was written @@ -30,7 +30,7 @@ module.exports = function(context) { // see https://preset-env.cssdb.org/features // by default we use stage 3+ require('postcss-preset-env')({ - browsers: browsersList, + browsers: pkg.browserslist, stage: 3, features: { 'custom-environment-variables': true, @@ -42,13 +42,13 @@ module.exports = function(context) { require('postcss-banner')({important: true, inline: true, banner}), // add/remove vendor prefixes based on browser list - require('autoprefixer')(browsersList), + require('autoprefixer')(pkg.browserslist), // minify require('cssnano')({ safe: true, preset: ['default', { - autoprefixer: browsersList + autoprefixer: pkg.browserslist }] }), diff --git a/scripts/primed-rollup-plugins.js b/scripts/primed-rollup-plugins.js deleted file mode 100644 index 7eaa6b8f..00000000 --- a/scripts/primed-rollup-plugins.js +++ /dev/null @@ -1,77 +0,0 @@ -const babel = require('rollup-plugin-babel'); -const commonjs = require('rollup-plugin-commonjs'); -const json = require('rollup-plugin-json'); -const multiEntry = require('rollup-plugin-multi-entry'); -const resolve = require('rollup-plugin-node-resolve'); -const {uglify} = require('rollup-plugin-uglify'); -const {minify} = require('uglify-es'); -const browsersList = require('./browserslist'); -const replace = require('rollup-plugin-re'); - -// three modules to find-replace in -const modules = [ - 'VRControls', - 'VREffect', - 'OrbitControls', - 'DeviceOrientationControls' -]; - -const globalReplace = function(str, pattern, replacement) { - return str.replace(new RegExp(pattern, 'g'), replacement); -}; - -module.exports = { - babel: babel({ - babelrc: false, - exclude: 'node_modules/**', - presets: [ - ['env', {loose: true, modules: false, targets: {browsers: browsersList}}] - ], - plugins: [ - 'external-helpers', - 'transform-object-assign' - ] - }), - commonjs: commonjs({sourceMap: false}), - json: json(), - multiEntry: multiEntry({exports: false}), - resolve: resolve({browser: true, main: true, jsnext: true}), - uglify: uglify({output: {comments: 'some'}}, minify), - replace: replace({ - include: ['node_modules/three/examples/js/**'], - patterns: [ - {transform(code, id) { - modules.forEach((m) => { - if (!(new RegExp(m)).test(id)) { - return; - } - - // trun the global modifiction into an import and a local variable definition - code = code.replace(`THREE.${m} =`, `import * as THREE from 'three';\nvar ${m} =`); - - // change references from the global modification to the local variable - code = globalReplace(code, `THREE.${m}`, m); - - // export that local variable as default from this module - code += `\nexport default ${m};`; - - // expose private functions so that users can manually use controls - // and we can add orientation controls - if (m === 'OrbitControls') { - code = globalReplace(code, 'function rotateLeft\\(', 'rotateLeft = function('); - code = globalReplace(code, 'function rotateUp\\(', 'rotateUp = function('); - - code = globalReplace(code, 'rotateLeft', 'scope.rotateLeft'); - code = globalReplace(code, 'rotateUp', 'scope.rotateUp'); - // comment out the context menu prevent default line... - code = globalReplace(code, - "scope.domElement.addEventListener\\( 'contextmenu'", - "\/\/scope.domElement.addEventListener\\( 'contextmenu'" - ); - } - }); - return code; - }} - ] - }) -}; diff --git a/scripts/rollup-replace.js b/scripts/rollup-replace.js new file mode 100644 index 00000000..077e63f2 --- /dev/null +++ b/scripts/rollup-replace.js @@ -0,0 +1,51 @@ +const replace = require('rollup-plugin-re'); + +// three modules to find-replace in +const modules = [ + 'VRControls', + 'VREffect', + 'OrbitControls', + 'DeviceOrientationControls' +]; + +const globalReplace = function(str, pattern, replacement) { + return str.replace(new RegExp(pattern, 'g'), replacement); +}; + +module.exports = replace({ + include: ['node_modules/three/examples/js/**'], + patterns: [ + {transform(code, id) { + modules.forEach((m) => { + if (!(new RegExp(m)).test(id)) { + return; + } + + // trun the global modifiction into an import and a local variable definition + code = code.replace(`THREE.${m} =`, `import * as THREE from 'three';\nvar ${m} =`); + + // change references from the global modification to the local variable + code = globalReplace(code, `THREE.${m}`, m); + + // export that local variable as default from this module + code += `\nexport default ${m};`; + + // expose private functions so that users can manually use controls + // and we can add orientation controls + if (m === 'OrbitControls') { + code = globalReplace(code, 'function rotateLeft\\(', 'rotateLeft = function('); + code = globalReplace(code, 'function rotateUp\\(', 'rotateUp = function('); + + code = globalReplace(code, 'rotateLeft', 'scope.rotateLeft'); + code = globalReplace(code, 'rotateUp', 'scope.rotateUp'); + // comment out the context menu prevent default line... + code = globalReplace(code, + "scope.domElement.addEventListener\\( 'contextmenu'", + "\/\/scope.domElement.addEventListener\\( 'contextmenu'" + ); + } + }); + return code; + }} + ] +}); diff --git a/scripts/rollup.config.js b/scripts/rollup.config.js index 5a631d12..d5665031 100644 --- a/scripts/rollup.config.js +++ b/scripts/rollup.config.js @@ -1,8 +1,36 @@ /** * Rollup configuration for packaging the plugin in various formats. */ -const plugins = require('./primed-rollup-plugins.js'); -const banner = require('./banner.js').comment; +const babel = require('rollup-plugin-babel'); +const commonjs = require('rollup-plugin-commonjs'); +const json = require('rollup-plugin-json'); +const multiEntry = require('rollup-plugin-multi-entry'); +const resolve = require('rollup-plugin-node-resolve'); +const {uglify} = require('rollup-plugin-uglify'); +const {minify} = require('uglify-es'); +const replace = require('./rollup-replace'); +const pkg = require('../package.json'); +const banner = `/*! @name ${pkg.name} @version ${pkg.version} @license ${pkg.license} */`; + +const plugins = { + babel: babel({ + babelrc: false, + exclude: 'node_modules/**', + presets: [ + ['env', {loose: true, modules: false, targets: {browsers: pkg.browserslist}}] + ], + plugins: [ + 'external-helpers', + 'transform-object-assign' + ] + }), + commonjs: commonjs({sourceMap: false}), + json: json(), + multiEntry: multiEntry({exports: false}), + resolve: resolve({browser: true, main: true, jsnext: true}), + uglify: uglify({output: {comments: 'some'}}, minify), + replace +}; // to prevent a screen during rollup watch/build process.stderr.isTTY = false; @@ -25,6 +53,16 @@ const moduleGlobals = { 'video.js': 'videojs' }; +const testGlobals = { + 'qunit': 'QUnit', + 'qunitjs': 'QUnit', + 'sinon': 'sinon', + 'video.js': 'videojs' +}; + +const testExternals = Object.keys(testGlobals).concat([ +]); + const builds = [{ // umd input: 'src/plugin.js', @@ -55,9 +93,7 @@ const builds = [{ external: Object.keys(moduleGlobals).concat([ 'global', 'global/document', - 'global/window', - 'three', - 'webvr-boilerplate' + 'global/window' ]), plugins: [ plugins.resolve, @@ -78,9 +114,7 @@ const builds = [{ external: Object.keys(moduleGlobals).concat([ 'global', 'global/document', - 'global/window', - 'three', - 'webvr-boilerplate' + 'global/window' ]), plugins: [ plugins.resolve, @@ -88,6 +122,24 @@ const builds = [{ plugins.replace, plugins.commonjs ] +}, { + // test bundle + input: 'test/**/*.test.js', + output: { + name: 'videojsVrTests', + file: 'test/dist/bundle.js', + format: 'iife', + globals: testGlobals + }, + external: testExternals, + plugins: [ + plugins.multiEntry, + plugins.resolve, + plugins.json, + plugins.replace, + plugins.commonjs, + plugins.babel + ] }]; if (!isWatch) {