Skip to content

Commit 986ec67

Browse files
feat(wizard): restrict hosting provider selection to a single option
Adjusted the project scaffolding wizard to allow users to select only one hosting provider at a time, laying the groundwork for improved deployment configuration. Related to #234
1 parent 2c062e9 commit 986ec67

File tree

8 files changed

+129
-64
lines changed

8 files changed

+129
-64
lines changed

packages/cli/curly-sun/vercel.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"headers": [
3+
{
4+
"source": "/(.*)",
5+
"headers": [
6+
{
7+
"key": "Cross-Origin-Embedder-Policy",
8+
"value": "require-crop"
9+
},
10+
{
11+
"key": "Cross-Origin-Embedder-Policy",
12+
"value": "same-origin"
13+
}
14+
]
15+
}
16+
]
17+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"headers": [
3+
{
4+
"source": "/(.*)",
5+
"headers": [
6+
{
7+
"key": "Cross-Origin-Embedder-Policy",
8+
"value": "require-crop"
9+
},
10+
{
11+
"key": "Cross-Origin-Embedder-Policy",
12+
"value": "same-origin"
13+
}
14+
]
15+
}
16+
]
17+
}
Lines changed: 72 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,79 @@
1-
/* eslint-disable prettier/prettier */
21
import fs from 'node:fs';
32
import path from 'node:path';
4-
import cloudflareConfigFile from './hosting-config/_headers?raw';
5-
import netlifyConfigFile from './hosting-config/netlify.toml?raw';
6-
import vercelConfigFile from './hosting-config/vercel.json?raw';
7-
8-
export async function generateHostingConfig(dest: string, providers: string[]) {
9-
const resolvedDest = path.resolve(dest);
10-
11-
if (!fs.existsSync(resolvedDest)) {
12-
console.log(`Directory does not exist. Creating directory: ${resolvedDest}`);
13-
fs.mkdirSync(resolvedDest, { recursive: true });
14-
} else {
15-
console.log(`Directory already exists: ${resolvedDest}`);
16-
}
17-
18-
if (providers.includes('Vercel')) {
19-
const vercelConfigPath = path.join(resolvedDest, 'vercel.json');
20-
console.log('Writing Vercel config file to:', vercelConfigPath);
21-
fs.writeFileSync(vercelConfigPath, vercelConfigFile);
22-
}
23-
24-
if (providers.includes('Netlify')) {
25-
const netlifyConfigPath = path.join(resolvedDest, 'netlify.toml');
26-
console.log('Writing Netlify config file to:', netlifyConfigPath);
27-
fs.writeFileSync(netlifyConfigPath, netlifyConfigFile);
3+
import { fileURLToPath } from 'node:url';
4+
import cloudflareConfigRaw from './hosting-config/_headers.txt?raw';
5+
import netlifyConfigRaw from './hosting-config/netlify_toml.txt?raw';
6+
import vercelConfigRaw from './hosting-config/vercel.json?raw';
7+
8+
const __filename = fileURLToPath(import.meta.url);
9+
const __dirname = path.dirname(__filename);
10+
11+
export async function generateHostingConfig(dest: string, provider: string) {
12+
const resolvedDest = path.resolve(dest);
13+
14+
if (!fs.existsSync(resolvedDest)) {
15+
console.log(`Directory does not exist. Creating directory: ${resolvedDest}`);
16+
fs.mkdirSync(resolvedDest, { recursive: true });
17+
} else {
18+
console.log(`Directory already exists: ${resolvedDest}`);
19+
}
20+
21+
if (provider.includes('Vercel')) {
22+
const vercelConfigPath = path.join(resolvedDest, 'vercel.json');
23+
console.log('Writing Vercel config file to:', vercelConfigPath);
24+
25+
try {
26+
const vercelConfig = typeof vercelConfigRaw === 'string' ? JSON.parse(vercelConfigRaw) : vercelConfigRaw;
27+
fs.writeFileSync(vercelConfigPath, JSON.stringify(vercelConfig, null, 2));
28+
} catch (error) {
29+
console.error('Failed to write Vercel config file:', error);
2830
}
29-
30-
if (providers.includes('Cloudflare')) {
31-
const cloudflareConfigPath = path.join(resolvedDest, '_headers');
32-
console.log('Writing Cloudflare config file to:', cloudflareConfigPath);
33-
fs.writeFileSync(cloudflareConfigPath, cloudflareConfigFile);
31+
}
32+
33+
if (provider.includes('Netlify')) {
34+
const netlifyConfigPath = path.join(resolvedDest, 'netlify.toml');
35+
console.log('Writing Netlify config file to:', netlifyConfigPath);
36+
37+
try {
38+
if (typeof netlifyConfigRaw !== 'string') {
39+
throw new Error('Netlify config must be a string.');
40+
}
41+
42+
fs.writeFileSync(netlifyConfigPath, netlifyConfigRaw);
43+
} catch (error) {
44+
console.error('Failed to write Netlify config file:', error);
3445
}
35-
36-
const templateDir = path.resolve(__dirname, '_template');
37-
console.log('Looking for template directory at:', templateDir);
38-
39-
if (fs.existsSync(templateDir)) {
40-
const gitignoreTemplatePath = path.join(templateDir, '.gitignore');
41-
42-
if (fs.existsSync(gitignoreTemplatePath)) {
43-
const gitignoreDestPath = path.join(resolvedDest, '.gitignore');
44-
console.log('Copying .gitignore to:', gitignoreDestPath);
45-
fs.copyFileSync(gitignoreTemplatePath, gitignoreDestPath);
46-
} else {
47-
console.warn('No .gitignore file found in template directory, skipping copy.');
46+
}
47+
48+
if (provider.includes('Cloudflare')) {
49+
const cloudflareConfigPath = path.join(resolvedDest, '_headers');
50+
console.log('Writing Cloudflare config file to:', cloudflareConfigPath);
51+
52+
try {
53+
if (typeof cloudflareConfigRaw !== 'string') {
54+
throw new Error('Cloudflare config must be a string.');
4855
}
56+
57+
fs.writeFileSync(cloudflareConfigPath, cloudflareConfigRaw);
58+
} catch (error) {
59+
console.error('Failed to write Cloudflare config file:', error);
60+
}
61+
}
62+
63+
const templateDir = path.resolve(__dirname, '_template');
64+
console.log('Looking for template directory at:', templateDir);
65+
66+
if (fs.existsSync(templateDir)) {
67+
const gitignoreTemplatePath = path.join(templateDir, '.gitignore');
68+
69+
if (fs.existsSync(gitignoreTemplatePath)) {
70+
const gitignoreDestPath = path.join(resolvedDest, '.gitignore');
71+
console.log('Copying .gitignore to:', gitignoreDestPath);
72+
fs.copyFileSync(gitignoreTemplatePath, gitignoreDestPath);
4973
} else {
50-
console.warn('Template directory does not exist, skipping .gitignore copy.');
74+
console.warn('No .gitignore file found in template directory, skipping copy.');
5175
}
52-
}
76+
} else {
77+
console.warn('Template directory does not exist, skipping .gitignore copy.');
78+
}
79+
}

packages/cli/src/commands/create/index.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -108,20 +108,20 @@ async function _createTutorial(flags: CreateOptions): Promise<undefined> {
108108
const dest = await getTutorialDirectory(tutorialName, flags);
109109
const resolvedDest = path.resolve(process.cwd(), dest);
110110

111-
const providers = await prompts.multiselect({
112-
message: 'Select hosting providers for automatic configuration (use space to select):',
111+
const provider = await prompts.select({
112+
message: 'Select hosting providers for automatic configuration:',
113113
options: [
114114
{ value: 'Vercel', label: 'Vercel' },
115115
{ value: 'Netlify', label: 'Netlify' },
116116
{ value: 'Cloudflare', label: 'Cloudflare' },
117117
],
118-
initialValues: [],
118+
initialValue: 'Vercel',
119119
});
120120

121-
assertNotCanceled(providers);
122-
prompts.log.info(`Configuring for: ${providers.join(', ')}`);
121+
assertNotCanceled(provider);
122+
prompts.log.info(`Configuring for: ${provider}`);
123123

124-
await generateHostingConfig(resolvedDest, providers);
124+
await generateHostingConfig(resolvedDest, provider);
125125

126126
await copyTemplate(resolvedDest, flags);
127127
updatePackageJson(resolvedDest, tutorialName, flags);

packages/cli/super-math/vercel.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"headers": [
3+
{
4+
"source": "/(.*)",
5+
"headers": [
6+
{
7+
"key": "Cross-Origin-Embedder-Policy",
8+
"value": "require-crop"
9+
},
10+
{
11+
"key": "Cross-Origin-Embedder-Policy",
12+
"value": "same-origin"
13+
}
14+
]
15+
}
16+
]
17+
}

packages/cli/tight-firefly/vercel.json

Lines changed: 0 additions & 13 deletions
This file was deleted.

0 commit comments

Comments
 (0)