windows-installer.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. "use strict";
  2. //Taken from Electron API Demos
  3. //https://github.com/electron/electron-api-demos/blob/master/script/installer.js
  4. const createWindowsInstaller = require('electron-winstaller').createWindowsInstaller;
  5. const path = require('path');
  6. const rimraf = require('rimraf');
  7. const win64 = 'win32-x64';
  8. const win32 = 'win32-ia32';
  9. const winArg = process.argv[2];
  10. const winExt = winArg === 'win32' ? win32 : win64;
  11. deleteOutputFolder()
  12. .then(getInstallerConfig)
  13. .then(createWindowsInstaller)
  14. .catch((error) => {
  15. console.error(error.message || error);
  16. process.exit(1);
  17. });
  18. function getInstallerConfig() {
  19. const rootPath = path.join(__dirname, '..');
  20. const outPath = path.join(rootPath, 'out');
  21. return Promise.resolve({
  22. appDirectory: path.join(outPath, 'flasher.js-' + winExt),
  23. iconUrl: 'https://raw.githubusercontent.com/thingssdk/flasher.js/resources/icon.ico',
  24. loadingGif: path.join(rootPath, 'resources', 'loading.gif'),
  25. noMsi: true,
  26. outputDirectory: path.join(outPath, 'installers'),
  27. setupExe: 'flasher.js-setup-' + winExt + '.exe',
  28. setupIcon: path.join(rootPath, 'resources', 'icon.ico'),
  29. skipUpdateIcon: true
  30. });
  31. }
  32. function deleteOutputFolder() {
  33. return new Promise((resolve, reject) => {
  34. rimraf(path.join(__dirname, '..', 'out', 'installers'), error => {
  35. if (error) reject(error);
  36. else resolve();
  37. });
  38. });
  39. }