I want to make an electron exe file, when launched, the WebdriverIO test is executed and the Allure-report is generated with the output of the result, at the moment I am doing the test with the npm test command, then I am generating the report with the allure generate --clean allure-results command and then I am making the exe file with the command electron builder --win, is it possible to do what I want or not? If possible please tell me how
My wdio.conf:
{
"name": "electron",
"version": "1.0.0",
"main": "main.js",
"scripts": {
"start": "electron .",
"test": "wdio"
},
Related
After building the electron application using electron-builder, I cannot open the application from the dist folder. I did change all my links to use path.join(__dirname, "relative_path/") as what I have seen in some answers here. But I can't open the application even though the packaging process is successful.
File structure for the electron app project
Here's an image of my file structure, and this is the package.json file of the project
{
"name": "my_little_reminder",
"version": "0.5.0",
"description": "A simple time reminder app",
"main": "src/index.js",
"scripts": {
"start": "electron .",
"test": "jest --coverage",
"build": "electron-builder --dir"
},
"author": "Leonlit",
"license": "MIT",
"dependencies": {
"node-notifier": ">=8.0.1",
"node-schedule": "^1.3.2",
"sqlite3": "^5.0.0",
"electron-log": "^4.3.1"
},
"devDependencies": {
"electron": "^11.2.1",
"electron-builder": "^22.9.1",
"jest": "^26.6.3"
}
}
Finally, here's a link to the repository if the information here is not enough, https://github.com/Leonlit/My-Little-Reminder/tree/development
Resolved the issue by adding and using the npm script "postinstall": "electron-builder install-app-deps".
Then, using path.join(app.getPath('userData'), '/tasks.db') instead of path.join(__dirname, '/tasks.db') for the sqlite database storage location.
Finally, changed a link in the index file which caused the application to always request for saving a ASAR file on app launch if left unfixed.
My compiled app don't run and i don't know why ...
electron-installer-debian -> 3.0.0
node -> 8.16.0
npm -> 6.4.1
operating system ->ubuntu 16.04.6 amd64
I can compile the example app successfully.
I can compile my app successfully.
What did i do
package.json content
{
"name": "electron-quick-start",
"version": "1.0.0",
"description": "A minimal Electron application",
"main": "main.js",
"scripts": {
"start": "electron .",
"build": "electron-packager . electron-quick-start --platform linux --arch x64 --out dist/",
"deb64": "electron-installer-debian --src dist/electron-quick-start-linux-x64/ --dest dist/installers/ --arch amd64"
},
"repository": "https://github.com/electron/electron-quick-start",
"keywords": [
"Electron",
"quick",
"start",
"tutorial",
"demo"
],
"author": "GitHub",
"license": "CC0-1.0",
"devDependencies": {
"electron": "^8.2.5",
"electron-installer-debian": "^3.0.0",
"electron-packager": "^14.2.1"
}
}
I compile my app successfullt by executing npm run build to build my app with electron-packager then i do npm run deb64 to compile my code.
It return a successfull sentence.
Then i find my electron-quick-start_1.0.0_amd64.deb in the dist/installers folder and install it successfully (no error of any kind).
What did you expect to happen?
I expect to run my app by searching it in the ubuntu search bar.
What actually happened?
The app juste don't run. No error pop up. Nothing ... :'(
Even if i try to run it from terminal
see the image
electron-installer-debian creates dab file which by default installs your app in usr/lib folder. If you navigate to usr/lib//resources/ give permissions to your app folder your app should work, but this is not recommended for security reasons.
I just wrote my first Electron app. Now I'm trying to build it through electron-packager. My package.json looks like this:
{
"name": "pixelcast",
"productName": "pixelcast",
"version": "0.0.1",
"author": "Wesley Peeters <wesley#youngones.works>",
"description": "Caster",
"license": null,
"main": "./dist/electron/main.js",
"scripts": {
"build": "node .electron-vue/build.js",
"build:darwin": "cross-env BUILD_TARGET=darwin node .electron-vue/build.js",
"build:linux": "cross-env BUILD_TARGET=linux node .electron-vue/build.js",
"build:mas": "cross-env BUILD_TARGET=mas node .electron-vue/build.js",
"build:win32": "cross-env BUILD_TARGET=win32 node .electron-vue/build.js",
"build:clean": "cross-env BUILD_TARGET=clean node .electron-vue/build.js",
"build:web": "cross-env BUILD_TARGET=web node .electron-vue/build.js",
"dev": "node .electron-vue/dev-runner.js",
"pack": "build --dir",
"dist": "build",
"pack:main": "cross-env NODE_ENV=production webpack --progress --colors --config .electron-vue/webpack.main.config.js",
"pack:renderer": "cross-env NODE_ENV=production webpack --progress --colors --config .electron-vue/webpack.renderer.config.js",
"postinstall": ""
},
"build": {
"appId": "nl.pixelservers.caster",
"win": {
"icon": "build/test.png",
"target": [
"portable"
]
}
},
}
this all works fine, but when I open the built app, this is my result:
How can I go about debugging an issue like this?
thanks.
(This might be more of a "comment" than an answer but I couldn't add the detail and image in comment)
It is hard to say without knowing how your project is structured. I use both electron-packager and electron-builder. The "dist" directory is solely for output so it is weird to me that you are referencing a script in that directory:
"main": "./dist/electron/main.js",
Given my project structure (shown below), I have "main.js" at the same level as "project.json" so:
"main": "main.js",
But maybe you have your project structured in a way which supports the way you are referencing "main.js"? . I'm using only electron-packager in the project below so no "dist" folder – I have the "release-builds" folder instead. My scripts for building look like this:
"package-mac": "electron-packager . --overwrite --platform=darwin --arch=x64 --asar --prune=true --out=release-builds",
"package-win": "electron-packager . --overwrite --platform=win32 --arch=ia32 --asar --prune=true --out=release-builds"
I am trying to generate a exe file with electron-builder not an installer so I am trying by setting the target to portable
{
"name": "hello-world",
"version": "1.0.0",
"description": "a hello world",
"main": "index.js",
"scripts": {
"start": "electron .",
"dist": "build"
},
"author": "KR",
"license": "ISC",
"devDependencies": {
"electron": "^4.1.4",
"electron-builder": "^20.39.0"
},
"build":{
"appId": "com.whatever.helloworld",
"win":{
"target": ["portable"],
"icon" : "build/icon.ico"
}
}
}
However when I try npm run dist I get
Configuring yargs through package.json is deprecated and will be removed in the next major release, please use the JS API instead.
Configuring yargs through package.json is deprecated and will be removed in the next major release, please use the JS API instead.
• electron-builder version=20.39.0
• loaded configuration file=package.json ("build" field)
• writing effective config file=dist\builder-effective-config.yaml
• no native production dependencies
• packaging platform=win32 arch=x64 electron=4.1.4 appOutDir=dist\win-unpacked
• default Electron icon is used reason=application icon is not set
• building target=portable file=dist\hello-world 1.0.0.exe archs=x64
and the program is stuck for ever. When I break it(ctrl-c), it says
Error: Exit code: 255. Command failed: D:\electrontest\hello-world\node_modules\7zip-bin\win\x64\7za.exe a -bd -mx=9 -mtc=off -mtm=off -mta=off D:\electrontest\hello-world\dist\hello-world-1.0.0-x64.nsis.7z .
So I guess the program is stuck in 7za compression.
I searched and there is no example of using electron-builder with portable only few with nsis. (I have another question but first I would like to run the basics).
use electron-builder from 1
then in package.json use in scripts:
"dist": "electron-builder --win=portable",
I am using browserify to merge all the .js files of my app into a dist/main.js. My package.json looks like:
"main": "./dist/main.js",
"scripts": {
"start": "electron ./dist/main.js",
},
"bin": {
"electron": "./node_modules/.bin/electron"
}
and I can correctly run my application with npm run start.
However if in main.js I use app.getAppPath() I get:
/home/myuser/projects/electronProject/node_modules/electron/dist/resources/default_app.asar
I would expect this to be
/home/myuser/projects/electronProject/dist/main.js
Did I misunderstood the usage of this method? How can I get the path of the Electron program entrypoint? What is the role of default_app.asar?
Thanks
Why aren't you using __dirname (node.js) or process.resourcesPath (electron)?
https://github.com/electron/electron/blob/master/docs/api/process.md
https://nodejs.org/docs/latest/api/globals.html#globals_dirname
It returns the current application directory:
app.getAppPath()
Returns String - The current application directory.
From the docs.
An asar file is a simple archive format that just appends the files to each other. I'm not sure exactly how you're building the application but tools like electron-packager and electron-builder output the files into a resources/app.asar archive and run the files from there. That means that your current application directory is going to be something/resources/app.asar. From there your main file is located at something/resources/app.asar/main.js.
For whom may ran into the same problem...
It's maybe a problem with your electron configuration field main in package.json
The script specified by the main field is the startup script of your
app, which will run the main process.
The example code from offical websites:
{
"name": "your-app",
"version": "0.1.0",
"main": "main.js",
"scripts": {
"start": "electron ."
}
}
app.getAppPath() output:
YOUR_PATH_TO/electron-quick-start
If you change the code snippet to
{
"name": "your-app",
"version": "0.1.0",
"main": "main.js",
"scripts": {
"start": "electron YOUR_PATH_TO/main.js"
}
}
Then app.getAppPath() output:
YOUR_PATH_TO/electron-quick-start/node_modules/electron/dist/resources/default_app.asar
So the consolution is : If you want to change the startup script, change it in the main field, not just change it in scritps field...