Repository navigation
Expand file tree
/
Copy pathstart.js
More file actions
46 lines (37 loc) · 1.48 KB
/
Copy pathstart.js
File metadata and controls
46 lines (37 loc) · 1.48 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
// @ts-check
const { spawnSync } = require('child_process');
const prompts = require('prompts');
const getAllPackageInfo = require('./monorepo/getAllPackageInfo');
const allPackages = getAllPackageInfo();
const extraArgs = process.argv.slice(2);
const defaults = ['@fluentui/react', '@fluentui/docs', '@fluentui/react-components'];
const projectsWithStartCommand = Object.entries(allPackages)
.reduce((acc, [pkg, info]) => {
if (info.packageJson.scripts && info.packageJson.scripts.start) {
acc.push({ title: pkg, value: { pkg, command: 'start' } });
}
if (info.packageJson.scripts && info.packageJson.scripts['start:profile']) {
acc.push({ title: `${pkg} (profile)`, value: { pkg, command: 'start:profile' } });
}
return acc;
}, [])
.filter(n => n && !defaults.includes(n.title))
.sort((a, b) => (a.title === b.title ? 0 : a.title > b.title ? 1 : -1));
const suggest = (input, choices) => Promise.resolve(choices.filter(i => i.title.includes(input)));
(async () => {
const response = await prompts({
type: 'autocomplete',
name: 'project',
message: 'Which project to start (select or type partial name)?',
suggest,
choices: [...defaults.map(p => ({ title: p, value: { pkg: p, command: 'start' } })), ...projectsWithStartCommand],
});
spawnSync(
'yarn',
['workspace', response.project.pkg, response.project.command, ...(extraArgs.length > 0 ? [extraArgs] : [])],
{
shell: true,
stdio: 'inherit',
},
);
})();