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

Override a tasks with tasks.local.json #156

Open
deRockerTom opened this issue Dec 21, 2023 · 1 comment
Open

Override a tasks with tasks.local.json #156

deRockerTom opened this issue Dec 21, 2023 · 1 comment

Comments

@deRockerTom
Copy link

Hi!

I've started to use the extension and I found something that could we useful when merging tasks. Sometimes we just want to override a tasks and we want to keep other ones from the tasks.shared.json

Example

tasks.shared.json

{
  "version": "2.0.0",
  "tasks": [
    {
        "label": "A",
        "type": "shell",
        "command": "script A",
        "problemMatcher": [],
        "runOptions": {
              "runOn": "folderOpen",
          },
    },
    {
        "label": "B",
        "type": "shell",
        "command": "script B",
        "problemMatcher": [],
    },
  ]
}

tasks.local.json

{
  "version": "2.0.0",
  "tasks": [
    {
        "label": "A",
        "type": "shell",
        "command": "script A",
        "problemMatcher": [],
    },
  ]
}

Actual tasks.json with "arrayMerge": "overwrite"

{
  "version": "2.0.0",
  "tasks": [
    {
        "label": "A",
        "type": "shell",
        "command": "script A",
        "problemMatcher": [],
    },
  ]
}

Actual Actual tasks.json with "arrayMerge": "combine"

{
  "version": "2.0.0",
  "tasks": [
    {
        "label": "A",
        "type": "shell",
        "command": "script A",
        "problemMatcher": [],
        "runOptions": {
              "runOn": "folderOpen",
          },
    },
    {
        "label": "B",
        "type": "shell",
        "command": "script B",
        "problemMatcher": [],
    },
    {
        "label": "A",
        "type": "shell",
        "command": "script A",
        "problemMatcher": [],
    },
  ]
}

tasks.json with this functionality

{
  "version": "2.0.0",
  "tasks": [
    {
        "label": "A",
        "type": "shell",
        "command": "script A",
        "problemMatcher": [],
    },
    {
        "label": "B",
        "type": "shell",
        "command": "script B",
        "problemMatcher": [],
    }
  ]
}
@deRockerTom
Copy link
Author

After looking a bit at deepMerge, a function like this could maybe be used to merge tasks array :

function arrayMerge(destination, source, _option) {
  const result = source.slice(0);
  destination.forEach((item) => {
    if (!result.find((resultItem) => resultItem.label === item.label)) {
      result.push(item);
    }
  });
  return result;
}

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

No branches or pull requests

1 participant