For instance, setting the app-version option would not only change the "ProductVersion metadata property on Windows, and CFBundleShortVersionString on OS X", but would also change version in the packaged app's package.json. This way, accessing app.version from Electron will return the version passed to electron-packager, and not the original version.
As far as I can tell, this would only apply to the version and name options. I think name should modify productName in package.json.
IMHO, this should eventually be made the default behavior, but that would require a major version change.
If this sounds good, I might go ahead and work on a PR for this.
Just so I'm clear about the feature you're requesting, you could like Electron Packager to update the version field of the Electron app's package.json if, for example, --app-version=1.2.3 is specified on the command line? If this is accurate, what is the use case for this feature?
Yes, but it would only update the version of package.json located in the temp directory for packaging. The main source code would be unchanged.
My use case for this feature is to have a script that uses electron-packager to make a test version of the app. The electron-packager name option would include the word "test". The packaged test app would then be able to check for the word test and modify its behavior as discussed here.
I'm not inclined to add this functionality to Electron Packager, partly because I don't see a broader use case for it, and partly because I think it will make the code base messier than it already is.
However, you can implement it for your app by using an afterCopy hook with the packager API:
const packager = require('electron-packager');
const packagerOptions = {
// ...
afterCopy: (buildPath, electronVersion, platform, arch, callback) => {
// read package.json from buildPath
// modify deserialized package.json
// write new package.json contents
callback();
}
// ...
};
packager(packagerOptions, (err, appPaths) => { /* ... */ });
OK, thanks for reminding me about afterCopy. That should do nicely.
electron-builder for such use case supports --extraMetadata — ability to inject/modify package.json (e.g. https://github.com/electron-userland/electron-builder/issues/639#issuecomment-237545651). Because in general such options should be inferred from package.json, not vice versa.
Most helpful comment
I'm not inclined to add this functionality to Electron Packager, partly because I don't see a broader use case for it, and partly because I think it will make the code base messier than it already is.
However, you can implement it for your app by using an afterCopy hook with the packager API: