@jxsuite/create 0.27.0 → 0.28.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/generate.ts +49 -8
- package/index.ts +8 -1
- 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,48 @@ 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
|
-
|
|
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. Includes the Images binding so `images.service:
|
|
62
|
+
* "cloudflare"` works out of the box.
|
|
63
|
+
*
|
|
64
|
+
* @param {{ slug: string; adapter: string }} opts
|
|
65
|
+
*/
|
|
66
|
+
function buildWranglerJsonc({ slug, adapter }: { slug: string; adapter: string }) {
|
|
67
|
+
const compatibilityDate = new Date().toISOString().slice(0, 10);
|
|
68
|
+
|
|
69
|
+
const config =
|
|
70
|
+
adapter === "cloudflare-workers"
|
|
71
|
+
? {
|
|
72
|
+
name: slug,
|
|
73
|
+
main: "./dist/worker.js",
|
|
74
|
+
compatibility_date: compatibilityDate,
|
|
75
|
+
assets: { directory: "./dist", binding: "ASSETS" },
|
|
76
|
+
images: { binding: "IMAGES" },
|
|
77
|
+
}
|
|
78
|
+
: {
|
|
79
|
+
name: slug,
|
|
80
|
+
compatibility_date: compatibilityDate,
|
|
81
|
+
pages_build_output_dir: "./dist",
|
|
82
|
+
images: { binding: "IMAGES" },
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
return JSON.stringify(config, null, "\t") + "\n";
|
|
49
86
|
}
|
|
50
87
|
|
|
51
88
|
/** @param {ProjectOptions} opts */
|
|
@@ -119,8 +156,15 @@ function buildPackageJson({
|
|
|
119
156
|
"@jxsuite/runtime": "^0.19.0",
|
|
120
157
|
};
|
|
121
158
|
|
|
122
|
-
|
|
159
|
+
const scripts: Record<string, string> = {
|
|
160
|
+
build: "jx build",
|
|
161
|
+
dev: "jx dev",
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
if (adapter && CF_ADAPTERS.includes(adapter)) {
|
|
123
165
|
devDependencies["wrangler"] = "^4";
|
|
166
|
+
scripts.deploy =
|
|
167
|
+
adapter === "cloudflare-workers" ? "wrangler deploy" : "wrangler pages deploy dist";
|
|
124
168
|
}
|
|
125
169
|
|
|
126
170
|
return {
|
|
@@ -128,10 +172,7 @@ function buildPackageJson({
|
|
|
128
172
|
private: true,
|
|
129
173
|
description: description || "",
|
|
130
174
|
license: "MIT",
|
|
131
|
-
scripts
|
|
132
|
-
build: "jx build",
|
|
133
|
-
dev: "jx dev",
|
|
134
|
-
},
|
|
175
|
+
scripts,
|
|
135
176
|
devDependencies,
|
|
136
177
|
};
|
|
137
178
|
}
|
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 = {
|
|
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 });
|