mirror of
https://github.com/cheveguerra/bot-whatsapp.git
synced 2026-04-18 03:29:15 +00:00
add validation cli
This commit is contained in:
17
packages/cli/install/index.js
Normal file
17
packages/cli/install/index.js
Normal file
@@ -0,0 +1,17 @@
|
||||
const { readFileSync } = require('fs')
|
||||
const { join } = require('path')
|
||||
const { installDeps } = require('./tool')
|
||||
|
||||
const PKG_TO_UPDATE = () => {
|
||||
const data = readFileSync(join(__dirname, 'pkg-to-update.json'), 'utf-8')
|
||||
const dataParse = JSON.parse(data)
|
||||
const pkg = Object.keys(dataParse).map((n) => `${n}@${dataParse[n]}`)
|
||||
return pkg
|
||||
}
|
||||
|
||||
const installAll = async () => {
|
||||
// const pkg = await getPkgManage()
|
||||
installDeps('npm', PKG_TO_UPDATE()).runInstall()
|
||||
}
|
||||
|
||||
module.exports = { installAll }
|
||||
67
packages/cli/install/tool.js
Normal file
67
packages/cli/install/tool.js
Normal file
@@ -0,0 +1,67 @@
|
||||
const { red } = require('kleur')
|
||||
const spawn = require('cross-spawn')
|
||||
const { detect } = require('detect-package-manager')
|
||||
const PKG_OPTION = {
|
||||
npm: 'install',
|
||||
yarn: 'add',
|
||||
pnpm: 'add',
|
||||
}
|
||||
|
||||
const getPkgManage = async () => {
|
||||
const pkg = await detect()
|
||||
return pkg
|
||||
}
|
||||
|
||||
const installDeps = (pkgManager, packageList) => {
|
||||
const errorMessage = `Ocurrio un error instalando ${packageList}`
|
||||
let childProcess = []
|
||||
|
||||
const installSingle = (pkgInstall) => () => {
|
||||
new Promise((resolve) => {
|
||||
try {
|
||||
childProcess = spawn(
|
||||
pkgManager,
|
||||
[PKG_OPTION[pkgManager], pkgInstall],
|
||||
{
|
||||
stdio: 'inherit',
|
||||
}
|
||||
)
|
||||
|
||||
childProcess.on('error', (e) => {
|
||||
console.error(e)
|
||||
console.error(red(errorMessage))
|
||||
resolve()
|
||||
})
|
||||
|
||||
childProcess.on('close', (code) => {
|
||||
if (code === 0) {
|
||||
resolve()
|
||||
} else {
|
||||
console.error(code)
|
||||
console.error(red(errorMessage))
|
||||
}
|
||||
})
|
||||
|
||||
resolve()
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
console.error(red(errorMessage))
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
if (typeof packageList === 'string') {
|
||||
childProcess.push(installSingle(packageList))
|
||||
} else {
|
||||
for (const pkg of packageList) {
|
||||
childProcess.push(installSingle(pkg))
|
||||
}
|
||||
}
|
||||
|
||||
const runInstall = () => {
|
||||
return Promise.all(childProcess.map((i) => i()))
|
||||
}
|
||||
return { runInstall }
|
||||
}
|
||||
|
||||
module.exports = { getPkgManage, installDeps }
|
||||
Reference in New Issue
Block a user