Skip to content

Commit af74cd9

Browse files
feat(cli): add provider flag to hosting config prompt
closes #234
1 parent edd717d commit af74cd9

File tree

3 files changed

+31
-11
lines changed

3 files changed

+31
-11
lines changed

packages/cli/src/commands/create/generate-hosting-config.ts

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,34 @@ import * as prompts from '@clack/prompts';
44
import chalk from 'chalk';
55
import { warnLabel } from 'src/utils/messages.js';
66
import { runTask } from 'src/utils/tasks.js';
7+
import { DEFAULT_VALUES, readFlag } from './options.js';
78
import cloudflareConfigRaw from './hosting-config/_headers.txt?raw';
89
import netlifyConfigRaw from './hosting-config/netlify_toml.txt?raw';
910
import vercelConfigRaw from './hosting-config/vercel.json?raw';
1011

11-
export async function generateHostingConfig(dest: string, provider: string, flags: { dryRun: boolean }) {
12+
export async function generateHostingConfig(dest: string, flags: { dryRun: boolean, provider?: string }) {
13+
let provider = readFlag(flags, 'provider' as any);
14+
15+
if (provider === undefined) {
16+
provider = await prompts.select({
17+
message: 'Select hosting providers for automatic configuration:',
18+
options: [
19+
{ value: 'Vercel', label: 'Vercel' },
20+
{ value: 'Netlify', label: 'Netlify' },
21+
{ value: 'Cloudflare', label: 'Cloudflare' },
22+
{ value: 'skip', label: 'Skip hosting configuration' },
23+
],
24+
initialValue: DEFAULT_VALUES.provider,
25+
});
26+
}
27+
28+
if (provider === 'skip') {
29+
prompts.log.message(
30+
`${chalk.blue('hosting provider config [skip]')} You can configure hosting provider settings manually later. For more information see https://tutorialkit.dev/guides/deployment/#headers-configuration`,
31+
);
32+
return;
33+
}
34+
1235
prompts.log.info(`${chalk.blue('Hosting Configuration')} Setting up configuration for ${provider}`);
1336

1437
const resolvedDest = path.resolve(dest);
@@ -43,9 +66,5 @@ export async function generateHostingConfig(dest: string, provider: string, flag
4366
return `Added ${filepath}`;
4467
},
4568
});
46-
} else {
47-
prompts.log.message(
48-
`${chalk.blue('hosting provider config [skip]')} You can configure hosting provider settings manually later. For more information see https://tutorialkit.dev/guides/deployment/#headers-configuration`,
49-
);
5069
}
5170
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export async function createTutorial(flags: yargs.Arguments) {
3030
['--install, --no-install', `Install dependencies (default ${chalk.yellow(DEFAULT_VALUES.install)})`],
3131
['--start, --no-start', `Start project (default ${chalk.yellow(DEFAULT_VALUES.start)})`],
3232
['--git, --no-git', `Initialize a local git repository (default ${chalk.yellow(DEFAULT_VALUES.git)})`],
33+
['--provider <name>, --no-provider', `Select a hosting provider (default ${chalk.yellow(DEFAULT_VALUES.provider)})`],
3334
['--dry-run', `Walk through steps without executing (default ${chalk.yellow(DEFAULT_VALUES.dryRun)})`],
3435
[
3536
'--package-manager <name>, -p <name>',
@@ -155,7 +156,7 @@ async function _createTutorial(flags: CreateOptions): Promise<undefined> {
155156
initialValue: 'Vercel',
156157
});
157158

158-
await generateHostingConfig(resolvedDest, String(provider), { dryRun: flags.dryRun });
159+
await generateHostingConfig(resolvedDest, { dryRun: flags.dryRun, provider: String(provider) });
159160

160161
updatePackageJson(resolvedDest, tutorialName, flags, String(provider));
161162

packages/cli/tests/create-tutorial.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ test('cannot create project without installing but with starting', async (contex
3030
const name = context.task.id;
3131

3232
await expect(
33-
execa('node', [cli, 'create', name, '--no-install', '--start'], {
33+
execa('node', [cli, 'create', name, '--no-install', '--no-provider', '--start'], {
3434
cwd: tmpDir,
3535
}),
3636
).rejects.toThrow('Cannot start project without installing dependencies.');
@@ -40,7 +40,7 @@ test('create a project', async (context) => {
4040
const name = context.task.id;
4141
const dest = path.join(tmpDir, name);
4242

43-
await execa('node', [cli, 'create', name, '--no-install', '--no-git', '--defaults'], {
43+
await execa('node', [cli, 'create', name, '--no-install', '--no-git', '--no-provider', '--defaults'], {
4444
cwd: tmpDir,
4545
});
4646

@@ -53,7 +53,7 @@ test('create and build a project', async (context) => {
5353
const name = context.task.id;
5454
const dest = path.join(tmpDir, name);
5555

56-
await execa('node', [cli, 'create', name, '--no-git', '--no-install', '--no-start', '--defaults'], {
56+
await execa('node', [cli, 'create', name, '--no-git', '--no-install', '--no-start', '--no-provider', '--defaults'], {
5757
cwd: tmpDir,
5858
});
5959

@@ -89,7 +89,7 @@ test('create and eject a project', async (context) => {
8989
const name = context.task.id;
9090
const dest = path.join(tmpDir, name);
9191

92-
await execa('node', [cli, 'create', name, '--no-git', '--no-install', '--no-start', '--defaults'], {
92+
await execa('node', [cli, 'create', name, '--no-git', '--no-install', '--no-start', '--no-provider', '--defaults'], {
9393
cwd: tmpDir,
9494
});
9595

@@ -117,7 +117,7 @@ test('create, eject and build a project', async (context) => {
117117
const name = context.task.id;
118118
const dest = path.join(tmpDir, name);
119119

120-
await execa('node', [cli, 'create', name, '--no-git', '--no-install', '--no-start', '--defaults'], {
120+
await execa('node', [cli, 'create', name, '--no-git', '--no-install', '--no-start', '--no-provider', '--defaults'], {
121121
cwd: tmpDir,
122122
});
123123

0 commit comments

Comments
 (0)