2021-12-21 16:13:45 +01:00
|
|
|
import chalk from 'next/dist/compiled/chalk'
|
2021-08-04 23:53:15 +02:00
|
|
|
import path from 'path'
|
|
|
|
|
|
|
|
import { MissingDependency } from './has-necessary-dependencies'
|
2022-06-19 14:33:23 +02:00
|
|
|
import { getPkgManager } from './helpers/get-pkg-manager'
|
2021-08-04 23:53:15 +02:00
|
|
|
import { install } from './helpers/install'
|
|
|
|
import { getOnline } from './helpers/get-online'
|
|
|
|
|
|
|
|
export type Dependencies = {
|
|
|
|
resolved: Map<string, string>
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function installDependencies(
|
|
|
|
baseDir: string,
|
|
|
|
deps: any,
|
|
|
|
dev: boolean = false
|
|
|
|
) {
|
2022-06-19 14:33:23 +02:00
|
|
|
const packageManager = getPkgManager(baseDir)
|
|
|
|
const isOnline = await getOnline()
|
2021-08-04 23:53:15 +02:00
|
|
|
|
|
|
|
if (deps.length) {
|
|
|
|
console.log()
|
2022-06-19 14:33:23 +02:00
|
|
|
console.log(
|
|
|
|
`Installing ${
|
|
|
|
dev ? 'devDependencies' : 'dependencies'
|
|
|
|
} (${packageManager}):`
|
|
|
|
)
|
2021-08-04 23:53:15 +02:00
|
|
|
for (const dep of deps) {
|
|
|
|
console.log(`- ${chalk.cyan(dep.pkg)}`)
|
|
|
|
}
|
|
|
|
console.log()
|
|
|
|
|
|
|
|
await install(
|
|
|
|
path.resolve(baseDir),
|
|
|
|
deps.map((dep: MissingDependency) => dep.pkg),
|
2022-06-19 14:33:23 +02:00
|
|
|
{ devDependencies: dev, isOnline, packageManager }
|
2021-08-04 23:53:15 +02:00
|
|
|
)
|
|
|
|
console.log()
|
|
|
|
}
|
|
|
|
}
|