Skip to content

Commit

Permalink
fix: move 'installDeps' to BaseClass
Browse files Browse the repository at this point in the history
  • Loading branch information
neikvon committed Oct 13, 2020
1 parent 2547f22 commit 71c37d1
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 25 deletions.
7 changes: 1 addition & 6 deletions src/commands/add.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,7 @@ export default class CommandAdd extends Command {
private async install(flags: Record<string, any>, targetDir: string) {
const spinner = this.createSpinner(`Installing dependencies...`).start()
try {
const packageManager = flags.packageManager || this.context.get('config').packageManager
const cmds = packageManager === 'yarn' ? [packageManager] : [packageManager, 'install']
this.debug(`\nrunning \`${cmds.join(' ')}\` in ${targetDir}`)
await this.exec(cmds[0], cmds.slice(1), {
cwd: targetDir
})
await this.installDeps(targetDir, flags.packageManager)
spinner.succeed(`Installed dependencies`)
} catch (err) {
spinner.fail('Failed to install dependencies. You can install them manually.')
Expand Down
19 changes: 19 additions & 0 deletions src/core/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,4 +148,23 @@ export abstract class BaseClass {
exit(code?: number): void {
process.exit(typeof code === undefined ? 0 : code)
}

installDeps(cwd = process.cwd(), packageManager?: string, lockfile = false, opts?: any) {
const pm = packageManager || this.context.get('config').packageManager

const cmds = [pm, 'install']

if (!lockfile) {
// pnpm: Headless installation requires a pnpm-lock.yaml file
cmds.push(pm === 'npm' ? '--no-package-lock' : pm === 'yarn' ? '--no-lockfile' : '')
}

this.debug(`\nrunning \`${cmds.join(' ')}\` in ${cwd}`)

return this.exec(cmds[0], cmds.slice(1).filter(Boolean), {
stdout: 'inherit',
...(opts || {}),
cwd
})
}
}
19 changes: 0 additions & 19 deletions src/core/template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,25 +95,6 @@ export abstract class Template extends BaseClass {
}
}

public installDeps(cwd = process.cwd(), packageManager?: string, lockfile = false, opts?: any) {
const pm = packageManager || this.context.get('config').packageManager

const cmds = [pm, 'install']

if (!lockfile) {
cmds.push(
pm === 'npm' ? '--no-package-lock' : pm === 'yarn' ? '--no-lockfile' : '--frozen-lockfile'
)
}

this.debug(`\nrunning \`${cmds.join(' ')}\` in ${cwd}`)

return this.exec(cmds[0], cmds.slice(1), {
...(opts || {}),
cwd
})
}

// processes
private async prepare(data?: any) {
this._debugPrefix = `Template "${this.id}"`
Expand Down

0 comments on commit 71c37d1

Please sign in to comment.