2017-05-25 16:41:29 +03:00
|
|
|
const { readFile, writeFile, exists } = require('mz/fs');
|
|
|
|
const main = require('apr-main');
|
2017-06-02 01:32:58 +03:00
|
|
|
const forEach = require('apr-for-each');
|
2017-06-09 07:26:25 +03:00
|
|
|
const find = require('apr-find');
|
2017-05-23 16:27:04 +03:00
|
|
|
const path = require('path');
|
|
|
|
|
2017-06-02 01:32:58 +03:00
|
|
|
const configs = ['webpack.config.dev', 'webpack.config.prod'];
|
2017-05-25 16:41:29 +03:00
|
|
|
|
2017-06-02 01:32:58 +03:00
|
|
|
const toCopy = [
|
|
|
|
'patch-webpack-config',
|
|
|
|
'webpack.config.dev',
|
|
|
|
'webpack.config.prod'
|
|
|
|
];
|
2017-05-23 16:27:04 +03:00
|
|
|
|
2017-06-09 07:26:25 +03:00
|
|
|
let ROOT;
|
|
|
|
|
2017-06-02 01:32:58 +03:00
|
|
|
const backup = async file => {
|
|
|
|
const backupPath = path.join(ROOT, `${file}.original.js`);
|
|
|
|
const backupExists = await exists(backupPath);
|
|
|
|
|
|
|
|
if (backupExists) {
|
|
|
|
return;
|
|
|
|
}
|
2017-05-25 16:41:29 +03:00
|
|
|
|
2017-06-02 01:32:58 +03:00
|
|
|
const originalPath = path.join(ROOT, `${file}.js`);
|
|
|
|
const orignalConfig = await readFile(originalPath, 'utf-8');
|
|
|
|
return writeFile(backupPath, orignalConfig);
|
|
|
|
};
|
2017-05-18 21:21:33 +03:00
|
|
|
|
2017-06-02 01:32:58 +03:00
|
|
|
const copy = async file => {
|
|
|
|
const srcPath = path.join(__dirname, `${file}.js`);
|
|
|
|
const destPath = path.join(ROOT, `${file}.js`);
|
|
|
|
|
|
|
|
const src = await readFile(srcPath, 'utf-8');
|
|
|
|
return writeFile(destPath, src);
|
|
|
|
};
|
|
|
|
|
|
|
|
main(
|
|
|
|
(async () => {
|
2017-06-09 07:26:25 +03:00
|
|
|
ROOT = await find([
|
|
|
|
path.join(__dirname, '../node_modules/react-scripts/config'),
|
|
|
|
path.join(__dirname, '../../../node_modules/react-scripts/config')
|
|
|
|
], exists);
|
|
|
|
|
|
|
|
if (!ROOT) {
|
|
|
|
throw new Error('react-scripts not found');
|
|
|
|
}
|
|
|
|
|
2017-06-02 01:32:58 +03:00
|
|
|
await forEach(configs, backup);
|
|
|
|
await forEach(toCopy, copy);
|
2017-05-25 23:03:39 +03:00
|
|
|
})()
|
|
|
|
);
|