initial commit

This commit is contained in:
cupcakearmy 2020-05-11 00:53:00 +02:00
parent c248b2a5a1
commit a6020b4dce
No known key found for this signature in database
GPG Key ID: D28129AE5654D9D9
4 changed files with 79 additions and 0 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
yarn.lock
node_modules

6
.prettierrc Normal file
View File

@ -0,0 +1,6 @@
{
"tabWidth": 2,
"useTabs": false,
"semi": false,
"singleQuote": true
}

17
package.json Normal file
View 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
View 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()