Commit f32d9ab2 by Jason Zhou

feat: add log display

parent a7568fb3
// 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)
}
......
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