@mushi-mushi/cli 0.25.0 → 0.26.0

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/init.js CHANGED
@@ -14,7 +14,10 @@ import {
14
14
  resolveConsoleUrl,
15
15
  resolveConsoleUrlSync,
16
16
  saveConfig
17
- } from "./chunk-2WHQONHK.js";
17
+ } from "./chunk-L3LUPBFG.js";
18
+ import {
19
+ MUSHI_CLI_VERSION
20
+ } from "./chunk-MCVRTQAI.js";
18
21
  import {
19
22
  FRAMEWORKS,
20
23
  detectFramework,
@@ -23,9 +26,6 @@ import {
23
26
  installCommand,
24
27
  readPackageJson
25
28
  } from "./chunk-AIZRI665.js";
26
- import {
27
- MUSHI_CLI_VERSION
28
- } from "./chunk-SS42XQ57.js";
29
29
 
30
30
  // src/init.ts
31
31
  import * as p from "@clack/prompts";
@@ -478,6 +478,7 @@ async function runInit(options = {}) {
478
478
  persistCliConfig(credentials.apiKey, credentials.projectId, endpoint);
479
479
  emitWizardFunnelEvent(credentials, endpoint, "wizard_env_written", { framework: framework.id });
480
480
  const enableRewards = await maybeEnableRewards(options);
481
+ await maybeInjectSnippet(cwd, framework, options);
481
482
  printNextSteps(framework, consoleBase, enableRewards);
482
483
  await maybeSendTestReport(credentials, { ...options, endpoint, consoleBase });
483
484
  await maybeOfferConnect(credentials, options, consoleBase);
@@ -821,7 +822,12 @@ async function writeEnvFile(cwd, apiKey, projectId, framework, endpoint, overwri
821
822
  const target = ENV_FILES.find((f) => existsSync2(join2(cwd, f))) ?? ENV_FILES[0];
822
823
  const targetPath = join2(cwd, target);
823
824
  const newVars = envVarsToWrite(apiKey, projectId, framework, endpoint);
824
- const existing = existsSync2(targetPath) ? readFileSync2(targetPath, "utf-8") : "";
825
+ let existing = "";
826
+ try {
827
+ existing = readFileSync2(targetPath, "utf-8");
828
+ } catch {
829
+ existing = "";
830
+ }
825
831
  if (existing.includes("MUSHI_PROJECT_ID")) {
826
832
  let shouldOverwrite = overwrite;
827
833
  if (!shouldOverwrite) {
@@ -908,6 +914,31 @@ function emitWizardFunnelEvent(credentials, endpoint, event, metadata = {}) {
908
914
  }).catch(() => {
909
915
  });
910
916
  }
917
+ async function maybeInjectSnippet(cwd, framework, options) {
918
+ if (options.yes || !process.stdin.isTTY) return;
919
+ const { ENTRY_CANDIDATES, injectSnippet, MUSHI_MARKER_START } = await import("./snippet-inject-NDAPEL2T.js");
920
+ const candidates = ENTRY_CANDIDATES[framework.id];
921
+ if (!candidates) return;
922
+ const { readFile, writeFile } = await import("fs/promises");
923
+ const nodePath = await import("path");
924
+ for (const rel of candidates) {
925
+ const abs = nodePath.join(cwd, rel);
926
+ let source;
927
+ try {
928
+ source = await readFile(abs, "utf8");
929
+ } catch {
930
+ continue;
931
+ }
932
+ const alreadyInjected = source.includes(MUSHI_MARKER_START);
933
+ const confirmed = await p.confirm({
934
+ message: alreadyInjected ? `Refresh the Mushi init block in ${rel}?` : `Add the Mushi init snippet to ${rel}? (wrapped in markers; re-runs update in place)`
935
+ });
936
+ if (p.isCancel(confirmed) || !confirmed) return;
937
+ await writeFile(abs, injectSnippet(source, framework.snippet()), "utf8");
938
+ p.log.success(`${alreadyInjected ? "Updated" : "Added"} Mushi init block in ${rel}`);
939
+ return;
940
+ }
941
+ }
911
942
  function printNextSteps(framework, consoleBase, enableRewards = false) {
912
943
  p.note(framework.snippet(), "Add this to your app:");
913
944
  if (enableRewards) {
@@ -941,7 +972,7 @@ async function maybeOfferConnect(credentials, options, _consoleBase) {
941
972
  if (p.isCancel(answer) || !answer) return;
942
973
  const endpoint = resolveCloudEndpoint(options.endpoint);
943
974
  try {
944
- const { runConnect } = await import("./connect-XFWRSEMW.js");
975
+ const { runConnect } = await import("./connect-HCWJ6NXP.js");
945
976
  await runConnect({
946
977
  apiKey: credentials.apiKey,
947
978
  projectId: credentials.projectId,
@@ -0,0 +1,83 @@
1
+ #!/usr/bin/env node
2
+
3
+ // src/snippet-inject.ts
4
+ import { readFile, readdir } from "fs/promises";
5
+ import { join } from "path";
6
+ var MUSHI_MARKER_START = "// <mushi-mushi:init>";
7
+ var MUSHI_MARKER_END = "// </mushi-mushi:init>";
8
+ var ENTRY_CANDIDATES = {
9
+ vanilla: ["src/main.ts", "src/main.js", "src/index.ts", "src/index.js", "main.ts", "main.js", "index.js"]
10
+ };
11
+ function injectSnippet(source, snippet) {
12
+ const block = `${MUSHI_MARKER_START}
13
+ ${snippet.trim()}
14
+ ${MUSHI_MARKER_END}`;
15
+ const startIdx = source.indexOf(MUSHI_MARKER_START);
16
+ const endIdx = source.indexOf(MUSHI_MARKER_END);
17
+ if (startIdx !== -1 && endIdx !== -1 && endIdx > startIdx) {
18
+ return source.slice(0, startIdx) + block + source.slice(endIdx + MUSHI_MARKER_END.length);
19
+ }
20
+ const cleaned = source.split("\n").filter((l) => !l.includes(MUSHI_MARKER_START) && !l.includes(MUSHI_MARKER_END)).join("\n");
21
+ if (cleaned.startsWith("#!")) {
22
+ const nl = cleaned.indexOf("\n");
23
+ return `${cleaned.slice(0, nl + 1)}${block}
24
+ ${cleaned.slice(nl + 1)}`;
25
+ }
26
+ return `${block}
27
+
28
+ ${cleaned}`;
29
+ }
30
+ var SOURCE_DIRS = ["src", "app", "pages", "lib", "components"];
31
+ var SOURCE_EXTS = /* @__PURE__ */ new Set([".ts", ".tsx", ".js", ".jsx", ".mjs", ".vue", ".svelte"]);
32
+ var MAX_FILES_SCANNED = 2e3;
33
+ async function findSdkImport(cwd) {
34
+ let scanned = 0;
35
+ async function walk(dir, depth) {
36
+ if (depth > 6 || scanned >= MAX_FILES_SCANNED) return null;
37
+ let entries;
38
+ try {
39
+ entries = await readdir(dir, { withFileTypes: true });
40
+ } catch {
41
+ return null;
42
+ }
43
+ for (const entry of entries) {
44
+ if (scanned >= MAX_FILES_SCANNED) return null;
45
+ if (entry.isDirectory()) {
46
+ if (entry.name === "node_modules" || entry.name.startsWith(".")) continue;
47
+ const hit = await walk(join(dir, entry.name), depth + 1);
48
+ if (hit) return hit;
49
+ } else if (SOURCE_EXTS.has(entry.name.slice(entry.name.lastIndexOf(".")))) {
50
+ scanned += 1;
51
+ try {
52
+ const content = await readFile(join(dir, entry.name), "utf8");
53
+ if (content.includes("@mushi-mushi/") || content.includes("MushiProvider")) {
54
+ return { file: join(dir, entry.name) };
55
+ }
56
+ } catch {
57
+ }
58
+ }
59
+ }
60
+ return null;
61
+ }
62
+ for (const dirName of SOURCE_DIRS) {
63
+ const hit = await walk(join(cwd, dirName), 0);
64
+ if (hit) return hit;
65
+ }
66
+ for (const name of ["main.ts", "main.js", "index.js", "index.ts", "index.html"]) {
67
+ try {
68
+ const content = await readFile(join(cwd, name), "utf8");
69
+ if (content.includes("@mushi-mushi/") || content.includes("MushiProvider") || content.includes("mushi-mushi")) {
70
+ return { file: join(cwd, name) };
71
+ }
72
+ } catch {
73
+ }
74
+ }
75
+ return null;
76
+ }
77
+ export {
78
+ ENTRY_CANDIDATES,
79
+ MUSHI_MARKER_END,
80
+ MUSHI_MARKER_START,
81
+ findSdkImport,
82
+ injectSnippet
83
+ };
@@ -0,0 +1,81 @@
1
+ // src/snippet-inject.ts
2
+ import { readFile, readdir } from "fs/promises";
3
+ import { join } from "path";
4
+ var MUSHI_MARKER_START = "// <mushi-mushi:init>";
5
+ var MUSHI_MARKER_END = "// </mushi-mushi:init>";
6
+ var ENTRY_CANDIDATES = {
7
+ vanilla: ["src/main.ts", "src/main.js", "src/index.ts", "src/index.js", "main.ts", "main.js", "index.js"]
8
+ };
9
+ function injectSnippet(source, snippet) {
10
+ const block = `${MUSHI_MARKER_START}
11
+ ${snippet.trim()}
12
+ ${MUSHI_MARKER_END}`;
13
+ const startIdx = source.indexOf(MUSHI_MARKER_START);
14
+ const endIdx = source.indexOf(MUSHI_MARKER_END);
15
+ if (startIdx !== -1 && endIdx !== -1 && endIdx > startIdx) {
16
+ return source.slice(0, startIdx) + block + source.slice(endIdx + MUSHI_MARKER_END.length);
17
+ }
18
+ const cleaned = source.split("\n").filter((l) => !l.includes(MUSHI_MARKER_START) && !l.includes(MUSHI_MARKER_END)).join("\n");
19
+ if (cleaned.startsWith("#!")) {
20
+ const nl = cleaned.indexOf("\n");
21
+ return `${cleaned.slice(0, nl + 1)}${block}
22
+ ${cleaned.slice(nl + 1)}`;
23
+ }
24
+ return `${block}
25
+
26
+ ${cleaned}`;
27
+ }
28
+ var SOURCE_DIRS = ["src", "app", "pages", "lib", "components"];
29
+ var SOURCE_EXTS = /* @__PURE__ */ new Set([".ts", ".tsx", ".js", ".jsx", ".mjs", ".vue", ".svelte"]);
30
+ var MAX_FILES_SCANNED = 2e3;
31
+ async function findSdkImport(cwd) {
32
+ let scanned = 0;
33
+ async function walk(dir, depth) {
34
+ if (depth > 6 || scanned >= MAX_FILES_SCANNED) return null;
35
+ let entries;
36
+ try {
37
+ entries = await readdir(dir, { withFileTypes: true });
38
+ } catch {
39
+ return null;
40
+ }
41
+ for (const entry of entries) {
42
+ if (scanned >= MAX_FILES_SCANNED) return null;
43
+ if (entry.isDirectory()) {
44
+ if (entry.name === "node_modules" || entry.name.startsWith(".")) continue;
45
+ const hit = await walk(join(dir, entry.name), depth + 1);
46
+ if (hit) return hit;
47
+ } else if (SOURCE_EXTS.has(entry.name.slice(entry.name.lastIndexOf(".")))) {
48
+ scanned += 1;
49
+ try {
50
+ const content = await readFile(join(dir, entry.name), "utf8");
51
+ if (content.includes("@mushi-mushi/") || content.includes("MushiProvider")) {
52
+ return { file: join(dir, entry.name) };
53
+ }
54
+ } catch {
55
+ }
56
+ }
57
+ }
58
+ return null;
59
+ }
60
+ for (const dirName of SOURCE_DIRS) {
61
+ const hit = await walk(join(cwd, dirName), 0);
62
+ if (hit) return hit;
63
+ }
64
+ for (const name of ["main.ts", "main.js", "index.js", "index.ts", "index.html"]) {
65
+ try {
66
+ const content = await readFile(join(cwd, name), "utf8");
67
+ if (content.includes("@mushi-mushi/") || content.includes("MushiProvider") || content.includes("mushi-mushi")) {
68
+ return { file: join(cwd, name) };
69
+ }
70
+ } catch {
71
+ }
72
+ }
73
+ return null;
74
+ }
75
+ export {
76
+ ENTRY_CANDIDATES,
77
+ MUSHI_MARKER_END,
78
+ MUSHI_MARKER_START,
79
+ findSdkImport,
80
+ injectSnippet
81
+ };
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env node
2
+ import {
3
+ MUSHI_CLI_VERSION
4
+ } from "./chunk-TYVJU4AH.js";
5
+ export {
6
+ MUSHI_CLI_VERSION
7
+ };
package/dist/version.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  MUSHI_CLI_VERSION
3
- } from "./chunk-SS42XQ57.js";
3
+ } from "./chunk-MCVRTQAI.js";
4
4
  export {
5
5
  MUSHI_CLI_VERSION
6
6
  };
@@ -0,0 +1,44 @@
1
+ import { FrameworkId } from './detect.js';
2
+
3
+ /**
4
+ * FILE: packages/cli/src/wizard-args.ts
5
+ * PURPOSE: Shared argument parsing, Node-version guard, and help text for the
6
+ * two thin entry-point shims (`mushi-mushi` launcher and
7
+ * `create-mushi-mushi`). Both bins forward the same flags to
8
+ * `runInit`, so the parsing and the flags help live here once. Each
9
+ * shim keeps only its own bin name, header, and usage lines.
10
+ */
11
+
12
+ /** Minimum Node major both shims require. Kept in sync with each package's `engines.node`. */
13
+ declare const MIN_NODE_MAJOR = 20;
14
+ interface ParsedArgs {
15
+ showHelp: boolean;
16
+ showVersion: boolean;
17
+ projectId?: string;
18
+ apiKey?: string;
19
+ framework?: FrameworkId;
20
+ skipInstall?: boolean;
21
+ skipTestReport?: boolean;
22
+ yes?: boolean;
23
+ cwd?: string;
24
+ endpoint?: string;
25
+ }
26
+ /**
27
+ * The flags block shared by both shims' help text. Ends with the Node
28
+ * requirement line and the docs footer. Each shim prepends its own
29
+ * bin-specific header and usage section.
30
+ */
31
+ declare const FLAGS_HELP: string;
32
+ /**
33
+ * Parse the wizard flags. A leading `init` token is tolerated (so
34
+ * `npx mushi-mushi init --yes` works the same as `npx mushi-mushi --yes`).
35
+ */
36
+ declare function parseArgs(argv: readonly string[]): ParsedArgs;
37
+ /**
38
+ * Exit with a friendly message if the running Node is older than
39
+ * {@link MIN_NODE_MAJOR}. `binName` is the invoking command (e.g. `mushi-mushi`
40
+ * or `create-mushi-mushi`) so the error reads naturally.
41
+ */
42
+ declare function assertNodeVersion(binName: string): void;
43
+
44
+ export { FLAGS_HELP, MIN_NODE_MAJOR, type ParsedArgs, assertNodeVersion, parseArgs };
@@ -0,0 +1,95 @@
1
+ import {
2
+ FRAMEWORK_IDS,
3
+ isFrameworkId
4
+ } from "./chunk-AIZRI665.js";
5
+
6
+ // src/wizard-args.ts
7
+ var MIN_NODE_MAJOR = 20;
8
+ var FLAGS_HELP = `Flags (forwarded to the wizard):
9
+ --project-id <uuid> skip the project ID prompt (UUID from the Projects page)
10
+ --api-key <key> skip the API key prompt (CI only \u2014 leaks into \`ps\`)
11
+ --framework <id> force a framework (${FRAMEWORK_IDS.join(", ")})
12
+ --skip-install print the install command instead of running it
13
+ --skip-test-report don't offer to send a test report at the end
14
+ --cwd <path> run in a different directory
15
+ --endpoint <url> override the Mushi API endpoint (self-hosted)
16
+ -y, --yes accept the detected framework without prompting
17
+ -v, --version print the version and exit
18
+ -h, --help show this help
19
+
20
+ Requires Node.js ${MIN_NODE_MAJOR} or newer.
21
+
22
+ Docs: https://github.com/kensaurus/mushi-mushi
23
+ Console: https://kensaur.us/mushi-mushi/`;
24
+ function parseArgs(argv) {
25
+ const args = argv[0] === "init" ? argv.slice(1) : argv;
26
+ const out = { showHelp: false, showVersion: false };
27
+ for (let i = 0; i < args.length; i++) {
28
+ const a = args[i];
29
+ if (a === "-h" || a === "--help") {
30
+ out.showHelp = true;
31
+ continue;
32
+ }
33
+ if (a === "-v" || a === "--version") {
34
+ out.showVersion = true;
35
+ continue;
36
+ }
37
+ if (a === "-y" || a === "--yes") {
38
+ out.yes = true;
39
+ continue;
40
+ }
41
+ if (a === "--skip-install") {
42
+ out.skipInstall = true;
43
+ continue;
44
+ }
45
+ if (a === "--skip-test-report") {
46
+ out.skipTestReport = true;
47
+ continue;
48
+ }
49
+ if (a === "--project-id") {
50
+ out.projectId = args[++i];
51
+ continue;
52
+ }
53
+ if (a === "--api-key") {
54
+ out.apiKey = args[++i];
55
+ continue;
56
+ }
57
+ if (a === "--cwd") {
58
+ out.cwd = args[++i];
59
+ continue;
60
+ }
61
+ if (a === "--endpoint") {
62
+ out.endpoint = args[++i];
63
+ continue;
64
+ }
65
+ if (a === "--framework") {
66
+ const fw = args[++i];
67
+ if (!isFrameworkId(fw)) {
68
+ throw new Error(`Unknown framework: ${fw}. Valid: ${FRAMEWORK_IDS.join(", ")}`);
69
+ }
70
+ out.framework = fw;
71
+ continue;
72
+ }
73
+ if (a.startsWith("-")) {
74
+ throw new Error(`Unknown flag: ${a}. Try --help.`);
75
+ }
76
+ }
77
+ return out;
78
+ }
79
+ function assertNodeVersion(binName) {
80
+ const major = Number(process.versions.node.split(".")[0]);
81
+ if (!Number.isFinite(major) || major < MIN_NODE_MAJOR) {
82
+ process.stderr.write(
83
+ `${binName} requires Node.js ${MIN_NODE_MAJOR} or newer. You are on ${process.versions.node}.
84
+ Upgrade Node (https://nodejs.org/) and try again.
85
+ `
86
+ );
87
+ process.exit(1);
88
+ }
89
+ }
90
+ export {
91
+ FLAGS_HELP,
92
+ MIN_NODE_MAJOR,
93
+ assertNodeVersion,
94
+ parseArgs
95
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mushi-mushi/cli",
3
- "version": "0.25.0",
3
+ "version": "0.26.0",
4
4
  "license": "MIT",
5
5
  "description": "CLI for Mushi Mushi — `mushi init` wizard installs the right SDK for your framework, plus report triage and pipeline health commands",
6
6
  "bin": {
@@ -91,6 +91,12 @@
91
91
  "default": "./dist/detect.js"
92
92
  }
93
93
  },
94
+ "./wizard-args": {
95
+ "import": {
96
+ "types": "./dist/wizard-args.d.ts",
97
+ "default": "./dist/wizard-args.js"
98
+ }
99
+ },
94
100
  "./version": {
95
101
  "import": {
96
102
  "types": "./dist/version.d.ts",
@@ -1,6 +0,0 @@
1
- // src/version.ts
2
- var MUSHI_CLI_VERSION = true ? "0.25.0" : "0.0.0-dev";
3
-
4
- export {
5
- MUSHI_CLI_VERSION
6
- };