Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ESM #23

Merged
merged 5 commits into from
Sep 1, 2021
Merged

ESM #23

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.
34 changes: 23 additions & 11 deletions .github/workflows/npm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,21 @@ jobs:
name: Build
strategy:
matrix:
os: [windows-latest]
node: [12, 14, 16]
os:
- windows-latest
node:
- 14
- 16

runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node }}
uses: actions/setup-node@v1
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.noden }}
cache: 'npm'
cache-dependency-path: package.json

- name: Install Dependencies
run: npm install
Expand All @@ -29,21 +34,26 @@ jobs:
needs: build
strategy:
matrix:
os: [windows-latest]
node: [12, 14, 16]
os:
- windows-latest
node:
- 14
- 16

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

- name: Install Dependencies
run: npm install

- name: Generate Version
run: ./scripts/generate-version.sh
- name: Generate Package JSON
run: ./scripts/generate-package-json.sh

- name: Pack Testing
run: ./scripts/npm-pack-testing.sh
Expand All @@ -55,16 +65,18 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
- uses: actions/setup-node@v2
with:
node-version: 16
registry-url: https://registry.npmjs.org/
cache: 'npm'
cache-dependency-path: package.json

- name: Install Dependencies
run: npm install

- name: Generate Version
run: ./scripts/generate-version.sh
- name: Generate Package JSON
run: ./scripts/generate-package-json.sh

- name: Set Publish Config
run: ./scripts/package-publish-config-tag.sh
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ npm install

## HISTORY

### main
### main v0.5

1. ES Module support

### v0.4.7 (Aug 15, 2021)

Expand Down
1 change: 1 addition & 0 deletions commonjs/code-root.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export declare const codeRoot: string
10 changes: 10 additions & 0 deletions commonjs/code-root.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const path = require('path')

const codeRoot = path.join(
__dirname,
'..',
)

module.exports = {
codeRoot,
}
9 changes: 9 additions & 0 deletions commonjs/code-root.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env -S ts-node --project tsconfig.cjs.json

import { test } from 'tstest'

import { codeRoot } from './code-root'

test('CJS: codeRoot()', async t => {
t.ok(codeRoot, 'should exist codeRoot')
})
1 change: 1 addition & 0 deletions commonjs/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{ "type": "commonjs" }
4 changes: 2 additions & 2 deletions examples/ding-dong-bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* limitations under the License.
*
*/
import {
import type {
EventLogoutPayload,
EventLoginPayload,
EventScanPayload,
Expand All @@ -26,7 +26,7 @@ import {

import {
PuppetXp,
} from '../src/mod'
} from '../src/mod.js'

/**
*
Expand Down
4 changes: 2 additions & 2 deletions examples/raw-sidecar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {
detach,
} from 'sidecar'

import { WeChatSidecar } from '../src/wechat-sidecar'
import { WeChatSidecar } from '../src/wechat-sidecar.js'

async function main () {
console.info('WeChat Sidecar starting...')
Expand All @@ -41,7 +41,7 @@ async function main () {

const toId = String(args[1])
const text = String(args[2])
const talkerId = String(args[3])
const talkerId = String(args[3])

console.info('recvMsg: talkerId =', talkerId)
console.info('recvMsg: text =', text)
Expand Down
15 changes: 7 additions & 8 deletions examples/ripe-wechaty.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
* Wechaty - Conversational RPA SDK for Chatbot Makers.
* - https://github.com/wechaty/wechaty
*/
import {
import {
Contact,
Message,
ScanStatus,
Wechaty,
log,
FileBox,
} from 'wechaty'

import { PuppetXp } from '../src/puppet-xp'
import { FileBox } from 'file-box'
import { PuppetXp } from '../src/puppet-xp.js'

function onScan (qrcode: string, status: ScanStatus) {
if (status === ScanStatus.Waiting || status === ScanStatus.Timeout) {
Expand Down Expand Up @@ -50,7 +50,7 @@ async function onMessage (msg: Message) {
if (msg.text() === 'at' && room) {
const mentionIdList = []
mentionIdList.push(talker)
console.debug(mentionIdList)
console.info(mentionIdList)
await room.say('hi',...mentionIdList)
}
if (room) {
Expand All @@ -64,20 +64,19 @@ async function onMessage (msg: Message) {
}
}


if (msg.text() === 'p') {
const fileBox1 = FileBox.fromUrl('http://pic.linecg.com/uploads/file/contents/2019/095d7772e8a0b1b.jpg')
await msg.say(fileBox1)
}

if (msg.text() === 'c') {
const contactList = await bot.Contact.findAll()
console.debug(contactList)
console.info(contactList)
}

if (msg.text() === 'r') {
const roomList = await bot.Room.findAll()
console.debug(roomList)
console.info(roomList)
}
}

Expand All @@ -97,6 +96,6 @@ bot.on('message', onMessage)

bot.start()
.then(() => {
log.info('StarterBot', 'Starter Bot Started.')
return log.info('StarterBot', 'Starter Bot Started.')
})
.catch(e => log.error('StarterBot', e))
54 changes: 35 additions & 19 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,29 +1,37 @@
{
"name": "wechaty-puppet-xp",
"version": "0.4.16",
"version": "0.5.2",
"description": "Puppet XP 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"
"wechaty": ">=0.69",
"wechaty-puppet": ">=0.43"
},
"scripts": {
"clean": "shx rm -fr dist/*",
"dist": "npm run clean && tsc && shx cp src/init-agent-script.js dist/src/init-agent-script.js",
"pack": "npm pack",
"start": "ts-node examples/ding-dong-bot.ts",
"start:raw": "cross-env BROLOG_LEVEL=silly ts-node examples/raw-sidecar.ts",
"start:ripe": "cross-env WECHATY_LOG=verbose ts-node examples/ripe-wechaty.ts",
"clean": "shx rm -fr dist/* generated/*",
"dist": "npm-run-all clean build dist:copy dist:commonjs",
"build": "tsc && tsc -p tsconfig.cjs.json",
"dist:commonjs": "shx echo '{\"type\": \"commonjs\"}' > dist/cjs/package.json",
"dist:copy": "npm-run-all copy:esm copy:cjs",
"copy:esm": "shx cp -R commonjs/ dist/esm/ && shx cp src/init-agent-script.js dist/esm/src",
"copy:cjs": "shx cp -R commonjs/ dist/cjs/ && shx cp src/init-agent-script.js dist/cjs/src",
"start": "cross-env NODE_OPTIONS='--no-warnings --loader=ts-node/esm' node examples/ding-dong-bot.ts",
"start:raw": "cross-env BROLOG_LEVEL=silly NODE_OPTIONS='--no-warnings --loader=ts-node/esm' node examples/raw-sidecar.ts",
"start:ripe": "cross-env WECHATY_LOG=verbose NODE_OPTIONS='--no-warnings --loader=ts-node/esm' node examples/ripe-wechaty.ts",
"lint": "npm run lint:es && npm run lint:ts && npm run lint:md",
"lint:md": "markdownlint README.md",
"lint:ts": "tsc --noEmit",
"lint:ts": "tsc --isolatedModules --noEmit",
"lint:es": "eslint \"src/**/*.ts\" \"tests/**/*.spec.ts\" --ignore-pattern tests/fixtures/",
"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": "tap --node-arg=--loader=ts-node/esm --node-arg=--no-warnings \"src/**/*.spec.ts\" \"tests/**/*.spec.ts\""
},
"repository": {
"type": "git",
Expand All @@ -46,27 +54,35 @@
},
"homepage": "https://github.com/wechaty/wechaty-puppet-mock#readme",
"devDependencies": {
"@chatie/eslint-config": "^0.12.4",
"@chatie/eslint-config": "^0.13.5",
"@chatie/git-scripts": "^0.6.2",
"@chatie/semver": "^0.4.7",
"@chatie/tsconfig": "^0.17.2",
"@chatie/tsconfig": "^0.19.6",
"@types/cuid": "^2.0.1",
"@types/faker": "^5.5.7",
"cross-env": "^7.0.3",
"npm-run-all": "^4.1.5",
"pkg-jq": "^0.2.11",
"shx": "^0.3.3",
"tstest": "^0.4.10",
"typescript": "4.3",
"tstest": "^0.5.16",
"typescript": "^4.4.2",
"wechaty": "^0.62.3",
"wechaty-puppet": "^0.41.3"
},
"peerDependencies": {},
"dependencies": {
"cuid": "^2.1.8",
"faker": "^5.5.3",
"sidecar": "^0.14.1",
"typed-emitter": "^1.3.1"
},
"files": [
"bin/",
"dist/",
"src/"
],
"tap": {
"check-coverage": false
},
"publishConfig": {
"access": "public",
"tag": "next"
Expand Down
17 changes: 17 additions & 0 deletions scripts/generate-package-json.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env bash
set -e

SRC_PACKAGE_JSON_TS_FILE='src/package-json.ts'

[ -f ${SRC_PACKAGE_JSON_TS_FILE} ] || {
echo ${SRC_PACKAGE_JSON_TS_FILE}" not found"
exit 1
}

cat <<_SRC_ > ${SRC_PACKAGE_JSON_TS_FILE}
/**
* This file was auto generated from scripts/generate-version.sh
*/
import type { PackageJson } from 'type-fest'
export const packageJson: PackageJson = $(cat package.json) as any
_SRC_
18 changes: 0 additions & 18 deletions scripts/generate-version.sh

This file was deleted.

Loading