Skip to content

Commit 0ade4a4

Browse files
authored
Merge pull request #7 from rroylance/feature/electron-packager
Feature/electron packager. - App packaging with electron-packager, more progress on #5.
2 parents 252d356 + 1f0ad26 commit 0ade4a4

File tree

4 files changed

+79
-2
lines changed

4 files changed

+79
-2
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@ node_modules
66

77
# Game
88
dist
9+
builds
910

1011
# OSX
1112
.DS_Store
1213

1314
# Visual Studio
14-
.vs
15+
.vs

README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,31 @@ To build the dev or dist version of your game, respectively, and then open up yo
226226

227227
After you're done writing your app, you can create a distribution by following the [Application Distribution][electron-distribution] guide and then executing the packaged app.
228228

229+
## Package Desktop App via Electron
230+
231+
** Note that I am not, currently, actively using this. So if you do, I'd appreciate if you could pass any changes you make or anything you need out of it. Although I'm not using it, I will still support it as best I can.**
232+
233+
You can package your game for Windows (win32 ia32/x64), OSX (darwin ia32/x64), Mac App Store (mas ia32/x64), Linux (linux ia32/x64/armv7l) using the following script;
234+
235+
```npm run electron:pack:dev```
236+
237+
or
238+
239+
```npm run electron:pack:dist```
240+
241+
To package the dev or dist version of your game, respectively, for the current platform you are on. You can provide many options to build specific platforms, for specific architectures, provide an icon, etc.
242+
243+
Refer to the [API Documentation][electron-pack-api] for a full list and details; I'm using it kind of oddly in that I'm using the API from the command line and not the command line version... to provide options appaend ' -- ' to the npm run command and then also append '--' to the option name and then either put the value after a space or '=', either way. Examples;
244+
245+
```npm run electron:pack:dist -- --platform win32 --arch=ia32 //32 bit Windows exe```
246+
```npm run electron:pack:dist -- --platform win32,darwin --arch=ia32,x64 //32 and 64 bit Windows exe and OSX app```
247+
248+
All builds will be in the builds/ folder in appropriately named folders.
249+
250+
###### Note that building for Windows from a non windows device requires a little bit of extra setup; refer to [Building Windows apps from non-Windows platforms][electron-pack-windows].
251+
252+
###### Also note that for OSX / MAS target bundles: the .app bundle can only be signed when building on a host OSX platform.
253+
229254
## Bugs/Issues?
230255

231256
If you have any issues please let me know via [GitHub Issues][issues]!
@@ -247,3 +272,5 @@ If you would like to have some of your code included; whether a new feature, a c
247272
[nodejs]: https://nodejs.org/en/
248273
[itchio]: https://rroylance.itch.io/phaser-npm-webpack-typescript-starter-project
249274
[electron-distribution]: https://electron.atom.io/docs/tutorial/application-distribution/
275+
[electron-pack-windows]: https://github.com/electron-userland/electron-packager#building-windows-apps-from-non-windows-platforms
276+
[electron-pack-api]: https://github.com/electron-userland/electron-packager/blob/master/docs/api.md

package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"name": "phaser-npm-webpack-typescript-starter-project",
3-
"version": "1.7.2",
3+
"productName": "phaser-npm-webpack-typescript-starter-project",
4+
"version": "1.7.3",
45
"main": "electron-main.js",
56
"scripts": {
67
"webpack:dev": "webpack --config webpack.dev.config.js --progress --colors",
@@ -15,6 +16,8 @@
1516
"postinstall": "npm run setupGameSize",
1617
"electron:dev": "npm run build:dev && electron .",
1718
"electron:dist": "npm run build:dist && electron .",
19+
"electron:pack:dev": "npm run build:dev && node ./scripts/packageElectronApp.js",
20+
"electron:pack:dist": "npm run build:dist && node ./scripts/packageElectronApp.js",
1821
"checkDepsVersions": "npm-check --skip-unused -u"
1922
},
2023
"repository": {
@@ -33,6 +36,7 @@
3336
"copy-webpack-plugin": "4.0.1",
3437
"echo-cli": "1.0.8",
3538
"electron": "1.4.15",
39+
"electron-packager": "8.5.2",
3640
"file-loader": "0.10.1",
3741
"git-revision-webpack-plugin": "2.4.1",
3842
"html-webpack-plugin": "2.28.0",

scripts/packageElectronApp.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
var packager = require('electron-packager');
2+
3+
var args = process.argv.slice(2);
4+
var options = {};
5+
6+
for (var a = 0, argsCount = args.length; a < argsCount; a++) {
7+
var currentArg = args[a];
8+
var nextArg = args[a + 1];
9+
10+
if (currentArg.indexOf('--') === 0 && (nextArg && nextArg.indexOf('--') === -1)) {
11+
currentArg = currentArg.slice(2);
12+
13+
options[currentArg] = nextArg;
14+
15+
a++;
16+
} else {
17+
currentArg = currentArg.slice(2).split('=');
18+
19+
if (currentArg.length > 1) {
20+
options[currentArg.shift()] = currentArg.shift();
21+
} else {
22+
options[currentArg.shift()] = true;
23+
}
24+
}
25+
}
26+
27+
options.dir = (options.dir || '.');
28+
options.out = (options.out || 'builds');
29+
options.overwrite = (options.overwrite || true);
30+
options.ignore = (options.ignore || function (fileName) {
31+
return !(fileName === '' ||
32+
fileName.indexOf('/dist') === 0 ||
33+
fileName.indexOf('/package.json') === 0 ||
34+
fileName.indexOf('/electron-main.js') === 0
35+
);
36+
});
37+
38+
packager(options, function done_callback (err) {
39+
if (err) {
40+
console.log(err);
41+
return;
42+
}
43+
44+
console.log('Packaging Complete ✔');
45+
});

0 commit comments

Comments
 (0)