This repository was archived by the owner on Jan 7, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathappStyle.js
More file actions
65 lines (53 loc) · 1.6 KB
/
appStyle.js
File metadata and controls
65 lines (53 loc) · 1.6 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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
const path = require('path');
const fs = require('fs');
require('colors');
const shippingConfigs = require('./configs');
const appStylePath = path.join(__dirname, '../../../../YourAweSomeProject/src/appStyle.js');
const destDirName = shippingConfigs.configDir;
function copyAppStyle(config, saving) {
const savePath = path.join(destDirName, config, 'appStyle/appStyle.js');
const restorePath = appStylePath;
const destFile = saving ? savePath : restorePath;
const initialFile = saving ? restorePath : savePath;
return new Promise((resolve, reject) => {
try {
console.log('Copying the appStyle');
fs.createReadStream(initialFile).pipe(fs.createWriteStream(destFile));
} catch (e) {
console.log('Error copying the appStyle'.red);
reject(e);
}
const verb = saving ? 'saved' : 'restored';
console.log(`AppStyle successfully ${verb}`.green);
resolve();
});
}
function saveAppStyle(config) {
console.log('');
console.log(`Saving the appStyle for config ${config}`.yellow);
const destDir = path.join(destDirName, config);
if (!fs.existsSync(destDir)) {
try {
fs.mkdirSync(destDir);
} catch (e) {
console.log(e);
}
}
if (!fs.existsSync(path.join(destDir, 'appStyle'))) {
try {
fs.mkdirSync(path.join(destDir, 'appStyle'));
} catch (e) {
console.log(e);
}
}
return copyAppStyle(config, true);
}
function restoreAppStyle(config) {
console.log('');
console.log(`Restoring the appStyle for config ${config}`.yellow);
return copyAppStyle(config, false);
}
module.exports = {
saveAppStyle,
restoreAppStyle
};