-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathstart.js
More file actions
57 lines (48 loc) · 1.49 KB
/
Copy pathstart.js
File metadata and controls
57 lines (48 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import { readFile } from 'fs/promises';
import { execa } from 'execa';
import { globby } from 'globby';
import prompt from 'prompts';
const jsLibs = ['React', 'Solid', 'Svelte', 'Vue', 'Web Components'];
async function main() {
const jsLibIndex = /** @type {any} */ (
await prompt.prompts.select({
type: 'select',
name: 'lib',
message: 'Pick a JS library',
choices: jsLibs.map((lib) => ({ title: lib })),
})
),
jsLib = jsLibs[jsLibIndex],
jsLibId = jsLib.replace(' ', '-').toLowerCase();
const examples = await globby(`player/${jsLibId}/*/package.json`);
const exampleIndex = /** @type {any} */ (
await prompt.prompts.select({
type: 'select',
name: 'lib',
message: 'Pick an example',
choices: examples.map((example) => ({
title: example
.split('/')[2]
.replace('css', 'CSS')
.split('-')
.filter((c) => c.length)
.map(capitalizeFirstLetter)
.join(' ')
.split('+')
.map(capitalizeFirstLetter)
.join(' + '),
})),
})
),
example = examples[exampleIndex];
const pkg = JSON.parse(await readFile(example, 'utf8'));
await execa('pnpm', ['-F', pkg.name, 'dev'], { stdio: 'inherit' });
}
main().catch((e) => {
if (e.exitCode === 1) return;
console.error(e);
process.exit(1);
});
function capitalizeFirstLetter(string) {
return string.charAt(0).toUpperCase() + string.slice(1);
}