Cross-platform compatibility cannot be realized by utilizing the shell command date that is available on  *nix platforms. This is because the Windows/cmd.exe DATE command behaves differently. The differences are:
- The *nix datecommand prints the date/time.
- The Windows/cmd.exe DATEcommand prompts the user to set the system date/time.
Also command substitution, i.e. the $(...) part is a bash feature found on most *nix shells - it will fail via Windows cmd.exe.
For a cross-platform solution (i.e. one that runs successfully on Windows, Linux, and macOS...), consider the following approach:
- Utilize a nodejs script to shell-out your cdandgitcommands using the built-inexecSync().
- Obtain the date using the moment package, or alternatively using the JavaScript Date()object similar to this answer instead.
- Invoke the nodejs script from the scriptssection of your package.json
Solution:
There are a couple of different ways to approach this as described in the following two sub-sections titled:
- Using an external nodejs (.js) file
- Inlining your JavaScript in package.json.
Note: both approaches effectively yield the same desired result.
Using an external nodejs (.js) file
- The following utilizes - momentfor obtaining the date. To install that run the following command in your project directory:
 - npm i -D moment
 
- Create a nodejs script as follows, let's name the file deploy.js and save it in the root of your project directory, i.e. in the same directory where package.json currently resides:: - deploy.js - const moment = require('moment');
const execSync = require('child_process').execSync;
const dateTime = moment().format('MM/DD/YYYY HH:mm:ss');
execSync(`cd dist && git add . && git commit -m \"Release at ${dateTime}\" && git push`, { stdio: [0, 1, 2]} );
 
- In the - scriptssection of your package.json replace your current- deployscript with the following:
 - package.json - "scripts": {
  "deploy": "node deploy"
}
 
- Invoke the npm - deployscript as per normal by running the following via your CLI:
 - npm run deploy
 
Explanation:
- In deploy.js we require the momentpackage and the nodejs built-inexecSync().
- To obtain the current date/time we invoke moment()and call itsformat()method to match your given formatting, i.e.MM/DD/YYYY HH:mm:ss.
- We then shell-out your cdandgitcommands usingexecSync. A reference to the date/time is provided in  thegitmessage part using Template literals, i.e.${dateTime}
- The options.stdiooption configures the pipes between the parent and child process -[0, 1, 2]effectively inherit'sstdin,stdout, andstderr.
Inlining your JavaScript in package.json.
Alternatively, you can inline your nodejs/JavaScript code in the scripts section of your package.json.
- In the scripts section of your package.json replace your current - deployscript with the following instead:
 - package.json - "scripts": {
  "deploy": "node -e \"const dateTime = require('moment')().format('MM/DD/YYYY HH:mm:ss'); require('child_process').execSync(`cd dist && git add . && git commit -m \"Release at ${dateTime}\" && git push`, { stdio: [0, 1, 2]} );\""
}
 
Explanation:
- This is effectively the same as the aforementioned solution that utilized a separate .jsfile (albeit slightly refactored). The use of a separate nodejs script/file is now redundant.
- The nodejs command line option -eis utilized to evaluate the inline JavaScript.