Skip to content

Commit

Permalink
publish version 0.7.1;
Browse files Browse the repository at this point in the history
delete and move some comments and TODOs;
  • Loading branch information
Bin-Huang committed Aug 2, 2017
1 parent fcf6d4a commit 05a324f
Show file tree
Hide file tree
Showing 12 changed files with 19 additions and 22 deletions.
2 changes: 1 addition & 1 deletion TODO
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
- document in English
- share package in some nodejs's bbs
- website? www.nodespider.org

- 设计考虑:plan管理中,使用class继承的方式替代type?对不同class的plan进行任务管理,往往就能解决不同种类任务的管理问题
- 考虑使用 add 代替 pipe 和 plan
1 change: 0 additions & 1 deletion build/defaultPlan.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ const preToUtf8_1 = require("./preToUtf8");
* 默认值 type: "default", info: {}, option: {request: {encoding: null}, pre: [preToUtf8(), preLoadJq()], callback }
* @param planOptionInput
*/
// TODO C 考虑是否使用类继承的方式,代替type
function defaultPlan(planOptionInput) {
// 当只传入一个rule函数,则包装成 IPlanInput 对象
if (typeof planOptionInput === "function") {
Expand Down
2 changes: 1 addition & 1 deletion build/downloadPlan.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
const fs = require("fs-extra");
const path = require("path");
const request = require("request");
// TODO B
// TODO B 完成pipe发生函数
function downloadPlan(opts) {
// TODO B 参数检验与默认赋值
const planOption = opts;
Expand Down
4 changes: 2 additions & 2 deletions build/pipe.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ class TxtTable {
* @param {Object} data
*/
add(data) {
// TODO: 参数检测
let chunk = "";
// 按顺序写入符合关键字段的数据,不存在于关键字列表的数据将被无视
for (const item of this.header) {
if (chunk !== "") {
chunk += "\t";
Expand Down Expand Up @@ -120,7 +120,7 @@ class CsvPipe {
* @param {Object} data
*/
add(data) {
// TODO: 参数检测
// 按顺序写入符合关键字段的数据,不存在于关键字列表的数据将被无视
let chunk = "";
for (const item of this.header) {
if (chunk !== "") {
Expand Down
8 changes: 4 additions & 4 deletions build/spider.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
// redis queue
// TODO B 注册pipe和queue可能存在异步操作,此时应该封装到promise或async函数。但依然存在问题:当还没注册好,就调动了queue或者save
// TODO C 更良好的报错提示
// TODO C handleError
Object.defineProperty(exports, "__esModule", { value: true });
const events_1 = require("events");
const uuid = require("uuid/v1");
Expand Down Expand Up @@ -298,8 +297,9 @@ function timerCallbackWhenMaxIsNumber(self) {
}
else {
if (self._STATE.currentTotalConnections === 0) {
// TODO C 爬虫工作全部完成
// 当所有连接已经结束,将开始执行结束
// TODO C 更好的事件名
self.emit("done"); // 爬虫工作全部结束,进入 end 阶段
}
}
}
Expand Down Expand Up @@ -327,8 +327,8 @@ function timerCallbackWhenMaxIsObject(self) {
}
else {
if (self._STATE.currentTotalConnections === 0) {
// TODO C 爬虫工作全部完成
// 当所有连接已经结束,将开始执行结束
// TODO C 更好的事件名
self.emit("done"); // 爬虫工作全部结束,进入 end 阶段
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nodespider",
"version": "0.7.0",
"version": "0.7.1",
"description": "Simple, flexible, delightful web crawler/spider package",
"main": "./build/index.js",
"typings": "./build/index.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion src/defaultPlan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export interface ICurrent extends ITask {
* 默认值 type: "default", info: {}, option: {request: {encoding: null}, pre: [preToUtf8(), preLoadJq()], callback }
* @param planOptionInput
*/
// TODO C 考虑是否使用类继承的方式,代替type

export default function defaultPlan(planOptionInput: IDefaultPlanOptionCallback|IDefaultPlanOptionInput): IPlan {
// 当只传入一个rule函数,则包装成 IPlanInput 对象
if (typeof planOptionInput === "function") {
Expand Down
2 changes: 1 addition & 1 deletion src/downloadPlan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as request from "request";
import NodeSpider from "./spider";
import { IPlan, ITask } from "./types";

// TODO B
// TODO B 完成pipe发生函数
export default function downloadPlan(opts) {
// TODO B 参数检验与默认赋值
const planOption = opts;
Expand Down
5 changes: 2 additions & 3 deletions src/pipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ class TxtTable {
* @param {Object} data
*/
public add(data: any) {
// TODO: 参数检测
let chunk = "";
// 按顺序写入符合关键字段的数据,不存在于关键字列表的数据将被无视
for (const item of this.header) {
if (chunk !== "") {
chunk += "\t";
Expand Down Expand Up @@ -144,8 +144,7 @@ class CsvPipe {
* @param {Object} data
*/
public add(data: any) {
// TODO: 参数检测

// 按顺序写入符合关键字段的数据,不存在于关键字列表的数据将被无视
let chunk = "";
for (const item of this.header) {
if (chunk !== "") {
Expand Down
4 changes: 2 additions & 2 deletions src/preLoadJq.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function loadJqOperation(error: Error, currentTask: ICurrent) {
// 自动处理了锚和 javascript: void(0)
// TODO B 存在不合法链接的返回
$.prototype.url = function() {
const result = [];
const result: string[] = [];
$(this).each(function() {
let newUrl = $(this).attr("href");
// 如果为空,或是类似 'javascirpt: void(0)' 的 js 代码,直接跳过
Expand All @@ -47,7 +47,7 @@ function loadJqOperation(error: Error, currentTask: ICurrent) {
* @returns {array}
*/
$.prototype.src = function() {
const result = [];
const result: string[] = [];
$(this).each(function() {
let newUrl = $(this).attr("src");
// 如果是相对路径,补全路径为绝对路径
Expand Down
8 changes: 4 additions & 4 deletions src/spider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
// redis queue
// TODO B 注册pipe和queue可能存在异步操作,此时应该封装到promise或async函数。但依然存在问题:当还没注册好,就调动了queue或者save
// TODO C 更良好的报错提示
// TODO C handleError

import * as charset from "charset";
import * as cheerio from "cheerio";
Expand Down Expand Up @@ -354,8 +353,9 @@ function timerCallbackWhenMaxIsNumber(self: NodeSpider) {
startTask(type, task, self);
} else {
if (self._STATE.currentTotalConnections === 0) {
// TODO C 爬虫工作全部完成
// 当所有连接已经结束,将开始执行结束
// TODO C 更好的事件名
self.emit("done"); // 爬虫工作全部结束,进入 end 阶段
}
}
}
Expand Down Expand Up @@ -386,8 +386,8 @@ function timerCallbackWhenMaxIsObject(self: NodeSpider) {
startTask(type, task, self);
} else {
if (self._STATE.currentTotalConnections === 0) {
// TODO C 爬虫工作全部完成
// 当所有连接已经结束,将开始执行结束
// TODO C 更好的事件名
self.emit("done"); // 爬虫工作全部结束,进入 end 阶段
}
}
}
Expand Down
1 change: 0 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ export interface ITask {
}

// ====== request options ======

export interface IRequestOpts {

}
Expand Down

0 comments on commit 05a324f

Please sign in to comment.