3 Star 8 Fork 4

于江浩 / winwin-hexo-editor

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
update.js 3.83 KB
一键复制 编辑 原始数据 按行查看 历史
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()
1
https://gitee.com/winwin_2011/winwin-hexo-editor.git
git@gitee.com:winwin_2011/winwin-hexo-editor.git
winwin_2011
winwin-hexo-editor
winwin-hexo-editor
master

搜索帮助