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

feat: add a plugin loader #58

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
23 changes: 21 additions & 2 deletions bin.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
#!/usr/bin/env node

import fs from 'fs'
import path from 'path'
import os from 'os'
import sade from 'sade'
import open from 'open'
import { getPkg } from './lib.js'
import { getClient, getPkg } from './lib.js'
import {
accessClaim,
authorize,
Expand Down Expand Up @@ -163,4 +166,20 @@ Run \`$ w3 --help\` for more info.
}
})

cli.parse(process.argv)
async function loadPlugins () {
try {
const dir = path.join(os.homedir(), '.w3cli', 'plugins')
const files = await fs.promises.readdir(dir)
if (!files.length) return

const client = await getClient()
for (const file of files) {
const module = await import(path.join(dir, file, 'index.js'))
await module.plugin(cli, client)
}
} catch (err) {
if (err.code !== 'ENOENT') throw err
}
}

loadPlugins().then(() => cli.parse(process.argv))