mirror of
https://github.com/vuejs/vue-cli.git
synced 2026-03-11 19:51:52 -05:00
chore: check links
This commit is contained in:
@@ -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"
|
||||
],
|
||||
|
||||
@@ -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
56
scripts/checkLinks.js
Normal 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)
|
||||
})
|
||||
Reference in New Issue
Block a user