Skip to content

Commit

Permalink
sync sponsors
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Jun 2, 2022
1 parent b59dca5 commit 3b331f6
Show file tree
Hide file tree
Showing 9 changed files with 303 additions and 610 deletions.
61 changes: 61 additions & 0 deletions _scripts/pre-deploy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// udpate to latest built files of Vue
require('./sync-sponsors')

const fs = require('fs')
const zlib = require('zlib')
const axios = require('axios')
const execSync = require('child_process').execSync

const themeconfPath = 'themes/vue/_config.yml'
const installPath = 'src/v2/guide/installation.md'
const themeconfig = fs.readFileSync(themeconfPath, 'utf-8')
const installation = fs.readFileSync(installPath, 'utf-8')

// get latest Vue version
console.log(`Checking latest Vue version...`)
const localVersion = themeconfig.match(/vue_version: (.*)/)[1]
const version = execSync('npm view vue@v2-latest version').toString().trim()

if (localVersion === version) {
console.log(`Version is up-to-date.`)
process.exit(0)
}

console.log(`Latest version: ${version}. Downloading dist files...`)

// replace version in theme config
fs.writeFileSync(
themeconfPath,
themeconfig.replace(/vue_version: .*/, 'vue_version: ' + version)
)

// grab it from unpkg
Promise.all([download(`vue.js`), download(`vue.min.js`)])
.then(([devSize, prodSize]) => {
// replace installation page version and size
fs.writeFileSync(
installPath,
installation
.replace(/vue_version: .*/, 'vue_version: ' + version)
.replace(/gz_size:.*/g, `gz_size: "${prodSize}"`)
.replace(/\/vue@[\d\.]+/g, `/vue@${version}`)
)
console.log(
`\nSuccessfully updated Vue version (${version}) and gzip file size (${prodSize}kb).\n`
)
})
.catch((err) => {
console.error(err)
process.exit(1)
})

function download(file) {
return axios({
url: `http://unpkg.com/vue@${version}/dist/${file}`,
method: 'get'
}).then((res) => {
fs.writeFileSync(`themes/vue/source/js/${file}`, res.data)
const zipped = zlib.gzipSync(Buffer.from(res.data))
return (zipped.length / 1024).toFixed(2)
})
}
19 changes: 19 additions & 0 deletions _scripts/sync-sponsors.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// sync latest data from sponsor.vuejs.org
const fs = require('fs')
const path = require('path')
const axios = require('axios')
const yaml = require('yaml')

const configPath = path.resolve(__dirname, '../themes/vue/_config.yml')

;(async () => {
const { data } = await axios(`https://sponsors.vuejs.org/data.json`)
const yml = yaml.stringify(data)
const config = fs.readFileSync(configPath, 'utf-8')
const updated = config
.replace(/(# START SPONSORS)[^]*(# END SPONSORS)/, `$1\n${yml}$2`)
// jp specific logic
.replace(`https://code-dict.com`, `https://jp.code-dict.com`)

fs.writeFileSync(configPath, updated)
})()
9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"node": ">=8.9.0"
},
"dependencies": {
"axios": "^0.27.2",
"hexo": "^3.6.0",
"hexo-deployer-git": "0.3.1",
"hexo-generator-alias": "git+https://github.com/chrisvfritz/vuejs.org-hexo-generator-alias.git",
Expand All @@ -22,7 +23,7 @@
"hexo-renderer-stylus": "^0.3.3",
"hexo-server": "^0.3.1",
"hoek": "^6.1.2",
"request": "^2.85.0"
"yaml": "^2.1.1"
},
"devDependencies": {
"husky": "^2.4.0",
Expand All @@ -35,8 +36,8 @@
"textlint-rule-preset-jtf-style": "^2.3.3"
},
"scripts": {
"start": "hexo server",
"build": "node pre-deploy.js && hexo clean && hexo generate",
"dev": "node _scripts/sync-sponsors && hexo server",
"build": "node _scripts/pre-deploy.js && hexo clean && hexo generate",
"deploy": "npm run build && hexo deploy",
"test": "npm run lint",
"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)};\""
Expand All @@ -49,4 +50,4 @@
"lint-staged": {
"*.md": "textlint --rulesdir ./node_modules/textlint-checker-for-vuejs-jp-docs/rules/textlint-rule-vue-jp-docs -f pretty-error"
}
}
}
74 changes: 0 additions & 74 deletions pre-deploy.js

This file was deleted.

Loading

0 comments on commit 3b331f6

Please sign in to comment.