1 | import { readFileSync } from 'fs';
|
2 | import { execSync } from 'child_process';
|
3 | import Logger from 'nightingale';
|
4 | import { version as currentVersion } from '../package.json';
|
5 | import { sendUpdate } from './client';
|
6 | import { exit } from './index';
|
7 |
|
8 | const logger = new Logger('app:update');
|
9 |
|
10 | export 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 | }
|