2023-02-06 11:21:48 -05:00
|
|
|
import type { Context } from './context';
|
2023-02-06 11:19:37 -05:00
|
|
|
|
|
|
|
import { execa } from 'execa';
|
2023-02-06 11:21:48 -05:00
|
|
|
import { info, spinner, title } from '../messages.js';
|
2023-02-06 11:19:37 -05:00
|
|
|
|
2023-02-06 11:21:48 -05:00
|
|
|
export async function dependencies(
|
|
|
|
ctx: Pick<Context, 'install' | 'yes' | 'prompt' | 'pkgManager' | 'cwd' | 'dryRun'>
|
|
|
|
) {
|
2023-02-06 11:19:37 -05:00
|
|
|
let deps = ctx.install ?? ctx.yes;
|
|
|
|
if (deps === undefined) {
|
|
|
|
({ deps } = await ctx.prompt({
|
|
|
|
name: 'deps',
|
|
|
|
type: 'confirm',
|
|
|
|
label: title('deps'),
|
|
|
|
message: `Install dependencies?`,
|
|
|
|
hint: 'recommended',
|
|
|
|
initial: true,
|
|
|
|
}));
|
|
|
|
ctx.install = deps;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ctx.dryRun) {
|
|
|
|
await info('--dry-run', `Skipping dependency installation`);
|
|
|
|
} else if (deps) {
|
|
|
|
await spinner({
|
|
|
|
start: `Dependencies installing with ${ctx.pkgManager}...`,
|
|
|
|
end: 'Dependencies installed',
|
|
|
|
while: () => install({ pkgManager: ctx.pkgManager, cwd: ctx.cwd }),
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
await info(
|
|
|
|
ctx.yes === false ? 'deps [skip]' : 'No problem!',
|
|
|
|
'Remember to install dependencies after setup.'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-06 11:21:48 -05:00
|
|
|
async function install({ pkgManager, cwd }: { pkgManager: string; cwd: string }) {
|
|
|
|
const installExec = execa(pkgManager, ['install'], { cwd });
|
|
|
|
return new Promise<void>((resolve, reject) => {
|
|
|
|
installExec.on('error', (error) => reject(error));
|
|
|
|
installExec.on('close', () => resolve());
|
|
|
|
});
|
2023-02-06 11:19:37 -05:00
|
|
|
}
|