Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch '4.0-dev' into fix#23850
- Loading branch information
Showing
19 changed files
with
548 additions
and
139 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
/** | ||
* For creating Brotli files you need to install iltorb | ||
* and import it like: | ||
* const { compressStream } = require('iltorb'); | ||
*/ | ||
const Fs = require('fs'); | ||
const { gzip } = require('@gfx/zopfli'); | ||
const RootPath = require('./utils/rootpath.es6.js')._(); | ||
const WalkSync = require('./utils/walk-sync.es6.js'); | ||
|
||
const compressStream = ''; | ||
const options = { | ||
verbose: false, | ||
verbose_more: false, | ||
numiterations: 15, | ||
blocksplitting: true, | ||
blocksplittingmax: 15, | ||
}; | ||
|
||
/** | ||
* Method that will create a gzipped vestion of the given file | ||
* | ||
* @param { string } file The path of the file | ||
* | ||
* @returns { void } | ||
*/ | ||
const handleFile = (file, enableBrotli) => { | ||
if (file.match('/images') || file.match('\\images')) { | ||
return; | ||
} | ||
|
||
|
||
if (file.match(/\.min\.js/) && !file.match(/\.min\.js\.gz/) && !file.match(/\.min\.js\.br/) && !file.toLowerCase().match(/json/) && !file.toLowerCase().match(/license/)) { | ||
// eslint-disable-next-line no-console | ||
console.log(`Processing: ${file}`); | ||
|
||
if (enableBrotli && compressStream) { | ||
// Brotli file | ||
Fs.createReadStream(file) | ||
.pipe(compressStream()) | ||
.pipe(Fs.createWriteStream(file.replace(/\.js$/, '.js.br'))); | ||
} else { | ||
// Gzip the file | ||
Fs.readFile(file, (err, data) => { | ||
if (err) throw err; | ||
gzip(data, options, (error, output) => { | ||
if (error) throw err; | ||
// Save the gzipped file | ||
Fs.writeFileSync( | ||
file.replace(/\.js$/, '.js.gz'), | ||
output, | ||
{ encoding: 'utf8' }, | ||
); | ||
}); | ||
}); | ||
} | ||
} | ||
|
||
if (file.match(/\.min\.css/) && !file.match(/\.min\.css\.gz/) && !file.match(/\.min\.css\.br/) && !file.match(/\.css\.map/) && !file.toLowerCase().match(/license/)) { | ||
// eslint-disable-next-line no-console | ||
console.log(`Processing: ${file}`); | ||
|
||
if (enableBrotli && compressStream) { | ||
// Brotli file | ||
Fs.createReadStream(file) | ||
.pipe(compressStream()) | ||
.pipe(Fs.createWriteStream(file.replace(/\.css$/, '.css.br'))); | ||
} else { | ||
// Gzip the file | ||
Fs.readFile(file, (err, data) => { | ||
if (err) throw err; | ||
gzip(data, options, (error, output) => { | ||
if (error) throw err; | ||
// Save the gzipped file | ||
Fs.writeFileSync( | ||
file.replace(/\.css$/, '.css.gz'), | ||
output, | ||
{ encoding: 'utf8' }, | ||
); | ||
}); | ||
}); | ||
} | ||
} | ||
}; | ||
|
||
/** | ||
* Method to gzip the script and stylesheet files | ||
* | ||
* @param brotliParam {string} The CLI argument | ||
* | ||
* @returns { void } | ||
*/ | ||
const gzipFiles = (brotliParam) => { | ||
let enableBrotli = false; | ||
if (brotliParam === 'brotli') { | ||
enableBrotli = true; | ||
} | ||
// Minify the legacy files | ||
// eslint-disable-next-line no-console | ||
console.log('Gziping stylesheets and scripts...'); | ||
|
||
const templatesFiles = WalkSync.run(`${RootPath}/templates`, []); | ||
const adminTemplatesFiles = WalkSync.run(`${RootPath}/administrator/templates`, []); | ||
const mediaFiles = WalkSync.run(`${RootPath}/media`, []); | ||
|
||
if (templatesFiles.length) { | ||
templatesFiles.forEach(file => handleFile(file, enableBrotli)); | ||
} | ||
if (adminTemplatesFiles.length) { | ||
adminTemplatesFiles.forEach(file => handleFile(file, enableBrotli)); | ||
} | ||
if (mediaFiles.length) { | ||
mediaFiles.forEach(file => handleFile(file, enableBrotli)); | ||
} | ||
}; | ||
|
||
module.exports.gzipFiles = gzipFiles; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.