embark/packages/embark/.babelrc.js
Eric Mastro 3f7842cf24 refactor(@embark/embarkjs): move module into own package (#1945)
**TODO:** The `embark eject-webpack` command needs to be updated. @michaelsbradleyjr - do you have suggestions as to how we could port this over? We could **assume** that the `basic-pipeline` plugin will be installed, and then read the embark config and overrides from the file system, however this feels like we are sort adding a dependency to a plugin, which is not right. Any suggestions?
2019-10-14 16:05:17 +09:00

61 lines
1.8 KiB
JavaScript

/* global __dirname module require */
const cloneDeep = require('lodash.clonedeep');
const {copySync, ensureDirSync} = require('fs-extra');
const glob = require('glob');
const {dirname, join, normalize, relative, sep} = 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 the un-transpiled webpack config and babel-loader
// overrides script from the basic-pipeline to be copied into the respective
// subdir in dist/; we also want to copy .ejs and .json 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).map(normalize);
ignored
.map(path => path.replace(`src${sep}`, `dist${sep}`))
.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(node.ignore || []);
return node;
}
const test = cloneDeep(node);
if (env === 'test') {
copyFiles(test.ignore || []);
return test;
}
return base;
};