d1s 0.2.3 → 0.2.5
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/.next/.next/BUILD_ID +1 -1
- package/dist/.next/.next/app-build-manifest.json +17 -17
- package/dist/.next/.next/app-path-routes-manifest.json +1 -1
- package/dist/.next/.next/build-manifest.json +2 -2
- package/dist/.next/.next/cache/.rscinfo +1 -1
- package/dist/.next/.next/cache/.tsbuildinfo +1 -1
- package/dist/.next/.next/cache/webpack/client-production/0.pack +0 -0
- package/dist/.next/.next/cache/webpack/client-production/1.pack +0 -0
- package/dist/.next/.next/cache/webpack/client-production/2.pack +0 -0
- package/dist/.next/.next/cache/webpack/client-production/index.pack +0 -0
- package/dist/.next/.next/cache/webpack/client-production/index.pack.old +0 -0
- package/dist/.next/.next/cache/webpack/edge-server-production/index.pack +0 -0
- package/dist/.next/.next/cache/webpack/server-production/0.pack +0 -0
- package/dist/.next/.next/cache/webpack/server-production/1.pack +0 -0
- package/dist/.next/.next/cache/webpack/server-production/index.pack +0 -0
- package/dist/.next/.next/cache/webpack/server-production/index.pack.old +0 -0
- package/dist/.next/.next/next-minimal-server.js.nft.json +1 -1
- package/dist/.next/.next/next-server.js.nft.json +1 -1
- package/dist/.next/.next/prerender-manifest.json +1 -1
- package/dist/.next/.next/server/app/_not-found/page_client-reference-manifest.js +1 -1
- package/dist/.next/.next/server/app/_not-found.html +1 -1
- package/dist/.next/.next/server/app/_not-found.rsc +2 -2
- package/dist/.next/.next/server/app/api/cloudflare/route.js +1 -1
- package/dist/.next/.next/server/app/api/cloudflare/route.js.nft.json +1 -1
- package/dist/.next/.next/server/app/api/cloudflare/route_client-reference-manifest.js +1 -1
- package/dist/.next/.next/server/app/api/databases/route.js +1 -1
- package/dist/.next/.next/server/app/api/databases/route.js.nft.json +1 -1
- package/dist/.next/.next/server/app/api/databases/route_client-reference-manifest.js +1 -1
- package/dist/.next/.next/server/app/api/migrations/sync/route.js +3 -3
- package/dist/.next/.next/server/app/api/migrations/sync/route.js.nft.json +1 -1
- package/dist/.next/.next/server/app/api/migrations/sync/route_client-reference-manifest.js +1 -1
- package/dist/.next/.next/server/app/api/migrations/sync-files/route.js +1 -1
- package/dist/.next/.next/server/app/api/migrations/sync-files/route.js.nft.json +1 -1
- package/dist/.next/.next/server/app/api/migrations/sync-files/route_client-reference-manifest.js +1 -1
- package/dist/.next/.next/server/app/api/pull-remote/confirm/route.js +1 -1
- package/dist/.next/.next/server/app/api/pull-remote/confirm/route.js.nft.json +1 -1
- package/dist/.next/.next/server/app/api/pull-remote/confirm/route_client-reference-manifest.js +1 -1
- package/dist/.next/.next/server/app/api/pull-remote/preview/route.js +1 -1
- package/dist/.next/.next/server/app/api/pull-remote/preview/route.js.nft.json +1 -1
- package/dist/.next/.next/server/app/api/pull-remote/preview/route_client-reference-manifest.js +1 -1
- package/dist/.next/.next/server/app/api/push-remote/confirm/route.js +2 -2
- package/dist/.next/.next/server/app/api/push-remote/confirm/route.js.nft.json +1 -1
- package/dist/.next/.next/server/app/api/push-remote/confirm/route_client-reference-manifest.js +1 -1
- package/dist/.next/.next/server/app/api/push-remote/preview/route.js +2 -2
- package/dist/.next/.next/server/app/api/push-remote/preview/route.js.nft.json +1 -1
- package/dist/.next/.next/server/app/api/push-remote/preview/route_client-reference-manifest.js +1 -1
- package/dist/.next/.next/server/app/api/query/route.js +2 -2
- package/dist/.next/.next/server/app/api/query/route.js.nft.json +1 -1
- package/dist/.next/.next/server/app/api/query/route_client-reference-manifest.js +1 -1
- package/dist/.next/.next/server/app/api/tables/[name]/route.js +4 -4
- package/dist/.next/.next/server/app/api/tables/[name]/route.js.nft.json +1 -1
- package/dist/.next/.next/server/app/api/tables/[name]/route_client-reference-manifest.js +1 -1
- package/dist/.next/.next/server/app/api/tables/route.js +2 -2
- package/dist/.next/.next/server/app/api/tables/route.js.nft.json +1 -1
- package/dist/.next/.next/server/app/api/tables/route_client-reference-manifest.js +1 -1
- package/dist/.next/.next/server/app/index.html +3 -3
- package/dist/.next/.next/server/app/index.rsc +3 -3
- package/dist/.next/.next/server/app/page.js +8 -8
- package/dist/.next/.next/server/app/page_client-reference-manifest.js +1 -1
- package/dist/.next/.next/server/app-paths-manifest.json +3 -3
- package/dist/.next/.next/server/chunks/336.js +1 -1
- package/dist/.next/.next/server/chunks/{801.js → 603.js} +11 -11
- package/dist/.next/.next/server/chunks/686.js +23 -0
- package/dist/.next/.next/server/chunks/992.js +2 -2
- package/dist/.next/.next/server/pages/404.html +1 -1
- package/dist/.next/.next/server/pages/500.html +1 -1
- package/dist/.next/.next/server/server-reference-manifest.json +1 -1
- package/dist/.next/.next/server/webpack-runtime.js +1 -1
- package/dist/.next/.next/static/chunks/app/page-79049bfa6cc07e11.js +1 -0
- package/dist/.next/.next/static/css/cf41da7a0d47f779.css +3 -0
- package/dist/.next/.next/trace +3 -3
- package/dist/.next/BUILD_ID +1 -1
- package/dist/.next/app-build-manifest.json +18 -18
- package/dist/.next/app-path-routes-manifest.json +1 -1
- package/dist/.next/build-manifest.json +2 -2
- package/dist/.next/cache/.rscinfo +1 -1
- package/dist/.next/cache/.tsbuildinfo +1 -1
- package/dist/.next/cache/webpack/client-production/0.pack +0 -0
- package/dist/.next/cache/webpack/client-production/index.pack +0 -0
- package/dist/.next/cache/webpack/edge-server-production/index.pack +0 -0
- package/dist/.next/cache/webpack/server-production/0.pack +0 -0
- package/dist/.next/cache/webpack/server-production/index.pack +0 -0
- package/dist/.next/next-minimal-server.js.nft.json +1 -1
- package/dist/.next/next-server.js.nft.json +1 -1
- package/dist/.next/prerender-manifest.json +1 -1
- package/dist/.next/server/app/_not-found/page_client-reference-manifest.js +1 -1
- package/dist/.next/server/app/_not-found.html +1 -1
- package/dist/.next/server/app/_not-found.rsc +2 -2
- package/dist/.next/server/app/api/cloudflare/route.js +1 -1
- package/dist/.next/server/app/api/cloudflare/route.js.nft.json +1 -1
- package/dist/.next/server/app/api/cloudflare/route_client-reference-manifest.js +1 -1
- package/dist/.next/server/app/api/databases/route.js +1 -1
- package/dist/.next/server/app/api/databases/route.js.nft.json +1 -1
- package/dist/.next/server/app/api/databases/route_client-reference-manifest.js +1 -1
- package/dist/.next/server/app/api/migrations/sync/route.js +3 -3
- package/dist/.next/server/app/api/migrations/sync/route.js.nft.json +1 -1
- package/dist/.next/server/app/api/migrations/sync/route_client-reference-manifest.js +1 -1
- package/dist/.next/server/app/api/migrations/sync-files/route.js +1 -1
- package/dist/.next/server/app/api/migrations/sync-files/route.js.nft.json +1 -1
- package/dist/.next/server/app/api/migrations/sync-files/route_client-reference-manifest.js +1 -1
- package/dist/.next/server/app/api/pull-remote/confirm/route.js +1 -1
- package/dist/.next/server/app/api/pull-remote/confirm/route.js.nft.json +1 -1
- package/dist/.next/server/app/api/pull-remote/confirm/route_client-reference-manifest.js +1 -1
- package/dist/.next/server/app/api/pull-remote/preview/route.js +1 -1
- package/dist/.next/server/app/api/pull-remote/preview/route.js.nft.json +1 -1
- package/dist/.next/server/app/api/pull-remote/preview/route_client-reference-manifest.js +1 -1
- package/dist/.next/server/app/api/push-remote/confirm/route.js +2 -2
- package/dist/.next/server/app/api/push-remote/confirm/route.js.nft.json +1 -1
- package/dist/.next/server/app/api/push-remote/confirm/route_client-reference-manifest.js +1 -1
- package/dist/.next/server/app/api/push-remote/preview/route.js +2 -2
- package/dist/.next/server/app/api/push-remote/preview/route.js.nft.json +1 -1
- package/dist/.next/server/app/api/push-remote/preview/route_client-reference-manifest.js +1 -1
- package/dist/.next/server/app/api/query/route.js +2 -2
- package/dist/.next/server/app/api/query/route.js.nft.json +1 -1
- package/dist/.next/server/app/api/query/route_client-reference-manifest.js +1 -1
- package/dist/.next/server/app/api/tables/[name]/route.js +4 -4
- package/dist/.next/server/app/api/tables/[name]/route.js.nft.json +1 -1
- package/dist/.next/server/app/api/tables/[name]/route_client-reference-manifest.js +1 -1
- package/dist/.next/server/app/api/tables/route.js +2 -2
- package/dist/.next/server/app/api/tables/route.js.nft.json +1 -1
- package/dist/.next/server/app/api/tables/route_client-reference-manifest.js +1 -1
- package/dist/.next/server/app/index.html +3 -3
- package/dist/.next/server/app/index.rsc +3 -3
- package/dist/.next/server/app/page.js +8 -8
- package/dist/.next/server/app/page_client-reference-manifest.js +1 -1
- package/dist/.next/server/app-paths-manifest.json +7 -7
- package/dist/.next/server/chunks/{801.js → 603.js} +11 -11
- package/dist/.next/server/chunks/686.js +23 -0
- package/dist/.next/server/pages/404.html +1 -1
- package/dist/.next/server/pages/500.html +1 -1
- package/dist/.next/server/server-reference-manifest.json +1 -1
- package/dist/.next/server/webpack-runtime.js +1 -1
- package/dist/.next/static/chunks/app/page-79049bfa6cc07e11.js +1 -0
- package/dist/.next/static/css/cf41da7a0d47f779.css +3 -0
- package/dist/.next/trace +14 -13
- package/dist/app/api/databases/route.js +1 -1
- package/dist/app/api/pull-remote/confirm/route.js +20 -20
- package/dist/app/api/push-remote/confirm/route.js +1 -1
- package/dist/app/api/push-remote/preview/route.js +1 -1
- package/dist/app/api/query/route.js +7 -7
- package/dist/app/app/api/databases/route.js +1 -1
- package/dist/app/app/api/pull-remote/confirm/route.js +20 -20
- package/dist/app/app/api/push-remote/confirm/route.js +1 -1
- package/dist/app/app/api/push-remote/preview/route.js +1 -1
- package/dist/app/app/api/query/route.js +7 -7
- package/dist/app/app/page.jsx +3 -6
- package/dist/app/page.jsx +3 -6
- package/dist/d1-studio.js +42 -87
- package/dist/lib/find-wrangler-config.js +10 -9
- package/dist/lib/logger.js +19 -0
- package/package.json +1 -1
- package/scripts/studio.js +42 -87
- package/src/app/api/databases/route.js +1 -1
- package/src/app/api/pull-remote/confirm/route.js +20 -20
- package/src/app/api/push-remote/confirm/route.js +1 -1
- package/src/app/api/push-remote/preview/route.js +1 -1
- package/src/app/api/query/route.js +7 -7
- package/src/app/page.jsx +3 -6
- package/src/components/sidebar.jsx +108 -92
- package/src/lib/find-wrangler-config.js +10 -9
- package/src/lib/logger.js +19 -0
- package/dist/.next/.next/cache/webpack/client-production/3.pack +0 -0
- package/dist/.next/.next/cache/webpack/client-production/4.pack +0 -0
- package/dist/.next/.next/cache/webpack/client-production/5.pack +0 -0
- package/dist/.next/.next/cache/webpack/server-production/2.pack +0 -0
- package/dist/.next/.next/cache/webpack/server-production/3.pack +0 -0
- package/dist/.next/.next/cache/webpack/server-production/4.pack +0 -0
- package/dist/.next/.next/server/chunks/973.js +0 -2
- package/dist/.next/.next/static/_t0S4u4KzUwKctaxLKvx4/_buildManifest.js +0 -1
- package/dist/.next/.next/static/_t0S4u4KzUwKctaxLKvx4/_ssgManifest.js +0 -1
- package/dist/.next/.next/static/chunks/app/page-75081ac7a88cb706.js +0 -1
- package/dist/.next/.next/static/css/c51a7ef325e30c16.css +0 -3
- package/dist/.next/.next/static/xzPddcyKcodbwNX_sKljr/_buildManifest.js +0 -1
- package/dist/.next/.next/static/xzPddcyKcodbwNX_sKljr/_ssgManifest.js +0 -1
- package/dist/.next/server/chunks/973.js +0 -2
- package/dist/.next/static/OmPVuV0d1lrcjSBQzxkdH/_buildManifest.js +0 -1
- package/dist/.next/static/OmPVuV0d1lrcjSBQzxkdH/_ssgManifest.js +0 -1
- package/dist/.next/static/chunks/app/page-75081ac7a88cb706.js +0 -1
- package/dist/.next/static/css/c51a7ef325e30c16.css +0 -3
- /package/dist/.next/.next/static/{ODMSSwVqLoDcBgbFHUjr8 → q6WmQmyONe88bMN0_jrC2}/_buildManifest.js +0 -0
- /package/dist/.next/.next/static/{ODMSSwVqLoDcBgbFHUjr8 → q6WmQmyONe88bMN0_jrC2}/_ssgManifest.js +0 -0
- /package/dist/.next/{.next/static/YIuXI2CxMwg2fuuUEBsXL → static/Tk1fnz_CXLavm23ZEeChG}/_buildManifest.js +0 -0
- /package/dist/.next/{.next/static/YIuXI2CxMwg2fuuUEBsXL → static/Tk1fnz_CXLavm23ZEeChG}/_ssgManifest.js +0 -0
package/dist/d1-studio.js
CHANGED
|
@@ -11,6 +11,7 @@ import express from 'express';
|
|
|
11
11
|
import { createServer } from 'http';
|
|
12
12
|
import next from 'next';
|
|
13
13
|
import { findWranglerConfig } from '../src/lib/find-wrangler-config.js';
|
|
14
|
+
import logger from '../src/lib/logger.js';
|
|
14
15
|
|
|
15
16
|
// Compute the absolute path of this file and its directory.
|
|
16
17
|
const __filename = fileURLToPath(import.meta.url);
|
|
@@ -46,14 +47,8 @@ async function validateLicenseRemote(licenseKey, email, hardwareId) {
|
|
|
46
47
|
try {
|
|
47
48
|
const response = await fetch(`${baseUrl}/api/validate-license`, {
|
|
48
49
|
method: 'POST',
|
|
49
|
-
headers: {
|
|
50
|
-
|
|
51
|
-
},
|
|
52
|
-
body: JSON.stringify({
|
|
53
|
-
licenseKey,
|
|
54
|
-
email,
|
|
55
|
-
hardwareId,
|
|
56
|
-
}),
|
|
50
|
+
headers: { 'Content-Type': 'application/json' },
|
|
51
|
+
body: JSON.stringify({ licenseKey, email, hardwareId }),
|
|
57
52
|
});
|
|
58
53
|
|
|
59
54
|
const result = await response.json();
|
|
@@ -65,7 +60,6 @@ async function validateLicenseRemote(licenseKey, email, hardwareId) {
|
|
|
65
60
|
);
|
|
66
61
|
}
|
|
67
62
|
|
|
68
|
-
// Check for subscription expiration if end_date is provided.
|
|
69
63
|
if (result.end_date && new Date(result.end_date) < new Date()) {
|
|
70
64
|
throw new LicenseError(
|
|
71
65
|
'Your subscription has expired. Please renew your license to continue using D1 Studio.',
|
|
@@ -78,7 +72,6 @@ async function validateLicenseRemote(licenseKey, email, hardwareId) {
|
|
|
78
72
|
if (error instanceof LicenseError) {
|
|
79
73
|
throw error;
|
|
80
74
|
}
|
|
81
|
-
|
|
82
75
|
if (error.name === 'TypeError' && error.message.includes('fetch')) {
|
|
83
76
|
throw new LicenseError(
|
|
84
77
|
process.env.NODE_ENV === 'development'
|
|
@@ -87,7 +80,6 @@ async function validateLicenseRemote(licenseKey, email, hardwareId) {
|
|
|
87
80
|
'CONNECTION_ERROR'
|
|
88
81
|
);
|
|
89
82
|
}
|
|
90
|
-
|
|
91
83
|
throw new LicenseError(
|
|
92
84
|
'An unexpected error occurred during license validation',
|
|
93
85
|
'VALIDATION_ERROR'
|
|
@@ -106,7 +98,6 @@ async function checkLicenseFile() {
|
|
|
106
98
|
if (licenseData.hardwareId !== hardwareId) {
|
|
107
99
|
return null;
|
|
108
100
|
}
|
|
109
|
-
|
|
110
101
|
return licenseData;
|
|
111
102
|
} catch (error) {
|
|
112
103
|
return null;
|
|
@@ -127,22 +118,19 @@ async function saveLicenseFile(licenseData) {
|
|
|
127
118
|
|
|
128
119
|
async function startServer(port, projectDirectory) {
|
|
129
120
|
return new Promise((resolvePromise, rejectPromise) => {
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
//
|
|
133
|
-
// In production (published package), __dirname is in the 'dist' folder so we use it directly.
|
|
134
|
-
// In development, we assume the structure is different and go one level up.
|
|
121
|
+
// Determine Next.js app directory based on environment:
|
|
122
|
+
// In production (published package) __dirname is used.
|
|
123
|
+
// In development (npm link), assume the build is in the parent folder.
|
|
135
124
|
const isProduction = process.env.NODE_ENV !== 'development';
|
|
136
125
|
const nextAppDir = isProduction ? __dirname : join(__dirname, '..');
|
|
137
126
|
|
|
127
|
+
const dev = process.env.NODE_ENV === 'development';
|
|
138
128
|
const app = next({
|
|
139
129
|
dev,
|
|
140
130
|
dir: nextAppDir,
|
|
141
131
|
conf: {
|
|
142
132
|
distDir: '.next',
|
|
143
|
-
experimental: {
|
|
144
|
-
appDir: true
|
|
145
|
-
}
|
|
133
|
+
experimental: { appDir: true }
|
|
146
134
|
}
|
|
147
135
|
});
|
|
148
136
|
const handle = app.getRequestHandler();
|
|
@@ -150,41 +138,29 @@ async function startServer(port, projectDirectory) {
|
|
|
150
138
|
app.prepare()
|
|
151
139
|
.then(() => {
|
|
152
140
|
const server = express();
|
|
153
|
-
|
|
154
|
-
// Set environment variables
|
|
155
141
|
process.env.PORT = port.toString();
|
|
156
142
|
process.env.D1_PROJECT_DIR = projectDirectory;
|
|
143
|
+
const httpServer = createServer((req, res) => handle(req, res));
|
|
157
144
|
|
|
158
|
-
|
|
159
|
-
const httpServer = createServer((req, res) => {
|
|
160
|
-
handle(req, res);
|
|
161
|
-
});
|
|
162
|
-
|
|
163
|
-
// Handle all requests through Next.js
|
|
164
|
-
server.all('*', (req, res) => {
|
|
165
|
-
return handle(req, res);
|
|
166
|
-
});
|
|
145
|
+
server.all('*', (req, res) => handle(req, res));
|
|
167
146
|
|
|
168
|
-
// Start listening
|
|
169
147
|
httpServer.listen(port, (err) => {
|
|
170
148
|
if (err) {
|
|
171
|
-
|
|
149
|
+
logger.error(chalk.red(`Failed to start server: ${err}`));
|
|
172
150
|
rejectPromise(err);
|
|
173
151
|
return;
|
|
174
152
|
}
|
|
175
|
-
|
|
176
|
-
console.log(chalk.green(`Server started on port ${port}`));
|
|
153
|
+
logger.info(chalk.green(`Server started on port ${port}`));
|
|
177
154
|
resolvePromise(httpServer);
|
|
178
155
|
});
|
|
179
156
|
|
|
180
|
-
// Handle server errors
|
|
181
157
|
httpServer.on('error', (err) => {
|
|
182
|
-
|
|
158
|
+
logger.error(chalk.red(`Server error: ${err}`));
|
|
183
159
|
rejectPromise(err);
|
|
184
160
|
});
|
|
185
161
|
})
|
|
186
162
|
.catch((err) => {
|
|
187
|
-
|
|
163
|
+
logger.error(chalk.red(`Failed to prepare Next.js app: ${err}`));
|
|
188
164
|
rejectPromise(err);
|
|
189
165
|
});
|
|
190
166
|
});
|
|
@@ -192,17 +168,15 @@ async function startServer(port, projectDirectory) {
|
|
|
192
168
|
|
|
193
169
|
async function startStudio() {
|
|
194
170
|
try {
|
|
195
|
-
|
|
171
|
+
logger.info(chalk.green('Initializing D1 Studio...'));
|
|
196
172
|
|
|
197
173
|
// Validate license
|
|
198
174
|
let licenseData = await checkLicenseFile();
|
|
199
|
-
|
|
175
|
+
logger.debug(chalk.blue(`License data found: ${JSON.stringify(licenseData)}`));
|
|
200
176
|
|
|
201
177
|
const TWELVE_HOURS_MS = 43200000; // 12 hours
|
|
202
178
|
let shouldRevalidate = true;
|
|
203
|
-
|
|
204
179
|
if (licenseData) {
|
|
205
|
-
// Use lastValidatedAt if available; otherwise, fall back to activatedAt.
|
|
206
180
|
const lastCheck = new Date(licenseData.lastValidatedAt || licenseData.activatedAt);
|
|
207
181
|
if (Date.now() - lastCheck.getTime() < TWELVE_HOURS_MS) {
|
|
208
182
|
shouldRevalidate = false;
|
|
@@ -211,7 +185,7 @@ async function startStudio() {
|
|
|
211
185
|
|
|
212
186
|
if (!licenseData || shouldRevalidate) {
|
|
213
187
|
const { default: inquirer } = await import('inquirer');
|
|
214
|
-
|
|
188
|
+
logger.info(chalk.yellow('\nPlease enter your D1 Studio license information:'));
|
|
215
189
|
|
|
216
190
|
const answers = await inquirer.prompt([
|
|
217
191
|
{
|
|
@@ -231,10 +205,9 @@ async function startStudio() {
|
|
|
231
205
|
},
|
|
232
206
|
]);
|
|
233
207
|
|
|
234
|
-
|
|
208
|
+
logger.debug(chalk.blue(`Entered license information: ${JSON.stringify(answers)}`));
|
|
235
209
|
|
|
236
210
|
const hardwareId = await generateHardwareId();
|
|
237
|
-
|
|
238
211
|
try {
|
|
239
212
|
const validation = await validateLicenseRemote(
|
|
240
213
|
answers.licenseKey,
|
|
@@ -242,51 +215,42 @@ async function startStudio() {
|
|
|
242
215
|
hardwareId
|
|
243
216
|
);
|
|
244
217
|
|
|
245
|
-
// Optionally, you can store the returned end_date for future checks.
|
|
246
218
|
licenseData = {
|
|
247
219
|
licenseKey: answers.licenseKey,
|
|
248
220
|
email: answers.email,
|
|
249
|
-
hardwareId,
|
|
250
|
-
licenseType: validation.licenseType,
|
|
251
221
|
activatedAt: new Date().toISOString(),
|
|
252
|
-
lastValidatedAt: new Date().toISOString(),
|
|
253
222
|
endDate: validation.end_date || null
|
|
254
223
|
};
|
|
255
224
|
|
|
256
225
|
await saveLicenseFile(licenseData);
|
|
257
|
-
|
|
226
|
+
logger.info(chalk.green('\nLicense activated successfully!'));
|
|
258
227
|
} catch (error) {
|
|
259
|
-
|
|
228
|
+
logger.error(chalk.red(`\nLicense validation failed: ${error.message}`));
|
|
260
229
|
process.exit(1);
|
|
261
230
|
}
|
|
262
|
-
} else {
|
|
263
|
-
console.log(chalk.blue('Using cached license data.'));
|
|
264
231
|
}
|
|
265
232
|
|
|
266
233
|
// Get wrangler configuration
|
|
267
234
|
try {
|
|
268
235
|
const userProjectPath = process.cwd();
|
|
269
|
-
|
|
270
236
|
if (!userProjectPath) {
|
|
271
|
-
|
|
237
|
+
logger.error(chalk.red('Error: Could not determine project directory'));
|
|
272
238
|
process.exit(1);
|
|
273
239
|
}
|
|
274
|
-
|
|
240
|
+
|
|
275
241
|
const wranglerResult = await findWranglerConfig(userProjectPath);
|
|
276
|
-
|
|
277
242
|
if (!wranglerResult || !wranglerResult.config) {
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
243
|
+
logger.error(chalk.red('\nError: No wrangler.toml found in current directory'));
|
|
244
|
+
logger.info(chalk.yellow('Make sure you are in a Cloudflare Workers project directory'));
|
|
245
|
+
logger.info(chalk.yellow('with a valid wrangler.toml file.'));
|
|
281
246
|
process.exit(1);
|
|
282
247
|
}
|
|
283
|
-
|
|
248
|
+
|
|
284
249
|
const { config, projectPath } = wranglerResult;
|
|
285
|
-
|
|
286
250
|
if (!config.d1_databases?.length) {
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
251
|
+
logger.error(chalk.red('\nError: No D1 databases configured in wrangler.toml'));
|
|
252
|
+
logger.info(chalk.yellow('\nAdd D1 configuration to your wrangler.toml:'));
|
|
253
|
+
logger.info(chalk.gray(`
|
|
290
254
|
[[d1_databases]]
|
|
291
255
|
binding = "DB"
|
|
292
256
|
database_name = "my-database"
|
|
@@ -294,11 +258,10 @@ async function startStudio() {
|
|
|
294
258
|
`));
|
|
295
259
|
process.exit(1);
|
|
296
260
|
}
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
console.log(chalk.green('\nFound D1 databases:'));
|
|
261
|
+
|
|
262
|
+
logger.info(chalk.green('\nFound D1 databases:'));
|
|
300
263
|
config.d1_databases.forEach((db) => {
|
|
301
|
-
|
|
264
|
+
logger.info(chalk.blue(` - ${db.database_name} (${db.binding})`));
|
|
302
265
|
});
|
|
303
266
|
|
|
304
267
|
const port = 4000;
|
|
@@ -306,7 +269,7 @@ async function startStudio() {
|
|
|
306
269
|
|
|
307
270
|
await startServer(port, projectPath);
|
|
308
271
|
|
|
309
|
-
|
|
272
|
+
logger.info(chalk.green(`
|
|
310
273
|
┌─────────────────────────────────────────┐
|
|
311
274
|
│ │
|
|
312
275
|
│ D1 Studio is running on port ${port} │
|
|
@@ -316,50 +279,42 @@ async function startStudio() {
|
|
|
316
279
|
└─────────────────────────────────────────┘
|
|
317
280
|
`));
|
|
318
281
|
|
|
319
|
-
// Add delay before opening browser
|
|
320
282
|
await new Promise(resolve => setTimeout(resolve, 2000));
|
|
321
283
|
|
|
322
284
|
try {
|
|
323
285
|
await open(url, {
|
|
324
286
|
wait: false,
|
|
325
287
|
url: true,
|
|
326
|
-
app: {
|
|
327
|
-
name: open.apps.chrome
|
|
328
|
-
}
|
|
288
|
+
app: { name: open.apps.chrome }
|
|
329
289
|
}).catch(() => {
|
|
330
|
-
return open(url, {
|
|
331
|
-
wait: false,
|
|
332
|
-
url: true
|
|
333
|
-
});
|
|
290
|
+
return open(url, { wait: false, url: true });
|
|
334
291
|
});
|
|
335
292
|
} catch (browserError) {
|
|
336
|
-
|
|
337
|
-
|
|
293
|
+
logger.info(chalk.yellow('\nCould not automatically open browser.'));
|
|
294
|
+
logger.info(chalk.blue(`Please open your browser and navigate to: ${url}`));
|
|
338
295
|
}
|
|
339
|
-
|
|
340
296
|
} catch (configError) {
|
|
341
|
-
|
|
297
|
+
logger.error(chalk.red(`\nConfiguration error: ${configError.message}`));
|
|
342
298
|
process.exit(1);
|
|
343
299
|
}
|
|
344
|
-
|
|
345
300
|
} catch (error) {
|
|
346
|
-
|
|
301
|
+
logger.error(chalk.red(`\nFailed to start D1 Studio: ${error}`));
|
|
347
302
|
process.exit(1);
|
|
348
303
|
}
|
|
349
304
|
}
|
|
350
305
|
|
|
351
306
|
// Handle termination
|
|
352
307
|
process.on('SIGINT', () => {
|
|
353
|
-
|
|
308
|
+
logger.info(chalk.yellow('\nShutting down D1 Studio...'));
|
|
354
309
|
process.exit(0);
|
|
355
310
|
});
|
|
356
311
|
|
|
357
312
|
process.on('SIGTERM', () => {
|
|
358
|
-
|
|
313
|
+
logger.info(chalk.yellow('\nShutting down D1 Studio...'));
|
|
359
314
|
process.exit(0);
|
|
360
315
|
});
|
|
361
316
|
|
|
362
317
|
startStudio().catch((error) => {
|
|
363
|
-
|
|
318
|
+
logger.error(chalk.red(`\nFailed to start D1 Studio: ${error}`));
|
|
364
319
|
process.exit(1);
|
|
365
320
|
});
|
|
@@ -3,7 +3,7 @@ import { readFile } from 'fs/promises';
|
|
|
3
3
|
import { findUp } from 'find-up';
|
|
4
4
|
import { parse as parseToml } from '@iarna/toml';
|
|
5
5
|
import stripJsonComments from 'strip-json-comments';
|
|
6
|
-
import
|
|
6
|
+
import logger from './logger.js';
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* Finds and parses the Wrangler configuration file.
|
|
@@ -17,14 +17,15 @@ export async function findWranglerConfig(userProjectPath) {
|
|
|
17
17
|
throw new Error('Project path is required and must be a string');
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
|
|
20
|
+
// Uncomment the following line to log the search path if needed:
|
|
21
|
+
// logger.debug(`Looking for wrangler configuration in: ${userProjectPath}`);
|
|
21
22
|
|
|
22
23
|
// Define the possible configuration file names in priority order.
|
|
23
24
|
const possibleFiles = ['wrangler.toml', 'wrangler.json', 'wrangler.jsonc'];
|
|
24
25
|
let configPath = null;
|
|
25
26
|
let configFileUsed = null;
|
|
26
27
|
|
|
27
|
-
// Search for any of the possible config files
|
|
28
|
+
// Search for any of the possible config files.
|
|
28
29
|
for (const file of possibleFiles) {
|
|
29
30
|
configPath = await findUp(file, { cwd: userProjectPath });
|
|
30
31
|
if (configPath) {
|
|
@@ -34,21 +35,21 @@ export async function findWranglerConfig(userProjectPath) {
|
|
|
34
35
|
}
|
|
35
36
|
|
|
36
37
|
if (!configPath) {
|
|
37
|
-
|
|
38
|
+
logger.warn(`No Wrangler configuration file found in: ${userProjectPath}`);
|
|
38
39
|
return null;
|
|
39
40
|
}
|
|
40
41
|
|
|
41
|
-
|
|
42
|
+
logger.info(`Found ${configFileUsed} at: ${configPath}`);
|
|
42
43
|
|
|
43
|
-
// Read the configuration file
|
|
44
|
+
// Read the configuration file.
|
|
44
45
|
let configContent = await readFile(configPath, 'utf-8');
|
|
45
46
|
let config;
|
|
46
47
|
|
|
47
|
-
// Parse based on file type
|
|
48
|
+
// Parse based on file type.
|
|
48
49
|
if (configFileUsed.endsWith('.toml')) {
|
|
49
50
|
config = parseToml(configContent);
|
|
50
51
|
} else {
|
|
51
|
-
// If it's JSONC, strip comments before parsing
|
|
52
|
+
// If it's JSONC, strip comments before parsing.
|
|
52
53
|
if (configFileUsed.endsWith('.jsonc')) {
|
|
53
54
|
configContent = stripJsonComments(configContent);
|
|
54
55
|
}
|
|
@@ -61,7 +62,7 @@ export async function findWranglerConfig(userProjectPath) {
|
|
|
61
62
|
};
|
|
62
63
|
|
|
63
64
|
} catch (error) {
|
|
64
|
-
|
|
65
|
+
logger.error(`Error reading Wrangler configuration: ${error.message}`);
|
|
65
66
|
throw error;
|
|
66
67
|
}
|
|
67
68
|
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import winston from 'winston';
|
|
2
|
+
|
|
3
|
+
const { combine, timestamp, printf, colorize } = winston.format;
|
|
4
|
+
|
|
5
|
+
const logFormat = printf(({ level, message, timestamp }) => {
|
|
6
|
+
return `${timestamp} ${level}: ${message}`;
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
const logger = winston.createLogger({
|
|
10
|
+
level: process.env.NODE_ENV === 'development' ? 'debug' : 'info',
|
|
11
|
+
format: combine(
|
|
12
|
+
timestamp({ format: 'YYYY-MM-DD HH:mm:ss' }),
|
|
13
|
+
colorize(),
|
|
14
|
+
logFormat
|
|
15
|
+
),
|
|
16
|
+
transports: [new winston.transports.Console()]
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
export default logger;
|