NPM Resource Changed ? Pending

User tests: Successful: Unsuccessful:

avatar brianteeman
brianteeman
17 Dec 2020

There is a node command to gzip the assets

npm run gzip

When testing on windows it doesn't work (no idea about linux/mac)

After applying this PR then running the same command and it will work. (note it will appear to hang at the end - just be patient its slow)

Discovered while testing #31635

avatar brianteeman brianteeman - open - 17 Dec 2020
avatar brianteeman brianteeman - change - 17 Dec 2020
Status New Pending
avatar joomla-cms-bot joomla-cms-bot - change - 17 Dec 2020
Category NPM Change
avatar wilsonge
wilsonge - comment - 17 Dec 2020

This currently works on my macbook but doesn't after

george@ ~/Sites/joomla-cms (4.0-dev) $ npm run gzip

> joomla@4.0.0 gzip /Users/george/Sites/joomla-cms
> node -e require('./build/build-modules-js/gzip-assets.es6.js').gzipFiles()

sh: -c: line 0: syntax error near unexpected token `('
sh: -c: line 0: `node -e require('./build/build-modules-js/gzip-assets.es6.js').gzipFiles()'
avatar dgrammatiko
dgrammatiko - comment - 18 Dec 2020

If you still wanna keep this script I guess a better fix would be to change the build.js to

/**
 * Command line helper
 *
 * To get the complete functional media folder please run
 *
 * npm install
 *
 * For dedicated tasks, please run:
 * node build.js --build-pages  === will create the error pages (for incomplete repo build PHP+NPM)
 * node build.js --copy-assets  === will clean the media/vendor folder and then will populate the folder from node_modules
 * node build.js --compile-js   === will transpile ES6 files and also uglify the ES6,ES5 files
 * node build.js --compile-css  === will compile all the scss defined files and also create a minified version of the css
 * node build.js --gzip  === will create gzip files for all the minified stylesheets and scripts.'
 *
 */

// eslint-disable-next-line import/no-extraneous-dependencies
const Program = require('commander');
// eslint-disable-next-line import/no-extraneous-dependencies

// Joomla Build modules
const errorPages = require('./build-modules-js/error-pages.es6.js');
const init = require('./build-modules-js/init.es6.js');
const compileCSS = require('./build-modules-js/compilecss.es6.js');
const compileJS = require('./build-modules-js/compilejs.es6.js');
const minifyVendor = require('./build-modules-js/javascript/minify-vendor.es6.js');
const watch = require('./build-modules-js/watch.es6.js');
const {gzipFiles} = require('./build-modules-js/gzip-assets.es6');

// The settings
const options = require('../package.json');
const settings = require('./build-modules-js/settings.json');

// Merge Joomla's specific settings to the main package.json object
if ('settings' in settings) {
  options.settings = settings.settings;
}

// Initialize the CLI
Program
  .version(options.version)
  .option('--copy-assets', 'Moving files from node_modules to media folder')
  .option('--build-pages', 'Creates the error pages for unsupported PHP version & incomplete environment')
  .option('--compile-js, --compile-js path', 'Handles ES6, ES5 and web component scripts')
  .option('--compile-css, --compile-css path', 'Compiles all the scss files to css')
  .option('--watch', 'Watch file changes and re-compile (ATM only works for the js in the media_source).')
  .option('--gzip', 'Precompress all the minified stylesheets and scripts.')
  .on('--help', () => {
    // eslint-disable-next-line no-console
    console.log(`Version: ${options.version}`);
    process.exit(0);
  })
  .parse(process.argv);


// Show help by default
if (!process.argv.slice(2).length) {
  Program.outputHelp();
  process.exit(1);
}

// Update the vendor folder
if (Program.copyAssets) {
  Promise.resolve()
    .then(init.copyAssets(options))
    .then(minifyVendor.compile(options))

    // Exit with success
    .then(() => process.exit(0))

    // Handle errors
    .catch((err) => {
      // eslint-disable-next-line no-console
      console.error(err);
      process.exit(-1);
    });
}


// Creates the error pages for unsupported PHP version & incomplete environment
if (Program.buildPages) {
  Promise.resolve()
    .then(() => {
      errorPages.run(options);
      })
    // Handle errors
    .catch((err) => {
      // eslint-disable-next-line no-console
      console.error(err);
      process.exit(-1);
    });
}

// Convert scss to css
if (Program.compileCss) {
  compileCSS.compile(options, Program.args[0]);
}

// Compress/transpile the javascript files
if (Program.compileJs) {
  compileJS.compileJS(options, Program.args[0]);
}

// Watch for changes
if (Program.watch) {
  watch.run();
}

// Compress/transpile the javascript files
if (Program.gzip) {
  gzipFiles();
}

and then in the package.json change "gzip": "node -e 'require(\"./build/build-modules-js/gzip-assets.es6.js\").gzipFiles()'", to "gzip": "node build/build.js --gzip",

avatar wilsonge
wilsonge - comment - 18 Dec 2020

Yeah I think that makes sense

avatar wilsonge
wilsonge - comment - 29 Dec 2020

Successor PR using @dgrammatiko 's method (can confirm that it works on OSX at least)

avatar wilsonge wilsonge - close - 29 Dec 2020
avatar wilsonge wilsonge - change - 29 Dec 2020
Status Pending Closed
Closed_Date 0000-00-00 00:00:00 2020-12-29 17:04:47
Closed_By wilsonge
Labels Added: NPM Resource Changed ?

Add a Comment

Login with GitHub to post a comment