cmx-sdk 0.2.1 → 0.2.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/README.md CHANGED
@@ -201,7 +201,7 @@ Generate typed functions and interfaces from your CMX data types and collections
201
201
  ### Usage
202
202
 
203
203
  ```bash
204
- npx cmx-sdk generate
204
+ npx cmx-sdk codegen types
205
205
  ```
206
206
 
207
207
  This fetches your workspace's schema from the CMX API and generates TypeScript files in `cmx/generated/`.
@@ -209,7 +209,18 @@ This fetches your workspace's schema from the CMX API and generates TypeScript f
209
209
  ### Options
210
210
 
211
211
  ```bash
212
- npx cmx-sdk generate --output src/cmx/generated # Custom output directory
212
+ npx cmx-sdk codegen types --output src/cmx/generated
213
+ npx cmx-sdk codegen pages --template layered --app-dir src/app --features-dir src/features
214
+ npx cmx-sdk codegen check
215
+ npx cmx-sdk codegen all
216
+ ```
217
+
218
+ ### MDX Tooling
219
+
220
+ ```bash
221
+ npx cmx-sdk mdx validate --dir src
222
+ npx cmx-sdk mdx validate --file src/content/post.mdx
223
+ npx cmx-sdk mdx doctor
213
224
  ```
214
225
 
215
226
  ### Requirements
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  // src/commands/add-studio.ts
4
- import { existsSync, readFileSync, writeFileSync, mkdirSync } from "fs";
4
+ import { existsSync, readFileSync, mkdirSync } from "fs";
5
5
  import { join, resolve } from "path";
6
6
  import { execSync } from "child_process";
7
7
  import { createWriteStream } from "fs";
@@ -96,22 +96,6 @@ async function addStudio() {
96
96
  `);
97
97
  process.exit(1);
98
98
  }
99
- const pkgJsonPath = join(projectRoot, "package.json");
100
- try {
101
- const pkg = JSON.parse(readFileSync(pkgJsonPath, "utf-8"));
102
- if (!pkg.scripts) pkg.scripts = {};
103
- if (!pkg.scripts.studio) {
104
- pkg.scripts.studio = "next dev --turbopack --port 4000 & npm --prefix .cmx/studio run dev";
105
- }
106
- if (!pkg.scripts["studio:only"]) {
107
- pkg.scripts["studio:only"] = "npm --prefix .cmx/studio run dev";
108
- }
109
- writeFileSync(pkgJsonPath, JSON.stringify(pkg, null, 2) + "\n", "utf-8");
110
- console.log(" \u2713 package.json \u306B studio \u30B9\u30AF\u30EA\u30D7\u30C8\u3092\u8FFD\u52A0\u3057\u307E\u3057\u305F");
111
- } catch {
112
- console.error(" \u26A0\uFE0F package.json \u306E\u66F4\u65B0\u306B\u5931\u6557\u3057\u307E\u3057\u305F");
113
- console.error(" \u624B\u52D5\u3067 studio \u30B9\u30AF\u30EA\u30D7\u30C8\u3092\u8FFD\u52A0\u3057\u3066\u304F\u3060\u3055\u3044\n");
114
- }
115
99
  console.log("\n \u{1F4E6} Studio \u306E\u4F9D\u5B58\u30D1\u30C3\u30B1\u30FC\u30B8\u3092\u30A4\u30F3\u30B9\u30C8\u30FC\u30EB\u4E2D...");
116
100
  try {
117
101
  const pm = existsSync(join(projectRoot, "pnpm-lock.yaml")) ? "pnpm" : existsSync(join(projectRoot, "yarn.lock")) ? "yarn" : "npm";
@@ -125,8 +109,8 @@ async function addStudio() {
125
109
  \u2705 CMX Studio \u3092\u8FFD\u52A0\u3057\u307E\u3057\u305F\uFF01
126
110
 
127
111
  \u8D77\u52D5\u65B9\u6CD5:
128
- npm run studio # \u30B5\u30A4\u30C8 + Studio \u3092\u8D77\u52D5
129
- npm run studio:only # Studio \u306E\u307F\u8D77\u52D5
112
+ npx cmx-sdk studio # \u30B5\u30A4\u30C8 + Studio \u3092\u8D77\u52D5
113
+ npm --prefix .cmx/studio run dev # Studio \u306E\u307F\u8D77\u52D5
130
114
  `);
131
115
  process.exit(0);
132
116
  }
@@ -0,0 +1,109 @@
1
+ #!/usr/bin/env node
2
+
3
+ // src/commands/studio.ts
4
+ import { existsSync, readFileSync } from "fs";
5
+ import { spawn } from "child_process";
6
+ import { join, resolve } from "path";
7
+ function findProjectRoot() {
8
+ let dir = resolve(process.cwd());
9
+ const root = resolve("/");
10
+ while (dir !== root) {
11
+ const pkgPath = join(dir, "package.json");
12
+ if (existsSync(pkgPath)) {
13
+ try {
14
+ const pkg = JSON.parse(readFileSync(pkgPath, "utf-8"));
15
+ if (pkg.dependencies?.["cmx-sdk"] || pkg.devDependencies?.["cmx-sdk"]) {
16
+ return dir;
17
+ }
18
+ } catch {
19
+ }
20
+ }
21
+ dir = resolve(dir, "..");
22
+ }
23
+ return null;
24
+ }
25
+ function detectPackageManager(dir) {
26
+ if (existsSync(join(dir, "pnpm-lock.yaml"))) return "pnpm";
27
+ if (existsSync(join(dir, "yarn.lock"))) return "yarn";
28
+ return "npm";
29
+ }
30
+ function getRunCommand(pm) {
31
+ if (pm === "pnpm") return { command: "pnpm", args: ["dev"] };
32
+ if (pm === "yarn") return { command: "yarn", args: ["dev"] };
33
+ return { command: "npm", args: ["run", "dev"] };
34
+ }
35
+ function toPlatformCommand(command) {
36
+ if (process.platform === "win32") {
37
+ if (command === "npm") return "npm.cmd";
38
+ if (command === "pnpm") return "pnpm.cmd";
39
+ if (command === "yarn") return "yarn.cmd";
40
+ }
41
+ return command;
42
+ }
43
+ async function studio() {
44
+ console.log("\n CMX Studio \u8D77\u52D5\u4E2D...\n");
45
+ const projectRoot = findProjectRoot();
46
+ if (!projectRoot) {
47
+ console.error(" \u274C CMX \u30D7\u30ED\u30B8\u30A7\u30AF\u30C8\u304C\u898B\u3064\u304B\u308A\u307E\u305B\u3093");
48
+ console.error(" package.json \u306B cmx-sdk \u4F9D\u5B58\u304C\u3042\u308B\u30C7\u30A3\u30EC\u30AF\u30C8\u30EA\u3067\u5B9F\u884C\u3057\u3066\u304F\u3060\u3055\u3044\n");
49
+ process.exit(1);
50
+ }
51
+ const studioDir = join(projectRoot, ".cmx", "studio");
52
+ if (!existsSync(join(studioDir, "package.json"))) {
53
+ console.error(" \u274C .cmx/studio \u304C\u898B\u3064\u304B\u308A\u307E\u305B\u3093");
54
+ console.error(" \u5148\u306B npx cmx-sdk add-studio \u3092\u5B9F\u884C\u3057\u3066\u304F\u3060\u3055\u3044\n");
55
+ process.exit(1);
56
+ }
57
+ const rootPm = detectPackageManager(projectRoot);
58
+ const studioPm = detectPackageManager(studioDir);
59
+ const rootRun = getRunCommand(rootPm);
60
+ const studioRun = getRunCommand(studioPm);
61
+ const children = [];
62
+ let shuttingDown = false;
63
+ const shutdown = (exitCode) => {
64
+ if (shuttingDown) return;
65
+ shuttingDown = true;
66
+ for (const child of children) {
67
+ if (!child.killed) child.kill("SIGTERM");
68
+ }
69
+ setTimeout(() => {
70
+ for (const child of children) {
71
+ if (!child.killed) child.kill("SIGKILL");
72
+ }
73
+ process.exit(exitCode);
74
+ }, 300).unref();
75
+ };
76
+ const spawnDev = (label, cwd, run) => {
77
+ const command = toPlatformCommand(run.command);
78
+ const child = spawn(command, run.args, {
79
+ cwd,
80
+ stdio: "inherit",
81
+ env: process.env
82
+ });
83
+ child.on("error", (error) => {
84
+ console.error(`
85
+ \u274C ${label} \u306E\u8D77\u52D5\u306B\u5931\u6557\u3057\u307E\u3057\u305F: ${error.message}
86
+ `);
87
+ shutdown(1);
88
+ });
89
+ child.on("exit", (code, signal) => {
90
+ if (shuttingDown) return;
91
+ const detail = signal ? `signal ${signal}` : `code ${code ?? 1}`;
92
+ console.error(`
93
+ \u26A0\uFE0F ${label} \u30D7\u30ED\u30BB\u30B9\u304C\u7D42\u4E86\u3057\u307E\u3057\u305F (${detail})
94
+ `);
95
+ shutdown(code ?? 1);
96
+ });
97
+ children.push(child);
98
+ };
99
+ console.log(" - site : http://localhost:4000");
100
+ console.log(" - studio : http://localhost:4001\n");
101
+ spawnDev("site", projectRoot, rootRun);
102
+ spawnDev("studio", studioDir, studioRun);
103
+ process.on("SIGINT", () => shutdown(0));
104
+ process.on("SIGTERM", () => shutdown(0));
105
+ }
106
+
107
+ export {
108
+ studio
109
+ };