@jxsuite/create 0.27.0 → 0.28.2

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.
Files changed (3) hide show
  1. package/generate.ts +46 -8
  2. package/index.ts +8 -1
  3. package/package.json +1 -1
package/generate.ts CHANGED
@@ -12,9 +12,11 @@ export interface ProjectOptions {
12
12
  name: string;
13
13
  description?: string;
14
14
  url?: string;
15
- adapter?: "static" | "cloudflare-pages" | "node" | "bun";
15
+ adapter?: "static" | "cloudflare-pages" | "cloudflare-workers" | "node" | "bun";
16
16
  }
17
17
 
18
+ const CF_ADAPTERS = ["cloudflare-pages", "cloudflare-workers"];
19
+
18
20
  /**
19
21
  * Generate a new Jx project at the given path.
20
22
  *
@@ -39,13 +41,45 @@ export async function generateProject(destPath: string, opts: ProjectOptions) {
39
41
  const projectJson = buildProjectJson({ name, description, url, adapter });
40
42
  const packageJson = buildPackageJson({ name, description, adapter });
41
43
 
42
- await Promise.all([
44
+ const writes = [
43
45
  writeFile(join(destPath, "project.json"), JSON.stringify(projectJson, null, "\t") + "\n"),
44
46
  writeFile(join(destPath, "package.json"), JSON.stringify(packageJson, null, " ") + "\n"),
45
47
  cp(join(TEMPLATE_DIR, "gitignore"), join(destPath, ".gitignore")),
46
48
  cp(join(TEMPLATE_DIR, "layouts"), join(destPath, "layouts"), { recursive: true }),
47
49
  cp(join(TEMPLATE_DIR, "pages"), join(destPath, "pages"), { recursive: true }),
48
- ]);
50
+ ];
51
+
52
+ if (adapter && CF_ADAPTERS.includes(adapter)) {
53
+ const wranglerJsonc = buildWranglerJsonc({ slug: packageJson.name, adapter });
54
+ writes.push(writeFile(join(destPath, "wrangler.jsonc"), wranglerJsonc));
55
+ }
56
+
57
+ await Promise.all(writes);
58
+ }
59
+
60
+ /**
61
+ * Build a wrangler.jsonc for Cloudflare adapters.
62
+ *
63
+ * @param {{ slug: string; adapter: string }} opts
64
+ */
65
+ function buildWranglerJsonc({ slug, adapter }: { slug: string; adapter: string }) {
66
+ const compatibilityDate = new Date().toISOString().slice(0, 10);
67
+
68
+ const config =
69
+ adapter === "cloudflare-workers"
70
+ ? {
71
+ name: slug,
72
+ main: "./dist/worker.js",
73
+ compatibility_date: compatibilityDate,
74
+ assets: { directory: "./dist", binding: "ASSETS" },
75
+ }
76
+ : {
77
+ name: slug,
78
+ compatibility_date: compatibilityDate,
79
+ pages_build_output_dir: "./dist",
80
+ };
81
+
82
+ return JSON.stringify(config, null, "\t") + "\n";
49
83
  }
50
84
 
51
85
  /** @param {ProjectOptions} opts */
@@ -119,8 +153,15 @@ function buildPackageJson({
119
153
  "@jxsuite/runtime": "^0.19.0",
120
154
  };
121
155
 
122
- if (adapter === "cloudflare-pages") {
156
+ const scripts: Record<string, string> = {
157
+ build: "jx build",
158
+ dev: "jx dev",
159
+ };
160
+
161
+ if (adapter && CF_ADAPTERS.includes(adapter)) {
123
162
  devDependencies["wrangler"] = "^4";
163
+ scripts.deploy =
164
+ adapter === "cloudflare-workers" ? "wrangler deploy" : "wrangler pages deploy dist";
124
165
  }
125
166
 
126
167
  return {
@@ -128,10 +169,7 @@ function buildPackageJson({
128
169
  private: true,
129
170
  description: description || "",
130
171
  license: "MIT",
131
- scripts: {
132
- build: "jx build",
133
- dev: "jx dev",
134
- },
172
+ scripts,
135
173
  devDependencies,
136
174
  };
137
175
  }
package/index.ts CHANGED
@@ -31,11 +31,18 @@ Deployment adapter:
31
31
  2) cloudflare-pages
32
32
  3) node
33
33
  4) bun
34
+ 5) cloudflare-workers
34
35
  `);
35
36
  const adapterChoice = await rl.question("Adapter [1]: ");
36
37
  rl.close();
37
38
 
38
- const adapterMap = { 1: "static", 2: "cloudflare-pages", 3: "node", 4: "bun" };
39
+ const adapterMap = {
40
+ 1: "static",
41
+ 2: "cloudflare-pages",
42
+ 3: "node",
43
+ 4: "bun",
44
+ 5: "cloudflare-workers",
45
+ };
39
46
  const adapter = adapterMap[adapterChoice] || "static";
40
47
 
41
48
  await generateProject(destPath, { name, description, url, adapter });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jxsuite/create",
3
- "version": "0.27.0",
3
+ "version": "0.28.2",
4
4
  "description": "Scaffold a new Jx project",
5
5
  "license": "MIT",
6
6
  "repository": {