( client: Client, opts: Partial<Options>, args: string[], telemetry: InitTelemetryClient )
| 30 | const EXAMPLE_API = 'https://examples.vercel.sh'; |
| 31 | |
| 32 | export 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 | } |
no test coverage detected