-
Notifications
You must be signed in to change notification settings - Fork 15
feat: add COOKIE_DOMAIN support for cross-subdomain sharing #9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,55 +9,58 @@ import { parse as parseToml, stringify as stringifyToml } from "smol-toml"; | |
| const __dirname = process.cwd(); | ||
|
|
||
| const config = { | ||
| preview: { | ||
| docs: false, | ||
| override: { | ||
| name: "typix-preview", | ||
| vars: { | ||
| MODE: "client", | ||
| PROVIDER_CLOUDFLARE_BUILTIN: "true", | ||
| }, | ||
| }, | ||
| }, | ||
| production: { | ||
| docs: true, | ||
| override: { | ||
| vars: { | ||
| MODE: "mixed", | ||
| GOOGLE_ANALYTICS_ID: process.env.GOOGLE_ANALYTICS_ID, | ||
| AUTH_EMAIL_VERIFICATION_ENABLED: "true", | ||
| AUTH_EMAIL_RESEND_API_KEY: process.env.AUTH_EMAIL_RESEND_API_KEY, | ||
| AUTH_EMAIL_RESEND_FROM: "Typix <[email protected]>", | ||
| AUTH_SOCIAL_GOOGLE_ENABLED: "true", | ||
| AUTH_SOCIAL_GOOGLE_CLIENT_ID: process.env.AUTH_SOCIAL_GOOGLE_CLIENT_ID, | ||
| AUTH_SOCIAL_GOOGLE_CLIENT_SECRET: process.env.AUTH_SOCIAL_GOOGLE_CLIENT_SECRET, | ||
| AUTH_SOCIAL_GITHUB_ENABLED: "true", | ||
| AUTH_SOCIAL_GITHUB_CLIENT_ID: process.env.AUTH_SOCIAL_GITHUB_CLIENT_ID, | ||
| AUTH_SOCIAL_GITHUB_CLIENT_SECRET: process.env.AUTH_SOCIAL_GITHUB_CLIENT_SECRET, | ||
| PROVIDER_CLOUDFLARE_BUILTIN: "true", | ||
| }, | ||
| }, | ||
| }, | ||
| preview: { | ||
| docs: false, | ||
| override: { | ||
| name: "typix-preview", | ||
| vars: { | ||
| MODE: "client", | ||
| PROVIDER_CLOUDFLARE_BUILTIN: "true", | ||
| }, | ||
| }, | ||
| }, | ||
| production: { | ||
| docs: true, | ||
| override: { | ||
| vars: { | ||
| MODE: "mixed", | ||
| GOOGLE_ANALYTICS_ID: process.env.GOOGLE_ANALYTICS_ID, | ||
| AUTH_EMAIL_VERIFICATION_ENABLED: "true", | ||
| AUTH_EMAIL_RESEND_API_KEY: process.env.AUTH_EMAIL_RESEND_API_KEY, | ||
| AUTH_EMAIL_RESEND_FROM: "Typix <[email protected]>", | ||
| AUTH_SOCIAL_GOOGLE_ENABLED: "true", | ||
| AUTH_SOCIAL_GOOGLE_CLIENT_ID: process.env.AUTH_SOCIAL_GOOGLE_CLIENT_ID, | ||
| AUTH_SOCIAL_GOOGLE_CLIENT_SECRET: | ||
| process.env.AUTH_SOCIAL_GOOGLE_CLIENT_SECRET, | ||
| AUTH_SOCIAL_GITHUB_ENABLED: "true", | ||
| AUTH_SOCIAL_GITHUB_CLIENT_ID: process.env.AUTH_SOCIAL_GITHUB_CLIENT_ID, | ||
| AUTH_SOCIAL_GITHUB_CLIENT_SECRET: | ||
| process.env.AUTH_SOCIAL_GITHUB_CLIENT_SECRET, | ||
| COOKIE_DOMAIN: process.env.COOKIE_DOMAIN, | ||
| PROVIDER_CLOUDFLARE_BUILTIN: "true", | ||
| }, | ||
| }, | ||
| }, | ||
| }; | ||
|
|
||
| /** | ||
| * Read wrangler.toml file | ||
| * @returns {any} Parsed TOML configuration object | ||
| */ | ||
| function readWranglerConfig() { | ||
| const wranglerPath = path.join(__dirname, "wrangler.toml"); | ||
| const content = fs.readFileSync(wranglerPath, "utf8"); | ||
| return parseToml(content); | ||
| const wranglerPath = path.join(__dirname, "wrangler.toml"); | ||
| const content = fs.readFileSync(wranglerPath, "utf8"); | ||
| return parseToml(content); | ||
| } | ||
|
|
||
| /** | ||
| * Write wrangler.toml file | ||
| * @param {any} config - Configuration object | ||
| */ | ||
| function writeWranglerConfig(config) { | ||
| const wranglerPath = path.join(__dirname, "wrangler.toml"); | ||
| const content = stringifyToml(config); | ||
| fs.writeFileSync(wranglerPath, content, "utf8"); | ||
| const wranglerPath = path.join(__dirname, "wrangler.toml"); | ||
| const content = stringifyToml(config); | ||
| fs.writeFileSync(wranglerPath, content, "utf8"); | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -67,17 +70,21 @@ function writeWranglerConfig(config) { | |
| * @returns {any} Merged object | ||
| */ | ||
| function deepMerge(target, source) { | ||
| const result = { ...target }; | ||
|
|
||
| for (const key in source) { | ||
| if (source[key] && typeof source[key] === "object" && !Array.isArray(source[key])) { | ||
| result[key] = deepMerge(result[key] || {}, source[key]); | ||
| } else { | ||
| result[key] = source[key]; | ||
| } | ||
| } | ||
|
|
||
| return result; | ||
| const result = { ...target }; | ||
|
|
||
| for (const key in source) { | ||
| if ( | ||
| source[key] && | ||
| typeof source[key] === "object" && | ||
| !Array.isArray(source[key]) | ||
| ) { | ||
| result[key] = deepMerge(result[key] || {}, source[key]); | ||
| } else { | ||
| result[key] = source[key]; | ||
| } | ||
| } | ||
|
|
||
| return result; | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -86,114 +93,124 @@ function deepMerge(target, source) { | |
| * @param {any} baseConfig - Base configuration copy | ||
| */ | ||
| function updateWranglerConfig(override, baseConfig) { | ||
| const updatedConfig = deepMerge(baseConfig, override); | ||
| writeWranglerConfig(updatedConfig); | ||
| const updatedConfig = deepMerge(baseConfig, override); | ||
| writeWranglerConfig(updatedConfig); | ||
| } | ||
|
|
||
| /** | ||
| * Build and deploy | ||
| */ | ||
| function buildAndDeploy(config) { | ||
| console.log("📦 Building application..."); | ||
| execSync("npm run build", { stdio: "inherit" }); | ||
| console.log("✅ Application built successfully"); | ||
|
|
||
| if (config.docs) { | ||
| console.log("📚 Building documentation..."); | ||
| execSync("cd ./docs && npm install && npm run build && cp -r ./out/ ../dist/home && cd ..", { stdio: "inherit" }); | ||
| console.log("✅ Documentation built successfully"); | ||
| } | ||
|
|
||
| console.log("🚀 Deploying to Cloudflare..."); | ||
| if (config.override.vars.MODE === "client") { | ||
| execSync("npm run deploy:no-migrate", { stdio: "inherit" }); | ||
| } else { | ||
| execSync("npm run deploy", { stdio: "inherit" }); | ||
| } | ||
| console.log("✅ Deployed successfully"); | ||
| console.log("📦 Building application..."); | ||
| execSync("npm run build", { stdio: "inherit" }); | ||
| console.log("✅ Application built successfully"); | ||
|
|
||
| if (config.docs) { | ||
| console.log("📚 Building documentation..."); | ||
| execSync( | ||
| "cd ./docs && npm install && npm run build && cp -r ./out/ ../dist/home && cd ..", | ||
| { stdio: "inherit" } | ||
| ); | ||
| console.log("✅ Documentation built successfully"); | ||
| } | ||
|
|
||
| console.log("🚀 Deploying to Cloudflare..."); | ||
| if (config.override.vars.MODE === "client") { | ||
| execSync("npm run deploy:no-migrate", { stdio: "inherit" }); | ||
| } else { | ||
| execSync("npm run deploy", { stdio: "inherit" }); | ||
| } | ||
| console.log("✅ Deployed successfully"); | ||
| } | ||
|
|
||
| /** | ||
| * Deploy multiple environments | ||
| * @param {string[]} environments - Environment list | ||
| */ | ||
| function deployEnvironments(environments) { | ||
| console.log(`🔄 Starting deployment for environments: ${environments.join(", ")}`); | ||
|
|
||
| // Read original configuration as a copy | ||
| const baseConfig = readWranglerConfig(); | ||
| console.log("📋 Base configuration loaded"); | ||
|
|
||
| for (const environment of environments) { | ||
| console.log(`\n--- Deploying ${environment} environment ---`); | ||
| const envConfig = config[environment]; | ||
| try { | ||
| updateWranglerConfig(envConfig.override, baseConfig); | ||
| buildAndDeploy(envConfig); | ||
| } catch (error) { | ||
| console.error( | ||
| `❌ Failed to deploy ${environment} environment:`, | ||
| error instanceof Error ? error.message : String(error), | ||
| ); | ||
| process.exit(1); | ||
| } | ||
| } | ||
|
|
||
| console.log(`\n🎉 All environments (${environments.join(", ")}) deployed successfully!`); | ||
| console.log( | ||
| `🔄 Starting deployment for environments: ${environments.join(", ")}` | ||
| ); | ||
|
|
||
| // Read original configuration as a copy | ||
| const baseConfig = readWranglerConfig(); | ||
| console.log("📋 Base configuration loaded"); | ||
|
|
||
| for (const environment of environments) { | ||
| console.log(`\n--- Deploying ${environment} environment ---`); | ||
| const envConfig = config[environment]; | ||
| try { | ||
| updateWranglerConfig(envConfig.override, baseConfig); | ||
| buildAndDeploy(envConfig); | ||
| } catch (error) { | ||
| console.error( | ||
| `❌ Failed to deploy ${environment} environment:`, | ||
| error instanceof Error ? error.message : String(error) | ||
| ); | ||
| process.exit(1); | ||
| } | ||
| } | ||
|
|
||
| console.log( | ||
| `\n🎉 All environments (${environments.join(", ")}) deployed successfully!` | ||
| ); | ||
| } | ||
|
|
||
| // Command line interface | ||
| function main() { | ||
| try { | ||
| const { values } = parseArgs({ | ||
| options: { | ||
| preview: { | ||
| type: "boolean", | ||
| short: "p", | ||
| default: false, | ||
| }, | ||
| production: { | ||
| type: "boolean", | ||
| short: "P", | ||
| default: false, | ||
| }, | ||
| help: { | ||
| type: "boolean", | ||
| short: "h", | ||
| default: false, | ||
| }, | ||
| }, | ||
| allowPositionals: false, | ||
| }); | ||
|
|
||
| const environments = []; | ||
|
|
||
| if (values.preview) { | ||
| environments.push("preview"); | ||
| } | ||
|
|
||
| if (values.production) { | ||
| environments.push("production"); | ||
| } | ||
|
|
||
| if (environments.length === 0) { | ||
| environments.push("production"); | ||
| } | ||
|
|
||
| for (const env of environments) { | ||
| if (!(env in config)) { | ||
| console.error(`❌ Unknown environment: ${env}`); | ||
| console.log("Available environments: production, preview"); | ||
| process.exit(1); | ||
| } | ||
| } | ||
|
|
||
| deployEnvironments(environments); | ||
| } catch (error) { | ||
| console.error("❌ Error parsing arguments:", error instanceof Error ? error.message : String(error)); | ||
| console.log("Use --help for usage information"); | ||
| process.exit(1); | ||
| } | ||
| try { | ||
| const { values } = parseArgs({ | ||
| options: { | ||
| preview: { | ||
| type: "boolean", | ||
| short: "p", | ||
| default: false, | ||
| }, | ||
| production: { | ||
| type: "boolean", | ||
| short: "P", | ||
| default: false, | ||
| }, | ||
| help: { | ||
| type: "boolean", | ||
| short: "h", | ||
| default: false, | ||
| }, | ||
| }, | ||
| allowPositionals: false, | ||
| }); | ||
|
|
||
| const environments = []; | ||
|
|
||
| if (values.preview) { | ||
| environments.push("preview"); | ||
| } | ||
|
|
||
| if (values.production) { | ||
| environments.push("production"); | ||
| } | ||
|
|
||
| if (environments.length === 0) { | ||
| environments.push("production"); | ||
| } | ||
|
|
||
| for (const env of environments) { | ||
| if (!(env in config)) { | ||
| console.error(`❌ Unknown environment: ${env}`); | ||
| console.log("Available environments: production, preview"); | ||
| process.exit(1); | ||
| } | ||
| } | ||
|
|
||
| deployEnvironments(environments); | ||
| } catch (error) { | ||
| console.error( | ||
| "❌ Error parsing arguments:", | ||
| error instanceof Error ? error.message : String(error) | ||
| ); | ||
| console.log("Use --help for usage information"); | ||
| process.exit(1); | ||
| } | ||
| } | ||
|
|
||
| main(); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.