Skip to content

Commit

Permalink
feat: implement dependency installation logic
Browse files Browse the repository at this point in the history
- Added the necessary logic to install dependencies.
  • Loading branch information
RaulCatalinas committed May 1, 2024
1 parent 7c94607 commit 7b5eb22
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 10 deletions.
Binary file modified bun.lockb
Binary file not shown.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"prepublishOnly": "bun run build"
},
"dependencies": {
"@npmcli/promise-spawn": "7.0.1",
"commander": "12.0.0",
"inquirer": "9.2.20",
"opener": "1.5.2"
Expand All @@ -24,6 +25,7 @@
"@swc/core": "1.4.17",
"@types/bun": "1.1.0",
"@types/inquirer": "9.0.7",
"@types/npmcli__promise-spawn": "6.0.3",
"@types/opener": "1.4.3",
"@typescript-eslint/eslint-plugin": "^7.0.1",
"eslint": "^8.0.1",
Expand Down
8 changes: 4 additions & 4 deletions src/constants/dependencies.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { PackageManager } from '@/types/package-manger'

export const INSTALLATION_COMMANDS: Record<PackageManager, string> = {
npm: 'npm install',
yarn: 'yarn add',
pnpm: 'pnpm add',
bun: 'bun add'
npm: 'install',
yarn: 'add',
pnpm: 'add',
bun: 'add'
}
2 changes: 1 addition & 1 deletion src/utils/commitlint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export async function generateCommitlintConfig(
try {
console.log('Configuring commitlint...')

installDependencies({
await installDependencies({
packageManagerToUse,
packagesToInstall: [
'lint-staged',
Expand Down
14 changes: 10 additions & 4 deletions src/utils/dependencies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,26 @@ import type { PackageManager } from '@/types/package-manger'
// Constants
import { INSTALLATION_COMMANDS } from '@/constants/dependencies'

// Third-Party libraries
import promiseSpawn from '@npmcli/promise-spawn'

interface Props {
packageManagerToUse: PackageManager
packagesToInstall: string | string[]
}

export function installDependencies({
export async function installDependencies({
packageManagerToUse,
packagesToInstall
}: Props) {
const packageManager = INSTALLATION_COMMANDS[packageManagerToUse]
const installationCommand = INSTALLATION_COMMANDS[packageManagerToUse]

console.log(`Installing dependencies using: ${packageManager}...`)
console.log(`Installing dependencies using: ${packageManagerToUse}...`)

// TODO: Implement the logic for installing dependencies using the package manager of the user's choice.
await promiseSpawn(
packageManagerToUse,
[installationCommand, packagesToInstall, '-D'].flat()
)

console.log('Installed dependencies')
}
2 changes: 1 addition & 1 deletion src/utils/husky-library.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { HUSKY_CONFIG } from '@/constants/husky-library'

export async function generateHuskyConfig(packageManagerToUse: PackageManager) {
try {
installDependencies({
await installDependencies({
packageManagerToUse,
packagesToInstall: 'husky'
})
Expand Down

0 comments on commit 7b5eb22

Please sign in to comment.