-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdeploy.js
More file actions
62 lines (51 loc) · 2.02 KB
/
deploy.js
File metadata and controls
62 lines (51 loc) · 2.02 KB
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
const path = require('path');
const fs = require('fs-extra');
const ghpages = require('gh-pages');
const exec = require('child_process').execSync;
const processTpl = require('./process-tpl');
const baseDir = 'packages/';
const distDir = '/dist/';
const siteDir = '_site/';
async function copyAndRebuild() {
try {
if (!fs.existsSync(siteDir)) {
fs.mkdirSync(siteDir);
} else {
await fs.emptyDir(siteDir);
}
const mainDist = `${baseDir}main${distDir}`;
const vueDist = `${baseDir}vue-maptalks${distDir}`;
const reactDist = `${baseDir}react-maptalks${distDir}`;
await fs.remove(vueDist);
await fs.remove(reactDist);
exec('yarn run build');
await fs.copy(vueDist, siteDir);
const vueData = fs.readFileSync(`${vueDist}index.html`, 'utf8');
await fs.copy(reactDist, siteDir);
const reactData = fs.readFileSync(`${reactDist}index.html`, 'utf8');
const /*{ template, scripts, styles }*/ vueTpl = processTpl(vueData, './');
const /*{ template, scripts, styles }*/ reactTpl = processTpl(reactData, './');
fs.writeFileSync(`${baseDir}main/tempString.js`, `// ! don't edit this file, this file will auto write by deploy.js
export const code_vue_html = \`${vueTpl.template}\`;
export const code_vue_scripts = \[${vueTpl.scripts.map(item => '\'' + item + '\'')}\];
export const code_vue_styles = \[${vueTpl.styles.map(item => '\'' + item + '\'')}\];
export const code_react_html = \`${reactTpl.template}\`;
export const code_react_scripts = \[${reactTpl.scripts.map(item => '\'' + item + '\'')}\];
export const code_react_styles = \[${reactTpl.styles.map(item => '\'' + item + '\'')}\];
`);
await fs.remove(mainDist);
exec('cd packages/main && yarn run rebuild');
await fs.copy(mainDist, siteDir);
} catch (e) {
console.error(e);
}
}
copyAndRebuild().then(res => {
ghpages.publish(path.join(__dirname, './_site'), function (err) {
if (err) {
console.log(err)
} else {
console.log('publish to github page done')
}
});
}).catch(e => console.log(e));