@brightsideoy/kama 0.1.0-alpha.42 â 0.1.0-alpha.43
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/bin/cli.js +26 -13
- package/package.json +1 -1
package/bin/cli.js
CHANGED
|
@@ -37,12 +37,15 @@ async function createFullWorkspace() {
|
|
|
37
37
|
|
|
38
38
|
const rootDir = join(process.cwd(), projName);
|
|
39
39
|
|
|
40
|
+
// đŻ Derive dynamic worker, database, and bucket names from project folder name
|
|
41
|
+
const workerName = `${projName}-worker`.toLowerCase().replace(/[^a-z0-9_-]/g, '-');
|
|
40
42
|
let dbName = `${projName}-db`.replace(/[^a-zA-Z0-9_-]/g, '_');
|
|
43
|
+
const bucketName = `${projName}-media-prod`.toLowerCase().replace(/[^a-z0-9_-]/g, '-');
|
|
41
44
|
|
|
42
45
|
console.log(`\nđ Creating workspace folder at ./${projName}...`);
|
|
43
46
|
mkdirSync(rootDir, { recursive: true });
|
|
44
47
|
|
|
45
|
-
// đŻ Scaffold schemas directory for custom
|
|
48
|
+
// đŻ Scaffold schemas directory for project-level custom YAML definitions
|
|
46
49
|
mkdirSync(join(rootDir, 'schemas', 'nodes'), { recursive: true });
|
|
47
50
|
mkdirSync(join(rootDir, 'schemas', 'blocks'), { recursive: true });
|
|
48
51
|
|
|
@@ -116,7 +119,7 @@ async function createFullWorkspace() {
|
|
|
116
119
|
}
|
|
117
120
|
// ------------------------------
|
|
118
121
|
|
|
119
|
-
// đŻ 1. Root package.json
|
|
122
|
+
// đŻ 1. Root package.json
|
|
120
123
|
writeFileSync(
|
|
121
124
|
join(rootDir, 'package.json'),
|
|
122
125
|
JSON.stringify({
|
|
@@ -135,8 +138,8 @@ async function createFullWorkspace() {
|
|
|
135
138
|
}, null, 2)
|
|
136
139
|
);
|
|
137
140
|
|
|
138
|
-
// đŻ 2. Setup CMS Worker
|
|
139
|
-
console.log(`\nâď¸ Configuring CMS Worker (${cmsDomain})...`);
|
|
141
|
+
// đŻ 2. Setup CMS Worker with Dynamic Names
|
|
142
|
+
console.log(`\nâď¸ Configuring CMS Worker '${workerName}' (${cmsDomain})...`);
|
|
140
143
|
const cmsDir = join(rootDir, 'cms-worker');
|
|
141
144
|
mkdirSync(cmsDir, { recursive: true });
|
|
142
145
|
|
|
@@ -148,7 +151,7 @@ async function createFullWorkspace() {
|
|
|
148
151
|
writeFileSync(
|
|
149
152
|
join(cmsDir, 'package.json'),
|
|
150
153
|
JSON.stringify({
|
|
151
|
-
name:
|
|
154
|
+
name: workerName,
|
|
152
155
|
type: 'module',
|
|
153
156
|
version: '1.0.0',
|
|
154
157
|
scripts: {
|
|
@@ -172,7 +175,7 @@ async function createFullWorkspace() {
|
|
|
172
175
|
join(cmsDir, 'wrangler.json'),
|
|
173
176
|
JSON.stringify({
|
|
174
177
|
$schema: '../node_modules/wrangler/config-schema.json',
|
|
175
|
-
name:
|
|
178
|
+
name: workerName,
|
|
176
179
|
main: 'index.js',
|
|
177
180
|
compatibility_date: '2026-08-01',
|
|
178
181
|
compatibility_flags: ['nodejs_compat'],
|
|
@@ -189,14 +192,14 @@ async function createFullWorkspace() {
|
|
|
189
192
|
}],
|
|
190
193
|
r2_buckets: [{
|
|
191
194
|
binding: 'MEDIA_BUCKET',
|
|
192
|
-
bucket_name:
|
|
195
|
+
bucket_name: bucketName,
|
|
193
196
|
}],
|
|
194
197
|
}, null, 2)
|
|
195
198
|
);
|
|
196
199
|
|
|
197
|
-
// 3. Setup First Astro Site
|
|
200
|
+
// đŻ 3. Setup First Astro Site tied to target workerName
|
|
198
201
|
const siteFolderName = siteDomain.split('.')[0];
|
|
199
|
-
await generateAstroSite(rootDir, siteFolderName, siteDomain, cmsDomain);
|
|
202
|
+
await generateAstroSite(rootDir, siteFolderName, siteDomain, cmsDomain, workerName);
|
|
200
203
|
|
|
201
204
|
console.log(`\n⨠Workspace ready! Next steps:`);
|
|
202
205
|
console.log(` 1. cd ${projName}`);
|
|
@@ -219,11 +222,21 @@ async function createNewSiteOnly() {
|
|
|
219
222
|
return;
|
|
220
223
|
}
|
|
221
224
|
|
|
225
|
+
// Try reading cms-worker/wrangler.json to determine workerName dynamically
|
|
226
|
+
let targetWorkerName = 'kama-worker';
|
|
227
|
+
const cmsWranglerPath = join(rootDir, 'cms-worker', 'wrangler.json');
|
|
228
|
+
if (existsSync(cmsWranglerPath)) {
|
|
229
|
+
try {
|
|
230
|
+
const cmsWrangler = JSON.parse(readFileSync(cmsWranglerPath, 'utf-8'));
|
|
231
|
+
if (cmsWrangler.name) targetWorkerName = cmsWrangler.name;
|
|
232
|
+
} catch (e) { }
|
|
233
|
+
}
|
|
234
|
+
|
|
222
235
|
const siteFolder = await rl.question('Site folder name (e.g., my-new-site): ');
|
|
223
236
|
const siteDomain = await rl.question('Website Domain (e.g., brand.com): ');
|
|
224
237
|
const cmsDomain = (await rl.question('CMS API Domain (e.g., cms.example.com): ')) || 'cms.example.com';
|
|
225
238
|
|
|
226
|
-
await generateAstroSite(rootDir, siteFolder, siteDomain, cmsDomain.replace(/^https?:\/\//, ''));
|
|
239
|
+
await generateAstroSite(rootDir, siteFolder, siteDomain, cmsDomain.replace(/^https?:\/\//, ''), targetWorkerName);
|
|
227
240
|
|
|
228
241
|
console.log(`\n⨠Site created in sites/${siteFolder}! Run 'npm install' at workspace root.`);
|
|
229
242
|
}
|
|
@@ -231,8 +244,8 @@ async function createNewSiteOnly() {
|
|
|
231
244
|
/**
|
|
232
245
|
* Helper: Scaffolds the Astro site with middleware, wrangler.json, & slug page
|
|
233
246
|
*/
|
|
234
|
-
async function generateAstroSite(rootDir, siteFolder, siteDomain, cmsDomain) {
|
|
235
|
-
console.log(`\nđ Scaffolding Astro site (${siteFolder}) mapped to ${siteDomain}...`);
|
|
247
|
+
async function generateAstroSite(rootDir, siteFolder, siteDomain, cmsDomain, workerName = 'kama-worker') {
|
|
248
|
+
console.log(`\nđ Scaffolding Astro site (${siteFolder}) mapped to ${siteDomain} (Service: ${workerName})...`);
|
|
236
249
|
|
|
237
250
|
const siteDir = join(rootDir, 'sites', siteFolder);
|
|
238
251
|
mkdirSync(join(siteDir, 'src/pages'), { recursive: true });
|
|
@@ -275,7 +288,7 @@ async function generateAstroSite(rootDir, siteFolder, siteDomain, cmsDomain) {
|
|
|
275
288
|
html_handling: 'drop-trailing-slash',
|
|
276
289
|
not_found_handling: '404-page',
|
|
277
290
|
},
|
|
278
|
-
services: [{ binding: 'CMS_WORKER', service:
|
|
291
|
+
services: [{ binding: 'CMS_WORKER', service: workerName }],
|
|
279
292
|
routes: [{ pattern: siteDomain, custom_domain: true }],
|
|
280
293
|
vars: {
|
|
281
294
|
PUBLIC_CMS_URL: `https://${cmsDomain}`,
|