Skip to content

Commit

Permalink
Add simple script to compile es6 to es5 using babel-core
Browse files Browse the repository at this point in the history
  • Loading branch information
dneukirchen committed Feb 12, 2018
1 parent 7305392 commit 4e4d949
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions build/build-modules-js/compile-es6.js
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);
});

0 comments on commit 4e4d949

Please sign in to comment.