Skip to content

Commit e15b203

Browse files
committed
Chore: update build script
1 parent de2a67c commit e15b203

File tree

3 files changed

+86
-70
lines changed

3 files changed

+86
-70
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ branches:
55
- master
66

77
language: node_js
8-
node_js: "8"
8+
node_js: "10"
99

1010
script:
1111
- git config --local user.name "Travis CI" && npm run deploy

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@
2727
"eslint-plugin-vue": "^5.0.0-beta.3",
2828
"eslint4b": "^5.7.0",
2929
"file-loader": "^2.0.0",
30+
"fs-extra": "^7.0.0",
3031
"material-design-icons": "^3.0.1",
3132
"npm-run-all": "^4.1.2",
3233
"pako": "^1.0.6",
3334
"postcss-loader": "^3.0.0",
3435
"postcss-preset-env": "^6.1.2",
3536
"rimraf": "^2.6.2",
36-
"shelljs": "^0.8.2",
3737
"string-replace-loader": "^1.3.0",
3838
"url-loader": "^1.1.2",
3939
"vue": "^2.5.9",

scripts/deploy.js

Lines changed: 84 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,87 +1,103 @@
11
"use strict"
22

3-
//------------------------------------------------------------------------------
4-
// Requirements
5-
//------------------------------------------------------------------------------
6-
7-
const sh = require("shelljs")
3+
const { spawn } = require("child_process")
4+
const path = require("path")
5+
const fs = require("fs-extra")
86
const version = require("../package.json").version
97
const ATOKEN = process.env.ATOKEN
10-
11-
//------------------------------------------------------------------------------
12-
// Helpers
13-
//------------------------------------------------------------------------------
14-
15-
/**
16-
* Execute `cp` command.
17-
* @returns {void}
18-
*/
19-
function cp(...args) {
20-
sh.echo(`> cp ${args.join(" ")}`)
21-
sh.cp(...args)
22-
}
23-
24-
/**
25-
* Execute `rm` command.
26-
* @returns {void}
27-
*/
28-
function rm(...args) {
29-
sh.echo(`> rm ${args.join(" ")}`)
30-
sh.rm(...args)
31-
}
8+
const BUILD_ROOT = path.resolve(__dirname, "../dist")
9+
const DEPLOY_ROOT = path.resolve(__dirname, "..")
3210

3311
/**
3412
* Execute a command.
3513
* @param {string} command The command to execute.
3614
* @returns {void}
3715
*/
3816
function exec(command) {
39-
sh.echo(`> ${command}`)
40-
const code = sh.exec(command, { stdio: "inherit" }).code
41-
if (code) {
42-
throw new Error(`Exited with ${code}.`)
43-
}
17+
console.log(`> ${command}`)
18+
return new Promise((resolve, reject) => {
19+
const cp = spawn(command, [], { shell: true, stdio: "inherit" })
20+
21+
cp.on("close", code => {
22+
if (code) {
23+
reject(new Error(`Exited with ${code}.`))
24+
} else {
25+
resolve()
26+
}
27+
})
28+
})
4429
}
4530

46-
//------------------------------------------------------------------------------
4731
// Main
48-
//------------------------------------------------------------------------------
32+
;(async () => {
33+
console.log("BUILD")
34+
await exec(`git checkout v${version}`)
35+
await exec("npm run -s build")
36+
37+
console.log("LOAD GH-PAGES")
38+
if (ATOKEN) {
39+
await exec(
40+
"git fetch --depth=1 https://github.com/mysticatea/vue-eslint-demo.git gh-pages:gh-pages",
41+
)
42+
await exec("git checkout gh-pages")
43+
} else {
44+
await exec("git checkout gh-pages")
45+
await exec("git pull")
46+
}
4947

50-
// Build.
51-
exec(`git checkout v${version}`)
52-
exec("npm run build")
48+
console.log("CHECK VERSIONS")
49+
const oldVersions = await fs.readFile("versions.json", "utf8")
50+
const newVersions = await fs.readFile("dist/versions.json", "utf8")
51+
console.log(`OLD: ${oldVersions}`)
52+
console.log(`NEW: ${newVersions}`)
5353

54-
// Load gh-pages.
55-
if (ATOKEN) {
56-
exec(
57-
"git fetch --depth=1 https://github.com/mysticatea/vue-eslint-demo.git gh-pages:gh-pages",
58-
)
59-
exec("git checkout gh-pages")
60-
} else {
61-
exec("git checkout gh-pages")
62-
exec("git pull")
63-
}
54+
// Deploy.
55+
if (newVersions !== oldVersions) {
56+
console.log("CLEAN")
57+
for (const filename of await fs.readdir(DEPLOY_ROOT)) {
58+
const stat = await fs.stat(filename)
59+
if (!stat.isFile() || filename.startsWith(".")) {
60+
continue
61+
}
6462

65-
// Check versions.
66-
const oldVersions = String(sh.cat("versions.json"))
67-
const newVersions = String(sh.cat("dist/versions.json"))
68-
sh.echo(`OLD: ${oldVersions}`)
69-
sh.echo(`NEW: ${newVersions}`)
63+
console.log(`> rm ${filename}`)
64+
await fs.unlink(filename)
65+
}
7066

71-
// Deploy.
72-
if (newVersions !== oldVersions) {
73-
rm("-rf", "vs", "index.*")
74-
cp("-r", "dist/*", ".")
75-
exec("git add -A")
76-
exec('git commit -m "Update: website"')
77-
exec(
78-
`git push${
79-
ATOKEN
80-
? ` https://mysticatea:${ATOKEN}@github.com/mysticatea/vue-eslint-demo.git gh-pages:gh-pages`
81-
: ""
82-
}`,
83-
)
84-
}
67+
console.log("DEPLOY")
68+
for (const filename of await fs.readdir(BUILD_ROOT)) {
69+
console.log(`> mv dist/${filename} ${filename}`)
70+
await fs.rename(
71+
path.join(BUILD_ROOT, filename),
72+
path.join(DEPLOY_ROOT, filename),
73+
)
74+
}
75+
76+
await exec("git add -A")
77+
let updated = false
78+
try {
79+
await exec('git commit -m "Update: website"')
80+
updated = true
81+
} catch (_error) {
82+
console.log("NO UPDATE")
83+
}
84+
if (updated) {
85+
await exec(
86+
`git push${
87+
ATOKEN
88+
? ` https://mysticatea:${ATOKEN}@github.com/mysticatea/vue-eslint-demo.git gh-pages:gh-pages`
89+
: ""
90+
}`,
91+
)
92+
}
93+
} else {
94+
console.log("NO UPDATE")
95+
}
8596

86-
// Back to master.
87-
exec("git checkout master")
97+
// Back to master.
98+
await exec("git checkout master")
99+
console.log("COMPLETE")
100+
})().catch(error => {
101+
console.error(error.stack)
102+
process.exitCode = 1
103+
})

0 commit comments

Comments
 (0)