Electron: Sharing the same project folder between macOS and Windows - windows

Goal
I've read many Electron tutorials about app bootstrapping and build pipeline and had assumed that you could have a single project to handle a cross-platform action.
But after numerous failures in the packaging and build process, I finally realized that maybe my assumption is wrong.
Problem
Here is my desired workflow based on electron-forge:
1. Create app skeleton on Windows
yarn create electron-app my-app
cd my-app
yarn add my-dependency
yarn start
yarn make
This all went well. Now onto macOS
2. Transfer project to macOS for a ride
On macOS, running the app will lead to an error
cd my-app
yarn start
The error looks like this
$ yarn start
yarn run v1.22.4
$ electron-forge start
✔ Checking your system
✔ Locating Application
✔ Preparing native dependencies: 1 / 1
✔ Launching Application
/path/to/my-app/node_modules/electron/dist/electron.exe: /path/to/my-app/node_modules/electron/dist/electron.exe: cannot execute binary file
error Command failed with exit code 126.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
So I blindly reinstall electron on macOS
yarn add electron
yarn start
yarn make
Things work fine on macOS.
Now back to Windows.
3. Travel back to Windows to double-check
This time. I got the similar problem as in Step #2. The Windows distribution now has the wrong Electron binary.
Findings
I found this file constantly getting overwritten even if I merge carefully when transferring project files between Windows and macOS.
my-app/node_modules/electron/path.txt
It contains a hardcoded path to Electron executable:
macOS
Electron.app/Contents/MacOS/Electron
Windows:
electron.exe
Workarounds
I could add pre-build steps against this by copying predefined metadata to the project folder depending on the current platform. But a hack like this sounds lame for a framework like Electron.
Question
So to me this metadata arrangement makes it difficult to share the same project between Windows and macOS. I can't imagine Electron developers working like this.
So What am I missing?

Basically, you shouldn't commit node_modules at all. Some post installation scripts may compile packages for a specific OS and the folder is usually huge.
Also, you shouldn't commit any result of a build, package or compile command. Typically, dist folders should be ignored.
Your repository should only contains code and configuration files.
The idea is that it makes no sense to commit these files and folders as you have all the required steps in order to reproduce the result on any machine: your windows computer, your macOS computer, your CI environment, etc. For example (these are pseudo-commands):
npm i or npm ci
npm run build
electron package
etc
So you should add all these folders to you .gitignore file:
# compiled output
/dist
/tmp
/out-tsc
/packages
# dependencies
/node_modules

Related

GraalVM installation directory not found

On MacOS 10.15.5, running IntelliJ Ultimate 2020.2.2.
I am trying to build a test project with Gluon using GraalVM via the client-gradle-plugin(0.1.32). I've followed all the setup listed in the README and GraalVM's docs as follows:
Download the latest GraalVM for mac from here
Unpack the tar and sudo mv it to /Library/Java/JavaVirtualMachines
Added the following to .zshrc:
export PATH=$PATH:/Library/Java/JavaVirtualMachines/graalvm-ce-java11-20.2.0/Contents/Home/bin
export JAVA_HOME=/Library/Java/JavaVirtualMachines/graalvm-ce-java11-20.2.0/Contents/Home
export GRAALVM_HOME=$JAVA_HOME
Set my Project SDK to point to the same place as $GRAALVM_HOME (not sure this was needed?)
My project builds and runs just fine on the desktop, but I am now trying to target iOS. I got to the point where it was trying to find my iOS sdk so I was double checking my XCode setup to try and connect the dots.
Suddenly, when running sudo ./gradlew build nativeBuild I started getting the same error I had been stuck on for a long time:
GraalVM installation directory not found. Either set GRAALVM_HOME as an environment variable or set graalvmHome in the client-plugin configuration
If I echo $GRAALVM_HOME I get /Library/Java/JavaVirtualMachines/graalvm-ce-java11-20.2.0/Contents/Home so things seem like they're set up correctly. I've tried to reset everything from the IDE, the computer, the GraalVM install and I can't come up with a way to get back to where my nativeBuild gets past this point.

Why is my ember-cli build time so slow on windows?

Ember-cli is building very slowly with ember server on windows.
Build successful - 13126ms.
Slowest Trees | Total
-------------------------------+----------------
TreeMerger (vendor) | 3154ms
TreeMerger (stylesAndVendor) | 2051ms
TreeMerger (appAndDependencies) | 1914ms
StaticCompiler | 1791ms
This is in contrast to the same project building in less that 1 second on a linux box.
There are two big culprits:
Real time file system scanning or protection
Realtime-protection from Windows Defender (also know as Microsoft Security Essentials in win7)
Windows Search Indexing
Antivirus scanning
Unused files in your bower_components folder
Real time Scanning
During a build numerous files are generate in the ./tmp folder of the ember project, both the indexer and the realtime-protection make additional reads of each file which adds a significant amount of additional file I/O operations.
The fix is to:
exclude node.exe and/or the ./tmp folder from realtime-protection, and
exclude the folder from indexing.
Disable real-time antivirus scanning
This should get your build time down to a couple seconds. Additional speed improvements for Windows are being investigated continuing to be investigated in relation to Broccoli's handling of the build process.
Managing unused bower files
Having lots of files in the bower_components is the biggest culprit.
I wrote up a script, clean-ember-cli.js, that deletes everything but ember-cli dependancies, and anything imported in the Brocfile.js. I'm getting back to around 5 second build times.
Update
Reports are that running console as admin also helps.
Official recommendation from ember-cli to improve its performance on windows
Install ember-cli-windows with node using the below command
npm install -g ember-cli-windows
Run the following command on your project root folder
ember-cli-windows
mind one important thing... and I didn`t found out in any forum... if you are working with a laptop and you are not connected with AC, windows may run in low performance mode to keep battery. This cause ember build proyects 4 times slower
Using ember-cli 1.13.13 with a command prompt running as an administrator fixed it for me
In addition to answers provided above run
ember s
in powershell in admin mode. This enables symlinks which are not enabled by default in windows. Having symlinks creates a flatter node_modules folder which results in faster running times.
(Source)
From build 20262 Windows 10 have WSL 2.
This is Linux on your machine and gives us performance as good as
on Linux.
Get last Ubuntu from Microsoft store.
Do not use /mnt/ folder for repo because of slow speed,
use ~ folder.
Connect with terminal on Ubuntu and clone your repository.
cd ~
git clone your-repo
install node version manager and node
Install ember-cli and start server.
npm install -g ember-cli
cd ~/your-repo
npm i
ember serve
In VSCode install plugin "Remote - WSL", open your repo and start development.
With Windows 7 I got a 50% improvement by turning off Encrypting File System (EFS) for the project's /tmp directory. (right-click Properties->Advanced->Encrypt contents...)
For later versions of Ember CLI running in admin mode as mentioned here and suggested by D-Go in his answer seems to be the way to go, assuming your company allows this.
If like me you are using GIT Bash to run Ember you may be interested in how to set it up to automatically run in admin mode here

Grunt, Cordova & Windows Phone

I am developing an app for multiple platforms using Cordova. Grunt is used as a build tool. I use it to copy my source code to the right folder for each platform so I can develop them independently.
This works fine with Android using the scripts that are provided by Cordova. However, I have no idea if or how it is possible to automate the WP build process. I'm looking for two things:
Add all files in the www directory to the VS project (it does not include files that are not added to the project, which is sad).
Build, install and run the app in the emulator. I used adb & Grunt's exec for Android which was really simple, is there something similar for WP?
If you look in a cordova windows phone project there is a directory called 'cordova' which contains scripts to do all of this.
There should be scripts to build and run your project.
The run script can pretty much do it all. You can call it like :
run --device --release
or
run --emulator --debug
or just
run
A recent commit now makes it possible to use www\** in the .csproj file, which solved my first issue.

How to run Grunt tasks during Xcode build phase?

I am developing a web application, which includes GruntJS build tasks. I deploy it using Phonegap/Cordova in the Xcode IDE.
I would like to integrate the grunt build process into my Xcode project to simplify running the project. Ideally Xcode should run all the processes that I manually invoke using the Grunt CLI beforehand.
My Gruntfile.js lies within the root Xcode project directory. I have a local grunt install (0.4.0rc4) in node_modules and grunt-cli installed globally.
project
- multiple project dirs ...
- node_modules
- www-src
- www
project.xcodeproj
Gruntfile.js
I have tried adding a custom Run script - build phase to my Xcode project with a command as simple as "grunt" which returns "grunt: command not found" during build. Clearly more effort is needed to reference grunt and/or the proper target directory.
Nice setup Gregor :-) I had exact same setup for my previous project. Here is how I setup my custom script in Xcode Build Phases:
cd "${PROJECT_DIR}"
PATH=${PATH}:/usr/local/bin
grunt
Hope this helps you :-)

JarBundler ant task build (OS X) which does not start in mac's /Application folder - permission denied

I have used the jarbundler ant task to create an OSX (10.6.4) XXX.app for my java app. The problem is that it starts fine in any other directory except the /Applications directory. A look at file permissions shows nothing amiss. I can get it to work by two methods - both not suitable for real deployments:
Build the .app with Jar Bundler GUI (hard to automate repeatedly)
Start and stop the .app file in another directory (e.g. my build dir) and then copy the .app file into /Applications/MyAppDir (not a solution for a install script!). It then works !
The error in OS X console is:
posix_spawn("/Applications/JyroJMS.app/Contents/MacOS/JavaApplicationStub", ...): Permission denied
I have tried various options in Jar bundler task like StartOnMainThread=true.
Any suggestions ?
I have found the problem(s):
1. I am using izpack to deploy the app bundle in a mistaken effort to standardized install process across platforms. This was causing issues with JavaApplicationStub execute permissions.
2. Also jarbundler.jar ant task is apparently using an old JavaApplicationStub. When I replaced it with java 6 version all went well.
So lessons learnt:
- I will not try to create a 'universal' installer - this does not work
- Will use compressed disk images to deploy my app bundle

Resources