mirror of
https://github.com/cupcakearmy/unbrew.git
synced 2025-01-22 06:56:30 +00:00
initial commit
This commit is contained in:
parent
c248b2a5a1
commit
a6020b4dce
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
yarn.lock
|
||||
node_modules
|
6
.prettierrc
Normal file
6
.prettierrc
Normal file
@ -0,0 +1,6 @@
|
||||
{
|
||||
"tabWidth": 2,
|
||||
"useTabs": false,
|
||||
"semi": false,
|
||||
"singleQuote": true
|
||||
}
|
17
package.json
Normal file
17
package.json
Normal file
@ -0,0 +1,17 @@
|
||||
{
|
||||
"name": "unbrew",
|
||||
"version": "0.1.0",
|
||||
"author": {
|
||||
"name": "Niccolo Borgioli",
|
||||
"email": "hi@nicco.io",
|
||||
"url": "https://nicco.io"
|
||||
},
|
||||
"license": "MIT",
|
||||
"bin": {
|
||||
"unbrew": "./src/index.js"
|
||||
},
|
||||
"dependencies": {
|
||||
"chalk": "4",
|
||||
"inquirer": "7"
|
||||
}
|
||||
}
|
54
src/index.js
Normal file
54
src/index.js
Normal file
@ -0,0 +1,54 @@
|
||||
const cp = require('child_process')
|
||||
const chalk = require('chalk')
|
||||
|
||||
const inquirer = require('inquirer')
|
||||
|
||||
function checkIfBrewIsInstalled() {
|
||||
try {
|
||||
cp.execSync('brew --version')
|
||||
return true
|
||||
} catch (e) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
function getListOfLeaves() {
|
||||
const list = cp.execSync('brew leaves', { encoding: 'utf-8' })
|
||||
return list.trim().split('\n')
|
||||
}
|
||||
|
||||
function getLoosers(keepers) {
|
||||
return getListOfLeaves().filter((leave) => !keepers.includes(leave))
|
||||
}
|
||||
|
||||
async function main() {
|
||||
if (!checkIfBrewIsInstalled()) {
|
||||
console.log(chalk.red.underline('Brew not installed'))
|
||||
return
|
||||
}
|
||||
|
||||
const { keepers } = await inquirer.prompt([
|
||||
{
|
||||
type: 'checkbox',
|
||||
message: 'Uncheck all unwanted packages',
|
||||
name: 'keepers',
|
||||
choices: getListOfLeaves().map((leave) => ({
|
||||
name: leave,
|
||||
checked: true,
|
||||
})),
|
||||
},
|
||||
])
|
||||
|
||||
console.log('🗑 Uninstalling:', chalk.bold.blue(getLoosers(keepers).join(' ')))
|
||||
// while (true) {
|
||||
// const loosers = getLoosers(keepers)
|
||||
// if (!loosers.length) break
|
||||
|
||||
// const joinedLoosers = loosers.join(' ')
|
||||
// cp.execSync(`brew uninstall ${joinedLoosers}`)
|
||||
// }
|
||||
console.log('🧽 Cleaning up')
|
||||
cp.execSync(`brew cleanup`)
|
||||
console.log(chalk.bold.green('🚀 Done'))
|
||||
}
|
||||
main()
|
Loading…
Reference in New Issue
Block a user