()
| 199 | } |
| 200 | |
| 201 | async function createBucketR2() { |
| 202 | const wranglerTomlPath = path.join(__dirname, "..", "wrangler.toml"); |
| 203 | let wranglerToml: toml.JsonMap; |
| 204 | |
| 205 | try { |
| 206 | const wranglerTomlContent = fs.readFileSync(wranglerTomlPath, "utf-8"); |
| 207 | wranglerToml = toml.parse(wranglerTomlContent); |
| 208 | } catch (error) { |
| 209 | console.error("\x1b[31mError reading wrangler.toml:", error, "\x1b[0m"); |
| 210 | cancel("Operation cancelled."); |
| 211 | } |
| 212 | |
| 213 | const bucketR2Spinner = spinner(); |
| 214 | const defaultBucketName = `${path.basename(process.cwd())}-bucket`; |
| 215 | bucketR2Name = await prompt( |
| 216 | "Enter the name of your bucket", |
| 217 | defaultBucketName, |
| 218 | ); |
| 219 | bucketR2Spinner.start("Creating bucket..."); |
| 220 | executeCommand(`wrangler r2 bucket create ${bucketR2Name}`); |
| 221 | bucketR2Spinner.stop("Bucket created."); |
| 222 | |
| 223 | // Update wrangler.toml with bucket configuration |
| 224 | wranglerToml = { |
| 225 | ...wranglerToml!, |
| 226 | r2_buckets: [ |
| 227 | { |
| 228 | binding: "MY_BUCKET", |
| 229 | bucket_name: bucketR2Name, |
| 230 | }, |
| 231 | ], |
| 232 | }; |
| 233 | |
| 234 | try { |
| 235 | const updatedToml = toml.stringify(wranglerToml); |
| 236 | fs.writeFileSync(wranglerTomlPath, updatedToml); |
| 237 | console.log( |
| 238 | "\x1b[33mBucket configuration updated in wrangler.toml\x1b[0m", |
| 239 | ); |
| 240 | } catch (error) { |
| 241 | console.error("\x1b[31mError updating wrangler.toml:", error, "\x1b[0m"); |
| 242 | cancel("Operation cancelled."); |
| 243 | } |
| 244 | |
| 245 | outro("Bucket configuration completed."); |
| 246 | } |
| 247 | |
| 248 | // Function to prompt for Google client credentials |
| 249 | async function promptForGoogleClientCredentials() { |
nothing calls this directly
no test coverage detected