@ztffn/presentation-generator-plugin 1.0.5 → 1.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/bin/index.js +65 -17
  2. package/package.json +1 -1
package/bin/index.js CHANGED
@@ -5,6 +5,7 @@ const { execSync } = require("child_process");
5
5
  const fs = require("fs");
6
6
  const path = require("path");
7
7
  const os = require("os");
8
+ const readline = require("readline");
8
9
 
9
10
  const NPM_PACKAGE = "@ztffn/presentation-generator-plugin";
10
11
  const PLUGIN_NAME = "presentation-generator";
@@ -100,14 +101,43 @@ async function downloadAndExtract(version, tarballUrl) {
100
101
  fs.rmSync(tmpDir, { recursive: true, force: true });
101
102
  }
102
103
 
103
- function registerPlugin() {
104
+ function prompt(question) {
105
+ const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
106
+ return new Promise((resolve) => {
107
+ rl.question(question, (answer) => {
108
+ rl.close();
109
+ resolve(answer.trim().toLowerCase());
110
+ });
111
+ });
112
+ }
113
+
114
+ async function resolveSettingsPath() {
115
+ const projectClaudeDir = path.join(process.cwd(), ".claude");
116
+ const userSettingsPath = path.join(os.homedir(), ".claude", "settings.json");
117
+
118
+ if (!fs.existsSync(projectClaudeDir)) {
119
+ return { settingsPath: userSettingsPath, scope: "user" };
120
+ }
121
+
122
+ console.log("\nDetected a .claude/ folder in the current directory.");
123
+ const answer = await prompt(
124
+ "Install for (u) user — available everywhere, or (p) project — this directory only? [u/p]: "
125
+ );
126
+
127
+ if (answer === "p") {
128
+ return {
129
+ settingsPath: path.join(projectClaudeDir, "settings.json"),
130
+ scope: "project",
131
+ };
132
+ }
133
+
134
+ return { settingsPath: userSettingsPath, scope: "user" };
135
+ }
136
+
137
+ async function registerPlugin() {
104
138
  console.log("\nRegistering plugin with Claude Code...");
105
139
 
106
- // Prefer project-level settings if .claude/ exists in cwd, else user-level
107
- const projectDir = path.join(process.cwd(), ".claude");
108
- const settingsPath = fs.existsSync(projectDir)
109
- ? path.join(projectDir, "settings.json")
110
- : path.join(os.homedir(), ".claude", "settings.json");
140
+ const { settingsPath, scope } = await resolveSettingsPath();
111
141
 
112
142
  try {
113
143
  let settings = {};
@@ -126,18 +156,15 @@ function registerPlugin() {
126
156
  fs.mkdirSync(path.dirname(settingsPath), { recursive: true });
127
157
  fs.writeFileSync(settingsPath, JSON.stringify(settings, null, 2) + "\n");
128
158
 
129
- const label = settingsPath.startsWith(process.cwd())
130
- ? ".claude/settings.json"
131
- : settingsPath;
132
- console.log(`Plugin registered in ${label} ✓`);
133
-
134
- if (settingsPath.startsWith(process.cwd())) {
135
- console.log("Commit that file to share the plugin with your team.");
159
+ if (scope === "project") {
160
+ console.log(`Plugin registered in .claude/settings.json ✓`);
161
+ console.log("Commit that file to enable the plugin for your whole team.");
162
+ } else {
163
+ console.log(`Plugin registered in ~/.claude/settings.json ✓`);
164
+ console.log("Available in all your Claude Code sessions.");
136
165
  }
137
166
  } catch {
138
- console.log(
139
- "\nCould not write settings. Add manually to .claude/settings.json:"
140
- );
167
+ console.log("\nCould not write settings. Add manually to ~/.claude/settings.json:");
141
168
  console.log(JSON.stringify({ enabledPlugins: [INSTALL_DIR] }, null, 2));
142
169
  console.log(`\nOr load for a single session:`);
143
170
  console.log(` claude --plugin-dir "${INSTALL_DIR}"`);
@@ -235,13 +262,34 @@ async function checkUpdate() {
235
262
  }
236
263
  }
237
264
 
265
+ function removeFromSettings(settingsPath) {
266
+ if (!fs.existsSync(settingsPath)) return;
267
+ try {
268
+ const settings = JSON.parse(fs.readFileSync(settingsPath, "utf8"));
269
+ if (!Array.isArray(settings.enabledPlugins)) return;
270
+ const before = settings.enabledPlugins.length;
271
+ settings.enabledPlugins = settings.enabledPlugins.filter((p) => p !== INSTALL_DIR);
272
+ if (settings.enabledPlugins.length !== before) {
273
+ fs.writeFileSync(settingsPath, JSON.stringify(settings, null, 2) + "\n");
274
+ console.log(`Removed from ${settingsPath}`);
275
+ }
276
+ } catch {
277
+ // ignore
278
+ }
279
+ }
280
+
238
281
  function uninstall() {
239
282
  if (!fs.existsSync(INSTALL_DIR)) {
240
283
  console.log("\nPlugin not installed.\n");
241
284
  return;
242
285
  }
243
286
  fs.rmSync(INSTALL_DIR, { recursive: true, force: true });
244
- console.log(`\nRemoved: ${INSTALL_DIR}\n`);
287
+ console.log(`\nRemoved: ${INSTALL_DIR}`);
288
+
289
+ // Clean up both possible settings locations
290
+ removeFromSettings(path.join(os.homedir(), ".claude", "settings.json"));
291
+ removeFromSettings(path.join(process.cwd(), ".claude", "settings.json"));
292
+ console.log();
245
293
  }
246
294
 
247
295
  function help() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ztffn/presentation-generator-plugin",
3
- "version": "1.0.5",
3
+ "version": "1.0.6",
4
4
  "description": "Claude Code plugin for generating graph-based presentations",
5
5
  "bin": {
6
6
  "presentation-generator-plugin": "bin/index.js"