UNPKG

pooliot-client

Version:
29 lines (26 loc) 889 B
import { readFileSync } from 'fs'; import { execSync } from 'child_process'; import Logger from 'nightingale'; import { version as currentVersion } from '../../package.json'; import { sendUpdate } from './client'; import { exit } from '../index'; const logger = new Logger('app:update'); export function selfUpdate() { sendUpdate({ updating: true }); logger.info('self update'); try { execSync('npm install -g pooliot-client', { stdio: 'inherit' }); const newVersion = JSON.parse(readFileSync(`${__dirname}/../../package.json`)).version; logger.info('self update migrate', { newVersion, currentVersion }); if (newVersion !== currentVersion) { execSync(`node migrate.js "${currentVersion}" "${newVersion}"`, { stdio: 'inherit', cwd: __dirname, }); } exit(); return true; } catch (err) { logger.error(err.message); } }