@nikitadmitrieff/feedback-chat 0.1.0 → 0.1.1
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.
- package/dist/cli/init.js +55 -3
- package/package.json +1 -1
package/dist/cli/init.js
CHANGED
|
@@ -24,6 +24,7 @@ const handler = createStatusHandler({
|
|
|
24
24
|
|
|
25
25
|
export const { GET, POST } = handler
|
|
26
26
|
`;
|
|
27
|
+
var SOURCE_DIRECTIVE = '@source "../node_modules/@nikitadmitrieff/feedback-chat/dist/**/*.js";';
|
|
27
28
|
function findAppDir(cwd) {
|
|
28
29
|
const candidates = [
|
|
29
30
|
join(cwd, "src", "app"),
|
|
@@ -34,6 +35,37 @@ function findAppDir(cwd) {
|
|
|
34
35
|
}
|
|
35
36
|
return null;
|
|
36
37
|
}
|
|
38
|
+
function findGlobalsCss(cwd) {
|
|
39
|
+
const candidates = [
|
|
40
|
+
join(cwd, "src", "app", "globals.css"),
|
|
41
|
+
join(cwd, "app", "globals.css"),
|
|
42
|
+
join(cwd, "styles", "globals.css"),
|
|
43
|
+
join(cwd, "src", "styles", "globals.css")
|
|
44
|
+
];
|
|
45
|
+
for (const path of candidates) {
|
|
46
|
+
if (existsSync(path)) return path;
|
|
47
|
+
}
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
function injectSourceDirective(cssPath) {
|
|
51
|
+
const content = readFileSync(cssPath, "utf-8");
|
|
52
|
+
if (content.includes(SOURCE_DIRECTIVE)) return false;
|
|
53
|
+
const lines = content.split("\n");
|
|
54
|
+
let insertIndex = -1;
|
|
55
|
+
for (let i = 0; i < lines.length; i++) {
|
|
56
|
+
if (lines[i].includes("@import") && lines[i].includes("tailwindcss")) {
|
|
57
|
+
insertIndex = i + 1;
|
|
58
|
+
break;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
if (insertIndex === -1) {
|
|
62
|
+
writeFileSync(cssPath, SOURCE_DIRECTIVE + "\n" + content);
|
|
63
|
+
} else {
|
|
64
|
+
lines.splice(insertIndex, 0, SOURCE_DIRECTIVE);
|
|
65
|
+
writeFileSync(cssPath, lines.join("\n"));
|
|
66
|
+
}
|
|
67
|
+
return true;
|
|
68
|
+
}
|
|
37
69
|
function safeWriteFile(filePath, content, overwrite) {
|
|
38
70
|
if (existsSync(filePath) && !overwrite) {
|
|
39
71
|
console.log(` Skipped ${filePath} (already exists)`);
|
|
@@ -131,6 +163,18 @@ async function main() {
|
|
|
131
163
|
if (safeWriteFile(statusRoutePath, STATUS_ROUTE_TEMPLATE, overwrite)) {
|
|
132
164
|
console.log(` Created ${statusRoutePath}`);
|
|
133
165
|
}
|
|
166
|
+
const globalsCss = findGlobalsCss(cwd);
|
|
167
|
+
if (globalsCss) {
|
|
168
|
+
if (injectSourceDirective(globalsCss)) {
|
|
169
|
+
console.log(` Patched ${globalsCss} (added @source directive for Tailwind v4)`);
|
|
170
|
+
} else {
|
|
171
|
+
console.log(` ${globalsCss} already has @source directive`);
|
|
172
|
+
}
|
|
173
|
+
} else {
|
|
174
|
+
console.log();
|
|
175
|
+
console.log(" \u26A0 Could not find globals.css \u2014 add this line manually:");
|
|
176
|
+
console.log(` ${SOURCE_DIRECTIVE}`);
|
|
177
|
+
}
|
|
134
178
|
const envPath = join(cwd, ".env.local");
|
|
135
179
|
appendEnvVar(envPath, "ANTHROPIC_API_KEY", widgetAnswers.apiKey);
|
|
136
180
|
appendEnvVar(envPath, "FEEDBACK_PASSWORD", widgetAnswers.password);
|
|
@@ -142,12 +186,20 @@ async function main() {
|
|
|
142
186
|
console.log();
|
|
143
187
|
console.log(" \u2500\u2500 Add to your layout \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500");
|
|
144
188
|
console.log();
|
|
189
|
+
console.log(" // Create a client component (e.g., components/FeedbackButton.tsx):");
|
|
190
|
+
console.log(" 'use client'");
|
|
191
|
+
console.log(" import { useState } from 'react'");
|
|
145
192
|
console.log(" import { FeedbackPanel } from '@nikitadmitrieff/feedback-chat'");
|
|
146
193
|
console.log(" import '@nikitadmitrieff/feedback-chat/styles.css'");
|
|
147
194
|
console.log();
|
|
148
|
-
console.log("
|
|
149
|
-
console.log("
|
|
150
|
-
console.log("
|
|
195
|
+
console.log(" export function FeedbackButton() {");
|
|
196
|
+
console.log(" const [open, setOpen] = useState(false)");
|
|
197
|
+
console.log(" return <FeedbackPanel isOpen={open} onToggle={() => setOpen(!open)} />");
|
|
198
|
+
console.log(" }");
|
|
199
|
+
console.log();
|
|
200
|
+
console.log(" // Then in your layout.tsx:");
|
|
201
|
+
console.log(" import { FeedbackButton } from '@/components/FeedbackButton'");
|
|
202
|
+
console.log(" // Inside <body>: <FeedbackButton />");
|
|
151
203
|
console.log();
|
|
152
204
|
console.log(" Done.");
|
|
153
205
|
console.log();
|