1

I published a module - Module A. I want to set this module to automatically copy a folder to the root directory AFTER installation. I created below index.js file

//Module A - index.js`

var cpx = require('cpx');
cpx.copy('node_modules/path/to/module-a/folder/to/copy/*.*', 'dest/');

//Module A - package.json under the scripts section

"postinstall": node ./node_modules/module-a

I created a new project and installed Module A. The postinstall script was executed but the files were NOT copied to the destination. but if I ran the command node ./node_modules/module-a manually again, it worked.

  1. Just wondering why the script was not working when running is postinstall stage.
  2. or there is a better way to do this copy action?
seanbun
  • 892
  • 3
  • 14
  • 32

1 Answers1

1

FYI, as of 2020, it appears that the CPX project is abandoned (last release was 3 years ago, authors won't fix reported vulnerabilities). cpx-fixed is a good alternative.

Wildhammer
  • 2,017
  • 1
  • 27
  • 33