Skip to content

Commit

Permalink
Implement installers via electron-builder
Browse files Browse the repository at this point in the history
  • Loading branch information
razzeee committed May 19, 2016
1 parent bb66ece commit be7cdb1
Show file tree
Hide file tree
Showing 5 changed files with 360 additions and 244 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,5 +86,10 @@ $ npm run package:linux
$ npm run package:all (Packages for all platform)
```

Create a windows installer with the following command. It will appear in the `release\windows-installer` directory.
```
$ npm run installer
```

## Contributing
Please see [CONTRIBUTING.md](./CONTRIBUTING.md).
15 changes: 10 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,20 @@
"package:osx": "gulp package:osx",
"package:linux": "gulp build && build --platform linux --arch all -d deb",
"package:all": "gulp package:all",
"prettify": "gulp prettify"
"prettify": "gulp prettify",
"installer": "node ./script/installer.js"
},
"devDependencies": {
"babel-core": "^6.7.5",
"babel-loader": "^6.2.4",
"babel-preset-react": "^6.5.0",
"chromedriver": "^2.20.0",
"del": "^2.2.0",
"electron-builder": "^3.11.0",
"electron-builder": "3.20.0",
"electron-connect": "^0.3.7",
"electron-packager": "^7.0.1",
"electron-prebuilt": "0.37.8",
"electron-winstaller": "^2.2.0",
"esformatter": "^0.9.3",
"esformatter-jsx": "^5.0.0",
"gulp": "^3.9.0",
Expand All @@ -47,6 +49,7 @@
"json-loader": "^0.5.4",
"mocha": "^2.3.4",
"mocha-circleci-reporter": "0.0.1",
"rimraf": "^2.5.2",
"should": "^8.0.1",
"style-loader": "^0.13.0",
"through2": "^2.0.1",
Expand All @@ -56,9 +59,11 @@
"webpack-stream": "^3.1.0"
},
"build": {
"linux": {
"synopsis": "Mattermost Desktop"
}
"app-bundle-id": "org.mattermost.desktop",
"app-category-type": "public.app-category.productivity",
"linux": {
"synopsis": "Mattermost Desktop"
}
},
"directories":{
"buildResources": "resources",
Expand Down
38 changes: 38 additions & 0 deletions script/installer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/usr/bin/env node

const createWindowsInstaller = require('electron-winstaller').createWindowsInstaller
const path = require('path')
const rimraf = require('rimraf')

deleteOutputFolder()
.then(getInstallerConfig)
.then(createWindowsInstaller)
.catch((error) => {
console.error(error.message || error)
process.exit(1)
})

function getInstallerConfig () {
const rootPath = path.join(__dirname, '..')
const outPath = path.join(rootPath, 'release')

return Promise.resolve({
appDirectory: path.join(outPath, 'Mattermost-win32-ia32'),
iconUrl: 'https://raw.githubusercontent.com/mattermost/desktop/master/resources/icon.ico',
//loadingGif: path.join(rootPath, 'assets', 'img', 'loading.gif'),
noMsi: true,
outputDirectory: path.join(outPath, 'windows-installer'),
setupExe: 'Mattermost.exe',
setupIcon: path.join(rootPath, 'resources', 'icon.ico'),
skipUpdateIcon: true,
exe: 'Mattermost.exe'
})
}

function deleteOutputFolder () {
return new Promise((resolve, reject) => {
rimraf(path.join(__dirname, '..', 'out', 'windows-installer'), (error) => {
error ? reject(error) : resolve()
})
})
}
49 changes: 49 additions & 0 deletions src/auto-updater.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
const ChildProcess = require('child_process')
const path = require('path')

exports.createShortcut = function (callback) {
spawnUpdate([
'--createShortcut',
path.basename(process.execPath),
'--shortcut-locations',
'StartMenu'
], callback)
}

exports.removeShortcut = function (callback) {
spawnUpdate([
'--removeShortcut',
path.basename(process.execPath)
], callback)
}

function spawnUpdate (args, callback) {
var updateExe = path.resolve(process.execPath, '..', '..', 'Update.exe')
var stdout = ''
var spawned = null

try {
spawned = ChildProcess.spawn(updateExe, args)
} catch (error) {
if (error && error.stdout == null) error.stdout = stdout
process.nextTick(function () { callback(error) })
return
}

var error = null

spawned.stdout.on('data', function (data) { stdout += data })

spawned.on('error', function (processError) {
if (!error) error = processError
})

spawned.on('close', function (code, signal) {
if (!error && code !== 0) {
error = new Error('Command failed: ' + code + ' ' + signal)
}
if (error && error.code == null) error.code = code
if (error && error.stdout == null) error.stdout = stdout
callback(error)
})
}
Loading

0 comments on commit be7cdb1

Please sign in to comment.