From 89926fa00219e3af0202e121c0159b8d357f1d01 Mon Sep 17 00:00:00 2001 From: Jackson Tian Date: Mon, 21 Nov 2016 11:24:52 +0800 Subject: [PATCH 1/4] Use eslint instead of jshint --- .eslintignore | 3 +++ .eslintrc | 46 ++++++++++++++++++++++++++++++++++++++++++++++ .jshintrc | 43 ------------------------------------------- 3 files changed, 49 insertions(+), 43 deletions(-) create mode 100644 .eslintignore create mode 100644 .eslintrc delete mode 100644 .jshintrc diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 0000000..a146beb --- /dev/null +++ b/.eslintignore @@ -0,0 +1,3 @@ +*.debug.js +*.min.js +node_modules/* diff --git a/.eslintrc b/.eslintrc new file mode 100644 index 0000000..3bd89b8 --- /dev/null +++ b/.eslintrc @@ -0,0 +1,46 @@ +{ + "rules": { + "indent": [2, 2], + "quotes": [2, "single"], + "linebreak-style": [2, "unix"], + "semi": [2, "always"], + "strict": [2, "global"], + "curly": 2, + "eqeqeq": 2, + "no-eval": 2, + "guard-for-in": 2, + "no-caller": 2, + "no-else-return": 2, + "no-eq-null": 2, + "no-extend-native": 2, + "no-extra-bind": 2, + "no-floating-decimal": 2, + "no-implied-eval": 2, + "no-labels": 2, + "no-with": 2, + "no-loop-func": 1, + "no-native-reassign": 2, + "no-redeclare": [2, {"builtinGlobals": true}], + "no-delete-var": 2, + "no-shadow-restricted-names": 2, + "no-undef-init": 2, + "no-use-before-define": 2, + "no-unused-vars": [2, {"args": "none"}], + "no-undef": 2, + "callback-return": [2, ["callback", "cb", "next"]], + "global-require": 0, + "no-console": 0 + }, + "env": { + "es6": true, + "node": true, + "browser": true + }, + "globals": { + "describe": true, + "it": true, + "before": true, + "after": true + }, + "extends": "eslint:recommended" +} diff --git a/.jshintrc b/.jshintrc deleted file mode 100644 index 576562c..0000000 --- a/.jshintrc +++ /dev/null @@ -1,43 +0,0 @@ -{ - "predef": [ - "document", - "module", - "require", - "__dirname", - "process", - "console", - "it", - "xit", - "describe", - "xdescribe", - "before", - "beforeEach", - "after", - "afterEach" - ], - - "node": true, - "es5": true, - "esnext": true, - "bitwise": true, - "curly": true, - "eqeqeq": true, - "forin": false, - "immed": true, - "latedef": true, - "noarg": true, - "noempty": true, - "nonew": true, - "plusplus": false, - "undef": true, - "strict": false, - "trailing": false, - "globalstrict": true, - "nonstandard": true, - "white": false, - "indent": 2, - "expr": true, - "multistr": true, - "onevar": false, - "unused": "vars" -} From b78ea5b8161665150164b0482720a46b0d54c4d6 Mon Sep 17 00:00:00 2001 From: Jackson Tian Date: Mon, 21 Nov 2016 12:20:22 +0800 Subject: [PATCH 2/4] Update node versions for traivs --- .travis.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 1bfa964..6994c99 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,6 @@ language: node_js node_js: - - "0.11" + - "4" + - "6" + - "7" script: make test-coveralls From ba317eb4834fbcf5ebe08e0fb4f24575330167b7 Mon Sep 17 00:00:00 2001 From: Jackson Tian Date: Mon, 21 Nov 2016 12:25:45 +0800 Subject: [PATCH 3/4] refine Makefile --- Makefile | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/Makefile b/Makefile index f51eec9..207e727 100644 --- a/Makefile +++ b/Makefile @@ -1,24 +1,21 @@ TESTS = test/*.js REPORTER = spec TIMEOUT = 20000 -ISTANBUL = ./node_modules/.bin/istanbul +PATH := ./node_modules/.bin:$(PATH) MOCHA = ./node_modules/mocha/bin/_mocha COVERALLS = ./node_modules/coveralls/bin/coveralls.js test: - @NODE_ENV=test node --harmony \ - $(MOCHA) -R $(REPORTER) -t $(TIMEOUT) \ - $(MOCHA_OPTS) \ - --harmony \ - $(TESTS) + NODE_ENV=test mocha -R $(REPORTER) -t $(TIMEOUT) \ + $(MOCHA_OPTS) $(TESTS) test-cov: - @NODE_ENV=test node --harmony \ - $(ISTANBUL) cover --report html $(MOCHA) -- -t $(TIMEOUT) -R spec $(TESTS) + @NODE_ENV=test \ + istanbul cover --report html $(MOCHA) -- -t $(TIMEOUT) -R spec $(TESTS) test-coveralls: - @NODE_ENV=test node --harmony \ - $(ISTANBUL) cover --report lcovonly $(MOCHA) -- -t $(TIMEOUT) -R spec $(TESTS) + @NODE_ENV=test \ + istanbul cover --report lcovonly $(MOCHA) -- -t $(TIMEOUT) -R spec $(TESTS) @echo TRAVIS_JOB_ID $(TRAVIS_JOB_ID) @cat ./coverage/lcov.info | $(COVERALLS) && rm -rf ./coverage From 21f6d20032391761b860cd40798c5cc944ee2004 Mon Sep 17 00:00:00 2001 From: Jackson Tian Date: Mon, 21 Nov 2016 12:28:34 +0800 Subject: [PATCH 4/4] refine project --- index.js | 3 --- lib/wechat.js | 9 +++++---- package.json | 11 +++++++---- 3 files changed, 12 insertions(+), 11 deletions(-) delete mode 100644 index.js diff --git a/index.js b/index.js deleted file mode 100644 index b76f6ca..0000000 --- a/index.js +++ /dev/null @@ -1,3 +0,0 @@ -var wechat = require('./lib/wechat'); - -module.exports = wechat; diff --git a/lib/wechat.js b/lib/wechat.js index 4b904a4..5eb4fbe 100644 --- a/lib/wechat.js +++ b/lib/wechat.js @@ -1,3 +1,5 @@ +'use strict'; + var getRawBody = require('raw-body'); var xml2js = require('xml2js'); var crypto = require('crypto'); @@ -19,7 +21,7 @@ wechat.prototype.setToken = function (config) { this.appid = config.appid || ''; this.encodingAESKey = config.encodingAESKey || ''; } else { - throw new Error('please check your config'); + throw new TypeError('please check your config'); } }; @@ -55,9 +57,8 @@ var formatMessage = function (result) { message[key] = (val || '').trim(); } } else { - message[key] = []; - result[key].forEach(function (item) { - message[key].push(formatMessage(item)); + message[key] = result[key].map(function (item) { + return formatMessage(item); }); } } diff --git a/package.json b/package.json index 2e73bcc..eb485aa 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "co-wechat", "version": "0.0.4", "description": "wechat api for co", - "main": "index.js", + "main": "lib/wechat.js", "scripts": { "test": "make test-all" }, @@ -27,13 +27,16 @@ "mocha": "*", "should": "~3.0.0", "expect.js": "*", - "koa": "0.13.*", + "koa": "^1.0.0", "koa-generic-session": "*", "travis-cov": "*", "coveralls": "*", "mocha-lcov-reporter": "*", "muk": "*", "rewire": "*", - "istanbul-harmony": "*" - } + "istanbul": "*" + }, + "files": [ + "lib" + ] }