forked from rbrahul/Awesome-JSON-Viewer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
chrome-ready.js
74 lines (66 loc) · 1.84 KB
/
chrome-ready.js
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
66
67
68
69
70
71
72
73
74
var exec = require('child_process').exec;
var fs = require('fs').promises;
exec(
'mv ' +
__dirname +
'/build/static/js/main*.js ' +
__dirname +
'/build/js/main.js',
function (error, stdout, stderr) {
if (error !== null) {
console.log('exec error: ' + error);
} else {
console.log('Main.js file has been generated successfully');
}
},
);
exec(
'mv ' +
__dirname +
'/build/static/css/main*.css ' +
__dirname +
'/build/css/main.css',
function (error, stdout, stderr) {
if (error !== null) {
console.log('exec error: ' + error);
} else {
console.log('Main.css file has been generated successfully');
}
},
);
exec('rm -rf ' + __dirname + '/build/static ', function (
error,
stdout,
stderr,
) {
if (error !== null) {
console.log('exec error: ' + error);
} else {
console.log('build/static has been deleted successfully');
}
});
['asset-manifest.json'].forEach((file) => {
exec('rm -f ' + __dirname + '/build/' + file, function (
error,
stdout,
stderr,
) {
if (error !== null) {
console.log('exec error: ' + error);
} else {
console.log('Unecessery files have been deleted successfully');
}
});
});
/** REMOVE HASH FROM INDEX.html from style.css and main.js */
const indexHTMLInBuild = __dirname + '/build/index.html';
fs.readFile(indexHTMLInBuild).then((data) => {
let text = data.toString();
text = text.replace(/main\.(?:.)+\.(js|css)"/g, (_, $1) => {
return `main.${$1}"`;
});
text = text.replace(/\/static/g, '');
fs.writeFile(indexHTMLInBuild, text).then(() => {
console.log('Removed file naming Hash from build/index.html');
});
});