Skip to content

Commit

Permalink
重构⛑(Post): 重命名为Columns,分离接口
Browse files Browse the repository at this point in the history
- eslintrc重写
- 移除prettier
- update node package
  • Loading branch information
bubao committed Jul 21, 2020
1 parent 6c26022 commit d425429
Show file tree
Hide file tree
Showing 24 changed files with 485 additions and 311 deletions.
90 changes: 51 additions & 39 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,41 +1,53 @@
{
"root": true,
"env": {
"es6": true,
"node": true
},
"extends": [
"standard",
"prettier",
"plugin:node/recommended"
],
"plugins": [
"standard",
"prettier"
],
"rules": {
"prettier/prettier": "error",
"semi": [
2,
"always"
],
"quotes": [
2,
"double"
],
"no-multiple-empty-lines": "error",
"no-var": "error",
"no-template-curly-in-string": "off",
"node/no-deprecated-api": "off",
"camelcase": "off",
"no-bitwise": "off",
"no-case-declarations": "off",
"no-new": "off",
"new-cap": "off",
"no-unmodified-loop-condition": "off",
"no-loop-func": "off",
"prefer-promise-reject-errors": "off",
"node/no-unsupported-features/es-syntax": "off",
"standard/no-callback-literal": "off"
}
"root": true,
"env": {
"es6": true,
"node": true
},
"extends": [
"eslint:recommended",
"plugin:node/recommended",
"standard"
],
"plugins": [
"standard"
],
"rules": {
"semi": [
2,
"always"
],
"space-infix-ops": [
"error",
{
"int32Hint": false
}
],
"quotes": [
"error",
"double"
],
"indent": [
"error",
"tab"
],
"no-use-before-define": "error",
"no-tabs": "off",
"no-multiple-empty-lines": "error",
"no-var": "error",
"no-unused-vars": "error",
"no-undef": "error",
"no-template-curly-in-string": "off",
"node/no-deprecated-api": "off",
"camelcase": "off",
"no-bitwise": "off",
"no-case-declarations": "off",
"no-new": "off",
"new-cap": "off",
"no-unmodified-loop-condition": "off",
"no-loop-func": "off",
"prefer-promise-reject-errors": "off",
"node/no-unsupported-features/es-syntax": "off",
"standard/no-callback-literal": "off"
}
}
12 changes: 0 additions & 12 deletions .prettierrc

This file was deleted.

8 changes: 3 additions & 5 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,11 @@
"workbench.colorCustomizations": {
"tab.unfocusedActiveBorder": "#4391c5"
},
// "prettier.trailingComma": "none",
// "prettier.endOfLine": "lf",
// "prettier.semi": true,
// 是否开启eslint检测
"eslint.enable": true,
// 文件保存时是否根据eslint进行格式化
// "eslint.autoFixOnSave": true,
"eslint.run": "onSave",
"eslint.run": "onType",
// "workbench.iconTheme": "material-icon-theme",
// "workbench.colorTheme": "Darcula Theme from IntelliJ",
"files.eol": "\n",
Expand All @@ -19,8 +16,9 @@
// "**/.vscode/**",
"**/node_modules/**"
],
"editor.formatOnSave": false,
"editor.tabSize": 4,
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
}
}
}
18 changes: 10 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
"version": "0.0.1",
"description": "zhihu api",
"main": "index.js",
"scripts": {
"lint": "eslint . --ext .js --fix"
},
"repository": {
"type": "git",
"url": "git+https://github.com/bubao/zhihu-api.git"
Expand Down Expand Up @@ -31,21 +34,17 @@
"commitizen": "^4.0.3",
"cz-customizable": "^6.2.0",
"eslint": "^6.6.0",
"eslint-config-prettier": "^6.7.0",
"eslint-config-standard": "^14.1.0",
"eslint-plugin-import": "^2.18.2",
"eslint-plugin-node": "^10.0.0",
"eslint-plugin-prettier": "^3.1.1",
"eslint-plugin-promise": "^4.2.1",
"eslint-plugin-standard": "^4.0.1",
"husky": "^2.2.0",
"prettier": "^1.17.0",
"pretty-quick": "^1.10.0"
"husky": "^2.2.0"
},
"husky": {
"hooks": {
"pre-commit": "pretty-quick --staged",
"pre-push": "pretty-quick --staged",
"pre-commit": "echo 'husky' && npm run lint",
"pre-push": "echo 'husky' && npm run lint",
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
}
},
Expand All @@ -59,5 +58,8 @@
},
"engines": {
"node": ">=8.3.0"
},
"directories": {
"test": "test"
}
}
}
10 changes: 5 additions & 5 deletions src/api/Base/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
* @author: bubao
* @Date: 2020-07-20 07:30:57
* @LastEditors: bubao
* @LastEditTime: 2020-07-20 08:10:58
* @LastEditTime: 2020-07-21 18:00:10
*/

const { request } = require("../config/commonModules");
const { request } = require("../../config/commonModules");
class Base {
/**
* @description 获取下一组数据
Expand All @@ -15,7 +15,7 @@ class Base {
* @returns
* @memberof Base
*/
async next() {
async next () {
const postsIteams = JSON.parse(
(await request({ ...this.ReqOps, url: this._next })).body
);
Expand All @@ -34,7 +34,7 @@ class Base {
* @returns
* @memberof Base
*/
async all() {
async all () {
let isEnd = false;
const postsList = [];

Expand All @@ -54,7 +54,7 @@ class Base {
* @returns
* @memberof Base
*/
async previous() {
async previous () {
const postsIteams = JSON.parse(
(await request({ ...this.ReqOps, url: this._previous })).body
);
Expand Down
12 changes: 6 additions & 6 deletions src/api/Columns.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const EventEmitter = require("events");
* @extends {EventEmitter}
*/
class Columns extends EventEmitter {
constructor() {
constructor () {
super();
this.instcance = null;
this.api = {
Expand All @@ -37,7 +37,7 @@ class Columns extends EventEmitter {
* @returns this
* @memberof Columns
*/
static init() {
static init () {
if (!this.instcance) {
this.instcance = new this();
}
Expand All @@ -50,7 +50,7 @@ class Columns extends EventEmitter {
* @returns {Promise} 响应结果
* @memberof Columns
*/
info(columnsID) {
info (columnsID) {
return request({
uri: template(this.api.info)({ columnsID }),
gzip: true,
Expand All @@ -64,7 +64,7 @@ class Columns extends EventEmitter {
* @returns {Promise} 响应结果
* @memberof Columns
*/
coauthors(columnsID) {
coauthors (columnsID) {
return request({
uri: template(this.api.info)({ columnsID }),
gzip: true,
Expand All @@ -80,7 +80,7 @@ class Columns extends EventEmitter {
* @returns {Promise} 响应体[]
* @memberof Columns
*/
articlesInfo(columnsID, limit = 20, offset = 0) {
articlesInfo (columnsID, limit = 20, offset = 0) {
const UrlTemplate = template(this.api.articles)({ columnsID });
const uri = getTrueURL(UrlTemplate, { limit, offset });
return request({
Expand All @@ -96,7 +96,7 @@ class Columns extends EventEmitter {
* @returns {Promise} 响应体
* @memberof Columns
*/
async articles(info) {
async articles (info) {
let item;
const posts = [];
while (info.length > 0) {
Expand Down
61 changes: 61 additions & 0 deletions src/api/Columns/Articles.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/**
* @description:
* @author: bubao
* @Date: 2020-07-21 18:21:28
* @LastEditors: bubao
* @LastEditTime: 2020-07-21 20:43:13
*/
const Base = require("../Base");
const API = require("../../config/api/index");
const { info } = require("./single");
/**
* @description 知乎专栏文章
* @author bubao
* @date 2020-07-21
* @class Articles
* @extends {Base}
*/
class Articles extends Base {
/**
*Creates an instance of Articles.
* @author bubao
* @date 2020-07-21
* @param {string} columnsId 专栏id
* @memberof Articles
*/
constructor (columnsId) {
super();
if (columnsId) {
this.init(columnsId);
}
}

/**
* @description 初始化
* @author bubao
* @date 2020-07-21
* @param {string} columnsId
* @memberof Articles
*/
init (columnsId) {
this.ReqOps = {
gzip: true,
url: API.columns.articles({ columnsId })
};
this._next = this.ReqOps.url;
this.columnsId = columnsId;
}

/**
* @description 知乎专栏信息
* @author bubao
* @date 2020-07-21
* @returns
* @memberof Articles
*/
async info () {
return await info(this.columnsId);
}
}

module.exports = Articles;
51 changes: 51 additions & 0 deletions src/api/Columns/Followers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/**
* @description:
* @author: bubao
* @Date: 2020-07-21 18:40:15
* @LastEditors: bubao
* @LastEditTime: 2020-07-21 19:35:50
*/
const Base = require("../Base");
const API = require("../../config/api/index");
// const { request } = require("../../config/commonModules");

/**
* @description 知乎专栏关注者
* @author bubao
* @date 2020-07-21
* @class Followers
* @extends {Base}
*/
class Followers extends Base {
/**
*Creates an instance of Followers.
* @author bubao
* @date 2020-07-21
* @param {string} columnsId 专栏id
* @memberof Articles
*/
constructor (columnsId) {
super();
if (columnsId) {
this.init(columnsId);
}
}

/**
* @description 初始化
* @author bubao
* @date 2020-07-21
* @param {string} columnsId
* @memberof Articles
*/
init (columnsId) {
this.ReqOps = {
gzip: true,
url: API.columns.followers({ columnsId })
};
this._next = this.ReqOps.url;
this.columnsId = columnsId;
}
}

module.exports = Followers;
Loading

0 comments on commit d425429

Please sign in to comment.