Skip to content

Commit

Permalink
support ESM (#41)
Browse files Browse the repository at this point in the history
* support ESM

* fix

* 0.6.53

* clean

* 0.6.54

* upgrade wechaty-vorpal for esm

* 0.7.1

* node v16 for ci

* 0.7.2
  • Loading branch information
huan authored Sep 19, 2021
1 parent 84a4de7 commit 0979236
Show file tree
Hide file tree
Showing 49 changed files with 369 additions and 244 deletions.
File renamed without changes.
24 changes: 16 additions & 8 deletions .github/workflows/npm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ jobs:
name: Build
strategy:
matrix:
os: [ubuntu-latest]
node: [12]
os:
- ubuntu-latest
node-version:
- 16

runs-on: ${{ matrix.os }}
steps:
Expand All @@ -17,6 +19,8 @@ jobs:
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
cache: npm
cache-dependency-path: package.json

- name: Install Dependencies
run: npm install
Expand All @@ -32,13 +36,15 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: 12
node-version: 16
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 @@ -54,14 +60,16 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: 12
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
26 changes: 15 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,23 @@ import { Version } from 'wechaty-vorpal-contrib'
vorpalExtensionList = [ Version() ]
```

## Contributors

[![contributor](https://sourcerer.io/fame/huan/wechaty/wechaty-vorpal-contrib/images/0)](https://sourcerer.io/fame/huan/wechaty/wechaty-vorpal-contrib/links/0)
[![contributor](https://sourcerer.io/fame/huan/wechaty/wechaty-vorpal-contrib/images/1)](https://sourcerer.io/fame/huan/wechaty/wechaty-vorpal-contrib/links/1)
[![contributor](https://sourcerer.io/fame/huan/wechaty/wechaty-vorpal-contrib/images/2)](https://sourcerer.io/fame/huan/wechaty/wechaty-vorpal-contrib/links/2)
[![contributor](https://sourcerer.io/fame/huan/wechaty/wechaty-vorpal-contrib/images/3)](https://sourcerer.io/fame/huan/wechaty/wechaty-vorpal-contrib/links/3)
[![contributor](https://sourcerer.io/fame/huan/wechaty/wechaty-vorpal-contrib/images/4)](https://sourcerer.io/fame/huan/wechaty/wechaty-vorpal-contrib/links/4)
[![contributor](https://sourcerer.io/fame/huan/wechaty/wechaty-vorpal-contrib/images/5)](https://sourcerer.io/fame/huan/wechaty/wechaty-vorpal-contrib/links/5)
[![contributor](https://sourcerer.io/fame/huan/wechaty/wechaty-vorpal-contrib/images/6)](https://sourcerer.io/fame/huan/wechaty/wechaty-vorpal-contrib/links/6)
[![contributor](https://sourcerer.io/fame/huan/wechaty/wechaty-vorpal-contrib/images/7)](https://sourcerer.io/fame/huan/wechaty/wechaty-vorpal-contrib/links/7)

## History

### main (Sep 20, 2021)

1. Enable ESM Modules

### v0.6 (July 10, 2020)

1. Upgrade to [wechaty-vorpal](https://github.com/wechaty/wechaty-vorpal)@0.6 to enhance the Command Action Functions
Expand All @@ -184,17 +199,6 @@ Init the first version of Wechaty Vorpal Extensions for official Wechaty ChatOps
1. `Eval` Extension for EVAL JavaScript code from the chat window!
1. `Cash` Extension for Cross-platform Linux commands in pure ES6

## Contributors

[![contributor](https://sourcerer.io/fame/huan/wechaty/wechaty-vorpal-contrib/images/0)](https://sourcerer.io/fame/huan/wechaty/wechaty-vorpal-contrib/links/0)
[![contributor](https://sourcerer.io/fame/huan/wechaty/wechaty-vorpal-contrib/images/1)](https://sourcerer.io/fame/huan/wechaty/wechaty-vorpal-contrib/links/1)
[![contributor](https://sourcerer.io/fame/huan/wechaty/wechaty-vorpal-contrib/images/2)](https://sourcerer.io/fame/huan/wechaty/wechaty-vorpal-contrib/links/2)
[![contributor](https://sourcerer.io/fame/huan/wechaty/wechaty-vorpal-contrib/images/3)](https://sourcerer.io/fame/huan/wechaty/wechaty-vorpal-contrib/links/3)
[![contributor](https://sourcerer.io/fame/huan/wechaty/wechaty-vorpal-contrib/images/4)](https://sourcerer.io/fame/huan/wechaty/wechaty-vorpal-contrib/links/4)
[![contributor](https://sourcerer.io/fame/huan/wechaty/wechaty-vorpal-contrib/images/5)](https://sourcerer.io/fame/huan/wechaty/wechaty-vorpal-contrib/links/5)
[![contributor](https://sourcerer.io/fame/huan/wechaty/wechaty-vorpal-contrib/images/6)](https://sourcerer.io/fame/huan/wechaty/wechaty-vorpal-contrib/links/6)
[![contributor](https://sourcerer.io/fame/huan/wechaty/wechaty-vorpal-contrib/images/7)](https://sourcerer.io/fame/huan/wechaty/wechaty-vorpal-contrib/links/7)

## Author

[Huan LI](https://github.com/huan) ([李卓桓](http://linkedin.com/in/zixia)), Tencent TVP of Chatbot, \<[email protected]\>
Expand Down
2 changes: 1 addition & 1 deletion examples/vorpal.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Vorpal } from 'wechaty-vorpal'

import { Cash } from '../src/contrib/cash'
import { Cash } from '../src/contrib/cash.js'

async function main () {
const vorpal = new Vorpal()
Expand Down
59 changes: 36 additions & 23 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,24 +1,33 @@
{
"name": "wechaty-vorpal-contrib",
"version": "0.6.52",
"version": "0.7.2",
"description": "Wechaty Chat CLI (Command Line Interface), Powered by Vorpal",
"main": "dist/src/mod.js",
"typings": "dist/src/mod.d.ts",
"type": "module",
"exports": {
".": {
"import": "./dist/esm/src/mod.js",
"require": "./dist/cjs/src/mod.js"
}
},
"typings": "./dist/esm/src/mod.d.ts",
"engines": {
"wechaty": ">=0.69",
"node": ">=14",
"wechaty-vorpal": ">=0.6.1"
},
"scripts": {
"build": "tsc && tsc -p tsconfig.cjs.json",
"clean": "shx rm -fr dist/*",
"dist": "npm run clean && tsc",
"pack": "npm pack",
"lint": "npm run lint:es && npm run lint:ts && npm run lint:md",
"dist": "npm-run-all clean build dist:commonjs",
"dist:commonjs": "jq -n \"{ type: \\\"commonjs\\\" }\" > dist/cjs/package.json",
"lint": "npm-run-all lint:es lint:ts lint:md",
"lint:md": "markdownlint README.md",
"lint:ts": "tsc --noEmit",
"example": "ts-node examples/ding-dong-bot.ts",
"lint:ts": "tsc --isolatedModules --noEmit",
"example": "cross-env NODE_OPTIONS=\"--no-warnings --loader=ts-node/esm\" node examples/ding-dong-bot.ts",
"start": "npm run example",
"test": "npm run lint && npm run test:unit",
"test": "npm-run-all lint test:unit",
"test:pack": "bash -x scripts/npm-pack-testing.sh",
"test:unit": "tap --node-arg=--require=ts-node/register \"src/**/*.spec.ts\" \"src/*.spec.ts\" \"tests/*.spec.ts\" \"tests/**/*.spec.ts\"",
"test:unit": "cross-env NODE_OPTIONS=\"--no-warnings --loader=ts-node/esm\" tap \"src/**/*.spec.ts\" \"tests/**/*.spec.ts\"",
"lint:es": "eslint --ignore-pattern tests/fixtures/ '{bin,examples,scripts,src,tests}/**/*.ts'"
},
"repository": {
Expand All @@ -39,34 +48,38 @@
},
"homepage": "https://github.com/wechaty/wechaty-vorpal-contrib#readme",
"devDependencies": {
"@chatie/eslint-config": "^0.12.1",
"@chatie/eslint-config": "^0.14.1",
"@chatie/git-scripts": "^0.6.2",
"@chatie/semver": "^0.4.7",
"@chatie/tsconfig": "^0.16.2",
"@chatie/tsconfig": "^0.20.2",
"@types/ip": "^1.1.0",
"@types/json-stringify-safe": "^5.0.0",
"pkg-jq": "^0.2.4",
"cross-env": "^7.0.3",
"npm-run-all": "^4.1.5",
"pkg-jq": "^0.2.11",
"rxjs": "^7.3.0",
"shx": "^0.3.3",
"tstest": "^0.5.16",
"wechaty": "^0.62.3",
"wechaty-mocker": "^0.3.4",
"wechaty-puppet-mock": "^0.28.1",
"wechaty-vorpal": "^0.6.17"
"wechaty": "^0.69.50",
"wechaty-mocker": "^0.9.1",
"wechaty-puppet-mock": "^0.31.5"
},
"peerDependencies": {
"wechaty-vorpal": "^0.7.4"
},
"dependencies": {
"cash": "^0.8.0",
"ip": "^1.1.5",
"json-stringify-safe": "^5.0.1",
"moment": "^2.29.1",
"public-ip": "^4.0.2",
"read-pkg-up": "^7.0.1",
"public-ip": "^4.0.4",
"utility-types": "^3.10.0"
},
"peerDependencies": {
"rxjs": ">=7.3",
"wechaty-vorpal": ">=0.6.17"
},
"files": [
"bin/",
"dist/",
"src/"
],
"git": {
"scripts": {
"pre-push": "npx git-scripts-pre-push"
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.

43 changes: 39 additions & 4 deletions scripts/npm-pack-testing.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,68 @@ set -e

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

if npx --package @chatie/semver semver-is-prod $VERSION; then
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 install --production ./*-*.*.*.tgz \
@chatie/tsconfig@$NPM_TAG \
pkg-jq \
"wechaty-puppet@$NPM_TAG" \
"wechaty@$NPM_TAG" \
"wechaty-vorpal@$NPM_TAG" \


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

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

#
# ES Modules
#
npx pkg-jq -i '.type="module"'


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

echo
echo "ES Module: pack testing..."
node smoke-testing.js
13 changes: 12 additions & 1 deletion src/config.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
export interface WechatyVorpalConfig {
import { packageJson } from './package-json.js'

interface WechatyVorpalConfig {
command?: string // the command name
}

const VERSION = packageJson.version || '0.0.0'

export type {
WechatyVorpalConfig,
}
export {
VERSION,
}
4 changes: 2 additions & 2 deletions src/contrib/announce.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {
log,
} from 'wechaty'
import {
import type {
Vorpal,
CommandContext,
Args,
Expand Down Expand Up @@ -30,7 +30,7 @@ async function announceAction (
): Promise<number> {
log.verbose('WechatyVorpalContrib', 'announceAction("%s")', JSON.stringify(args))

const announcement: string = args.announcement as string
const announcement: string = args['announcement'] as string
const options = args.options as any as AnnounceOptions

const room = await this.wechaty.Room.find({ id: options.room })
Expand Down
2 changes: 1 addition & 1 deletion src/contrib/cash.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {
import type {
Vorpal,
} from 'wechaty-vorpal'
import { log } from 'wechaty'
Expand Down
17 changes: 12 additions & 5 deletions src/contrib/ddr/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@
import {
log,
} from 'wechaty'
import {
import type {
CommandContext,
Args,
} from 'wechaty-vorpal'

import { Reporter } from './reporter'
import { Monitor } from './monitor'
import { Reporter } from './reporter.js'
import { Monitor } from './monitor.js'

import {
DEFAULT_OPTIONS,
DdrOptions,
} from './ddr'
} from './ddr.js'

async function action (
this: CommandContext,
Expand Down Expand Up @@ -93,7 +93,14 @@ async function action (

} catch (e) {
log.error('WechatyVorpalContrib', 'Ddr() ddr$.toPromise() rejection %s', e)
console.error(e.stack)
const name = (e as Error).name
const message = (e as Error).message
const stack = (e as Error).stack
this.log([
name,
message,
stack,
].join('\n'))
return 1
}

Expand Down
Loading

0 comments on commit 0979236

Please sign in to comment.