forked from joomla/joomla-cms
-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[4.0] Feature/compile es6 (joomla#19650)
* Improve eslint IDE support (ignore .js, lint *.es6.js) * Adjust eslint rules: allow usage of dev dependencies in build directory * Add babelrc * Install glob and babel-core * Add simple script to compile es6 to es5 using babel-core * Disable module transformation By default babel transforms to commonjs. * CS * Example-1: Copy old file and suffix it with .es6.js * Example-2: Fix code style according to new style guide * Example-3: Execute compiler * Add do-not-modify message * Change browser targets * Use literals * Use arrow function * CS * Update target browsers * Allow „use-strict“ * Remove & Revert example * Revert CS
- Loading branch information
1 parent
a354d8f
commit 8d194a9
Showing
5 changed files
with
68 additions
and
4 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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"presets": [ | ||
[ | ||
"env", | ||
{ | ||
"modules": false, | ||
"targets": { | ||
"browsers": [ | ||
"last 1 version" | ||
] | ||
} | ||
} | ||
] | ||
] | ||
} |
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 +1,4 @@ | ||
# A list of files to ignore from linting | ||
*.js | ||
!*.es6.js | ||
!build/**/*.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
const glob = require('glob'); | ||
const fs = require('fs'); | ||
const babel = require('babel-core'); | ||
|
||
const pattern = './**/*.es6.js'; | ||
const options = { | ||
ignore: './node_modules/**', | ||
}; | ||
|
||
/** | ||
* Compiles es6 files to es5. | ||
* @param filePath | ||
*/ | ||
const compileFile = (filePath) => { | ||
const headerText = `PLEASE DO NOT MODIFY THIS FILE. WORK ON THE ES6 VERSION. | ||
OTHERWISE YOUR CHANGES WILL BE REPLACED ON THE NEXT BUILD.`; | ||
const babelOptions = { | ||
plugins: [ | ||
['add-header-comment', { header: [headerText] }], | ||
], | ||
}; | ||
|
||
babel.transformFile(filePath, babelOptions, (error, result) => { | ||
if (error) process.exit(1); | ||
const fileName = filePath.slice(0, -7); | ||
fs.writeFile(`${fileName}.js`, result.code, (fsError) => { | ||
if (fsError) process.exit(1); | ||
}); | ||
}); | ||
}; | ||
|
||
// Compile all files of the given pattern | ||
glob(pattern, options, (error, files) => { | ||
if (error) process.exit(1); | ||
files.forEach(compileFile); | ||
}); |
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