Skip to content

Commit 5de42a3

Browse files
Attempted to fix error with locating config files
1 parent ac47667 commit 5de42a3

File tree

2 files changed

+55
-6
lines changed

2 files changed

+55
-6
lines changed

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

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -338,10 +338,30 @@ function verifyFlags(flags: CreateOptions) {
338338
}
339339
}
340340

341-
function generateHostingConfig(dest: string, providers: string[]) {
341+
async function generateHostingConfig(dest: string, providers: string[]) {
342+
const resolvedDest = path.resolve(dest);
343+
344+
if (!fs.existsSync(resolvedDest)) {
345+
console.log(`Directory does not exist. Creating directory: ${resolvedDest}`);
346+
fs.mkdirSync(resolvedDest, { recursive: true });
347+
} else {
348+
console.log(`Directory already exists: ${resolvedDest}`);
349+
}
350+
351+
const templateDir = path.resolve(__dirname, '_template');
352+
console.log('Looking for template directory at:', templateDir);
353+
354+
if (!fs.existsSync(templateDir)) {
355+
console.error('Template directory does not exist at:', templateDir);
356+
} else {
357+
console.log('Template directory found at:', templateDir);
358+
}
359+
342360
if (providers.includes('Vercel')) {
361+
const vercelConfigPath = path.join(resolvedDest, 'vercel.json');
362+
console.log('Vercel config file will be written to:', vercelConfigPath);
343363
fs.writeFileSync(
344-
path.join(dest, 'vercel.json'),
364+
vercelConfigPath,
345365
JSON.stringify(
346366
{
347367
headers: [{ source: '/(.*)', headers: [{ key: 'Access-Control-Allow-Origin', value: '*' }] }],
@@ -353,24 +373,40 @@ function generateHostingConfig(dest: string, providers: string[]) {
353373
}
354374

355375
if (providers.includes('Netlify')) {
376+
const netlifyConfigPath = path.join(resolvedDest, 'netlify.toml');
377+
console.log('Netlify config file will be written to:', netlifyConfigPath);
356378
fs.writeFileSync(
357-
path.join(dest, 'netlify.toml'),
379+
netlifyConfigPath,
358380
`[build]
359381
publish = "build"
360382
command = "npm run build"
361383
362-
[[headers]]
384+
[[headers]]
363385
for = "/*"
364386
[headers.values]
365-
Access-Control-Allow-Origin = "*"`,
387+
Access-Control-Allow-Origin = "*"`,
366388
);
367389
}
368390

369391
if (providers.includes('Cloudflare')) {
392+
const cloudflareConfigPath = path.join(resolvedDest, '_headers');
393+
console.log('Cloudflare config file will be written to:', cloudflareConfigPath);
370394
fs.writeFileSync(
371-
path.join(dest, '_headers'),
395+
cloudflareConfigPath,
372396
`/*
373397
Access-Control-Allow-Origin: *`,
374398
);
375399
}
400+
401+
if (fs.existsSync(templateDir)) {
402+
const gitignoreTemplatePath = path.join(templateDir, '.gitignore');
403+
404+
if (fs.existsSync(gitignoreTemplatePath)) {
405+
const gitignoreDestPath = path.join(resolvedDest, '.gitignore');
406+
console.log('Copying .gitignore to:', gitignoreDestPath);
407+
fs.copyFileSync(gitignoreTemplatePath, gitignoreDestPath);
408+
} else {
409+
console.warn('No .gitignore file found in template directory, skipping copy.');
410+
}
411+
}
376412
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"headers": [
3+
{
4+
"source": "/(.*)",
5+
"headers": [
6+
{
7+
"key": "Access-Control-Allow-Origin",
8+
"value": "*"
9+
}
10+
]
11+
}
12+
]
13+
}

0 commit comments

Comments
 (0)