chore: use execFile for git commands in version check
This commit is contained in:
parent
f82c158a6b
commit
e4b1f60a66
1 changed files with 6 additions and 6 deletions
|
|
@ -1,15 +1,15 @@
|
|||
// check if running the latest version
|
||||
|
||||
import { log } from 'console';
|
||||
import { exec } from 'child_process';
|
||||
import { execFile } from 'child_process';
|
||||
|
||||
const execp = cmd => new Promise((resolve, reject) => {
|
||||
exec(cmd, (error, stdout, stderr) => {
|
||||
const runGit = (...args) => new Promise((resolve, reject) => {
|
||||
execFile('git', args, { cwd: process.cwd() }, (error, stdout, stderr) => {
|
||||
if (stderr) console.error(`stderr: ${stderr}`);
|
||||
// if (stdout) console.log(`stdout: ${stdout}`);
|
||||
if (error) {
|
||||
console.log(`error: ${error.message}`);
|
||||
if (error.message.includes('command not found')) {
|
||||
if (error.code === 'ENOENT' || error.message.includes('command not found')) {
|
||||
console.info('Install git to check for updates!');
|
||||
}
|
||||
return reject(error);
|
||||
|
|
@ -29,8 +29,8 @@ if (process.env.NOVNC_PORT) {
|
|||
date = process.env.NOW;
|
||||
} else {
|
||||
log('Not running inside Docker.');
|
||||
sha = await execp('git rev-parse HEAD');
|
||||
date = await execp('git show -s --format=%cD'); // same as format as `date -R` (RFC2822)
|
||||
sha = await runGit('rev-parse', 'HEAD');
|
||||
date = await runGit('show', '-s', '--format=%cD'); // same as format as `date -R` (RFC2822)
|
||||
// date = await execp('git show -s --format=%ch'); // %ch is same as --date=human (short/relative)
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue