@stephenov/feedbackwidget 0.5.0 → 0.5.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.d.mts +1 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +20 -8
- package/dist/cli.mjs +20 -8
- package/package.json +1 -1
package/dist/cli.d.mts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
package/dist/cli.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
package/dist/cli.js
CHANGED
|
@@ -217,19 +217,31 @@ function injectWidget(apiKey) {
|
|
|
217
217
|
if (content.includes("FeedbackWidget")) {
|
|
218
218
|
return null;
|
|
219
219
|
}
|
|
220
|
-
const
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
220
|
+
const lines = content.split("\n");
|
|
221
|
+
let lastImportIndex = -1;
|
|
222
|
+
for (let i = 0; i < lines.length; i++) {
|
|
223
|
+
if (lines[i].startsWith("import ")) {
|
|
224
|
+
lastImportIndex = i;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
if (lastImportIndex >= 0) {
|
|
228
|
+
lines.splice(lastImportIndex + 1, 0, importLine);
|
|
224
229
|
} else {
|
|
225
|
-
|
|
230
|
+
lines.unshift(importLine);
|
|
226
231
|
}
|
|
227
|
-
|
|
228
|
-
|
|
232
|
+
content = lines.join("\n");
|
|
233
|
+
const bodyRegex = /(<body[^>]*>)/;
|
|
234
|
+
const bodyMatch = content.match(bodyRegex);
|
|
235
|
+
if (bodyMatch && bodyMatch.index !== void 0) {
|
|
229
236
|
const insertPos = bodyMatch.index + bodyMatch[0].length;
|
|
230
237
|
content = content.slice(0, insertPos) + "\n " + component + content.slice(insertPos);
|
|
231
238
|
}
|
|
232
|
-
import_fs.default.writeFileSync(layoutPath, content);
|
|
239
|
+
import_fs.default.writeFileSync(layoutPath, content, { encoding: "utf-8", flag: "w" });
|
|
240
|
+
const verify = import_fs.default.readFileSync(layoutPath, "utf-8");
|
|
241
|
+
if (!verify.includes("FeedbackWidget")) {
|
|
242
|
+
console.error(" Warning: File write may not have persisted. Check " + layoutPath);
|
|
243
|
+
return null;
|
|
244
|
+
}
|
|
233
245
|
return { file: layoutPath.replace(cwd + "/", "") };
|
|
234
246
|
}
|
|
235
247
|
}
|
package/dist/cli.mjs
CHANGED
|
@@ -194,19 +194,31 @@ function injectWidget(apiKey) {
|
|
|
194
194
|
if (content.includes("FeedbackWidget")) {
|
|
195
195
|
return null;
|
|
196
196
|
}
|
|
197
|
-
const
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
197
|
+
const lines = content.split("\n");
|
|
198
|
+
let lastImportIndex = -1;
|
|
199
|
+
for (let i = 0; i < lines.length; i++) {
|
|
200
|
+
if (lines[i].startsWith("import ")) {
|
|
201
|
+
lastImportIndex = i;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
if (lastImportIndex >= 0) {
|
|
205
|
+
lines.splice(lastImportIndex + 1, 0, importLine);
|
|
201
206
|
} else {
|
|
202
|
-
|
|
207
|
+
lines.unshift(importLine);
|
|
203
208
|
}
|
|
204
|
-
|
|
205
|
-
|
|
209
|
+
content = lines.join("\n");
|
|
210
|
+
const bodyRegex = /(<body[^>]*>)/;
|
|
211
|
+
const bodyMatch = content.match(bodyRegex);
|
|
212
|
+
if (bodyMatch && bodyMatch.index !== void 0) {
|
|
206
213
|
const insertPos = bodyMatch.index + bodyMatch[0].length;
|
|
207
214
|
content = content.slice(0, insertPos) + "\n " + component + content.slice(insertPos);
|
|
208
215
|
}
|
|
209
|
-
fs.writeFileSync(layoutPath, content);
|
|
216
|
+
fs.writeFileSync(layoutPath, content, { encoding: "utf-8", flag: "w" });
|
|
217
|
+
const verify = fs.readFileSync(layoutPath, "utf-8");
|
|
218
|
+
if (!verify.includes("FeedbackWidget")) {
|
|
219
|
+
console.error(" Warning: File write may not have persisted. Check " + layoutPath);
|
|
220
|
+
return null;
|
|
221
|
+
}
|
|
210
222
|
return { file: layoutPath.replace(cwd + "/", "") };
|
|
211
223
|
}
|
|
212
224
|
}
|