-
Notifications
You must be signed in to change notification settings - Fork 83
feat: add hosting config files #440
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 18 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
ac47667
feat(scaffolding): add hosting config files for common providers
RonithManikonda 5de42a3
Attempted to fix error with locating config files
RonithManikonda 2c062e9
feat(cli): move hosting configuration generation to dedicated file
RonithManikonda 986ec67
feat(wizard): restrict hosting provider selection to a single option
RonithManikonda 686174d
feat(cli): adjusted the order in which files are generated to avoid e…
RonithManikonda b4247e1
deleted tutorials that were made during testing
RonithManikonda 14e3408
Merge branch 'main' into ronith/add-hosting-config-files
AriPerkkio 4df1fc6
fix(cli): add 'skip' option and update defaults for hosting config
RonithManikonda edd717d
chore(prettier): fix formatting errors
RonithManikonda af74cd9
feat(cli): add provider flag to hosting config prompt
RonithManikonda facf7d2
chore(prettier): fix formatting errors
RonithManikonda 7c45e6e
fix(cli): ensure --no-provider skips hosting config prompt
RonithManikonda bbc7ec9
chore(prettier): fix formatting errors
RonithManikonda 13103d9
chore(prettier): fix formatting errors
RonithManikonda 675c5fb
Apply suggestions from code review
RonithManikonda a1771db
test(cli): add tests for Netlify, Cloudflare, and Vercel providers
RonithManikonda 8de3e52
Merge branch 'ronith/add-hosting-config-files' of https://github.com/…
RonithManikonda 8abfb97
test(cli): updated test for Cloudflare to reflect functionality
RonithManikonda 9dcefcb
Update packages/cli/src/commands/create/index.ts
AriPerkkio 97a237d
fix: handle `--no-provider` value
AriPerkkio 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
80 changes: 80 additions & 0 deletions
80
packages/cli/src/commands/create/generate-hosting-config.ts
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 |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import fs from 'node:fs'; | ||
import path from 'node:path'; | ||
import * as prompts from '@clack/prompts'; | ||
import chalk from 'chalk'; | ||
import { warnLabel } from 'src/utils/messages.js'; | ||
import { runTask } from 'src/utils/tasks.js'; | ||
import cloudflareConfigRaw from './hosting-config/_headers.txt?raw'; | ||
import netlifyConfigRaw from './hosting-config/netlify_toml.txt?raw'; | ||
import vercelConfigRaw from './hosting-config/vercel.json?raw'; | ||
import { DEFAULT_VALUES, readFlag, type CreateOptions } from './options.js'; | ||
|
||
export async function generateHostingConfig(dest: string, flags: CreateOptions) { | ||
let provider = readFlag(flags, 'provider'); | ||
|
||
if (provider === undefined) { | ||
provider = (await prompts.select({ | ||
message: 'Select hosting providers for automatic configuration:', | ||
options: [ | ||
{ value: 'Vercel', label: 'Vercel' }, | ||
{ value: 'Netlify', label: 'Netlify' }, | ||
{ value: 'Cloudflare', label: 'Cloudflare' }, | ||
{ value: 'skip', label: 'Skip hosting configuration' }, | ||
], | ||
initialValue: DEFAULT_VALUES.provider, | ||
})) as string; | ||
} | ||
|
||
if (!provider || provider === 'skip') { | ||
prompts.log.message( | ||
`${chalk.blue('hosting provider config [skip]')} You can configure hosting provider settings manually later.`, | ||
); | ||
|
||
return provider; | ||
} | ||
|
||
prompts.log.info(`${chalk.blue('Hosting Configuration')} Setting up configuration for ${provider}`); | ||
|
||
const resolvedDest = path.resolve(dest); | ||
|
||
if (!fs.existsSync(resolvedDest)) { | ||
fs.mkdirSync(resolvedDest, { recursive: true }); | ||
} | ||
|
||
let config: string | undefined; | ||
let filename: string | undefined; | ||
|
||
switch (provider.toLowerCase()) { | ||
case 'vercel': { | ||
config = typeof vercelConfigRaw === 'string' ? vercelConfigRaw : JSON.stringify(vercelConfigRaw, null, 2); | ||
filename = 'vercel.json'; | ||
break; | ||
} | ||
case 'netlify': { | ||
config = netlifyConfigRaw; | ||
filename = 'netlify.toml'; | ||
break; | ||
} | ||
case 'cloudflare': { | ||
config = cloudflareConfigRaw; | ||
filename = '_headers'; | ||
break; | ||
} | ||
} | ||
|
||
if (config && filename) { | ||
await runTask({ | ||
title: `Create hosting files for ${provider}`, | ||
dryRun: flags.dryRun, | ||
dryRunMessage: `${warnLabel('DRY RUN')} Skipped hosting provider config creation`, | ||
task: async () => { | ||
const filepath = path.join(resolvedDest, filename); | ||
fs.writeFileSync(filepath, config); | ||
|
||
return `Added ${filepath}`; | ||
}, | ||
}); | ||
} | ||
|
||
return provider; | ||
} |
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
/* | ||
Cross-Origin-Embedder-Policy: require-corp | ||
Cross-Origin-Opener-Policy: same-origin |
5 changes: 5 additions & 0 deletions
5
packages/cli/src/commands/create/hosting-config/netlify_toml.txt
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
[[headers]] | ||
for = "/*" | ||
[headers.values] | ||
Cross-Origin-Embedder-Policy = "require-corp" | ||
Cross-Origin-Opener-Policy = "same-origin" |
17 changes: 17 additions & 0 deletions
17
packages/cli/src/commands/create/hosting-config/vercel.json
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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"headers": [ | ||
{ | ||
"source": "/(.*)", | ||
"headers": [ | ||
{ | ||
"key": "Cross-Origin-Embedder-Policy", | ||
"value": "require-crop" | ||
}, | ||
{ | ||
"key": "Cross-Origin-Embedder-Policy", | ||
"value": "same-origin" | ||
} | ||
] | ||
} | ||
] | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
declare module '*?raw' { | ||
const content: string; | ||
export default content; | ||
} |
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.