在package.json中读取package.json版本

时间:2017-08-29 10:40:13

标签: node.js npm package.json

我有一个{ "name": "myapp", "version": "0.0.1", "license": "MIT", "scripts": { "ng": "ng", "start": "webpack-dev-server --port=4200", "build": "webpack", "docker-build": "docker build -t myapp .", "docker-run": "docker run -d --name myapp -p 9090:9090 myapp", "docker-push": "docker build -t myapp . & docker tag myapp myrepo/myapp:{$VERSION} & docker push myrepo/myapp:{$VERSION}" }, ... } 文件,如下所示:

npm run docker-push

我在运行package.json时尝试获取版本号,因此它会自动使用版本号public void RetriveDiagCodeName( [FieldName("DIAG_CODE1")] Field<string> diagCode1, [FieldName("DIAG_CODE2")] Field<string> diagCode2) { Dictionary<string, Field<string>> dictDiagCode = new Dictionary<string,Field<string>>(); dictDiagCode.Add("1", diagCode1); dictDiagCode.Add("2", diagCode2); Field<string> diagCodeName; string diagCodeValue = "1234B; diagCodename = dictDiagCode.Keys.OfType<Field<string>>().FirstOrDefault(k=> dictDiagCode[k] == diagCodeValue); } 标记版本。我怎样才能做到这一点?

1 个答案:

答案 0 :(得分:3)

您可以使用环境变量npm_package_version

提示:要查看由npm设置的所有可用环境变量,您可以添加&#34; printenv | grep npm&#34;作为一个剧本:

{
  "name": "myapp",
  "version": "1.0.0",
  "scripts": {
    "start": "node app.js",
    "version": "echo ${npm_package_version}", // return current version
    "vars": "printenv | grep npm" // return all ENV vars with 'npm'
  }
  // ...
}