From 717d7f7a093f504a744cedac169451c7b0567411 Mon Sep 17 00:00:00 2001 From: "142vip.cn" Date: Mon, 30 Oct 2023 17:53:30 +0800 Subject: [PATCH] =?UTF-8?q?perf(scripts):=20=E4=BF=AE=E6=94=B9lint?= =?UTF-8?q?=E8=84=9A=E6=9C=AC=EF=BC=8C=E4=BC=98=E5=8C=96markdown=E6=96=87?= =?UTF-8?q?=E6=A1=A3=E6=A0=BC=E5=BC=8F=E5=8C=96=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .dockerignore | 5 +- .github/workflows/CI.yml | 2 +- .gitignore | 80 +++++++------------------- .markdownlint.js | 6 +- .markdownignore => .markdownlintignore | 3 + package.json | 2 +- scripts/ci | 1 - scripts/lint | 37 ++++++------ 8 files changed, 53 insertions(+), 83 deletions(-) rename .markdownignore => .markdownlintignore (65%) diff --git a/.dockerignore b/.dockerignore index b512c09d..696ef35a 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1 +1,4 @@ -node_modules \ No newline at end of file +node_modules +.idea +.github +.husky \ No newline at end of file diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index beba41ee..f77f1657 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -65,7 +65,7 @@ jobs: - name: Code LintFix run: | - ./scripts/lint --fix + ./scripts/lint - name: Build Site run: | diff --git a/.gitignore b/.gitignore index abd21d59..e5544272 100644 --- a/.gitignore +++ b/.gitignore @@ -1,75 +1,39 @@ +# Logs logs *.log -npm-debug.log* -yarn-debug.log* -yarn-error.log* +.vscode +.vscode/* +*/.DS_Store +.DS_Store +*/.vscode .idea - -# Runtime data -pids -*.pid -*.seed -*.pid.lock - -# docs -lib-cov - # Coverage directory used by tools like istanbul coverage - +*.lcov # nyc test coverage .nyc_output - -# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) -.grunt - -# Bower dependency directory (https://bower.io/) -bower_components - -# node-waf configuration -.lock-wscript - -# Compiled binary addons (http://nodejs.org/api/addons.html) -build/Release - # Dependency directories node_modules/ jspm_packages/ - -# Typescript v1 declaration files +# TypeScript v1 declaration files typings/ - # Optional npm cache directory .npm - -# Optional eslint cache -.eslintcache - -# Optional REPL history -.node_repl_history - # Output of 'npm pack' *.tgz - -# Yarn Integrity file -.yarn-integrity - -# dotenv environment variables file -.git -.vscode -.env -.DS_Store +# parcel-bundler cache (https://parceljs.org/) +.cache +# Next.js build output +.next +.nuxt dist -lib -es -_site -yarn.lock -package-lock.json -/coverage - -# useless files -templete -/docs/.vuepress/.temp/ -/docs/.vuepress/.cache/ +# Gatsby files +.cache/ +# vuepress build output +# .vuepress/dist +docs/.vuepress/.cache/ +docs/.vuepress/.temp/ +docs/.vuepress/dist/ +# TernJS port file +.tern-port /.husky/ -.vercel diff --git a/.markdownlint.js b/.markdownlint.js index f3599b97..2717fd96 100644 --- a/.markdownlint.js +++ b/.markdownlint.js @@ -1,3 +1,4 @@ +// 参考: module.exports = { "default": true, "MD001": false, @@ -11,6 +12,9 @@ module.exports = { "MD024": { "allow_different_nesting": true }, + "MD025": { + "front_matter_title": "" + }, "MD033": { "allowed_elements": [ "br", @@ -65,4 +69,4 @@ module.exports = { "MD042": false, "MD046": false, "MD049": false -} \ No newline at end of file +} diff --git a/.markdownignore b/.markdownlintignore similarity index 65% rename from .markdownignore rename to .markdownlintignore index a472ff0f..fbf21643 100644 --- a/.markdownignore +++ b/.markdownlintignore @@ -1,3 +1,6 @@ **/node_modules/** CHANGELOG.md LICENSE +.idea +.husky +.github diff --git a/package.json b/package.json index eaf186f7..7c7bff9e 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,7 @@ "scripts": { "preinstall": "chmod +x ./scripts/*", "postinstall": "npm run build:mark-map", - "prepare": "rm -f .husky/pre-commit && husky install && npx husky add .husky/pre-commit \"./scripts/lint --fix\" && chmod +x .husky/pre-commit", + "prepare": "rm -f .husky/pre-commit && husky install && npx husky add .husky/pre-commit \"./scripts/lint\" && chmod +x .husky/pre-commit", "dev": "vuepress dev docs", "build": "./scripts/bundle build", "build:proxy": "./scripts/bundle build_proxy", diff --git a/scripts/ci b/scripts/ci index 31913355..c27e18ae 100755 --- a/scripts/ci +++ b/scripts/ci @@ -37,4 +37,3 @@ fi # 安装项目依赖 pnpm i --frozen-lockfile --registry https://registry.npmmirror.com - diff --git a/scripts/lint b/scripts/lint index 275cd2ed..6112ba5e 100755 --- a/scripts/lint +++ b/scripts/lint @@ -1,25 +1,22 @@ -#!/usr/bin/env node +#!/bin/bash -/** - * - * 格式化代码 - * 例如: - * - ./scripts/lint - * - ./scripts/lint --fix - */ +## +## 自动格式化 +## - 代码 +## - markdown文档 +## 使用: + # - ./scripts/lint +## 参考链接: +## - https://eslint.org/docs/latest/use/getting-started +## - https://github.com/igorshubovych/markdownlint-cli +## -const {execShell} = require('./.exec') -const scriptName = process.argv[2] -const fixed = scriptName != null ? '--fix' : ''; +# 设置 PATH 环境变量,避免command not found问题 +export PATH="$(pnpm bin):$PATH" -// 格式化代码 -const lintCode = `eslint ${fixed} --ext .js,.ts,.vue --ignore-path .gitignore .`; +# ESLint格式化代码 +eslint --fix --ext .js,.ts,.vue --ignore-path .gitignore . -// 遍历格式化docs目录下的markdown 文档 -const lintMd = 'find docs -type f -name \"*.md\" -print0 | xargs -0 -I {} markdownlint -c .markdownlint.js --fix {}'; +# markdown-cli格式化markdown 文档 +markdownlint '**/*.md' -c .markdownlint.js -p .markdownlintignore --fix -// 可以在--fix后指定目录 -(async () => await execShell([ - lintCode, - lintMd -]))()