Npm 使用模块创建自定义终端命令

Npm 使用模块创建自定义终端命令,npm,Npm,我正在编写一个节点模块来生成必要的redux文件。我的目标是让最终用户运行npm install——保存redux文件gen,然后能够直接从终端运行redux generate store,而不是运行节点…. 下面是我的包.json的重要部分 { "name": "redux-file-gen", "version": "1.0.8", "description": "Generates necessary files for react-redux application",

我正在编写一个节点模块来生成必要的redux文件。我的目标是让最终用户运行
npm install——保存redux文件gen
,然后能够直接从终端运行
redux generate store
,而不是运行
节点….

下面是我的
包.json的重要部分

{
  "name": "redux-file-gen",
  "version": "1.0.8",
  "description": "Generates necessary files for react-redux application",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
  },
  "preferGlobal": "true",
  "bin": {
    "redux": "index.js"
  },
  "dependencies": {
    "colors": "^1.1.2",
    "shelljs": "^0.7.5"
  }
}
我可以在自己的机器上运行
npm link
,以创建自定义终端命令。但是当我发布到npm并将其安装到另一台机器上时,
redux
命令未定义

我尝试使用
postinstall
让npm运行
npm链接
,但这不起作用

现在,为了运行我的生成器,用户必须运行

node node_modules/redux-file-gen/index.js
有人知道如何解决这个问题吗


下面是节点模块的链接

我找到了答案。为了能够在终端中使用
redux
命令,我必须全局安装该软件包。所以,我只需要跑步

npm install -g redux-file-gen
这将允许我使用自定义命令