├── play ├── src │ ├── components │ │ ├── name.vue │ │ └── HelloWorld.vue │ ├── assets │ │ └── logo.png │ ├── main.js │ └── App.vue ├── README.md ├── public │ ├── favicon.ico │ └── index.html ├── .eslintignore ├── .husky │ ├── pre-commit │ └── commit-msg ├── babel.config.js ├── .prettierrc ├── .gitignore ├── package.json ├── commitlint.config.js ├── commitlint.config copy.js └── .eslintrc.js ├── index.ts ├── .eslintignore ├── src ├── static │ ├── eslint.png │ ├── loading.png │ ├── Jun-20-2022-1.gif │ └── Jun-20-2022-2.gif ├── utils │ ├── path.ts │ ├── check.ts │ ├── debug.ts │ ├── env.ts │ └── tool.ts ├── templet │ ├── prettierrc.ts │ ├── commitlint-no-emoji.config.ts │ ├── commitlint.config.ts │ └── eslintrc.ts ├── core │ ├── eslintignore.ts │ ├── special.ts │ ├── husky.ts │ ├── commitlint.ts │ ├── vscode.ts │ └── eslint.ts ├── especial.ts ├── cli.ts └── start.ts ├── .husky ├── pre-commit └── commit-msg ├── .prettierrc ├── .gitignore ├── .github └── workflows │ └── nodejs.yml ├── .cz-config.js ├── .history ├── README_20221113004239.md ├── README_20230208145450.md ├── README_20230208145459.md ├── README_20230208145501.md ├── README_20230208145543.md └── README_20230208145548.md ├── README.md ├── package.json ├── commitlint.config.js ├── tsconfig.json ├── .eslintrc.js └── .eslintcache /play/src/components/name.vue: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /play/README.md: -------------------------------------------------------------------------------- 1 | ## 测试使用的项目 2 | -------------------------------------------------------------------------------- /index.ts: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | import cliInit from './src/cli'; 3 | cliInit(); 4 | -------------------------------------------------------------------------------- /.eslintignore: -------------------------------------------------------------------------------- 1 | 2 | .prettierrc 3 | !commitlint.config.js 4 | .babel.config.js 5 | !.umirc.ts 6 | -------------------------------------------------------------------------------- /play/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lyh0371/web-norm/HEAD/play/public/favicon.ico -------------------------------------------------------------------------------- /src/static/eslint.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lyh0371/web-norm/HEAD/src/static/eslint.png -------------------------------------------------------------------------------- /src/static/loading.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lyh0371/web-norm/HEAD/src/static/loading.png -------------------------------------------------------------------------------- /.husky/pre-commit: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | . "$(dirname -- "$0")/_/husky.sh" 3 | npm run pre-commit 4 | -------------------------------------------------------------------------------- /play/.eslintignore: -------------------------------------------------------------------------------- 1 | 2 | .eslintrc.js 3 | .prettierrc 4 | commitlint.config.js 5 | .babel.config.js 6 | -------------------------------------------------------------------------------- /play/src/assets/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lyh0371/web-norm/HEAD/play/src/assets/logo.png -------------------------------------------------------------------------------- /src/static/Jun-20-2022-1.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lyh0371/web-norm/HEAD/src/static/Jun-20-2022-1.gif -------------------------------------------------------------------------------- /src/static/Jun-20-2022-2.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lyh0371/web-norm/HEAD/src/static/Jun-20-2022-2.gif -------------------------------------------------------------------------------- /play/.husky/pre-commit: -------------------------------------------------------------------------------- 1 | 2 | #!/usr/bin/env sh 3 | . "$(dirname -- "$0")/_/husky.sh" 4 | npm run pre-commit 5 | -------------------------------------------------------------------------------- /play/babel.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | presets: [ 3 | '@vue/cli-plugin-babel/preset' 4 | ] 5 | } 6 | -------------------------------------------------------------------------------- /.husky/commit-msg: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | . "$(dirname -- "$0")/_/husky.sh" 3 | 4 | npx --no-install commitlint --edit $1 5 | -------------------------------------------------------------------------------- /play/.husky/commit-msg: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | . "$(dirname -- "$0")/_/husky.sh" 3 | 4 | npx --no-install commitlint --edit $1 5 | -------------------------------------------------------------------------------- /.prettierrc: -------------------------------------------------------------------------------- 1 | 2 | { 3 | "semi": false, 4 | "singleQuote": true, 5 | "printWidth": 180, 6 | "tabWidth": 2, 7 | "trailingComma": "none" 8 | } 9 | 10 | -------------------------------------------------------------------------------- /play/.prettierrc: -------------------------------------------------------------------------------- 1 | 2 | { 3 | "semi": false, 4 | "singleQuote": true, 5 | "printWidth": 180, 6 | "tabWidth": 2, 7 | "trailingComma": "none" 8 | } 9 | 10 | -------------------------------------------------------------------------------- /play/src/main.js: -------------------------------------------------------------------------------- 1 | import Vue from 'vue' 2 | import App from './App.vue' 3 | 4 | Vue.config.productionTip = false 5 | 6 | new Vue({ 7 | render: h => h(App), 8 | }).$mount('#app') 9 | -------------------------------------------------------------------------------- /src/utils/path.ts: -------------------------------------------------------------------------------- 1 | import { getEnv } from './env' 2 | import path from 'path' 3 | export const getpath = (name: string) => { 4 | const basePath = getEnv('base') as string 5 | return path.resolve(basePath, name) 6 | } 7 | -------------------------------------------------------------------------------- /src/templet/prettierrc.ts: -------------------------------------------------------------------------------- 1 | export const prettierrcInit = ` 2 | { 3 | "semi": false, 4 | "singleQuote": true, 5 | "printWidth": 100, 6 | "tabWidth": 2, 7 | "trailingComma": "none" 8 | } 9 | 10 | ` 11 | -------------------------------------------------------------------------------- /play/.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | node_modules 3 | /dist 4 | 5 | 6 | # local env files 7 | .env.local 8 | .env.*.local 9 | 10 | # Log files 11 | npm-debug.log* 12 | yarn-debug.log* 13 | yarn-error.log* 14 | pnpm-debug.log* 15 | 16 | # Editor directories and files 17 | .idea 18 | .vscode 19 | *.suo 20 | *.ntvs* 21 | *.njsproj 22 | *.sln 23 | *.sw? 24 | -------------------------------------------------------------------------------- /src/core/eslintignore.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * husk 结合 commitlint 提交信息校验 3 | */ 4 | import fs from 'fs-extra'; 5 | import { getpath } from '../utils/path'; 6 | 7 | const eslintignore = ` 8 | .prettierrc 9 | !commitlint.config.js 10 | .babel.config.js 11 | !.umirc.ts 12 | `; 13 | export const eslintignoreInit = async () => { 14 | fs.outputFileSync(getpath('.eslintignore'), eslintignore); 15 | }; 16 | -------------------------------------------------------------------------------- /src/especial.ts: -------------------------------------------------------------------------------- 1 | export const teepEslintConfig = { 2 | rules: { 3 | 'no-console': ['error', { allow: ['warn', 'error'] }], 4 | 'no-nested-ternary': ['error'], 5 | 'max-lines': [ 6 | 'error', 7 | { 8 | max: 1500, 9 | skipBlankLines: true, 10 | skipComments: true 11 | } 12 | ], 13 | complexity: ['error', 15], 14 | eqeqeq: 2 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .progress-estimator 2 | # Logs 3 | logs 4 | *.log 5 | npm-debug.log* 6 | yarn-debug.log* 7 | yarn-error.log* 8 | 9 | node_modules 10 | play/node_modules/ 11 | .DS_Store 12 | dist 13 | dist-ssr 14 | coverage 15 | *.local 16 | 17 | /cypress/videos/ 18 | /cypress/screenshots/ 19 | 20 | # Editor directories and files 21 | .vscode/* 22 | !.vscode/extensions.json 23 | .idea 24 | *.suo 25 | *.ntvs* 26 | *.njsproj 27 | *.sln 28 | *.sw? 29 | -------------------------------------------------------------------------------- /src/core/special.ts: -------------------------------------------------------------------------------- 1 | // 一些特殊的处理 2 | import fs from 'fs-extra'; 3 | import { env, getPackageJson } from '../utils/env'; 4 | import { getpath } from '../utils/path'; 5 | export const specialFn = async () => { 6 | const { isVue3 } = env; 7 | if (!isVue3) return; 8 | let pkgJson = await getPackageJson(); 9 | if (pkgJson.type) { 10 | delete pkgJson.type; 11 | } 12 | fs.writeJsonSync(getpath('package.json'), pkgJson, { spaces: 2 }); 13 | // 如果是vue3 的话 需要把package中的 type="module"去掉 14 | }; 15 | -------------------------------------------------------------------------------- /play/src/App.vue: -------------------------------------------------------------------------------- 1 | 7 | 8 | 18 | 19 | 29 | -------------------------------------------------------------------------------- /.github/workflows/nodejs.yml: -------------------------------------------------------------------------------- 1 | name: 发布npm 2 | on: 3 | push: 4 | branches: [ release ] 5 | jobs: 6 | build: 7 | runs-on: ubuntu-latest 8 | steps: 9 | - name: Checkout 10 | uses: actions/checkout@v3 11 | - name: setupNode 12 | uses: actions/setup-node@v3 13 | with: 14 | node-version: '16.x' 15 | registry-url: 'https://registry.npmjs.org' 16 | - name: 依赖安装 17 | run: npm install 18 | - name: 构建 19 | run: npm run build 20 | - run: cd ./dist && npm publish 21 | 22 | env: 23 | NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} 24 | GITHUB_TOKEN: ${{ secrets.ACCESS_TOKEN }} 25 | -------------------------------------------------------------------------------- /play/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | <%= htmlWebpackPlugin.options.title %> 9 | 10 | 11 | 14 |
15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /.cz-config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | types: [ 3 | { value: '✨feat', name: '✨feat: 增加新功能' }, 4 | { value: '🐛fix', name: '🐛fix: 修复bug' }, 5 | { value: '📝docs', name: '📝docs: 修改文档' }, 6 | { value: '🚀perf', name: '🚀perf: 性能优化' }, 7 | { value: '📦build', name: '📦build: 打包' }, 8 | { value: '👷ci', name: '👷ci: CI部署' }, 9 | { value: '🔂revert', name: '🔂revert: 版本回退' }, 10 | { value: '💎 style', name: '💎style: 样式修改不影响逻辑' }, 11 | { value: '🚨test', name: '🚨test: 增删测试' }, 12 | ], 13 | messages: { 14 | type: '请选择提交的类型;', 15 | customScope: '请输入修改的范围(可选)', 16 | subject: '请简要描述提交(必填)', 17 | body: '请输入详细描述(可选)', 18 | footer: '请选择要关闭的issue(可选)', 19 | confirmCommit: '确认要使用以上信息提交?(y/n)', 20 | }, 21 | skip: ['body', 'footer'], 22 | subjectLimit: 72, 23 | }; 24 | -------------------------------------------------------------------------------- /src/utils/check.ts: -------------------------------------------------------------------------------- 1 | // 各种检测函数 2 | import fs from 'fs-extra' 3 | import { debugError } from './debug' 4 | import { getEnv } from './env' 5 | /** 6 | * @name 判断文件夹存不存在 7 | */ 8 | export const pathExists = async (name: string, ext: boolean = true): Promise => { 9 | const base = getEnv('base') as string 10 | const res = await fs.pathExists(`${base}/${name}`) 11 | if (!res) { 12 | ext && debugError(`${base}/${name}不存在`) 13 | return false 14 | } else { 15 | return res 16 | } 17 | } 18 | 19 | /** 20 | * @name 判断是哪个vue版本 21 | */ 22 | export const checkVueVersion = (version: string) => { 23 | const v = version.split('.')[0] as string 24 | return Number(v.match(/\d+/g)) 25 | } 26 | 27 | /** 28 | * @name 判断使用的是npm和yarn 29 | */ 30 | export const checkNpmOrYarn = async (_basePath?: string): Promise => { 31 | // 如果原项目使用的是yarn进行安装的,那还是使用npm进行按照,否则就使用npm 32 | if (await pathExists('yarn.lock', false)) { 33 | return ['yarn', 'add'] 34 | } 35 | return ['npm', 'init'] 36 | } 37 | -------------------------------------------------------------------------------- /src/utils/debug.ts: -------------------------------------------------------------------------------- 1 | import chalk from 'chalk' 2 | const log = console.log 3 | let debugSwitch = true 4 | 5 | /** 6 | * debug开关,默认开启 7 | * @param debug boolean 8 | */ 9 | const switchDebug = (debug: boolean) => { 10 | debugSwitch = debug 11 | } 12 | 13 | /** 14 | * debug 错误信息 15 | * @param type 类型 16 | * @param msg 信息 17 | */ 18 | const debugError = (msg: string) => { 19 | debugSwitch && log(chalk.hex('#646cff')(`[web-norm]:`) + chalk.red(msg)) 20 | // 如果出错就退出 21 | process.exit(0) 22 | } 23 | 24 | /** 25 | * debug 信息 26 | * @param type 类型 27 | * @param msg 信息 28 | */ 29 | const debugInfo = (msg: string) => { 30 | debugSwitch && log(chalk.hex('#646cff')(`[web-norm]:`) + chalk.green(msg)) 31 | } 32 | 33 | /** 34 | * debug 强调 35 | * @param type 类型 36 | * @param msg 信息 37 | */ 38 | 39 | const debugprocess = (msg: string) => { 40 | debugSwitch && log(chalk.hex('#646cff')(`[web-norm]:`) + chalk.yellow(msg)) 41 | } 42 | /** 43 | * debug warning信息 44 | * @param type 类型 45 | * @param msg 信息 46 | */ 47 | const debugWarning = (msg: string) => { 48 | log(chalk.hex('#646cff')(`[web-norm]:`) + chalk.yellow(msg)) 49 | } 50 | 51 | const debugTxt = (msg: string) => { 52 | log(chalk.hex('#646cff')(`[web-norm]:`) + chalk.hex('#5c6d82')(msg)) 53 | } 54 | 55 | export { switchDebug, debugInfo, debugError, debugWarning, debugprocess, debugTxt } 56 | -------------------------------------------------------------------------------- /src/cli.ts: -------------------------------------------------------------------------------- 1 | // 解析命令行参数以及获取脚本运行的路径 2 | import cac from 'cac' 3 | import { start } from './start' 4 | import { prompt } from 'enquirer' 5 | 6 | const cli = cac('web-norm') 7 | import { existsSync, setEnv } from './utils/env' 8 | const cliInit = () => { 9 | cli 10 | .command('[root]') 11 | .alias('alias') 12 | .option('-n, --en', 'lang') 13 | .option('-s,--simple', 'simple') 14 | .option('-n,--noEmoji', 'noEmoji') 15 | .option('-n,--especial', 'especial') 16 | .action(async (_root, options) => { 17 | let base: string = options.base 18 | const { en, simple, noEmoji, especial } = options 19 | 20 | en && setEnv('isZh', true) 21 | simple && setEnv('simple', true) 22 | noEmoji && setEnv('noEmoji', true) 23 | setEnv('especial', especial) 24 | if (existsSync('.eslintrc.js')) { 25 | const response: any = await prompt([ 26 | { 27 | type: 'select', // 交互类型 -- 单选(无序) 28 | message: '是否覆盖已有eslint配置', // 引导词 29 | name: 'especial', // 自定义的字段名 30 | choices: ['是', '否(合并配置)'] // 选项列表 31 | } 32 | ]) 33 | setEnv('merge', response.especial != '是') 34 | } 35 | if (!base) { 36 | // 项目的最终路径 37 | base = process.cwd() 38 | } 39 | setEnv('base', base) 40 | 41 | await start(base) 42 | }) 43 | 44 | cli.help() 45 | cli.version('1.0.0') 46 | cli.parse() 47 | } 48 | 49 | export default cliInit 50 | -------------------------------------------------------------------------------- /src/start.ts: -------------------------------------------------------------------------------- 1 | // 开始分析项目 2 | import { getPackageJson, initProjectInfo } from './utils/env' 3 | import { debugError, debugInfo, debugprocess, debugTxt } from './utils/debug' 4 | import { eslintInit } from './core/eslint' 5 | import { huskyInit } from './core/husky' 6 | import { eslintignoreInit } from './core/eslintignore' 7 | import { commitLintInit } from './core/commitlint' 8 | import { vscodeInit } from './core/vscode' 9 | import { specialFn } from './core/special' 10 | export const start = async (base: string) => { 11 | const pckJson = await getPackageJson(base) 12 | 13 | await initProjectInfo(pckJson) 14 | // TODO: 分析package.json 1.查看项目类型 15 | // if (!getEnv('isVue')) { 16 | // debugError('暂不支持除Vue之外的其他版本'); 17 | // } 18 | try { 19 | // TODO: 安装eslint 和 preitter 并自动生成配置文件 20 | await eslintInit() 21 | // TODO: 安装 hucky 并自动生成配置文件 22 | await huskyInit() 23 | // TODO: 生成.vscode 配置文件 支持自动格式化代码 24 | await commitLintInit() 25 | // TODO: 添加eslint忽略文件 26 | await eslintignoreInit() 27 | // await downNodeModules(); 28 | await specialFn() 29 | await vscodeInit() 30 | debugInfo('success!') 31 | debugprocess('请重新安装依赖!npm install or yarn or ...') 32 | debugTxt(` 33 | 34 | 😎 请确保您吃饭的家伙是vscode 35 | 😘 推荐安装vscode插件 eslint、prettier-eslint、prettier(这不是广告) 36 | 😫 一脸懵逼?请前往 https://github.com/lyh0371/web-norm 37 | `) 38 | // debugTxt(``); 39 | } catch (error) { 40 | debugError(JSON.stringify(error)) 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/core/husky.ts: -------------------------------------------------------------------------------- 1 | import { writeInPkg, run } from '../utils/tool' 2 | import fs from 'fs-extra' 3 | import { getPackageJson } from '../utils/env' 4 | import { getpath } from '../utils/path' 5 | import { debugInfo, debugWarning } from '../utils/debug' 6 | import { pathExists } from '../utils/check' 7 | // 需要安装的依赖 8 | const devDependencies = ['husky@^8.0.1', 'lint-staged@^12.4.1'] 9 | 10 | export const huskyInit = async () => { 11 | // 检查是否有git 如果没有 需要先初始化git 12 | if (!pathExists('.git', false)) { 13 | debugWarning(`请先初始化git`) 14 | debugInfo('参考命令 git init') 15 | process.exit() 16 | } 17 | // 安装依赖 18 | await writeInPkg(devDependencies) 19 | // 更改package 20 | const pkgJson = await getPackageJson() 21 | pkgJson.scripts['prepare'] = 'husky install' 22 | pkgJson.scripts['pre-commit'] = 'lint-staged' 23 | pkgJson.scripts['postinstallmac'] = 'git config core.hooksPath .husky && chmod 700 .husky/*' 24 | pkgJson.scripts['prettierwrite'] = 'prettier --write src/**/*.{vue,ts,js,tsx,jsx}' 25 | pkgJson.scripts['prettiercheck'] = 'prettier --check src/**/*.{vue,ts,js,tsx,jsx}' 26 | pkgJson.scripts['eslint'] = 'eslint --cache --max-warnings 0 "{src,mock}/**/*.{vue,ts,js,tsx}" --fix' 27 | pkgJson['lint-staged'] = { 28 | '*.{js,ts,vue,jsx,tsx}': ['eslint --cache --fix'], 29 | '*.{js,jsx,ts,tsx,md,html,css,lees,scss,sass}': 'prettier --write' 30 | } 31 | fs.writeJsonSync(getpath('package.json'), pkgJson, { spaces: 2 }) 32 | 33 | await run('npm run prepare') 34 | await run('npx husky add .husky/pre-commit "npm-run-pre-commit"') 35 | } 36 | -------------------------------------------------------------------------------- /play/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "play", 3 | "version": "0.1.0", 4 | "private": true, 5 | "scripts": { 6 | "dev": "vue-cli-service serve", 7 | "build": "vue-cli-service build", 8 | "lint": "vue-cli-service lint", 9 | "web": "npm link web-norm && web-norm", 10 | "prepare": "husky install", 11 | "pre-commit": "lint-staged", 12 | "commit": "git add . && git-cz" 13 | }, 14 | "dependencies": { 15 | "core-js": "^3.6.5", 16 | "husky": "^8.0.1", 17 | "lint-staged": "^13.0.1", 18 | "vue": "^2.6.11" 19 | }, 20 | "devDependencies": { 21 | "@commitlint/cli": "^17.0.2", 22 | "@commitlint/config-angular": "^17.0.0", 23 | "@commitlint/cz-commitlint": "^17.0.0", 24 | "@vue/cli-plugin-babel": "~4.5.13", 25 | "@vue/cli-plugin-eslint": "~4.5.13", 26 | "@vue/cli-service": "~4.5.13", 27 | "babel-eslint": "^10.1.0", 28 | "cac": "^6.7.12", 29 | "commitizen": "^4.2.4", 30 | "cz-customizable": "^6.3.0", 31 | "eslint": "^8.17.0", 32 | "eslint-friendly-formatter": "^4.0.1", 33 | "eslint-plugin-html": "^6.2.0", 34 | "eslint-plugin-prettier": "^4.0.0", 35 | "eslint-plugin-vue": "^9.1.1", 36 | "prettier": "^2.6.2", 37 | "vue-template-compiler": "^2.6.11" 38 | }, 39 | "browserslist": [ 40 | "> 1%", 41 | "last 2 versions", 42 | "not dead" 43 | ], 44 | "lint-staged": { 45 | "*.{js,ts,vue,jsx,tsx}": [ 46 | "eslint --ext .js,.jsx,.ts,.tsx,.vue" 47 | ], 48 | "*.{js,jsx,ts,tsx,md,html,css,lees,scss,sass}": "prettier --write" 49 | }, 50 | "config": { 51 | "commitizen": { 52 | "path": "@commitlint/cz-commitlint" 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/core/commitlint.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * husk 结合 commitlint 提交信息校验 3 | */ 4 | import { getPackageJson,getEnv } from '../utils/env'; 5 | import { writeInPkg, run } from '../utils/tool'; 6 | import fs from 'fs-extra'; 7 | import { commitLintConfig } from '../templet/commitlint.config'; 8 | import {commitLintConfigNoEmoji} from '../templet/commitlint-no-emoji.config'; 9 | import { getpath } from '../utils/path'; 10 | 11 | const devDependencies = [ 12 | '@commitlint/cli@^17.0.3', 13 | '@commitlint/config-angular@^17.0.3', 14 | 'commitizen@^4.2.4', 15 | 'cz-customizable@^6.9.0', 16 | '@commitlint/cz-commitlint@^17.0.3', 17 | 'inquirer@^8.0.0', 18 | ]; 19 | 20 | const commitMsg = `#!/usr/bin/env sh 21 | . "$(dirname -- "$0")/_/husky.sh" 22 | 23 | npx --no-install commitlint --edit $1 24 | `; 25 | 26 | const preCommit = `#!/usr/bin/env sh 27 | . "$(dirname -- "$0")/_/husky.sh" 28 | npm run pre-commit 29 | `; 30 | 31 | const commitlintPath = getpath('commitlint.config.js'); 32 | 33 | export const commitLintInit = async () => { 34 | await writeInPkg(devDependencies); 35 | await run('npx husky add .husky/commit-msg "npm-run-test"'); 36 | let pkgJson = await getPackageJson(); 37 | pkgJson['config'] = { 38 | commitizen: { 39 | path: '@commitlint/cz-commitlint', 40 | }, 41 | }; 42 | pkgJson.scripts['commit'] = 'git add . && git-cz'; 43 | fs.writeJsonSync(getpath('package.json'), pkgJson, { spaces: 2 }); 44 | 45 | if (await fs.pathExists(commitlintPath)) { 46 | // 删除 47 | fs.removeSync(commitlintPath); 48 | } 49 | const _commitLintConfig = getEnv('noEmoji')?commitLintConfigNoEmoji:commitLintConfig 50 | fs.outputFileSync(commitlintPath, _commitLintConfig); 51 | fs.outputFileSync(getpath('./.husky/commit-msg'), commitMsg); 52 | fs.outputFileSync(getpath('./.husky/pre-commit'), preCommit); 53 | }; 54 | -------------------------------------------------------------------------------- /play/src/components/HelloWorld.vue: -------------------------------------------------------------------------------- 1 | 32 | 33 | 41 | 42 | 43 | 59 | -------------------------------------------------------------------------------- /.history/README_20221113004239.md: -------------------------------------------------------------------------------- 1 |
2 |

web-norm

3 |

4 | GitHub stars 5 | GitHub forks 6 |

7 | 8 | ## 初衷 9 | 10 | 每当接手一个新项目(如果项目中没有配置 eslint husky commitlint)等这些规范的话,就需要自己手动配置一遍,配置多了后我只能来句窝草!😬 11 | 12 | ## 目标 13 | 14 | 一个命令自动化配置项目规范 15 | 16 | ## 你将得到 17 | 18 | - 保存代码自动格式化💯 19 | - 提交前 commit 校验💯 20 | - eslint + pretter 校验💯 21 | - husky 自动装载💯 22 | - 说吧,你还想要啥... 23 | 24 | ## 安装 25 | 26 | 1 局部安装(推荐使用) 27 | 28 | ```sh 29 | npm install web-norm -D | yarn add web-norm -D | pnpm install web-norm -D 30 | ``` 31 | 32 | 在 package.json 中 33 | 34 | ```sh 35 | "scripts": { 36 | "web-norm": "web-norm", 37 | }, 38 | ``` 39 | 40 | 2. 全局安装 41 | 42 | ```sh 43 | npm install web-norm -g | yarn add web-norm -g | pnpm install web-norm -g 44 | ``` 45 | 46 | ## 使用 47 | 48 | 运行命令 49 | 50 | ```tip 51 | 请确保您的项目使用了git,否则会导致`husky`不生效 52 | ``` 53 | 54 | ```sh 55 | npm run web-norm 56 | ``` 57 | 58 | 59 | 60 | 61 | ## 支持配置 62 | 63 | `web-norm` 默认在提交记录上为带表情符号 📦👷📝🌟🐛🚀🌠🔂💎🚨 。如果不喜欢这些表情符号的话可以在用 `web-norm` 初始化项目的时候加上 `--noEmoji` 去掉 64 | 65 | ```sh 66 | "scripts": { 67 | "web-norm": "web-norm --noEmoji", 68 | }, 69 | ``` 70 | 71 | 72 | ## 验证 73 | 74 | 代码提交前校验 75 | 76 | ```sh 77 | npm run commit 78 | ``` 79 | 80 | 81 | 82 | ## 在老项目中使用 83 | 84 | 在老项目使用会牵扯到一个问题就是以前的代码规范和通过`web-norm`生成的代码规范不一致怎么办? 85 | 86 | 1、如果项目比较小,只有几个文件,你可以把所以的文件都保存一遍即可(保存的时候 vscode 会自动格式化代码,确保使用 vscode 编辑器并安装 eslint 和 pretter 插件) 87 | 88 | 89 | 90 | 2、如果项目比较大,建议使用 vscode 插件`Format Files`进行自动化保存 91 | 92 | 93 | 94 | ## 可能遇到问题,详细内容参考这篇文章[可能遇到问题](https://juejin.cn/post/7124196350446534670#heading-4) 95 | 96 | - husky 无法触发 97 | 98 | 1. 项目首先需要被 `git` 管理 99 | 100 | 2. mac 电脑执行 `npm run postinstallmac` 来设置 husky 的读写权限 101 | 102 | 103 | ## 说明 104 | 105 | 1. `web-norm` 只支持 vue(包括 vue3)及 react 项目 106 | 107 | 2. 在使用过程中遇到任何问题,请提交 issues 😚 108 | -------------------------------------------------------------------------------- /src/utils/env.ts: -------------------------------------------------------------------------------- 1 | import path from 'path' 2 | import fs from 'fs-extra' 3 | import { checkVueVersion } from './check' 4 | export const env = { 5 | base: '', 6 | isVue: false, 7 | isVue3: false, 8 | isReact: false, 9 | isVue2: false, 10 | isVueCli: false, 11 | isWebpack: true, 12 | isEslint: false, 13 | especial: false, 14 | merge: false, // 是否覆盖原有eslint 默认覆盖 15 | isZh: true, // 中英文 16 | simple: false, // 是否是简单模式 默认是否 17 | noEmoji: false // 是否不要表情 默认是要 18 | } 19 | 20 | type envKeys = keyof typeof env 21 | 22 | /** 23 | * @name 设置变量 24 | */ 25 | export const setEnv = (key: envKeys, val: any) => { 26 | env[key] = val as never 27 | } 28 | /** 29 | * @name 获取变量 30 | */ 31 | export const getEnv = (key: envKeys) => { 32 | return env[key] 33 | } 34 | 35 | /** 36 | * @name 检测是否包含指定文件 37 | * 38 | */ 39 | 40 | export const existsSync = (fileName: string, base: string = getEnv('base') as string) => { 41 | const file = path.resolve(base, fileName) 42 | return fs.existsSync(file) 43 | } 44 | 45 | /** 46 | * @name 获取指定文件,并转化为json 47 | * 48 | */ 49 | 50 | export const getFiletoJson = async (fileName: string, base: string = getEnv('base') as string) => { 51 | const file = path.resolve(base, fileName) 52 | const res = fs.existsSync(file) 53 | if (!res) return false 54 | const json = fs.readJSON(file) 55 | return json 56 | } 57 | /** 58 | * @name 把package.json转化为json 59 | */ 60 | export const getPackageJson = async (base: string = getEnv('base') as string) => { 61 | return getFiletoJson('package.json', base) 62 | } 63 | 64 | /** 65 | * @name 获取eslintrc 66 | */ 67 | export const getEslintrc = async (base: string = getEnv('base') as string) => { 68 | const file = path.resolve(base, '.eslintrc.js') 69 | const res = fs.existsSync(file) 70 | if (!res) return false 71 | const eslintStr = await fs.readFile(file, 'utf8') 72 | return eval(eslintStr) 73 | } 74 | 75 | export const initProjectInfo = async (pckJson: any) => { 76 | const deps = { ...pckJson.devDependencies, ...pckJson.dependencies } 77 | if (deps['vue']) { 78 | setEnv('isVue', true) 79 | if (checkVueVersion(deps['vue']) === 2) { 80 | setEnv('isVue2', true) 81 | } 82 | if (checkVueVersion(deps['vue']) === 3) { 83 | setEnv('isVue3', true) 84 | } 85 | } 86 | 87 | if (deps['react']) { 88 | setEnv('isReact', true) 89 | } 90 | 91 | if (deps['eslint']) { 92 | setEnv('isEslint', true) 93 | } 94 | return true 95 | } 96 | -------------------------------------------------------------------------------- /src/core/vscode.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * vscode 配置 3 | */ 4 | import fs from 'fs-extra'; 5 | import { getpath } from '../utils/path'; 6 | 7 | export const vscodeInit = async () => { 8 | const haveVscodeSetting = await fs.pathExists(getpath('./vscode/settings.json')); 9 | 10 | let vscodeSetting = {}; 11 | if (!haveVscodeSetting) { 12 | vscodeSetting = { 13 | // 每次保存自动格式化 14 | 'editor.formatOnSave': true, 15 | // 每次保存的时候将代码按eslint格式进行修复 16 | 'editor.codeActionsOnSave': { 17 | 'source.fixAll.eslint': true, 18 | }, 19 | 'editor.defaultFormatter': 'esbenp.prettier-vscode', 20 | // vue文件默认格式化方式vetur 21 | '[vue]': { 22 | // "editor.defaultFormatter": "octref.vetur" 23 | 'editor.defaultFormatter': 'esbenp.prettier-vscode', 24 | }, 25 | 26 | 'javascript.format.insertSpaceBeforeFunctionParenthesis': true, // 函数前加上空格 只有在默认vetur的时候生效 27 | // js文件默认格式化方式 和vue中的js保持一致使用编辑器自带的ts格式 28 | '[javascript]': { 29 | // "editor.defaultFormatter": "vscode.typescript-language-features" 30 | // javascript文件默认格式化方式prettier 31 | 'editor.defaultFormatter': 'esbenp.prettier-vscode', 32 | }, 33 | // json文件默认格式化方式prettier 34 | '[json]': { 35 | 'editor.defaultFormatter': 'esbenp.prettier-vscode', 36 | }, 37 | // css文件默认格式化方式prettier 38 | '[css]': { 39 | 'editor.defaultFormatter': 'esbenp.prettier-vscode', 40 | }, 41 | // typescript文件默认格式化方式prettier 42 | '[typescript]': { 43 | 'editor.defaultFormatter': 'esbenp.prettier-vscode', 44 | }, 45 | 46 | // 控制折行方式 - "on" (根据视区宽度折行) 47 | 'editor.wordWrap': 'on', 48 | 'editor.tabSize': 2, // 换行默认以tab缩进 2个字符 49 | 'editor.snippetSuggestions': 'top', // 将建议的代码段优先级提前选择,比如输入for第一个提示是for循环代码段。 50 | 'files.associations': { 51 | // 文件关联语言的优先级配置 52 | '*.js': 'javascriptreact', 53 | '*.vue': 'vue', 54 | '*.cshtml': 'html', 55 | '*.dwt': 'html', 56 | }, 57 | // "eslint.validate": ["javascript", "javascriptreact", "typescript", "typescriptreact"], 58 | 59 | 'editor.formatOnPaste': true, 60 | }; 61 | } else { 62 | // const nowSetting = await getPackageJson('./vscode/settings.json'); 63 | const nowSetting = fs.readJSON(getpath('./vscode/settings.json')); 64 | vscodeSetting = { ...nowSetting, ...vscodeSetting }; 65 | } 66 | fs.outputFileSync(getpath('./.vscode/settings.json'), JSON.stringify(vscodeSetting, null, 2)); 67 | }; 68 | -------------------------------------------------------------------------------- /.history/README_20230208145450.md: -------------------------------------------------------------------------------- 1 |
2 |

web-norm

3 |

4 | GitHub stars 5 | GitHub forks 6 |

7 | 8 | ## 新坑推广 9 | 10 | [vv-react-table(虚拟列表解决方案)](https://github.com/lyh0371/vv-react-table) 11 | 12 | ## 初衷 13 | 14 | 每当接手一个新项目(如果项目中没有配置 eslint husky commitlint)等这些规范的话,就需要自己手动配置一遍,配置多了后我只能来句窝草!😬 15 | 16 | ## 目标 17 | 18 | 一个命令自动化配置项目规范 19 | 20 | ## 你将得到 21 | 22 | - 保存代码自动格式化💯 23 | - 提交前 commit 校验💯 24 | - eslint + pretter 校验💯 25 | - husky 自动装载💯 26 | - 说吧,你还想要啥... 27 | 28 | ## 安装 29 | 30 | 1 局部安装(推荐使用) 31 | 32 | ```sh 33 | npm install web-norm -D | yarn add web-norm -D | pnpm install web-norm -D 34 | ``` 35 | 36 | 在 package.json 中 37 | 38 | ```sh 39 | "scripts": { 40 | "web-norm": "web-norm", 41 | }, 42 | ``` 43 | 44 | 2. 全局安装 45 | 46 | ```sh 47 | npm install web-norm -g | yarn add web-norm -g | pnpm install web-norm -g 48 | ``` 49 | 50 | ## 使用 51 | 52 | 运行命令 53 | 54 | ```tip 55 | 请确保您的项目使用了git,否则会导致`husky`不生效 56 | ``` 57 | 58 | ```sh 59 | npm run web-norm 60 | ``` 61 | 62 | 63 | 64 | 65 | ## 支持配置 66 | 67 | `web-norm` 默认在提交记录上为带表情符号 📦👷📝🌟🐛🚀🌠🔂💎🚨 。如果不喜欢这些表情符号的话可以在用 `web-norm` 初始化项目的时候加上 `--noEmoji` 去掉 68 | 69 | ```sh 70 | "scripts": { 71 | "web-norm": "web-norm --noEmoji", 72 | }, 73 | ``` 74 | 75 | 76 | ## 验证 77 | 78 | 代码提交前校验 79 | 80 | ```sh 81 | npm run commit 82 | ``` 83 | 84 | 85 | 86 | ## 在老项目中使用 87 | 88 | 在老项目使用会牵扯到一个问题就是以前的代码规范和通过`web-norm`生成的代码规范不一致怎么办? 89 | 90 | 1、如果项目比较小,只有几个文件,你可以把所以的文件都保存一遍即可(保存的时候 vscode 会自动格式化代码,确保使用 vscode 编辑器并安装 eslint 和 pretter 插件) 91 | 92 | 93 | 94 | 2、如果项目比较大,建议使用 vscode 插件`Format Files`进行自动化保存 95 | 96 | 97 | 98 | ## 可能遇到问题,详细内容参考这篇文章[可能遇到问题](https://juejin.cn/post/7124196350446534670#heading-4) 99 | 100 | - husky 无法触发 101 | 102 | 1. 项目首先需要被 `git` 管理 103 | 104 | 2. mac 电脑执行 `npm run postinstallmac` 来设置 husky 的读写权限 105 | 106 | 107 | ## 说明 108 | 109 | 1. `web-norm` 只支持 vue(包括 vue3)及 react 项目 110 | 111 | 2. 在使用过程中遇到任何问题,请提交 issues 😚 112 | -------------------------------------------------------------------------------- /.history/README_20230208145459.md: -------------------------------------------------------------------------------- 1 |
2 |

web-norm

3 |

4 | GitHub stars 5 | GitHub forks 6 |

7 | 8 | ## 新坑推广 9 | 10 | [vv-react-table(虚拟列表解决方案)](https://github.com/lyh0371/vv-react-table) 欢迎使用 11 | 12 | ## 初衷 13 | 14 | 每当接手一个新项目(如果项目中没有配置 eslint husky commitlint)等这些规范的话,就需要自己手动配置一遍,配置多了后我只能来句窝草!😬 15 | 16 | ## 目标 17 | 18 | 一个命令自动化配置项目规范 19 | 20 | ## 你将得到 21 | 22 | - 保存代码自动格式化💯 23 | - 提交前 commit 校验💯 24 | - eslint + pretter 校验💯 25 | - husky 自动装载💯 26 | - 说吧,你还想要啥... 27 | 28 | ## 安装 29 | 30 | 1 局部安装(推荐使用) 31 | 32 | ```sh 33 | npm install web-norm -D | yarn add web-norm -D | pnpm install web-norm -D 34 | ``` 35 | 36 | 在 package.json 中 37 | 38 | ```sh 39 | "scripts": { 40 | "web-norm": "web-norm", 41 | }, 42 | ``` 43 | 44 | 2. 全局安装 45 | 46 | ```sh 47 | npm install web-norm -g | yarn add web-norm -g | pnpm install web-norm -g 48 | ``` 49 | 50 | ## 使用 51 | 52 | 运行命令 53 | 54 | ```tip 55 | 请确保您的项目使用了git,否则会导致`husky`不生效 56 | ``` 57 | 58 | ```sh 59 | npm run web-norm 60 | ``` 61 | 62 | 63 | 64 | 65 | ## 支持配置 66 | 67 | `web-norm` 默认在提交记录上为带表情符号 📦👷📝🌟🐛🚀🌠🔂💎🚨 。如果不喜欢这些表情符号的话可以在用 `web-norm` 初始化项目的时候加上 `--noEmoji` 去掉 68 | 69 | ```sh 70 | "scripts": { 71 | "web-norm": "web-norm --noEmoji", 72 | }, 73 | ``` 74 | 75 | 76 | ## 验证 77 | 78 | 代码提交前校验 79 | 80 | ```sh 81 | npm run commit 82 | ``` 83 | 84 | 85 | 86 | ## 在老项目中使用 87 | 88 | 在老项目使用会牵扯到一个问题就是以前的代码规范和通过`web-norm`生成的代码规范不一致怎么办? 89 | 90 | 1、如果项目比较小,只有几个文件,你可以把所以的文件都保存一遍即可(保存的时候 vscode 会自动格式化代码,确保使用 vscode 编辑器并安装 eslint 和 pretter 插件) 91 | 92 | 93 | 94 | 2、如果项目比较大,建议使用 vscode 插件`Format Files`进行自动化保存 95 | 96 | 97 | 98 | ## 可能遇到问题,详细内容参考这篇文章[可能遇到问题](https://juejin.cn/post/7124196350446534670#heading-4) 99 | 100 | - husky 无法触发 101 | 102 | 1. 项目首先需要被 `git` 管理 103 | 104 | 2. mac 电脑执行 `npm run postinstallmac` 来设置 husky 的读写权限 105 | 106 | 107 | ## 说明 108 | 109 | 1. `web-norm` 只支持 vue(包括 vue3)及 react 项目 110 | 111 | 2. 在使用过程中遇到任何问题,请提交 issues 😚 112 | -------------------------------------------------------------------------------- /.history/README_20230208145501.md: -------------------------------------------------------------------------------- 1 |
2 |

web-norm

3 |

4 | GitHub stars 5 | GitHub forks 6 |

7 | 8 | ## 新坑推广 9 | 10 | [vv-react-table(虚拟列表解决方案)](https://github.com/lyh0371/vv-react-table) 欢迎使用 11 | 12 | ## 初衷 13 | 14 | 每当接手一个新项目(如果项目中没有配置 eslint husky commitlint)等这些规范的话,就需要自己手动配置一遍,配置多了后我只能来句窝草!😬 15 | 16 | ## 目标 17 | 18 | 一个命令自动化配置项目规范 19 | 20 | ## 你将得到 21 | 22 | - 保存代码自动格式化💯 23 | - 提交前 commit 校验💯 24 | - eslint + pretter 校验💯 25 | - husky 自动装载💯 26 | - 说吧,你还想要啥... 27 | 28 | ## 安装 29 | 30 | 1 局部安装(推荐使用) 31 | 32 | ```sh 33 | npm install web-norm -D | yarn add web-norm -D | pnpm install web-norm -D 34 | ``` 35 | 36 | 在 package.json 中 37 | 38 | ```sh 39 | "scripts": { 40 | "web-norm": "web-norm", 41 | }, 42 | ``` 43 | 44 | 2. 全局安装 45 | 46 | ```sh 47 | npm install web-norm -g | yarn add web-norm -g | pnpm install web-norm -g 48 | ``` 49 | 50 | ## 使用 51 | 52 | 运行命令 53 | 54 | ```tip 55 | 请确保您的项目使用了git,否则会导致`husky`不生效 56 | ``` 57 | 58 | ```sh 59 | npm run web-norm 60 | ``` 61 | 62 | 63 | 64 | 65 | ## 支持配置 66 | 67 | `web-norm` 默认在提交记录上为带表情符号 📦👷📝🌟🐛🚀🌠🔂💎🚨 。如果不喜欢这些表情符号的话可以在用 `web-norm` 初始化项目的时候加上 `--noEmoji` 去掉 68 | 69 | ```sh 70 | "scripts": { 71 | "web-norm": "web-norm --noEmoji", 72 | }, 73 | ``` 74 | 75 | 76 | ## 验证 77 | 78 | 代码提交前校验 79 | 80 | ```sh 81 | npm run commit 82 | ``` 83 | 84 | 85 | 86 | ## 在老项目中使用 87 | 88 | 在老项目使用会牵扯到一个问题就是以前的代码规范和通过`web-norm`生成的代码规范不一致怎么办? 89 | 90 | 1、如果项目比较小,只有几个文件,你可以把所以的文件都保存一遍即可(保存的时候 vscode 会自动格式化代码,确保使用 vscode 编辑器并安装 eslint 和 pretter 插件) 91 | 92 | 93 | 94 | 2、如果项目比较大,建议使用 vscode 插件`Format Files`进行自动化保存 95 | 96 | 97 | 98 | ## 可能遇到问题,详细内容参考这篇文章[可能遇到问题](https://juejin.cn/post/7124196350446534670#heading-4) 99 | 100 | - husky 无法触发 101 | 102 | 1. 项目首先需要被 `git` 管理 103 | 104 | 2. mac 电脑执行 `npm run postinstallmac` 来设置 husky 的读写权限 105 | 106 | 107 | ## 说明 108 | 109 | 1. `web-norm` 只支持 vue(包括 vue3)及 react 项目 110 | 111 | 2. 在使用过程中遇到任何问题,请提交 issues 😚 112 | -------------------------------------------------------------------------------- /.history/README_20230208145543.md: -------------------------------------------------------------------------------- 1 |
2 |

web-norm

3 |

4 | GitHub stars 5 | GitHub forks 6 |

7 | 8 | ## 新坑推广🔥🔥 9 | 10 | [vv-react-table(虚拟列表解决方案)](https://github.com/lyh0371/vv-react-table) 欢迎使用 11 | 12 | ## 初衷 13 | 14 | 每当接手一个新项目(如果项目中没有配置 eslint husky commitlint)等这些规范的话,就需要自己手动配置一遍,配置多了后我只能来句窝草!😬 15 | 16 | ## 目标 17 | 18 | 一个命令自动化配置项目规范 19 | 20 | ## 你将得到 21 | 22 | - 保存代码自动格式化💯 23 | - 提交前 commit 校验💯 24 | - eslint + pretter 校验💯 25 | - husky 自动装载💯 26 | - 说吧,你还想要啥... 27 | 28 | ## 安装 29 | 30 | 1 局部安装(推荐使用) 31 | 32 | ```sh 33 | npm install web-norm -D | yarn add web-norm -D | pnpm install web-norm -D 34 | ``` 35 | 36 | 在 package.json 中 37 | 38 | ```sh 39 | "scripts": { 40 | "web-norm": "web-norm", 41 | }, 42 | ``` 43 | 44 | 2. 全局安装 45 | 46 | ```sh 47 | npm install web-norm -g | yarn add web-norm -g | pnpm install web-norm -g 48 | ``` 49 | 50 | ## 使用 51 | 52 | 运行命令 53 | 54 | ```tip 55 | 请确保您的项目使用了git,否则会导致`husky`不生效 56 | ``` 57 | 58 | ```sh 59 | npm run web-norm 60 | ``` 61 | 62 | 63 | 64 | 65 | ## 支持配置 66 | 67 | `web-norm` 默认在提交记录上为带表情符号 📦👷📝🌟🐛🚀🌠🔂💎🚨 。如果不喜欢这些表情符号的话可以在用 `web-norm` 初始化项目的时候加上 `--noEmoji` 去掉 68 | 69 | ```sh 70 | "scripts": { 71 | "web-norm": "web-norm --noEmoji", 72 | }, 73 | ``` 74 | 75 | 76 | ## 验证 77 | 78 | 代码提交前校验 79 | 80 | ```sh 81 | npm run commit 82 | ``` 83 | 84 | 85 | 86 | ## 在老项目中使用 87 | 88 | 在老项目使用会牵扯到一个问题就是以前的代码规范和通过`web-norm`生成的代码规范不一致怎么办? 89 | 90 | 1、如果项目比较小,只有几个文件,你可以把所以的文件都保存一遍即可(保存的时候 vscode 会自动格式化代码,确保使用 vscode 编辑器并安装 eslint 和 pretter 插件) 91 | 92 | 93 | 94 | 2、如果项目比较大,建议使用 vscode 插件`Format Files`进行自动化保存 95 | 96 | 97 | 98 | ## 可能遇到问题,详细内容参考这篇文章[可能遇到问题](https://juejin.cn/post/7124196350446534670#heading-4) 99 | 100 | - husky 无法触发 101 | 102 | 1. 项目首先需要被 `git` 管理 103 | 104 | 2. mac 电脑执行 `npm run postinstallmac` 来设置 husky 的读写权限 105 | 106 | 107 | ## 说明 108 | 109 | 1. `web-norm` 只支持 vue(包括 vue3)及 react 项目 110 | 111 | 2. 在使用过程中遇到任何问题,请提交 issues 😚 112 | -------------------------------------------------------------------------------- /.history/README_20230208145548.md: -------------------------------------------------------------------------------- 1 |
2 |

web-norm

3 |

4 | GitHub stars 5 | GitHub forks 6 |

7 | 8 | ## 新坑推广🔥🔥 9 | 10 | [vv-react-table(虚拟列表解决方案)](https://github.com/lyh0371/vv-react-table) 欢迎使用😚 11 | 12 | ## 初衷 13 | 14 | 每当接手一个新项目(如果项目中没有配置 eslint husky commitlint)等这些规范的话,就需要自己手动配置一遍,配置多了后我只能来句窝草!😬 15 | 16 | ## 目标 17 | 18 | 一个命令自动化配置项目规范 19 | 20 | ## 你将得到 21 | 22 | - 保存代码自动格式化💯 23 | - 提交前 commit 校验💯 24 | - eslint + pretter 校验💯 25 | - husky 自动装载💯 26 | - 说吧,你还想要啥... 27 | 28 | ## 安装 29 | 30 | 1 局部安装(推荐使用) 31 | 32 | ```sh 33 | npm install web-norm -D | yarn add web-norm -D | pnpm install web-norm -D 34 | ``` 35 | 36 | 在 package.json 中 37 | 38 | ```sh 39 | "scripts": { 40 | "web-norm": "web-norm", 41 | }, 42 | ``` 43 | 44 | 2. 全局安装 45 | 46 | ```sh 47 | npm install web-norm -g | yarn add web-norm -g | pnpm install web-norm -g 48 | ``` 49 | 50 | ## 使用 51 | 52 | 运行命令 53 | 54 | ```tip 55 | 请确保您的项目使用了git,否则会导致`husky`不生效 56 | ``` 57 | 58 | ```sh 59 | npm run web-norm 60 | ``` 61 | 62 | 63 | 64 | 65 | ## 支持配置 66 | 67 | `web-norm` 默认在提交记录上为带表情符号 📦👷📝🌟🐛🚀🌠🔂💎🚨 。如果不喜欢这些表情符号的话可以在用 `web-norm` 初始化项目的时候加上 `--noEmoji` 去掉 68 | 69 | ```sh 70 | "scripts": { 71 | "web-norm": "web-norm --noEmoji", 72 | }, 73 | ``` 74 | 75 | 76 | ## 验证 77 | 78 | 代码提交前校验 79 | 80 | ```sh 81 | npm run commit 82 | ``` 83 | 84 | 85 | 86 | ## 在老项目中使用 87 | 88 | 在老项目使用会牵扯到一个问题就是以前的代码规范和通过`web-norm`生成的代码规范不一致怎么办? 89 | 90 | 1、如果项目比较小,只有几个文件,你可以把所以的文件都保存一遍即可(保存的时候 vscode 会自动格式化代码,确保使用 vscode 编辑器并安装 eslint 和 pretter 插件) 91 | 92 | 93 | 94 | 2、如果项目比较大,建议使用 vscode 插件`Format Files`进行自动化保存 95 | 96 | 97 | 98 | ## 可能遇到问题,详细内容参考这篇文章[可能遇到问题](https://juejin.cn/post/7124196350446534670#heading-4) 99 | 100 | - husky 无法触发 101 | 102 | 1. 项目首先需要被 `git` 管理 103 | 104 | 2. mac 电脑执行 `npm run postinstallmac` 来设置 husky 的读写权限 105 | 106 | 107 | ## 说明 108 | 109 | 1. `web-norm` 只支持 vue(包括 vue3)及 react 项目 110 | 111 | 2. 在使用过程中遇到任何问题,请提交 issues 😚 112 | -------------------------------------------------------------------------------- /src/utils/tool.ts: -------------------------------------------------------------------------------- 1 | import spawn from 'cross-spawn'; 2 | import fs from 'fs-extra'; 3 | 4 | import { getEnv, getPackageJson } from './env'; 5 | import { checkNpmOrYarn } from './check'; 6 | import { getpath } from './path'; 7 | 8 | import { debugInfo, debugWarning } from './debug'; 9 | export const down = async (runName: string | string[], type: string) => { 10 | const basePath = getEnv('base') as string; 11 | const [n, i] = await checkNpmOrYarn(basePath); 12 | if (typeof runName === 'string') { 13 | await spawnSync(n, i, runName, type, basePath); 14 | return false; 15 | } 16 | runName.forEach(async (runItem) => { 17 | await spawnSync(n, i, runItem, type, basePath); 18 | }); 19 | }; 20 | 21 | export const spawnSync = (n: string, i: string, runItem: string, type: string, basePath: string) => { 22 | return new Promise((resolve) => { 23 | spawn.sync(n, [i, runItem, type], { 24 | stdio: 'pipe', 25 | cwd: basePath, 26 | }); 27 | debugInfo(`${runItem}✅`); 28 | 29 | resolve({ success: true }); 30 | }); 31 | }; 32 | 33 | /** 34 | * @name 写入依赖 35 | */ 36 | 37 | /** 38 | * @name 睡眠函数 39 | * @param numberMillis -- 要睡眠的毫秒数 40 | */ 41 | export const sleep = (numberMillis: number) => { 42 | var now = new Date(); 43 | var exitTime = now.getTime() + numberMillis; 44 | while (true) { 45 | now = new Date(); 46 | if (now.getTime() > exitTime) return; 47 | } 48 | }; 49 | 50 | export const writeInPkg = async (devArr: string[], key: string = 'devDependencies') => { 51 | let pkg = await getPackageJson(); 52 | devArr.forEach((item: string) => { 53 | // 为了防止安装包里面的名字有@ 54 | const index = item.lastIndexOf('@'); 55 | const k = index === -1 ? item : item.slice(0, index); 56 | const v = index === -1 ? '' : item.slice(index + 1) || ''; 57 | pkg[key][k] = v; 58 | debugInfo(`${item}✅`); 59 | sleep(Math.random() * 500); 60 | }); 61 | fs.writeJsonSync(getpath('package.json'), pkg, { spaces: 2 }); 62 | }; 63 | 64 | export const run = async (str: string) => { 65 | const basePath = getEnv('base') as string; 66 | const runArr = str.split(' '); 67 | if (runArr.length < 2) { 68 | debugWarning(`运行参数错误${str}`); 69 | return false; 70 | } 71 | const [npm, ...args] = runArr; 72 | debugInfo(`${runArr.join(' ')}✅`); 73 | spawn.sync(npm, args, { 74 | stdio: 'pipe', 75 | cwd: basePath, 76 | }); 77 | }; 78 | 79 | export const downNodeModules = async () => { 80 | const basePath = getEnv('base') as string; 81 | const [n] = await checkNpmOrYarn(basePath); 82 | await run(`${n} install`); 83 | }; 84 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |
2 |

web-norm

3 |

4 | GitHub stars 5 | GitHub forks 6 |

7 | 8 | ## 其他性感的开源项目 🔥🔥 9 | 10 | - [vv-react-table(虚拟列表解决方案)](https://github.com/lyh0371/vv-react-table) 欢迎使用 😚 11 | - [web-guide(与框架无关的前端动态新手引导插件)](https://github.com/lyh0371/web-guide)欢迎使用 😚 12 | - [sp-ui(基于 vue3+vite2 的组件库-小玩意)](https://github.com/lyh0371/sp-ui)欢迎把玩 😚 13 | 14 | ## 初衷 15 | 16 | 每当接手一个新项目(如果项目中没有配置 eslint husky commitlint)等这些规范的话,就需要自己手动配置一遍,配置多了后我只能来句窝草!😬 17 | 18 | ## 目标 19 | 20 | 一个命令自动化配置项目规范 21 | 22 | ## 你将得到 23 | 24 | - 保存代码自动格式化 💯 25 | - 提交前 commit 校验 💯 26 | - eslint + pretter 校验 💯 27 | - husky 自动装载 💯 28 | - 说吧,你还想要啥... 29 | 30 | ## 安装 31 | 32 | 1 局部安装(推荐使用) 33 | 34 | ```sh 35 | npm install web-norm -D | yarn add web-norm -D | pnpm install web-norm -D 36 | ``` 37 | 38 | 在 package.json 中 39 | 40 | ```sh 41 | "scripts": { 42 | "web-norm": "web-norm", 43 | }, 44 | ``` 45 | 46 | 2. 全局安装 47 | 48 | ```sh 49 | npm install web-norm -g | yarn add web-norm -g | pnpm install web-norm -g 50 | ``` 51 | 52 | ## 使用 53 | 54 | 运行命令 55 | 56 | ```tip 57 | 请确保您的项目使用了git,否则会导致`husky`不生效 58 | ``` 59 | 60 | ```sh 61 | npm run web-norm 62 | ``` 63 | 64 | 65 | 66 | ## 支持配置 67 | 68 | `web-norm` 默认在提交记录上为带表情符号 📦👷📝🌟🐛🚀🌠🔂💎🚨 。如果不喜欢这些表情符号的话可以在用 `web-norm` 初始化项目的时候加上 `--noEmoji` 去掉 69 | 70 | ```sh 71 | "scripts": { 72 | "web-norm": "web-norm --noEmoji", 73 | }, 74 | ``` 75 | 76 | ## 验证 77 | 78 | 代码提交前校验 79 | 80 | ```sh 81 | npm run commit 82 | ``` 83 | 84 | 85 | 86 | ## 在老项目中使用 87 | 88 | 在老项目使用会牵扯到一个问题就是以前的代码规范和通过`web-norm`生成的代码规范不一致怎么办? 89 | 90 | 1、如果项目比较小,只有几个文件,你可以把所以的文件都保存一遍即可(保存的时候 vscode 会自动格式化代码,确保使用 vscode 编辑器并安装 eslint 和 pretter 插件) 91 | 92 | 93 | 94 | 2、如果项目比较大,建议使用 vscode 插件`Format Files`进行自动化保存 95 | 96 | 97 | 98 | ## 可能遇到问题,详细内容参考这篇文章[可能遇到问题](https://juejin.cn/post/7124196350446534670#heading-4) 99 | 100 | - husky 无法触发 101 | 102 | 1. 项目首先需要被 `git` 管理 103 | 104 | 2. mac 电脑执行 `npm run postinstallmac` 来设置 husky 的读写权限 105 | 106 | ## 说明 107 | 108 | 1. 在使用过程中遇到任何问题,请提交 issues 😚 109 | -------------------------------------------------------------------------------- /src/core/eslint.ts: -------------------------------------------------------------------------------- 1 | import fs from 'fs-extra' 2 | import { writeInPkg } from '../utils/tool' 3 | import { getPackageJson, getEnv, getEslintrc } from '../utils/env' 4 | import { prettierrcInit } from '../templet/prettierrc' 5 | import { eslintrcFn } from '../templet/eslintrc' 6 | import { getpath } from '../utils/path' 7 | import { teepEslintConfig } from '../especial' 8 | import { debugError } from '../utils/debug' 9 | const baseDep = [ 10 | 'eslint@^7.25.0', 11 | 'prettier@^2.7.1', 12 | 'eslint-friendly-formatter@^4.0.1', 13 | 'eslint-plugin-prettier@^4.0.0', 14 | 'eslint-plugin-html@^6.2.0', 15 | 'eslint-config-prettier@^8.5.0' 16 | ] 17 | 18 | interface Obj { 19 | [key: string]: any 20 | } 21 | 22 | export const eslintInit = async () => { 23 | let devDependencies: string[] = baseDep 24 | if (getEnv('isVue2')) { 25 | devDependencies = [...baseDep, 'eslint-plugin-vue@^9.21.1'] 26 | } 27 | if (getEnv('isVue3')) { 28 | devDependencies = [...baseDep, 'eslint-plugin-vue@^9.21.1', '@typescript-eslint/parser@^5.30.7'] 29 | } 30 | if (getEnv('isReact')) { 31 | devDependencies = [...baseDep, 'eslint-plugin-react@^7.30.1', 'eslint-plugin-jsx-a11y@^6.6.1', '@typescript-eslint/parser@^5.30.7', '@typescript-eslint/eslint-plugin@5.30.7'] 32 | } 33 | 34 | if (getEnv('merge')) { 35 | // 合并操作 36 | const oldEslintConfig = await getEslintrc() 37 | if (oldEslintConfig) { 38 | // 存在旧版本eslint 39 | const nEslint = getEnv('especial') ? teepEslintConfig.rules : {} 40 | const mEslint = meageEslint(oldEslintConfig, nEslint) 41 | const eslintToString = JSON.stringify(mEslint, null, 2) 42 | writeEslintConfig(`module.exports = ${eslintToString}`) 43 | } 44 | return false 45 | } 46 | 47 | // 调用down直接可以把依赖安装好 48 | // await down(devDependencies, '-D'); 49 | // writeInPkg 只是把依赖写入到package中 50 | await writeInPkg(devDependencies, 'devDependencies') 51 | 52 | writeEslintConfig(eslintrcFn(getEnv('especial') as boolean)) 53 | // 合并 执行一次 eslint 把重复的对象合并 54 | const eslint2 = await getEslintrc() 55 | writeEslintConfig(`module.exports = ${JSON.stringify(eslint2, null, 2)}`) 56 | async function writeEslintConfig(eslintConfig: string) { 57 | fs.outputFileSync(getpath('./.eslintrc.js'), eslintConfig) 58 | fs.outputFileSync(getpath('./.prettierrc'), prettierrcInit) 59 | let pkgJson = await getPackageJson() 60 | if (pkgJson['eslintConfig']) { 61 | delete pkgJson.eslintConfig 62 | } 63 | fs.writeJsonSync(getpath('package.json'), pkgJson, { spaces: 2 }) 64 | } 65 | } 66 | 67 | function meageEslint(oldEslintConfig: Obj, newEslintRules: Obj): Obj { 68 | const { rules } = oldEslintConfig 69 | if (oldEslintConfig && rules) { 70 | oldEslintConfig.rules = { 71 | ...oldEslintConfig.rules, 72 | ...newEslintRules 73 | } 74 | return oldEslintConfig 75 | } else { 76 | debugError('.eslintrc格式有误,请删除后再运行命令') 77 | return {} 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "web-norm", 3 | "version": "1.1.6", 4 | "description": "前端项目规范一键安装", 5 | "main": "dist/index.js", 6 | "scripts": { 7 | "dev": "nodemon ./index.ts", 8 | "tsc": "tsc", 9 | "build": "rm -rf dist && tsc && ts-node build/index.ts", 10 | "serve": "ts-node ./index.ts", 11 | "serve2": "ts-node ./index.ts --especial", 12 | "tsc-init": "tsc --init", 13 | "version": "ts-node build/version.ts", 14 | "commit": "git add . && git-cz", 15 | "prepare": "husky install", 16 | "release": "rm -rf dist && tsc && ts-node build/index.ts", 17 | "w": "web-norm1 --en", 18 | "pre-commit": "lint-staged", 19 | "postinstallmac": "git config core.hooksPath .husky && chmod 700 .husky/*", 20 | "eslint": "eslint --cache --max-warnings 0 \"{src,mock}/**/*.{vue,ts,js,tsx}\" --fix", 21 | "prettierwrite": "prettier --write src/**/*.{vue,ts,js,tsx,jsx}", 22 | "prettiercheck": "prettier --check src/**/*.{vue,ts,js,tsx,jsx}" 23 | }, 24 | "bin": { 25 | "web-norm": "./dist/index.js" 26 | }, 27 | "config": { 28 | "commitizen": { 29 | "path": "@commitlint/cz-commitlint" 30 | } 31 | }, 32 | "repository": { 33 | "type": "git", 34 | "url": "git+https://github.com/lyh0371/web-norm.git" 35 | }, 36 | "keywords": [], 37 | "author": "", 38 | "license": "ISC", 39 | "bugs": { 40 | "url": "https://github.com/lyh0371/web-norm/issues" 41 | }, 42 | "homepage": "https://github.com/lyh0371/web-norm#readme", 43 | "devDependencies": { 44 | "@commitlint/cli": "^17.0.3", 45 | "@commitlint/config-angular": "^17.0.3", 46 | "@commitlint/cz-commitlint": "^17.0.3", 47 | "@rollup/plugin-commonjs": "^22.0.0", 48 | "@rollup/plugin-node-resolve": "^13.3.0", 49 | "@types/cross-spawn": "^6.0.2", 50 | "@types/fs-extra": "^9.0.13", 51 | "@types/node": "^17.0.35", 52 | "babel-eslint": "^10.1.0", 53 | "commitizen": "^4.2.4", 54 | "cross-spawn": "^7.0.3", 55 | "cz-customizable": "^6.9.0", 56 | "eslint": "^7.25.0", 57 | "eslint-config-prettier": "^8.5.0", 58 | "eslint-friendly-formatter": "^4.0.1", 59 | "eslint-plugin-html": "^6.2.0", 60 | "eslint-plugin-prettier": "^4.0.0", 61 | "eslint-plugin-vue": "^9.20.1", 62 | "husky": "^8.0.1", 63 | "inquirer": "^8.0.0", 64 | "lint-staged": "^12.4.1", 65 | "minimist": "^1.2.6", 66 | "nodemon": "^2.0.16", 67 | "prettier": "^2.7.1", 68 | "rollup": "^2.75.6", 69 | "rollup-plugin-terser": "^7.0.2", 70 | "rollup-plugin-typescript2": "^0.32.1", 71 | "ts-node": "^10.7.0", 72 | "typescript": "^4.6.4" 73 | }, 74 | "dependencies": { 75 | "cac": "^6.7.12", 76 | "chalk": "^4.0.1", 77 | "enquirer": "^2.4.1", 78 | "fs-extra": "^10.1.0", 79 | "load-json-file": "^7.0.1", 80 | "husky": "^8.0.1", 81 | "cross-spawn": "^7.0.3", 82 | "babel-eslint": "^10.1.0" 83 | }, 84 | "lint-staged": { 85 | "*.{tsx}": [ 86 | "npm run eslint" 87 | ] 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /play/commitlint.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | extends: ['@commitlint/config-angular'], 3 | parserPreset: { 4 | parserOpts: { 5 | headerPattern: /^(.*?)(?:\((.*)\))?:?\s(.*)$/, 6 | headerCorrespondence: ['type', 'scope', 'subject'] 7 | } 8 | }, 9 | rules: { 10 | 'type-case': [0], 11 | 'type-empty': [2, 'never'], 12 | 'type-enum': [2, 'always', ['build', 'ci', 'docs', 'feat', 'fix', 'perf', 'refactor', 'revert', 'style', 'test']], 13 | 'scope-empty': [2, 'never'], 14 | 'subject-empty': [2, 'never'] 15 | }, 16 | prompt: { 17 | settings: {}, 18 | skip: ['body', 'footer', 'issues'], 19 | messages: { 20 | skip: '回车直接跳过', 21 | max: '最大%d字符', 22 | min: '%d chars at least', 23 | emptyWarning: '内容不能为空,重新输入', 24 | upperLimitWarning: 'over limit', 25 | lowerLimitWarning: 'below limit' 26 | }, 27 | questions: { 28 | type: { 29 | description: '请选择提交类型', 30 | enum: { 31 | feat: { 32 | description: '增加新功能', 33 | title: 'Features', 34 | emoji: '🌟' 35 | }, 36 | fix: { 37 | description: '修复bug', 38 | title: 'Bug Fixes', 39 | emoji: '🐛' 40 | }, 41 | docs: { 42 | description: '修改文档', 43 | title: 'Documentation', 44 | emoji: '📝' 45 | }, 46 | style: { 47 | description: '样式修改不影响逻辑', 48 | title: 'Styles', 49 | emoji: '💎' 50 | }, 51 | refactor: { 52 | description: '功能/代码重构', 53 | title: 'Code Refactoring', 54 | emoji: '🌠' 55 | }, 56 | perf: { 57 | description: '性能优化', 58 | title: 'Performance Improvements', 59 | emoji: '🚀' 60 | }, 61 | test: { 62 | description: '增删测试', 63 | title: 'Tests', 64 | emoji: '🚨' 65 | }, 66 | build: { 67 | description: '打包', 68 | title: '打包', 69 | emoji: '📦' 70 | }, 71 | ci: { 72 | description: 'CI部署', 73 | title: 'Continuous Integrations', 74 | emoji: '⚙️' 75 | }, 76 | 77 | revert: { 78 | description: '版本回退', 79 | title: 'Reverts', 80 | emoji: '🔂' 81 | } 82 | } 83 | }, 84 | scope: { 85 | description: '请输入修改的范围(必填)' 86 | }, 87 | subject: { 88 | description: '请简要描述提交(必填)' 89 | }, 90 | body: { 91 | description: '请输入详细描述(可选)' 92 | }, 93 | isBreaking: { 94 | description: '有什么突破性的变化吗?' 95 | }, 96 | breakingBody: { 97 | description: '一个破坏性的变更提交需要一个主体。 请输入提交本身的更长的描述 ' 98 | }, 99 | breaking: { 100 | description: 'Describe the breaking changes' 101 | }, 102 | isIssueAffected: { 103 | description: '是否有未解决的问题?' 104 | }, 105 | issuesBody: { 106 | description: 'If issues are closed, the commit requires a body. Please enter a longer description of the commit itself' 107 | }, 108 | issues: { 109 | description: '请输入问题说明' 110 | } 111 | } 112 | } 113 | } 114 | -------------------------------------------------------------------------------- /play/commitlint.config copy.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | extends: ['@commitlint/config-angular'], 3 | parserPreset: { 4 | parserOpts: { 5 | headerPattern: /^(.*?)(?:\((.*)\))?:?\s(.*)$/, 6 | headerCorrespondence: ['type', 'scope', 'subject'] 7 | } 8 | }, 9 | rules: { 10 | 'type-case': [0], 11 | 'type-empty': [2, 'never'], 12 | 'type-enum': [2, 'always', ['📦build', '👷ci', '📝docs', '🌟feat', '🐛fix', '🚀perf', '🌠refactor', '🔂revert', '💎style', '🚨test']], 13 | 'scope-empty': [2, 'never'], 14 | 'subject-empty': [2, 'never'] 15 | }, 16 | prompt: { 17 | settings: {}, 18 | skip: ['body', 'footer', 'issues'], 19 | messages: { 20 | skip: '回车直接跳过', 21 | max: '最大%d字符', 22 | min: '%d chars at least', 23 | emptyWarning: '内容不能为空,重新输入', 24 | upperLimitWarning: 'over limit', 25 | lowerLimitWarning: 'below limit' 26 | }, 27 | questions: { 28 | type: { 29 | description: '请选择提交类型', 30 | enum: { 31 | '🌟feat': { 32 | description: '增加新功能', 33 | title: 'Features', 34 | emoji: '🌟' 35 | }, 36 | '🐛fix': { 37 | description: '修复bug', 38 | title: 'Bug Fixes', 39 | emoji: '🐛' 40 | }, 41 | '📝docs': { 42 | description: '修改文档', 43 | title: 'Documentation', 44 | emoji: '📝' 45 | }, 46 | '💎style': { 47 | description: '样式修改不影响逻辑', 48 | title: 'Styles', 49 | emoji: '💎' 50 | }, 51 | '🌠refactor': { 52 | description: '功能/代码重构', 53 | title: 'Code Refactoring', 54 | emoji: '🌠' 55 | }, 56 | '🚀perf': { 57 | description: '性能优化', 58 | title: 'Performance Improvements', 59 | emoji: '🚀' 60 | }, 61 | '🚨test': { 62 | description: '增删测试', 63 | title: 'Tests', 64 | emoji: '🚨' 65 | }, 66 | '📦build': { 67 | description: '打包', 68 | title: '打包', 69 | emoji: '📦' 70 | }, 71 | '👷ci': { 72 | description: 'CI部署', 73 | title: 'Continuous Integrations', 74 | emoji: '⚙️' 75 | }, 76 | 77 | '🔂revert': { 78 | description: '版本回退', 79 | title: 'Reverts', 80 | emoji: '🔂' 81 | } 82 | } 83 | }, 84 | scope: { 85 | description: '请输入修改的范围(必填)' 86 | }, 87 | subject: { 88 | description: '请简要描述提交(必填)' 89 | }, 90 | body: { 91 | description: '请输入详细描述(可选)' 92 | }, 93 | isBreaking: { 94 | description: '有什么突破性的变化吗?' 95 | }, 96 | breakingBody: { 97 | description: '一个破坏性的变更提交需要一个主体。 请输入提交本身的更长的描述 ' 98 | }, 99 | breaking: { 100 | description: 'Describe the breaking changes' 101 | }, 102 | isIssueAffected: { 103 | description: '是否有未解决的问题?' 104 | }, 105 | issuesBody: { 106 | description: 'If issues are closed, the commit requires a body. Please enter a longer description of the commit itself' 107 | }, 108 | issues: { 109 | description: '请输入问题说明' 110 | } 111 | } 112 | } 113 | } 114 | -------------------------------------------------------------------------------- /commitlint.config.js: -------------------------------------------------------------------------------- 1 | 2 | module.exports={ 3 | extends: ['@commitlint/config-angular'], 4 | parserPreset: { 5 | parserOpts: { 6 | headerPattern: /^(.*?)(?:\((.*)\))?:?\s(.*)$/, 7 | headerCorrespondence: ['type', 'scope', 'subject'], 8 | }, 9 | }, 10 | rules: { 11 | 'type-case': [0], 12 | 'type-empty': [2, 'never'], 13 | 'type-enum': [ 14 | 2, 15 | 'always', 16 | [ 17 | '📦build', 18 | '👷ci', 19 | '📝docs', 20 | '🌟feat', 21 | '🐛fix', 22 | '🚀perf', 23 | '🌠refactor', 24 | '🔂revert', 25 | '💎style', 26 | '🚨test', 27 | ], 28 | ], 29 | 'scope-empty': [2, 'never'], 30 | 'subject-empty': [2, 'never'], 31 | }, 32 | prompt: { 33 | settings: {}, 34 | skip: ['body', 'footer', 'issues'], 35 | messages: { 36 | skip: '回车直接跳过', 37 | max: '最大%d字符', 38 | min: '%d chars at least', 39 | emptyWarning: '内容不能为空,重新输入', 40 | upperLimitWarning: 'over limit', 41 | lowerLimitWarning: 'below limit', 42 | }, 43 | questions: { 44 | type: { 45 | description: '请选择提交类型', 46 | enum: { 47 | '🌟feat': { 48 | description: '增加新功能', 49 | title: 'Features', 50 | emoji: '🌟', 51 | }, 52 | '🐛fix': { 53 | description: '修复bug', 54 | title: 'Bug Fixes', 55 | emoji: '🐛', 56 | }, 57 | '📝docs': { 58 | description: '修改文档', 59 | title: 'Documentation', 60 | emoji: '📝', 61 | }, 62 | '💎style': { 63 | description: '样式修改不影响逻辑', 64 | title: 'Styles', 65 | emoji: '💎', 66 | }, 67 | '🌠refactor': { 68 | description: '功能/代码重构', 69 | title: 'Code Refactoring', 70 | emoji: '🌠', 71 | }, 72 | '🚀perf': { 73 | description: '性能优化', 74 | title: 'Performance Improvements', 75 | emoji: '🚀', 76 | }, 77 | '🚨test': { 78 | description: '增删测试', 79 | title: 'Tests', 80 | emoji: '🚨', 81 | }, 82 | '📦build': { 83 | description: '打包', 84 | title: '打包', 85 | emoji: '📦', 86 | }, 87 | '👷ci': { 88 | description: 'CI部署', 89 | title: 'Continuous Integrations', 90 | emoji: '⚙️', 91 | }, 92 | 93 | '🔂revert': { 94 | description: '版本回退', 95 | title: 'Reverts', 96 | emoji: '🔂', 97 | }, 98 | }, 99 | }, 100 | scope: { 101 | description: '请输入修改的范围(必填)', 102 | }, 103 | subject: { 104 | description: '请简要描述提交(必填)', 105 | }, 106 | body: { 107 | description: '请输入详细描述(可选)', 108 | }, 109 | isBreaking: { 110 | description: '有什么突破性的变化吗?', 111 | }, 112 | breakingBody: { 113 | description: 114 | '一个破坏性的变更提交需要一个主体。 请输入提交本身的更长的描述 ', 115 | }, 116 | breaking: { 117 | description: 'Describe the breaking changes', 118 | }, 119 | isIssueAffected: { 120 | description: '是否有未解决的问题?', 121 | }, 122 | issuesBody: { 123 | description: 124 | 'If issues are closed, the commit requires a body. Please enter a longer description of the commit itself', 125 | }, 126 | issues: { 127 | description: '请输入问题说明', 128 | }, 129 | }, 130 | }, 131 | } -------------------------------------------------------------------------------- /src/templet/commitlint-no-emoji.config.ts: -------------------------------------------------------------------------------- 1 | export const commitLintConfigNoEmoji = ` 2 | module.exports={ 3 | extends: ['@commitlint/config-angular'], 4 | parserPreset: { 5 | parserOpts: { 6 | headerPattern: /^(.*?)(?:\\((.*)\\))?:?\\s(.*)$/, 7 | headerCorrespondence: ['type', 'scope', 'subject'], 8 | }, 9 | }, 10 | rules: { 11 | 'type-case': [0], 12 | 'type-empty': [2, 'never'], 13 | 'type-enum': [ 14 | 2, 15 | 'always', 16 | [ 17 | 'build', 18 | 'ci', 19 | 'docs', 20 | 'feat', 21 | 'fix', 22 | 'perf', 23 | 'refactor', 24 | 'revert', 25 | 'style', 26 | 'test', 27 | ], 28 | ], 29 | 'scope-empty': [2, 'never'], 30 | 'subject-empty': [2, 'never'], 31 | }, 32 | prompt: { 33 | settings: {}, 34 | skip: ['body', 'footer', 'issues'], 35 | messages: { 36 | skip: '回车直接跳过', 37 | max: '最大%d字符', 38 | min: '%d chars at least', 39 | emptyWarning: '内容不能为空,重新输入', 40 | upperLimitWarning: 'over limit', 41 | lowerLimitWarning: 'below limit', 42 | }, 43 | questions: { 44 | type: { 45 | description: '请选择提交类型', 46 | enum: { 47 | 'feat': { 48 | description: '增加新功能', 49 | title: 'Features', 50 | emoji: '🌟', 51 | }, 52 | 'fix': { 53 | description: '修复bug', 54 | title: 'Bug Fixes', 55 | emoji: '🐛', 56 | }, 57 | 'docs': { 58 | description: '修改文档', 59 | title: 'Documentation', 60 | emoji: '📝', 61 | }, 62 | 'style': { 63 | description: '样式修改不影响逻辑', 64 | title: 'Styles', 65 | emoji: '💎', 66 | }, 67 | 'refactor': { 68 | description: '功能/代码重构', 69 | title: 'Code Refactoring', 70 | emoji: '🌠', 71 | }, 72 | 'perf': { 73 | description: '性能优化', 74 | title: 'Performance Improvements', 75 | emoji: '🚀', 76 | }, 77 | 'test': { 78 | description: '增删测试', 79 | title: 'Tests', 80 | emoji: '🚨', 81 | }, 82 | 'build': { 83 | description: '打包', 84 | title: '打包', 85 | emoji: '📦', 86 | }, 87 | 'ci': { 88 | description: 'CI部署', 89 | title: 'Continuous Integrations', 90 | emoji: '⚙️', 91 | }, 92 | 93 | 'revert': { 94 | description: '版本回退', 95 | title: 'Reverts', 96 | emoji: '🔂', 97 | }, 98 | }, 99 | }, 100 | scope: { 101 | description: '请输入修改的范围(必填)', 102 | }, 103 | subject: { 104 | description: '请简要描述提交(必填)', 105 | }, 106 | body: { 107 | description: '请输入详细描述(可选)', 108 | }, 109 | isBreaking: { 110 | description: '有什么突破性的变化吗?', 111 | }, 112 | breakingBody: { 113 | description: 114 | '一个破坏性的变更提交需要一个主体。 请输入提交本身的更长的描述 ', 115 | }, 116 | breaking: { 117 | description: 'Describe the breaking changes', 118 | }, 119 | isIssueAffected: { 120 | description: '是否有未解决的问题?', 121 | }, 122 | issuesBody: { 123 | description: 124 | 'If issues are closed, the commit requires a body. Please enter a longer description of the commit itself', 125 | }, 126 | issues: { 127 | description: '请输入问题说明', 128 | }, 129 | }, 130 | }, 131 | }`; 132 | -------------------------------------------------------------------------------- /src/templet/commitlint.config.ts: -------------------------------------------------------------------------------- 1 | export const commitLintConfig = ` 2 | module.exports={ 3 | extends: ['@commitlint/config-angular'], 4 | parserPreset: { 5 | parserOpts: { 6 | headerPattern: /^(.*?)(?:\\((.*)\\))?:?\\s(.*)$/, 7 | headerCorrespondence: ['type', 'scope', 'subject'], 8 | }, 9 | }, 10 | rules: { 11 | 'type-case': [0], 12 | 'type-empty': [2, 'never'], 13 | 'type-enum': [ 14 | 2, 15 | 'always', 16 | [ 17 | '📦build', 18 | '👷ci', 19 | '📝docs', 20 | '🌟feat', 21 | '🐛fix', 22 | '🚀perf', 23 | '🌠refactor', 24 | '🔂revert', 25 | '💎style', 26 | '🚨test', 27 | ], 28 | ], 29 | 'scope-empty': [2, 'never'], 30 | 'subject-empty': [2, 'never'], 31 | }, 32 | prompt: { 33 | settings: {}, 34 | skip: ['body', 'footer', 'issues'], 35 | messages: { 36 | skip: '回车直接跳过', 37 | max: '最大%d字符', 38 | min: '%d chars at least', 39 | emptyWarning: '内容不能为空,重新输入', 40 | upperLimitWarning: 'over limit', 41 | lowerLimitWarning: 'below limit', 42 | }, 43 | questions: { 44 | type: { 45 | description: '请选择提交类型', 46 | enum: { 47 | '🌟feat': { 48 | description: '增加新功能', 49 | title: 'Features', 50 | emoji: '🌟', 51 | }, 52 | '🐛fix': { 53 | description: '修复bug', 54 | title: 'Bug Fixes', 55 | emoji: '🐛', 56 | }, 57 | '📝docs': { 58 | description: '修改文档', 59 | title: 'Documentation', 60 | emoji: '📝', 61 | }, 62 | '💎style': { 63 | description: '样式修改不影响逻辑', 64 | title: 'Styles', 65 | emoji: '💎', 66 | }, 67 | '🌠refactor': { 68 | description: '功能/代码重构', 69 | title: 'Code Refactoring', 70 | emoji: '🌠', 71 | }, 72 | '🚀perf': { 73 | description: '性能优化', 74 | title: 'Performance Improvements', 75 | emoji: '🚀', 76 | }, 77 | '🚨test': { 78 | description: '增删测试', 79 | title: 'Tests', 80 | emoji: '🚨', 81 | }, 82 | '📦build': { 83 | description: '打包', 84 | title: '打包', 85 | emoji: '📦', 86 | }, 87 | '👷ci': { 88 | description: 'CI部署', 89 | title: 'Continuous Integrations', 90 | emoji: '⚙️', 91 | }, 92 | 93 | '🔂revert': { 94 | description: '版本回退', 95 | title: 'Reverts', 96 | emoji: '🔂', 97 | }, 98 | }, 99 | }, 100 | scope: { 101 | description: '请输入修改的范围(必填)', 102 | }, 103 | subject: { 104 | description: '请简要描述提交(必填)', 105 | }, 106 | body: { 107 | description: '请输入详细描述(可选)', 108 | }, 109 | isBreaking: { 110 | description: '有什么突破性的变化吗?', 111 | }, 112 | breakingBody: { 113 | description: 114 | '一个破坏性的变更提交需要一个主体。 请输入提交本身的更长的描述 ', 115 | }, 116 | breaking: { 117 | description: 'Describe the breaking changes', 118 | }, 119 | isIssueAffected: { 120 | description: '是否有未解决的问题?', 121 | }, 122 | issuesBody: { 123 | description: 124 | 'If issues are closed, the commit requires a body. Please enter a longer description of the commit itself', 125 | }, 126 | issues: { 127 | description: '请输入问题说明', 128 | }, 129 | }, 130 | }, 131 | }`; 132 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | /* 访问 https://aka.ms/tsconfig.json 查看更多 */ 4 | 5 | /* 基本选项 */ 6 | // "incremental": true, /* 启用增量编译 */ 7 | "target": "es5", /* 指定 ECMAScript 目标版本: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', 或者 'ESNEXT'. */ 8 | "module": "commonjs", /* 指定使用模块: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', 或者 'ESNext'. */ 9 | // "lib": [], /* 指定要包含在编译中的库文件 */ 10 | // "allowJs": true, /* 允许编译 javascript 文件 */ 11 | // "checkJs": true, /* 报告 javascript 文件中的错误 */ 12 | // "jsx": "preserve", /* 指定 jsx 代码的生成: 'preserve', 'react-native', 'react', 'react-jsx' 或者 'react-jsxdev'. */ 13 | // "declaration": true, /* 生成相应的 '.d.ts' 文件 */ 14 | // "declarationMap": true, /* 对每个 '.d.ts' 文件进行遍历 */ 15 | // "sourceMap": true, /* 生成相应的 '.map' 文件 */ 16 | // "outFile": "./", /* 将输出文件合并为一个文件 */ 17 | "outDir": "./dist", /* 指定输出目录 */ 18 | // "rootDir": "./", /* 用来控制输出目录结构 --outDir */ 19 | // "composite": true, /* 启用项目编译 */ 20 | // "tsBuildInfoFile": "./", /* 指定文件来存储增量编译信息 */ 21 | "removeComments": true, /* 删除编译后的所有的注释 */ 22 | // "noEmit": true, /* 不生成输出文件 */ 23 | // "importHelpers": true, /* 从 tslib 导入辅助工具函数 */ 24 | // "downlevelIteration": true, /* 在 ES5 和 ES3 中全面支持 for-of */ 25 | // "isolatedModules": true, /* 将每个文件作为单独的模块 (与 'ts.transpileModule' 类似) */ 26 | 27 | /* 严格的类型检查选项 */ 28 | "strict": true, /* 启用所有严格类型检查选项 */ 29 | // "noImplicitAny": true, /* 在表达式和声明上有隐含的 any 类型时报错 */ 30 | // "strictNullChecks": true, /* 启用严格的 null 检查 */ 31 | // "strictFunctionTypes": true, /* 启用严格的 function 类型检查 */ 32 | // "strictBindCallApply": true, /* 启用严格的 bind、call、apply 方法参数检查 */ 33 | // "strictPropertyInitialization": true, /* 启用严格的类的属性初始化检查 */ 34 | // "noImplicitThis": true, /* 当 this 表达式值为 any 类型的时候,生成一个错误 */ 35 | // "alwaysStrict": true, /* 以严格模式检查每个模块,并在每个文件里加入 'use strict' */ 36 | 37 | /* 额外的检查 */ 38 | "noUnusedLocals": true, /* 有未使用的变量时,抛出错误 */ 39 | "noUnusedParameters": true, /* 有未使用的参数时,抛出错误 */ 40 | // "noImplicitReturns": true, /* 并不是所有函数里的代码都有返回值时,抛出错误 */ 41 | // "noFallthroughCasesInSwitch": true, /* 报告 switch 语句的 fallthrough 错误。(即,不允许 switch 的 case 语句贯穿) */ 42 | // "noUncheckedIndexedAccess": true, /* 在索引签名结果中包含 undefined */ 43 | // "noPropertyAccessFromIndexSignature": true, /* 需要索引签名中未声明的属性才能使用元素访问 */ 44 | 45 | /* Module Resolution Options */ 46 | // "moduleResolution": "node", /* 选择模块解析策略: 'node' (Node.js) or 'classic' (TypeScript pre-1.6) */ 47 | // "baseUrl": "./", /* 用于解析非相对模块名称的基目录 */ 48 | // "paths": {}, /* 模块名到基于 baseUrl 的路径映射的列表 */ 49 | // "rootDirs": [], /* 根文件夹列表,其组合内容表示项目运行时的结构内容 */ 50 | // "typeRoots": [], /* 包含类型声明的文件列表 */ 51 | // "types": [], /* 需要包含的类型声明文件名列表 */ 52 | // "allowSyntheticDefaultImports": true, /* 允许从没有设置默认导出的模块中默认导入 */ 53 | "esModuleInterop": true, /* 通过为所有导入创建名称空间对象,启用 CommonJS 和 ES 模块之间的的互动性 */ 54 | // "preserveSymlinks": true, /* 不解析符号链接的真实路径 */ 55 | // "allowUmdGlobalAccess": true, /* 允许从模块访问 UMD 全局变量 */ 56 | 57 | /* Source Map Options */ 58 | // "sourceRoot": "", /* 指定调试器应该找到 TypeScript 文件而不是源文件的位置 */ 59 | // "mapRoot": "", /* 指定调试器应该找到映射文件而不是生成文件的位置 */ 60 | // "inlineSourceMap": true, /* 生成单个 soucemaps 文件,而不是将 sourcemaps 生成不同的文件 */ 61 | // "inlineSources": true, /* E将代码与 sourcemaps 生成到一个文件中,要求同时设置了 --inlineSourceMap 或 --sourceMap 属性 */ 62 | 63 | /* Experimental Options */ 64 | // "experimentalDecorators": true, /* 启用装饰器 */ 65 | // "emitDecoratorMetadata": true, /* 为装饰器提供元数据的支持 */ 66 | 67 | /* Advanced Options */ 68 | "skipLibCheck": true, /* 跳过声明文件的类型检查 */ 69 | "forceConsistentCasingInFileNames": true, /* 进制对同一文件使用大小写不一致的引用 */ 70 | "resolveJsonModule":true, 71 | }, 72 | "include": [ 73 | "./index.ts", 74 | "src**/*.ts" 75 | ], 76 | } 77 | -------------------------------------------------------------------------------- /.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | root: true, 3 | parserOptions: { 4 | ecmaVersion: 11, 5 | parser: 'babel-eslint', 6 | sourceType: 'module' 7 | }, 8 | env: { 9 | browser: true, 10 | node: true, 11 | es6: true 12 | }, 13 | plugins: ['prettier'], 14 | extends: ['plugin:vue/recommended', 'eslint:recommended', 'plugin:prettier/recommended'], 15 | rules: { 16 | 'vue/order-in-components': 'off', 17 | 'vue/html-self-closing': 'off', 18 | 'vue/require-default-prop': 'off', 19 | 'vue/max-attributes-per-line': [ 20 | 0, 21 | { 22 | singleline: 10, 23 | multiline: { 24 | max: 1, 25 | allowFirstLine: false 26 | } 27 | } 28 | ], 29 | 'vue/singleline-html-element-content-newline': 'off', 30 | 'vue/multiline-html-element-content-newline': 'off', 31 | 'vue/name-property-casing': ['error', 'PascalCase'], 32 | 'vue/no-v-html': 'off', 33 | 'prettier/prettier': 'error', 34 | 'accessor-pairs': 2, 35 | 'arrow-spacing': [ 36 | 2, 37 | { 38 | before: true, 39 | after: true 40 | } 41 | ], 42 | 'block-spacing': [2, 'always'], 43 | 'brace-style': [ 44 | 2, 45 | '1tbs', 46 | { 47 | allowSingleLine: true 48 | } 49 | ], 50 | camelcase: [ 51 | 0, 52 | { 53 | properties: 'always' 54 | } 55 | ], 56 | 'comma-dangle': [ 57 | 'error', 58 | { 59 | arrays: 'never', 60 | objects: 'never', 61 | imports: 'never', 62 | exports: 'never', 63 | functions: 'never' 64 | } 65 | ], 66 | 'comma-spacing': [ 67 | 2, 68 | { 69 | before: false, 70 | after: true 71 | } 72 | ], 73 | 'comma-style': [2, 'last'], 74 | 'constructor-super': 2, 75 | curly: [2, 'multi-line'], 76 | 'dot-location': [2, 'property'], 77 | 'eol-last': 2, 78 | eqeqeq: 'off', 79 | 'generator-star-spacing': [ 80 | 2, 81 | { 82 | before: true, 83 | after: true 84 | } 85 | ], 86 | 'handle-callback-err': [2, '^(err|error)$'], 87 | indent: 'off', 88 | 'key-spacing': [ 89 | 2, 90 | { 91 | beforeColon: false, 92 | afterColon: true 93 | } 94 | ], 95 | 'keyword-spacing': [ 96 | 2, 97 | { 98 | before: true, 99 | after: true 100 | } 101 | ], 102 | 'new-cap': [ 103 | 2, 104 | { 105 | newIsCap: true, 106 | capIsNew: false 107 | } 108 | ], 109 | 'new-parens': 2, 110 | 'no-array-constructor': 2, 111 | 'no-caller': 2, 112 | 'no-console': [ 113 | 'error', 114 | { 115 | allow: ['warn', 'error'] 116 | } 117 | ], 118 | 'no-class-assign': 2, 119 | 'no-cond-assign': 2, 120 | 'no-const-assign': 2, 121 | 'no-control-regex': 0, 122 | 'no-delete-var': 2, 123 | 'no-dupe-args': 2, 124 | 'no-dupe-class-members': 2, 125 | 'no-dupe-keys': 2, 126 | 'no-duplicate-case': 2, 127 | 'no-empty-character-class': 2, 128 | 'no-empty-pattern': 2, 129 | 'no-eval': 0, 130 | 'no-ex-assign': 2, 131 | 'no-extend-native': 2, 132 | 'no-extra-bind': 2, 133 | 'no-extra-boolean-cast': 2, 134 | 'no-extra-parens': [2, 'functions'], 135 | 'no-fallthrough': 2, 136 | 'no-floating-decimal': 2, 137 | 'no-func-assign': 2, 138 | 'no-implied-eval': 2, 139 | 'no-inner-declarations': [2, 'functions'], 140 | 'no-invalid-regexp': 2, 141 | 'no-irregular-whitespace': 2, 142 | 'no-iterator': 2, 143 | 'no-label-var': 2, 144 | 'no-labels': [ 145 | 2, 146 | { 147 | allowLoop: false, 148 | allowSwitch: false 149 | } 150 | ], 151 | 'no-lone-blocks': 2, 152 | 'no-mixed-spaces-and-tabs': 2, 153 | 'no-multi-spaces': 2, 154 | 'no-multi-str': 2, 155 | 'no-multiple-empty-lines': [ 156 | 2, 157 | { 158 | max: 1 159 | } 160 | ], 161 | 'no-native-reassign': 2, 162 | 'no-negated-in-lhs': 2, 163 | 'no-new-object': 2, 164 | 'no-new-require': 2, 165 | 'no-new-symbol': 2, 166 | 'no-new-wrappers': 2, 167 | 'no-obj-calls': 2, 168 | 'no-octal': 2, 169 | 'no-octal-escape': 2, 170 | 'no-path-concat': 2, 171 | 'no-proto': 2, 172 | 'no-redeclare': 2, 173 | 'no-regex-spaces': 2, 174 | 'no-return-assign': [2, 'except-parens'], 175 | 'no-self-assign': 2, 176 | 'no-self-compare': 2, 177 | 'no-sequences': 2, 178 | 'no-shadow-restricted-names': 2, 179 | 'no-spaced-func': 2, 180 | 'no-sparse-arrays': 2, 181 | 'no-this-before-super': 2, 182 | 'no-throw-literal': 2, 183 | 'no-trailing-spaces': 2, 184 | 'no-undef': 2, 185 | 'no-undef-init': 2, 186 | 'no-unexpected-multiline': 2, 187 | 'no-unmodified-loop-condition': 2, 188 | 'no-unneeded-ternary': [ 189 | 2, 190 | { 191 | defaultAssignment: false 192 | } 193 | ], 194 | 'no-unreachable': 2, 195 | 'no-unsafe-finally': 2, 196 | 'no-unused-vars': [ 197 | 2, 198 | { 199 | vars: 'all', 200 | args: 'none' 201 | } 202 | ], 203 | 'no-useless-call': 2, 204 | 'no-useless-computed-key': 2, 205 | 'no-useless-constructor': 2, 206 | 'no-useless-escape': 0, 207 | 'no-whitespace-before-property': 2, 208 | 'no-with': 2, 209 | 'one-var': [ 210 | 2, 211 | { 212 | initialized: 'never' 213 | } 214 | ], 215 | 'operator-linebreak': [ 216 | 2, 217 | 'after', 218 | { 219 | overrides: { 220 | '?': 'before', 221 | ':': 'before' 222 | } 223 | } 224 | ], 225 | 'padded-blocks': [2, 'never'], 226 | quotes: 'off', 227 | semi: 'off', 228 | 'semi-spacing': [ 229 | 2, 230 | { 231 | before: false, 232 | after: true 233 | } 234 | ], 235 | 'space-before-blocks': [2, 'always'], 236 | 'space-before-function-paren': 'off', 237 | 'space-in-parens': [2, 'never'], 238 | 'space-infix-ops': 2, 239 | 'space-unary-ops': [ 240 | 2, 241 | { 242 | words: true, 243 | nonwords: false 244 | } 245 | ], 246 | 'spaced-comment': 'off', 247 | 'template-curly-spacing': [2, 'never'], 248 | 'use-isnan': 2, 249 | 'valid-typeof': 2, 250 | 'wrap-iife': [2, 'any'], 251 | 'yield-star-spacing': [2, 'both'], 252 | yoda: [2, 'never'], 253 | 'prefer-const': 2, 254 | 'no-debugger': 0, 255 | 'object-curly-spacing': [ 256 | 0, 257 | 'always', 258 | { 259 | objectsInObjects: false 260 | } 261 | ], 262 | 'array-bracket-spacing': [2, 'never'] 263 | } 264 | } 265 | -------------------------------------------------------------------------------- /play/.eslintrc.js: -------------------------------------------------------------------------------- 1 | 2 | module.exports = { 3 | root: true, 4 | parserOptions: { 5 | ecmaVersion: 11, 6 | parser: 'babel-eslint', 7 | sourceType: 'module' 8 | }, 9 | env: { 10 | browser: true, 11 | node: true, 12 | es6: true 13 | }, 14 | plugins: ['prettier'], 15 | extends: ['plugin:vue/recommended', 'eslint:recommended', 'plugin:prettier/recommended'], 16 | rules: { 17 | 'prettier/prettier': 'error', 18 | 'vue/order-in-components': 'off', 19 | 'vue/html-self-closing': 'off', 20 | 'vue/require-default-prop': 'off', 21 | 'vue/max-attributes-per-line': [ 22 | 0, 23 | { 24 | singleline: 10, 25 | multiline: { 26 | max: 1, 27 | allowFirstLine: false 28 | } 29 | } 30 | ], 31 | 'vue/singleline-html-element-content-newline': 'off', 32 | 'vue/multiline-html-element-content-newline': 'off', 33 | 'vue/name-property-casing': ['error', 'PascalCase'], 34 | 'vue/no-v-html': 'off', 35 | 'accessor-pairs': 2, 36 | 'arrow-spacing': [ 37 | 2, 38 | { 39 | before: true, 40 | after: true 41 | } 42 | ], 43 | 'block-spacing': [2, 'always'], 44 | 'brace-style': [ 45 | 2, 46 | '1tbs', 47 | { 48 | allowSingleLine: true 49 | } 50 | ], 51 | camelcase: [ 52 | 0, 53 | { 54 | properties: 'always' 55 | } 56 | ], 57 | 'comma-dangle': [ 58 | 'error', 59 | { 60 | arrays: 'never', 61 | objects: 'never', 62 | imports: 'never', 63 | exports: 'never', 64 | functions: 'never' 65 | } 66 | ], 67 | 'comma-spacing': [ 68 | 2, 69 | { 70 | before: false, 71 | after: true 72 | } 73 | ], 74 | 'comma-style': [2, 'last'], 75 | 'constructor-super': 2, 76 | curly: [2, 'multi-line'], 77 | 'dot-location': [2, 'property'], 78 | 'eol-last': 2, 79 | eqeqeq: 'off', 80 | 'generator-star-spacing': [ 81 | 2, 82 | { 83 | before: true, 84 | after: true 85 | } 86 | ], 87 | 'handle-callback-err': [2, '^(err|error)$'], 88 | indent: 'off', 89 | // indent: [ 90 | // 2, 91 | // 2, 92 | // { 93 | // SwitchCase: 1, 94 | // }, 95 | // ], 96 | 'jsx-quotes': [2, 'prefer-single'], 97 | 'key-spacing': [ 98 | 2, 99 | { 100 | beforeColon: false, 101 | afterColon: true 102 | } 103 | ], 104 | 'keyword-spacing': [ 105 | 2, 106 | { 107 | before: true, 108 | after: true 109 | } 110 | ], 111 | 'new-cap': [ 112 | 2, 113 | { 114 | newIsCap: true, 115 | capIsNew: false 116 | } 117 | ], 118 | 'new-parens': 2, 119 | 'no-array-constructor': 2, 120 | 'no-caller': 2, 121 | 'no-console': 'off', 122 | 'no-class-assign': 2, 123 | 'no-cond-assign': 2, 124 | 'no-const-assign': 2, 125 | 'no-control-regex': 0, 126 | 'no-delete-var': 2, 127 | 'no-dupe-args': 2, 128 | 'no-dupe-class-members': 2, 129 | 'no-dupe-keys': 2, 130 | 'no-duplicate-case': 2, 131 | 'no-empty-character-class': 2, 132 | 'no-empty-pattern': 2, 133 | 'no-eval': 0, 134 | 'no-ex-assign': 2, 135 | 'no-extend-native': 2, 136 | 'no-extra-bind': 2, 137 | 'no-extra-boolean-cast': 2, 138 | 'no-extra-parens': [2, 'functions'], 139 | 'no-fallthrough': 2, 140 | 'no-floating-decimal': 2, 141 | 'no-func-assign': 2, 142 | 'no-implied-eval': 2, 143 | 'no-inner-declarations': [2, 'functions'], 144 | 'no-invalid-regexp': 2, 145 | 'no-irregular-whitespace': 2, 146 | 'no-iterator': 2, 147 | 'no-label-var': 2, 148 | 'no-labels': [ 149 | 2, 150 | { 151 | allowLoop: false, 152 | allowSwitch: false 153 | } 154 | ], 155 | 'no-lone-blocks': 2, 156 | 'no-mixed-spaces-and-tabs': 2, 157 | 'no-multi-spaces': 2, 158 | 'no-multi-str': 2, 159 | 'no-multiple-empty-lines': [ 160 | 2, 161 | { 162 | max: 1 163 | } 164 | ], 165 | 'no-native-reassign': 2, 166 | 'no-negated-in-lhs': 2, 167 | 'no-new-object': 2, 168 | 'no-new-require': 2, 169 | 'no-new-symbol': 2, 170 | 'no-new-wrappers': 2, 171 | 'no-obj-calls': 2, 172 | 'no-octal': 2, 173 | 'no-octal-escape': 2, 174 | 'no-path-concat': 2, 175 | 'no-proto': 2, 176 | 'no-redeclare': 2, 177 | 'no-regex-spaces': 2, 178 | 'no-return-assign': [2, 'except-parens'], 179 | 'no-self-assign': 2, 180 | 'no-self-compare': 2, 181 | 'no-sequences': 2, 182 | 'no-shadow-restricted-names': 2, 183 | 'no-spaced-func': 2, 184 | 'no-sparse-arrays': 2, 185 | 'no-this-before-super': 2, 186 | 'no-throw-literal': 2, 187 | 'no-trailing-spaces': 2, 188 | 'no-undef': 2, 189 | 'no-undef-init': 2, 190 | 'no-unexpected-multiline': 2, 191 | 'no-unmodified-loop-condition': 2, 192 | 'no-unneeded-ternary': [ 193 | 2, 194 | { 195 | defaultAssignment: false 196 | } 197 | ], 198 | 'no-unreachable': 2, 199 | 'no-unsafe-finally': 2, 200 | 'no-unused-vars': [ 201 | 2, 202 | { 203 | vars: 'all', 204 | args: 'none' 205 | } 206 | ], 207 | 'no-useless-call': 2, 208 | 'no-useless-computed-key': 2, 209 | 'no-useless-constructor': 2, 210 | 'no-useless-escape': 0, 211 | 'no-whitespace-before-property': 2, 212 | 'no-with': 2, 213 | 'one-var': [ 214 | 2, 215 | { 216 | initialized: 'never' 217 | } 218 | ], 219 | 'operator-linebreak': [ 220 | 2, 221 | 'after', 222 | { 223 | overrides: { 224 | '?': 'before', 225 | ':': 'before' 226 | } 227 | } 228 | ], 229 | 'padded-blocks': [2, 'never'], 230 | quotes: 'off', 231 | semi: 'off', 232 | 'semi-spacing': [ 233 | 2, 234 | { 235 | before: false, 236 | after: true 237 | } 238 | ], 239 | 'space-before-blocks': [2, 'always'], 240 | 'space-before-function-paren': 'off', 241 | 'space-in-parens': [2, 'never'], 242 | 'space-infix-ops': 2, 243 | 'space-unary-ops': [ 244 | 2, 245 | { 246 | words: true, 247 | nonwords: false 248 | } 249 | ], 250 | 'spaced-comment': 'off', 251 | 'template-curly-spacing': [2, 'never'], 252 | 'use-isnan': 2, 253 | 'valid-typeof': 2, 254 | 'wrap-iife': [2, 'any'], 255 | 'yield-star-spacing': [2, 'both'], 256 | yoda: [2, 'never'], 257 | 'prefer-const': 2, 258 | 'no-debugger': process.env.NODE_ENV === 'production' ? 2 : 0, 259 | 'object-curly-spacing': [ 260 | 0, 261 | 'always', 262 | { 263 | objectsInObjects: false 264 | } 265 | ], 266 | 'array-bracket-spacing': [2, 'never'] 267 | } 268 | } 269 | 270 | -------------------------------------------------------------------------------- /.eslintcache: -------------------------------------------------------------------------------- 1 | [{"/Users/lyh/Desktop/prTemp/web-norm/src/cli.ts":"1","/Users/lyh/Desktop/prTemp/web-norm/src/core/commitlint.ts":"2","/Users/lyh/Desktop/prTemp/web-norm/src/core/eslint.ts":"3","/Users/lyh/Desktop/prTemp/web-norm/src/core/eslintignore.ts":"4","/Users/lyh/Desktop/prTemp/web-norm/src/core/husky.ts":"5","/Users/lyh/Desktop/prTemp/web-norm/src/core/special.ts":"6","/Users/lyh/Desktop/prTemp/web-norm/src/core/vscode.ts":"7","/Users/lyh/Desktop/prTemp/web-norm/src/especial.ts":"8","/Users/lyh/Desktop/prTemp/web-norm/src/start.ts":"9","/Users/lyh/Desktop/prTemp/web-norm/src/templet/commitlint-no-emoji.config.ts":"10","/Users/lyh/Desktop/prTemp/web-norm/src/templet/commitlint.config.ts":"11","/Users/lyh/Desktop/prTemp/web-norm/src/templet/eslintrc.ts":"12","/Users/lyh/Desktop/prTemp/web-norm/src/templet/prettierrc.ts":"13","/Users/lyh/Desktop/prTemp/web-norm/src/utils/check.ts":"14","/Users/lyh/Desktop/prTemp/web-norm/src/utils/debug.ts":"15","/Users/lyh/Desktop/prTemp/web-norm/src/utils/env.ts":"16","/Users/lyh/Desktop/prTemp/web-norm/src/utils/path.ts":"17","/Users/lyh/Desktop/prTemp/web-norm/src/utils/tool.ts":"18"},{"size":1393,"mtime":1706596616917,"results":"19","hashOfConfig":"20"},{"size":1618,"mtime":1706596115913,"results":"21","hashOfConfig":"20"},{"size":2288,"mtime":1706596770553,"results":"22","hashOfConfig":"20"},{"size":321,"mtime":1706596115914,"results":"23","hashOfConfig":"20"},{"size":1486,"mtime":1706596853068,"results":"24","hashOfConfig":"20"},{"size":465,"mtime":1706596115915,"results":"25","hashOfConfig":"20"},{"size":2600,"mtime":1706596115916,"results":"26","hashOfConfig":"20"},{"size":109,"mtime":1706596730619,"results":"27","hashOfConfig":"20"},{"size":1534,"mtime":1658718641264,"results":"28","hashOfConfig":"20"},{"size":3365,"mtime":1706596115917,"results":"29","hashOfConfig":"20"},{"size":3438,"mtime":1706596115917,"results":"30","hashOfConfig":"20"},{"size":6353,"mtime":1706596115918,"results":"31","hashOfConfig":"20"},{"size":158,"mtime":1706596115918,"results":"32","hashOfConfig":"20"},{"size":979,"mtime":1706596115940,"results":"33","hashOfConfig":"20"},{"size":1183,"mtime":1706596115963,"results":"34","hashOfConfig":"20"},{"size":2178,"mtime":1706596621561,"results":"35","hashOfConfig":"20"},{"size":182,"mtime":1706596115997,"results":"36","hashOfConfig":"20"},{"size":2300,"mtime":1706596115921,"results":"37","hashOfConfig":"20"},{"filePath":"38","messages":"39","suppressedMessages":"40","errorCount":1,"fatalErrorCount":1,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0,"source":null},"1qmntqh",{"filePath":"41","messages":"42","suppressedMessages":"43","errorCount":1,"fatalErrorCount":1,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0,"source":null},{"filePath":"44","messages":"45","suppressedMessages":"46","errorCount":1,"fatalErrorCount":1,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0,"source":null},{"filePath":"47","messages":"48","suppressedMessages":"49","errorCount":1,"fatalErrorCount":1,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0,"source":null},{"filePath":"50","messages":"51","suppressedMessages":"52","errorCount":1,"fatalErrorCount":1,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0,"source":null},{"filePath":"53","messages":"54","suppressedMessages":"55","errorCount":1,"fatalErrorCount":1,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0,"source":null},{"filePath":"56","messages":"57","suppressedMessages":"58","errorCount":1,"fatalErrorCount":1,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0,"source":null},{"filePath":"59","messages":"60","suppressedMessages":"61","errorCount":1,"fatalErrorCount":1,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0,"source":null},{"filePath":"62","messages":"63","suppressedMessages":"64","errorCount":1,"fatalErrorCount":1,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0,"source":null},{"filePath":"65","messages":"66","suppressedMessages":"67","errorCount":1,"fatalErrorCount":1,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0,"source":null},{"filePath":"68","messages":"69","suppressedMessages":"70","errorCount":1,"fatalErrorCount":1,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0,"source":null},{"filePath":"71","messages":"72","suppressedMessages":"73","errorCount":1,"fatalErrorCount":1,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0,"source":null},{"filePath":"74","messages":"75","suppressedMessages":"76","errorCount":1,"fatalErrorCount":1,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0,"source":null},{"filePath":"77","messages":"78","suppressedMessages":"79","errorCount":1,"fatalErrorCount":1,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0,"source":null},{"filePath":"80","messages":"81","suppressedMessages":"82","errorCount":1,"fatalErrorCount":1,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0,"source":null},{"filePath":"83","messages":"84","suppressedMessages":"85","errorCount":1,"fatalErrorCount":1,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0,"source":null},{"filePath":"86","messages":"87","suppressedMessages":"88","errorCount":1,"fatalErrorCount":1,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0,"source":null},{"filePath":"89","messages":"90","suppressedMessages":"91","errorCount":1,"fatalErrorCount":1,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0,"source":null},"/Users/lyh/Desktop/prTemp/web-norm/src/cli.ts",["92"],[],"/Users/lyh/Desktop/prTemp/web-norm/src/core/commitlint.ts",["93"],[],"/Users/lyh/Desktop/prTemp/web-norm/src/core/eslint.ts",["94"],[],"/Users/lyh/Desktop/prTemp/web-norm/src/core/eslintignore.ts",["95"],[],"/Users/lyh/Desktop/prTemp/web-norm/src/core/husky.ts",["96"],[],"/Users/lyh/Desktop/prTemp/web-norm/src/core/special.ts",["97"],[],"/Users/lyh/Desktop/prTemp/web-norm/src/core/vscode.ts",["98"],[],"/Users/lyh/Desktop/prTemp/web-norm/src/especial.ts",["99"],[],"/Users/lyh/Desktop/prTemp/web-norm/src/start.ts",["100"],[],"/Users/lyh/Desktop/prTemp/web-norm/src/templet/commitlint-no-emoji.config.ts",["101"],[],"/Users/lyh/Desktop/prTemp/web-norm/src/templet/commitlint.config.ts",["102"],[],"/Users/lyh/Desktop/prTemp/web-norm/src/templet/eslintrc.ts",["103"],[],"/Users/lyh/Desktop/prTemp/web-norm/src/templet/prettierrc.ts",["104"],[],"/Users/lyh/Desktop/prTemp/web-norm/src/utils/check.ts",["105"],[],"/Users/lyh/Desktop/prTemp/web-norm/src/utils/debug.ts",["106"],[],"/Users/lyh/Desktop/prTemp/web-norm/src/utils/env.ts",["107"],[],"/Users/lyh/Desktop/prTemp/web-norm/src/utils/path.ts",["108"],[],"/Users/lyh/Desktop/prTemp/web-norm/src/utils/tool.ts",["109"],[],{"ruleId":null,"fatal":true,"severity":2,"message":"110"},{"ruleId":null,"fatal":true,"severity":2,"message":"110"},{"ruleId":null,"fatal":true,"severity":2,"message":"110"},{"ruleId":null,"fatal":true,"severity":2,"message":"110"},{"ruleId":null,"fatal":true,"severity":2,"message":"110"},{"ruleId":null,"fatal":true,"severity":2,"message":"110"},{"ruleId":null,"fatal":true,"severity":2,"message":"110"},{"ruleId":null,"fatal":true,"severity":2,"message":"110"},{"ruleId":null,"fatal":true,"severity":2,"message":"110"},{"ruleId":null,"fatal":true,"severity":2,"message":"110"},{"ruleId":null,"fatal":true,"severity":2,"message":"110"},{"ruleId":null,"fatal":true,"severity":2,"message":"110"},{"ruleId":null,"fatal":true,"severity":2,"message":"110"},{"ruleId":null,"fatal":true,"severity":2,"message":"110"},{"ruleId":null,"fatal":true,"severity":2,"message":"110"},{"ruleId":null,"fatal":true,"severity":2,"message":"110"},{"ruleId":null,"fatal":true,"severity":2,"message":"110"},{"ruleId":null,"fatal":true,"severity":2,"message":"110"},"Parsing error: Cannot find module 'babel-eslint'\nRequire stack:\n- /Users/lyh/Desktop/prTemp/web-norm/node_modules/vue-eslint-parser/index.js\n- /Users/lyh/Desktop/prTemp/web-norm/node_modules/eslint-plugin-vue/lib/utils/index.js\n- /Users/lyh/Desktop/prTemp/web-norm/node_modules/eslint-plugin-vue/lib/rules/array-bracket-newline.js\n- /Users/lyh/Desktop/prTemp/web-norm/node_modules/eslint-plugin-vue/lib/index.js\n- /Users/lyh/Desktop/prTemp/web-norm/node_modules/@eslint/eslintrc/dist/eslintrc.cjs"] -------------------------------------------------------------------------------- /src/templet/eslintrc.ts: -------------------------------------------------------------------------------- 1 | import { getEnv } from '../utils/env' 2 | import { teepEslintConfig } from '../especial' 3 | function formatObject(obj: Object) { 4 | const objStr = JSON.stringify(obj, null, 2) 5 | return objStr.slice(1, -1).replace(/"/g, "'") 6 | } 7 | const especialRules = formatObject(teepEslintConfig.rules) 8 | function getBaseEslint(especial: boolean = false) { 9 | return ` 10 | 'prettier/prettier': 'error', 11 | 'accessor-pairs': 2, 12 | 'arrow-spacing': [ 13 | 2, 14 | { 15 | before: true, 16 | after: true 17 | } 18 | ], 19 | 'block-spacing': [2, 'always'], 20 | 'brace-style': [ 21 | 2, 22 | '1tbs', 23 | { 24 | allowSingleLine: true 25 | } 26 | ], 27 | camelcase: [ 28 | 0, 29 | { 30 | properties: 'always' 31 | } 32 | ], 33 | 'comma-dangle': [ 34 | 'error', 35 | { 36 | arrays: 'never', 37 | objects: 'never', 38 | imports: 'never', 39 | exports: 'never', 40 | functions: 'never' 41 | } 42 | ], 43 | 'comma-spacing': [ 44 | 2, 45 | { 46 | before: false, 47 | after: true 48 | } 49 | ], 50 | 'comma-style': [2, 'last'], 51 | 'constructor-super': 2, 52 | curly: [2, 'multi-line'], 53 | 'dot-location': [2, 'property'], 54 | 'eol-last': 2, 55 | eqeqeq: 2, 56 | 'generator-star-spacing': [ 57 | 2, 58 | { 59 | before: true, 60 | after: true 61 | } 62 | ], 63 | 'handle-callback-err': [2, '^(err|error)$'], 64 | indent: 'off', 65 | 'key-spacing': [ 66 | 2, 67 | { 68 | beforeColon: false, 69 | afterColon: true 70 | } 71 | ], 72 | 'keyword-spacing': [ 73 | 2, 74 | { 75 | before: true, 76 | after: true 77 | } 78 | ], 79 | 'new-cap': [ 80 | 2, 81 | { 82 | newIsCap: true, 83 | capIsNew: false 84 | } 85 | ], 86 | 'new-parens': 2, 87 | 'no-array-constructor': 2, 88 | 'no-caller': 2, 89 | 'no-console': 'off', 90 | 'no-class-assign': 2, 91 | 'no-cond-assign': 2, 92 | 'no-const-assign': 2, 93 | 'no-control-regex': 0, 94 | 'no-delete-var': 2, 95 | 'no-dupe-args': 2, 96 | 'no-dupe-class-members': 2, 97 | 'no-dupe-keys': 2, 98 | 'no-duplicate-case': 2, 99 | 'no-empty-character-class': 2, 100 | 'no-empty-pattern': 2, 101 | 'no-eval': 0, 102 | 'no-ex-assign': 2, 103 | 'no-extend-native': 2, 104 | 'no-extra-bind': 2, 105 | 'no-extra-boolean-cast': 2, 106 | 'no-extra-parens': [2, 'functions'], 107 | 'no-fallthrough': 2, 108 | 'no-floating-decimal': 2, 109 | 'no-func-assign': 2, 110 | 'no-implied-eval': 2, 111 | 'no-inner-declarations': [2, 'functions'], 112 | 'no-invalid-regexp': 2, 113 | 'no-irregular-whitespace': 2, 114 | 'no-iterator': 2, 115 | 'no-label-var': 2, 116 | 'no-labels': [ 117 | 2, 118 | { 119 | allowLoop: false, 120 | allowSwitch: false 121 | } 122 | ], 123 | 'no-lone-blocks': 2, 124 | 'no-mixed-spaces-and-tabs': 2, 125 | 'no-multi-spaces': 2, 126 | 'no-multi-str': 2, 127 | 'no-multiple-empty-lines': [ 128 | 2, 129 | { 130 | max: 1 131 | } 132 | ], 133 | 'no-native-reassign': 2, 134 | 'no-negated-in-lhs': 2, 135 | 'no-new-object': 2, 136 | 'no-new-require': 2, 137 | 'no-new-symbol': 2, 138 | 'no-new-wrappers': 2, 139 | 'no-obj-calls': 2, 140 | 'no-octal': 2, 141 | 'no-octal-escape': 2, 142 | 'no-path-concat': 2, 143 | 'no-proto': 2, 144 | 'no-redeclare': 2, 145 | 'no-regex-spaces': 2, 146 | 'no-return-assign': [2, 'except-parens'], 147 | 'no-self-assign': 2, 148 | 'no-self-compare': 2, 149 | 'no-sequences': 2, 150 | 'no-shadow-restricted-names': 2, 151 | 'no-spaced-func': 2, 152 | 'no-sparse-arrays': 2, 153 | 'no-this-before-super': 2, 154 | 'no-throw-literal': 2, 155 | 'no-trailing-spaces': 2, 156 | 'no-undef': 2, 157 | 'no-undef-init': 2, 158 | 'no-unexpected-multiline': 2, 159 | 'no-unmodified-loop-condition': 2, 160 | 'no-unneeded-ternary': [ 161 | 2, 162 | { 163 | defaultAssignment: false 164 | } 165 | ], 166 | 'no-unreachable': 2, 167 | 'no-unsafe-finally': 2, 168 | 'no-unused-vars': [ 169 | 2, 170 | { 171 | vars: 'all', 172 | args: 'none', 173 | varsIgnorePattern: '^_' 174 | } 175 | ], 176 | 'no-useless-call': 2, 177 | 'no-useless-computed-key': 2, 178 | 'no-useless-constructor': 2, 179 | 'no-useless-escape': 0, 180 | 'no-whitespace-before-property': 2, 181 | 'no-with': 2, 182 | 'one-var': [ 183 | 2, 184 | { 185 | initialized: 'never' 186 | } 187 | ], 188 | 'operator-linebreak': [ 189 | 2, 190 | 'after', 191 | { 192 | overrides: { 193 | '?': 'before', 194 | ':': 'before' 195 | } 196 | } 197 | ], 198 | 'padded-blocks': [2, 'never'], 199 | quotes: 'off', 200 | semi: 'off', 201 | 'semi-spacing': [ 202 | 2, 203 | { 204 | before: false, 205 | after: true 206 | } 207 | ], 208 | 'space-before-blocks': [2, 'always'], 209 | 'space-before-function-paren': 'off', 210 | 'space-in-parens': [2, 'never'], 211 | 'space-infix-ops': 2, 212 | 'space-unary-ops': [ 213 | 2, 214 | { 215 | words: true, 216 | nonwords: false 217 | } 218 | ], 219 | 'spaced-comment': 'off', 220 | 'template-curly-spacing': [2, 'never'], 221 | 'use-isnan': 2, 222 | 'valid-typeof': 2, 223 | 'wrap-iife': [2, 'any'], 224 | 'yield-star-spacing': [2, 'both'], 225 | yoda: [2, 'never'], 226 | 'prefer-const': 2, 227 | 'no-debugger': process.env.NODE_ENV === 'production' ? 2 : 0, 228 | 'object-curly-spacing': [ 229 | 0, 230 | 'always', 231 | { 232 | objectsInObjects: false 233 | } 234 | ], 235 | 'array-bracket-spacing': [2, 'never'], 236 | ${especial ? especialRules : ''} 237 | ` 238 | } 239 | 240 | export const eslintrcFn = (especial?: boolean) => { 241 | // 其他 242 | let eslintrcInit = ` 243 | module.exports = { 244 | root: true, 245 | parserOptions: { 246 | ecmaVersion: 11, 247 | parser: 'babel-eslint', 248 | sourceType: 'module', 249 | "ecmaFeatures": { 250 | "legacyDecorators": true 251 | } 252 | }, 253 | env: { 254 | browser: true, 255 | node: true, 256 | es6: true 257 | }, 258 | plugins: ['prettier'], 259 | extends: [ 'eslint:recommended', 'plugin:prettier/recommended'], 260 | rules: { 261 | ${getBaseEslint(especial)} 262 | } 263 | } 264 | 265 | ` 266 | // vue2 267 | if (getEnv('isVue2')) { 268 | eslintrcInit = ` 269 | module.exports = { 270 | root: true, 271 | parserOptions: { 272 | ecmaVersion: 11, 273 | parser: 'babel-eslint', 274 | sourceType: 'module', 275 | "ecmaFeatures": { 276 | "legacyDecorators": true 277 | } 278 | }, 279 | env: { 280 | browser: true, 281 | node: true, 282 | es6: true 283 | }, 284 | plugins: ['prettier'], 285 | extends: ['plugin:vue/recommended', 'eslint:recommended', 'plugin:prettier/recommended'], 286 | rules: { 287 | 'vue/order-in-components': 'off', 288 | 'vue/html-self-closing': 'off', 289 | 'vue/require-default-prop': 'off', 290 | 'vue/max-attributes-per-line': [ 291 | 0, 292 | { 293 | singleline: 10, 294 | multiline: { 295 | max: 1, 296 | allowFirstLine: false 297 | } 298 | } 299 | ], 300 | 'vue/singleline-html-element-content-newline': 'off', 301 | 'vue/multiline-html-element-content-newline': 'off', 302 | 'vue/name-property-casing': ['error', 'PascalCase'], 303 | 'vue/no-v-html': 'off', 304 | ${getBaseEslint(especial)} 305 | } 306 | }` 307 | } 308 | if (getEnv('isVue3')) { 309 | // vue3 310 | eslintrcInit = ` 311 | module.exports = { 312 | root: true, 313 | parserOptions: { 314 | ecmaVersion: 11, 315 | sourceType: 'module', 316 | parser: '@typescript-eslint/parser', 317 | "ecmaFeatures": { 318 | "legacyDecorators": true 319 | } 320 | }, 321 | env: { 322 | browser: true, 323 | node: true, 324 | es6: true 325 | }, 326 | plugins: ['prettier'], 327 | extends: ['plugin:vue/vue3-recommended', 'eslint:recommended', 'plugin:prettier/recommended'], 328 | rules: { 329 | 'vue/order-in-components': 'off', 330 | 'vue/html-self-closing': 'off', 331 | 'vue/require-default-prop': 'off', 332 | 'vue/max-attributes-per-line': [ 333 | 0, 334 | { 335 | singleline: 10, 336 | multiline: { 337 | max: 1, 338 | allowFirstLine: false 339 | } 340 | } 341 | ], 342 | 'vue/singleline-html-element-content-newline': 'off', 343 | 'vue/multiline-html-element-content-newline': 'off', 344 | 'vue/name-property-casing': 'off', 345 | 'vue/no-v-html': 'off', 346 | ${getBaseEslint(especial)} 347 | } 348 | } 349 | ` 350 | } 351 | if (getEnv('isReact')) { 352 | eslintrcInit = ` 353 | module.exports = { 354 | root: true, 355 | parserOptions: { 356 | ecmaVersion: 11, 357 | sourceType: 'module', 358 | parser: '@typescript-eslint/parser', 359 | "ecmaFeatures": { 360 | "legacyDecorators": true 361 | } 362 | }, 363 | env: { 364 | browser: true, 365 | node: true, 366 | es6: true 367 | }, 368 | plugins: ['react', 'prettier', '@typescript-eslint/eslint-plugin', 'jsx-a11y'], 369 | extends: ['plugin:react/recommended', 'plugin:@typescript-eslint/recommended', 'eslint:recommended', 'plugin:prettier/recommended'], 370 | rules: { 371 | 'react/react-in-jsx-scope': 0, 372 | ${getBaseEslint(especial)} 373 | } 374 | } 375 | ` 376 | } 377 | return eslintrcInit 378 | } 379 | --------------------------------------------------------------------------------