mirror of
https://github.com/pockethost/pockethost.git
synced 2026-03-21 15:49:05 +00:00
feat(pockethost): Added plugin template command and updated docs
This commit is contained in:
5
.changeset/1719774712814.md
Normal file
5
.changeset/1719774712814.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'pockethost': minor
|
||||
---
|
||||
|
||||
Added plugin template command and updated docs
|
||||
@@ -10,6 +10,7 @@
|
||||
"czvf",
|
||||
"daos",
|
||||
"Darkmode",
|
||||
"dasherize",
|
||||
"Deallocator",
|
||||
"devcert",
|
||||
"Dockerized",
|
||||
@@ -44,6 +45,7 @@
|
||||
"pbgo",
|
||||
"PBOUNCE",
|
||||
"pexec",
|
||||
"plopfile",
|
||||
"plugified",
|
||||
"pocketbase",
|
||||
"pockethost",
|
||||
|
||||
@@ -36,11 +36,13 @@
|
||||
"get-port": "^6.1.2",
|
||||
"http-proxy": "^1.18.1",
|
||||
"immer": "^10.1.1",
|
||||
"inflection": "^3.0.0",
|
||||
"json-stringify-safe": "^5.0.1",
|
||||
"listr2": "^8.2.3",
|
||||
"minimist": "^1.2.8",
|
||||
"nanoid": "^5.0.2",
|
||||
"node-fetch": "^3.3.2",
|
||||
"node-plop": "^0.32.0",
|
||||
"pocketbase": "^0.21.3",
|
||||
"rimraf": "^5.0.5",
|
||||
"semver": "^7.6.2",
|
||||
|
||||
@@ -11,6 +11,8 @@
|
||||
- [Extending the PocketHost CLI](#extending-the-pockethost-cli)
|
||||
- [Reference](#reference)
|
||||
- [Core Actions](#core-actions)
|
||||
- [AfterPluginsLoaded (since 1.6.0)](#afterpluginsloaded-since-160)
|
||||
- [KillInstance (since 1.6.0)](#killinstance-since-160)
|
||||
- [Core Filters](#core-filters)
|
||||
- [ServerSlugs (since 1.4.0)](#serverslugs-since-140)
|
||||
- [InstanceConfig (since 1.5.0)](#instanceconfig-since-150)
|
||||
@@ -63,6 +65,14 @@ Use PocketHost to generate a Typescript plugin starter, and follow that code.
|
||||
pockethost plugin create <my-plugin-name>
|
||||
```
|
||||
|
||||
Plugin template features:
|
||||
|
||||
- Listen to PocketHost events
|
||||
- Install a PocketBase JS Hooks file when instances launch
|
||||
- Use a local JSON database to store local settings and config
|
||||
- Add custom commands to the PocketHost CLI
|
||||
- Attach to the `serve` PocketHost event
|
||||
|
||||
## Plugin Events Lifecycle
|
||||
|
||||
PocketHost executes many actions and filters that your plugin can access to add, extend, and enhance various features.
|
||||
|
||||
@@ -1,10 +1,19 @@
|
||||
import { Command } from 'commander'
|
||||
import { readFileSync } from 'fs'
|
||||
import { dasherize, underscore } from 'inflection'
|
||||
import nodePlop from 'node-plop'
|
||||
import { dirname } from 'node:path'
|
||||
import { fileURLToPath } from 'node:url'
|
||||
import { join } from 'path'
|
||||
import { cwd } from 'process'
|
||||
import { error, info } from '../..'
|
||||
import { version } from '../../../../package.json'
|
||||
import { PH_PLUGINS, PH_PROJECT_DIR } from '../../../constants'
|
||||
import { appendConfig, filterConfig } from '../../../core'
|
||||
import { getCompatibleVersions, getPackageJson, removePackage } from './util'
|
||||
|
||||
const __dirname = dirname(fileURLToPath(import.meta.url))
|
||||
|
||||
export const PluginCommand = () => {
|
||||
const cmd = new Command(`plugin`)
|
||||
.description(`Manage PocketHost plugins`)
|
||||
@@ -77,5 +86,28 @@ export const PluginCommand = () => {
|
||||
}
|
||||
}),
|
||||
)
|
||||
|
||||
.addCommand(
|
||||
new Command(`create`)
|
||||
.description(`Create a new plugin`)
|
||||
.alias(`new`)
|
||||
.alias(`n`)
|
||||
.alias(`make`)
|
||||
.alias(`generate`)
|
||||
.argument(`<name>`, `Plugin name (dash case)`)
|
||||
.action(async (name) => {
|
||||
const dashCase = dasherize(underscore(name))
|
||||
const plopfilePath = join(__dirname, 'plopfile.mjs')
|
||||
const plopInstance = await nodePlop(plopfilePath, {
|
||||
destBasePath: cwd(),
|
||||
force: false,
|
||||
})
|
||||
const generator = plopInstance.getGenerator('plugin')
|
||||
const results = await generator.runActions({
|
||||
name: dashCase,
|
||||
version,
|
||||
})
|
||||
}),
|
||||
)
|
||||
return cmd
|
||||
}
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
import { execSync } from 'child_process'
|
||||
import { dirname, join } from 'path'
|
||||
import { fileURLToPath } from 'url'
|
||||
|
||||
const __dirname = dirname(fileURLToPath(import.meta.url))
|
||||
|
||||
/** @typedef {import('plop').NodePlopAPI} Plop */
|
||||
|
||||
export default function (/** @type {Plop} */ plop) {
|
||||
plop.setGenerator('plugin', {
|
||||
description: 'Generate a new plugin',
|
||||
prompts: [
|
||||
{
|
||||
type: 'input',
|
||||
name: 'name',
|
||||
message: 'Plugin Name (dash case)',
|
||||
},
|
||||
{
|
||||
type: 'input',
|
||||
name: 'version',
|
||||
message: 'PocketHost base version',
|
||||
},
|
||||
],
|
||||
actions: (data) => {
|
||||
return [
|
||||
{
|
||||
type: 'addMany',
|
||||
destination: 'plugin-{{dashCase name}}',
|
||||
base: join(__dirname, 'plugin-template'),
|
||||
templateFiles: join(__dirname, `plugin-template/**/*`),
|
||||
},
|
||||
async () => {
|
||||
console.log(execSync(`pnpm i`).toString())
|
||||
},
|
||||
]
|
||||
},
|
||||
})
|
||||
}
|
||||
25
plopfile.mjs
25
plopfile.mjs
@@ -185,29 +185,4 @@ export default function (/** @type {Plop} */ plop) {
|
||||
]
|
||||
},
|
||||
})
|
||||
|
||||
plop.setGenerator('plugin', {
|
||||
description: 'Generate a new plugin',
|
||||
prompts: [
|
||||
{
|
||||
type: 'input',
|
||||
name: 'name',
|
||||
message: 'Plugin Name (dash case)',
|
||||
},
|
||||
],
|
||||
actions: (data) => {
|
||||
data.version = version
|
||||
return [
|
||||
{
|
||||
type: 'addMany',
|
||||
destination: 'packages/plugin-{{dashCase name}}',
|
||||
base: 'plop-templates/plugin-template',
|
||||
templateFiles: `plop-templates/plugin-template/**/*`,
|
||||
},
|
||||
async () => {
|
||||
console.log(execSync(`pnpm i`).toString())
|
||||
},
|
||||
]
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
8
pnpm-lock.yaml
generated
8
pnpm-lock.yaml
generated
@@ -163,7 +163,7 @@ importers:
|
||||
specifier: ^3.0.0
|
||||
version: 3.0.0
|
||||
pockethost:
|
||||
specifier: workspace:^1.5.0
|
||||
specifier: workspace:^1.6.0
|
||||
version: link:../pockethost
|
||||
devDependencies:
|
||||
'@types/node':
|
||||
@@ -352,6 +352,9 @@ importers:
|
||||
immer:
|
||||
specifier: ^10.1.1
|
||||
version: 10.1.1
|
||||
inflection:
|
||||
specifier: ^3.0.0
|
||||
version: 3.0.0
|
||||
json-stringify-safe:
|
||||
specifier: ^5.0.1
|
||||
version: 5.0.1
|
||||
@@ -367,6 +370,9 @@ importers:
|
||||
node-fetch:
|
||||
specifier: ^3.3.2
|
||||
version: 3.3.2
|
||||
node-plop:
|
||||
specifier: ^0.32.0
|
||||
version: 0.32.0
|
||||
pocketbase:
|
||||
specifier: ^0.21.3
|
||||
version: 0.21.3
|
||||
|
||||
Reference in New Issue
Block a user