【實用】項目直接打包並推動到遠程倉庫

//依賴shelljs,自己安裝


// 局部模式
const shell = require('shelljs');
// 全局模式下,就不需要用shell開頭了。
// require('shelljs/global');

if (shell.exec('npm run build').code !== 0) { // 執行npm run build 命令
  shell.echo('Error: Git commit failed');
  shell.exit(1);
}


shell.exec('git pull origin master');

// 由於我的用另外一個倉庫存放dist目錄,所以這裏要將文件增量複製到目標目錄。並切換到對應目錄。
shell.cp('-r', './dist/*', '../shop-diy-dist/htdocs/member/shop/setting/diy');
shell.cd('../shop-diy-dist');

// 不能在一股腦全部添加了
shell.exec('git add htdocs/member/shop/setting/diy/');
shell.exec('git commit -m autopush');
shell.exec('git push origin master');

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章