chore: check links

This commit is contained in:
Guillaume Chau
2018-06-10 17:06:22 +02:00
parent caf31a17d0
commit 503e308c43
3 changed files with 62 additions and 5 deletions

View File

@@ -9,6 +9,7 @@
"test": "node scripts/test.js",
"pretest": "yarn clean",
"lint": "eslint --fix packages/**/*.js packages/**/bin/*",
"check-links": "node scripts/checkLinks.js",
"clean": "rimraf packages/test/*",
"sync": "node scripts/syncDeps.js",
"boot": "node scripts/bootstrap.js",
@@ -17,7 +18,7 @@
"docs:build": "vuepress build docs"
},
"gitHooks": {
"pre-commit": "lint-staged",
"pre-commit": "lint-staged && yarn run check-links",
"commit-msg": "node scripts/verifyCommitMsg.js"
},
"jest": {
@@ -34,7 +35,7 @@
]
},
"lint-staged": {
"*.js": [
"*.{js,vue}": [
"eslint --fix",
"git add"
],

View File

@@ -77,7 +77,7 @@ module.exports = api => {
api.describeTask({
match: /vue-cli-service serve/,
description: 'vue-webpack.tasks.serve.description',
link: 'https://github.com/vuejs/vue-cli/blob/dev/docs/cli-service.md#serve',
link: 'https://cli.vuejs.org/guide/cli-service.html#vue-cli-service-serve',
icon: '/_plugin/%40vue%2Fcli-service/webpack-logo.png',
prompts: [
{
@@ -152,7 +152,7 @@ module.exports = api => {
api.describeTask({
match: /vue-cli-service build/,
description: 'vue-webpack.tasks.build.description',
link: 'https://github.com/vuejs/vue-cli/blob/dev/docs/cli-service.md#build',
link: 'https://cli.vuejs.org/guide/cli-service.html#vue-cli-service-build',
icon: '/_plugin/%40vue%2Fcli-service/webpack-logo.png',
prompts: [
{
@@ -243,7 +243,7 @@ module.exports = api => {
name: 'inspect',
command: 'vue-cli-service inspect',
description: 'vue-webpack.tasks.inspect.description',
link: 'https://github.com/vuejs/vue-cli/blob/dev/docs/webpack.md#inspecting-the-projects-webpack-config',
link: 'https://cli.vuejs.org/guide/webpack.html#inspecting-the-project-s-webpack-config',
icon: '/_plugin/%40vue%2Fcli-service/webpack-inspect-logo.png',
prompts: [
{

56
scripts/checkLinks.js Normal file
View File

@@ -0,0 +1,56 @@
const path = require('path')
const fs = require('fs')
const request = require('request-promise-native')
const root = path.resolve(__dirname, '../packages/@vue')
const promises = []
async function checkLink (file, link, n) {
try {
const result = await request({
method: 'HEAD',
uri: link,
resolveWithFullResponse: true
})
if (result.statusCode !== 200) {
throw new Error('error')
} else {
console.log('[OK]', link, result.statusCode)
}
} catch (e) {
console.warn('[!!]', link, `${file}:${parseInt(n) + 1}`)
throw e
}
}
function checkLinks (file) {
const contents = fs.readFileSync(file, { encoding: 'utf8' })
const lines = contents.split('\n')
for (const n in lines) {
const line = lines[n]
const matched = line.match(/link:\s+'(.+?)'/)
if (matched) {
const link = matched[1]
promises.push(checkLink(file, link, n))
}
}
}
function checkFiles (folder, recursive = false) {
const files = fs.readdirSync(folder)
for (const file of files) {
const fullPath = path.join(folder, file)
if (file === 'ui.js') {
checkLinks(fullPath)
} else if (file === 'ui' && fs.statSync(fullPath).isDirectory()) {
checkLinks(path.join(fullPath, 'index.js'))
} else if (recursive) {
checkFiles(fullPath)
}
}
}
checkFiles(root, true)
Promise.all(promises).catch(() => {
process.exit(1)
})