代码拉取完成,页面将自动刷新
const fs = require('fs')
const chalk = require('chalk')
const { Printer, Executer, readJsonFile } = require('./scripts/lib')
const logo = fs.readFileSync('./assets/logo.art')
const printer = new Printer()
async function update () {
// #region LOGO
printer.log(chalk.blue.bold(logo + chalk.underline('/ winwin-hexo-editor ') + '/'))
// #endregion
// #region Version
printer.printSection('Check Version')
const oldVersion = readJsonFile('./package.json').version
printer.info('Current Version ' + oldVersion)
if (oldVersion.indexOf('-') >= 0) {
printer.warn('This is a preview version!')
}
// #endregion
// #region Check Dependences
printer.printSection('Check Dependences')
const NODE = 'node'
const hasNode = await Executer.hasCommand(NODE + ' -v')
if (!hasNode) {
printer.error('Node is required! Please install node.js first')
process.exit(101)
} else {
printer.info(`${NODE} : ${chalk.green('pass')}`)
}
const NPM = 'npm'
const hasNPM = await Executer.hasCommand(NPM + ' -v')
if (!hasNPM) {
printer.error('npm not found, is there anything wrong with your node installation?')
process.exit(102)
} else {
printer.info(`${NPM} : ${chalk.green('pass')}`)
}
const YARN = 'yarn'
const hasYarn = await Executer.hasCommand(YARN + ' -v')
if (!hasYarn) {
printer.info(`${NODE} : ${chalk.red('pass')}`)
printer.warn('yarn not found, use npm instead.')
} else {
printer.info(`${YARN} : ${chalk.green('pass')}`)
}
// #endregion
// #region Fetch Updates
printer.printSection('Fetch Updates')
try {
printer.info('Fetching updates')
await Executer.run('git reset --hard')
await Executer.run('git submodule foreach "git reset --hard"')
await Executer.run('git pull')
printer.success('Updated')
} catch (err) {
const failed = new Printer('Installation Failed')
failed.error(err)
failed.error('error occured when fetching updates')
process.exit(201)
}
// #endregion
// #region Fetch Submodules
printer.printSection('Fetch Submodules')
try {
printer.info('Fetching submodules updates')
await Executer.run('git submodule sync')
await Executer.run('git submodule update --init --recursive')
printer.success('Submodules updated')
} catch (err) {
const failed = new Printer('Installation Failed')
failed.error(err)
failed.error('error occured when fetching submodules')
process.exit(301)
}
// #endregion
// #region Install Dependences
printer.printSection('Install Dependences')
const cmd = hasYarn ? 'yarn' : 'npm install'
try {
printer.info('Dependences installing')
await Executer.run(cmd)
printer.success('Dependences installed')
} catch (err) {
const failed = new Printer('Installation Failed')
failed.error(err)
failed.error(cmd, 'failed')
failed.error('error occured when install dependences')
process.exit(401)
}
// #endregion
// #region Finished
printer.clear()
printer.log(chalk.green.bold('Finished!'))
// #region Version
const newVersion = readJsonFile('./package.json').version
printer.info('Current Version ' + newVersion)
if (newVersion.indexOf('-') >= 0) {
printer.warn('This is a preview version!')
}
// #endregion
printer.log('Run ' + chalk.blue.bold('`npm start`') + ' to start with node')
printer.log('Run ' + chalk.blue.bold('`npm run prd`') + ' to start with pm2')
printer.log('Run ' + chalk.blue.bold('`npm run stop`') + ' to stop')
printer.log('Run ' + chalk.blue.bold('`npm run restart`') + ' to restart')
printer.log()
printer.log(chalk.green.bold('Remember to restart your service manually!'))
printer.log('Have fun :p')
printer.log(chalk.grey('For uninstall:'))
printer.log(chalk.grey('- Remove the following folder: ' + process.cwd()))
printer.log(chalk.grey('- Stop youre service manually.'))
// #endregion
}
update()
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。