-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeploy.js
75 lines (71 loc) · 2.24 KB
/
deploy.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
75
const simpleGit = require('simple-git');
const fs = require('fs-extra');
const path = require('path');
const options = {
baseDir: process.cwd(),
binary: 'git',
maxConcurrentProcesses: 6,
};
const git = simpleGit(options);
const directory = '.';
let distFolder = path.join(directory, "dist");
fs.readdir(directory).then((files) => {
let deleteAllExceptDist = [];
for (const file of files) {
if (file != ".git" &&
file != ".gitignore" &&
file != ".vscode" &&
file != "node_modules" &&
file != "dist") {
console.log("Delete", file);
deleteAllExceptDist.push(fs.remove(path.join(directory, file)));
}
}
return Promise.all(deleteAllExceptDist);
}).then(() => {
console.log("Checkout gh-pages");
return git.checkout("gh-pages");
}).then(() => {
return fs.readdir(directory).then((files) => {
let deleteAllExceptDist = [];
for (const file of files) {
if (file != ".git" &&
file != ".gitignore" &&
file != ".vscode" &&
file != "node_modules" &&
file != "CNAME" &&
file != "dist") {
console.log("Delete", file);
deleteAllExceptDist.push(fs.remove(path.join(directory, file)));
}
}
return Promise.all(deleteAllExceptDist);
});
}).then(() => {
console.log("Read dist folder contents");
return fs.readdir(distFolder);
}).then((files) => {
console.log("Move all files out");
let moveUp = files.map((file) => { return fs.move(path.join(distFolder, file), path.join(directory, file), {overwrite: true}); });
return Promise.all(moveUp);
}).then(() => {
// delete dist
console.log("Delete dist folder");
return fs.remove(distFolder);
}).then(() => {
// git add everything
console.log("git add everything");
return git.add(".");
}).then(() => {
// git commit
console.log("Commit");
return git.commit(`Deploy at ${(new Date()).toString()}`);
}).then(() => {
// git push
console.log("Push");
return git.push();
}).then(() => {
console.log("Checkout working branch");
// git checkout all again
return git.checkout("main");
});