mirror of https://github.com/embarklabs/embark.git
extract copy/preserve logic into a helper in lib/core/fs
preserved files should end with <number>.<ext> vs. <ext>.<number>
This commit is contained in:
parent
dc8b171354
commit
ae878fd7c8
|
@ -419,33 +419,15 @@ class EmbarkController {
|
||||||
|
|
||||||
ejectWebpack() {
|
ejectWebpack() {
|
||||||
var fs = require('../lib/core/fs.js');
|
var fs = require('../lib/core/fs.js');
|
||||||
|
var embarkConfig = fs.embarkPath('lib/pipeline/webpack.config.js');
|
||||||
var dappConfig = fs.dappPath('webpack.config.js');
|
var dappConfig = fs.dappPath('webpack.config.js');
|
||||||
var embarkConfig = fs.embarkPath('lib/pipeline', 'webpack.config.js');
|
fs.copyPreserve(embarkConfig, dappConfig);
|
||||||
let ext = 1;
|
console.log(__('webpack config ejected to:').dim.yellow);
|
||||||
let dappConfigOld = dappConfig;
|
|
||||||
while (fs.existsSync(dappConfigOld)) {
|
|
||||||
dappConfigOld = dappConfig + `.${ext}`;
|
|
||||||
ext++;
|
|
||||||
}
|
|
||||||
if (dappConfigOld !== dappConfig) {
|
|
||||||
fs.copySync(dappConfig, dappConfigOld);
|
|
||||||
}
|
|
||||||
fs.copySync(embarkConfig, dappConfig);
|
|
||||||
console.log(__('webpack config ejected to: ').dim.yellow);
|
|
||||||
console.log(`${dappConfig}`.green);
|
console.log(`${dappConfig}`.green);
|
||||||
|
var embarkOverrides = fs.embarkPath('lib/pipeline/webpack-overrides.js');
|
||||||
var dappOverrides = fs.dappPath('webpack-overrides.js');
|
var dappOverrides = fs.dappPath('webpack-overrides.js');
|
||||||
var embarkOverrides = fs.embarkPath('lib/pipeline', 'webpack-overrides.js');
|
fs.copyPreserve(embarkOverrides, dappOverrides);
|
||||||
ext = 1;
|
console.log(__('webpack overrides ejected to:').dim.yellow);
|
||||||
let dappOverridesOld = dappOverrides;
|
|
||||||
while (fs.existsSync(dappOverridesOld)) {
|
|
||||||
dappOverridesOld = dappOverrides + `.${ext}`;
|
|
||||||
ext++;
|
|
||||||
}
|
|
||||||
if (dappOverridesOld !== dappOverrides) {
|
|
||||||
fs.copySync(dappOverrides, dappOverridesOld);
|
|
||||||
}
|
|
||||||
fs.copySync(embarkOverrides, dappOverrides);
|
|
||||||
console.log(__('webpack overrides ejected to: ').dim.yellow);
|
|
||||||
console.log(`${dappOverrides}`.green);
|
console.log(`${dappOverrides}`.green);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -115,6 +115,23 @@ function tmpDir() {
|
||||||
return utils.joinPath(os.tmpdir(), ...arguments);
|
return utils.joinPath(os.tmpdir(), ...arguments);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function copyPreserve(sourceFilePath, targetFilePath) {
|
||||||
|
const path = require('path');
|
||||||
|
let ext = 1;
|
||||||
|
let preserved = targetFilePath;
|
||||||
|
while (fs.existsSync(preserved)) {
|
||||||
|
preserved = utils.joinPath(
|
||||||
|
path.dirname(targetFilePath),
|
||||||
|
`${path.basename(targetFilePath)}.${ext}${path.extname(targetFilePath)}`
|
||||||
|
);
|
||||||
|
ext++;
|
||||||
|
}
|
||||||
|
if (preserved !== targetFilePath) {
|
||||||
|
fs.copySync(targetFilePath, preserved);
|
||||||
|
}
|
||||||
|
fs.copySync(sourceFilePath, targetFilePath);
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
mkdirpSync,
|
mkdirpSync,
|
||||||
mkdirp,
|
mkdirp,
|
||||||
|
@ -139,5 +156,6 @@ module.exports = {
|
||||||
embarkPath,
|
embarkPath,
|
||||||
dappPath,
|
dappPath,
|
||||||
createWriteStream,
|
createWriteStream,
|
||||||
tmpDir
|
tmpDir,
|
||||||
|
copyPreserve
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue