Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rename file with NPM

Is there a way to rename a single file in npm scripts? I want to prepare files for distribution, but I need the built files to be named differently than they are in the source...

I have tried orn, but that only seems to work on the command line, not as an npm script. I'm specifically looking to just add a cross-platform dependency to do my project, rather than writing my own javascript script to copy files over.

My ideal solution is something I can include in the package.json, as a one line command, e.g. rename old-file-name new-file-name

like image 211
JRJurman Avatar asked Feb 07 '16 20:02

JRJurman


1 Answers

Sure. npm script can run any node js file you want.

For example:

require('fs').rename(oldPath,newPath)

More Info:

  • https://nodejs.org/api/fs.html#fs_fs_rename_oldpath_newpath_callback
  • https://docs.npmjs.com/misc/scripts
like image 142
Aminadav Glickshtein Avatar answered Sep 25 '22 23:09

Aminadav Glickshtein