Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
13 changes: 3 additions & 10 deletions .github/workflows/npm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
matrix:
os:
- ubuntu-latest
node:
node-version:
- 16

runs-on: ${{ matrix.os }}
Expand All @@ -18,7 +18,7 @@ jobs:
- name: Use Node.js ${{ matrix.node }}
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.noden }}
node-version: ${{ matrix.node-version }}
cache: npm
cache-dependency-path: package.json

Expand All @@ -32,18 +32,12 @@ jobs:
name: Pack
needs: build
runs-on: ubuntu-latest
strategy:
matrix:
os:
- ubuntu-latest
node:
- 16

steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node}}
node-version: 16
cache: npm
cache-dependency-path: package.json

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

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

## History

### main v1.11 (Nov 29, 2021)

1. Adapt to Wechaty v1.11

### v0.0.1 (Jun 27, 2018)

Initial version.
Expand Down
20 changes: 7 additions & 13 deletions examples/ding-dong-bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,10 @@
* limitations under the License.
*
*/
import {
EventLogoutPayload,
EventLoginPayload,
EventScanPayload,
EventErrorPayload,
EventMessagePayload,
} from 'wechaty-puppet'
import type * as PUPPET from 'wechaty-puppet'
import {
PuppetWalnut,
} from '../src/mod'
} from '../src/mod.js'

/**
*
Expand Down Expand Up @@ -70,7 +64,7 @@ puppet.start()
* `scan`, `login`, `logout`, `error`, and `message`
*
*/
function onScan (payload: EventScanPayload) {
function onScan (payload: PUPPET.payloads.EventScan) {
if (payload.qrcode) {
const qrcodeImageUrl = [
'https://wechaty.js.org/qrcode/',
Expand All @@ -83,16 +77,16 @@ function onScan (payload: EventScanPayload) {
}
}

function onLogin (payload: EventLoginPayload) {
function onLogin (payload: PUPPET.payloads.EventLogin) {
console.info(`${payload.contactId} login`)
puppet.messageSendText(payload.contactId, 'Wechaty login').catch(console.error)
}

function onLogout (payload: EventLogoutPayload) {
function onLogout (payload: PUPPET.payloads.EventLogout) {
console.info(`${payload.contactId} logouted`)
}

function onError (payload: EventErrorPayload) {
function onError (payload: PUPPET.payloads.EventError) {
console.error('Bot error:', payload.data)
}

Expand All @@ -102,7 +96,7 @@ function onError (payload: EventErrorPayload) {
* dealing with Messages.
*
*/
async function onMessage (payload: EventMessagePayload) {
async function onMessage (payload: PUPPET.payloads.EventMessage) {
const msgPayload = await puppet.messagePayload(payload.messageId)
if (/ding/i.test(msgPayload.text || '')) {
console.info('ding success')
Expand Down
63 changes: 32 additions & 31 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,31 +1,36 @@
{
"name": "wechaty-puppet-walnut",
"version": "0.1.41",
"version": "1.11.4",
"description": "Puppet Walnut for Wechaty",
"directories": {
"test": "tests"
"type": "module",
"exports": {
".": {
"import": "./dist/esm/src/mod.js",
"require": "./dist/cjs/src/mod.js"
}
},
"main": "dist/src/mod.js",
"typings": "dist/src/mod.d.ts",
"typings": "./dist/esm/src/mod.d.ts",
"engines": {
"wechaty": ">=0.60"
"node": ">=16",
"npm": ">=7"
},
"scripts": {
"clean": "shx rm -fr dist/*",
"dist": "npm run clean && tsc",
"pack": "npm pack",
"start": "ts-node examples/ding-dong-bot.ts",
"lint": "npm run lint:es && npm run lint:ts && npm run lint:md",
"dist": "npm-run-all clean build dist:commonjs",
"build": "tsc && tsc -p tsconfig.cjs.json",
"dist:commonjs": "jq -n \"{ type: \\\"commonjs\\\" }\" > dist/cjs/package.json",
"lint": "npm-run-all lint:es lint:ts lint:md",
"lint:ts": "tsc --isolatedModules --noEmit",
"lint:md": "markdownlint README.md",
"lint:ts": "tsc --noEmit",
"lint:es": "eslint \"src/**/*.ts\" \"tests/**/*.spec.ts\" --ignore-pattern tests/fixtures/",
"start": "ts-node examples/ding-dong-bot.ts",
"test": "npm run lint && npm run test:unit",
"test:pack": "bash -x scripts/npm-pack-testing.sh",
"test:unit": "blue-tape -r ts-node/register 'src/**/*.spec.ts' 'tests/**/*.spec.ts'"
"test:unit": "cross-env NODE_OPTIONS=\"--no-warnings --loader=ts-node/esm\" tap \"src/**/*.spec.ts\" \"tests/**/*.spec.ts\""
},
"repository": {
"type": "git",
"url": "git+https://github.com/wechaty/wechaty-puppet-mock.git"
"url": "git+https://github.com/wechaty/puppet-walnut.git"
},
"keywords": [
"chatie",
Expand All @@ -40,38 +45,34 @@
"author": "Huan LI <[email protected]>",
"license": "Apache-2.0",
"bugs": {
"url": "https://github.com/wechaty/wechaty-puppet-mock/issues"
"url": "https://github.com/wechaty/puppet-walnut/issues"
},
"homepage": "https://github.com/wechaty/wechaty-puppet-mock#readme",
"homepage": "https://github.com/wechaty/puppet-walnut#readme",
"devDependencies": {
"@chatie/eslint-config": "^0.12.4",
"@chatie/eslint-config": "^1.0.4",
"@chatie/git-scripts": "^0.6.2",
"@chatie/semver": "^0.4.7",
"@chatie/tsconfig": "^0.17.2",
"@types/cuid": "^1.3.1",
"@types/faker": "^5.5.7",
"@chatie/tsconfig": "^4.6.2",
"@types/koa": "^2.13.4",
"@types/koa-router": "^7.4.4",
"@types/node": "^16.10.5",
"@types/request-promise": "^4.1.48",
"@types/uuid": "^8.3.1",
"pkg-jq": "^0.2.11",
"shx": "^0.3.3",
"tstest": "^0.4.10",
"typescript": "4.3",
"wechaty": "^0.75.17",
"wechaty-puppet": "^0.41.3"
"@types/uuid": "^8.3.3"
},
"peerDependencies": {
"wechaty-puppet": "^1.11.12"
},
"dependencies": {
"cuid": "^2.1.8",
"faker": "^5.5.3",
"koa": "^2.13.1",
"koa": "^2.13.4",
"koa-body": "^4.2.0",
"koa-router": "^10.1.1",
"request": "^2.88.2",
"request-promise": "^4.2.6",
"typed-emitter": "^1.3.1"
"uuid": "^8.3.2"
},
"files": [
"dist",
"src"
],
"publishConfig": {
"access": "public",
"tag": "next"
Expand Down
Empty file modified scripts/generate-version.sh
100644 → 100755
Empty file.
44 changes: 32 additions & 12 deletions scripts/npm-pack-testing.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,39 +1,59 @@
#!/usr/bin/env bash
set -e

VERSION=$(npx pkg-jq -r .version)

if npx --package @chatie/semver semver-is-prod "$VERSION"; then
NPM_TAG=latest
else
NPM_TAG=next
fi

npm run dist
npm run pack
npm pack

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

cd $TMPDIR

npm init -y
npm install ./*-*.*.*.tgz \
@chatie/tsconfig@$NPM_TAG \
\
"wechaty-puppet@$NPM_TAG" \
"wechaty@$NPM_TAG" \

#
# CommonJS
#
./node_modules/.bin/tsc \
--esModuleInterop \
--lib esnext \
--noEmitOnError \
--noImplicitAny \
--skipLibCheck \
--target es5 \
--module CommonJS \
--moduleResolution node \
smoke-testing.ts

echo
echo "CommonJS: pack testing..."
node smoke-testing.js

#
# ES Modules
#

# https://stackoverflow.com/a/59203952/1123955
echo "`jq '.type="module"' package.json`" > package.json

./node_modules/.bin/tsc \
--esModuleInterop \
--lib esnext \
--noEmitOnError \
--noImplicitAny \
--target es6 \
--module commonjs \
--skipLibCheck \
--target es2020 \
--module es2020 \
--moduleResolution node \
smoke-testing.ts

node --version
echo
echo "ES Module: pack testing..."
node smoke-testing.js
Empty file modified scripts/package-publish-config-tag.sh
100644 → 100755
Empty file.
4 changes: 2 additions & 2 deletions src/config.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import {
FileBox,
} from 'wechaty-puppet'
} from 'file-box'

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

export function qrCodeForChatie (): FileBox {
return FileBox.fromQRCode(CHATIE_OFFICIAL_ACCOUNT_QRCODE)
}

export { VERSION } from './version'
export { VERSION } from './version.js'
4 changes: 2 additions & 2 deletions src/mod.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { VERSION } from './version'
import { PuppetWalnut } from './puppet-walnut'
import { VERSION } from './version.js'
import { PuppetWalnut } from './puppet-walnut.js'

export {
VERSION,
Expand Down
8 changes: 4 additions & 4 deletions src/puppet-walnut.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env -S node
import test from 'tstest'
#!/usr/bin/env -S node --no-warnings --loader ts-node/esm
import { test } from 'tstest'

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

/**
* zrn-fight - https://github.com/zrn-fight
Expand All @@ -15,7 +15,7 @@ import { PuppetWalnut } from './puppet-walnut'
*
*/

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