Skip to content

Commit fc3af7d

Browse files
committed
Added post build script for deployment
1 parent 98580c5 commit fc3af7d

68 files changed

Lines changed: 2057 additions & 88 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

asset-manifest.json

Lines changed: 321 additions & 9 deletions
Large diffs are not rendered by default.

favicon.ico

2.26 MB
Binary file not shown.

index.html

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

package.json

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,19 @@
1616
"start": "react-scripts start",
1717
"build": "react-scripts build",
1818
"test": "react-scripts test --env=jsdom",
19-
"eject": "react-scripts eject"
19+
"eject": "react-scripts eject",
20+
"postbuild": "node postbuild.js"
2021
},
2122
"browserslist": [
2223
">0.2%",
2324
"not dead",
2425
"not ie <= 11",
2526
"not op_mini all"
26-
]
27+
],
28+
"devDependencies": {
29+
"chalk": "^2.4.1",
30+
"colors-cli": "^1.0.20",
31+
"mv": "^2.1.1",
32+
"promise-fs": "^2.0.1"
33+
}
2734
}

postbuild.js

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
const fs = require("promise-fs")
2+
const colors = require('colors-cli')
3+
const files = []
4+
5+
const error = colors.red
6+
const success = colors.green
7+
8+
const walker = async (files, path, nest) => {
9+
10+
const dirFiles = await fs.readdir(path)
11+
12+
for (let c = 0; c < dirFiles.length; c++) {
13+
const file = dirFiles[c]
14+
const stats = await fs.lstat(`${path}${file}`)
15+
16+
if (stats.isDirectory()) {
17+
await walker(files, `${path}${file}/`, `${nest}/${file}`)
18+
} else {
19+
files.push(`${nest}/${file}`)
20+
}
21+
}
22+
}
23+
24+
const deletor = async (path) => {
25+
26+
const dirFiles = await fs.readdir(path)
27+
28+
for (let c = 0; c < dirFiles.length; c++) {
29+
const file = dirFiles[c]
30+
const stats = await fs.lstat(`${path}${file}`)
31+
32+
if (stats.isDirectory()) {
33+
await deletor(`${path}${file}/`)
34+
} else {
35+
await fs.unlink(`${path}${file}`)
36+
}
37+
}
38+
}
39+
40+
deletor("./static/")
41+
.then(() => {
42+
console.log(success("Deleted all old files"))
43+
return ""
44+
})
45+
.then(() => walker(files, "build/", "."))
46+
.then(() => {
47+
// console.log(files)
48+
49+
const fileWritePromises = files.map(name => {
50+
return new Promise(async (resolve, reject) => {
51+
try {
52+
const data = await fs.readFile(`build/${name}`)
53+
await fs.writeFile(name, data, {flag: "a+"})
54+
55+
resolve()
56+
} catch (err) {
57+
reject(err)
58+
}
59+
})
60+
})
61+
62+
return Promise.all(fileWritePromises)
63+
})
64+
.then(() => {
65+
console.log(success("All files have been written and ready to be deployed."))
66+
})
67+
.catch(err => {
68+
console.log(error(err))
69+
console.log(error("Please rebuild or checkout to the last stable release"))
70+
})

0 commit comments

Comments
 (0)