@brightsideoy/kama 0.1.0-alpha.17 ā 0.1.0-alpha.22
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 +59 -6
- package/package.json +3 -3
package/bin/cli.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
import { execSync } from 'node:child_process';
|
|
2
3
|
import { existsSync, mkdirSync, writeFileSync } from 'node:fs';
|
|
3
4
|
import { join } from 'node:path';
|
|
4
5
|
import * as readline from 'node:readline/promises';
|
|
@@ -35,10 +36,54 @@ async function createFullWorkspace() {
|
|
|
35
36
|
const siteDomain = (await rl.question('First Website Domain (e.g., www.example.com): ')) || 'www.example.com';
|
|
36
37
|
|
|
37
38
|
const rootDir = join(process.cwd(), projName);
|
|
39
|
+
const dbName = `${projName}-db`.replace(/[^a-zA-Z0-9_-]/g, '_'); // safe DB name
|
|
38
40
|
|
|
39
41
|
console.log(`\nš Creating workspace folder at ./${projName}...`);
|
|
40
42
|
mkdirSync(rootDir, { recursive: true });
|
|
41
43
|
|
|
44
|
+
// --- AUTO D1 CREATION MAGIC ---
|
|
45
|
+
let d1DatabaseId = 'REPLACE_WITH_YOUR_D1_ID';
|
|
46
|
+
let isAuthenticated = false;
|
|
47
|
+
|
|
48
|
+
console.log(`\nš Checking Cloudflare authentication...`);
|
|
49
|
+
try {
|
|
50
|
+
execSync('npx wrangler whoami', { stdio: 'pipe' });
|
|
51
|
+
isAuthenticated = true;
|
|
52
|
+
console.log(`ā
Logged in to Cloudflare.`);
|
|
53
|
+
} catch (error) {
|
|
54
|
+
console.log(`ā ļø You are not logged in to Cloudflare.`);
|
|
55
|
+
console.log(`š Launching browser for Cloudflare login...`);
|
|
56
|
+
try {
|
|
57
|
+
execSync('npx wrangler login', { stdio: 'inherit' });
|
|
58
|
+
isAuthenticated = true;
|
|
59
|
+
console.log(`ā
Successfully logged in!`);
|
|
60
|
+
} catch (loginError) {
|
|
61
|
+
console.log(`ā Login failed or was cancelled.`);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if (isAuthenticated) {
|
|
66
|
+
console.log(`\nšļø Attempting to auto-create Cloudflare D1 Database '${dbName}'...`);
|
|
67
|
+
try {
|
|
68
|
+
const d1Output = execSync(`npx wrangler d1 create ${dbName}`, { encoding: 'utf-8', stdio: 'pipe' });
|
|
69
|
+
|
|
70
|
+
const uuidRegex = /[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}/;
|
|
71
|
+
const match = d1Output.match(uuidRegex);
|
|
72
|
+
|
|
73
|
+
if (match) {
|
|
74
|
+
d1DatabaseId = match[0];
|
|
75
|
+
console.log(`ā
Success! Database ID bound: ${d1DatabaseId}`);
|
|
76
|
+
} else {
|
|
77
|
+
console.log(`ā ļø Could not parse the database ID from Wrangler. You may need to update wrangler.json manually.`);
|
|
78
|
+
}
|
|
79
|
+
} catch (error) {
|
|
80
|
+
console.log(`ā ļø Auto-creation failed. We'll leave a placeholder.`);
|
|
81
|
+
}
|
|
82
|
+
} else {
|
|
83
|
+
console.log(`ā ļø Skipping database creation. We'll leave a placeholder in wrangler.json.`);
|
|
84
|
+
}
|
|
85
|
+
// ------------------------------
|
|
86
|
+
|
|
42
87
|
// 1. Root package.json
|
|
43
88
|
writeFileSync(
|
|
44
89
|
join(rootDir, 'package.json'),
|
|
@@ -66,8 +111,12 @@ async function createFullWorkspace() {
|
|
|
66
111
|
type: 'module',
|
|
67
112
|
version: '1.0.0',
|
|
68
113
|
scripts: {
|
|
69
|
-
|
|
70
|
-
|
|
114
|
+
"build-schema": "tsx node_modules/@brightsideoy/kama/scripts/build-schema.ts",
|
|
115
|
+
"bundle-schemas": "node node_modules/@brightsideoy/kama/scripts/bundle-definitions.js",
|
|
116
|
+
"schema:local": `npm run build-schema && wrangler d1 execute ${dbName} --local --file=./schema.sql`,
|
|
117
|
+
"schema:remote": `npm run build-schema && wrangler d1 execute ${dbName} --remote --file=./schema.sql`,
|
|
118
|
+
"dev": "npm run schema:local && npm run bundle-schemas && wrangler dev",
|
|
119
|
+
"deploy": "npm run schema:remote && npm run bundle-schemas && wrangler deploy"
|
|
71
120
|
},
|
|
72
121
|
dependencies: {
|
|
73
122
|
'@brightsideoy/kama': 'latest',
|
|
@@ -92,8 +141,8 @@ async function createFullWorkspace() {
|
|
|
92
141
|
vars: { CDN_DOMAIN: cmsDomain },
|
|
93
142
|
d1_databases: [{
|
|
94
143
|
binding: 'DB',
|
|
95
|
-
database_name:
|
|
96
|
-
database_id:
|
|
144
|
+
database_name: dbName,
|
|
145
|
+
database_id: d1DatabaseId,
|
|
97
146
|
}],
|
|
98
147
|
r2_buckets: [{
|
|
99
148
|
binding: 'MEDIA_BUCKET',
|
|
@@ -103,13 +152,17 @@ async function createFullWorkspace() {
|
|
|
103
152
|
);
|
|
104
153
|
|
|
105
154
|
// 3. Setup First Astro Site
|
|
106
|
-
const siteFolderName = siteDomain.split('.')[0];
|
|
155
|
+
const siteFolderName = siteDomain.split('.')[0];
|
|
107
156
|
await generateAstroSite(rootDir, siteFolderName, siteDomain, cmsDomain);
|
|
108
157
|
|
|
109
158
|
console.log(`\n⨠Workspace ready! Next steps:`);
|
|
110
159
|
console.log(` 1. cd ${projName}`);
|
|
111
160
|
console.log(` 2. npm install`);
|
|
112
|
-
|
|
161
|
+
if (d1DatabaseId === 'REPLACE_WITH_YOUR_D1_ID') {
|
|
162
|
+
console.log(` 3. Run 'npx wrangler login', create a D1 database, and update cms-worker/wrangler.json`);
|
|
163
|
+
} else {
|
|
164
|
+
console.log(` 3. You are fully configured! Run 'npm run dev:cms' from the workspace root to start the backend.`);
|
|
165
|
+
}
|
|
113
166
|
}
|
|
114
167
|
|
|
115
168
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@brightsideoy/kama",
|
|
3
|
-
"version": "0.1.0-alpha.
|
|
3
|
+
"version": "0.1.0-alpha.22",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -11,8 +11,8 @@
|
|
|
11
11
|
}
|
|
12
12
|
},
|
|
13
13
|
"bin": {
|
|
14
|
-
"kama": "
|
|
15
|
-
"create-kama": "
|
|
14
|
+
"kama": "bin/cli.js",
|
|
15
|
+
"create-kama": "bin/cli.js"
|
|
16
16
|
},
|
|
17
17
|
"files": [
|
|
18
18
|
"dist",
|