build.cjs 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. const path = require('path');
  2. const shell = require('shelljs');
  3. const work_dir = path.join(__dirname, '..');
  4. function build() {
  5. shell.cd(work_dir);
  6. shell.rm('-rf', 'dist');
  7. shell.exec('npx vite build');
  8. shell.cd('dist');
  9. shell.mkdir('src');
  10. shell.cp('-R', '../src/assets', './src/');
  11. shell.cd(work_dir);
  12. }
  13. function pack() {
  14. const file_name = genFileName();
  15. const folder_name = `dist_${file_name}`;
  16. const zip_name = `${folder_name}.zip`
  17. const release_dir = '~/Desktop/';
  18. shell.cp('-R', './dist', folder_name);
  19. shell.exec(`zip -q -r ${zip_name} ${folder_name}`);
  20. shell.rm('-rf', folder_name);
  21. shell.mv(zip_name, release_dir);
  22. '-'.repeat(32).split('').forEach((item, index, val) => {
  23. if (index <= 3) console.log(val.join(''));
  24. });
  25. console.log(`Target File Path:${release_dir}${zip_name}`);
  26. }
  27. function genFileName() {
  28. const dt = new Date();
  29. const str_full = dt.toISOString();
  30. const str_1 = str_full.replace('T', '_');
  31. const str_2 = str_1.replace(/:/g, '-');
  32. const str_3 = str_2.replace(/.[0-9]{3}Z/, '');
  33. return str_3;
  34. }
  35. (function autorun() {build();pack();})();