2

I need to generate two apps from the same codebase (e.g. "pro" and "lite" versions). There are a lot of questions here about this but none I found involve node or electron.

I have only used env in development in very simple ways and after searching around, I haven't seen any mention of being able to use them in a deployed application.

So two tasks:
1. Changing the name of the app

So, using the package.json file with electron builder, I've tried to change the productName like this:

  "productName": process.env.APP_NAME,
  "main": "main.js",
  "scripts": {
    "package-mac": process.env.APP_NAME='Bingo' electron-packager . --overwrite  --platform=darwin --arch=x64  --prune=true --out=release-builds"
}

But that didn't work. Also saw this construction but it also didn't work:

  "productName": '${process.env.APP_NAME}',

Am I on the wrong track here?

2. Vars for use at runtime
To do the "pro" & "lite" thing, I need at least a flag to know how to configure things.
Are env vars in anyway suitable for this?

I guess if I am able to change the app name, I can access that at runtime but it seems like I am missing something important with all this.

spring
  • 18,009
  • 15
  • 80
  • 160
  • 1
    As far as I'm aware you would have to build a shim/pass-through program that would alternate versions based on input. a.e. a `.bat` file or a separate `node` app that would determine and run the build differently. This is because there's no JS involved when it gets up and running for distribution, it's all configuration, so setting a flag *in* the config isn't possible. – zfrisch Jul 03 '19 at 21:29

1 Answers1

1

Using dot-json, you can have npm scripts like:

  "productName": "Bingo",
  "main": "main.js",
  "scripts": {
    "package-mac": "echo $APP_NAME; dot-json package.json productName $APP_NAME --indent 2; electron-packager . --overwrite  --platform=darwin --arch=x64  --prune=true --out=release-builds"
  }

In Terminal, maybe, you can run

 $ APP_NAME='Bingo Pro' npm run package-mac
Akinjide
  • 2,723
  • 22
  • 28
  • Thanks for the reply. I wasn't able to get that to work – got the `"Usage"` man page from `dot-json`. – spring Jul 03 '19 at 23:01