繁体   English   中英

编辑 package.js 文件

[英]Editing package.js file

我很难理解如何使用 package.js 文件运行所有 my.js 文件我有几乎 2000.js 脚本我需要一个一个地运行它们,我使用的是由 gameflip 在我找到了 package.js 的文件夹,但我不知道如何使用它,谁能告诉我该怎么做? 在这里谢谢你的脚本:

    {
  "name": "gfapi",
  "version": "0.1.1",
  "description": "Gameflip API",
  "keywords": "Gameflip",
  "homepage": "https://github.com/iJJi/gfapi",
  "bugs": "https://github.com/iJJi/gfapi/issues",
  "author": {
    "name": "Eng-Shien Wu",
    "email": "engshien.wu@ijji.com"
  },
  "license": "MIT",
  "private": true,
  "files": [
    "index.js"
  ],
  "repository": "iJJi/gfapi",                
  "engines": {
    "node": ">=8.5.0"
  },
  "scripts": {
    "bulk_listing": "node src/samples/bulk_listing.js",
    "test": "ENVIRONMENT=mocha mocha src/test --recursive",
    "docs": "jsdoc -c jsdoc_conf.js -d docs -P package.json index.js; docco -o docs/samples src/samples/*.js src/samples/*.rb"
  },
  "dependencies": {
    "base-64": "^0.1.0",
    "bluebird": "^3.5.0",
    "bunyan": "^1.8.12",
    "file-type": "^8.1.0",
    "http-errors": "^1.6.2",
    "node-rest-client-promise": "^3.1.1",
    "promise-ratelimit": "^0.0.3",
    "request": "^2.85.0",
    "request-promise": "^4.2.2",
    "speakeasy": "^2.0.0"
  },
  "devDependencies": {
    "marked": "^0.3.19",
    "docco": "^0.7.0",``
    "jsdoc": "^3.5.5"
  }
}

您发布的不是package.js (我什至不知道它是否存在),而是package.json 它由节点Package管理器 NPM 生成。 它是所有项目依赖项的列表。 我认为您正在寻找的是 npm 脚本,它们在 package.Z46638716ECDF35FCAD6Z 的package.json script

npm run <script>

# For example :
npm run bulk_listing
npm run test
npm run docs

每个脚本将在此package.json中运行其相关命令。

npm run bulk_listing
# Will do the same thing as:
node src/samples/bulk_listing.js

更多关于package.json的信息。


我在下面谈到的脚本

如果要运行所有脚本,这应该可以完成工作:

const fileNames = ["path/to/fileA", "fileB"]; // I assume you have something to get all the files path. Isn't that npm run bulk_listing ?

fileNames.forEach(async (path, index) => {
    // It's pretty much like 'node <path>'
    await require(path);
    // All the code here is executed AFTER the script has been launched
    console.log(`LAUNCHED ${index} | ${path}`)
});

暂无
暂无

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

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