Skip to content

Commit

Permalink
feat: initialize
Browse files Browse the repository at this point in the history
  • Loading branch information
mld-njupt committed Jun 19, 2022
0 parents commit 896f683
Show file tree
Hide file tree
Showing 43 changed files with 10,930 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/node_modules
/build
/dist
17 changes: 17 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module.exports = {
env: {
browser: true,
es2021: true,
node: true,
},
extends: ['eslint:recommended', 'plugin:react/recommended', 'plugin:@typescript-eslint/recommended'],
parser: '@typescript-eslint/parser',
parserOptions: {
ecmaFeatures: {
jsx: true,
},
ecmaVersion: 'latest',
sourceType: 'module',
},
plugins: ['react', '@typescript-eslint'],
}
23 changes: 23 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# production
/build

# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local

npm-debug.log*
yarn-debug.log*
yarn-error.log*
4 changes: 4 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

npx esno cli/git/commit/blockCommit.ts
4 changes: 4 additions & 0 deletions .husky/pre-push
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

npx esno cli/git/push/blockPush.ts
3 changes: 3 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/node_modules
/build
/dist
10 changes: 10 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"trailingComma": "all",
"tabWidth": 2,
"semi": false,
"singleQuote": true,
"endOfLine": "lf",
"printWidth": 120,
"bracketSpacing": true,
"arrowParens": "always"
}
44 changes: 44 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"search.exclude": {
"**/node_modules": true,
"dist": true,
"yarn.lock": true
},
"editor.formatOnSave": true,
"[javascript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[javascriptreact]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[typescript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[typescriptreact]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[json]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[html]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[markdown]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[css]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[less]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[scss]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"eslint.validate": ["javascript", "javascriptreact", "typescript", "typescriptreact"],
"typescript.tsdk": "./node_modules/typescript/lib", // 代替 vscode 的 ts 语法智能提示
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
},
"cSpell.words": ["antd"]
}
81 changes: 81 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# 南京邮电大学比赛管理系统前端

## 前置准备

#### 环境

- Node >= 16 (低于 16 版本会有不可预知问题,运行项目前应先升级 node 版本)
- Yarn >= 1 <2 (本项目依赖安装暂时仅支持 yarn, 注意不要使用 yarn2.x)
- VSCode(使用前请安装Eslint和Prettier - Code formatter扩展)

#### 需要掌握的技能

- React 的基本语法, 主要的 hooks
- Ts 基础知识,如基本的变量声明、泛型
- sass 基础知识
- 数据管理Recoil 的基本使用
- 发送网络请求axios的基本使用

## 代码提交

#### commit

本项目中`git commit`命令会被拦截,应使用`yarn commit`进行提交。在根目录执行`yarn commit`根据提示信息填写便可,同时该命令内置了`git add .`命令,因此执行前不再需要手动执行`git add .`(执行一遍也不会出错)。

#### push

同样`git push`命令也会被拦截,需要使用`yarn push`命令进行代码提交。`yarn push`内置了发版流程,根据提示进行操作即可。同时还会在提交代码前将开发分支与远程 master 分支进行合并,保证代码是最新的。

## 代码结构

```
src/
├── api // 用于存放request请求函数
│ ├── index.ts // 一般在/api/index.ts或request.ts中写拦截器和BaseURL等内容,便于管理
│ │ // 建议将token等信息统一在拦截器中插入,避免产生冗余代码
│ └── example2.ts // 其他文件中需从index.ts中import引入BaseURL等全局配置,便于统一管理
├── util // 用于存放工具函数的文件夹
│ ├── example1.ts // 例如时间格式化等函数在项目中可能多次复用,应当写在util文件夹中的代码中并export
│ └── example2.ts
├── components // 用于存放公共组件代码,一般存可复用组件
│ ├── ExampleComponent1 // 组件代码通常以文件夹形式出现,组件名即`组件相关文件(夹)名都应当首字母大写,并以驼峰命名法命名
│ │ ├── index.tsx // 组件代码文件
│ │ ├── index.scss // 组件样式
│ │ └── ChildComponent // 在必要时,可以设置子组件,但是子组件应当只可由文件夹对应的其父组件使用
│ │ ├── index.tsx
│ │ └── index.scss
│ └── ExampleComponent2
│ ├── index.tsx
│ └── index.scss
├── routes // 用于存放路由相关代码
│ ├── example1.ts
│ └── example2.ts
├── test // 用于存放测试代码
│ ├── example1.ts
│ └── example2.ts
├── store // 用于存放存储相关代码,例如Recoil的atom代码应该存放在此并export
│ ├── example1.ts
│ └── example2.ts
├── assets // 用于存放资源文件,例如图片、字体、数据等
│ ├── example1.jpg
│ ├── example1.png
│ └── example2.svg
├── type // 用于存放ts中类型定义
│ ├── example1.ts
│ └── example2.ts
└── pages // 用于存放页面
├── example1
│ ├── index.tsx
│ └── index.scss
└── example2
├── index.tsx
├── index.scss
└── ChildComponent // 在必要时,可以设置页面的子组件,但是页面的子组件应当只可由其对应父级页面使用
├── index.tsx
└── index.scss
```





3 changes: 3 additions & 0 deletions cli/git/commit/blockCommit.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import chalk from 'chalk'
console.log(chalk.red('git commit会被拦截,请使用yarn commit提交代码'))
process.exit(1)
108 changes: 108 additions & 0 deletions cli/git/commit/commitManager.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
import util from 'node:util'
import { exec } from 'node:child_process'
import chalk from 'chalk'
import inquirer from 'inquirer'

const asyncExec = util.promisify(exec)
const { log } = console
const commitData = {
type: '',
scope: '',
subject: '',
}
async function getCommitData() {
const commitPrompList = [
{
type: 'list',
message: chalk.yellow(`请选择一种coomit提交类型:
feat: 添加新功能,
fix: 修复bug,
refactor: 代码重构,
chore: 改变构建流程,新增依赖库、工具、构造工具的或者外部依赖的改动,
docs: 只改动了文档相关的内容,
style: 不影响代码含义的改动,例如去掉空格、改变缩进、增删分号,
perf: 提升性能或者其他和项目有关的优化,
test: 添加测试或者修改现有测试,
ci: 自动化流程配置修改,
misc: 不属于以上任何一个分类
`),
name: 'type',
choices: ['feat', 'fix', 'refactor', 'chore', 'docs', 'style', 'perf', 'test', 'ci', 'misc'],
pageSize: 14,
loop: false,
},
{
type: 'input',
message: chalk.yellow('填写本次commit的影响范围(填写主要受影响的页面或组件等, 可选):'),
name: 'scope',
},
{
type: 'input',
message: chalk.yellow('填写本次commit内容的简要说明(必填):'),
name: 'subject',
validate(val: string) {
if (val === '') {
console.log(chalk.red('\n此项为必填项\n'))
return false
}
if (val.length >= 50) {
console.log(chalk.red('\n提交说明应尽量简短,不能超过50个字符\n'))
return false
}
return true
},
},
]
const { type, scope, subject } = await inquirer.prompt(commitPrompList)
Object.assign(commitData, {
type,
scope,
subject,
})
}
async function formatFiles() {
log(chalk.blue('开始执行代码格式化'))
const { stdout } = await asyncExec('yarn format')
log(stdout)
}
async function lintFiles() {
log(chalk.blue('开始执行eslint校验'))
const { stdout } = await asyncExec('yarn lint')
log(stdout)
}
async function gitAdd() {
try {
const { stdout } = await asyncExec('git add .')
log(stdout)
} catch (error) {
log(chalk.red('git add执行出错,尝试手动执行'))
log(chalk.red(error))
process.exit(1)
}
}
async function gitCommit() {
const { type, subject } = commitData
let { scope } = commitData
if (scope !== '') {
scope = `(${scope})`
}
try {
const { stdout } = await asyncExec(`git commit -m "${type}${scope}: ${subject}" -n`)
log(stdout)
} catch (error) {
log(chalk.red('git commit执行出错'))
log(chalk.red(error))
process.exit(1)
}
}
export default {
prepare: {
getCommitData,
formatFiles,
lintFiles,
},
gitCommand: {
gitAdd,
gitCommit,
},
}
8 changes: 8 additions & 0 deletions cli/git/commit/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import commitManager from './commitManager'
const { getCommitData, formatFiles, lintFiles } = commitManager.prepare
await getCommitData()
await formatFiles()
await lintFiles()
const { gitAdd, gitCommit } = commitManager.gitCommand
await gitAdd()
await gitCommit()
3 changes: 3 additions & 0 deletions cli/git/push/blockPush.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import chalk from 'chalk'
console.log(chalk.red('git push会被拦截,请使用yarn push提交代码'))
process.exit(1)
7 changes: 7 additions & 0 deletions cli/git/push/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import pushManager from './pushManager'
const { getBranch, mergeLatestMaster } = pushManager.prepare
await getBranch()
await mergeLatestMaster()

const { gitPush } = pushManager.gitCommand
await gitPush()
Loading

0 comments on commit 896f683

Please sign in to comment.