Lines 1-54javascript
2 * CLI plugin management: install, remove, list user plugins.
3 * User plugins live in ~/.openwriter/plugins/ with their own package.json and node_modules.
5import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'fs';
6import { join } from 'path';
7import { homedir } from 'os';
8import { execSync } from 'child_process';
9const PLUGINS_DIR = join(homedir(), '.openwriter', 'plugins');
HighChild Process
Package source references child process execution.
dist/server/plugin-install.jsView on unpkg · L7 10const PLUGINS_PKG = join(PLUGINS_DIR, 'package.json');
11const VALID_NAME = /^(@openwriter\/plugin-[\w-]+|openwriter-plugin-[\w-]+|@[\w-]+\/openwriter-plugin-[\w-]+)$/;
12/** Ensure ~/.openwriter/plugins/ exists with a package.json */
13export function ensureUserPluginsDir() {
14 if (!existsSync(PLUGINS_DIR)) {
15 mkdirSync(PLUGINS_DIR, { recursive: true });
17 if (!existsSync(PLUGINS_PKG)) {
18 writeFileSync(PLUGINS_PKG, JSON.stringify({
22 }, null, 2), 'utf-8');
25/** Install a plugin package into the user plugins directory */
26export function installPlugin(packageName) {
27 if (!VALID_NAME.test(packageName)) {
28 console.error(`Invalid plugin name: ${packageName}`);
29 console.error('Plugin names must match: openwriter-plugin-*, @openwriter/plugin-*, or @scope/openwriter-plugin-*');
32 ensureUserPluginsDir();
33 console.error(`Installing ${packageName}...`);
35 execSync(`npm install --save ${packageName}`, {
36 cwd: PLUGINS_DIR,
HighRuntime Package Install
Package source invokes a package manager install command at runtime.
dist/server/plugin-install.jsView on unpkg · L34 39 console.error(`Installed ${packageName} successfully.`);
42 console.error(`Failed to install ${packageName}.`);
46/** Remove a plugin package from the user plugins directory */
47export function removePlugin(packageName) {
48 ensureUserPluginsDir();
49 const pkg = readPkg();
50 if (!pkg.dependencies?.[packageName]) {
51 console.error(`Plugin ${packageName} is not installed.`);
54 console.error(`Removing ${packageName}...`);