简体   繁体   中英

Running package.json scripts of external libraries JS

I have a created library that has a script called "versionator": "node app.js" inside package.json. But currently, other projects that download this library can only use it by importing the module as:

const versionator = require("versionator")
versionator()

Is there a way that i can run the script called "versionator" that is inside my library folder from another projects that download this lib?

repo: https://github.com/sousadiego11/versionator-js

在此处输入图像描述

What you need is to specify a bin object inside your package.json

https://docs.npmjs.com/cli/v8/configuring-npm/package-json#bin

{
  "bin": {
    "versionator": "./app.js"
  }
}

This will create a bin called versionator.

Edit:

As CherryDT pointed out in his comment you can call it then via

npx versionator

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM