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() {
|
||||
var fs = require('../lib/core/fs.js');
|
||||
var embarkConfig = fs.embarkPath('lib/pipeline/webpack.config.js');
|
||||
var dappConfig = fs.dappPath('webpack.config.js');
|
||||
var embarkConfig = fs.embarkPath('lib/pipeline', 'webpack.config.js');
|
||||
let ext = 1;
|
||||
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);
|
||||
fs.copyPreserve(embarkConfig, dappConfig);
|
||||
console.log(__('webpack config ejected to:').dim.yellow);
|
||||
console.log(`${dappConfig}`.green);
|
||||
var embarkOverrides = fs.embarkPath('lib/pipeline/webpack-overrides.js');
|
||||
var dappOverrides = fs.dappPath('webpack-overrides.js');
|
||||
var embarkOverrides = fs.embarkPath('lib/pipeline', 'webpack-overrides.js');
|
||||
ext = 1;
|
||||
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);
|
||||
fs.copyPreserve(embarkOverrides, dappOverrides);
|
||||
console.log(__('webpack overrides ejected to:').dim.yellow);
|
||||
console.log(`${dappOverrides}`.green);
|
||||
}
|
||||
|
||||
|
|
|
@ -115,6 +115,23 @@ function tmpDir() {
|
|||
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 = {
|
||||
mkdirpSync,
|
||||
mkdirp,
|
||||
|
@ -139,5 +156,6 @@ module.exports = {
|
|||
embarkPath,
|
||||
dappPath,
|
||||
createWriteStream,
|
||||
tmpDir
|
||||
tmpDir,
|
||||
copyPreserve
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue