From 13c07e6ce9f64b649f43b0e64820545dc4a7793e Mon Sep 17 00:00:00 2001 From: mattpen Date: Thu, 14 Mar 2019 13:55:09 -0600 Subject: [PATCH] Added LZMA asset for #746 --- js/grunt/buildRunnable.js | 18 +++++++++++++++++- package.json | 5 +++-- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/js/grunt/buildRunnable.js b/js/grunt/buildRunnable.js index 9473fbe6b..f72912970 100644 --- a/js/grunt/buildRunnable.js +++ b/js/grunt/buildRunnable.js @@ -16,6 +16,7 @@ const ChipperConstants = require( '../common/ChipperConstants' ); const ChipperStringUtils = require( '../common/ChipperStringUtils' ); const copyDirectory = require( './copyDirectory' ); const copySupplementalPhetioFiles = require( './phet-io/copySupplementalPhetioFiles' ); +const fs = require( 'fs' ); const generateThumbnails = require( './generateThumbnails' ); const generateTwitterCard = require( './generateTwitterCard' ); const getA11yViewHTMLFromTemplate = require( './getA11yViewHTMLFromTemplate' ); @@ -30,6 +31,7 @@ const getTitleStringKey = require( './getTitleStringKey' ); const grunt = require( 'grunt' ); const jimp = require( 'jimp' ); const loadFileAsDataURI = require( '../common/loadFileAsDataURI' ); +const lzma = require( 'lzma-native' ); // eslint-disable-line require-statement-match const minify = require( './minify' ); const nodeHTMLEncoder = require( 'node-html-encoder' ); // eslint-disable-line require-statement-match const packageRunnable = require( './packageRunnable' ); @@ -187,13 +189,27 @@ module.exports = async function( repo, minifyOptions, instrument, allHTML, brand includeAllLocales: true, isDebugBuild: false }, commonInitializationOptions ) ); - grunt.file.write( `${buildDir}/${repo}_all_${brand}.html`, packageRunnable( { + + const allHTMLFilename = `${buildDir}/${repo}_all_${brand}.html`; + + grunt.file.write( allHTMLFilename, packageRunnable( { repo: repo, stringMap: stringMap, htmlHeader: htmlHeader, locale: ChipperConstants.FALLBACK_LOCALE, scripts: [ initializationScript, splashScript, mipmapsJavaScript, ...productionPreloads, chipperStringsScript, productionJS ] } ) ); + + try { + // Create LZMA compressed asset + fs.createReadStream( allHTMLFilename ) + .pipe( lzma.createCompressor() ) + .pipe( fs.createWriteStream( `${allHTMLFilename}.xz` ) ); + } + catch ( error ) { + grunt.log.error( error ); + throw new Error( 'lzma compression failed' ); + } } // Debug build (always included) diff --git a/package.json b/package.json index d39a1b280..24295814a 100644 --- a/package.json +++ b/package.json @@ -17,16 +17,17 @@ "jscpd": "^0.6.18", "jsdoc": "~3.5.5", "lodash": "^4.17.10", + "lzma-native": "^4.0.3", "md5": "~2", "node-html-encoder": "~0.0.2", "pngjs": "~0.4.0", "qunit": "~2.4.1", "request": "^2.87.0", - "request-promise-native": "~1.0.5", + "request-promise-native": "^1.0.7", "requirejs": "~2.3.5", "uglify-es": "~3.1.10" }, "eslintConfig": { "extends": "../chipper/eslint/sim_eslintrc.js" } -} \ No newline at end of file +}