ruyadorno / ntl

Node Task List: Interactive cli to list and run package.json scripts
https://www.npmjs.com/package/ntl
MIT License
935 stars 35 forks source link

using a seperate file to define scripts and paching them into package.json #63

Open KilianKilmister opened 4 years ago

KilianKilmister commented 4 years ago

Is there any interest for adding the possibility to patch the package.json with scripts defined in a seperate file?

It wouldn't be hard to implement and would allow users to use YAML, JS or JSON5 and their pleasantness. This would also allow the command and the description to be right next to eachother, which i would like

command could look like this:

ntl -p/--patch path/to/file (defaulting to <pkg-root>/.ntlrc.<ext>)

so the structure would be something like:

{
    "build": {
      "command": "make build",
      "description": "Builds the project"
    },
    "coverage": {
      "command": "jest --coverage",
      "description": "Run test outputing code coverage"
    },
    "test": {
      "command": "jest"
    },
  // or if it has no desc, a shorthand
  "lint": "standard src/**/*.js"
}

this could be used together with general configs #23 like:

{
  // config properites...
 "scripts": {
  // like above...
  }
}

this would also expose a common surface for a module that extends ntl, as config properties can be easily added. we could also add a complementary API that lets you import these scripts (for eg. for usage with npm run-script)

this could also be extended down the line to rather easily implement monorepo support #58 via a 'namespace': {<name>: <path/to/package>} property or something like that.

I'm planning on writing a patcher that does something like this (without the many practicallity featueres of course) for a module i'm writing. so if there is interest in this, i could provide a fundament and help with the further implementation

ruyadorno commented 4 years ago

That sounds like something that would be interesting to have for sure! 😄 As you pointed out I think the place to start would be to get a proper file config as discussed in #23 so that we could also allow scripts/descriptions/more metadata to live there and be more flexible with regards to user format preference.

I don't even think it would need to be behind a flag such as --patch and would just make it the default behavior for any scripts defined in your .ntlrc file to overwrite the ones defined in package.json