npm pre/post hook with wildcard match

Viewed 1297

Let's say I have the following scripts in my package.json

{
  "scripts": {
     "release:public": "....",
     "release:beta": "...."
  }
}

But now I want to add a prerelease script that is identical for both release:public and release:beta. Is that possible to have a prerelease:* or another way to runs before both scripts?

1 Answers

I do understand your question and the example from RobC is usable, but the naming was not recommended. When you use pre in a script command name followed by a command name that also exists. The part wil run before (previous) the other (https://docs.npmjs.com/cli/v8/using-npm/scripts#npm-run-user-defined)

{
 ...
  "scripts": {
    "beforerelease": "....",
    "release:public": "npm run beforerelease && ....",
    "release:beta": "npm run beforerelease &&  ...."
  },
  ...
}

But that is an even amount of work then using the pre-tag functionality like this

    {
 ...
  "scripts": {
    "prerelease:public": "....",
    "release:public": "....",
    "prerelease:beta": "....",
    "release:beta": "...."
  },
  ...
}

Like Kousha probably has, i have a package with a lot of different run scripts. And i want to use one script that runs before a lot of the others. So the question is still standing: Is it possible in any way to use wildcards in de command part of a script tag in a package.json?

Related