MCPcopy Create free account
hub / github.com/vercel/vercel / init

Function init

packages/cli/src/commands/init/init.ts:32–89  ·  view source on GitHub ↗
(
  client: Client,
  opts: Partial<Options>,
  args: string[],
  telemetry: InitTelemetryClient
)

Source from the content-addressed store, hash-verified

30const EXAMPLE_API = 'https://examples.vercel.sh';
31
32export default async function init(
33 client: Client,
34 opts: Partial<Options>,
35 args: string[],
36 telemetry: InitTelemetryClient
37) {
38 const [name, dir] = args;
39 const force = opts['--force'];
40
41 const examples = await fetchExampleList(client);
42
43 if (!examples) {
44 throw new Error('Could not fetch example list.');
45 }
46
47 const exampleList = examples.filter(x => x.visible).map(x => x.name);
48
49 if (!name) {
50 if (client.stdin.isTTY !== true) {
51 output.print('No framework provided');
52 return 0;
53 }
54 const chosen = await chooseFromDropdown(
55 client,
56 'Select example:',
57 exampleList
58 );
59
60 if (!chosen) {
61 output.log('Canceled');
62 return 0;
63 }
64
65 return extractExample(client, chosen, dir, force);
66 }
67
68 if (exampleList.includes(name)) {
69 telemetry.trackCliArgumentExample(name, true);
70 return extractExample(client, name, dir, force);
71 }
72
73 const oldExample = examples.find(x => !x.visible && x.name === name);
74 if (oldExample) {
75 telemetry.trackCliArgumentExample(name, true);
76 return extractExample(client, name, dir, force, 'v1');
77 }
78
79 telemetry.trackCliArgumentExample(name, false);
80
81 const found = await guess(client, exampleList, name);
82
83 if (typeof found === 'string') {
84 return extractExample(client, found, dir, force);
85 }
86
87 output.log('No changes made.');
88 return 0;
89}

Callers 2

mainFunction · 0.70
index.test.tsFile · 0.50

Calls 9

fetchExampleListFunction · 0.85
chooseFromDropdownFunction · 0.85
extractExampleFunction · 0.85
guessFunction · 0.85
filterMethod · 0.80
printMethod · 0.80
logMethod · 0.45
findMethod · 0.45

Tested by

no test coverage detected