Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
SystemLight committed Jul 8, 2022
0 parents commit 61a45a4
Show file tree
Hide file tree
Showing 29 changed files with 9,162 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .browserslistrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
> 0.5%
last 2 versions
Firefox ESR
not dead
5 changes: 5 additions & 0 deletions .commitlintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"extends": [
"@commitlint/config-conventional"
]
}
15 changes: 15 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# EditorConfig is awesome: https://editorconfig.org/

# top-most EditorConfig file
root = true

[*]
indent_style = space
indent_size = 2
end_of_line = crlf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.md]
trim_trailing_whitespace = false
8 changes: 8 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
dist/
build/
node_modules/
public/
scripts/
tests/
plop-templates/
assets/
183 changes: 183 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
const path = require('path')
const fs = require('fs')

// https://eslint.org/docs/user-guide/configuring/
class EslintRecommendConfig {
constructor() {
this.cwd = process.cwd()
this.isTsProject = fs.existsSync(path.resolve(this.cwd, 'tsconfig.json'))
this.packageJSON = require(path.join(this.cwd, 'package.json')) // package.json文件信息对象
this.dependencies = Object.keys({
...this.packageJSON['devDependencies'],
...this.packageJSON['dependencies']
}) // 项目依赖库数组,用于判定包含什么框架
this.config = {}
}

build() {
this.buildBasic()
this.buildParser()
this.buildFormatter()
this.buildPlugin()
this.buildConfig()
this.toConfig()

return this
}

buildBasic() {
this.config.root = true
this.config.env = {
browser: true,
es2022: true,
node: true
}
this.config.settings = {}
this.config.extends = [
'eslint:recommended'
]

if (this.isTsProject) {
this.config.extends.push(
'plugin:@typescript-eslint/recommended' // @typescript-eslint/eslint-plugin
)
}

if (this.dependencies.includes('react')) {
this.config.settings.react = {
version: 'detect'
}

this.config.extends.push(
'plugin:react/recommended', // eslint-plugin-react
'plugin:react-hooks/recommended' // eslint-plugin-react-hooks
)
}

return this
}

buildParser() {
// ts解析器:https://github.com/typescript-eslint/typescript-eslint/tree/main/packages/parser
// js解析器:https://www.npmjs.com/package/@babel/eslint-parser
if (this.isTsProject) {
this.config.parser = '@typescript-eslint/parser'
this.config.parserOptions = {}
} else {
this.config.parser = '@babel/eslint-parser'
let presets = ['@babel/preset-env']
let plugins = []
if (this.dependencies.includes('react')) {
presets.push('@babel/preset-react')
}
if (this.dependencies.includes('@babel/plugin-proposal-decorators')) {
plugins.push(
// 装饰器属性,https://babel.dev/docs/en/babel-plugin-proposal-decorators
[
'@babel/plugin-proposal-decorators',
{
legacy: true
}
]
)
}
this.config.parserOptions = {
requireConfigFile: false,
babelOptions: {
presets: presets,
plugins: plugins
}
}
}

Object.assign(this.config.parserOptions, {
sourceType: 'module',
ecmaVersion: 2022
})

return this
}

buildFormatter() {
return this
}

buildPlugin() {
return this
}

buildConfig() {
this.config.rules = {
'require-jsdoc': 'off',
'no-control-regex': 'off',
'no-invalid-this': 'off',
'linebreak-style': 'off',
'max-len': 'off',
'no-unused-vars': 'off',
'quotes': [
'error',
'single'
],
'semi': [
'error',
'never'
],
'arrow-parens': [
'error',
'always'
],
'comma-dangle': [
'error',
{
'arrays': 'never',
'objects': 'never',
'imports': 'never',
'exports': 'never',
'functions': 'never'
}
],
'indent': [
'error',
2,
{
'SwitchCase': 1
}
],
'padded-blocks': [
'error',
'never'
],
'space-before-function-paren': [
'error',
{
'asyncArrow': 'always',
'anonymous': 'always',
'named': 'never'
}
],
'no-multiple-empty-lines': [
'error',
{
'max': 1
}
]
}

if (this.isTsProject) {
Object.assign(this.config.rules, {
'@typescript-eslint/no-non-null-assertion': 'off',
'@typescript-eslint/no-var-requires': 'off'
})
}
return this
}

toConfig(debug) {
if (debug) {
console.log(this.config)
}
return this.config
}
}

module.exports = new EslintRecommendConfig().build().toConfig()
116 changes: 116 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
# See https://github.com/github/gitignore for more about ignoring files.

# IDE content
.idea/
.vscode/

# Special content
build/

# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage
*.lcov

# nyc test coverage
.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# TypeScript v1 declaration files
typings/

# TypeScript cache
*.tsbuildinfo

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env
.env.test

# parcel-bundler cache (https://parceljs.org/)
.cache

# Next.js build output
.next

# Nuxt.js build / generate output
.nuxt
dist

# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and not Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public

# vuepress build output
.vuepress/dist

# Serverless directories
.serverless/

# FuseBox cache
.fusebox/

# DynamoDB Local files
.dynamodb/

# TernJS port file
.tern-port

# Stores VSCode versions used for testing VSCode extensions
.vscode-test
28 changes: 28 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
dist/
build/
public/
assets/

*.svg
*.png
*.jpg

*.css
*.scss
*.less

*.toml
*.md
*.html
*.ejs

.DS_Store
.gitignore
.prettierignore
.eslintcache
.eslintignore
.editorconfig
.dockerignore
LICENSE
package.json
yarn-error.log
Loading

0 comments on commit 61a45a4

Please sign in to comment.