sherry-utils
Version:
sherry-utils for Sherry
38 lines (33 loc) • 903 B
JavaScript
const { spawn } = require('./spawn')
class NpmClient {
constructor() {
// Yarn first by default.
const { stdout, status } = spawn.sync('yarn', ['--version'])
this.set(status === 0 && stdout ? 'yarn' : 'npm')
}
set(npmClient) {
if (typeof npmClient === 'string') {
if (npmClient.includes('npm')) {
this.commandName = npmClient
this.baseOn = 'npm'
} else if (npmClient.includes('yarn')) {
this.commandName = npmClient
this.baseOn = 'yarn'
}
}
// Custom NPM Client
if (typeof npmClient === 'object') {
const { commandName, baseOn } = npmClient
if (commandName) {
this.commandName = commandName
}
if (baseOn) {
this.baseOn = baseOn
}
}
}
isPublicClient() {
return this.commandName === 'npm' || this.commandName === 'yarn'
}
}
module.exports = new NpmClient()