@brightsideoy/kama 0.1.0-alpha.14 → 0.1.0-alpha.17
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 +88 -118
- package/package.json +1 -1
package/bin/cli.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import {
|
|
3
|
-
import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
2
|
+
import { existsSync, mkdirSync, writeFileSync } from 'node:fs';
|
|
4
3
|
import { join } from 'node:path';
|
|
5
4
|
import * as readline from 'node:readline/promises';
|
|
6
5
|
|
|
@@ -31,13 +30,11 @@ async function main() {
|
|
|
31
30
|
* MODE 1: Kickstart full Monorepo Workspace
|
|
32
31
|
*/
|
|
33
32
|
async function createFullWorkspace() {
|
|
34
|
-
const projName = (await rl.question('Project folder name [kama-
|
|
35
|
-
const
|
|
36
|
-
const
|
|
33
|
+
const projName = (await rl.question('Project folder name [kama-workspace]: ')) || 'kama-workspace';
|
|
34
|
+
const cmsDomain = (await rl.question('CMS Admin Domain (e.g., cms.example.com): ')) || 'cms.example.com';
|
|
35
|
+
const siteDomain = (await rl.question('First Website Domain (e.g., www.example.com): ')) || 'www.example.com';
|
|
37
36
|
|
|
38
37
|
const rootDir = join(process.cwd(), projName);
|
|
39
|
-
const cmsDomain = `kama.${domain}`;
|
|
40
|
-
const siteDomain = `${sitePrefix}.${domain}`;
|
|
41
38
|
|
|
42
39
|
console.log(`\n📁 Creating workspace folder at ./${projName}...`);
|
|
43
40
|
mkdirSync(rootDir, { recursive: true });
|
|
@@ -45,20 +42,16 @@ async function createFullWorkspace() {
|
|
|
45
42
|
// 1. Root package.json
|
|
46
43
|
writeFileSync(
|
|
47
44
|
join(rootDir, 'package.json'),
|
|
48
|
-
JSON.stringify(
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
'deploy:cms': 'npm run deploy -w cms-worker',
|
|
57
|
-
},
|
|
45
|
+
JSON.stringify({
|
|
46
|
+
name: projName,
|
|
47
|
+
private: true,
|
|
48
|
+
type: 'module',
|
|
49
|
+
workspaces: ['cms-worker', 'sites/*'],
|
|
50
|
+
scripts: {
|
|
51
|
+
'dev:cms': 'npm run dev -w cms-worker',
|
|
52
|
+
'deploy:cms': 'npm run deploy -w cms-worker',
|
|
58
53
|
},
|
|
59
|
-
|
|
60
|
-
2
|
|
61
|
-
)
|
|
54
|
+
}, null, 2)
|
|
62
55
|
);
|
|
63
56
|
|
|
64
57
|
// 2. Setup CMS Worker
|
|
@@ -68,61 +61,50 @@ async function createFullWorkspace() {
|
|
|
68
61
|
|
|
69
62
|
writeFileSync(
|
|
70
63
|
join(cmsDir, 'package.json'),
|
|
71
|
-
JSON.stringify(
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
deploy: 'wrangler deploy',
|
|
79
|
-
},
|
|
80
|
-
dependencies: {
|
|
81
|
-
'@brightsideoy/kama': 'latest',
|
|
82
|
-
},
|
|
83
|
-
devDependencies: {
|
|
84
|
-
wrangler: '^4.127.1',
|
|
85
|
-
tsx: '^4.19.2',
|
|
86
|
-
},
|
|
64
|
+
JSON.stringify({
|
|
65
|
+
name: 'kama-worker',
|
|
66
|
+
type: 'module',
|
|
67
|
+
version: '1.0.0',
|
|
68
|
+
scripts: {
|
|
69
|
+
dev: 'wrangler dev',
|
|
70
|
+
deploy: 'wrangler deploy',
|
|
87
71
|
},
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
72
|
+
dependencies: {
|
|
73
|
+
'@brightsideoy/kama': 'latest',
|
|
74
|
+
},
|
|
75
|
+
devDependencies: {
|
|
76
|
+
wrangler: '^4.127.1',
|
|
77
|
+
tsx: '^4.19.2',
|
|
78
|
+
},
|
|
79
|
+
}, null, 2)
|
|
91
80
|
);
|
|
92
81
|
|
|
93
82
|
writeFileSync(
|
|
94
83
|
join(cmsDir, 'wrangler.json'),
|
|
95
|
-
JSON.stringify(
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
binding: 'MEDIA_BUCKET',
|
|
115
|
-
bucket_name: 'kama-media-prod',
|
|
116
|
-
},
|
|
117
|
-
],
|
|
118
|
-
},
|
|
119
|
-
null,
|
|
120
|
-
2
|
|
121
|
-
)
|
|
84
|
+
JSON.stringify({
|
|
85
|
+
$schema: 'node_modules/wrangler/config-schema.json',
|
|
86
|
+
name: 'kama-worker',
|
|
87
|
+
main: 'node_modules/@brightsideoy/kama/dist/index.js',
|
|
88
|
+
compatibility_date: '2026-08-01',
|
|
89
|
+
compatibility_flags: ['nodejs_compat'],
|
|
90
|
+
assets: { directory: './dist', binding: 'ASSETS' },
|
|
91
|
+
routes: [{ pattern: cmsDomain, custom_domain: true }],
|
|
92
|
+
vars: { CDN_DOMAIN: cmsDomain },
|
|
93
|
+
d1_databases: [{
|
|
94
|
+
binding: 'DB',
|
|
95
|
+
database_name: 'kama_cms_db',
|
|
96
|
+
database_id: 'REPLACE_WITH_YOUR_D1_ID',
|
|
97
|
+
}],
|
|
98
|
+
r2_buckets: [{
|
|
99
|
+
binding: 'MEDIA_BUCKET',
|
|
100
|
+
bucket_name: 'kama-media-prod',
|
|
101
|
+
}],
|
|
102
|
+
}, null, 2)
|
|
122
103
|
);
|
|
123
104
|
|
|
124
105
|
// 3. Setup First Astro Site
|
|
125
|
-
|
|
106
|
+
const siteFolderName = siteDomain.split('.')[0]; // e.g. "www" or "demo"
|
|
107
|
+
await generateAstroSite(rootDir, siteFolderName, siteDomain, cmsDomain);
|
|
126
108
|
|
|
127
109
|
console.log(`\n✨ Workspace ready! Next steps:`);
|
|
128
110
|
console.log(` 1. cd ${projName}`);
|
|
@@ -141,13 +123,13 @@ async function createNewSiteOnly() {
|
|
|
141
123
|
return;
|
|
142
124
|
}
|
|
143
125
|
|
|
144
|
-
const
|
|
145
|
-
const
|
|
146
|
-
const cmsDomain = (await rl.question('CMS API
|
|
126
|
+
const siteFolder = await rl.question('Site folder name (e.g., my-new-site): ');
|
|
127
|
+
const siteDomain = await rl.question('Website Domain (e.g., brand.com): ');
|
|
128
|
+
const cmsDomain = (await rl.question('CMS API Domain (e.g., cms.example.com): ')) || 'cms.example.com';
|
|
147
129
|
|
|
148
|
-
await generateAstroSite(rootDir,
|
|
130
|
+
await generateAstroSite(rootDir, siteFolder, siteDomain, cmsDomain.replace(/^https?:\/\//, ''));
|
|
149
131
|
|
|
150
|
-
console.log(`\n✨ Site created in sites/${
|
|
132
|
+
console.log(`\n✨ Site created in sites/${siteFolder}! Run 'npm install' at workspace root.`);
|
|
151
133
|
}
|
|
152
134
|
|
|
153
135
|
/**
|
|
@@ -162,61 +144,50 @@ async function generateAstroSite(rootDir, siteFolder, siteDomain, cmsDomain) {
|
|
|
162
144
|
mkdirSync(join(siteDir, 'src/components/blocks'), { recursive: true });
|
|
163
145
|
mkdirSync(join(siteDir, 'src/lib'), { recursive: true });
|
|
164
146
|
|
|
165
|
-
// 1. package.json
|
|
166
147
|
writeFileSync(
|
|
167
148
|
join(siteDir, 'package.json'),
|
|
168
|
-
JSON.stringify(
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
deploy: 'astro build && wrangler deploy',
|
|
179
|
-
},
|
|
180
|
-
dependencies: {
|
|
181
|
-
'@astrojs/cloudflare': '^14.2.5',
|
|
182
|
-
'@brightsideoy/kama': 'latest',
|
|
183
|
-
astro: '^7.2.2',
|
|
184
|
-
wrangler: '^4.127.1',
|
|
185
|
-
},
|
|
149
|
+
JSON.stringify({
|
|
150
|
+
name: siteFolder,
|
|
151
|
+
type: 'module',
|
|
152
|
+
version: '0.0.1',
|
|
153
|
+
engines: { node: '>=22.12.0' },
|
|
154
|
+
scripts: {
|
|
155
|
+
dev: 'astro dev',
|
|
156
|
+
build: 'astro build',
|
|
157
|
+
preview: 'astro preview',
|
|
158
|
+
deploy: 'astro build && wrangler deploy',
|
|
186
159
|
},
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
160
|
+
dependencies: {
|
|
161
|
+
'@astrojs/cloudflare': '^14.2.5',
|
|
162
|
+
'@brightsideoy/kama': 'latest',
|
|
163
|
+
astro: '^7.2.2',
|
|
164
|
+
wrangler: '^4.127.1',
|
|
165
|
+
},
|
|
166
|
+
}, null, 2)
|
|
190
167
|
);
|
|
191
168
|
|
|
192
|
-
// 2. wrangler.json
|
|
193
169
|
writeFileSync(
|
|
194
170
|
join(siteDir, 'wrangler.json'),
|
|
195
|
-
JSON.stringify(
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
PUBLIC_API_URL: `https://${cmsDomain}`,
|
|
212
|
-
},
|
|
171
|
+
JSON.stringify({
|
|
172
|
+
$schema: 'node_modules/wrangler/config-schema.json',
|
|
173
|
+
name: siteFolder,
|
|
174
|
+
compatibility_date: '2026-08-01',
|
|
175
|
+
compatibility_flags: ['nodejs_compat'],
|
|
176
|
+
assets: {
|
|
177
|
+
directory: './dist',
|
|
178
|
+
binding: 'ASSETS',
|
|
179
|
+
html_handling: 'drop-trailing-slash',
|
|
180
|
+
not_found_handling: '404-page',
|
|
181
|
+
},
|
|
182
|
+
services: [{ binding: 'CMS_WORKER', service: 'kama-worker' }],
|
|
183
|
+
routes: [{ pattern: siteDomain, custom_domain: true }],
|
|
184
|
+
vars: {
|
|
185
|
+
PUBLIC_CMS_URL: `https://${cmsDomain}`,
|
|
186
|
+
PUBLIC_API_URL: `https://${cmsDomain}`,
|
|
213
187
|
},
|
|
214
|
-
|
|
215
|
-
2
|
|
216
|
-
)
|
|
188
|
+
}, null, 2)
|
|
217
189
|
);
|
|
218
190
|
|
|
219
|
-
// 3. astro.config.mjs
|
|
220
191
|
const astroConfig = `import { defineConfig } from 'astro/config';
|
|
221
192
|
import cloudflare from '@astrojs/cloudflare';
|
|
222
193
|
|
|
@@ -238,7 +209,6 @@ export default defineConfig({
|
|
|
238
209
|
});`;
|
|
239
210
|
writeFileSync(join(siteDir, 'astro.config.mjs'), astroConfig);
|
|
240
211
|
|
|
241
|
-
// 4. .env file
|
|
242
212
|
writeFileSync(
|
|
243
213
|
join(siteDir, '.env'),
|
|
244
214
|
`PUBLIC_CMS_URL="https://${cmsDomain}"\nPUBLIC_API_URL="https://${cmsDomain}"\n`
|