-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add simple script to compile es6 to es5 using babel-core
- Loading branch information
1 parent
7305392
commit 4e4d949
Showing
1 changed file
with
27 additions
and
0 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,27 @@ | ||
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) => { | ||
babel.transformFile(filePath, {}, (error, result) => { | ||
if (error) process.exit(1); | ||
const fileName = filePath.slice(0, -7); | ||
fs.writeFile(`${fileName}.js`, result.code); | ||
}); | ||
}; | ||
|
||
// Compile all files of the given pattern | ||
glob(pattern, options, (error, files) => { | ||
if (error) process.exit(1); | ||
files.forEach(compileFile); | ||
}); | ||
|