create-trokky 0.1.5 → 0.1.6
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/dist/emit.d.ts +2 -1
- package/dist/emit.js +15 -3
- package/dist/generate.js +5 -3
- package/package.json +1 -1
package/dist/emit.d.ts
CHANGED
|
@@ -11,7 +11,8 @@ export declare function astroConfig(config: ProjectConfig): string;
|
|
|
11
11
|
* takes its bindings from `cloudflare:workers`, a server is handed the core through Astro locals.
|
|
12
12
|
*/
|
|
13
13
|
export declare function pageHelper(config: ProjectConfig): string;
|
|
14
|
-
|
|
14
|
+
/** `seedFiles`: the project ships public/seed/, which the sample-content seed reads through ASSETS. */
|
|
15
|
+
export declare function wranglerConfig(config: ProjectConfig, seedFiles?: boolean): string;
|
|
15
16
|
/** The Worker's Trokky wiring: which adapters are imported is the composition, literally. */
|
|
16
17
|
export declare function workersCore(config: ProjectConfig): string;
|
|
17
18
|
export declare function workersEntry(config: ProjectConfig): string;
|
package/dist/emit.js
CHANGED
|
@@ -134,10 +134,14 @@ export async function load(astro: AstroGlobal): Promise<Site> {
|
|
|
134
134
|
}
|
|
135
135
|
`;
|
|
136
136
|
}
|
|
137
|
-
|
|
137
|
+
/** `seedFiles`: the project ships public/seed/, which the sample-content seed reads through ASSETS. */
|
|
138
|
+
export function wranglerConfig(config, seedFiles = false) {
|
|
139
|
+
// An API-only project whose sample content ships files still binds ./public: the seed reads
|
|
140
|
+
// them through the binding, and run_worker_first keeps them from being served. One whose seed
|
|
141
|
+
// has no files has no public/ at all, and wrangler refuses a missing assets directory.
|
|
138
142
|
const assets = hasFrontend(config)
|
|
139
143
|
? `"./dist/client"`
|
|
140
|
-
: hasStudio(config)
|
|
144
|
+
: hasStudio(config) || seedFiles
|
|
141
145
|
? `"./public"`
|
|
142
146
|
: null;
|
|
143
147
|
const lines = [
|
|
@@ -150,7 +154,15 @@ export function wranglerConfig(config) {
|
|
|
150
154
|
' "compatibility_flags": ["nodejs_compat"],',
|
|
151
155
|
];
|
|
152
156
|
if (assets) {
|
|
153
|
-
lines.push(' "assets": {', ` "directory": ${assets},`, ' "binding": "ASSETS",',
|
|
157
|
+
lines.push(' "assets": {', ` "directory": ${assets},`, ' "binding": "ASSETS",', ...(hasStudio(config)
|
|
158
|
+
? [
|
|
159
|
+
' // Every request goes through the Worker: /studio needs its config injected, and /api',
|
|
160
|
+
' // is not a file. Static files are fetched through the binding by the handlers.',
|
|
161
|
+
]
|
|
162
|
+
: [
|
|
163
|
+
' // Only the sample-content seed reads these, through the binding. Every request goes',
|
|
164
|
+
' // through the Worker, which serves nothing outside /api, so none of them is public.',
|
|
165
|
+
]), ' "run_worker_first": true,', ' "html_handling": "none",', ' "not_found_handling": "none"', ' },');
|
|
154
166
|
}
|
|
155
167
|
lines.push(' "d1_databases": [', ` { "binding": "DB", "database_name": ${JSON.stringify(config.name)}, "database_id": "" }`, ' ],', ' "r2_buckets": [', ` { "binding": "MEDIA", "bucket_name": ${JSON.stringify(config.name + '-media')} }`, ' ],');
|
|
156
168
|
if (config.images === 'cloudflare-images') {
|
package/dist/generate.js
CHANGED
|
@@ -54,7 +54,8 @@ export function generate(config, source) {
|
|
|
54
54
|
tree.set('src/trokky/page.ts', emit.pageHelper(config));
|
|
55
55
|
}
|
|
56
56
|
if (config.target === 'workers') {
|
|
57
|
-
tree.
|
|
57
|
+
const seedFiles = [...tree.keys()].some(k => k.startsWith('public/seed/'));
|
|
58
|
+
tree.set('wrangler.jsonc', emit.wranglerConfig(config, seedFiles));
|
|
58
59
|
tree.set('src/worker.ts', emit.workersEntry(config));
|
|
59
60
|
tree.set('src/trokky/core.ts', emit.workersCore(config));
|
|
60
61
|
tree.set('.dev.vars.example', emit.envExample(config));
|
|
@@ -68,8 +69,9 @@ export function generate(config, source) {
|
|
|
68
69
|
if (!hasStudio(config)) {
|
|
69
70
|
tree.delete('scripts/copy-studio.mjs');
|
|
70
71
|
}
|
|
71
|
-
//
|
|
72
|
-
|
|
72
|
+
// Blank content has nothing to seed. Every other project reads its seed files: from disk on
|
|
73
|
+
// Node, through the assets binding on Workers (bound for API-only projects too).
|
|
74
|
+
if (config.content === 'blank') {
|
|
73
75
|
for (const path of [...tree.keys()])
|
|
74
76
|
if (path.startsWith('public/seed/'))
|
|
75
77
|
tree.delete(path);
|