我正在使用this package在预提交挂钩上执行节点脚本。

package.json:

{
  "name": "MyApp",
  "version": "0.0.0",
  "description": "ERROR: No README.md file found!",
  "main": "index.js",
  "scripts": {
    "bump": "node ./bump.js",
  },
  "pre-commit": [
    "bump"
  ],
  "devDependencies": {
    "pre-commit": "^1.2.2"
  }
}


ump.js:

#!/usr/bin/env node
'use strict';

const fs = require( 'fs' )
const fileName = __dirname + '/../src/buildNumber.json'
const file = require( fileName )

const date = new Date()

// set current datetime
file.dateTime = date.toLocaleDateString() + ' ' + date.toLocaleTimeString()

// increment build number
file.buildNumber += 1

fs.writeFile( fileName, JSON.stringify( file, null, 2 ), function ( err ) {
    if ( err ) return console.log( err )
    console.log( JSON.stringify( file ) )
    console.log( 'writing to ' + fileName )
} )


我的问题是对该文件的更改未提交。我究竟做错了什么?

最佳答案

您需要将更改添加到git临时区域(使用git add),以便它们将成为下一次提交的一部分

"scripts": {
    "bump": "node ./bump.js && git add ../src/buildNumber.json",
 },

08-17 12:59