Commit 60a55828 by Jason Zhou

feat:

- add commands - add log display - add backup function
parent f32d9ab2
#!/usr/bin/env node #!/usr/bin/env node
const inquirer = require('inquirer') const inquirer = require('inquirer')
const program = require('commander')
const chalk = require('chalk')
const { log, colors } = require('../packages/utils/log')
const { spawn } = require('child_process') const { spawn } = require('child_process')
const _ = require('lodash')
const { const {
updateConfigFiles, updateConfigFiles,
updateLegacyCodes, updateLegacyCodes,
upgradePackages, upgradePackages,
preserveOldFiles preserveOldFiles,
restoreOldFiles
} = require('../packages/actions') } = require('../packages/actions')
const BANNER = ` const BANNER = `
...@@ -27,7 +32,9 @@ const BANNER = ` ...@@ -27,7 +32,9 @@ const BANNER = `
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
` `
const main = async () => { const VERSION = '0.1.0'
const run = async () => {
console.info(BANNER) console.info(BANNER)
const { mode } = await inquirer.prompt([ const { mode } = await inquirer.prompt([
...@@ -35,9 +42,11 @@ const main = async () => { ...@@ -35,9 +42,11 @@ const main = async () => {
name: 'mode', name: 'mode',
type: 'list', type: 'list',
message: [ message: [
'Which mode would like to choose:', colors.title('Which mode would like to choose:'),
' 🚝 chill - webpack 4, ES2018 output, cheap-eval-source-map', colors.item(
' 🚀 mad max - coming soon ...', ' 🚝 chill - webpack 4, ES2018 output, cheap-eval-source-map'
),
colors.item(' 🚀 mad max - coming soon ...\n'), // add extra \n for good looking
// ' 🚀 mad max - webpack 4, ES2018 output, no source map, no backend log', // ' 🚀 mad max - webpack 4, ES2018 output, no source map, no backend log',
'' ''
].join('\n'), ].join('\n'),
...@@ -46,16 +55,18 @@ const main = async () => { ...@@ -46,16 +55,18 @@ const main = async () => {
} }
]) ])
console.log('Preserve current configs ...') // add extra \n for good looking
console.log('\n')
log.title('📥 Preserve current configs')
preserveOldFiles() preserveOldFiles()
console.log('Update config files ...') log.title('📝 Update config files')
updateConfigFiles(mode) updateConfigFiles(mode)
console.log('Update legacy codes ...') log.title('💯 Update legacy codes')
updateLegacyCodes() updateLegacyCodes()
console.log('Upgrade pacakages ...') log.title('🐣 Upgrade pacakages')
upgradePackages() upgradePackages()
console.log('yarn dev') log.title('🐥 Everything set! Run yarn dev')
// since shelljs.exec doesn't work with inqurier.js // since shelljs.exec doesn't work with inqurier.js
// use spawn instead // use spawn instead
spawn('yarn', ['dev'], { spawn('yarn', ['dev'], {
...@@ -63,4 +74,30 @@ const main = async () => { ...@@ -63,4 +74,30 @@ const main = async () => {
}) })
} }
main() program.version(VERSION)
program
.command('run')
.description('Run wildcat')
.action(run)
program
.command('restore')
.description(
'Restore the previous configs, make sure you have execed wildcat run command or it may go wrong.'
)
.action(restoreOldFiles)
program.parse(process.argv)
// default command when no params attached
if (_.isEmpty(program.args)) {
console.info(BANNER)
console.info(chalk.cyanBright(`Version: v${VERSION}\n`))
console.info(
`🐾 ${chalk.cyanBright(
'Wildcat is a cli tool for accelerating webpack dev server of Bobcat.'
)}`
)
program.help()
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment