Skip to content

Commit

Permalink
feat(app): Ask permission before deleting mode-specific files. #4748
Browse files Browse the repository at this point in the history
  • Loading branch information
rstoenescu committed Aug 10, 2019
1 parent 5c1e9d7 commit 3586676
Showing 1 changed file with 51 additions and 20 deletions.
71 changes: 51 additions & 20 deletions app/bin/quasar-mode
Expand Up @@ -9,9 +9,10 @@ const


const argv = parseArgs(process.argv.slice(2), { const argv = parseArgs(process.argv.slice(2), {
alias: { alias: {
y: 'yes',
h: 'help' h: 'help'
}, },
boolean: ['h'] boolean: ['y', 'h']
}) })


function showHelp() { function showHelp() {
Expand All @@ -20,12 +21,14 @@ function showHelp() {
Add/Remove support for PWA / Cordova / Electron modes. Add/Remove support for PWA / Cordova / Electron modes.
Usage Usage
$ quasar mode [add|remove] [pwa|ssr|cordova|electron] $ quasar mode [add|remove] [pwa|ssr|cordova|electron] [--yes]
# determine what modes are currently installed: # determine what modes are currently installed:
$ quasar mode $ quasar mode
Options Options
--yes, -y Skips the "Are you sure?" question
when removing a Quasar mode
--help, -h Displays this message --help, -h Displays this message
`) `)
process.exit(0) process.exit(0)
Expand All @@ -47,7 +50,7 @@ const
getMode = require('../lib/mode'), getMode = require('../lib/mode'),
{ green, grey } = require('chalk') { green, grey } = require('chalk')


if (argv._.length === 2) { async function run () {
let [ action, mode ] = argv._ let [ action, mode ] = argv._


if (!['add', 'remove'].includes(action)) { if (!['add', 'remove'].includes(action)) {
Expand All @@ -63,23 +66,51 @@ if (argv._.length === 2) {
process.exit(1) process.exit(1)
} }


getMode(mode)[action]() const cliMode = getMode(mode)
process.exit(0)
}


log(`Detecting installed modes...`) if (action === 'remove' && argv.yes !== true && cliMode.isInstalled) {
console.log()


const info = [] const inquirer = require('inquirer')
;['pwa', 'ssr', 'cordova', 'electron'].forEach(mode => { const answer = await inquirer.prompt([{
const QuasarMode = getMode(mode) name: 'go',
info.push([ type: 'confirm',
`Mode ${mode.toUpperCase()}`, message: `Will also remove /src-${mode} folder. Are you sure?`,
getMode(mode).isInstalled ? green('yes') : grey('no') default: false
]) }])
})
if (!answer.go) {
console.log()
console.log(`⚠️ Aborted...`)
console.log()
process.exit(0)
}
}


console.log( cliMode[action]()
'\n' + }
info.map(msg => ' ' + msg[0].padEnd(16, '.') + ' ' + msg[1]).join('\n') +
'\n' function displayModes () {
) log(`Detecting installed modes...`)

const info = []
;['pwa', 'ssr', 'cordova', 'electron'].forEach(mode => {
info.push([
`Mode ${mode.toUpperCase()}`,
getMode(mode).isInstalled ? green('yes') : grey('no')
])
})

console.log(
'\n' +
info.map(msg => ' ' + msg[0].padEnd(16, '.') + ' ' + msg[1]).join('\n') +
'\n'
)
}

if (argv._.length === 2) {
run()
}
else {
displayModes()
}

0 comments on commit 3586676

Please sign in to comment.