Skip to content

Commit

Permalink
feat: add mlz-lint
Browse files Browse the repository at this point in the history
  • Loading branch information
wangzhen committed Feb 21, 2020
1 parent 7f3aea0 commit b93befa
Show file tree
Hide file tree
Showing 17 changed files with 3,307 additions and 561 deletions.
7 changes: 7 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// .eslintrc.js
module.exports = {
"extends": "./node_modules/@mlz/lint/ts-eslintrc.js",
"rules": {
// 自定义
}
}
3 changes: 3 additions & 0 deletions commitlint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
extends: ['@commitlint/config-conventional'],
};
54 changes: 27 additions & 27 deletions examples/index.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,26 @@
import Http from "../src/index";
const token = "xxxxx";
/* eslint-disable @typescript-eslint/camelcase */
import Http from '../src/index';
const token = 'xxxxx';
const type = 3;

// Http.setAuthorizationTypeOrToken("authorization_type", type, "Authorization", token);
Http.setReqInterceptor(
config => {
config.headers.Authorization = "xxxx_token";
(config) => {
config.headers.Authorization = 'xxxx_token';
config.headers.authorization_type = 4;
return config;
},
err => {
return Promise.reject(err);
},
"https://xxx-xxx-xxxx-xxxxx.xxxx.xx"
(err) => Promise.reject(err),
'https://xxx-xxx-xxxx-xxxxx.xxxx.xx',
);

Http.setReqInterceptor(
config => {
(config) => {
config.headers.Authorization = token;
config.headers.authorization_type = 3;
return config;
},
err => {
return Promise.reject(err);
}
(err) => Promise.reject(err),
);

console.log('INSTANCES_REQUEST_INTERCEPTORS', Http.INSTANCES_REQUEST_INTERCEPTORS);
Expand All @@ -50,38 +47,41 @@ console.log('GLOBAL_REQUEST_INTERCEPTORS', Http.GLOBAL_REQUEST_INTERCEPTORS);

console.log(Http.INSTANCES_RESPONSE_INTERCEPTORS);

const httpIns = new Http("https://xxx-xxx.xxx.xx");
const httpIns2 = new Http("https://xxx-xxx-xxxx-xxxxx.xxxx.xx");
const httpIns3 = new Http("https://xxx-xxx-xxxx-xxxxx.xxxx.xx");
const httpIns = new Http('https://xxx-xxx.xxx.xx');
const httpIns2 = new Http('https://xxx-xxx-xxxx-xxxxx.xxxx.xx');
const httpIns3 = new Http('https://xxx-xxx-xxxx-xxxxx.xxxx.xx');

httpIns
.post("/xxx/xxx/xxx/xxx", {
amount: "1",
student_id: "1000824602",
ticket_type: "101"
.post('/xxx/xxx/xxx/xxx', {
amount: '1',
student_id: '1000824602',
ticket_type: '101',
})
.then(res => {})
.catch(err => {
// eslint-disable-next-line @typescript-eslint/no-empty-function
.then((res) => {})
.catch((err) => {
console.log(err);
});

// httpIns2.setInstancesAuthorizationTypeOrToken("type", 4, "token", "Bearer");

// eslint-disable-next-line promise/catch-or-return
httpIns2
.get("/xxxx/xxxx/xxx/xxx/xxx", { params: { card_type: 4 } })
.then(res => {});
.get('/xxxx/xxxx/xxx/xxx/xxx', { params: { card_type: 4 } })
// eslint-disable-next-line @typescript-eslint/no-empty-function
.then((res) => {});

// httpIns3.setInstancesAuthorizationTypeOrToken("type", 1, "token", "xxx");
httpIns3
.get("/xxx/xxx")
.then(res => {
.get('/xxx/xxx')
.then((res) => {
console.log('res: ', res);
if (/^2/.test(res.status)) {
console.log("object");
console.log('object');
} else {
console.log(res.data.error_code);
}
})
.catch(err => {
.catch((err) => {
console.log(err);
});
62 changes: 31 additions & 31 deletions examples/server.js
Original file line number Diff line number Diff line change
@@ -1,56 +1,56 @@
const express = require('express')
const bodyParser = require('body-parser')
const cookieParser = require('cookie-parser')
const webpack = require('webpack')
const webpackDevMiddleware = require('webpack-dev-middleware')
const webpackHotMiddleware = require('webpack-hot-middleware')
const WebpackConfig = require('./webpack.config')
const express = require('express');
const bodyParser = require('body-parser');
const cookieParser = require('cookie-parser');
const webpack = require('webpack');
const webpackDevMiddleware = require('webpack-dev-middleware');
const webpackHotMiddleware = require('webpack-hot-middleware');
const WebpackConfig = require('./webpack.config');

const app = express()
const compiler = webpack(WebpackConfig)
const app = express();
const compiler = webpack(WebpackConfig);

app.use(webpackDevMiddleware(compiler, {
publicPath: '/__build__/',
stats: {
colors: true,
chunks: false
}
}))
chunks: false,
},
}));

app.use(webpackHotMiddleware(compiler))
app.use(webpackHotMiddleware(compiler));

app.use(express.static(__dirname, {
setHeaders (res) {
res.cookie('XSRF-TOKEN-D', '1234abc')
}
}))
setHeaders(res) {
res.cookie('XSRF-TOKEN-D', '1234abc');
},
}));

app.use(bodyParser.json())
app.use(bodyParser.urlencoded({ extended: true }))
app.use(cookieParser())
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(cookieParser());


const router = express.Router()
const router = express.Router();

router.get('/error/timeout', function(req, res) {
setTimeout(() => {
res.json({
msg: `hello world`
})
}, 6000)
})
msg: 'hello world',
});
}, 6000);
});

router.post('/base/post', function(req, res) {
res.json(req.body)
})
res.json(req.body);
});


app.use(router)
app.use(router);

const port = process.env.PORT || 8080
const port = process.env.PORT || 8080;
module.exports = app.listen(port, () => {
console.log(`Server listening on http://localhost:${port}, Ctrl+C to stop`)
})
console.log(`Server listening on http://localhost:${port}, Ctrl+C to stop`);
});



Expand Down
32 changes: 16 additions & 16 deletions examples/webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
const path = require('path')
const webpack = require('webpack')
const path = require('path');
const webpack = require('webpack');

module.exports = {
mode: 'development',

entry: {
index: ['webpack-hot-middleware/client', path.join(__dirname, './index.js')]
index: ['webpack-hot-middleware/client', path.join(__dirname, './index.js')],
},

/**
Expand All @@ -14,7 +14,7 @@ module.exports = {
output: {
path: path.join(__dirname, '__build__'),
filename: '[name].js',
publicPath: '/__build__/'
publicPath: '/__build__/',
},

module: {
Expand All @@ -34,26 +34,26 @@ module.exports = {
{
loader: 'ts-loader',
options: {
transpileOnly: true
}
}
]
transpileOnly: true,
},
},
],
},
{
test: /\.css$/,
use: [
'style-loader', 'css-loader'
]
}
]
'style-loader', 'css-loader',
],
},
],
},

resolve: {
extensions: ['.ts', '.tsx', '.js']
extensions: ['.ts', '.tsx', '.js'],
},

plugins: [
new webpack.HotModuleReplacementPlugin(),
new webpack.NoEmitOnErrorsPlugin()
]
}
new webpack.NoEmitOnErrorsPlugin(),
],
};
Loading

0 comments on commit b93befa

Please sign in to comment.