-
Notifications
You must be signed in to change notification settings - Fork 0
/
prepare-build.js
53 lines (49 loc) · 1.94 KB
/
prepare-build.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
const { readdirSync, lstatSync, unlinkSync, readFileSync, writeFileSync } = require('fs');
const { exec, execSync } = require('child_process');
exec('yarn build', {}, async (err, stout) => {
console.log(stout);
exec('git checkout -B gh-pages', {}, (err, branch_stdout) => {
if (err) {
console.log(err);
return;
}
console.log(branch_stdout);
const files = readdirSync('./');
files.forEach(each => {
if (each !== 'build' && each !== 'prepare-build.js' && each.indexOf('.git') !== 0 && each !== 'node_modules') {
if (lstatSync(each).isDirectory()) {
console.log('Removing directory ['+ each + ']')
execSync(`rm -rf ${each}`);
} else {
console.log('Removing file ['+each +']')
unlinkSync(each)
}
}
});
readdirSync('./build').forEach(each => {
console.log(`Coping file [build/${each}] to [${each}]`)
// if (!lstatSync(each).isDirectory()) copyFileSync('./build/' +each, each);
execSync(`cp -R ./build/${each} ${each}`)
});
const indexHtml = readFileSync('index.html', { encoding: 'utf8' })
.replace(/href="\//g, 'href="')
.replace(/src="\//g, 'src="');
writeFileSync('index.html', indexHtml);
exec('git add .', {}, (err, commit_stdout) => {
if (err) {
console.log(err);
return;
}
console.log(commit_stdout);
execSync('git commit -m "prepared build and release"');
execSync('git push origin gh-pages -f');
exec('git checkout master', {}, (err, checkout_stdout) => {
if (err) {
console.log(err);
return;
}
console.log(checkout_stdout);
});
});
});
});