cmx-sdk 0.1.21 → 0.1.23

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.
@@ -0,0 +1,135 @@
1
+ #!/usr/bin/env node
2
+
3
+ // src/commands/add-studio.ts
4
+ import { existsSync, readFileSync, writeFileSync, mkdirSync } from "fs";
5
+ import { join, resolve } from "path";
6
+ import { execSync } from "child_process";
7
+ import { createWriteStream } from "fs";
8
+ import { pipeline } from "stream/promises";
9
+ import https from "https";
10
+ import { extract } from "tar";
11
+ var REPO_OWNER = "kzkm-lab";
12
+ var REPO_NAME = "cmx-starter-kit";
13
+ var REPO_BRANCH = "main";
14
+ function findProjectRoot() {
15
+ let dir = resolve(process.cwd());
16
+ const root = resolve("/");
17
+ while (dir !== root) {
18
+ const pkgPath = join(dir, "package.json");
19
+ if (existsSync(pkgPath)) {
20
+ try {
21
+ const pkg = JSON.parse(readFileSync(pkgPath, "utf-8"));
22
+ if (pkg.dependencies?.["cmx-sdk"] || pkg.devDependencies?.["cmx-sdk"]) {
23
+ return dir;
24
+ }
25
+ } catch {
26
+ }
27
+ }
28
+ dir = resolve(dir, "..");
29
+ }
30
+ return null;
31
+ }
32
+ async function downloadStudio(targetDir) {
33
+ const tarballUrl = `https://api.github.com/repos/${REPO_OWNER}/${REPO_NAME}/tarball/${REPO_BRANCH}`;
34
+ const tmpFile = join(targetDir, ".tmp-studio-tarball.tar.gz");
35
+ await new Promise((resolve2, reject) => {
36
+ const download = (url) => {
37
+ https.get(url, {
38
+ headers: { "User-Agent": "cmx-sdk", Accept: "application/vnd.github+json" }
39
+ }, (res) => {
40
+ if (res.statusCode === 301 || res.statusCode === 302) {
41
+ const redirectUrl = res.headers.location;
42
+ if (redirectUrl) {
43
+ download(redirectUrl);
44
+ return;
45
+ }
46
+ }
47
+ if (res.statusCode !== 200) {
48
+ reject(new Error(`\u30C0\u30A6\u30F3\u30ED\u30FC\u30C9\u306B\u5931\u6557\u3057\u307E\u3057\u305F (HTTP ${res.statusCode})`));
49
+ return;
50
+ }
51
+ const fileStream = createWriteStream(tmpFile);
52
+ pipeline(res, fileStream).then(resolve2).catch(reject);
53
+ }).on("error", reject);
54
+ };
55
+ download(tarballUrl);
56
+ });
57
+ const studioDir = join(targetDir, ".cmx", "studio");
58
+ mkdirSync(studioDir, { recursive: true });
59
+ await extract({
60
+ file: tmpFile,
61
+ cwd: studioDir,
62
+ strip: 2,
63
+ // {owner}-{repo}-{hash}/.cmx/studio/ → 2階層スキップ
64
+ filter: (path) => {
65
+ const parts = path.split("/");
66
+ return parts.length >= 3 && parts[1] === ".cmx" && parts[2] === "studio";
67
+ }
68
+ });
69
+ try {
70
+ const { rmSync } = await import("fs");
71
+ rmSync(tmpFile);
72
+ } catch {
73
+ }
74
+ }
75
+ async function addStudio() {
76
+ console.log("\n CMX Studio \u3092\u8FFD\u52A0\u4E2D...\n");
77
+ const projectRoot = findProjectRoot();
78
+ if (!projectRoot) {
79
+ console.error(" \u274C CMX \u30D7\u30ED\u30B8\u30A7\u30AF\u30C8\u304C\u898B\u3064\u304B\u308A\u307E\u305B\u3093");
80
+ 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");
81
+ process.exit(1);
82
+ }
83
+ const studioDir = join(projectRoot, ".cmx", "studio");
84
+ if (existsSync(studioDir)) {
85
+ console.error(" \u274C .cmx/studio/ \u306F\u65E2\u306B\u5B58\u5728\u3057\u307E\u3059");
86
+ console.error(" \u518D\u30A4\u30F3\u30B9\u30C8\u30FC\u30EB\u3059\u308B\u5834\u5408\u306F\u5148\u306B\u524A\u9664\u3057\u3066\u304F\u3060\u3055\u3044\n");
87
+ process.exit(1);
88
+ }
89
+ console.log(" \u23F3 Studio \u3092\u30C0\u30A6\u30F3\u30ED\u30FC\u30C9\u4E2D...");
90
+ try {
91
+ await downloadStudio(projectRoot);
92
+ console.log(" \u2713 Studio \u3092\u30C0\u30A6\u30F3\u30ED\u30FC\u30C9\u3057\u307E\u3057\u305F");
93
+ } catch (error) {
94
+ console.error("\n \u274C Studio \u306E\u30C0\u30A6\u30F3\u30ED\u30FC\u30C9\u306B\u5931\u6557\u3057\u307E\u3057\u305F");
95
+ console.error(` ${error instanceof Error ? error.message : "\u4E0D\u660E\u306A\u30A8\u30E9\u30FC"}
96
+ `);
97
+ process.exit(1);
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
+ console.log("\n \u{1F4E6} Studio \u306E\u4F9D\u5B58\u30D1\u30C3\u30B1\u30FC\u30B8\u3092\u30A4\u30F3\u30B9\u30C8\u30FC\u30EB\u4E2D...");
116
+ try {
117
+ const pm = existsSync(join(projectRoot, "pnpm-lock.yaml")) ? "pnpm" : existsSync(join(projectRoot, "yarn.lock")) ? "yarn" : "npm";
118
+ const installCmd = pm === "yarn" ? "yarn" : `${pm} install`;
119
+ execSync(installCmd, { cwd: studioDir, stdio: "inherit" });
120
+ } catch {
121
+ console.error("\n \u26A0\uFE0F \u4F9D\u5B58\u30D1\u30C3\u30B1\u30FC\u30B8\u306E\u30A4\u30F3\u30B9\u30C8\u30FC\u30EB\u306B\u5931\u6557\u3057\u307E\u3057\u305F");
122
+ console.error(" cd .cmx/studio && npm install \u3067\u624B\u52D5\u30A4\u30F3\u30B9\u30C8\u30FC\u30EB\u3057\u3066\u304F\u3060\u3055\u3044\n");
123
+ }
124
+ console.log(`
125
+ \u2705 CMX Studio \u3092\u8FFD\u52A0\u3057\u307E\u3057\u305F\uFF01
126
+
127
+ \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
130
+ `);
131
+ process.exit(0);
132
+ }
133
+ export {
134
+ addStudio
135
+ };
package/dist/cli.js CHANGED
@@ -1658,16 +1658,16 @@ config();
1658
1658
  var program = new Command();
1659
1659
  program.name("cmx-sdk").description("CMX SDK - CLI tool for managing CMX schemas and content").version("0.1.13");
1660
1660
  program.action(async () => {
1661
- const { interactiveMenu } = await import("./interactive-menu-HMKKC57H.js");
1661
+ const { interactiveMenu } = await import("./interactive-menu-3Q4Q3ZLW.js");
1662
1662
  await interactiveMenu();
1663
1663
  });
1664
1664
  program.command("init [project-name]").description("\u65B0\u898F CMX \u30B5\u30A4\u30C8\u3092\u4F5C\u6210").option("--no-studio", "CMX Studio \u3092\u30B9\u30AD\u30C3\u30D7").option("--pm <manager>", "\u30D1\u30C3\u30B1\u30FC\u30B8\u30DE\u30CD\u30FC\u30B8\u30E3\u30FC (npm, pnpm, yarn)").action(async (projectName, options) => {
1665
- const { init } = await import("./init-37BFTU52.js");
1665
+ const { init } = await import("./init-EIMBQB3E.js");
1666
1666
  await init(projectName, options);
1667
1667
  });
1668
- program.command("studio").description("\u30B5\u30A4\u30C8 + CMX Studio \u3092\u8D77\u52D5").option("--only", "Studio \u306E\u307F\u8D77\u52D5\uFF08\u30B5\u30A4\u30C8\u306F\u8D77\u52D5\u3057\u306A\u3044\uFF09").action(async (options) => {
1669
- const { studio } = await import("./studio-76GY2A5B.js");
1670
- await studio(options);
1668
+ program.command("add-studio").description("\u65E2\u5B58\u30D7\u30ED\u30B8\u30A7\u30AF\u30C8\u306B CMX Studio \u3092\u8FFD\u52A0").action(async () => {
1669
+ const { addStudio } = await import("./add-studio-C2L2NYQC.js");
1670
+ await addStudio();
1671
1671
  });
1672
1672
  program.command("list-collections").description("List all collections").action(listCollections);
1673
1673
  program.command("list-data-types").description("List all data types").action(listDataTypes);
@@ -158,11 +158,12 @@ async function init(projectName, options) {
158
158
  \u6B21\u306E\u30B9\u30C6\u30C3\u30D7:
159
159
  cd ${name}
160
160
  ${runCmd} dev # \u30B5\u30A4\u30C8\u3092\u8D77\u52D5 (localhost:4000)${includeStudio ? `
161
- npx cmx-sdk studio # Studio \u3092\u8D77\u52D5 (localhost:4001)` : ""}
161
+ ${runCmd} studio # \u30B5\u30A4\u30C8 + Studio \u3092\u8D77\u52D5` : ""}
162
162
 
163
163
  \u{1F4D6} \u30C9\u30AD\u30E5\u30E1\u30F3\u30C8: https://cmx-ai.org/docs
164
164
  \u{1F3A8} CMX Admin: https://app.cmx-ai.org
165
165
  `);
166
+ process.exit(0);
166
167
  }
167
168
  export {
168
169
  init
@@ -8,7 +8,7 @@ async function interactiveMenu() {
8
8
  message: "\u4F55\u3092\u3057\u307E\u3059\u304B?",
9
9
  choices: [
10
10
  { name: "\u65B0\u898F\u30B5\u30A4\u30C8\u3092\u4F5C\u6210", value: "init" },
11
- { name: "Studio \u3092\u8D77\u52D5", value: "studio" },
11
+ { name: "Studio \u3092\u8FFD\u52A0", value: "add-studio" },
12
12
  { name: "\u578B\u3092\u751F\u6210", value: "generate" },
13
13
  { name: "\u30DA\u30FC\u30B8\u3092\u751F\u6210", value: "scaffold" },
14
14
  { name: "\u30D8\u30EB\u30D7", value: "help" }
@@ -16,31 +16,38 @@ async function interactiveMenu() {
16
16
  });
17
17
  switch (action) {
18
18
  case "init": {
19
- const { init } = await import("./init-37BFTU52.js");
19
+ const { init } = await import("./init-EIMBQB3E.js");
20
20
  return init(void 0, {});
21
21
  }
22
- case "studio": {
23
- const { studio } = await import("./studio-76GY2A5B.js");
24
- return studio();
22
+ case "add-studio": {
23
+ const { addStudio } = await import("./add-studio-C2L2NYQC.js");
24
+ return addStudio();
25
25
  }
26
26
  case "generate": {
27
27
  console.log("\n npx cmx-sdk generate \u3092\u5B9F\u884C\u3057\u3066\u304F\u3060\u3055\u3044\n");
28
+ process.exit(0);
28
29
  break;
29
30
  }
30
31
  case "scaffold": {
31
32
  console.log("\n npx cmx-sdk scaffold \u3092\u5B9F\u884C\u3057\u3066\u304F\u3060\u3055\u3044\n");
33
+ process.exit(0);
32
34
  break;
33
35
  }
34
36
  case "help": {
35
37
  console.log(`
36
38
  \u4F7F\u3044\u65B9:
37
39
  npx cmx-sdk init [project-name] \u65B0\u898F\u30B5\u30A4\u30C8\u3092\u4F5C\u6210
38
- npx cmx-sdk studio \u30B5\u30A4\u30C8 + Studio \u3092\u8D77\u52D5
39
- npx cmx-sdk studio --only Studio \u306E\u307F\u8D77\u52D5
40
+ npx cmx-sdk add-studio Studio \u3092\u8FFD\u52A0
40
41
  npx cmx-sdk generate TypeScript \u578B\u3092\u751F\u6210
41
42
  npx cmx-sdk scaffold Next.js \u30DA\u30FC\u30B8\u3092\u751F\u6210
42
43
  npx cmx-sdk --help \u5168\u30B3\u30DE\u30F3\u30C9\u3092\u8868\u793A
44
+
45
+ \u8D77\u52D5:
46
+ npm run dev \u30B5\u30A4\u30C8\u3092\u8D77\u52D5 (localhost:4000)
47
+ npm run studio \u30B5\u30A4\u30C8 + Studio \u3092\u8D77\u52D5
48
+ npm run studio:only Studio \u306E\u307F\u8D77\u52D5
43
49
  `);
50
+ process.exit(0);
44
51
  break;
45
52
  }
46
53
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cmx-sdk",
3
- "version": "0.1.21",
3
+ "version": "0.1.23",
4
4
  "description": "CMX SDK - Official SDK for building content-driven websites with CMX",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -1,132 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- // src/commands/studio.ts
4
- import { existsSync, readFileSync } from "fs";
5
- import { join, resolve } from "path";
6
- import { execSync, spawn } from "child_process";
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 ensureInstalled(dir, label) {
31
- const nodeModules = join(dir, "node_modules");
32
- if (!existsSync(nodeModules)) {
33
- console.log(` \u{1F4E6} ${label}\u306E\u4F9D\u5B58\u30D1\u30C3\u30B1\u30FC\u30B8\u3092\u30A4\u30F3\u30B9\u30C8\u30FC\u30EB\u4E2D...`);
34
- const pm = detectPackageManager(dir);
35
- const installCmd = pm === "yarn" ? "yarn" : `${pm} install`;
36
- try {
37
- execSync(installCmd, { cwd: dir, stdio: "inherit" });
38
- } catch {
39
- console.error(`
40
- \u274C ${label}\u306E\u4F9D\u5B58\u30D1\u30C3\u30B1\u30FC\u30B8\u306E\u30A4\u30F3\u30B9\u30C8\u30FC\u30EB\u306B\u5931\u6557\u3057\u307E\u3057\u305F
41
- `);
42
- process.exit(1);
43
- }
44
- console.log("");
45
- }
46
- }
47
- async function studio(options = {}) {
48
- console.log("\n CMX Studio \u3092\u8D77\u52D5\u4E2D...\n");
49
- const projectRoot = findProjectRoot();
50
- if (!projectRoot) {
51
- console.error(" \u274C CMX \u30D7\u30ED\u30B8\u30A7\u30AF\u30C8\u304C\u898B\u3064\u304B\u308A\u307E\u305B\u3093");
52
- 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");
53
- process.exit(1);
54
- }
55
- const studioDir = join(projectRoot, ".cmx", "studio");
56
- if (!existsSync(studioDir)) {
57
- console.error(" \u274C .cmx/studio/ \u304C\u898B\u3064\u304B\u308A\u307E\u305B\u3093");
58
- console.error(" CMX Starter Kit \u306E Studio \u4ED8\u304D\u30D0\u30FC\u30B8\u30E7\u30F3\u3092\u4F7F\u7528\u3057\u3066\u304F\u3060\u3055\u3044\n");
59
- process.exit(1);
60
- }
61
- const children = [];
62
- if (!options.only) {
63
- ensureInstalled(projectRoot, "\u30B5\u30A4\u30C8");
64
- console.log(" \u{1F310} http://localhost:4000 \u3067\u30B5\u30A4\u30C8\u3092\u8D77\u52D5\u3057\u307E\u3059");
65
- const sitePm = detectPackageManager(projectRoot);
66
- const siteChild = spawn(sitePm, ["run", "dev"], {
67
- cwd: projectRoot,
68
- stdio: "pipe",
69
- shell: true
70
- });
71
- children.push(siteChild);
72
- siteChild.stdout?.on("data", (data) => {
73
- const lines = data.toString().split("\n").filter(Boolean);
74
- for (const line of lines) {
75
- console.log(` [site] ${line}`);
76
- }
77
- });
78
- siteChild.stderr?.on("data", (data) => {
79
- const lines = data.toString().split("\n").filter(Boolean);
80
- for (const line of lines) {
81
- console.error(` [site] ${line}`);
82
- }
83
- });
84
- }
85
- ensureInstalled(studioDir, "Studio");
86
- console.log(" \u{1F680} http://localhost:4001 \u3067 Studio \u3092\u8D77\u52D5\u3057\u307E\u3059\n");
87
- const studioPm = detectPackageManager(studioDir);
88
- const studioChild = spawn(studioPm, ["run", "dev"], {
89
- cwd: studioDir,
90
- stdio: options.only ? "inherit" : "pipe",
91
- shell: true
92
- });
93
- children.push(studioChild);
94
- if (!options.only) {
95
- studioChild.stdout?.on("data", (data) => {
96
- const lines = data.toString().split("\n").filter(Boolean);
97
- for (const line of lines) {
98
- console.log(` [studio] ${line}`);
99
- }
100
- });
101
- studioChild.stderr?.on("data", (data) => {
102
- const lines = data.toString().split("\n").filter(Boolean);
103
- for (const line of lines) {
104
- console.error(` [studio] ${line}`);
105
- }
106
- });
107
- }
108
- setTimeout(() => {
109
- try {
110
- const openCmd = process.platform === "darwin" ? "open" : process.platform === "win32" ? "start" : "xdg-open";
111
- execSync(`${openCmd} http://localhost:4001`, { stdio: "ignore" });
112
- } catch {
113
- }
114
- }, 3e3);
115
- process.on("SIGINT", () => {
116
- for (const child of children) {
117
- child.kill();
118
- }
119
- process.exit(0);
120
- });
121
- for (const child of children) {
122
- child.on("exit", (code) => {
123
- for (const c of children) {
124
- if (c !== child) c.kill();
125
- }
126
- process.exit(code ?? 0);
127
- });
128
- }
129
- }
130
- export {
131
- studio
132
- };