2

I'm using this package to execute a node script on pre-commit hook.

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"
  }
}

bump.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 )
} )

The problem I have is that the changes to the file are not committed. What am I doing wrong?

1 Answer 1

1

You need to add the changes to git staging area (with git add) so they will be a part of the next commit

"scripts": {
    "bump": "node ./bump.js && git add ../src/buildNumber.json",
 },
Sign up to request clarification or add additional context in comments.

1 Comment

OMG, you're absolutely right, feel myself so stupid now:) Thanks a lot!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.