Commit 00ec5533 by Jason Zhou

Merge branch 'develop' into 'master'

Develop See merge request !1
parents e59917e9 60a55828
# Wildcat
Wildcat is a cli tool for accelerating the webpack dev server of Bobcat. It is achieved by the following but not all methods:
Wildcat is a cli tool for accelerating webpack dev server of Bobcat. It is achieved by the following but not all methods:
- webpack 4
- es2018 code output
- a low cost source map config: `cheap-cheap-module-eval-source-map`
......
#!/usr/bin/env node
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 _ = require('lodash')
const {
updateConfigFiles,
updateLegacyCodes,
upgradePackages,
preserveOldFiles
preserveOldFiles,
restoreOldFiles
} = require('../packages/actions')
const BANNER = `
......@@ -27,7 +32,9 @@ const BANNER = `
| | | | | | | | | | | | | | |
`
const main = async () => {
const VERSION = '0.1.0'
const run = async () => {
console.info(BANNER)
const { mode } = await inquirer.prompt([
......@@ -35,9 +42,11 @@ const main = async () => {
name: 'mode',
type: 'list',
message: [
'Which mode would like to choose:',
' 🚝 chill - webpack 4, ES2018 output, cheap-eval-source-map',
' 🚀 mad max - coming soon ...',
colors.title('Which mode would like to choose:'),
colors.item(
' 🚝 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',
''
].join('\n'),
......@@ -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()
console.log('Update config files ...')
log.title('📝 Update config files')
updateConfigFiles(mode)
console.log('Update legacy codes ...')
log.title('💯 Update legacy codes')
updateLegacyCodes()
console.log('Upgrade pacakages ...')
log.title('🐣 Upgrade pacakages')
upgradePackages()
console.log('yarn dev')
log.title('🐥 Everything set! Run yarn dev')
// since shelljs.exec doesn't work with inqurier.js
// use spawn instead
spawn('yarn', ['dev'], {
......@@ -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()
}
{
"name": "wildcat",
"version": "1.0.0",
"version": "0.1.0",
"description": "",
"main": "index.js",
"bin": {
......@@ -10,13 +10,14 @@
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"author": "jason.zhou@strikingly.com",
"license": "ISC",
"dependencies": {
"chalk": "^2.4.1",
"commander": "^2.16.0",
"ejs": "^2.6.1",
"handlebars": "^4.0.11",
"inquirer": "^6.0.0",
"lodash": "^4.17.10",
"shelljs": "^0.8.2"
},
......
// const path = require('path')
const fs = require('fs')
const path = require('path')
const chalk = require('chalk')
const shell = require('shelljs')
const handlebars = require('handlebars')
const { log } = require('./utils/log')
const { TEMPLATES, PACKAGES, LEGACY_CODES, BACKUP_FILES } = require('./configs')
handlebars.registerHelper('if_eq', function(a, b, opts) {
......@@ -12,15 +15,16 @@ handlebars.registerHelper('if_eq', function(a, b, opts) {
const preserveOldFiles = () => {
BACKUP_FILES.forEach(file => {
console.log(`Preserving ${file} ...`)
log.item(`Preserving ${file} ...`)
const basename = path.basename(file)
fs.copyFileSync(file, `${__dirname}/backups/${basename}`)
})
}
const restoreOldFiles = () => {
log.title('📤 Restore previous configs')
BACKUP_FILES.forEach(file => {
console.log(`Restoring ${file} ...`)
log.item(`Restoring ${file} ...`)
const basename = path.basename(file)
fs.copyFileSync(`${__dirname}/backups/${basename}`, file)
})
......@@ -28,6 +32,7 @@ const restoreOldFiles = () => {
const updateConfigFiles = (mode = 'chill') => {
TEMPLATES.forEach(filename => {
log.item(`Updating ${filename} ...`)
const content = fs.readFileSync(
`${__dirname}/templates/${filename}.template`,
'utf8'
......@@ -40,6 +45,7 @@ const updateConfigFiles = (mode = 'chill') => {
const updateLegacyCodes = () => {
LEGACY_CODES.forEach(({ name, update }) => {
log.item(`Updating ${name} ...`)
const content = fs.readFileSync(name, 'utf8')
const output = update(content)
fs.writeFileSync(name, output, 'utf8')
......@@ -49,7 +55,10 @@ const updateLegacyCodes = () => {
const upgradePackages = () => {
const command =
'yarn add -D ' +
PACKAGES.map(({ name, version }) => `${name}@${version}`).join(' ')
PACKAGES.map(({ name, version }) => {
log.item(`${name}:⛳️ ${chalk.bgGreen.black(version)}`)
return `${name}@${version}`
}).join(' ')
const { code, stderr } = shell.exec(command)
if (!code) console.error(stderr)
}
......
const chalk = require('chalk')
const titleColor = title => chalk.yellowBright(title)
const itemColor = item => chalk.green(item)
const title = title => {
console.log(titleColor(`${title}\n`))
}
const item = item => {
console.log(itemColor(` ${item}\n`))
}
module.exports = {
log: { title, item },
colors: {
title: titleColor,
item: itemColor
}
}
......@@ -149,6 +149,10 @@ chardet@^0.4.0:
version "0.4.2"
resolved "https://registry.yarnpkg.com/chardet/-/chardet-0.4.2.tgz#b5473b33dc97c424e5d98dc87d55d4d8a29c8bf2"
chardet@^0.5.0:
version "0.5.0"
resolved "https://registry.yarnpkg.com/chardet/-/chardet-0.5.0.tgz#fe3ac73c00c3d865ffcc02a0682e2c20b6a06029"
circular-json@^0.3.1:
version "0.3.3"
resolved "https://registry.yarnpkg.com/circular-json/-/circular-json-0.3.3.tgz#815c99ea84f6809529d2f45791bdf82711352d66"
......@@ -444,6 +448,14 @@ external-editor@^2.1.0:
iconv-lite "^0.4.17"
tmp "^0.0.33"
external-editor@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/external-editor/-/external-editor-3.0.0.tgz#dc35c48c6f98a30ca27a20e9687d7f3c77704bb6"
dependencies:
chardet "^0.5.0"
iconv-lite "^0.4.22"
tmp "^0.0.33"
fast-deep-equal@^2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/fast-deep-equal/-/fast-deep-equal-2.0.1.tgz#7b05218ddf9667bf7f370bf7fdb2cb15fdd0aa49"
......@@ -571,7 +583,7 @@ hosted-git-info@^2.1.4:
version "2.7.1"
resolved "https://registry.yarnpkg.com/hosted-git-info/-/hosted-git-info-2.7.1.tgz#97f236977bd6e125408930ff6de3eec6281ec047"
iconv-lite@^0.4.17:
iconv-lite@^0.4.17, iconv-lite@^0.4.22:
version "0.4.23"
resolved "https://registry.yarnpkg.com/iconv-lite/-/iconv-lite-0.4.23.tgz#297871f63be507adcfbfca715d0cd0eed84e9a63"
dependencies:
......@@ -614,6 +626,24 @@ inquirer@^5.2.0:
strip-ansi "^4.0.0"
through "^2.3.6"
inquirer@^6.0.0:
version "6.0.0"
resolved "https://registry.yarnpkg.com/inquirer/-/inquirer-6.0.0.tgz#e8c20303ddc15bbfc2c12a6213710ccd9e1413d8"
dependencies:
ansi-escapes "^3.0.0"
chalk "^2.0.0"
cli-cursor "^2.1.0"
cli-width "^2.0.0"
external-editor "^3.0.0"
figures "^2.0.0"
lodash "^4.3.0"
mute-stream "0.0.7"
run-async "^2.2.0"
rxjs "^6.1.0"
string-width "^2.1.0"
strip-ansi "^4.0.0"
through "^2.3.6"
interpret@^1.0.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/interpret/-/interpret-1.1.0.tgz#7ed1b1410c6a0e0f78cf95d3b8440c63f78b8614"
......@@ -1014,6 +1044,12 @@ rxjs@^5.5.2:
dependencies:
symbol-observable "1.0.1"
rxjs@^6.1.0:
version "6.2.2"
resolved "https://registry.yarnpkg.com/rxjs/-/rxjs-6.2.2.tgz#eb75fa3c186ff5289907d06483a77884586e1cf9"
dependencies:
tslib "^1.9.0"
"safer-buffer@>= 2.1.2 < 3":
version "2.1.2"
resolved "https://registry.yarnpkg.com/safer-buffer/-/safer-buffer-2.1.2.tgz#44fa161b0187b9549dd84bb91802f9bd8385cd6a"
......@@ -1162,6 +1198,10 @@ tmp@^0.0.33:
dependencies:
os-tmpdir "~1.0.2"
tslib@^1.9.0:
version "1.9.3"
resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.9.3.tgz#d7e4dd79245d85428c4d7e4822a79917954ca286"
type-check@~0.3.2:
version "0.3.2"
resolved "https://registry.yarnpkg.com/type-check/-/type-check-0.3.2.tgz#5884cab512cf1d355e3fb784f30804b2b520db72"
......
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