-
Notifications
You must be signed in to change notification settings - Fork 63
How to use npm link to develop wechaty puppet padpro
If you want to be a contributor to wechaty-puppet-padpro
, you will encounter a problem, which is how to develop the wechaty-puppet-padpro
locally.
We use npm link
to link wechaty
packages together.
Here is what we usually do when we develop wechaty
's puppets.
First of all, fork wechaty
, wechaty-puppet
and the puppet implementation you are developing into your local workspace. We take wechaty-puppet-padpro
as an example here.
Then you will have wechaty
, wechaty-puppet
and wechaty-puppet-padpro
in your local workspace.
Do npm install
in theses three folders to download every dependency needed.
Then in each folder, do a npm link
to link the current folder to your global npm folder.
Do npm run dist
in wechaty-puppet
folder, since this is the base dependency of the other two.
Do npm link wechaty-puppet
in wechaty
and wechaty-puppet-padpro
folder to make sure that wechaty
and wechaty-puppet-padpro
are using the same wechaty-puppet
, otherwise, you will encounter incompatible Puppet
error.
Do npm run dist
in wechaty
and wechaty-puppet-padpro
folder to use typescript compile the ts
into js
file.
Then create another folder and put your test code into it, let's name the folder test
.
In test
folder, do npm link wechaty
and npm link wechaty-puppet-padpro
.
Then add your test code in that folder, here is the code I usually use for myself.
I will put these code into a bot.ts
file, then install the extra qrcode-terminal
dependency, then run this with ts-node bot.ts
import { Wechaty, Message } from 'wechaty';
import { generate } from 'qrcode-terminal';
import { PuppetPadpro } from 'wechaty-puppet-padpro';
const puppet = new PuppetPadpro({
token: '{token}',
});
const bot = new Wechaty({
profile: 'test',
puppet
});
bot
.on('scan', (qrcode, status) => {
generate(qrcode, { small: true })
const qrcodeImageUrl = [
'https://api.qrserver.com/v1/create-qr-code/?data=',
encodeURIComponent(qrcode),
].join('')
console.log(`[${status}] ${qrcodeImageUrl}\nScan QR Code above to log in: `)
})
.on('login', async user => {
console.log(`Login: ${user}`);
})
.on('message', async (message: Message) => {
console.log(`Message ${message}`)
})
.on('logout', async user => {
console.log(`Logout: ${user}`)
})
.start()