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-16 15:30:05 -05:00
|
|
|
import { error, 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',
|
2023-02-16 15:28:15 -05:00
|
|
|
while: () =>
|
|
|
|
install({ pkgManager: ctx.pkgManager, cwd: ctx.cwd }).catch((e) => {
|
|
|
|
// eslint-disable-next-line no-console
|
|
|
|
error('error', e);
|
|
|
|
process.exit(1);
|
|
|
|
}),
|
2023-02-06 11:19:37 -05:00
|
|
|
});
|
|
|
|
} 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) => {
|
2023-02-16 15:28:15 -05:00
|
|
|
setTimeout(() => reject(`Request timed out after one minute`), 60_000);
|
|
|
|
installExec.on('error', (e) => reject(e));
|
2023-02-06 11:21:48 -05:00
|
|
|
installExec.on('close', () => resolve());
|
|
|
|
});
|
2023-02-06 11:19:37 -05:00
|
|
|
}
|