Verified Commit 768c13c2 authored by Camil Staps's avatar Camil Staps 🚀

Add wrapper around electron-packager

parent c9fd4d85
...@@ -110,14 +110,34 @@ To distribute your application you don't want your users to have to install ...@@ -110,14 +110,34 @@ To distribute your application you don't want your users to have to install
Node.js. It is possible to package Electron applications complete with a Chrome Node.js. It is possible to package Electron applications complete with a Chrome
runtime, so that you get a completely stand-alone application. runtime, so that you get a completely stand-alone application.
To do this with an iTasks-Electron application, you need to write a `build.js` You need to run `npm install --save-dev electron-packager copy-dir` to install
script that collects all relevant files and uses the necessary dependencies to be able to package applications.
[`electron-packager`][electron-packager] to create a stand-alone distribution.
I am still in the process of creating helper functions to easily write a After that, you need to write a `build.js` using iTask-Electron's
`build.js`. For now, you can see how it is done in TextSheets: `clean-electron-packager.js`. A simple `build.js` looks like this:
- https://gitlab.com/camilstaps/text-sheets/-/blob/master/src/build.js ```js
- https://gitlab.com/camilstaps/text-sheets/-/blob/master/.gitlab-ci.yml const path=require ('path');
const packager=require ('./iTasks-electron/src/clean-electron-packager.js');
packager ({
out: path.join ('..','dist'),
cleanApp: 'myproject',
electronApp: 'ApplicationName'
}).then (appPaths => {
console.log (`Electron app bundles created:\n${appPaths.join('\n')}`);
});
```
This assumes that the Clean application (excluding `.exe`) is called
`myproject`. The application is put in `../dist/<name>-<platform>-<arch>`, and
the main executable is `ApplicationName` (with the appropriate extension
depending on the operating system).
In more advanced cases you may want to ignore certain files from the
distribution, or add files in the build step. See the build script of
TextSheets for a more advanced configuration:
https://gitlab.com/camilstaps/text-sheets/-/blob/master/src/build.js
[Electron]: https://www.electronjs.org/ [Electron]: https://www.electronjs.org/
[Electron-BrowserWindow]: https://www.electronjs.org/docs/api/browser-window [Electron-BrowserWindow]: https://www.electronjs.org/docs/api/browser-window
......
const fs=require ('fs');
const path=require ('path');
const copydir=require ('copy-dir');
const packager=require ('electron-packager');
module.exports=function (_opts) {
const opts={
dir: '.',
out: _opts.out,
overwrite: true,
executableName: _opts.electronApp,
ignore: [
/\.([di]cl|prj(\.default)?|prp)$/,
/^\/WebPublic$/,
/^\/iTasks-electron$/,
/^\/Clean System Files$/,
/^build.js$/,
],
afterCopy: [
(buildPath,version,platform,arch,done) => {
/* -www directory is expected at the root */
copydir.sync (
path.join (buildPath,_opts.cleanApp+'-www'),
path.join (buildPath,'..','..',_opts.cleanApp+'-www')
);
/* Server app is expected at the root */
const exts=['exe','bc','pbc'];
for (i in exts)
fs.renameSync (
path.join (buildPath,_opts.cleanApp+'.'+exts[i]),
path.join (buildPath,'..','..',_opts.cleanApp+'.'+exts[i])
);
if ('afterCopy' in _opts)
_opts.afterCopy (buildPath,version,platform,arch,done);
else
done();
}
]
};
if ('ignore' in _opts)
opts.ignore.concat (_opts.ignore);
return packager (opts);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment