简体   繁体   English

自定义节点模块以安装依赖项

[英]Custom Node module to install dependencies

Currently I have a custom Yeoman generator for some applications. 目前,我为某些应用程序定制了Yeoman生成器。 This generator requires some dependencies and configurations. 该生成器需要一些依赖关系和配置。

1 - GruntJS to be installed globally; 1-将在全球范围内安装GruntJS;

2 - Bower to be installed globally; 2-Bower将在全球范围内安装;

3 - Yeoman to be installed globally; 3-Yeoman将在全球范围内安装;

4 - Some other configurations to be in place; 4-其他适当的配置;

Question : Is there any tool to manage this dependencies work flow? 问题 :是否有任何工具可以管理此依赖关系工作流程?

Optimally, I'm hoping for a two-step process 理想情况下,我希望分两个步骤进行

1 - Install Node.Js 1-安装Node.Js

2 - npm install my-generator 2-NPM安装我的发电机

The second step will be responsible for installing all the packages globally. 第二步将负责全局安装所有软件包。

I saw some examples that used preinstall script in the package.json like below: 我在package.json中看到了一些使用预安装脚本的示例,如下所示:

...
scripts: {
  preinstall: 'npm install bower -g; npm install grunt-cli -g'
}
...

This solution did not work for me and I also read in several places that this is an anti-pattern. 该解决方案对我不起作用,我还在几个地方读到这是一种反模式。

Any help appreciated! 任何帮助表示赞赏!

It's antipattern because npm normally downgrades the superuser permission before execute preinstall scripts. 这是反模式,因为npm通常在执行预安装脚本之前会降级超级用户权限。 But in order to install global packages you have to execute it as sudo . 但是要安装全局软件包,您必须以sudo身份执行它。 The problem is that you need to make your instalation unsafe by giving superpowers to npm install scripts. 问题是您需要通过赋予npm安装脚本超级权限来使安装不安全

You can do it by creating a .npmrc file in your project root directory with the following content: 您可以通过在项目根目录中创建一个.npmrc文件来实现以下目的:

unsafe-perm = true

You package.json will look like: 您的package.json将如下所示:

{
  "name": "foo",
  "version": "1.4.4",
  "scripts" :  { 
    "preinstall" : "npm install -g bower; npm install -g grunt-cli"
  }
}

Then you can run 那你就可以跑

sudo npm install

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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