有没有办法为Node.js项目自动构建package.json文件

Is package.json supposed to be manually edited? 是否应该手动编辑package.json? Couldn't a program like npm j
摘要由CSDN通过智能技术生成

本文翻译自:Is there a way to automatically build the package.json file for Node.js projects

Is package.json supposed to be manually edited? 是否应该手动编辑package.json? Couldn't a program like npm just look through the files, see the "require" statements, and then use that to put the necessary entries in the package.json file? 像npm这样的程序难道只能查看文件,查看“require”语句,然后使用它将必要的条目放在package.json文件中吗? Are there any programs like that? 有没有这样的节目?


#1楼

参考:https://stackoom.com/question/fnRO/有没有办法为Node-js项目自动构建package-json文件


#2楼

I just wrote a simple script to collect the dependencies in ./node_modules. 我刚写了一个简单的脚本来收集./node_modules中的依赖项。 It fulfills my requirement at the moment. 它满足了我的要求。 This may help some others, I post it here. 这可能有助于其他人,我在这里发布。

var fs = require("fs");

function main() {
  fs.readdir("./node_modules", function (err, dirs) {
    if (err) {
      console.log(err);
      return;
    }
    dirs.forEach(function(dir){
      if (dir.indexOf(".") !== 0) {
        var packageJsonFile = "./node_modules/" + dir + "/package.json";
        if (fs.existsSync(packageJsonFile)) {
          fs.readFile(packageJsonFile, function (err, data) {
        
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值