How to set relative path in a .js file which works inside a executable(windows exe) file for below scenario

15 Views Asked by At

I created a node exe using below package.json with pkg.

{
  "name": "appium",
  "version": "2.5.1",
  "description": "Appium Server",
  "main": "index.js",
  "scripts": {
    "test": "appium"
  },
   "bin": {
    "appium": "./index.js"
  },
  "author": "test",
  "license": "ISC",
  "dependencies": {
    "appium": "^2.5.1",
    "appium-uiautomator2-driver": "^3.0.2",
    "appium-xcuitest-driver": "^7.3.1",
    "pkg": "^5.8.1"
  },
  "devDependencies": {
    "appium-uiautomator2-driver": "3.0.2",
    "appium-xcuitest-driver": "7.3.1"
  },
  "pkg": {
    "targets": [
      "node16-win-x64"
    ],
    "assets": [
      "."
    ],
    "outputPath": "dist"
  }
}

This creates the appium exe and it works. The problem here is, the appium looks for it's driver in the user's home folder as it defined in it's file.

exports.DEFAULT_APPIUM_HOME = path_1.default.resolve((0, os_1.homedir)(), '.appium');

the above code is defined in the below file. C:\Users\user\Desktop\newServer\node_modules@appium\support\build\lib\env.js

Now, Inside this folder "C:\Users\user\Desktop\newServer\node_modules" I've added appium and it's drivers also using these commands "npm install –save appium" , "npm install –save appium-xcuitest-driver". So, the node_modules has these drivers as well.

Now, I want to change the appium home path in the env.js file to look in the node_moduels folder instead of user's home folder. This should work after creating the exe file.

Basically, the exe will have the node_modules folder in it as per the above packages.json. So after changing the path in the env.js file, it should take the driver which is already located in the exe file.

The ultimate goal, appium server and it's driver should be in a single exe file and it should work in any system.

I tried changing the path in different ways.. But it's not working as expected.

So , any help on this please.

0

There are 0 best solutions below