How to rename file with npm script

后端 未结 3 1568
予麋鹿
予麋鹿 2021-01-13 11:19

I am using copyfiles as an npm scirpt copyfiles -u 2 /src/app/conf.dev.json dist/config/ but in the end I want to get the file renamed

Ho

3条回答
  •  爱一瞬间的悲伤
    2021-01-13 11:51

    You must define the callback function:

    fs.rename('oldFile.txt', 'newFile.txt', (err) => {
      if (err) throw err;
      console.log('Rename complete!');
    });
    

    Something like that:

    "copy": "copyfiles -u 2 /src/app/conf.dev.json dist/config/ && node -e require('fs').rename('dist/config/conf.prod.json','dist/config/conf.json' , (err) => { (err? console.log(err) : console.log('Rename complete!') ) } )"
    

    @see https://nodejs.org/api/fs.html#fs_fs_rename_oldpath_newpath_callback

提交回复
热议问题