2019-09-18 19:30:41 +00:00
|
|
|
/* global __dirname module require */
|
|
|
|
|
|
|
|
const cloneDeep = require('lodash.clonedeep');
|
|
|
|
const {copySync, ensureDirSync} = require('fs-extra');
|
|
|
|
const glob = require('glob');
|
2019-10-02 21:14:23 +00:00
|
|
|
const {dirname, join, normalize, relative, sep} = require('path');
|
2019-09-18 19:30:41 +00:00
|
|
|
|
|
|
|
// @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 .hbs 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));
|
|
|
|
|
2019-10-02 21:14:23 +00:00
|
|
|
ignored = ignored.concat(others).map(normalize);
|
2019-09-18 19:30:41 +00:00
|
|
|
ignored
|
2019-10-02 21:14:23 +00:00
|
|
|
.map(path => path.replace(`src${sep}`, `dist${sep}`))
|
2019-09-18 19:30:41 +00:00
|
|
|
.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;
|
|
|
|
};
|