-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuildAndDeploy.js
47 lines (41 loc) · 1.7 KB
/
buildAndDeploy.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
let { readdir, readFile, writeFile, stat, mkdirSync } = require('fs');
const { promisify } = require('util');
var { copy } = require("fs-extra");
let rmdir = promisify(require('rimraf'));
readdir = promisify(readdir);
readFile = promisify(readFile);
stat = promisify(stat);
writeFile = promisify(writeFile);
copy = promisify(copy);
const deploymentFolderPath = '../one-note-spaced-repetition';
const buildFolderPath = './build';
const indexHTML = `${buildFolderPath}/index.html`;
readFile(indexHTML, 'UTF-8')
.then(fileContent => {
let html = fileContent.replace(/="\//g, `="./`);
html = html.replace('React App', 'Spaced repetition for one note');
html = html.replace('</head>', '<meta http-eqiv="Content-Security-Policy" content="sandbox allow-popups" /></head>');
writeFile(indexHTML, html)
})
.catch(error => console.log("Error modifying index.html"));
readdir(deploymentFolderPath).then(files => {
files.forEach(async (file, index) => {
if (file !== '.git') {
await rmdir(`${deploymentFolderPath}/${file}`);
}
if (index === files.length - 1) {
readdir(buildFolderPath).then(files => {
files.forEach(async file => {
const stats = await stat(`${buildFolderPath}/${file}`);
if (stats.isDirectory()) {
mkdirSync(`${deploymentFolderPath}/${file}`)
}
copy(`${buildFolderPath}/${file}`, `${deploymentFolderPath}/${file}`)
.catch(err => {
console.log(`Error copying file ${err}`);
});
});
});
}
});
});