From 10c338bf1b5fd7c259a2e87dd2986fd876fa32d5 Mon Sep 17 00:00:00 2001 From: toddtarsi Date: Mon, 25 Dec 2023 05:15:45 -0700 Subject: [PATCH] troubleshooting npx distribution --- packages/selenium-ide/bin.js | 39 ++++++++++++++++++++++++------ packages/selenium-ide/package.json | 2 +- 2 files changed, 32 insertions(+), 9 deletions(-) diff --git a/packages/selenium-ide/bin.js b/packages/selenium-ide/bin.js index cc3c562f5..28654d05c 100644 --- a/packages/selenium-ide/bin.js +++ b/packages/selenium-ide/bin.js @@ -1,11 +1,34 @@ #!/usr/bin/env node -const { join } = require('path'); -const { spawn } = require('child_process'); -const electronPath = require('electron'); +const { join } = require('path') +const { spawn } = require('child_process') -const appPath = join(__dirname, 'build', 'main-bundle.js'); +const { execSync } = require('child_process') +const fs = require('fs/promises') -const electronProcess = spawn(electronPath, [appPath]); -electronProcess.stdout.on('data', (data) => process.stdout.write(data)); -electronProcess.stderr.on('data', (data) => process.stderr.write(data)); -electronProcess.on('close', (code) => process.exit(code)); +async function installElectron() { + // Read package.json + const packageJson = JSON.parse(fs.readFile('package.json', 'utf8')) + // Get the Electron version from package.json + const electronVersion = packageJson.devDependencies.electron + // Install Electron + console.log(`Installing Electron ${electronVersion}...`) + execSync(`npm i electron@${electronVersion}`, { stdio: 'inherit' }) + console.log('Electron installed successfully.') +} + +const main = async () => { + let electronPath + try { + electronPath = require('electron') + } catch (e) { + await installElectron() + } + electronPath = require('electron') + const appPath = join(__dirname, 'build', 'main-bundle.js') + const electronProcess = spawn(electronPath, [appPath]) + electronProcess.stdout.on('data', (data) => process.stdout.write(data)) + electronProcess.stderr.on('data', (data) => process.stderr.write(data)) + electronProcess.on('close', (code) => process.exit(code)) +} + +main() diff --git a/packages/selenium-ide/package.json b/packages/selenium-ide/package.json index c93564af2..e1800f5f3 100644 --- a/packages/selenium-ide/package.json +++ b/packages/selenium-ide/package.json @@ -1,6 +1,6 @@ { "name": "selenium-ide", - "version": "4.0.1-alpha.65", + "version": "4.0.1-alpha.66", "private": false, "description": "Selenium IDE electron app", "author": "Todd ",