dch dch - 3 months ago 43
Node.js Question

Converting mac node script to windows

I have a postinstall node script that copies previously run scripts into my npm-scripts folder. However, this only works for Mac. I need to have it work for Windows as well so I am creating a new file that will run 1 for windows or the one listed below for Mac.

`cp ../node_modules/some-components/npm-scripts/*.js ../npm_scripts`

I'm not seeing a clear way to convert the syntax to be usable by a windows machine as well as whether to use copy or robocopy. Any suggestions would be greatly appreciated.


Create a copy.js file which performs the copy platform-independently via a Node.js API (i.e. do not rely on Windows or Unix-specific shell commands cp or copy). My suggestion: Use fs-extra, which also handles copying directories, in contrast to the included fs.

var fs = require('fs-extra'); // add to your dependencies via 'npm install fs-extra --save'
var path = require('path');

      path.resolve(__dirname, '../path/to/source', 
      path.resolve(__dirname, '../path/to/destination'));