apostil 0.1.1 → 0.1.3

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.
@@ -0,0 +1,293 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ var __create = Object.create;
4
+ var __defProp = Object.defineProperty;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getProtoOf = Object.getPrototypeOf;
8
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
18
+ // If the importer is in node compatibility mode or this is not an ESM
19
+ // file that has been converted to a CommonJS file using a Babel-
20
+ // compatible transform (i.e. "__esModule" has not been set), then set
21
+ // "default" to the CommonJS "module.exports" for node compatibility.
22
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
23
+ mod
24
+ ));
25
+
26
+ // src/cli/index.ts
27
+ var import_promises = __toESM(require("fs/promises"), 1);
28
+ var import_path = __toESM(require("path"), 1);
29
+ var args = process.argv.slice(2);
30
+ var command = args[0];
31
+ if (command === "init") {
32
+ const mode = parseMode(args.slice(1));
33
+ init(mode);
34
+ } else if (command === "remove") {
35
+ remove();
36
+ } else if (command === "help" || command === "--help" || command === "-h" || !command) {
37
+ printHelp();
38
+ } else {
39
+ console.log(` Unknown command: ${command}
40
+ `);
41
+ printHelp();
42
+ }
43
+ function parseMode(flags) {
44
+ if (flags.includes("--dev")) return "dev";
45
+ if (flags.includes("--public")) return "public";
46
+ return "personal";
47
+ }
48
+ function printHelp() {
49
+ console.log(`
50
+ apostil \u2014 Pin-and-comment feedback for React & Next.js
51
+
52
+ Usage:
53
+ npx apostil init [mode] Set up apostil in your Next.js project
54
+ npx apostil remove Remove apostil from your project
55
+ npx apostil help Show this help
56
+
57
+ Modes:
58
+ (default) Personal \u2014 local dev only, comments gitignored
59
+ --dev Dev + staging \u2014 comments gitignored, env-controlled
60
+ --public All environments \u2014 comments committed to git
61
+ `);
62
+ }
63
+ async function init(mode) {
64
+ const cwd = process.cwd();
65
+ const appDir = await findAppDir(cwd);
66
+ if (!appDir) {
67
+ console.log(" Could not find a Next.js app/ directory.");
68
+ console.log(" Make sure you're running this from your project root.\n");
69
+ process.exit(1);
70
+ }
71
+ const useSrc = appDir.includes("src/app");
72
+ const modeLabel = mode === "personal" ? "personal" : mode === "dev" ? "dev" : "public";
73
+ console.log(`
74
+ Setting up apostil (${modeLabel} mode)...
75
+ `);
76
+ const apiDir = import_path.default.join(appDir, "api", "apostil");
77
+ const apiFile = import_path.default.join(apiDir, "route.ts");
78
+ if (await fileExists(apiFile)) {
79
+ console.log(" \u2713 API route already exists");
80
+ } else {
81
+ await import_promises.default.mkdir(apiDir, { recursive: true });
82
+ await import_promises.default.writeFile(
83
+ apiFile,
84
+ `export { GET, POST } from "apostil/adapters/nextjs";
85
+ `,
86
+ "utf-8"
87
+ );
88
+ console.log(` \u2713 Created ${rel(cwd, apiFile)}`);
89
+ }
90
+ const componentsDir = import_path.default.join(cwd, useSrc ? "src/components" : "components");
91
+ const wrapperFile = import_path.default.join(componentsDir, "apostil-wrapper.tsx");
92
+ await import_promises.default.mkdir(componentsDir, { recursive: true });
93
+ await import_promises.default.writeFile(wrapperFile, getWrapperComponent(mode), "utf-8");
94
+ console.log(` \u2713 Created ${rel(cwd, wrapperFile)} (${modeLabel} mode)`);
95
+ const commentsDir = import_path.default.join(cwd, ".apostil");
96
+ await import_promises.default.mkdir(commentsDir, { recursive: true });
97
+ console.log(" \u2713 Created .apostil/ directory");
98
+ const gitignorePath = import_path.default.join(cwd, ".gitignore");
99
+ let gitignore = "";
100
+ try {
101
+ gitignore = await import_promises.default.readFile(gitignorePath, "utf-8");
102
+ } catch {
103
+ }
104
+ if (mode === "public") {
105
+ if (gitignore.includes(".apostil")) {
106
+ console.log(" \u2713 .gitignore unchanged (public mode \u2014 comments will be committed)");
107
+ } else {
108
+ console.log(" \u2713 Comments will be committed to git (public mode)");
109
+ }
110
+ } else {
111
+ if (!gitignore.includes(".apostil")) {
112
+ const entry = "\n# Apostil comments\n.apostil/\n";
113
+ await import_promises.default.appendFile(gitignorePath, entry, "utf-8");
114
+ console.log(" \u2713 Added .apostil/ to .gitignore");
115
+ } else {
116
+ console.log(" \u2713 .gitignore already configured");
117
+ }
118
+ }
119
+ const layoutInjected = await injectIntoLayout(appDir, useSrc);
120
+ if (layoutInjected) {
121
+ console.log(" \u2713 Added <ApostilWrapper> to root layout");
122
+ }
123
+ console.log("\n Done! Run your dev server and press C to start commenting.\n");
124
+ }
125
+ async function remove() {
126
+ const cwd = process.cwd();
127
+ const appDir = await findAppDir(cwd);
128
+ const useSrc = appDir?.includes("src/app") ?? false;
129
+ console.log("\n Removing apostil...\n");
130
+ if (appDir) {
131
+ const apiDir = import_path.default.join(appDir, "api", "apostil");
132
+ if (await fileExists(import_path.default.join(apiDir, "route.ts"))) {
133
+ await import_promises.default.rm(apiDir, { recursive: true });
134
+ console.log(" \u2713 Removed API route");
135
+ }
136
+ }
137
+ const componentsDir = import_path.default.join(cwd, useSrc ? "src/components" : "components");
138
+ const wrapperFile = import_path.default.join(componentsDir, "apostil-wrapper.tsx");
139
+ if (await fileExists(wrapperFile)) {
140
+ await import_promises.default.rm(wrapperFile);
141
+ console.log(" \u2713 Removed wrapper component");
142
+ }
143
+ if (appDir) {
144
+ const unwrapped = await removeFromLayout(appDir);
145
+ if (unwrapped) {
146
+ console.log(" \u2713 Removed <ApostilWrapper> from root layout");
147
+ }
148
+ }
149
+ const commentsDir = import_path.default.join(cwd, ".apostil");
150
+ if (await fileExists(commentsDir)) {
151
+ await import_promises.default.rm(commentsDir, { recursive: true });
152
+ console.log(" \u2713 Removed .apostil/ directory");
153
+ }
154
+ const gitignorePath = import_path.default.join(cwd, ".gitignore");
155
+ try {
156
+ let gitignore = await import_promises.default.readFile(gitignorePath, "utf-8");
157
+ gitignore = gitignore.replace(/\n?# Apostil comments\n\.apostil\/\n?/g, "");
158
+ await import_promises.default.writeFile(gitignorePath, gitignore, "utf-8");
159
+ console.log(" \u2713 Cleaned .gitignore");
160
+ } catch {
161
+ }
162
+ console.log(`
163
+ Done! Now run: npm uninstall apostil
164
+ `);
165
+ }
166
+ function getWrapperComponent(mode) {
167
+ const envGuard = mode === "personal" ? `
168
+ // Personal mode \u2014 only active in local development
169
+ if (process.env.NODE_ENV !== "development") {
170
+ return <>{children}</>;
171
+ }
172
+ ` : mode === "dev" ? `
173
+ // Dev mode \u2014 active in dev + staging, disabled in production
174
+ // Set NEXT_PUBLIC_APOSTIL=true to force on in any environment
175
+ const forceOn = process.env.NEXT_PUBLIC_APOSTIL === "true";
176
+ if (process.env.NODE_ENV === "production" && !forceOn) {
177
+ return <>{children}</>;
178
+ }
179
+ ` : `
180
+ // Public mode \u2014 active in all environments
181
+ // Set NEXT_PUBLIC_APOSTIL=false to disable
182
+ if (process.env.NEXT_PUBLIC_APOSTIL === "false") {
183
+ return <>{children}</>;
184
+ }
185
+ `;
186
+ return `"use client";
187
+
188
+ import { usePathname } from "next/navigation";
189
+ import {
190
+ ApostilProvider,
191
+ CommentOverlay,
192
+ CommentToggle,
193
+ CommentSidebar,
194
+ } from "apostil";
195
+
196
+ export function ApostilWrapper({ children }: { children: React.ReactNode }) {${envGuard}
197
+ const pathname = usePathname();
198
+ const pageId = pathname.replace(/\\//g, "--").replace(/^--/, "") || "home";
199
+
200
+ return (
201
+ <ApostilProvider pageId={pageId}>
202
+ {children}
203
+ <CommentOverlay />
204
+ <CommentSidebar />
205
+ <CommentToggle />
206
+ </ApostilProvider>
207
+ );
208
+ }
209
+ `;
210
+ }
211
+ async function injectIntoLayout(appDir, useSrc) {
212
+ const layoutPath = await findLayout(appDir);
213
+ if (!layoutPath) return false;
214
+ let content = await import_promises.default.readFile(layoutPath, "utf-8");
215
+ if (content.includes("ApostilWrapper")) {
216
+ console.log(" \u2713 Layout already has <ApostilWrapper>");
217
+ return false;
218
+ }
219
+ const importPath = useSrc ? "@/components/apostil-wrapper" : "../components/apostil-wrapper";
220
+ const importLine = `import { ApostilWrapper } from "${importPath}";
221
+ `;
222
+ const importRegex = /^import\s.+$/gm;
223
+ let lastImportIndex = 0;
224
+ let match;
225
+ while ((match = importRegex.exec(content)) !== null) {
226
+ lastImportIndex = match.index + match[0].length;
227
+ }
228
+ if (lastImportIndex > 0) {
229
+ content = content.slice(0, lastImportIndex) + "\n" + importLine + content.slice(lastImportIndex);
230
+ } else {
231
+ const useDirective = content.match(/^["']use (client|server)["'];?\n/);
232
+ const insertAt = useDirective ? useDirective[0].length : 0;
233
+ content = content.slice(0, insertAt) + importLine + content.slice(insertAt);
234
+ }
235
+ const bodyChildrenRegex = /(<body[^>]*>)([\s\S]*?)(\{[\s]*children[\s]*\})([\s\S]*?)(<\/body>)/;
236
+ const bodyMatch = content.match(bodyChildrenRegex);
237
+ if (bodyMatch) {
238
+ content = content.replace(
239
+ bodyChildrenRegex,
240
+ `$1$2<ApostilWrapper>$3</ApostilWrapper>$4$5`
241
+ );
242
+ } else {
243
+ const childrenRegex = /(\{[\s]*children[\s]*\})/;
244
+ if (childrenRegex.test(content)) {
245
+ content = content.replace(childrenRegex, `<ApostilWrapper>$1</ApostilWrapper>`);
246
+ } else {
247
+ console.log(" \u26A0 Could not find {children} in layout \u2014 add <ApostilWrapper> manually");
248
+ return false;
249
+ }
250
+ }
251
+ await import_promises.default.writeFile(layoutPath, content, "utf-8");
252
+ return true;
253
+ }
254
+ async function removeFromLayout(appDir) {
255
+ const layoutPath = await findLayout(appDir);
256
+ if (!layoutPath) return false;
257
+ let content = await import_promises.default.readFile(layoutPath, "utf-8");
258
+ if (!content.includes("ApostilWrapper")) return false;
259
+ content = content.replace(/import\s*\{[^}]*ApostilWrapper[^}]*\}\s*from\s*["'][^"']+["'];?\n?/g, "");
260
+ content = content.replace(/<ApostilWrapper>([\s\S]*?)<\/ApostilWrapper>/g, "$1");
261
+ await import_promises.default.writeFile(layoutPath, content, "utf-8");
262
+ return true;
263
+ }
264
+ async function findAppDir(cwd) {
265
+ for (const candidate of ["src/app", "app"]) {
266
+ const dir = import_path.default.join(cwd, candidate);
267
+ try {
268
+ const stat = await import_promises.default.stat(dir);
269
+ if (stat.isDirectory()) return dir;
270
+ } catch {
271
+ }
272
+ }
273
+ return null;
274
+ }
275
+ async function findLayout(appDir) {
276
+ for (const ext of ["tsx", "jsx", "ts", "js"]) {
277
+ const file = import_path.default.join(appDir, `layout.${ext}`);
278
+ if (await fileExists(file)) return file;
279
+ }
280
+ return null;
281
+ }
282
+ async function fileExists(p) {
283
+ try {
284
+ await import_promises.default.stat(p);
285
+ return true;
286
+ } catch {
287
+ return false;
288
+ }
289
+ }
290
+ function rel(cwd, filePath) {
291
+ return import_path.default.relative(cwd, filePath);
292
+ }
293
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/cli/index.ts"],"sourcesContent":["#!/usr/bin/env node\n\nimport fs from \"fs/promises\";\nimport path from \"path\";\n\ntype Mode = \"personal\" | \"dev\" | \"public\";\n\nconst args = process.argv.slice(2);\nconst command = args[0];\n\nif (command === \"init\") {\n const mode = parseMode(args.slice(1));\n init(mode);\n} else if (command === \"remove\") {\n remove();\n} else if (command === \"help\" || command === \"--help\" || command === \"-h\" || !command) {\n printHelp();\n} else {\n console.log(` Unknown command: ${command}\\n`);\n printHelp();\n}\n\nfunction parseMode(flags: string[]): Mode {\n if (flags.includes(\"--dev\")) return \"dev\";\n if (flags.includes(\"--public\")) return \"public\";\n return \"personal\";\n}\n\nfunction printHelp() {\n console.log(`\n apostil — Pin-and-comment feedback for React & Next.js\n\n Usage:\n npx apostil init [mode] Set up apostil in your Next.js project\n npx apostil remove Remove apostil from your project\n npx apostil help Show this help\n\n Modes:\n (default) Personal — local dev only, comments gitignored\n --dev Dev + staging — comments gitignored, env-controlled\n --public All environments — comments committed to git\n`);\n}\n\nasync function init(mode: Mode) {\n const cwd = process.cwd();\n\n // Detect Next.js app directory\n const appDir = await findAppDir(cwd);\n if (!appDir) {\n console.log(\" Could not find a Next.js app/ directory.\");\n console.log(\" Make sure you're running this from your project root.\\n\");\n process.exit(1);\n }\n\n // Detect src/ prefix\n const useSrc = appDir.includes(\"src/app\");\n\n const modeLabel = mode === \"personal\" ? \"personal\" : mode === \"dev\" ? \"dev\" : \"public\";\n console.log(`\\n Setting up apostil (${modeLabel} mode)...\\n`);\n\n // 1. Create API route\n const apiDir = path.join(appDir, \"api\", \"apostil\");\n const apiFile = path.join(apiDir, \"route.ts\");\n if (await fileExists(apiFile)) {\n console.log(\" ✓ API route already exists\");\n } else {\n await fs.mkdir(apiDir, { recursive: true });\n await fs.writeFile(\n apiFile,\n `export { GET, POST } from \"apostil/adapters/nextjs\";\\n`,\n \"utf-8\"\n );\n console.log(` ✓ Created ${rel(cwd, apiFile)}`);\n }\n\n // 2. Create wrapper component\n const componentsDir = path.join(cwd, useSrc ? \"src/components\" : \"components\");\n const wrapperFile = path.join(componentsDir, \"apostil-wrapper.tsx\");\n await fs.mkdir(componentsDir, { recursive: true });\n await fs.writeFile(wrapperFile, getWrapperComponent(mode), \"utf-8\");\n console.log(` ✓ Created ${rel(cwd, wrapperFile)} (${modeLabel} mode)`);\n\n // 3. Create .apostil/ directory for comment storage\n const commentsDir = path.join(cwd, \".apostil\");\n await fs.mkdir(commentsDir, { recursive: true });\n console.log(\" ✓ Created .apostil/ directory\");\n\n // 4. Handle .gitignore based on mode\n const gitignorePath = path.join(cwd, \".gitignore\");\n let gitignore = \"\";\n try {\n gitignore = await fs.readFile(gitignorePath, \"utf-8\");\n } catch {}\n\n if (mode === \"public\") {\n // Public mode: don't gitignore comments — they get committed\n if (gitignore.includes(\".apostil\")) {\n console.log(\" ✓ .gitignore unchanged (public mode — comments will be committed)\");\n } else {\n console.log(\" ✓ Comments will be committed to git (public mode)\");\n }\n } else {\n // Personal & dev: gitignore comments\n if (!gitignore.includes(\".apostil\")) {\n const entry = \"\\n# Apostil comments\\n.apostil/\\n\";\n await fs.appendFile(gitignorePath, entry, \"utf-8\");\n console.log(\" ✓ Added .apostil/ to .gitignore\");\n } else {\n console.log(\" ✓ .gitignore already configured\");\n }\n }\n\n // 5. Inject wrapper into root layout\n const layoutInjected = await injectIntoLayout(appDir, useSrc);\n if (layoutInjected) {\n console.log(\" ✓ Added <ApostilWrapper> to root layout\");\n }\n\n console.log(\"\\n Done! Run your dev server and press C to start commenting.\\n\");\n}\n\nasync function remove() {\n const cwd = process.cwd();\n const appDir = await findAppDir(cwd);\n const useSrc = appDir?.includes(\"src/app\") ?? false;\n\n console.log(\"\\n Removing apostil...\\n\");\n\n // 1. Remove API route\n if (appDir) {\n const apiDir = path.join(appDir, \"api\", \"apostil\");\n if (await fileExists(path.join(apiDir, \"route.ts\"))) {\n await fs.rm(apiDir, { recursive: true });\n console.log(\" ✓ Removed API route\");\n }\n }\n\n // 2. Remove wrapper component\n const componentsDir = path.join(cwd, useSrc ? \"src/components\" : \"components\");\n const wrapperFile = path.join(componentsDir, \"apostil-wrapper.tsx\");\n if (await fileExists(wrapperFile)) {\n await fs.rm(wrapperFile);\n console.log(\" ✓ Removed wrapper component\");\n }\n\n // 3. Remove wrapper from layout\n if (appDir) {\n const unwrapped = await removeFromLayout(appDir);\n if (unwrapped) {\n console.log(\" ✓ Removed <ApostilWrapper> from root layout\");\n }\n }\n\n // 4. Remove .apostil/ directory\n const commentsDir = path.join(cwd, \".apostil\");\n if (await fileExists(commentsDir)) {\n await fs.rm(commentsDir, { recursive: true });\n console.log(\" ✓ Removed .apostil/ directory\");\n }\n\n // 5. Remove from .gitignore\n const gitignorePath = path.join(cwd, \".gitignore\");\n try {\n let gitignore = await fs.readFile(gitignorePath, \"utf-8\");\n gitignore = gitignore.replace(/\\n?# Apostil comments\\n\\.apostil\\/\\n?/g, \"\");\n await fs.writeFile(gitignorePath, gitignore, \"utf-8\");\n console.log(\" ✓ Cleaned .gitignore\");\n } catch {}\n\n console.log(`\n Done! Now run: npm uninstall apostil\n`);\n}\n\n// --- Wrapper component template ---\n\nfunction getWrapperComponent(mode: Mode): string {\n const envGuard = mode === \"personal\"\n ? `\n // Personal mode — only active in local development\n if (process.env.NODE_ENV !== \"development\") {\n return <>{children}</>;\n }\n`\n : mode === \"dev\"\n ? `\n // Dev mode — active in dev + staging, disabled in production\n // Set NEXT_PUBLIC_APOSTIL=true to force on in any environment\n const forceOn = process.env.NEXT_PUBLIC_APOSTIL === \"true\";\n if (process.env.NODE_ENV === \"production\" && !forceOn) {\n return <>{children}</>;\n }\n`\n : `\n // Public mode — active in all environments\n // Set NEXT_PUBLIC_APOSTIL=false to disable\n if (process.env.NEXT_PUBLIC_APOSTIL === \"false\") {\n return <>{children}</>;\n }\n`;\n\n return `\"use client\";\n\nimport { usePathname } from \"next/navigation\";\nimport {\n ApostilProvider,\n CommentOverlay,\n CommentToggle,\n CommentSidebar,\n} from \"apostil\";\n\nexport function ApostilWrapper({ children }: { children: React.ReactNode }) {${envGuard}\n const pathname = usePathname();\n const pageId = pathname.replace(/\\\\//g, \"--\").replace(/^--/, \"\") || \"home\";\n\n return (\n <ApostilProvider pageId={pageId}>\n {children}\n <CommentOverlay />\n <CommentSidebar />\n <CommentToggle />\n </ApostilProvider>\n );\n}\n`;\n}\n\n// --- Layout injection ---\n\nasync function injectIntoLayout(appDir: string, useSrc: boolean): Promise<boolean> {\n const layoutPath = await findLayout(appDir);\n if (!layoutPath) return false;\n\n let content = await fs.readFile(layoutPath, \"utf-8\");\n\n // Skip if already injected\n if (content.includes(\"ApostilWrapper\")) {\n console.log(\" ✓ Layout already has <ApostilWrapper>\");\n return false;\n }\n\n // Add import at the top (after existing imports or \"use\" directives)\n const importPath = useSrc ? \"@/components/apostil-wrapper\" : \"../components/apostil-wrapper\";\n const importLine = `import { ApostilWrapper } from \"${importPath}\";\\n`;\n\n // Find the last import statement and insert after it\n const importRegex = /^import\\s.+$/gm;\n let lastImportIndex = 0;\n let match: RegExpExecArray | null;\n while ((match = importRegex.exec(content)) !== null) {\n lastImportIndex = match.index + match[0].length;\n }\n\n if (lastImportIndex > 0) {\n content = content.slice(0, lastImportIndex) + \"\\n\" + importLine + content.slice(lastImportIndex);\n } else {\n // No imports found, add at the top (after \"use client\" or \"use server\" if present)\n const useDirective = content.match(/^[\"']use (client|server)[\"'];?\\n/);\n const insertAt = useDirective ? useDirective[0].length : 0;\n content = content.slice(0, insertAt) + importLine + content.slice(insertAt);\n }\n\n // Wrap {children} with <ApostilWrapper>\n // Handle both {children} and { children } patterns inside <body>\n const bodyChildrenRegex = /(<body[^>]*>)([\\s\\S]*?)(\\{[\\s]*children[\\s]*\\})([\\s\\S]*?)(<\\/body>)/;\n const bodyMatch = content.match(bodyChildrenRegex);\n\n if (bodyMatch) {\n content = content.replace(\n bodyChildrenRegex,\n `$1$2<ApostilWrapper>$3</ApostilWrapper>$4$5`\n );\n } else {\n // Fallback: try to find {children} anywhere and wrap it\n const childrenRegex = /(\\{[\\s]*children[\\s]*\\})/;\n if (childrenRegex.test(content)) {\n content = content.replace(childrenRegex, `<ApostilWrapper>$1</ApostilWrapper>`);\n } else {\n console.log(\" ⚠ Could not find {children} in layout — add <ApostilWrapper> manually\");\n return false;\n }\n }\n\n await fs.writeFile(layoutPath, content, \"utf-8\");\n return true;\n}\n\nasync function removeFromLayout(appDir: string): Promise<boolean> {\n const layoutPath = await findLayout(appDir);\n if (!layoutPath) return false;\n\n let content = await fs.readFile(layoutPath, \"utf-8\");\n\n if (!content.includes(\"ApostilWrapper\")) return false;\n\n // Remove import line\n content = content.replace(/import\\s*\\{[^}]*ApostilWrapper[^}]*\\}\\s*from\\s*[\"'][^\"']+[\"'];?\\n?/g, \"\");\n\n // Unwrap <ApostilWrapper>{children}</ApostilWrapper>\n content = content.replace(/<ApostilWrapper>([\\s\\S]*?)<\\/ApostilWrapper>/g, \"$1\");\n\n await fs.writeFile(layoutPath, content, \"utf-8\");\n return true;\n}\n\n// --- Helpers ---\n\nasync function findAppDir(cwd: string): Promise<string | null> {\n for (const candidate of [\"src/app\", \"app\"]) {\n const dir = path.join(cwd, candidate);\n try {\n const stat = await fs.stat(dir);\n if (stat.isDirectory()) return dir;\n } catch {}\n }\n return null;\n}\n\nasync function findLayout(appDir: string): Promise<string | null> {\n for (const ext of [\"tsx\", \"jsx\", \"ts\", \"js\"]) {\n const file = path.join(appDir, `layout.${ext}`);\n if (await fileExists(file)) return file;\n }\n return null;\n}\n\nasync function fileExists(p: string): Promise<boolean> {\n try {\n await fs.stat(p);\n return true;\n } catch {\n return false;\n }\n}\n\nfunction rel(cwd: string, filePath: string): string {\n return path.relative(cwd, filePath);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,sBAAe;AACf,kBAAiB;AAIjB,IAAM,OAAO,QAAQ,KAAK,MAAM,CAAC;AACjC,IAAM,UAAU,KAAK,CAAC;AAEtB,IAAI,YAAY,QAAQ;AACtB,QAAM,OAAO,UAAU,KAAK,MAAM,CAAC,CAAC;AACpC,OAAK,IAAI;AACX,WAAW,YAAY,UAAU;AAC/B,SAAO;AACT,WAAW,YAAY,UAAU,YAAY,YAAY,YAAY,QAAQ,CAAC,SAAS;AACrF,YAAU;AACZ,OAAO;AACL,UAAQ,IAAI,sBAAsB,OAAO;AAAA,CAAI;AAC7C,YAAU;AACZ;AAEA,SAAS,UAAU,OAAuB;AACxC,MAAI,MAAM,SAAS,OAAO,EAAG,QAAO;AACpC,MAAI,MAAM,SAAS,UAAU,EAAG,QAAO;AACvC,SAAO;AACT;AAEA,SAAS,YAAY;AACnB,UAAQ,IAAI;AAAA;AAAA;AAAA;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,MAAI,CAAC,QAAQ,SAAS,gBAAgB,EAAG,QAAO;AAGhD,YAAU,QAAQ,QAAQ,uEAAuE,EAAE;AAGnG,YAAU,QAAQ,QAAQ,iDAAiD,IAAI;AAE/E,QAAM,gBAAAA,QAAG,UAAU,YAAY,SAAS,OAAO;AAC/C,SAAO;AACT;AAIA,eAAe,WAAW,KAAqC;AAC7D,aAAW,aAAa,CAAC,WAAW,KAAK,GAAG;AAC1C,UAAM,MAAM,YAAAD,QAAK,KAAK,KAAK,SAAS;AACpC,QAAI;AACF,YAAM,OAAO,MAAM,gBAAAC,QAAG,KAAK,GAAG;AAC9B,UAAI,KAAK,YAAY,EAAG,QAAO;AAAA,IACjC,QAAQ;AAAA,IAAC;AAAA,EACX;AACA,SAAO;AACT;AAEA,eAAe,WAAW,QAAwC;AAChE,aAAW,OAAO,CAAC,OAAO,OAAO,MAAM,IAAI,GAAG;AAC5C,UAAM,OAAO,YAAAD,QAAK,KAAK,QAAQ,UAAU,GAAG,EAAE;AAC9C,QAAI,MAAM,WAAW,IAAI,EAAG,QAAO;AAAA,EACrC;AACA,SAAO;AACT;AAEA,eAAe,WAAW,GAA6B;AACrD,MAAI;AACF,UAAM,gBAAAC,QAAG,KAAK,CAAC;AACf,WAAO;AAAA,EACT,QAAQ;AACN,WAAO;AAAA,EACT;AACF;AAEA,SAAS,IAAI,KAAa,UAA0B;AAClD,SAAO,YAAAD,QAAK,SAAS,KAAK,QAAQ;AACpC;","names":["path","fs"]}
@@ -0,0 +1 @@
1
+ #!/usr/bin/env node
package/dist/cli/index.js CHANGED
@@ -6,7 +6,8 @@ import path from "path";
6
6
  var args = process.argv.slice(2);
7
7
  var command = args[0];
8
8
  if (command === "init") {
9
- init();
9
+ const mode = parseMode(args.slice(1));
10
+ init(mode);
10
11
  } else if (command === "remove") {
11
12
  remove();
12
13
  } else if (command === "help" || command === "--help" || command === "-h" || !command) {
@@ -16,17 +17,27 @@ if (command === "init") {
16
17
  `);
17
18
  printHelp();
18
19
  }
20
+ function parseMode(flags) {
21
+ if (flags.includes("--dev")) return "dev";
22
+ if (flags.includes("--public")) return "public";
23
+ return "personal";
24
+ }
19
25
  function printHelp() {
20
26
  console.log(`
21
27
  apostil \u2014 Pin-and-comment feedback for React & Next.js
22
28
 
23
29
  Usage:
24
- npx apostil init Set up apostil in your Next.js project
25
- npx apostil remove Remove apostil from your project
26
- npx apostil help Show this help
30
+ npx apostil init [mode] Set up apostil in your Next.js project
31
+ npx apostil remove Remove apostil from your project
32
+ npx apostil help Show this help
33
+
34
+ Modes:
35
+ (default) Personal \u2014 local dev only, comments gitignored
36
+ --dev Dev + staging \u2014 comments gitignored, env-controlled
37
+ --public All environments \u2014 comments committed to git
27
38
  `);
28
39
  }
29
- async function init() {
40
+ async function init(mode) {
30
41
  const cwd = process.cwd();
31
42
  const appDir = await findAppDir(cwd);
32
43
  if (!appDir) {
@@ -35,7 +46,10 @@ async function init() {
35
46
  process.exit(1);
36
47
  }
37
48
  const useSrc = appDir.includes("src/app");
38
- console.log("\n Setting up apostil...\n");
49
+ const modeLabel = mode === "personal" ? "personal" : mode === "dev" ? "dev" : "public";
50
+ console.log(`
51
+ Setting up apostil (${modeLabel} mode)...
52
+ `);
39
53
  const apiDir = path.join(appDir, "api", "apostil");
40
54
  const apiFile = path.join(apiDir, "route.ts");
41
55
  if (await fileExists(apiFile)) {
@@ -48,17 +62,13 @@ async function init() {
48
62
  `,
49
63
  "utf-8"
50
64
  );
51
- console.log(" \u2713 Created ${rel(cwd, apiFile)}");
65
+ console.log(` \u2713 Created ${rel(cwd, apiFile)}`);
52
66
  }
53
67
  const componentsDir = path.join(cwd, useSrc ? "src/components" : "components");
54
68
  const wrapperFile = path.join(componentsDir, "apostil-wrapper.tsx");
55
- if (await fileExists(wrapperFile)) {
56
- console.log(" \u2713 Wrapper component already exists");
57
- } else {
58
- await fs.mkdir(componentsDir, { recursive: true });
59
- await fs.writeFile(wrapperFile, getWrapperComponent(), "utf-8");
60
- console.log(` \u2713 Created ${rel(cwd, wrapperFile)}`);
61
- }
69
+ await fs.mkdir(componentsDir, { recursive: true });
70
+ await fs.writeFile(wrapperFile, getWrapperComponent(mode), "utf-8");
71
+ console.log(` \u2713 Created ${rel(cwd, wrapperFile)} (${modeLabel} mode)`);
62
72
  const commentsDir = path.join(cwd, ".apostil");
63
73
  await fs.mkdir(commentsDir, { recursive: true });
64
74
  console.log(" \u2713 Created .apostil/ directory");
@@ -68,16 +78,24 @@ async function init() {
68
78
  gitignore = await fs.readFile(gitignorePath, "utf-8");
69
79
  } catch {
70
80
  }
71
- if (!gitignore.includes(".apostil")) {
72
- const entry = "\n# Apostil comments\n.apostil/\n";
73
- await fs.appendFile(gitignorePath, entry, "utf-8");
74
- console.log(" \u2713 Added .apostil/ to .gitignore");
81
+ if (mode === "public") {
82
+ if (gitignore.includes(".apostil")) {
83
+ console.log(" \u2713 .gitignore unchanged (public mode \u2014 comments will be committed)");
84
+ } else {
85
+ console.log(" \u2713 Comments will be committed to git (public mode)");
86
+ }
75
87
  } else {
76
- console.log(" \u2713 .gitignore already configured");
88
+ if (!gitignore.includes(".apostil")) {
89
+ const entry = "\n# Apostil comments\n.apostil/\n";
90
+ await fs.appendFile(gitignorePath, entry, "utf-8");
91
+ console.log(" \u2713 Added .apostil/ to .gitignore");
92
+ } else {
93
+ console.log(" \u2713 .gitignore already configured");
94
+ }
77
95
  }
78
96
  const layoutInjected = await injectIntoLayout(appDir, useSrc);
79
97
  if (layoutInjected) {
80
- console.log(` \u2713 Added <ApostilWrapper> to root layout`);
98
+ console.log(" \u2713 Added <ApostilWrapper> to root layout");
81
99
  }
82
100
  console.log("\n Done! Run your dev server and press C to start commenting.\n");
83
101
  }
@@ -122,7 +140,26 @@ async function remove() {
122
140
  Done! Now run: npm uninstall apostil
123
141
  `);
124
142
  }
125
- function getWrapperComponent() {
143
+ function getWrapperComponent(mode) {
144
+ const envGuard = mode === "personal" ? `
145
+ // Personal mode \u2014 only active in local development
146
+ if (process.env.NODE_ENV !== "development") {
147
+ return <>{children}</>;
148
+ }
149
+ ` : mode === "dev" ? `
150
+ // Dev mode \u2014 active in dev + staging, disabled in production
151
+ // Set NEXT_PUBLIC_APOSTIL=true to force on in any environment
152
+ const forceOn = process.env.NEXT_PUBLIC_APOSTIL === "true";
153
+ if (process.env.NODE_ENV === "production" && !forceOn) {
154
+ return <>{children}</>;
155
+ }
156
+ ` : `
157
+ // Public mode \u2014 active in all environments
158
+ // Set NEXT_PUBLIC_APOSTIL=false to disable
159
+ if (process.env.NEXT_PUBLIC_APOSTIL === "false") {
160
+ return <>{children}</>;
161
+ }
162
+ `;
126
163
  return `"use client";
127
164
 
128
165
  import { usePathname } from "next/navigation";
@@ -133,7 +170,7 @@ import {
133
170
  CommentSidebar,
134
171
  } from "apostil";
135
172
 
136
- export function ApostilWrapper({ children }: { children: React.ReactNode }) {
173
+ export function ApostilWrapper({ children }: { children: React.ReactNode }) {${envGuard}
137
174
  const pathname = usePathname();
138
175
  const pageId = pathname.replace(/\\//g, "--").replace(/^--/, "") || "home";
139
176
 
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/cli/index.ts"],"sourcesContent":["#!/usr/bin/env node\n\nimport fs from \"fs/promises\";\nimport path from \"path\";\n\nconst args = process.argv.slice(2);\nconst command = args[0];\n\nif (command === \"init\") {\n init();\n} else if (command === \"remove\") {\n remove();\n} else if (command === \"help\" || command === \"--help\" || command === \"-h\" || !command) {\n printHelp();\n} else {\n console.log(` Unknown command: ${command}\\n`);\n printHelp();\n}\n\nfunction printHelp() {\n console.log(`\n apostil — Pin-and-comment feedback for React & Next.js\n\n Usage:\n npx apostil init Set up apostil in your Next.js project\n npx apostil remove Remove apostil from your project\n npx apostil help Show this help\n`);\n}\n\nasync function init() {\n const cwd = process.cwd();\n\n // Detect Next.js app directory\n const appDir = await findAppDir(cwd);\n if (!appDir) {\n console.log(\" Could not find a Next.js app/ directory.\");\n console.log(\" Make sure you're running this from your project root.\\n\");\n process.exit(1);\n }\n\n // Detect src/ prefix\n const useSrc = appDir.includes(\"src/app\");\n\n console.log(\"\\n Setting up apostil...\\n\");\n\n // 1. Create API route\n const apiDir = path.join(appDir, \"api\", \"apostil\");\n const apiFile = path.join(apiDir, \"route.ts\");\n if (await fileExists(apiFile)) {\n console.log(\" ✓ API route already exists\");\n } else {\n await fs.mkdir(apiDir, { recursive: true });\n await fs.writeFile(\n apiFile,\n `export { GET, POST } from \"apostil/adapters/nextjs\";\\n`,\n \"utf-8\"\n );\n console.log(\" ✓ Created ${rel(cwd, apiFile)}\");\n }\n\n // 2. Create wrapper component\n const componentsDir = path.join(cwd, useSrc ? \"src/components\" : \"components\");\n const wrapperFile = path.join(componentsDir, \"apostil-wrapper.tsx\");\n if (await fileExists(wrapperFile)) {\n console.log(\" ✓ Wrapper component already exists\");\n } else {\n await fs.mkdir(componentsDir, { recursive: true });\n await fs.writeFile(wrapperFile, getWrapperComponent(), \"utf-8\");\n console.log(` ✓ Created ${rel(cwd, wrapperFile)}`);\n }\n\n // 3. Create .apostil/ directory for comment storage\n const commentsDir = path.join(cwd, \".apostil\");\n await fs.mkdir(commentsDir, { recursive: true });\n console.log(\" ✓ Created .apostil/ directory\");\n\n // 4. Add .apostil/ to .gitignore\n const gitignorePath = path.join(cwd, \".gitignore\");\n let gitignore = \"\";\n try {\n gitignore = await fs.readFile(gitignorePath, \"utf-8\");\n } catch {}\n\n if (!gitignore.includes(\".apostil\")) {\n const entry = \"\\n# Apostil comments\\n.apostil/\\n\";\n await fs.appendFile(gitignorePath, entry, \"utf-8\");\n console.log(\" ✓ Added .apostil/ to .gitignore\");\n } else {\n console.log(\" ✓ .gitignore already configured\");\n }\n\n // 5. Inject wrapper into root layout\n const layoutInjected = await injectIntoLayout(appDir, useSrc);\n if (layoutInjected) {\n console.log(` ✓ Added <ApostilWrapper> to root layout`);\n }\n\n console.log(\"\\n Done! Run your dev server and press C to start commenting.\\n\");\n}\n\nasync function remove() {\n const cwd = process.cwd();\n const appDir = await findAppDir(cwd);\n const useSrc = appDir?.includes(\"src/app\") ?? false;\n\n console.log(\"\\n Removing apostil...\\n\");\n\n // 1. Remove API route\n if (appDir) {\n const apiDir = path.join(appDir, \"api\", \"apostil\");\n if (await fileExists(path.join(apiDir, \"route.ts\"))) {\n await fs.rm(apiDir, { recursive: true });\n console.log(\" ✓ Removed API route\");\n }\n }\n\n // 2. Remove wrapper component\n const componentsDir = path.join(cwd, useSrc ? \"src/components\" : \"components\");\n const wrapperFile = path.join(componentsDir, \"apostil-wrapper.tsx\");\n if (await fileExists(wrapperFile)) {\n await fs.rm(wrapperFile);\n console.log(\" ✓ Removed wrapper component\");\n }\n\n // 3. Remove wrapper from layout\n if (appDir) {\n const unwrapped = await removeFromLayout(appDir);\n if (unwrapped) {\n console.log(\" ✓ Removed <ApostilWrapper> from root layout\");\n }\n }\n\n // 4. Remove .apostil/ directory\n const commentsDir = path.join(cwd, \".apostil\");\n if (await fileExists(commentsDir)) {\n await fs.rm(commentsDir, { recursive: true });\n console.log(\" ✓ Removed .apostil/ directory\");\n }\n\n // 5. Remove from .gitignore\n const gitignorePath = path.join(cwd, \".gitignore\");\n try {\n let gitignore = await fs.readFile(gitignorePath, \"utf-8\");\n gitignore = gitignore.replace(/\\n?# Apostil comments\\n\\.apostil\\/\\n?/g, \"\");\n await fs.writeFile(gitignorePath, gitignore, \"utf-8\");\n console.log(\" ✓ Cleaned .gitignore\");\n } catch {}\n\n console.log(`\n Done! Now run: npm uninstall apostil\n`);\n}\n\n// --- Wrapper component template ---\n\nfunction getWrapperComponent(): string {\n return `\"use client\";\n\nimport { usePathname } from \"next/navigation\";\nimport {\n ApostilProvider,\n CommentOverlay,\n CommentToggle,\n CommentSidebar,\n} from \"apostil\";\n\nexport function ApostilWrapper({ children }: { children: React.ReactNode }) {\n const pathname = usePathname();\n const pageId = pathname.replace(/\\\\//g, \"--\").replace(/^--/, \"\") || \"home\";\n\n return (\n <ApostilProvider pageId={pageId}>\n {children}\n <CommentOverlay />\n <CommentSidebar />\n <CommentToggle />\n </ApostilProvider>\n );\n}\n`;\n}\n\n// --- Layout injection ---\n\nasync function injectIntoLayout(appDir: string, useSrc: boolean): Promise<boolean> {\n const layoutPath = await findLayout(appDir);\n if (!layoutPath) return false;\n\n let content = await fs.readFile(layoutPath, \"utf-8\");\n\n // Skip if already injected\n if (content.includes(\"ApostilWrapper\")) {\n console.log(\" ✓ Layout already has <ApostilWrapper>\");\n return false;\n }\n\n // Add import at the top (after existing imports or \"use\" directives)\n const importPath = useSrc ? \"@/components/apostil-wrapper\" : \"../components/apostil-wrapper\";\n const importLine = `import { ApostilWrapper } from \"${importPath}\";\\n`;\n\n // Find the last import statement and insert after it\n const importRegex = /^import\\s.+$/gm;\n let lastImportIndex = 0;\n let match: RegExpExecArray | null;\n while ((match = importRegex.exec(content)) !== null) {\n lastImportIndex = match.index + match[0].length;\n }\n\n if (lastImportIndex > 0) {\n content = content.slice(0, lastImportIndex) + \"\\n\" + importLine + content.slice(lastImportIndex);\n } else {\n // No imports found, add at the top (after \"use client\" or \"use server\" if present)\n const useDirective = content.match(/^[\"']use (client|server)[\"'];?\\n/);\n const insertAt = useDirective ? useDirective[0].length : 0;\n content = content.slice(0, insertAt) + importLine + content.slice(insertAt);\n }\n\n // Wrap {children} with <ApostilWrapper>\n // Handle both {children} and { children } patterns inside <body>\n const bodyChildrenRegex = /(<body[^>]*>)([\\s\\S]*?)(\\{[\\s]*children[\\s]*\\})([\\s\\S]*?)(<\\/body>)/;\n const bodyMatch = content.match(bodyChildrenRegex);\n\n if (bodyMatch) {\n // Wrap {children} inside <body> with <ApostilWrapper>\n content = content.replace(\n bodyChildrenRegex,\n `$1$2<ApostilWrapper>$3</ApostilWrapper>$4$5`\n );\n } else {\n // Fallback: try to find {children} anywhere and wrap it\n const childrenRegex = /(\\{[\\s]*children[\\s]*\\})/;\n if (childrenRegex.test(content)) {\n content = content.replace(childrenRegex, `<ApostilWrapper>$1</ApostilWrapper>`);\n } else {\n console.log(\" ⚠ Could not find {children} in layout — add <ApostilWrapper> manually\");\n return false;\n }\n }\n\n await fs.writeFile(layoutPath, content, \"utf-8\");\n return true;\n}\n\nasync function removeFromLayout(appDir: string): Promise<boolean> {\n const layoutPath = await findLayout(appDir);\n if (!layoutPath) return false;\n\n let content = await fs.readFile(layoutPath, \"utf-8\");\n\n if (!content.includes(\"ApostilWrapper\")) return false;\n\n // Remove import line\n content = content.replace(/import\\s*\\{[^}]*ApostilWrapper[^}]*\\}\\s*from\\s*[\"'][^\"']+[\"'];?\\n?/g, \"\");\n\n // Unwrap <ApostilWrapper>{children}</ApostilWrapper>\n content = content.replace(/<ApostilWrapper>([\\s\\S]*?)<\\/ApostilWrapper>/g, \"$1\");\n\n await fs.writeFile(layoutPath, content, \"utf-8\");\n return true;\n}\n\n// --- Helpers ---\n\nasync function findAppDir(cwd: string): Promise<string | null> {\n for (const candidate of [\"src/app\", \"app\"]) {\n const dir = path.join(cwd, candidate);\n try {\n const stat = await fs.stat(dir);\n if (stat.isDirectory()) return dir;\n } catch {}\n }\n return null;\n}\n\nasync function findLayout(appDir: string): Promise<string | null> {\n for (const ext of [\"tsx\", \"jsx\", \"ts\", \"js\"]) {\n const file = path.join(appDir, `layout.${ext}`);\n if (await fileExists(file)) return file;\n }\n return null;\n}\n\nasync function fileExists(p: string): Promise<boolean> {\n try {\n await fs.stat(p);\n return true;\n } catch {\n return false;\n }\n}\n\nfunction rel(cwd: string, filePath: string): string {\n return path.relative(cwd, filePath);\n}\n"],"mappings":";;;AAEA,OAAO,QAAQ;AACf,OAAO,UAAU;AAEjB,IAAM,OAAO,QAAQ,KAAK,MAAM,CAAC;AACjC,IAAM,UAAU,KAAK,CAAC;AAEtB,IAAI,YAAY,QAAQ;AACtB,OAAK;AACP,WAAW,YAAY,UAAU;AAC/B,SAAO;AACT,WAAW,YAAY,UAAU,YAAY,YAAY,YAAY,QAAQ,CAAC,SAAS;AACrF,YAAU;AACZ,OAAO;AACL,UAAQ,IAAI,sBAAsB,OAAO;AAAA,CAAI;AAC7C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GAAG,EAAE;AAC9C,QAAI,MAAM,WAAW,IAAI,EAAG,QAAO;AAAA,EACrC;AACA,SAAO;AACT;AAEA,eAAe,WAAW,GAA6B;AACrD,MAAI;AACF,UAAM,GAAG,KAAK,CAAC;AACf,WAAO;AAAA,EACT,QAAQ;AACN,WAAO;AAAA,EACT;AACF;AAEA,SAAS,IAAI,KAAa,UAA0B;AAClD,SAAO,KAAK,SAAS,KAAK,QAAQ;AACpC;","names":[]}
1
+ {"version":3,"sources":["../../src/cli/index.ts"],"sourcesContent":["#!/usr/bin/env node\n\nimport fs from \"fs/promises\";\nimport path from \"path\";\n\ntype Mode = \"personal\" | \"dev\" | \"public\";\n\nconst args = process.argv.slice(2);\nconst command = args[0];\n\nif (command === \"init\") {\n const mode = parseMode(args.slice(1));\n init(mode);\n} else if (command === \"remove\") {\n remove();\n} else if (command === \"help\" || command === \"--help\" || command === \"-h\" || !command) {\n printHelp();\n} else {\n console.log(` Unknown command: ${command}\\n`);\n printHelp();\n}\n\nfunction parseMode(flags: string[]): Mode {\n if (flags.includes(\"--dev\")) return \"dev\";\n if (flags.includes(\"--public\")) return \"public\";\n return \"personal\";\n}\n\nfunction printHelp() {\n console.log(`\n apostil — Pin-and-comment feedback for React & Next.js\n\n Usage:\n npx apostil init [mode] Set up apostil in your Next.js project\n npx apostil remove Remove apostil from your project\n npx apostil help Show this help\n\n Modes:\n (default) Personal — local dev only, comments gitignored\n --dev Dev + staging — comments gitignored, env-controlled\n --public All environments — comments committed to git\n`);\n}\n\nasync function init(mode: Mode) {\n const cwd = process.cwd();\n\n // Detect Next.js app directory\n const appDir = await findAppDir(cwd);\n if (!appDir) {\n console.log(\" Could not find a Next.js app/ directory.\");\n console.log(\" Make sure you're running this from your project root.\\n\");\n process.exit(1);\n }\n\n // Detect src/ prefix\n const useSrc = appDir.includes(\"src/app\");\n\n const modeLabel = mode === \"personal\" ? \"personal\" : mode === \"dev\" ? \"dev\" : \"public\";\n console.log(`\\n Setting up apostil (${modeLabel} mode)...\\n`);\n\n // 1. Create API route\n const apiDir = path.join(appDir, \"api\", \"apostil\");\n const apiFile = path.join(apiDir, \"route.ts\");\n if (await fileExists(apiFile)) {\n console.log(\" ✓ API route already exists\");\n } else {\n await fs.mkdir(apiDir, { recursive: true });\n await fs.writeFile(\n apiFile,\n `export { GET, POST } from \"apostil/adapters/nextjs\";\\n`,\n \"utf-8\"\n );\n console.log(` ✓ Created ${rel(cwd, apiFile)}`);\n }\n\n // 2. Create wrapper component\n const componentsDir = path.join(cwd, useSrc ? \"src/components\" : \"components\");\n const wrapperFile = path.join(componentsDir, \"apostil-wrapper.tsx\");\n await fs.mkdir(componentsDir, { recursive: true });\n await fs.writeFile(wrapperFile, getWrapperComponent(mode), \"utf-8\");\n console.log(` ✓ Created ${rel(cwd, wrapperFile)} (${modeLabel} mode)`);\n\n // 3. Create .apostil/ directory for comment storage\n const commentsDir = path.join(cwd, \".apostil\");\n await fs.mkdir(commentsDir, { recursive: true });\n console.log(\" ✓ Created .apostil/ directory\");\n\n // 4. Handle .gitignore based on mode\n const gitignorePath = path.join(cwd, \".gitignore\");\n let gitignore = \"\";\n try {\n gitignore = await fs.readFile(gitignorePath, \"utf-8\");\n } catch {}\n\n if (mode === \"public\") {\n // Public mode: don't gitignore comments — they get committed\n if (gitignore.includes(\".apostil\")) {\n console.log(\" ✓ .gitignore unchanged (public mode — comments will be committed)\");\n } else {\n console.log(\" ✓ Comments will be committed to git (public mode)\");\n }\n } else {\n // Personal & dev: gitignore comments\n if (!gitignore.includes(\".apostil\")) {\n const entry = \"\\n# Apostil comments\\n.apostil/\\n\";\n await fs.appendFile(gitignorePath, entry, \"utf-8\");\n console.log(\" ✓ Added .apostil/ to .gitignore\");\n } else {\n console.log(\" ✓ .gitignore already configured\");\n }\n }\n\n // 5. Inject wrapper into root layout\n const layoutInjected = await injectIntoLayout(appDir, useSrc);\n if (layoutInjected) {\n console.log(\" ✓ Added <ApostilWrapper> to root layout\");\n }\n\n console.log(\"\\n Done! Run your dev server and press C to start commenting.\\n\");\n}\n\nasync function remove() {\n const cwd = process.cwd();\n const appDir = await findAppDir(cwd);\n const useSrc = appDir?.includes(\"src/app\") ?? false;\n\n console.log(\"\\n Removing apostil...\\n\");\n\n // 1. Remove API route\n if (appDir) {\n const apiDir = path.join(appDir, \"api\", \"apostil\");\n if (await fileExists(path.join(apiDir, \"route.ts\"))) {\n await fs.rm(apiDir, { recursive: true });\n console.log(\" ✓ Removed API route\");\n }\n }\n\n // 2. Remove wrapper component\n const componentsDir = path.join(cwd, useSrc ? \"src/components\" : \"components\");\n const wrapperFile = path.join(componentsDir, \"apostil-wrapper.tsx\");\n if (await fileExists(wrapperFile)) {\n await fs.rm(wrapperFile);\n console.log(\" ✓ Removed wrapper component\");\n }\n\n // 3. Remove wrapper from layout\n if (appDir) {\n const unwrapped = await removeFromLayout(appDir);\n if (unwrapped) {\n console.log(\" ✓ Removed <ApostilWrapper> from root layout\");\n }\n }\n\n // 4. Remove .apostil/ directory\n const commentsDir = path.join(cwd, \".apostil\");\n if (await fileExists(commentsDir)) {\n await fs.rm(commentsDir, { recursive: true });\n console.log(\" ✓ Removed .apostil/ directory\");\n }\n\n // 5. Remove from .gitignore\n const gitignorePath = path.join(cwd, \".gitignore\");\n try {\n let gitignore = await fs.readFile(gitignorePath, \"utf-8\");\n gitignore = gitignore.replace(/\\n?# Apostil comments\\n\\.apostil\\/\\n?/g, \"\");\n await fs.writeFile(gitignorePath, gitignore, \"utf-8\");\n console.log(\" ✓ Cleaned .gitignore\");\n } catch {}\n\n console.log(`\n Done! Now run: npm uninstall apostil\n`);\n}\n\n// --- Wrapper component template ---\n\nfunction getWrapperComponent(mode: Mode): string {\n const envGuard = mode === \"personal\"\n ? `\n // Personal mode — only active in local development\n if (process.env.NODE_ENV !== \"development\") {\n return <>{children}</>;\n }\n`\n : mode === \"dev\"\n ? `\n // Dev mode — active in dev + staging, disabled in production\n // Set NEXT_PUBLIC_APOSTIL=true to force on in any environment\n const forceOn = process.env.NEXT_PUBLIC_APOSTIL === \"true\";\n if (process.env.NODE_ENV === \"production\" && !forceOn) {\n return <>{children}</>;\n }\n`\n : `\n // Public mode — active in all environments\n // Set NEXT_PUBLIC_APOSTIL=false to disable\n if (process.env.NEXT_PUBLIC_APOSTIL === \"false\") {\n return <>{children}</>;\n }\n`;\n\n return `\"use client\";\n\nimport { usePathname } from \"next/navigation\";\nimport {\n ApostilProvider,\n CommentOverlay,\n CommentToggle,\n CommentSidebar,\n} from \"apostil\";\n\nexport function ApostilWrapper({ children }: { children: React.ReactNode }) {${envGuard}\n const pathname = usePathname();\n const pageId = pathname.replace(/\\\\//g, \"--\").replace(/^--/, \"\") || \"home\";\n\n return (\n <ApostilProvider pageId={pageId}>\n {children}\n <CommentOverlay />\n <CommentSidebar />\n <CommentToggle />\n </ApostilProvider>\n );\n}\n`;\n}\n\n// --- Layout injection ---\n\nasync function injectIntoLayout(appDir: string, useSrc: boolean): Promise<boolean> {\n const layoutPath = await findLayout(appDir);\n if (!layoutPath) return false;\n\n let content = await fs.readFile(layoutPath, \"utf-8\");\n\n // Skip if already injected\n if (content.includes(\"ApostilWrapper\")) {\n console.log(\" ✓ Layout already has <ApostilWrapper>\");\n return false;\n }\n\n // Add import at the top (after existing imports or \"use\" directives)\n const importPath = useSrc ? \"@/components/apostil-wrapper\" : \"../components/apostil-wrapper\";\n const importLine = `import { ApostilWrapper } from \"${importPath}\";\\n`;\n\n // Find the last import statement and insert after it\n const importRegex = /^import\\s.+$/gm;\n let lastImportIndex = 0;\n let match: RegExpExecArray | null;\n while ((match = importRegex.exec(content)) !== null) {\n lastImportIndex = match.index + match[0].length;\n }\n\n if (lastImportIndex > 0) {\n content = content.slice(0, lastImportIndex) + \"\\n\" + importLine + content.slice(lastImportIndex);\n } else {\n // No imports found, add at the top (after \"use client\" or \"use server\" if present)\n const useDirective = content.match(/^[\"']use (client|server)[\"'];?\\n/);\n const insertAt = useDirective ? useDirective[0].length : 0;\n content = content.slice(0, insertAt) + importLine + content.slice(insertAt);\n }\n\n // Wrap {children} with <ApostilWrapper>\n // Handle both {children} and { children } patterns inside <body>\n const bodyChildrenRegex = /(<body[^>]*>)([\\s\\S]*?)(\\{[\\s]*children[\\s]*\\})([\\s\\S]*?)(<\\/body>)/;\n const bodyMatch = content.match(bodyChildrenRegex);\n\n if (bodyMatch) {\n content = content.replace(\n bodyChildrenRegex,\n `$1$2<ApostilWrapper>$3</ApostilWrapper>$4$5`\n );\n } else {\n // Fallback: try to find {children} anywhere and wrap it\n const childrenRegex = /(\\{[\\s]*children[\\s]*\\})/;\n if (childrenRegex.test(content)) {\n content = content.replace(childrenRegex, `<ApostilWrapper>$1</ApostilWrapper>`);\n } else {\n console.log(\" ⚠ Could not find {children} in layout — add <ApostilWrapper> manually\");\n return false;\n }\n }\n\n await fs.writeFile(layoutPath, content, \"utf-8\");\n return true;\n}\n\nasync function removeFromLayout(appDir: string): Promise<boolean> {\n const layoutPath = await findLayout(appDir);\n if (!layoutPath) return false;\n\n let content = await fs.readFile(layoutPath, \"utf-8\");\n\n if (!content.includes(\"ApostilWrapper\")) return false;\n\n // Remove import line\n content = content.replace(/import\\s*\\{[^}]*ApostilWrapper[^}]*\\}\\s*from\\s*[\"'][^\"']+[\"'];?\\n?/g, \"\");\n\n // Unwrap <ApostilWrapper>{children}</ApostilWrapper>\n content = content.replace(/<ApostilWrapper>([\\s\\S]*?)<\\/ApostilWrapper>/g, \"$1\");\n\n await fs.writeFile(layoutPath, content, \"utf-8\");\n return true;\n}\n\n// --- Helpers ---\n\nasync function findAppDir(cwd: string): Promise<string | null> {\n for (const candidate of [\"src/app\", \"app\"]) {\n const dir = path.join(cwd, candidate);\n try {\n const stat = await fs.stat(dir);\n if (stat.isDirectory()) return dir;\n } catch {}\n }\n return null;\n}\n\nasync function findLayout(appDir: string): Promise<string | null> {\n for (const ext of [\"tsx\", \"jsx\", \"ts\", \"js\"]) {\n const file = path.join(appDir, `layout.${ext}`);\n if (await fileExists(file)) return file;\n }\n return null;\n}\n\nasync function fileExists(p: string): Promise<boolean> {\n try {\n await fs.stat(p);\n return true;\n } catch {\n return false;\n }\n}\n\nfunction rel(cwd: string, filePath: string): string {\n return path.relative(cwd, filePath);\n}\n"],"mappings":";;;AAEA,OAAO,QAAQ;AACf,OAAO,UAAU;AAIjB,IAAM,OAAO,QAAQ,KAAK,MAAM,CAAC;AACjC,IAAM,UAAU,KAAK,CAAC;AAEtB,IAAI,YAAY,QAAQ;AACtB,QAAM,OAAO,UAAU,KAAK,MAAM,CAAC,CAAC;AACpC,OAAK,IAAI;AACX,WAAW,YAAY,UAAU;AAC/B,SAAO;AACT,WAAW,YAAY,UAAU,YAAY,YAAY,YAAY,QAAQ,CAAC,SAAS;AACrF,YAAU;AACZ,OAAO;AACL,UAAQ,IAAI,sBAAsB,OAAO;AAAA,CAAI;AAC7C,YAAU;AACZ;AAEA,SAAS,UAAU,OAAuB;AACxC,MAAI,MAAM,SAAS,OAAO,EAAG,QAAO;AACpC,MAAI,MAAM,SAAS,UAAU,EAAG,QAAO;AACvC,SAAO;AACT;AAEA,SAAS,YAAY;AACnB,UAAQ,IAAI;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,CAYb;AACD;AAEA,eAAe,KAAK,MAAY;AAC9B,QAAM,MAAM,QAAQ,IAAI;AAGxB,QAAM,SAAS,MAAM,WAAW,GAAG;AACnC,MAAI,CAAC,QAAQ;AACX,YAAQ,IAAI,4CAA4C;AACxD,YAAQ,IAAI,2DAA2D;AACvE,YAAQ,KAAK,CAAC;AAAA,EAChB;AAGA,QAAM,SAAS,OAAO,SAAS,SAAS;AAExC,QAAM,YAAY,SAAS,aAAa,aAAa,SAAS,QAAQ,QAAQ;AAC9E,UAAQ,IAAI;AAAA,wBAA2B,SAAS;AAAA,CAAa;AAG7D,QAAM,SAAS,KAAK,KAAK,QAAQ,OAAO,SAAS;AACjD,QAAM,UAAU,KAAK,KAAK,QAAQ,UAAU;AAC5C,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