Commit f32d9ab2 by Jason Zhou

feat: add log display

parent a7568fb3
// const path = require('path') // const path = require('path')
const fs = require('fs') const fs = require('fs')
const path = require('path') const path = require('path')
const chalk = require('chalk')
const shell = require('shelljs') const shell = require('shelljs')
const handlebars = require('handlebars') const handlebars = require('handlebars')
const { log } = require('./utils/log')
const { TEMPLATES, PACKAGES, LEGACY_CODES, BACKUP_FILES } = require('./configs') const { TEMPLATES, PACKAGES, LEGACY_CODES, BACKUP_FILES } = require('./configs')
handlebars.registerHelper('if_eq', function(a, b, opts) { handlebars.registerHelper('if_eq', function(a, b, opts) {
...@@ -12,15 +15,16 @@ handlebars.registerHelper('if_eq', function(a, b, opts) { ...@@ -12,15 +15,16 @@ handlebars.registerHelper('if_eq', function(a, b, opts) {
const preserveOldFiles = () => { const preserveOldFiles = () => {
BACKUP_FILES.forEach(file => { BACKUP_FILES.forEach(file => {
console.log(`Preserving ${file} ...`) log.item(`Preserving ${file} ...`)
const basename = path.basename(file) const basename = path.basename(file)
fs.copyFileSync(file, `${__dirname}/backups/${basename}`) fs.copyFileSync(file, `${__dirname}/backups/${basename}`)
}) })
} }
const restoreOldFiles = () => { const restoreOldFiles = () => {
log.title('📤 Restore previous configs')
BACKUP_FILES.forEach(file => { BACKUP_FILES.forEach(file => {
console.log(`Restoring ${file} ...`) log.item(`Restoring ${file} ...`)
const basename = path.basename(file) const basename = path.basename(file)
fs.copyFileSync(`${__dirname}/backups/${basename}`, file) fs.copyFileSync(`${__dirname}/backups/${basename}`, file)
}) })
...@@ -28,6 +32,7 @@ const restoreOldFiles = () => { ...@@ -28,6 +32,7 @@ const restoreOldFiles = () => {
const updateConfigFiles = (mode = 'chill') => { const updateConfigFiles = (mode = 'chill') => {
TEMPLATES.forEach(filename => { TEMPLATES.forEach(filename => {
log.item(`Updating ${filename} ...`)
const content = fs.readFileSync( const content = fs.readFileSync(
`${__dirname}/templates/${filename}.template`, `${__dirname}/templates/${filename}.template`,
'utf8' 'utf8'
...@@ -40,6 +45,7 @@ const updateConfigFiles = (mode = 'chill') => { ...@@ -40,6 +45,7 @@ const updateConfigFiles = (mode = 'chill') => {
const updateLegacyCodes = () => { const updateLegacyCodes = () => {
LEGACY_CODES.forEach(({ name, update }) => { LEGACY_CODES.forEach(({ name, update }) => {
log.item(`Updating ${name} ...`)
const content = fs.readFileSync(name, 'utf8') const content = fs.readFileSync(name, 'utf8')
const output = update(content) const output = update(content)
fs.writeFileSync(name, output, 'utf8') fs.writeFileSync(name, output, 'utf8')
...@@ -49,7 +55,10 @@ const updateLegacyCodes = () => { ...@@ -49,7 +55,10 @@ const updateLegacyCodes = () => {
const upgradePackages = () => { const upgradePackages = () => {
const command = const command =
'yarn add -D ' + '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) const { code, stderr } = shell.exec(command)
if (!code) console.error(stderr) if (!code) console.error(stderr)
} }
......
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