4
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Electronのアプリケーションバージョンにgitのハッシュ値を付ける

Last updated at Posted at 2019-01-19

概要

Electron アプリケーションやパッケージのバージョンとして git のハッシュ値を利用するための、簡単なスクリプト。

バージョン取得

package.jsonversion に値を記載した状態で、version.jsを実行すると、
git ハッシュ値(先頭8桁)を付け加えたバージョンを返す。

$ node version.js
0.0.1+bf1894c3

パッケージへのバージョン指定

electron-builderbuild 実行時に、以下のようなオプションを渡して、version.jsが返すバージョンを指定する。

    "package-linux": "yarn build && electron-builder build --linux -c.extraMetadata.version=`node ./version.js`",

Electron renderer process からのバージョン取得

app.getVersion() で取得。

app/components/Home.js

// @flow
import React, { Component } from 'react';
import { Link } from 'react-router-dom';
import { remote } from 'electron';
import routes from '../constants/routes';
import styles from './Home.css';

const { app } = remote;

type Props = {};

export default class Home extends Component<Props> {
  props: Props;

  render() {
    return (
      <div className={styles.container} data-tid="container">
        <h2>Home</h2>
        <Link to={routes.COUNTER}>to Counter</Link>
        <p>version {app.getVersion()}</p>
      </div>
    );
  }
}
4
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?