Skip to content

Commit 47a5b36

Browse files
authored
Merge pull request #16 from wechaty/wechaty-1.x
Adapt to Wechaty v1.11
2 parents 090b455 + 3a765e2 commit 47a5b36

16 files changed

+181
-228
lines changed
File renamed without changes.

.github/workflows/npm.yml

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jobs:
99
matrix:
1010
os:
1111
- ubuntu-latest
12-
node:
12+
node-version:
1313
- 16
1414

1515
runs-on: ${{ matrix.os }}
@@ -18,7 +18,7 @@ jobs:
1818
- name: Use Node.js ${{ matrix.node }}
1919
uses: actions/setup-node@v2
2020
with:
21-
node-version: ${{ matrix.noden }}
21+
node-version: ${{ matrix.node-version }}
2222
cache: npm
2323
cache-dependency-path: package.json
2424

@@ -32,18 +32,12 @@ jobs:
3232
name: Pack
3333
needs: build
3434
runs-on: ubuntu-latest
35-
strategy:
36-
matrix:
37-
os:
38-
- ubuntu-latest
39-
node:
40-
- 16
4135

4236
steps:
4337
- uses: actions/checkout@v2
4438
- uses: actions/setup-node@v2
4539
with:
46-
node-version: ${{ matrix.node}}
40+
node-version: 16
4741
cache: npm
4842
cache-dependency-path: package.json
4943

@@ -102,4 +96,3 @@ jobs:
10296
- name: Is Not A Publish Branch
10397
if: steps.check-branch.outputs.match != 'true'
10498
run: echo 'Not A Publish Branch'
105-

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,12 @@ Wechaty 社区目前已经支持微信、Whatsapp、企业微信、飞书等常
102102
- [Koa](https://koa.bootcss.com/)
103103
- [TypeScripts中文手册](https://www.tslang.cn/docs/handbook/basic-types.html)
104104

105+
## History
106+
107+
### main v1.11 (Nov 29, 2021)
108+
109+
1. Adapt to Wechaty v1.11
110+
105111
### v0.0.1 (Jun 27, 2018)
106112

107113
Initial version.

examples/ding-dong-bot.ts

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,10 @@
1616
* limitations under the License.
1717
*
1818
*/
19-
import {
20-
EventLogoutPayload,
21-
EventLoginPayload,
22-
EventScanPayload,
23-
EventErrorPayload,
24-
EventMessagePayload,
25-
} from 'wechaty-puppet'
19+
import type * as PUPPET from 'wechaty-puppet'
2620
import {
2721
PuppetWalnut,
28-
} from '../src/mod'
22+
} from '../src/mod.js'
2923

3024
/**
3125
*
@@ -70,7 +64,7 @@ puppet.start()
7064
* `scan`, `login`, `logout`, `error`, and `message`
7165
*
7266
*/
73-
function onScan (payload: EventScanPayload) {
67+
function onScan (payload: PUPPET.payloads.EventScan) {
7468
if (payload.qrcode) {
7569
const qrcodeImageUrl = [
7670
'https://wechaty.js.org/qrcode/',
@@ -83,16 +77,16 @@ function onScan (payload: EventScanPayload) {
8377
}
8478
}
8579

86-
function onLogin (payload: EventLoginPayload) {
80+
function onLogin (payload: PUPPET.payloads.EventLogin) {
8781
console.info(`${payload.contactId} login`)
8882
puppet.messageSendText(payload.contactId, 'Wechaty login').catch(console.error)
8983
}
9084

91-
function onLogout (payload: EventLogoutPayload) {
85+
function onLogout (payload: PUPPET.payloads.EventLogout) {
9286
console.info(`${payload.contactId} logouted`)
9387
}
9488

95-
function onError (payload: EventErrorPayload) {
89+
function onError (payload: PUPPET.payloads.EventError) {
9690
console.error('Bot error:', payload.data)
9791
}
9892

@@ -102,7 +96,7 @@ function onError (payload: EventErrorPayload) {
10296
* dealing with Messages.
10397
*
10498
*/
105-
async function onMessage (payload: EventMessagePayload) {
99+
async function onMessage (payload: PUPPET.payloads.EventMessage) {
106100
const msgPayload = await puppet.messagePayload(payload.messageId)
107101
if (/ding/i.test(msgPayload.text || '')) {
108102
console.info('ding success')

package.json

Lines changed: 32 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,36 @@
11
{
22
"name": "wechaty-puppet-walnut",
3-
"version": "0.1.41",
3+
"version": "1.11.4",
44
"description": "Puppet Walnut for Wechaty",
5-
"directories": {
6-
"test": "tests"
5+
"type": "module",
6+
"exports": {
7+
".": {
8+
"import": "./dist/esm/src/mod.js",
9+
"require": "./dist/cjs/src/mod.js"
10+
}
711
},
8-
"main": "dist/src/mod.js",
9-
"typings": "dist/src/mod.d.ts",
12+
"typings": "./dist/esm/src/mod.d.ts",
1013
"engines": {
11-
"wechaty": ">=0.60"
14+
"node": ">=16",
15+
"npm": ">=7"
1216
},
1317
"scripts": {
1418
"clean": "shx rm -fr dist/*",
15-
"dist": "npm run clean && tsc",
16-
"pack": "npm pack",
17-
"start": "ts-node examples/ding-dong-bot.ts",
18-
"lint": "npm run lint:es && npm run lint:ts && npm run lint:md",
19+
"dist": "npm-run-all clean build dist:commonjs",
20+
"build": "tsc && tsc -p tsconfig.cjs.json",
21+
"dist:commonjs": "jq -n \"{ type: \\\"commonjs\\\" }\" > dist/cjs/package.json",
22+
"lint": "npm-run-all lint:es lint:ts lint:md",
23+
"lint:ts": "tsc --isolatedModules --noEmit",
1924
"lint:md": "markdownlint README.md",
20-
"lint:ts": "tsc --noEmit",
2125
"lint:es": "eslint \"src/**/*.ts\" \"tests/**/*.spec.ts\" --ignore-pattern tests/fixtures/",
26+
"start": "ts-node examples/ding-dong-bot.ts",
2227
"test": "npm run lint && npm run test:unit",
2328
"test:pack": "bash -x scripts/npm-pack-testing.sh",
24-
"test:unit": "blue-tape -r ts-node/register 'src/**/*.spec.ts' 'tests/**/*.spec.ts'"
29+
"test:unit": "cross-env NODE_OPTIONS=\"--no-warnings --loader=ts-node/esm\" tap \"src/**/*.spec.ts\" \"tests/**/*.spec.ts\""
2530
},
2631
"repository": {
2732
"type": "git",
28-
"url": "git+https://github.com/wechaty/wechaty-puppet-mock.git"
33+
"url": "git+https://github.com/wechaty/puppet-walnut.git"
2934
},
3035
"keywords": [
3136
"chatie",
@@ -40,38 +45,34 @@
4045
"author": "Huan LI <[email protected]>",
4146
"license": "Apache-2.0",
4247
"bugs": {
43-
"url": "https://github.com/wechaty/wechaty-puppet-mock/issues"
48+
"url": "https://github.com/wechaty/puppet-walnut/issues"
4449
},
45-
"homepage": "https://github.com/wechaty/wechaty-puppet-mock#readme",
50+
"homepage": "https://github.com/wechaty/puppet-walnut#readme",
4651
"devDependencies": {
47-
"@chatie/eslint-config": "^0.12.4",
52+
"@chatie/eslint-config": "^1.0.4",
4853
"@chatie/git-scripts": "^0.6.2",
4954
"@chatie/semver": "^0.4.7",
50-
"@chatie/tsconfig": "^0.17.2",
51-
"@types/cuid": "^1.3.1",
52-
"@types/faker": "^5.5.7",
55+
"@chatie/tsconfig": "^4.6.2",
5356
"@types/koa": "^2.13.4",
5457
"@types/koa-router": "^7.4.4",
55-
"@types/node": "^16.10.5",
5658
"@types/request-promise": "^4.1.48",
57-
"@types/uuid": "^8.3.1",
58-
"pkg-jq": "^0.2.11",
59-
"shx": "^0.3.3",
60-
"tstest": "^0.4.10",
61-
"typescript": "4.3",
62-
"wechaty": "^0.75.17",
63-
"wechaty-puppet": "^0.41.3"
59+
"@types/uuid": "^8.3.3"
60+
},
61+
"peerDependencies": {
62+
"wechaty-puppet": "^1.11.12"
6463
},
6564
"dependencies": {
66-
"cuid": "^2.1.8",
67-
"faker": "^5.5.3",
68-
"koa": "^2.13.1",
65+
"koa": "^2.13.4",
6966
"koa-body": "^4.2.0",
7067
"koa-router": "^10.1.1",
7168
"request": "^2.88.2",
7269
"request-promise": "^4.2.6",
73-
"typed-emitter": "^1.3.1"
70+
"uuid": "^8.3.2"
7471
},
72+
"files": [
73+
"dist",
74+
"src"
75+
],
7576
"publishConfig": {
7677
"access": "public",
7778
"tag": "next"

scripts/generate-version.sh

100644100755
File mode changed.

scripts/npm-pack-testing.sh

100644100755
Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,59 @@
11
#!/usr/bin/env bash
22
set -e
33

4-
VERSION=$(npx pkg-jq -r .version)
5-
6-
if npx --package @chatie/semver semver-is-prod "$VERSION"; then
7-
NPM_TAG=latest
8-
else
9-
NPM_TAG=next
10-
fi
11-
124
npm run dist
13-
npm run pack
5+
npm pack
146

157
TMPDIR="/tmp/npm-pack-testing.$$"
168
mkdir "$TMPDIR"
179
mv ./*-*.*.*.tgz "$TMPDIR"
1810
cp tests/fixtures/smoke-testing.ts "$TMPDIR"
1911

2012
cd $TMPDIR
13+
2114
npm init -y
2215
npm install ./*-*.*.*.tgz \
2316
@chatie/tsconfig@$NPM_TAG \
2417
\
2518
"wechaty-puppet@$NPM_TAG" \
2619
"wechaty@$NPM_TAG" \
2720

21+
#
22+
# CommonJS
23+
#
2824
./node_modules/.bin/tsc \
2925
--esModuleInterop \
3026
--lib esnext \
27+
--noEmitOnError \
28+
--noImplicitAny \
3129
--skipLibCheck \
30+
--target es5 \
31+
--module CommonJS \
32+
--moduleResolution node \
33+
smoke-testing.ts
34+
35+
echo
36+
echo "CommonJS: pack testing..."
37+
node smoke-testing.js
38+
39+
#
40+
# ES Modules
41+
#
42+
43+
# https://stackoverflow.com/a/59203952/1123955
44+
echo "`jq '.type="module"' package.json`" > package.json
45+
46+
./node_modules/.bin/tsc \
47+
--esModuleInterop \
48+
--lib esnext \
3249
--noEmitOnError \
3350
--noImplicitAny \
34-
--target es6 \
35-
--module commonjs \
51+
--skipLibCheck \
52+
--target es2020 \
53+
--module es2020 \
54+
--moduleResolution node \
3655
smoke-testing.ts
3756

38-
node --version
57+
echo
58+
echo "ES Module: pack testing..."
3959
node smoke-testing.js

scripts/package-publish-config-tag.sh

100644100755
File mode changed.

src/config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import {
22
FileBox,
3-
} from 'wechaty-puppet'
3+
} from 'file-box'
44

55
export const CHATIE_OFFICIAL_ACCOUNT_QRCODE = 'http://weixin.qq.com/r/qymXj7DEO_1ErfTs93y5'
66

77
export function qrCodeForChatie (): FileBox {
88
return FileBox.fromQRCode(CHATIE_OFFICIAL_ACCOUNT_QRCODE)
99
}
1010

11-
export { VERSION } from './version'
11+
export { VERSION } from './version.js'

src/mod.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { VERSION } from './version'
2-
import { PuppetWalnut } from './puppet-walnut'
1+
import { VERSION } from './version.js'
2+
import { PuppetWalnut } from './puppet-walnut.js'
33

44
export {
55
VERSION,

src/puppet-walnut.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
#!/usr/bin/env -S node
2-
import test from 'tstest'
1+
#!/usr/bin/env -S node --no-warnings --loader ts-node/esm
2+
import { test } from 'tstest'
33

4-
import { PuppetWalnut } from './puppet-walnut'
4+
import { PuppetWalnut } from './puppet-walnut.js'
55

66
/**
77
* zrn-fight - https://github.com/zrn-fight
@@ -15,7 +15,7 @@ import { PuppetWalnut } from './puppet-walnut'
1515
*
1616
*/
1717

18-
test.skip('PuppetWalnut perfect restart testing', async (t) => {
18+
test.skip('PuppetWalnut perfect restart testing', async t => {
1919
const puppet = new PuppetWalnut({ sms: '12345' })
2020
for (let n = 0; n < 3; n++) {
2121
await puppet.start()

0 commit comments

Comments
 (0)