fix: use node to update status bar with latest git commit (#671)
* fix: use node to update status bar with latest git commit * fix: handle case when git commit file is empty * fix: use node for build script * fix: include bash script * fix: sync ouput of bash and node scripts * refactor: add regex comment again * refactor: use 7 characters for short hash * fix: use node for yarn build
This commit is contained in:
Родитель
ac604b6bd4
Коммит
7166cdae57
|
@ -52,8 +52,8 @@
|
|||
"scripts": {
|
||||
"start": "env-cmd -f .env.electron nf start -p 3000",
|
||||
"compile": "tsc",
|
||||
"build": "./scripts/dump_git_info.sh && react-scripts build",
|
||||
"react-start": "./scripts/dump_git_info.sh && react-scripts start",
|
||||
"build": "node ./scripts/dump_git_info.js && react-scripts build",
|
||||
"react-start": "node ./scripts/dump_git_info.js && react-scripts start",
|
||||
"test": "react-scripts test --env=jsdom --silent",
|
||||
"eject": "react-scripts eject",
|
||||
"webpack:dev": "webpack --config ./config/webpack.dev.js",
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
spawn = require('child_process').spawn,
|
||||
fs = require('fs');
|
||||
|
||||
git = spawn('git', ['log', '-1']),
|
||||
buf = Buffer.alloc(0);
|
||||
|
||||
git.stdout.on('data', (data) => {
|
||||
buf = Buffer.concat([buf, data])
|
||||
});
|
||||
|
||||
git.stderr.on('data', (data) => {
|
||||
console.log(data.toString());
|
||||
});
|
||||
|
||||
git.on('close', (code) => {
|
||||
fs.writeFile("src/git-commit-info.txt", buf.toString(), (err, data) => {
|
||||
if (err) {
|
||||
console.log(err);
|
||||
}
|
||||
});
|
||||
});
|
|
@ -1,4 +1,4 @@
|
|||
#!/bin/bash
|
||||
|
||||
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
|
||||
git status && git log -1 > $DIR/../src/git-commit-info.txt || echo 'Not a Git repo. Continue...'
|
||||
git status && git log -1 > $DIR/../src/git-commit-info.txt || echo 'Not a Git repo. Continue...'
|
||||
|
|
|
@ -18,8 +18,8 @@ export class StatusBar extends React.Component<IStatusBarProps, IStatusBarState>
|
|||
const commitInfoUrl = require("../../../git-commit-info.txt");
|
||||
axios.get(commitInfoUrl).then(res => {
|
||||
// match the git commit hash
|
||||
const commitHash = /commit ([0-9a-fA-F]{8})/.exec(res.data)[1];
|
||||
this.setState({commitHash});
|
||||
const commitHash = /commit ([0-9a-fA-F]{7})/.exec(res?.data)[1];
|
||||
this.setState({ commitHash: commitHash || "" });
|
||||
});
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче