Instalasi
npm install node-plug
Lalu buat file misalnya plugin.js setelah itu buat kode seperti ini
export const t = { async run() { await console.log('foo') }, } // atau /*const test = 'foo' export const t = { async run() { await console.log(test) }, }*/ // atau /*const test = { run() { console.log('foo') }, } export const t = { async run() { await test.run() }, }*/
Lalu buat file main.js atau index.js
import { addPlugin, runPlugin, test } from 'node-plug' import { t } from './plugin.js' // Menambahkan plugin addPlugin(t) // Menjalankan plugin runPlugin() // Melakukan pengujian test(['bar'])
Kode di atas akan menampilkan:
Tapi jika:
import { addPlugin, runPlugin, test } from 'node-plug' import { t } from './plugin.js' // Menambahkan plugin addPlugin(t) // Menjalankan plugin runPlugin() // Melakukan pengujian test(['foo'])
Maka pengujian berhasil dijalankan
Top comments (0)