UNPKG

882 BJavaScriptView Raw
1import { readFileSync } from 'fs';
2import { execSync } from 'child_process';
3import Logger from 'nightingale';
4import { version as currentVersion } from '../package.json';
5import { sendUpdate } from './client';
6import { exit } from './index';
7
8const logger = new Logger('app:update');
9
10export function selfUpdate() {
11 sendUpdate({ updating: true });
12 logger.info('self update');
13 try {
14 execSync('npm install -g pooliot-client', { stdio: 'inherit' });
15 const newVersion = JSON.parse(readFileSync(`${__dirname}/../package.json`)).version;
16 logger.info('self update migrate', { newVersion, currentVersion });
17 if (newVersion !== currentVersion) {
18 execSync(`node migrate.js "${currentVersion}" "${newVersion}"`, {
19 stdio: 'inherit',
20 cwd: __dirname,
21 });
22 }
23 exit();
24 return true;
25 } catch (err) {
26 logger.error(err.message);
27 }
28}