bennymeg / nx-electron

Electron schematics for nrwl nx platform
Apache License 2.0
328 stars 85 forks source link

Files in maker.options should allow relative paths #169

Closed paustint closed 2 years ago

paustint commented 2 years ago

Is your feature request related to a problem? Please describe. When adding additional files to maker.options.json, an absolute file path is required for the files to be copied, but this is not transferrable between different computers or CI.

"files": [
  {
    "from": "/Users/foo/dev/node/bar/dist/apps/electron/worker",
    "to": "electron/worker",
    "filter": ["main.js", "assets"]
  },
  {
    "from": "/Users/foo/dev/node/bar/dist/apps/electron/preferences",
    "to": "electron/preferences",
    "filter": ["**/!(*.+(js|css).map)", "assets"]
  }
],

Describe the solution you'd like I should be able to use a relative path, such as apps/electron/worker and this should be transformed into an absolute path during the packaging process when builder-effective-config.yaml is generated.

Describe alternatives you've considered I have found two workarounds:

  1. use full filepaths (not transferrable between computers)
  2. Modify the filepath in a custom beforePack script and add in the path
// assume this is in the options
// "from": "${CWD}/dist/apps/electron/worker",

exports.default = async function (context) {
  context.targets.forEach((target) => {
    target?.packager?.info?._configuration?.files?.forEach((file) => {
      if (file.from) {
        file.from = file.from.replace('${CWD}', process.cwd());
      }
    });
  });
};

Additional context If I am missing anything, please let me know - I have tried all sorts of different relative file paths and none have been successful so far.

bennymeg commented 2 years ago

Added in v13.2.1

Edit: All the source paths are now resolved against <root>/dist/apps/

Example usage: (as per #155)

"files": [
    {
        "from": "<backend-project>/build",
        "to": "build",
        "filter": ["*.node"]
    }
],