forked from joomla/joomla-cms
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[4.0] Transpile es6 files (joomla#20954)
* Transpile es6 files as part of the --compilejs command * Update compile-es6.js * Update compilejs.js * Update compilejs.js * Update compilejs.js * fix all - Es6 everywhere (CLI) - Fix the incompatible html page for sub folders - ES6 transpiling when using —compilejs * again * m * mm * mmm
- Loading branch information
Showing
19 changed files
with
1,371 additions
and
1,208 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
# A list of files to ignore from linting | ||
*.js | ||
!*.es6.js | ||
!build/**/*.js | ||
build/**/**/*.js | ||
*.vue | ||
build/incompatible_page/*.js |
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 |
---|---|---|
@@ -1,60 +1,59 @@ | ||
const babelify = require("babelify"); | ||
const browserify = require("browserify"); | ||
const Chalk = require('chalk'); | ||
const babelify = require('babelify'); | ||
const browserify = require('browserify'); | ||
const chalk = require('chalk'); | ||
const fs = require('fs'); | ||
const fsExtra = require('fs-extra'); | ||
const Path = require('path'); | ||
const Promise = require('bluebird'); | ||
const UglifyJS = require('uglify-es'); | ||
const rootPath = require('./rootpath.js')._(); | ||
|
||
const compile = (options) => { | ||
// Make sure that the dist paths exist | ||
if (!fs.existsSync(`${rootPath}/media/system/webcomponents`)) { | ||
fsExtra.mkdirSync(`${rootPath}/media/system/webcomponents`); | ||
} | ||
if (!fs.existsSync(`${rootPath}/media/system/webcomponents/js`)) { | ||
fsExtra.mkdirSync(`${rootPath}/media/system/webcomponents/js`); | ||
} | ||
|
||
if (!fs.existsSync(Path.join(rootPath, '/media/system/webcomponents/css'))) { | ||
fs.mkdirSync(Path.join(rootPath, '/media/system/webcomponents/css')); | ||
} | ||
|
||
options.settings.elements.forEach((element) => { | ||
const b = browserify(); | ||
const c = browserify(); | ||
|
||
// Copy the ES6 file | ||
const es6File = fs.readFileSync(`${rootPath}/build/webcomponents/js/${element}/${element}.js`, 'utf8'); | ||
fs.writeFileSync(`${rootPath}/media/system/webcomponents/js/joomla-${element}.js`, es6File, { encoding: 'utf8' }); | ||
|
||
// And the minified version | ||
fs.writeFileSync(`${rootPath}/media/system/webcomponents/js/joomla-${element}.min.js`, UglifyJS.minify(es6File).code, { encoding: 'utf8' }); | ||
|
||
// Transpile a copy for ES5 | ||
fs.writeFileSync(`${rootPath}/media/system/webcomponents/js/joomla-${element}-es5.js`, ''); | ||
const bundleFs = fs.createWriteStream(`${rootPath}/media/system/webcomponents/js/joomla-${element}-es5.js`); | ||
const bundleFsMin = fs.createWriteStream(`${rootPath}/media/system/webcomponents/js/joomla-${element}-es5.min.js`); | ||
|
||
b.add(`${rootPath}/build/webcomponents/js/${element}/${element}.js`); | ||
c.add(`${rootPath}/build/webcomponents/js/${element}/${element}.js`); | ||
b.transform(babelify, { presets: ['babel-preset-es2015'] }).bundle().pipe(bundleFs); | ||
c.transform(babelify, { presets: ['babel-preset-es2015', 'babel-preset-minify'] }).bundle().pipe(bundleFsMin); | ||
}); | ||
}; | ||
|
||
const compileCEjs = (options, path) => { | ||
Promise.resolve() | ||
.then(() => compile(options, path)) | ||
|
||
// Various variables | ||
const rootPath = __dirname.replace('/build/build-modules-js', '').replace('\\build\\build-modules-js', ''); | ||
|
||
compileCejs = (options) => { | ||
// Make sure that the dist paths exist | ||
if (!fs.existsSync(rootPath + '/media/system/webcomponents')) { | ||
fsExtra.mkdirSync(rootPath + '/media/system/webcomponents'); | ||
} | ||
if (!fs.existsSync(rootPath + '/media/system/webcomponents/js')) { | ||
fsExtra.mkdirSync(rootPath + '/media/system/webcomponents/js'); | ||
} | ||
|
||
if (!fs.existsSync(Path.join(rootPath, '/media/system/webcomponents/css'))) { | ||
fs.mkdirSync(Path.join(rootPath, '/media/system/webcomponents/css')); | ||
} | ||
|
||
options.settings.elements.forEach((element) => { | ||
const b = browserify(); | ||
const c = browserify(); | ||
|
||
// Copy the ES6 file | ||
const es6File = fs.readFileSync(rootPath + '/build/webcomponents/js/' + element + '/' + element + '.js', "utf8"); | ||
fs.writeFileSync(rootPath + '/media/system/webcomponents/js/joomla-' + element + '.js', es6File, { encoding: "utf8" }); | ||
|
||
// And the minified version | ||
fs.writeFileSync(rootPath + '/media/system/webcomponents/js/joomla-' + element + '.min.js', UglifyJS.minify(es6File).code, { encoding: "utf8" }); | ||
|
||
// Transpile a copy for ES5 | ||
fs.writeFileSync(rootPath + '/media/system/webcomponents/js/joomla-' + element + '-es5.js', ''); | ||
const bundleFs = fs.createWriteStream(rootPath + '/media/system/webcomponents/js/joomla-' + element + '-es5.js'); | ||
const bundleFsMin = fs.createWriteStream(rootPath + '/media/system/webcomponents/js/joomla-' + element + '-es5.min.js'); | ||
|
||
b.add(rootPath + '/build/webcomponents/js/' + element + '/' + element + '.js'); | ||
c.add(rootPath + '/build/webcomponents/js/' + element + '/' + element + '.js'); | ||
b.transform(babelify, { presets: ["babel-preset-es2015"] }).bundle().pipe(bundleFs); | ||
c.transform(babelify, { presets: ["babel-preset-es2015", "babel-preset-minify"] }).bundle().pipe(bundleFsMin); | ||
}); | ||
} | ||
|
||
compileCEjs = (options, path) => { | ||
Promise.resolve() | ||
.then(() => compileCejs(options, path)) | ||
|
||
// Handle errors | ||
.catch((err) => { | ||
console.error(Chalk.red(err)); | ||
process.exit(-1); | ||
}); | ||
// Handle errors | ||
.catch((err) => { | ||
// eslint-disable-next-line no-console | ||
console.error(`${chalk.red(err)}`); | ||
process.exit(-1); | ||
}); | ||
}; | ||
|
||
module.exports.compileCEjs = compileCEjs; | ||
module.exports.compile = compileCEjs; |
Oops, something went wrong.