@jxsuite/create 0.28.2 → 0.28.4
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 +45 -35
- package/index.ts +3 -3
- package/package.json +1 -1
package/generate.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/** Shared project generation logic. Used by both the CLI scaffolder and the Studio server endpoint. */
|
|
2
2
|
|
|
3
|
-
import { mkdir, writeFile
|
|
4
|
-
import { join
|
|
5
|
-
|
|
3
|
+
import { cp, mkdir, writeFile } from "node:fs/promises";
|
|
4
|
+
import { join } from "node:path";
|
|
5
|
+
|
|
6
6
|
import { existsSync } from "node:fs";
|
|
7
7
|
|
|
8
|
-
const __dirname =
|
|
8
|
+
const __dirname = import.meta.dirname;
|
|
9
9
|
const TEMPLATE_DIR = join(__dirname, "template");
|
|
10
10
|
|
|
11
11
|
export interface ProjectOptions {
|
|
@@ -15,7 +15,7 @@ export interface ProjectOptions {
|
|
|
15
15
|
adapter?: "static" | "cloudflare-pages" | "cloudflare-workers" | "node" | "bun";
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
const CF_ADAPTERS = ["cloudflare-pages", "cloudflare-workers"];
|
|
18
|
+
const CF_ADAPTERS = new Set(["cloudflare-pages", "cloudflare-workers"]);
|
|
19
19
|
|
|
20
20
|
/**
|
|
21
21
|
* Generate a new Jx project at the given path.
|
|
@@ -38,19 +38,19 @@ export async function generateProject(destPath: string, opts: ProjectOptions) {
|
|
|
38
38
|
await mkdir(join(destPath, "public"), { recursive: true });
|
|
39
39
|
await mkdir(join(destPath, "content"), { recursive: true });
|
|
40
40
|
|
|
41
|
-
const projectJson = buildProjectJson({
|
|
42
|
-
const packageJson = buildPackageJson({
|
|
41
|
+
const projectJson = buildProjectJson({ adapter, description, name, url });
|
|
42
|
+
const packageJson = buildPackageJson({ adapter, description, name });
|
|
43
43
|
|
|
44
44
|
const writes = [
|
|
45
|
-
writeFile(join(destPath, "project.json"), JSON.stringify(projectJson, null, "\t")
|
|
46
|
-
writeFile(join(destPath, "package.json"), JSON.stringify(packageJson, null, " ")
|
|
45
|
+
writeFile(join(destPath, "project.json"), `${JSON.stringify(projectJson, null, "\t")}\n`),
|
|
46
|
+
writeFile(join(destPath, "package.json"), `${JSON.stringify(packageJson, null, " ")}\n`),
|
|
47
47
|
cp(join(TEMPLATE_DIR, "gitignore"), join(destPath, ".gitignore")),
|
|
48
48
|
cp(join(TEMPLATE_DIR, "layouts"), join(destPath, "layouts"), { recursive: true }),
|
|
49
49
|
cp(join(TEMPLATE_DIR, "pages"), join(destPath, "pages"), { recursive: true }),
|
|
50
50
|
];
|
|
51
51
|
|
|
52
|
-
if (adapter && CF_ADAPTERS.
|
|
53
|
-
const wranglerJsonc = buildWranglerJsonc({ slug: packageJson.name
|
|
52
|
+
if (adapter && CF_ADAPTERS.has(adapter)) {
|
|
53
|
+
const wranglerJsonc = buildWranglerJsonc({ adapter, slug: packageJson.name });
|
|
54
54
|
writes.push(writeFile(join(destPath, "wrangler.jsonc"), wranglerJsonc));
|
|
55
55
|
}
|
|
56
56
|
|
|
@@ -65,42 +65,45 @@ export async function generateProject(destPath: string, opts: ProjectOptions) {
|
|
|
65
65
|
function buildWranglerJsonc({ slug, adapter }: { slug: string; adapter: string }) {
|
|
66
66
|
const compatibilityDate = new Date().toISOString().slice(0, 10);
|
|
67
67
|
|
|
68
|
+
// Nodejs_compat: server functions routinely pull in Node-flavored npm packages
|
|
68
69
|
const config =
|
|
69
70
|
adapter === "cloudflare-workers"
|
|
70
71
|
? {
|
|
71
|
-
|
|
72
|
-
main: "./dist/worker.js",
|
|
72
|
+
assets: { binding: "ASSETS", directory: "./dist" },
|
|
73
73
|
compatibility_date: compatibilityDate,
|
|
74
|
-
|
|
74
|
+
compatibility_flags: ["nodejs_compat"],
|
|
75
|
+
main: "./dist/worker.js",
|
|
76
|
+
name: slug,
|
|
75
77
|
}
|
|
76
78
|
: {
|
|
77
|
-
name: slug,
|
|
78
79
|
compatibility_date: compatibilityDate,
|
|
80
|
+
compatibility_flags: ["nodejs_compat"],
|
|
81
|
+
name: slug,
|
|
79
82
|
pages_build_output_dir: "./dist",
|
|
80
83
|
};
|
|
81
84
|
|
|
82
|
-
return JSON.stringify(config, null, "\t")
|
|
85
|
+
return `${JSON.stringify(config, null, "\t")}\n`;
|
|
83
86
|
}
|
|
84
87
|
|
|
85
88
|
/** @param {ProjectOptions} opts */
|
|
86
89
|
function buildProjectJson({ name, description, url, adapter }: ProjectOptions) {
|
|
87
90
|
const $head = [
|
|
88
91
|
{
|
|
92
|
+
attributes: { content: "width=device-width, initial-scale=1", name: "viewport" },
|
|
89
93
|
tagName: "meta",
|
|
90
|
-
attributes: { name: "viewport", content: "width=device-width, initial-scale=1" },
|
|
91
94
|
},
|
|
92
95
|
];
|
|
93
96
|
|
|
94
97
|
if (description) {
|
|
95
98
|
$head.push({
|
|
99
|
+
attributes: { content: description, name: "description" },
|
|
96
100
|
tagName: "meta",
|
|
97
|
-
attributes: { name: "description", content: description },
|
|
98
101
|
});
|
|
99
102
|
}
|
|
100
103
|
|
|
101
104
|
const build: { outDir: string; format: string; trailingSlash: string; adapter?: string } = {
|
|
102
|
-
outDir: "./dist",
|
|
103
105
|
format: "directory",
|
|
106
|
+
outDir: "./dist",
|
|
104
107
|
trailingSlash: "always",
|
|
105
108
|
};
|
|
106
109
|
|
|
@@ -109,12 +112,6 @@ function buildProjectJson({ name, description, url, adapter }: ProjectOptions) {
|
|
|
109
112
|
}
|
|
110
113
|
|
|
111
114
|
return {
|
|
112
|
-
name,
|
|
113
|
-
url: url || "https://example.com",
|
|
114
|
-
defaults: {
|
|
115
|
-
layout: "./layouts/base.json",
|
|
116
|
-
lang: "en",
|
|
117
|
-
},
|
|
118
115
|
$head,
|
|
119
116
|
$media: {
|
|
120
117
|
"--": "1280px",
|
|
@@ -122,14 +119,20 @@ function buildProjectJson({ name, description, url, adapter }: ProjectOptions) {
|
|
|
122
119
|
"--md": "(max-width: 768px)",
|
|
123
120
|
"--sm": "(max-width: 640px)",
|
|
124
121
|
},
|
|
122
|
+
build,
|
|
123
|
+
defaults: {
|
|
124
|
+
lang: "en",
|
|
125
|
+
layout: "./layouts/base.json",
|
|
126
|
+
},
|
|
127
|
+
name,
|
|
125
128
|
style: {
|
|
126
|
-
|
|
127
|
-
padding: "0",
|
|
129
|
+
color: "#1a1a1a",
|
|
128
130
|
fontFamily: "system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif",
|
|
129
131
|
lineHeight: "1.6",
|
|
130
|
-
|
|
132
|
+
margin: "0",
|
|
133
|
+
padding: "0",
|
|
131
134
|
},
|
|
132
|
-
|
|
135
|
+
url: url || "https://example.com",
|
|
133
136
|
};
|
|
134
137
|
}
|
|
135
138
|
|
|
@@ -145,9 +148,10 @@ function buildPackageJson({
|
|
|
145
148
|
}) {
|
|
146
149
|
const slug = name
|
|
147
150
|
.toLowerCase()
|
|
148
|
-
.
|
|
149
|
-
.
|
|
151
|
+
.replaceAll(/[^a-z0-9]+/g, "-")
|
|
152
|
+
.replaceAll(/^-|-$/g, "");
|
|
150
153
|
|
|
154
|
+
const dependencies: Record<string, string> = {};
|
|
151
155
|
const devDependencies: Record<string, string> = {
|
|
152
156
|
"@jxsuite/compiler": "^0.19.0",
|
|
153
157
|
"@jxsuite/runtime": "^0.19.0",
|
|
@@ -158,18 +162,24 @@ function buildPackageJson({
|
|
|
158
162
|
dev: "jx dev",
|
|
159
163
|
};
|
|
160
164
|
|
|
161
|
-
if (adapter &&
|
|
165
|
+
if (adapter && adapter !== "static") {
|
|
166
|
+
// The generated server worker imports hono; wrangler/node/bun resolve it from node_modules
|
|
167
|
+
dependencies["hono"] = "^4";
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
if (adapter && CF_ADAPTERS.has(adapter)) {
|
|
162
171
|
devDependencies["wrangler"] = "^4";
|
|
163
172
|
scripts.deploy =
|
|
164
173
|
adapter === "cloudflare-workers" ? "wrangler deploy" : "wrangler pages deploy dist";
|
|
165
174
|
}
|
|
166
175
|
|
|
167
176
|
return {
|
|
168
|
-
name: slug,
|
|
169
|
-
private: true,
|
|
170
177
|
description: description || "",
|
|
178
|
+
devDependencies,
|
|
171
179
|
license: "MIT",
|
|
180
|
+
name: slug,
|
|
181
|
+
private: true,
|
|
172
182
|
scripts,
|
|
173
|
-
|
|
183
|
+
...(Object.keys(dependencies).length > 0 && { dependencies }),
|
|
174
184
|
};
|
|
175
185
|
}
|
package/index.ts
CHANGED
|
@@ -7,10 +7,10 @@
|
|
|
7
7
|
|
|
8
8
|
import { createInterface } from "node:readline/promises";
|
|
9
9
|
import { stdin, stdout } from "node:process";
|
|
10
|
-
import {
|
|
10
|
+
import { basename, resolve } from "node:path";
|
|
11
11
|
import { generateProject } from "./generate";
|
|
12
12
|
|
|
13
|
-
const dest = process.argv
|
|
13
|
+
const [dest] = process.argv.slice(2);
|
|
14
14
|
if (!dest) {
|
|
15
15
|
console.error("Usage: bun create @jxsuite <directory>");
|
|
16
16
|
process.exit(1);
|
|
@@ -45,7 +45,7 @@ const adapterMap = {
|
|
|
45
45
|
};
|
|
46
46
|
const adapter = adapterMap[adapterChoice] || "static";
|
|
47
47
|
|
|
48
|
-
await generateProject(destPath, {
|
|
48
|
+
await generateProject(destPath, { adapter, description, name, url });
|
|
49
49
|
|
|
50
50
|
console.log(`
|
|
51
51
|
Project created at ${destPath}
|