Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hope build command can add options for conditional compilation #494

Closed
towertop opened this issue Jun 13, 2016 · 6 comments · May be fixed by qcif/data-curator#563
Closed

Hope build command can add options for conditional compilation #494

towertop opened this issue Jun 13, 2016 · 6 comments · May be fixed by qcif/data-curator#563
Labels

Comments

@towertop
Copy link

I'm using electron-builder 5.1.0 to generate an installer for my app. I hoped the build command can help me a way to run some logging or checking code only in test version but it looks not support this yet.

My idea is like to add an option "--add-pakcage-json-field" to build command. It only put the given field and string to the application package.json.

So I use command:
build --win --x64 --add-package-json-field "env" "test"

My app get a modified package.json:

{
// other fields like name, version
// and a new item appended
"env": "test"
}

That way I can check the 'env' field in code and package my app in 2 commands, rather than modifying code manually.

Look forward to this feature if possible.

@develar
Copy link
Member

develar commented Jun 13, 2016

Why you have to modify package.json? Why not just put some magic file using https://github.com/electron-userland/electron-builder/wiki/Options#BuildMetadata-extraResources into the app resources and then check/read file in the app code?

@towertop
Copy link
Author

Putting a magic file doesn't reduce more developers' manual work.

The ideal way is the build command can generate 2 versions of installer.

For example I write development package.json as:

{
  "scripts" : {
    "test": "build --win --x64 --add-package-json-field env test",
    "dist": "build --win --x64 --add-package-json-field env production"
  }
}

Then I can simply type 'npm test' to generate a test installer which would dump much logs for debugging. And typing 'npm dist' can get another installer for the final distribution.

I mentioned to put the condition field in package.json, it is for I usually read in name, version, and other metadata of app from it. It should be easy to test the env field and decide whether to do logging.

@develar
Copy link
Member

develar commented Jun 14, 2016

I mentioned to put the condition field in package.json, it is for I usually read in name, version, and other metadata of app from it

Important clarification, so, now is clear that magic file will just add complexity to your code.

@develar
Copy link
Member

develar commented Jun 14, 2016

Why not just check

export function isDev() {
  return app.getAppPath().includes("/node_modules/electron-prebuilt/")
}

?

@towertop
Copy link
Author

export function isDev() {
return app.getAppPath().includes("/node_modules/electron-prebuilt/")
}

This way only helps when developing in the workspace folder but not in an installation. After getting the application installed from the installer, it includes no electron-prebuilt. I think it is still helpful to be able to do logging conditionally in that situation.

@develar
Copy link
Member

develar commented Jul 31, 2016

Fixed. For ASAR only.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants