embark/packages/plugins/web3/.babelrc.js

59 lines
1.6 KiB
JavaScript

/* global __dirname module require */
const cloneDeep = require('lodash.clonedeep');
const {copySync, ensureDirSync} = require('fs-extra');
const glob = require('glob');
const {dirname, join, relative} = require('path');
// @babel/cli v7's --copy-files option does not work well together with
// config-specified ignore paths, and that's a problem for embark-collective
// actions since the @babel/cli invocation must be the same across all packages
// in the collective; so any package in the collective that excludes src/ files
// from transpilation via its package-local .babelrc.js should copy those files
// into dist/, but only if they are expected to be in dist/; .babelrc.js should
// also copy any non .js,.ts files into /dist
// in this case we want we want to copy .ejs files
function copyFiles (ignored) {
const others = glob.sync(
join(__dirname, 'src/**/*.*'),
{ignore: [
join(__dirname, 'src/**/*.js'),
join(__dirname, 'src/**/*.ts'),
join(__dirname, 'src/**/*.disabled')
]}
).map(path => relative(__dirname, path));
ignored = ignored.concat(others);
ignored
.map(path => path.replace('src/', 'dist/'))
.forEach((dest, index) => {
ensureDirSync(dirname(join(__dirname, dest)));
const source = ignored[index];
copySync(join(__dirname, source), join(__dirname, dest));
});
}
module.exports = (api) => {
const env = api.env();
const base = {};
const node = cloneDeep(base);
if (env === 'node') {
copyFiles([]);
return node;
}
const test = cloneDeep(node);
if (env === 'test') {
copyFiles([]);
return test;
}
return base;
};