-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcopyThemeHelper.js
More file actions
32 lines (27 loc) · 1.1 KB
/
copyThemeHelper.js
File metadata and controls
32 lines (27 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
const fs = require('fs');
const path = require('path');
const { exec } = require('child_process');
var copyMagentoFile = function(fileName, parent, child) {
const parentEnv = parent.src;
const themeEnv = child.src;
const filePath = fileName.replace(parentEnv, '');
const parentFileToCopy = `${parentEnv}/${filePath}`;
const themeFile = `${themeEnv}${filePath}`;
fs.promises.mkdir(path.parse(themeFile).dir, { recursive: true }, (err) => {
if (err) throw err;
}).then(() => {
fs.createReadStream(parentFileToCopy).pipe(fs.createWriteStream(themeFile));
commitFile(themeFile);
});
}
const commitFile = (themeFile) => {
const fileName = path.parse(themeFile).base;
exec(`git add ${themeFile} && git commit -m "chore: copy ${fileName} to override \n\nCopying ${themeFile} to theme to override." `, (err, stdout, stderr) => {
if (err) {
console.log('This file may have already been committed.')
return;
}
console.log(`File copied to theme. Committing ${themeFile}`);
});
}
module.exports = {copyMagentoFile, commitFile};