Skip to content

Commit 3b331f6

Browse files
committed
sync sponsors
1 parent b59dca5 commit 3b331f6

File tree

9 files changed

+303
-610
lines changed

9 files changed

+303
-610
lines changed

_scripts/pre-deploy.js

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
// udpate to latest built files of Vue
2+
require('./sync-sponsors')
3+
4+
const fs = require('fs')
5+
const zlib = require('zlib')
6+
const axios = require('axios')
7+
const execSync = require('child_process').execSync
8+
9+
const themeconfPath = 'themes/vue/_config.yml'
10+
const installPath = 'src/v2/guide/installation.md'
11+
const themeconfig = fs.readFileSync(themeconfPath, 'utf-8')
12+
const installation = fs.readFileSync(installPath, 'utf-8')
13+
14+
// get latest Vue version
15+
console.log(`Checking latest Vue version...`)
16+
const localVersion = themeconfig.match(/vue_version: (.*)/)[1]
17+
const version = execSync('npm view vue@v2-latest version').toString().trim()
18+
19+
if (localVersion === version) {
20+
console.log(`Version is up-to-date.`)
21+
process.exit(0)
22+
}
23+
24+
console.log(`Latest version: ${version}. Downloading dist files...`)
25+
26+
// replace version in theme config
27+
fs.writeFileSync(
28+
themeconfPath,
29+
themeconfig.replace(/vue_version: .*/, 'vue_version: ' + version)
30+
)
31+
32+
// grab it from unpkg
33+
Promise.all([download(`vue.js`), download(`vue.min.js`)])
34+
.then(([devSize, prodSize]) => {
35+
// replace installation page version and size
36+
fs.writeFileSync(
37+
installPath,
38+
installation
39+
.replace(/vue_version: .*/, 'vue_version: ' + version)
40+
.replace(/gz_size:.*/g, `gz_size: "${prodSize}"`)
41+
.replace(/\/vue@[\d\.]+/g, `/vue@${version}`)
42+
)
43+
console.log(
44+
`\nSuccessfully updated Vue version (${version}) and gzip file size (${prodSize}kb).\n`
45+
)
46+
})
47+
.catch((err) => {
48+
console.error(err)
49+
process.exit(1)
50+
})
51+
52+
function download(file) {
53+
return axios({
54+
url: `http://unpkg.com/vue@${version}/dist/${file}`,
55+
method: 'get'
56+
}).then((res) => {
57+
fs.writeFileSync(`themes/vue/source/js/${file}`, res.data)
58+
const zipped = zlib.gzipSync(Buffer.from(res.data))
59+
return (zipped.length / 1024).toFixed(2)
60+
})
61+
}

_scripts/sync-sponsors.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// sync latest data from sponsor.vuejs.org
2+
const fs = require('fs')
3+
const path = require('path')
4+
const axios = require('axios')
5+
const yaml = require('yaml')
6+
7+
const configPath = path.resolve(__dirname, '../themes/vue/_config.yml')
8+
9+
;(async () => {
10+
const { data } = await axios(`https://sponsors.vuejs.org/data.json`)
11+
const yml = yaml.stringify(data)
12+
const config = fs.readFileSync(configPath, 'utf-8')
13+
const updated = config
14+
.replace(/(# START SPONSORS)[^]*(# END SPONSORS)/, `$1\n${yml}$2`)
15+
// jp specific logic
16+
.replace(`https://code-dict.com`, `https://jp.code-dict.com`)
17+
18+
fs.writeFileSync(configPath, updated)
19+
})()

package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"node": ">=8.9.0"
99
},
1010
"dependencies": {
11+
"axios": "^0.27.2",
1112
"hexo": "^3.6.0",
1213
"hexo-deployer-git": "0.3.1",
1314
"hexo-generator-alias": "git+https://github.com/chrisvfritz/vuejs.org-hexo-generator-alias.git",
@@ -22,7 +23,7 @@
2223
"hexo-renderer-stylus": "^0.3.3",
2324
"hexo-server": "^0.3.1",
2425
"hoek": "^6.1.2",
25-
"request": "^2.85.0"
26+
"yaml": "^2.1.1"
2627
},
2728
"devDependencies": {
2829
"husky": "^2.4.0",
@@ -35,8 +36,8 @@
3536
"textlint-rule-preset-jtf-style": "^2.3.3"
3637
},
3738
"scripts": {
38-
"start": "hexo server",
39-
"build": "node pre-deploy.js && hexo clean && hexo generate",
39+
"dev": "node _scripts/sync-sponsors && hexo server",
40+
"build": "node _scripts/pre-deploy.js && hexo clean && hexo generate",
4041
"deploy": "npm run build && hexo deploy",
4142
"test": "npm run lint",
4243
"lint": "node -e \"var shell=require('shelljs');var files=shell.find(['./src/v2/**/*.md','./src/_posts/*.md']).filter(function(file){return !file.endsWith('/guide/team.md')}).join(' ');if(shell.exec('textlint --rulesdir ./node_modules/textlint-checker-for-vuejs-jp-docs/rules/textlint-rule-vue-jp-docs -f pretty-error '+files).code!==0){shell.exit(1)};\""
@@ -49,4 +50,4 @@
4950
"lint-staged": {
5051
"*.md": "textlint --rulesdir ./node_modules/textlint-checker-for-vuejs-jp-docs/rules/textlint-rule-vue-jp-docs -f pretty-error"
5152
}
52-
}
53+
}

pre-deploy.js

Lines changed: 0 additions & 74 deletions
This file was deleted.

0 commit comments

Comments
 (0)