Browse Source

Refactor Windows scripts to use command line argument for architecture

samjulien 8 năm trước cách đây
mục cha
commit
85445e5fa5

+ 3 - 4
package.json

@@ -17,17 +17,16 @@
 
     "sign-mac": "electron-osx-sign out/Flasher.js-darwin-x64/Flasher.js.app",
     "sign-windows": "node ./scripts/sign-windows.js",
-    "sign-windows-32": "node ./scripts/sign-windows-32.js",
+    "sign-windows-32": "node ./scripts/sign-windows.js win32",
     "sign-installer-windows": "node ./scripts/sign-installer-windows.js",
-    "sign-installer-windows-32": "node ./scripts/sign-installer-windows-32.js",
 
     "installer-windows": "node ./scripts/windows-installer.js",
-    "installer-windows-32": "node ./scripts/windows-installer-32.js",
+    "installer-windows-32": "node ./scripts/windows-installer.js win32",
     "installer-mac": "electron-installer-dmg --overwrite --out=out/ out/Flasher.js-darwin-x64/Flasher.js.app Flasher.js --icon=resources/icon.icns --background=resources/drag_to_install.png",
     "installer-linux": "electron-installer-debian --src out/flasher.js-linux-x64/ --arch amd64 --config linux-config.json",
   
     "dist-windows": "npm run pre-rebuild && npm run rebuild && npm run pack-windows && npm run sign-windows && npm run installer-windows && npm run sign-installer-windows",    
-    "dist-windows-32": "npm run pre-rebuild && npm run rebuild-32 && npm run pack-windows-32 && npm run sign-windows-32 && npm run installer-windows-32 && npm run sign-installer-windows-32",
+    "dist-windows-32": "npm run pre-rebuild && npm run rebuild-32 && npm run pack-windows-32 && npm run sign-windows-32 && npm run installer-windows-32 && npm run sign-installer-windows",
     "dist-linux": "npm run pre-rebuild && npm run rebuild && npm run pack-linux && npm run installer-linux",
     "dist-mac": "npm run pre-rebuild && npm run rebuild && npm run pack-mac && npm run sign-mac && npm run installer-mac"
   },

+ 0 - 23
scripts/sign-installer-windows-32.js

@@ -1,23 +0,0 @@
-"use strict";
-
-const fs = require("fs");
-const path = require('path');
-
-const rootPath = path.join(__dirname, '..');
-const outPath = path.join(rootPath, 'out');
-const packedPath = path.join(outPath, 'installers');
-const exec = require('child_process').execSync;
-
-fs.readdir(packedPath, (err, files) => {
-    const dllsAndExes = files.filter(file => {
-        return file.endsWith(".dll") || file.endsWith(".exe");
-    });
-    
-    dllsAndExes.forEach(run);
-});
-
-
-function run(file) {
-    exec(`signtool.exe sign /a /d "Flasher.js" /du https://github.com/ThingsSDK/flasher.js /s MY /n "Andrew Chalkley" /fd sha1 /t http://timestamp.verisign.com/scripts/timstamp.dll /v "${path.join(packedPath, file)}"`);
-    exec(`signtool.exe sign /a /d "Flasher.js" /du https://github.com/ThingsSDK/flasher.js /s MY /n "Andrew Chalkley" /fd sha256 /tr http://sha256timestamp.ws.symantec.com/sha256/timestamp /td sha256 /as /v "${path.join(packedPath, file)}"`);
-}

+ 0 - 21
scripts/sign-windows-32.js

@@ -1,21 +0,0 @@
-"use strict";
-const fs = require("fs");
-const path = require('path');
-
-const rootPath = path.join(__dirname, '..');
-const outPath = path.join(rootPath, 'out');
-const packedPath = path.join(outPath, 'flasher.js-win32-ia32');
-const exec = require('child_process').execSync;
-
-fs.readdir(packedPath, (err, files) => {
-    const dllsAndExes = files.filter(file => {
-        return file.endsWith(".dll") || file.endsWith(".exe");
-    });
-    dllsAndExes.forEach(run);
-});
-
-
-function run(file) {
-    exec(`signtool.exe sign /a /d "Flasher.js" /du https://github.com/ThingsSDK/flasher.js /s MY /n "Andrew Chalkley" /fd sha1 /t http://timestamp.verisign.com/scripts/timstamp.dll /v "${path.join(packedPath, file)}"`);
-    exec(`signtool.exe sign /a /d "Flasher.js" /du https://github.com/ThingsSDK/flasher.js /s MY /n "Andrew Chalkley" /fd sha256 /tr http://sha256timestamp.ws.symantec.com/sha256/timestamp /td sha256 /as /v "${path.join(packedPath, file)}"`);
-}

+ 6 - 1
scripts/sign-windows.js

@@ -2,9 +2,14 @@
 const fs = require("fs");
 const path = require('path');
 
+const win64 = 'win32-x64';
+const win32 = 'win32-ia32';
+const winArg = process.argv[2];
+const winExt = winArg === 'win32' ? win32: win64;
+
 const rootPath = path.join(__dirname, '..');
 const outPath = path.join(rootPath, 'out');
-const packedPath = path.join(outPath, 'flasher.js-win32-x64');
+const packedPath = path.join(outPath, 'flasher.js-' + winExt);
 const exec = require('child_process').execSync;
 
 fs.readdir(packedPath, (err, files) => {

+ 0 - 41
scripts/windows-installer-32.js

@@ -1,41 +0,0 @@
-
-"use strict";
-//Taken from Electron API Demos
-//https://github.com/electron/electron-api-demos/blob/master/script/installer.js
-
-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, 'out');
-
-  return Promise.resolve({
-    appDirectory: path.join(outPath, 'flasher.js-win32-ia32'),
-    iconUrl: 'https://raw.githubusercontent.com/thingssdk/flasher.js/resources/icon.ico', 
-    loadingGif: path.join(rootPath, 'resources', 'loading.gif'),
-    noMsi: true,
-    outputDirectory: path.join(outPath, 'installers'),
-    setupExe: 'flasher.js-setup.exe',
-    setupIcon: path.join(rootPath, 'resources', 'icon.ico'),
-    skipUpdateIcon: true
-  });
-}
-
-function deleteOutputFolder() {
-  return new Promise((resolve, reject) => {
-    rimraf(path.join(__dirname, '..', 'out', 'installers'), error => {
-      if (error) reject(error);
-      else resolve();
-    });
-  });
-}

+ 6 - 1
scripts/windows-installer.js

@@ -7,6 +7,11 @@ const createWindowsInstaller = require('electron-winstaller').createWindowsInsta
 const path = require('path');
 const rimraf = require('rimraf');
 
+const win64 = 'win32-x64';
+const win32 = 'win32-ia32';
+const winArg = process.argv[2];
+const winExt = winArg === 'win32' ? win32: win64;
+
 deleteOutputFolder()
   .then(getInstallerConfig)
   .then(createWindowsInstaller)
@@ -20,7 +25,7 @@ function getInstallerConfig() {
   const outPath = path.join(rootPath, 'out');
 
   return Promise.resolve({
-    appDirectory: path.join(outPath, 'flasher.js-win32-x64'),
+    appDirectory: path.join(outPath, 'flasher.js-' + winExt),
     iconUrl: 'https://raw.githubusercontent.com/thingssdk/flasher.js/resources/icon.ico', 
     loadingGif: path.join(rootPath, 'resources', 'loading.gif'),
     noMsi: true,