admin管理员组文章数量:1279043
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 mand 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 mand, e.g. rename old-file-name new-file-name
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 mand 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 mand, e.g. rename old-file-name new-file-name
3 Answers
Reset to default 4Sure. npm script
can run any node js file you want.
For example:
require('fs').rename(oldPath,newPath)
More Info:
- https://nodejs/api/fs.html#fs_fs_rename_oldpath_newpath_callback
- https://docs.npmjs./misc/scripts
Turns out the npm library cash offers several basic mand line utilities that can be run as a single line mand from a package.json. For renaming, you can use the sub-package cash-mv to rename a specific file.
Configure the scripts section of your package.json as follows:
"scripts": {
"rename": "node -e \"require('fs').rename('C:/abc.text', 'C:/xyz.text', function(err) { if (err) console.log(err); console.log('File renamed!') })\""
},
Then run the following npm mand:
npm run copy-and-rename
On successful pletion you should see the following logged to the console after the file has been copied and renamed:
File successfully renamed!
本文标签: javascriptRename file with NPMStack Overflow
版权声明:本文标题:javascript - Rename file with NPM - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741241550a2364078.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论