Skip to content

Commit

Permalink
chore: feat code lint
Browse files Browse the repository at this point in the history
  • Loading branch information
lzxb committed May 16, 2020
1 parent 6c5ff00 commit dcc5ebe
Show file tree
Hide file tree
Showing 23 changed files with 2,957 additions and 255 deletions.
16 changes: 16 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# http://editorconfig.org
root = true

[*]
#缩进风格:空格
indent_style = space
#缩进大小
indent_size = 4
#换行符lf
end_of_line = lf
#字符集utf-8
charset = utf-8
#是否删除行尾的空格
trim_trailing_whitespace = true
#是否在文件的最后插入一个空行
insert_final_newline = true
3 changes: 3 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
dist/**
node_modules/**
dist/**
5 changes: 5 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
extends: [
require.resolve('@fmfe/genesis-lint')
]
}
7 changes: 7 additions & 0 deletions .stylelintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
*.json
*.js
*.ts
*.png
*.eot
*.ttf
*.woff
10 changes: 10 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
// 使用项目配置规则
"eslint.options": {
"configFile": "./.eslintrc.js"
},
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true,
"source.fixAll.stylelint": true
},
}
2 changes: 1 addition & 1 deletion genesis.build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ const start = () => {
*/
return build.start();
};
start();
start();
2 changes: 1 addition & 1 deletion genesis.dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ const start = async () => {
*/
startApp(renderer);
};
start();
start();
2 changes: 1 addition & 1 deletion genesis.prod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ app.use(
/**
* 启动应用
*/
startApp(renderer);
startApp(renderer);
63 changes: 33 additions & 30 deletions mock/mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import express from 'express';
import bodyParser from 'body-parser';
import cookieParser from 'cookie-parser';


export interface BlogItem {
author: string;
content: string;
Expand Down Expand Up @@ -35,7 +34,7 @@ export const initMock = (app: express.Application) => {
* 发表微博
*/
app.post('/api/blog', bodyParser.json(), (req, res, next) => {
const { author, content, } = req.body;
const { author, content } = req.body;
if (typeof author !== 'string' || typeof content !== 'string') {
return res.json({
success: false,
Expand All @@ -48,46 +47,50 @@ export const initMock = (app: express.Application) => {
content,
createTime: Date.now()
});
res.json({ success: true })
})
res.json({ success: true });
});

/**
* 用户登录
*/
app.post('/api/signin', cookieParser(), bodyParser.json(), (req, res, next) => {
const { name } = req.body;
if (typeof name !== 'string' || !name) {
return res.json({
success: false,
message: '用户登录名错误'
app.post(
'/api/signin',
cookieParser(),
bodyParser.json(),
(req, res, next) => {
const { name } = req.body;
if (typeof name !== 'string' || !name) {
return res.json({
success: false,
message: '用户登录名错误'
});
}
/**
* 保存用户的昵称
*/
res.cookie('name', name, {
httpOnly: false,
path: '/'
});
res.json({
success: true,
data: {
ok: true
}
});
}
/**
* 保存用户的昵称
*/
res.cookie('name', name, {
httpOnly: false,
path: '/'
});
res.json({
success: true,
data: {
ok: true
}
});
});
);
/**
* 用户退出
*/
app.post('/api/signout', cookieParser(), (req, res, next) => {

res.clearCookie('name');
res.json({
success: true,
data: {
ok: true
}
})
});
});
/**
* 获取用户昵称
Expand All @@ -98,13 +101,13 @@ export const initMock = (app: express.Application) => {
return res.json({
success: false,
message: '请先登录'
})
});
}
res.json({
success: true,
data: {
name
}
})
})
}
});
});
};
82 changes: 53 additions & 29 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,31 +1,55 @@
{
"name": "vue-demo",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"dev": "ts-node genesis.dev -p=tsconfig.json",
"build": "rm -rf dist && NODE_ENV=production ts-node genesis.build -p=tsconfig.json",
"start": "NODE_ENV=production ts-node genesis.prod -p=tsconfig.json"
},
"author": "",
"license": "MIT",
"devDependencies": {
"@fmfe/genesis-compiler": "^0.0.56",
"@types/express": "^4.17.6",
"@types/node": "^14.0.1",
"ts-node": "^8.10.1"
},
"dependencies": {
"@fmfe/genesis-app": "^0.0.56",
"@fmfe/genesis-core": "^0.0.56",
"axios": "^0.19.2",
"body-parser": "^1.19.0",
"cookie-parser": "^1.4.5",
"express": "^4.17.1",
"vue-meta": "^2.3.3",
"vue-property-decorator": "^8.4.2",
"vue-router": "^3.1.6",
"vuex": "^3.4.0"
}
"name": "vue-demo",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"dev": "ts-node genesis.dev -p=tsconfig.json",
"build": "rm -rf dist && NODE_ENV=production ts-node genesis.build -p=tsconfig.json",
"start": "NODE_ENV=production ts-node genesis.prod -p=tsconfig.json",
"lint": "npm run lint:js && npm run lint:css",
"lint:js": "eslint . --ext .js,.ts,.vue --fix",
"lint:css": "stylelint . --syntax less --fix --ignore-path ./.stylelintignore | stylelint . --custom-syntax postcss-html --fix"
},
"author": "",
"license": "MIT",
"devDependencies": {
"@fmfe/genesis-compiler": "^0.0.56",
"@fmfe/genesis-lint": "^0.0.56",
"@types/express": "^4.17.6",
"@types/node": "^14.0.1",
"ts-node": "^8.10.1"
},
"dependencies": {
"@fmfe/genesis-app": "^0.0.56",
"@fmfe/genesis-core": "^0.0.56",
"axios": "^0.19.2",
"body-parser": "^1.19.0",
"cookie-parser": "^1.4.5",
"express": "^4.17.1",
"vue-meta": "^2.3.3",
"vue-property-decorator": "^8.4.2",
"vue-router": "^3.1.6",
"vuex": "^3.4.0"
},
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
},
"lint-staged": {
"*.{ts,js}": [
"eslint --ext .js,.ts --fix",
"git add"
],
"*.{css,less}": [
"stylelint --syntax less --fix",
"git add"
],
"*.{vue}": [
"eslint --ext .js,.ts --fix",
"stylelint --custom-syntax postcss-html --fix",
"git add"
]
}
}
24 changes: 12 additions & 12 deletions src/base-vue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,31 @@ export class BaseVue extends Vue {
/**
* 获取 store 状态
*/
public get state () {
public get state() {
return this.$store.state as State;
}
/**
* 获取请求对象
*/
public get request () {
public get request() {
return this.$root.$options.request!;
}
/**
* 登录用户
*/
public signin (name: string) {
this.$store.commit('signin', name)
public signin(name: string) {
this.$store.commit('signin', name);
}
/**
* 退出登录
*/
public signout () {
this.$store.commit('signin', '')
public signout() {
this.$store.commit('signin', '');
}
/**
* 获取微博列表数据
*/
public async getBlogList () {
public async getBlogList() {
const res = await this.request.get('/api/blog/list');
if (res.success) {
this.$store.commit('getBlogList', res.data.list);
Expand All @@ -38,7 +38,7 @@ export class BaseVue extends Vue {
/**
* 发表微博
*/
public async postBlog (content: string) {
public async postBlog(content: string) {
const res = await this.request.post('/api/blog', {
author: this.state.user.name,
content
Expand All @@ -47,16 +47,16 @@ export class BaseVue extends Vue {
this.getBlogList(); // 发表成功后,重新获取微博数据
return true;
}
alert('发表失败');
return false;
alert('发表失败');
return false;
}
/**
* 获取当前用户登录信息
*/
public async getCurrentUser () {
public async getCurrentUser() {
const res = await this.request.get('/api/current-user');
if (res.success) {
return this.signin(res.data.name);
}
}
}
}
14 changes: 6 additions & 8 deletions src/components/v-header.vue
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
<template>
<header class="header">
<h2 class="title" v-if="title">{{title}}</h2>
<h2 v-if="title" class="title">{{ title }}</h2>
</header>
</template>
<script lang="ts">
import Vue from 'vue'
import Vue from 'vue';
import { Component, Prop } from 'vue-property-decorator';
@Component<VHeader>({
})
@Component<VHeader>({})
export default class VHeader extends Vue {
@Prop({
type: String,
Expand All @@ -25,8 +23,8 @@ export default class VHeader extends Vue {
border-bottom: 1px solid #ccc;
}
.title {
text-align: center;
font-size: 18px;
margin: 0;
font-size: 18px;
text-align: center;
}
</style>
</style>
2 changes: 1 addition & 1 deletion src/entry-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ import { createRequest } from './request/request';

Vue.use(Meta);

export { App, createStore, createRouter, createRequest }
export { App, createStore, createRouter, createRequest };
4 changes: 2 additions & 2 deletions src/entry-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export default async (clientOptions: ClientOptions): Promise<Vue> => {
*/
clientOptions,
/**
* new Vue({ ...vueOptions })
* new Vue({ ...vueOptions })
*/
vueOptions: {
/**
Expand All @@ -44,5 +44,5 @@ export default async (clientOptions: ClientOptions): Promise<Vue> => {
*/
request
}
})
});
};
Loading

0 comments on commit dcc5ebe

Please sign in to comment.