@commentkit/comment-kit 2.1.1 → 2.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.
- package/CHANGELOG.md +29 -0
- package/dist/node/cli/doctor.js +33 -24
- package/dist/node/cli/init.js +281 -13
- package/dist/node/cli/main.js +43 -12
- package/dist/npm/chunks/{AgentSend-B4rxdY68.js → AgentSend-BQQUJP6N.js} +2 -2
- package/dist/npm/chunks/{Checklist-Cy68X5qC.js → Checklist-RlhnW32b.js} +8 -7
- package/dist/npm/chunks/{Composer-D65l6Jg4.js → Composer-D1ubijPl.js} +27 -26
- package/dist/npm/chunks/{DatePicker-BPzzqW3f.js → DatePicker-TshUaQHj.js} +1 -1
- package/dist/npm/chunks/{Guest-C-ZhARI0.js → Guest-Dt0QYw0v.js} +4 -3
- package/dist/npm/chunks/{MarkupEditor-BOb2jFTR.js → MarkupEditor-BA_p3sl9.js} +2 -1
- package/dist/npm/chunks/{Panel-DgdCgaC-.js → Panel-BDt2-Db1.js} +109 -108
- package/dist/npm/chunks/{Settings-BbWu2Rd5.js → Settings-CAv8hp89.js} +18 -17
- package/dist/npm/chunks/{Shortcuts-C5wEx-Mq.js → Shortcuts-CFDTnP5H.js} +3 -3
- package/dist/npm/chunks/{SignInFirst-BlMbutED.js → SignInFirst-DDAq5Jg8.js} +3 -3
- package/dist/npm/chunks/{StyleEditor-BN2z7mUs.js → StyleEditor-CPeOeu8g.js} +2 -2
- package/dist/npm/chunks/{StylePanel-BZk-r-kl.js → StylePanel-Cq1kpV26.js} +2 -2
- package/dist/npm/chunks/TaskFields-5DrG37f5.js +652 -0
- package/dist/npm/chunks/{ThreadCard-xKy4JbXK.js → ThreadCard-DWOvH-6X.js} +60 -59
- package/dist/npm/chunks/{Viewer-DL6M3wAT.js → Viewer-oM3stPeq.js} +1 -1
- package/dist/npm/chunks/{agent-D1VQvc14.js → agent-C_0_3eQI.js} +1 -1
- package/dist/npm/chunks/{card-bits-B94SwnS9.js → card-bits-v0qOEmQL.js} +2 -2
- package/dist/npm/chunks/{client-CULjcQxz.js → client-D571FlER.js} +7 -7
- package/dist/npm/chunks/{confetti-K_xKxQGa.js → confetti-CM1XHlrM.js} +1 -1
- package/dist/npm/chunks/{dpop-DpxIN5kL.js → dpop-D9namjeG.js} +1 -1
- package/dist/npm/chunks/{entrance-CO0AzUKy.js → entrance-D7kmBxF3.js} +29 -29
- package/dist/npm/chunks/{extension-DpfiPOjC.js → extension-DMu26PbD.js} +1 -1
- package/dist/npm/chunks/{extension-faFfCApb.js → extension-DQDpEs3f.js} +2 -2
- package/dist/npm/chunks/{identify-963WDKul.js → identify-DQi27FAI.js} +1 -1
- package/dist/npm/chunks/{live-BI72WQBA.js → live-KT4Lz5KA.js} +5 -5
- package/dist/npm/chunks/{page-key-CW8Mtf60.js → page-key-DJLO6bSu.js} +1 -1
- package/dist/npm/chunks/{pick-BRhngGMq.js → pick-DxkzYQsl.js} +1 -1
- package/dist/npm/chunks/{pkce-BEeLAZhN.js → pkce-DoqJ0Xee.js} +1 -1
- package/dist/npm/chunks/{report-DAzQvgUh.js → report-BQT_YYBQ.js} +1 -1
- package/dist/npm/chunks/sheet-77GHVTpR.js +18 -0
- package/dist/npm/chunks/{show-Ka3g4eCJ.js → show-C0biDb3b.js} +11 -9
- package/dist/npm/chunks/{signin-Car5vP1U.js → signin-BF96ZF52.js} +3 -3
- package/dist/npm/chunks/{source-dd_it90W.js → source-McjgKuFO.js} +1 -1
- package/dist/npm/chunks/{src-fTYV50pw.js → src-DwEQI1-g.js} +57 -52
- package/dist/npm/chunks/{start-CE5eR33Z.js → start-B8nZq-te.js} +428 -429
- package/dist/npm/chunks/{upload-Dcv9CCly.js → upload-CJ_71f0-.js} +1 -1
- package/dist/npm/chunks/{uploads-CmeoNVO2.js → uploads-AeS6wVkL.js} +21 -20
- package/dist/npm/chunks/waiting-BRtT3ZZT.js +54 -0
- package/dist/npm/chunks/{wrap-B0mzrRhc.js → wrap-B9jekR6h.js} +1 -1
- package/dist/npm/element.js +1 -1
- package/dist/npm/headless.js +2 -2
- package/dist/npm/index.js +2 -2
- package/dist/npm/react.js +1 -1
- package/dist/npm/svelte.js +1 -1
- package/dist/npm/types/core/client.d.ts +2 -0
- package/dist/npm/vue.js +1 -1
- package/package.json +1 -1
- package/dist/npm/chunks/TaskFields-B2-YvIwV.js +0 -617
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,34 @@
|
|
|
1
1
|
# @commentkit/comment-kit
|
|
2
2
|
|
|
3
|
+
## [2.1.3] - 2026-11-24
|
|
4
|
+
|
|
5
|
+
### Added
|
|
6
|
+
|
|
7
|
+
- `init --plugin` adds the build plugin on its own, for a website that loads the widget with the script tag and wants the source file and line on its feedback. It needs the package as a dev dependency and says so.
|
|
8
|
+
|
|
9
|
+
### Changed
|
|
10
|
+
|
|
11
|
+
- `init` recognises a website that already loads the widget with the hosted script tag. It says CommentKit is already installed there and offers no `init()` call, env file or package install.
|
|
12
|
+
|
|
13
|
+
### Fixed
|
|
14
|
+
|
|
15
|
+
- `doctor` no longer reports "No project key found" in a folder whose script tag takes its key from the app's config (for example `data-project="{{ config('services.commentkit.key') }}"` in Laravel, or `data-project={KEY}` in a Next.js layout). It reads the key from the config file or the constant. When the key really is set at run time, it says so and points to `doctor <address>` without failing.
|
|
16
|
+
- `status`, `pull` and the other commands find a script-tag folder's website from that key, without running `use` first.
|
|
17
|
+
- `init` no longer warns that a page "will not show the widget" when the page includes the script tag through a Blade component or include.
|
|
18
|
+
- `doctor <address>` no longer reports a blocked script for a site that bundles the package from npm: it checks `script-src` only when the page loads the hosted script.
|
|
19
|
+
- `token list` shows CI tokens only. A terminal or coding agent sign-in is no longer listed there, and `token revoke` refuses one with a message saying where to end it.
|
|
20
|
+
|
|
21
|
+
## [2.1.2] - 2026-11-22
|
|
22
|
+
|
|
23
|
+
### Changed
|
|
24
|
+
|
|
25
|
+
- When Cmd/Ctrl+Shift+K brings up a hidden widget and it takes a moment to arrive, a small "Loading…" appears where the toolbar will be. The toolbar also arrives sooner on slow connections, because the parts it needs now download at the same time. Pressing the shortcut again while it loads is the same request: it no longer opens the inbox or reaches your page.
|
|
26
|
+
|
|
27
|
+
### Fixed
|
|
28
|
+
|
|
29
|
+
- The toolbar's ⋯ menu closes when you press Comment (or C, or anything that opens the inbox, Settings or a note by the toolbar), so it no longer sits on top of the "Sign in to comment" note. Opening the menu while that note shows closes the note.
|
|
30
|
+
- The lists for priority, assignee, labels, due date and status open whole. In the comment box they were cut off by the bottom of the card; they now open below when there is room, above when there is not, and scroll inside themselves on small screens.
|
|
31
|
+
|
|
3
32
|
## [2.1.1] - 2026-11-21
|
|
4
33
|
|
|
5
34
|
### Fixed
|
package/dist/node/cli/doctor.js
CHANGED
|
@@ -5,7 +5,7 @@ import { join } from "node:path";
|
|
|
5
5
|
import { DASHBOARD } from "../shared/dashboard-places.js";
|
|
6
6
|
import { CliError, Connection, endpointFrom } from "./api.js";
|
|
7
7
|
import { safeUrl } from "./format.js";
|
|
8
|
-
import { describePlace, PLUGIN_IMPORT, plan
|
|
8
|
+
import { describePlace, envValue, PLUGIN_IMPORT, plan } from "./init.js";
|
|
9
9
|
import { PUBLISHABLE_KEY } from "./main.js";
|
|
10
10
|
const TIMEOUT_MS = 10_000;
|
|
11
11
|
const MAX_PAGE_BYTES = 2 * 1024 * 1024;
|
|
@@ -329,13 +329,7 @@ function readJson(file) {
|
|
|
329
329
|
return null;
|
|
330
330
|
}
|
|
331
331
|
}
|
|
332
|
-
|
|
333
|
-
export function envValue(text, name) {
|
|
334
|
-
const m = new RegExp(`^\\s*(?:export\\s+)?${name}\\s*=\\s*(.*)$`, "m").exec(text);
|
|
335
|
-
if (!m)
|
|
336
|
-
return null;
|
|
337
|
-
return m[1].trim().replace(/\s+#.*$/, "").replace(/^(["'])(.*)\1$/, "$2");
|
|
338
|
-
}
|
|
332
|
+
export { envValue };
|
|
339
333
|
function projectSetup(cwd, flagKey, env) {
|
|
340
334
|
const checks = [];
|
|
341
335
|
const pkg = readJson(join(cwd, "package.json"));
|
|
@@ -349,15 +343,20 @@ function projectSetup(cwd, flagKey, env) {
|
|
|
349
343
|
const installedVersion = typeof installed?.version === "string" ? clean(installed.version, 40) : null;
|
|
350
344
|
const html = htmlFiles.map((f) => ({ file: f, text: readFileSync(join(cwd, f), "utf8") }));
|
|
351
345
|
const htmlLoader = html.map((h) => ({ file: h.file, sdk: findSdk(h.text, "http://localhost/") })).find((h) => h.sdk.loader);
|
|
352
|
-
//
|
|
353
|
-
|
|
354
|
-
const
|
|
346
|
+
// The hosted script tag the folder loads the widget with (a Blade template, index.html, a Next.js layout…),
|
|
347
|
+
// with its key read statically: written on the tag, or through config(), an env variable or a constant.
|
|
348
|
+
const tag = p.scriptTag;
|
|
349
|
+
// The package can be there for the build plugin alone: with the script tag, the widget is not bundled.
|
|
350
|
+
const bundled = Boolean(deps[SDK]) && !tag;
|
|
355
351
|
// Where the widget is: the entry or a file it imports (Vite, Laravel), else what init's plan found.
|
|
356
352
|
const widget = p.widget;
|
|
357
353
|
const add = p.install[0]?.join(" ") ?? `npm install ${SDK}`;
|
|
358
354
|
if (!appFound) {
|
|
359
355
|
checks.push({ id: "setup.app", status: "info", message: "No package.json or index.html in this folder, so the project checks were skipped.", fix: `Run ${CLI} doctor in your app's folder to include them.` });
|
|
360
356
|
}
|
|
357
|
+
else if (tag) {
|
|
358
|
+
checks.push({ id: "setup.package", status: "pass", message: `The CommentKit script tag is in ${tag.file}.` });
|
|
359
|
+
}
|
|
361
360
|
else if (bundled) {
|
|
362
361
|
checks.push(installedVersion
|
|
363
362
|
? { id: "setup.package", status: "pass", message: `${SDK} ${installedVersion} is installed (${p.label}).` }
|
|
@@ -366,9 +365,6 @@ function projectSetup(cwd, flagKey, env) {
|
|
|
366
365
|
else if (htmlLoader) {
|
|
367
366
|
checks.push({ id: "setup.package", status: "pass", message: `The CommentKit script tag is in ${htmlLoader.file}.` });
|
|
368
367
|
}
|
|
369
|
-
else if (templateTags.length) {
|
|
370
|
-
checks.push({ id: "setup.package", status: "pass", message: `The CommentKit script tag is in ${templateTags.map((t) => t.file).slice(0, 3).join(", ")}${templateTags.length > 3 ? ` and ${templateTags.length - 3} more` : ""}.` });
|
|
371
|
-
}
|
|
372
368
|
else if (p.entry === "done") {
|
|
373
369
|
checks.push({ id: "setup.package", status: "pass", message: `The CommentKit script tag is in your ${p.label} app.` });
|
|
374
370
|
}
|
|
@@ -418,17 +414,21 @@ function projectSetup(cwd, flagKey, env) {
|
|
|
418
414
|
keyVar = name;
|
|
419
415
|
}
|
|
420
416
|
}
|
|
421
|
-
|
|
417
|
+
// index.html's tag as written; a folder whose tag init.ts found (tag) has its key resolved below instead.
|
|
418
|
+
if (!key && !tag && htmlLoader?.sdk.loader?.key) {
|
|
422
419
|
key = htmlLoader.sdk.loader.key;
|
|
423
420
|
keySource = htmlLoader.file;
|
|
424
421
|
}
|
|
425
|
-
// Written into the code as the default (init({ project: import.meta.env.VITE_COMMENTKIT_KEY || "pk_…" })), or
|
|
426
|
-
|
|
422
|
+
// Written into the code as the default (init({ project: import.meta.env.VITE_COMMENTKIT_KEY || "pk_…" })), or the
|
|
423
|
+
// script tag's key: on the tag, or where it reads it (config/services.php, .env, a constant in the layout).
|
|
424
|
+
const written = [widget, tag].find((place) => place?.key);
|
|
427
425
|
if (!key && written) {
|
|
428
426
|
key = written.key;
|
|
429
|
-
keySource = written.file;
|
|
427
|
+
keySource = written.keySource ?? written.file;
|
|
430
428
|
}
|
|
431
429
|
}
|
|
430
|
+
// A script tag whose key the app supplies at run time in a way a static read cannot follow: not an error.
|
|
431
|
+
const keyAtRunTime = !key && Boolean(tag?.keyAtRunTime);
|
|
432
432
|
if (key && !PUBLISHABLE_KEY.test(key)) {
|
|
433
433
|
checks.push({ id: "setup.key", status: "fail", message: `The project key in ${keySource} is not a publishable key (it should look like pk_live_… or pk_test_…).`, fix: `Copy the key again from ${DASHBOARD.install} in CommentKit.` });
|
|
434
434
|
}
|
|
@@ -438,6 +438,9 @@ function projectSetup(cwd, flagKey, env) {
|
|
|
438
438
|
checks.push({ id: "setup.key-name", status: "warn", message: `${p.label} apps do not read ${keyVar}, so the widget gets no key.`, fix: `Rename it to ${p.envVar} in ${keySource.split(" ")[0]}.` });
|
|
439
439
|
}
|
|
440
440
|
}
|
|
441
|
+
else if (keyAtRunTime) {
|
|
442
|
+
checks.push({ id: "setup.key", status: "info", message: `The script tag in ${tag.file} takes its project key from the app at run time, so it cannot be read here. ${CLI} doctor <address> checks the key on the live page.` });
|
|
443
|
+
}
|
|
441
444
|
else if (appFound && p.framework === "laravel") {
|
|
442
445
|
checks.push({ id: "setup.key", status: "fail", message: "No project key found in .env, your JavaScript entry or a Blade script tag.", fix: `Run ${CLI} init, or write the key into your entry: init({ project: import.meta.env.VITE_COMMENTKIT_KEY || "pk_…" }) (the key is in ${DASHBOARD.install} in CommentKit). If the key comes from somewhere else, run ${CLI} doctor --key pk_… instead.` });
|
|
443
446
|
}
|
|
@@ -447,16 +450,21 @@ function projectSetup(cwd, flagKey, env) {
|
|
|
447
450
|
// A Laravel app without a JavaScript entry uses the script tag: there is no build to add the plugin to.
|
|
448
451
|
if (appFound && p.framework !== "html" && !(p.framework === "laravel" && !p.configFile)) {
|
|
449
452
|
const config = p.configFile ? readFileSync(join(cwd, p.configFile), "utf8") : "";
|
|
453
|
+
// With the script tag, init adds the plugin only when asked (--plugin), and it needs the package as a dev dependency.
|
|
454
|
+
const how = tag
|
|
455
|
+
? `Run ${CLI} init --plugin ${p.configFile && !p.configEdit ? "for the lines to add" : "to add it"} (it needs ${SDK} as a dev dependency).`
|
|
456
|
+
: p.configFile && !p.configEdit ? `Run ${CLI} init: it prints the lines to add to ${p.configFile}, which it cannot edit safely.` : `Run ${CLI} init to add it.`;
|
|
450
457
|
if (PLUGIN_IMPORT.test(config))
|
|
451
458
|
checks.push({ id: "setup.plugin", status: "pass", message: `The build plugin is set up in ${p.configFile}.` });
|
|
452
459
|
else
|
|
453
|
-
checks.push({ id: "setup.plugin", status: "info", message: "The build plugin is not set up. It is optional: it adds source file and line to feedback, so you and your coding agent land on the right code.", fix:
|
|
460
|
+
checks.push({ id: "setup.plugin", status: "info", message: "The build plugin is not set up. It is optional: it adds source file and line to feedback, so you and your coding agent land on the right code.", fix: how });
|
|
454
461
|
}
|
|
455
|
-
return { checks, key, keySource, installedVersion, bundled, appFound };
|
|
462
|
+
return { checks, key, keySource, installedVersion, bundled, appFound, keyAtRunTime };
|
|
456
463
|
}
|
|
457
464
|
/**
|
|
458
465
|
* The publishable key written in this folder, where doctor and init look for it: the env files init
|
|
459
|
-
* writes, the
|
|
466
|
+
* writes, the default in the entry file, the script tag's key (on the tag, or read statically through
|
|
467
|
+
* config('…') and config/*.php, an env variable or a constant in the layout; init.ts tagKey). Not the shell's
|
|
460
468
|
* environment variables: they belong to the terminal, not to the folder.
|
|
461
469
|
*/
|
|
462
470
|
export function folderKey(cwd) {
|
|
@@ -682,7 +690,7 @@ export async function doctor(options, deps = {}) {
|
|
|
682
690
|
config = result.config;
|
|
683
691
|
checks.push(result.check);
|
|
684
692
|
}
|
|
685
|
-
else if (setup.appFound) {
|
|
693
|
+
else if (setup.appFound && !setup.keyAtRunTime) {
|
|
686
694
|
checks.push({ id: "api.key", status: "info", message: "Skipped the check with CommentKit: there is no valid project key." });
|
|
687
695
|
}
|
|
688
696
|
// The folder's key belongs to another website than the one the CLI is signed in to. When CommentKit
|
|
@@ -769,8 +777,9 @@ export async function doctor(options, deps = {}) {
|
|
|
769
777
|
const where = headerCsp && meta.length ? "the Content-Security-Policy header and <meta> tag" : headerCsp ? "the Content-Security-Policy header" : "the <meta http-equiv=\"Content-Security-Policy\"> tag";
|
|
770
778
|
const pageUrl = page.url.href;
|
|
771
779
|
// The loader comes from the CDN and imports the widget from the same folder (src/loader.ts).
|
|
772
|
-
// A bundled SDK is the site's own code, so script-src only matters for the script tag
|
|
773
|
-
|
|
780
|
+
// A bundled SDK is the site's own code, so script-src only matters for the script tag: checked when the
|
|
781
|
+
// page has the tag, or when neither the page nor this folder shows signs of the bundled SDK.
|
|
782
|
+
if (sdk.loader || (!sdk.markers.length && !setup.bundled)) {
|
|
774
783
|
const loaderSrc = sdk.loader?.src ?? `${endpoint}/cdn/v1/loader.js`;
|
|
775
784
|
const origin = new URL(loaderSrc).origin;
|
|
776
785
|
const v = cspAllows(policies, "script", loaderSrc, pageUrl, sdk.loader?.nonce ?? undefined);
|
package/dist/node/cli/init.js
CHANGED
|
@@ -239,6 +239,192 @@ function resolveImport(dir, from, spec, laravel) {
|
|
|
239
239
|
return candidates.find((f) => SCRIPT_FILE.test(f) && existsSync(join(dir, f)) && statSync(join(dir, f)).isFile()) ?? null;
|
|
240
240
|
}
|
|
241
241
|
const KEY_LITERAL = /\bpk_(?:live|test)_[a-z0-9]{20,40}\b/;
|
|
242
|
+
/** KEY=value lines of an env file (quotes and `export` allowed). */
|
|
243
|
+
export function envValue(text, name) {
|
|
244
|
+
const m = new RegExp(`^\\s*(?:export\\s+)?${name}\\s*=\\s*(.*)$`, "m").exec(text);
|
|
245
|
+
if (!m)
|
|
246
|
+
return null;
|
|
247
|
+
return m[1].trim().replace(/\s+#.*$/, "").replace(/^(["'])(.*)\1$/, "$2");
|
|
248
|
+
}
|
|
249
|
+
// ---------------------------------------------------------------------------------------------
|
|
250
|
+
// The key of a script tag whose data-project is not written out: a static read, nothing is run.
|
|
251
|
+
/** The env files Laravel's env() reads, and those a JavaScript build (Next.js, Vite) reads, most specific first. */
|
|
252
|
+
const PHP_ENV_FILES = [".env"];
|
|
253
|
+
const JS_ENV_FILES = [".env.local", ".env.production.local", ".env.production", ".env"];
|
|
254
|
+
/** Config files and layouts are small; anything larger is not read for a key. */
|
|
255
|
+
const MAX_KEY_FILE = 256 * 1024;
|
|
256
|
+
function readSmall(dir, file) {
|
|
257
|
+
try {
|
|
258
|
+
const path = join(dir, file);
|
|
259
|
+
if (!statSync(path).isFile() || statSync(path).size > MAX_KEY_FILE)
|
|
260
|
+
return null;
|
|
261
|
+
return readFileSync(path, "utf8");
|
|
262
|
+
}
|
|
263
|
+
catch {
|
|
264
|
+
return null;
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
/** The first env file in `files` that sets `name` to something, as { value, source }. */
|
|
268
|
+
function envFrom(dir, files, name) {
|
|
269
|
+
for (const file of files) {
|
|
270
|
+
const text = readSmall(dir, file);
|
|
271
|
+
const value = text === null ? null : envValue(text, name);
|
|
272
|
+
if (value)
|
|
273
|
+
return { value, source: `${file} (${name})` };
|
|
274
|
+
}
|
|
275
|
+
return null;
|
|
276
|
+
}
|
|
277
|
+
/**
|
|
278
|
+
* The key an expression gives, read statically: an env variable it names when an env file sets it (env('X'),
|
|
279
|
+
* process.env.X, import.meta.env.X), else the publishable key written in it as the default
|
|
280
|
+
* (env('X') ?: 'pk_…', env('X', 'pk_…'), process.env.X || "pk_…"). A value an env file sets that is not a
|
|
281
|
+
* publishable key is returned as it is, so doctor can say so without printing it. Null when neither is there.
|
|
282
|
+
*/
|
|
283
|
+
function keyOfExpression(dir, expr, file) {
|
|
284
|
+
const names = [];
|
|
285
|
+
for (const m of expr.matchAll(/\benv\s*\(\s*(["'])([A-Za-z_][A-Za-z0-9_]*)\1/g))
|
|
286
|
+
names.push({ name: m[2], files: PHP_ENV_FILES });
|
|
287
|
+
for (const m of expr.matchAll(/\b(?:process|import\.meta)\.env(?:\.([A-Za-z_][A-Za-z0-9_]*)|\[\s*(["'])([A-Za-z_][A-Za-z0-9_]*)\2\s*\])/g))
|
|
288
|
+
names.push({ name: m[1] ?? m[3], files: JS_ENV_FILES });
|
|
289
|
+
// Vite replaces %VITE_X% in index.html with the env variable.
|
|
290
|
+
for (const m of expr.matchAll(/^%([A-Za-z_][A-Za-z0-9_]*)%$/g))
|
|
291
|
+
names.push({ name: m[1], files: JS_ENV_FILES });
|
|
292
|
+
for (const { name, files } of names) {
|
|
293
|
+
const found = envFrom(dir, files, name);
|
|
294
|
+
if (found)
|
|
295
|
+
return { key: found.value, source: found.source };
|
|
296
|
+
}
|
|
297
|
+
const literal = /(["'`])(pk_(?:live|test)_[a-z0-9]{20,40})\1/.exec(expr)?.[2];
|
|
298
|
+
return literal ? { key: literal, source: file } : null;
|
|
299
|
+
}
|
|
300
|
+
/** 1 for each character of PHP `source` that is code; 0 inside strings and comments. */
|
|
301
|
+
function phpMask(source) {
|
|
302
|
+
const mask = new Uint8Array(source.length);
|
|
303
|
+
let i = 0;
|
|
304
|
+
while (i < source.length) {
|
|
305
|
+
const c = source[i];
|
|
306
|
+
if ((c === "/" && source[i + 1] === "/") || (c === "#" && source[i + 1] !== "[")) {
|
|
307
|
+
while (i < source.length && source[i] !== "\n")
|
|
308
|
+
i++;
|
|
309
|
+
}
|
|
310
|
+
else if (c === "/" && source[i + 1] === "*") {
|
|
311
|
+
const end = source.indexOf("*/", i + 2);
|
|
312
|
+
i = end < 0 ? source.length : end + 2;
|
|
313
|
+
}
|
|
314
|
+
else if (c === '"' || c === "'") {
|
|
315
|
+
i++;
|
|
316
|
+
while (i < source.length && source[i] !== c)
|
|
317
|
+
i += source[i] === "\\" ? 2 : 1;
|
|
318
|
+
i++;
|
|
319
|
+
}
|
|
320
|
+
else {
|
|
321
|
+
mask[i++] = 1;
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
return mask;
|
|
325
|
+
}
|
|
326
|
+
/**
|
|
327
|
+
* The PHP expression a Laravel config file gives for `path` (config('services.commentkit.key') reads
|
|
328
|
+
* config/services.php, then ['commentkit']['key']). Only array literals are followed; null for anything else.
|
|
329
|
+
*/
|
|
330
|
+
export function phpConfigValue(source, path) {
|
|
331
|
+
const mask = phpMask(source);
|
|
332
|
+
const ret = [...source.matchAll(/\breturn\s*(\[|array\s*\()/g)].find((m) => mask[m.index]);
|
|
333
|
+
if (!ret || !path.length)
|
|
334
|
+
return null;
|
|
335
|
+
let open = ret.index + ret[0].length - 1;
|
|
336
|
+
for (let n = 0; n < path.length; n++) {
|
|
337
|
+
const close = closing(source, mask, open);
|
|
338
|
+
if (close < 0)
|
|
339
|
+
return null;
|
|
340
|
+
let depth = 0;
|
|
341
|
+
let value = -1;
|
|
342
|
+
for (let i = open + 1; i < close && value < 0; i++) {
|
|
343
|
+
if (mask[i]) {
|
|
344
|
+
if ("([{".includes(source[i]))
|
|
345
|
+
depth++;
|
|
346
|
+
else if (")]}".includes(source[i]))
|
|
347
|
+
depth--;
|
|
348
|
+
continue;
|
|
349
|
+
}
|
|
350
|
+
// A string starting here, at the top level of this array: is it the key we want, followed by =>?
|
|
351
|
+
if (depth !== 0 || mask[i - 1] === 0)
|
|
352
|
+
continue;
|
|
353
|
+
const m = /^(["'])([^"'\\]*)\1\s*=>\s*/.exec(source.slice(i, close));
|
|
354
|
+
if (m && m[2] === path[n])
|
|
355
|
+
value = i + m[0].length;
|
|
356
|
+
}
|
|
357
|
+
if (value < 0)
|
|
358
|
+
return null;
|
|
359
|
+
if (n < path.length - 1) {
|
|
360
|
+
const nested = /^(\[|array\s*\()/.exec(source.slice(value));
|
|
361
|
+
if (!nested)
|
|
362
|
+
return null;
|
|
363
|
+
open = value + nested[0].length - 1;
|
|
364
|
+
continue;
|
|
365
|
+
}
|
|
366
|
+
// The last key: its value runs to the next comma at this level, or the end of the array.
|
|
367
|
+
let end = value;
|
|
368
|
+
for (let d = 0; end < close; end++) {
|
|
369
|
+
if (!mask[end])
|
|
370
|
+
continue;
|
|
371
|
+
if ("([{".includes(source[end]))
|
|
372
|
+
d++;
|
|
373
|
+
else if (")]}".includes(source[end]))
|
|
374
|
+
d--;
|
|
375
|
+
else if (source[end] === "," && d === 0)
|
|
376
|
+
break;
|
|
377
|
+
}
|
|
378
|
+
return source.slice(value, end).trim();
|
|
379
|
+
}
|
|
380
|
+
return null;
|
|
381
|
+
}
|
|
382
|
+
/** The value of the data-project attribute of a script tag as written: "…", '…', {…} (JSX) or bare. */
|
|
383
|
+
function dataProject(tag) {
|
|
384
|
+
const m = /\bdata-project\s*=\s*(?:"([^"]*)"|'([^']*)'|\{([^}]*)\}|([^\s"'>{]+))/i.exec(tag);
|
|
385
|
+
return m ? { value: (m[1] ?? m[2] ?? m[3] ?? m[4] ?? "").trim(), jsx: m[3] !== undefined } : null;
|
|
386
|
+
}
|
|
387
|
+
/**
|
|
388
|
+
* The key a script tag in `file` uses: written on the tag (data-project="pk_…", loader.js?project=pk_…),
|
|
389
|
+
* or through config('a.b') (Blade), an env variable, or a constant declared in the same file (JSX
|
|
390
|
+
* data-project={KEY}). `atRunTime` when the tag has a key from somewhere this static read cannot follow.
|
|
391
|
+
*/
|
|
392
|
+
export function tagKey(dir, file, text, tag) {
|
|
393
|
+
const query = /[?&]project=(pk_(?:live|test)_[a-z0-9]{20,40})\b/.exec(tag)?.[1];
|
|
394
|
+
const attr = dataProject(tag);
|
|
395
|
+
const raw = attr?.value ?? "";
|
|
396
|
+
if (!raw)
|
|
397
|
+
return query ? { key: query } : {};
|
|
398
|
+
const literal = /^(pk_(?:live|test)_[a-z0-9]{20,40})$/.exec(raw)?.[1];
|
|
399
|
+
if (literal)
|
|
400
|
+
return { key: literal };
|
|
401
|
+
// Plain text that is no template or expression: the key as written (doctor says when it is not a publishable key).
|
|
402
|
+
if (!attr.jsx && !/[{}%$()]/.test(raw))
|
|
403
|
+
return { key: raw };
|
|
404
|
+
let expr = raw.replace(/^\{\{-?|-?\}\}$|^\{!!|!!\}$/g, "").trim();
|
|
405
|
+
// JSX: data-project={COMMENTKIT_KEY} → const COMMENTKIT_KEY = process.env.X || "pk_…"; in the same file.
|
|
406
|
+
if (attr.jsx && /^[A-Za-z_$][\w$]*$/.test(expr)) {
|
|
407
|
+
const name = expr.replace(/\$/g, "\\$");
|
|
408
|
+
const declared = new RegExp(`\\b(?:const|let|var)\\s+${name}\\s*(?::[^=\\n]+)?=\\s*([^;\\n]+)`).exec(text);
|
|
409
|
+
if (!declared)
|
|
410
|
+
return { keyAtRunTime: true };
|
|
411
|
+
expr = declared[1];
|
|
412
|
+
}
|
|
413
|
+
// Blade: {{ config('services.commentkit.key') }}, optionally with a default.
|
|
414
|
+
const config = /\bconfig\s*\(\s*(["'])([A-Za-z0-9_-]+(?:\.[A-Za-z0-9_-]+)+)\1\s*(?:,([^)]*))?\)/.exec(expr);
|
|
415
|
+
if (config) {
|
|
416
|
+
const [name, ...path] = config[2].split(".");
|
|
417
|
+
const configFile = `config/${name}.php`;
|
|
418
|
+
const source = readSmall(dir, configFile);
|
|
419
|
+
const value = source === null ? null : phpConfigValue(source, path);
|
|
420
|
+
const found = (value !== null && keyOfExpression(dir, value, configFile)) || (config[3] ? keyOfExpression(dir, config[3], file) : null);
|
|
421
|
+
return found ? { key: found.key, keySource: found.source } : { keyAtRunTime: true };
|
|
422
|
+
}
|
|
423
|
+
const found = keyOfExpression(dir, expr, file);
|
|
424
|
+
if (!found)
|
|
425
|
+
return { keyAtRunTime: true };
|
|
426
|
+
return found.source === file ? { key: found.key } : { key: found.key, keySource: found.source };
|
|
427
|
+
}
|
|
242
428
|
/** Is the widget set up in one of `entries`, or in a file one of them imports directly? */
|
|
243
429
|
export function widgetInEntries(dir, entries, laravel = false) {
|
|
244
430
|
const read = (file) => readFileSync(join(dir, file), "utf8");
|
|
@@ -301,18 +487,75 @@ function publicHtml(dir) {
|
|
|
301
487
|
return [];
|
|
302
488
|
}
|
|
303
489
|
}
|
|
490
|
+
/** The script tag in `file`, with the key it uses (tagKey), or null when the file has no tag. */
|
|
491
|
+
function tagIn(dir, file, text) {
|
|
492
|
+
const tag = LOADER_TAG.exec(text)?.[0];
|
|
493
|
+
return tag ? { file, ...tagKey(dir, file, text, tag) } : null;
|
|
494
|
+
}
|
|
304
495
|
/** Blade templates and public/*.html files that hold the CommentKit script tag. */
|
|
305
496
|
export function templatesWithTag(dir) {
|
|
306
497
|
const found = [];
|
|
307
498
|
for (const file of [...bladeFiles(dir), ...publicHtml(dir)]) {
|
|
308
|
-
const
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
continue;
|
|
312
|
-
const key = /\bdata-project\s*=\s*["']?(pk_(?:live|test)_[a-z0-9]{20,40})\b/.exec(tag)?.[1] ?? /[?&]project=(pk_(?:live|test)_[a-z0-9]{20,40})\b/.exec(tag)?.[1];
|
|
313
|
-
found.push({ file, ...(key ? { key } : {}) });
|
|
499
|
+
const place = tagIn(dir, file, readFileSync(join(dir, file), "utf8"));
|
|
500
|
+
if (place)
|
|
501
|
+
found.push(place);
|
|
314
502
|
}
|
|
315
|
-
|
|
503
|
+
// A tag whose key can be read first: a second copy of the component without one says less.
|
|
504
|
+
return found.sort((a, b) => Number(Boolean(b.key)) - Number(Boolean(a.key)));
|
|
505
|
+
}
|
|
506
|
+
/** The files that render a JavaScript app's whole document: where its script tag goes. */
|
|
507
|
+
const DOCUMENT_FILES = [
|
|
508
|
+
"index.html", "public/index.html", "src/app.html",
|
|
509
|
+
...["app/layout", "src/app/layout", "pages/_document", "src/pages/_document", "app/root"].flatMap((f) => ["tsx", "jsx", "js"].map((e) => `${f}.${e}`)),
|
|
510
|
+
];
|
|
511
|
+
/**
|
|
512
|
+
* The hosted script tag this folder already loads the widget with, when the widget is not set up in its
|
|
513
|
+
* JavaScript (no init() or <CommentKit> in an entry): a Blade template or public/*.html page (Laravel), or
|
|
514
|
+
* index.html, a Next.js or React Router layout, or an Astro layout. Null when there is none.
|
|
515
|
+
*/
|
|
516
|
+
export function findScriptTag(dir, framework) {
|
|
517
|
+
if (framework === "laravel") {
|
|
518
|
+
if (widgetInEntries(dir, laravelEntries(dir), true))
|
|
519
|
+
return null;
|
|
520
|
+
return templatesWithTag(dir)[0] ?? null;
|
|
521
|
+
}
|
|
522
|
+
if (framework === "vite" && widgetInEntries(dir, viteEntries(dir)))
|
|
523
|
+
return null;
|
|
524
|
+
let astro = [];
|
|
525
|
+
try {
|
|
526
|
+
astro = readdirSync(join(dir, "src/layouts")).filter((f) => f.endsWith(".astro")).sort().map((f) => `src/layouts/${f}`);
|
|
527
|
+
}
|
|
528
|
+
catch {
|
|
529
|
+
// no layouts folder
|
|
530
|
+
}
|
|
531
|
+
const found = [...DOCUMENT_FILES, ...astro].flatMap((file) => {
|
|
532
|
+
const text = readSmall(dir, file);
|
|
533
|
+
if (text === null || /["']@commentkit\/comment-kit(?:\/[a-z]+)?["']/.test(text))
|
|
534
|
+
return [];
|
|
535
|
+
const place = tagIn(dir, file, text);
|
|
536
|
+
return place ? [place] : [];
|
|
537
|
+
});
|
|
538
|
+
return found.find((p) => p.key) ?? found[0] ?? null;
|
|
539
|
+
}
|
|
540
|
+
/**
|
|
541
|
+
* Does a Blade template hold the script tag, or include (one level) a component or partial that does?
|
|
542
|
+
* `<x-commentkit />` is resources/views/components/commentkit.blade.php, `<x-site.tag />` components/site/tag.blade.php
|
|
543
|
+
* (or …/tag/index.blade.php), @include('partials.commentkit') resources/views/partials/commentkit.blade.php.
|
|
544
|
+
*/
|
|
545
|
+
export function bladeLoadsTag(dir, file, tagFiles) {
|
|
546
|
+
if (tagFiles.has(file))
|
|
547
|
+
return true;
|
|
548
|
+
const text = readSmall(dir, file) ?? "";
|
|
549
|
+
const views = "resources/views";
|
|
550
|
+
const included = [];
|
|
551
|
+
for (const m of text.matchAll(/<x-([a-z0-9][a-z0-9._:-]*)[\s/>]/gi)) {
|
|
552
|
+
const path = m[1].replace(/::/g, "/").replace(/\./g, "/");
|
|
553
|
+
included.push(`${views}/components/${path}.blade.php`, `${views}/components/${path}/index.blade.php`);
|
|
554
|
+
}
|
|
555
|
+
for (const m of text.matchAll(/@(?:include|includeIf|includeWhen|includeUnless|includeFirst|component|each)\s*\(\s*(?:[^'"]*?,\s*)?(["'])([a-z0-9_.\-/]+)\1/gi)) {
|
|
556
|
+
included.push(`${views}/${m[2].replace(/\./g, "/")}.blade.php`);
|
|
557
|
+
}
|
|
558
|
+
return included.some((f) => tagFiles.has(f));
|
|
316
559
|
}
|
|
317
560
|
/**
|
|
318
561
|
* Where the widget is set up, for the frameworks whose entry init can find more than one way: a Vite app's
|
|
@@ -537,7 +780,17 @@ export function wrapNextConfig(source) {
|
|
|
537
780
|
}
|
|
538
781
|
export function plan(dir, key) {
|
|
539
782
|
const detected = detect(dir);
|
|
540
|
-
|
|
783
|
+
const scriptTag = findScriptTag(dir, detected.framework);
|
|
784
|
+
const base = basePlan(dir, key, detected, scriptTag);
|
|
785
|
+
const add = detected.packageManager === "npm" ? ["npm", "install"] : [detected.packageManager, "add"];
|
|
786
|
+
if (!scriptTag)
|
|
787
|
+
return { ...base, entry: entryEdit(dir, detected.framework, key, major(detected.deps.svelte) ?? 5), widget: findWidget(dir, detected.framework), scriptTag: null, pluginInstall: [] };
|
|
788
|
+
// Installed with the script tag: nothing to add for the widget. The package is only needed for the
|
|
789
|
+
// optional build plugin, and then as a dev dependency.
|
|
790
|
+
return {
|
|
791
|
+
...base, install: [], entry: "done", widget: findWidget(dir, detected.framework) ?? scriptTag, scriptTag,
|
|
792
|
+
pluginInstall: detected.deps["@commentkit/comment-kit"] || !base.configFile ? [] : [[...add, "-D", "@commentkit/comment-kit"]],
|
|
793
|
+
};
|
|
541
794
|
}
|
|
542
795
|
/** "resources/js/commentkit.ts, imported by resources/js/app.ts" */
|
|
543
796
|
export function describePlace(place) {
|
|
@@ -550,7 +803,7 @@ const VITE_LAZY_PLUGIN = 'import commentkit from "@commentkit/comment-kit/vite";
|
|
|
550
803
|
export function vitePluginSnippet(source) {
|
|
551
804
|
return /\blazyPlugins\s*\(/.test(source) ? VITE_LAZY_PLUGIN : VITE_PLUGIN;
|
|
552
805
|
}
|
|
553
|
-
function basePlan(dir, key, { framework, packageManager, deps }) {
|
|
806
|
+
function basePlan(dir, key, { framework, packageManager, deps }, scriptTag) {
|
|
554
807
|
const add = packageManager === "npm" ? ["npm", "install"] : [packageManager, "add"];
|
|
555
808
|
// One package: the widget and the build plugins (@commentkit/comment-kit/vite, /next, /astro).
|
|
556
809
|
// Nothing to install for a plain website, or when package.json already lists the package.
|
|
@@ -609,7 +862,7 @@ function basePlan(dir, key, { framework, packageManager, deps }) {
|
|
|
609
862
|
};
|
|
610
863
|
}
|
|
611
864
|
case "laravel":
|
|
612
|
-
return laravelPlan(dir, key, packageManager, deps, install);
|
|
865
|
+
return laravelPlan(dir, key, packageManager, deps, install, scriptTag);
|
|
613
866
|
default:
|
|
614
867
|
return {
|
|
615
868
|
framework, packageManager, label: "a plain website", envFile: "", envVar: "", configFile: null, configEdit: null, configSnippet: "", manual: [], notes: [], install: [],
|
|
@@ -628,7 +881,7 @@ function laravelFlavour(dir, deps) {
|
|
|
628
881
|
const composer = readJsonFile(join(dir, "composer.json"));
|
|
629
882
|
return composer?.require?.["livewire/livewire"] || composer?.require?.["livewire/flux"] ? "Livewire" : "Blade";
|
|
630
883
|
}
|
|
631
|
-
function laravelPlan(dir, key, packageManager, deps, install) {
|
|
884
|
+
function laravelPlan(dir, key, packageManager, deps, install, scriptTag) {
|
|
632
885
|
const configFile = first(dir, VITE_CONFIGS);
|
|
633
886
|
const config = configFile ? readFileSync(join(dir, configFile), "utf8") : "";
|
|
634
887
|
const entries = laravelEntries(dir);
|
|
@@ -638,12 +891,25 @@ function laravelPlan(dir, key, packageManager, deps, install) {
|
|
|
638
891
|
const manual = [];
|
|
639
892
|
const composer = readJsonFile(join(dir, "composer.json"));
|
|
640
893
|
const placed = findWidget(dir, "laravel");
|
|
894
|
+
// Templates that hold the script tag, and whether a template loads it (itself or through a component it includes).
|
|
895
|
+
const tagFiles = new Set(templatesWithTag(dir).map((t) => t.file));
|
|
896
|
+
const loadsTag = (file) => tagFiles.size > 0 && bladeLoadsTag(dir, file, tagFiles);
|
|
641
897
|
if (entry && !placed) {
|
|
642
898
|
notes.push(`The key goes into ${entry} as the default value. Publishable keys are public by design, so it is safe to commit, and your server needs no new environment variable. To use another key in one place (pk_test_… on staging), set VITE_COMMENTKIT_KEY there before the build.`);
|
|
643
899
|
}
|
|
644
|
-
if (
|
|
900
|
+
if (scriptTag) {
|
|
901
|
+
// The widget comes from the script tag, not the JavaScript entry: a page shows it when its layout loads the tag.
|
|
902
|
+
const without = bladeLayouts(dir, templates).filter((f) => !loadsTag(f));
|
|
903
|
+
if (without.length) {
|
|
904
|
+
const shown = without.slice(0, 5).join(", ") + (without.length > 5 ? ` and ${without.length - 5} more` : "");
|
|
905
|
+
notes.push(`${without.length === 1 ? "This layout does" : "These layouts do"} not load the script tag, so ${without.length === 1 ? "its" : "their"} pages do not show the widget (fine if that is on purpose): ${shown}.`);
|
|
906
|
+
}
|
|
907
|
+
}
|
|
908
|
+
else if (entry) {
|
|
645
909
|
// Layouts whose @vite(...) lists only stylesheets: their pages never load the entry, so the widget is not there.
|
|
646
910
|
for (const file of templates) {
|
|
911
|
+
if (loadsTag(file))
|
|
912
|
+
continue;
|
|
647
913
|
for (const list of cssOnlyVite(readFileSync(join(dir, file), "utf8"))) {
|
|
648
914
|
const quoted = [...list, entry].map((f) => `'${f}'`).join(", ");
|
|
649
915
|
manual.push(`${file} loads only stylesheets with @vite, so its pages will not show the widget. To show it there, change that line to: @vite([${quoted}])`);
|
|
@@ -651,7 +917,9 @@ function laravelPlan(dir, key, packageManager, deps, install) {
|
|
|
651
917
|
}
|
|
652
918
|
}
|
|
653
919
|
if (composer?.require?.["filament/filament"]) {
|
|
654
|
-
notes.push(
|
|
920
|
+
notes.push(scriptTag
|
|
921
|
+
? "Filament admin panels render their own pages, without your layouts' script tag, so the widget does not show in them."
|
|
922
|
+
: `Filament admin panels do not load ${entry ?? "your app's JavaScript entry"}, so the widget does not show in them.`);
|
|
655
923
|
}
|
|
656
924
|
// No JavaScript entry at all: pages are plain Blade. init does not edit Blade; it prints the line and where it goes.
|
|
657
925
|
const layouts = bladeLayouts(dir, templates).slice(0, 5);
|
package/dist/node/cli/main.js
CHANGED
|
@@ -86,16 +86,18 @@ Which website a command uses, first match wins:
|
|
|
86
86
|
2. .commentkit/project.json in this folder or a parent (this command)
|
|
87
87
|
3. the publishable key in this folder (env file, entry file, script tag)
|
|
88
88
|
4. the sign-in's only website`,
|
|
89
|
-
init: `Usage: npx @commentkit/comment-kit init [--yes] [--dry-run] [--install] [--key pk_…]
|
|
89
|
+
init: `Usage: npx @commentkit/comment-kit init [--yes] [--dry-run] [--install] [--plugin] [--key pk_…]
|
|
90
90
|
|
|
91
91
|
Finds your framework (Next.js, Vite, SvelteKit, Astro, Nuxt, Laravel or a plain website) and
|
|
92
92
|
sets CommentKit up: the key in your env file (Laravel: in the entry, as the default), the build
|
|
93
93
|
plugin in your config, .commentkit/ in .gitignore, and the widget in your layout or entry file.
|
|
94
|
-
Asks before each change.
|
|
94
|
+
Asks before each change. When the folder already loads the widget with the script tag, it says
|
|
95
|
+
so and changes nothing for the widget; the build plugin is then offered on its own (--plugin).
|
|
95
96
|
|
|
96
97
|
--yes, -y Make every change without asking
|
|
97
98
|
--dry-run Show what would change, change nothing
|
|
98
99
|
--install Also install the package
|
|
100
|
+
--plugin With the script tag: also add the optional build plugin
|
|
99
101
|
--key <pk_…> Use this project key without signing in`,
|
|
100
102
|
doctor: `Usage: npx @commentkit/comment-kit doctor [url] [--key pk_…] [--json]
|
|
101
103
|
|
|
@@ -476,7 +478,7 @@ function run(command, cwd) {
|
|
|
476
478
|
});
|
|
477
479
|
}
|
|
478
480
|
async function init(args, out, cwd) {
|
|
479
|
-
const { values } = parseArgs({ args, options: { yes: { type: "boolean", short: "y" }, install: { type: "boolean" }, key: { type: "string" }, "dry-run": { type: "boolean" } } });
|
|
481
|
+
const { values } = parseArgs({ args, options: { yes: { type: "boolean", short: "y" }, install: { type: "boolean" }, plugin: { type: "boolean" }, key: { type: "string" }, "dry-run": { type: "boolean" } } });
|
|
480
482
|
const yes = Boolean(values.yes);
|
|
481
483
|
const dryRun = Boolean(values["dry-run"]);
|
|
482
484
|
let key = values.key;
|
|
@@ -518,6 +520,10 @@ async function init(args, out, cwd) {
|
|
|
518
520
|
throw new CliError("That is not a publishable key (pk_live_… or pk_test_…).");
|
|
519
521
|
const p = plan(cwd, key);
|
|
520
522
|
out.log(`Found ${p.label}.${dryRun ? " Dry run: nothing is changed." : ""}\n`);
|
|
523
|
+
// Already installed with the hosted script tag: said first, and nothing is added for the widget.
|
|
524
|
+
const tag = p.scriptTag;
|
|
525
|
+
if (tag)
|
|
526
|
+
out.log(`CommentKit is already installed here with the script tag in ${tag.file}. Nothing more is needed for the widget.\n`);
|
|
521
527
|
let skipped = 0;
|
|
522
528
|
// Each change is shown and confirmed (or --yes) before it is written; --dry-run only shows it.
|
|
523
529
|
const change = async (file, before, after, question) => {
|
|
@@ -535,7 +541,8 @@ async function init(args, out, cwd) {
|
|
|
535
541
|
skipped++;
|
|
536
542
|
};
|
|
537
543
|
const readOr = (file) => (existsSync(join(cwd, file)) ? readFileSync(join(cwd, file), "utf8") : "");
|
|
538
|
-
|
|
544
|
+
// The script tag carries its own key: no env file for it.
|
|
545
|
+
if (p.envVar && p.envFile && !tag) {
|
|
539
546
|
const before = readOr(p.envFile);
|
|
540
547
|
await change(p.envFile, before, setEnv(before, p.envVar, key), `Add ${p.envVar} to ${p.envFile}?`);
|
|
541
548
|
}
|
|
@@ -554,13 +561,16 @@ async function init(args, out, cwd) {
|
|
|
554
561
|
}
|
|
555
562
|
}
|
|
556
563
|
const configBefore = p.configFile ? readOr(p.configFile) : "";
|
|
557
|
-
|
|
564
|
+
// With the script tag the build plugin is a separate, optional step: only with --plugin.
|
|
565
|
+
const pluginOffered = Boolean(p.configFile) && (!tag || Boolean(values.plugin));
|
|
566
|
+
const pluginPending = Boolean(p.configFile && p.configEdit && p.configEdit !== configBefore) || Boolean(p.configFile && !p.configEdit);
|
|
567
|
+
if (pluginOffered && p.configFile && p.configEdit) {
|
|
558
568
|
await change(p.configFile, configBefore, p.configEdit, `Add the CommentKit build plugin to ${p.configFile}?`);
|
|
559
569
|
}
|
|
560
|
-
else if (p.configFile && !p.configEdit) {
|
|
570
|
+
else if (pluginOffered && p.configFile && !p.configEdit) {
|
|
561
571
|
out.log(`Could not edit ${p.configFile} safely, so it was left as it is. Add the build plugin by hand:\n ${p.configSnippet}\n${PLUGIN_NODE_NOTE}\n(more: https://commentkit.dev/docs/frameworks)\n`);
|
|
562
572
|
}
|
|
563
|
-
if (p.entry && p.entry !== "done") {
|
|
573
|
+
if (!tag && p.entry && p.entry !== "done") {
|
|
564
574
|
const { file, content, created } = p.entry;
|
|
565
575
|
await change(file, created ? "" : readOr(file), content, created ? `Create ${file} to show the widget?` : `Show the widget: add it to ${file}?`);
|
|
566
576
|
}
|
|
@@ -569,8 +579,27 @@ async function init(args, out, cwd) {
|
|
|
569
579
|
for (const line of p.notes)
|
|
570
580
|
out.log(line);
|
|
571
581
|
// Laravel servers often build on deploy, with whatever Node they have.
|
|
572
|
-
if (p.framework === "laravel" && p.configFile && p.configEdit && p.configEdit !== configBefore)
|
|
582
|
+
if (pluginOffered && p.framework === "laravel" && p.configFile && p.configEdit && p.configEdit !== configBefore)
|
|
573
583
|
out.log(PLUGIN_NODE_NOTE);
|
|
584
|
+
if (tag && pluginPending) {
|
|
585
|
+
if (!values.plugin) {
|
|
586
|
+
out.log(`${p.manual.length || p.notes.length ? "\n" : ""}Optional: the build plugin adds the source file and line to each piece of feedback, so you and your coding agent land on the right code. The script tag keeps showing the widget; the plugin needs @commentkit/comment-kit as a dev dependency${p.pluginInstall.length ? ` (${p.pluginInstall[0].join(" ")})` : ""}. To add it, run ${CLI} init --plugin${dryRun ? " --dry-run" : ""}.`);
|
|
587
|
+
}
|
|
588
|
+
else if (p.pluginInstall.length) {
|
|
589
|
+
if (values.install && !dryRun) {
|
|
590
|
+
for (const command of p.pluginInstall) {
|
|
591
|
+
out.log(`$ ${command.join(" ")}`);
|
|
592
|
+
if ((await run(command, cwd)) !== 0)
|
|
593
|
+
throw new CliError(`${command.join(" ")} failed.`);
|
|
594
|
+
}
|
|
595
|
+
}
|
|
596
|
+
else {
|
|
597
|
+
out.log("\nThe build plugin needs the package as a dev dependency:");
|
|
598
|
+
for (const command of p.pluginInstall)
|
|
599
|
+
out.log(` ${command.join(" ")}`);
|
|
600
|
+
}
|
|
601
|
+
}
|
|
602
|
+
}
|
|
574
603
|
if (p.install.length) {
|
|
575
604
|
if (values.install && !dryRun) {
|
|
576
605
|
for (const command of p.install) {
|
|
@@ -585,10 +614,12 @@ async function init(args, out, cwd) {
|
|
|
585
614
|
out.log(` ${command.join(" ")}`);
|
|
586
615
|
}
|
|
587
616
|
}
|
|
588
|
-
if (
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
617
|
+
if (!tag) {
|
|
618
|
+
if (p.entry === "done")
|
|
619
|
+
out.log(`\nThe widget is already in your app${p.widget ? ` (${describePlace(p.widget)})` : ""}.`);
|
|
620
|
+
else if (!p.entry)
|
|
621
|
+
out.log(`\nLast step, show the widget. ${p.snippet}\n`);
|
|
622
|
+
}
|
|
592
623
|
if (dryRun) {
|
|
593
624
|
out.log("\nRun it again without --dry-run to make these changes.");
|
|
594
625
|
return 0;
|