gulpfile.mjs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import gulp from 'gulp';
  2. import shell from 'gulp-shell';
  3. import gulp_zip from 'gulp-zip';
  4. const { series } = gulp;
  5. const dev_server = 'ds-001:/data/containers/safety2/backend'; // 开发服务器地址
  6. const stage_server = 'dev:/data/projects/safety2/backend'; // 预生产服务器地址
  7. const prod_server = 'hejin-online:/data/hejin'; // 生产服务器地址
  8. const zipfile = 'safety2-client.zip';
  9. const srcfiles = ['dist/client_angular/browser/**/*'];
  10. const basePath = './dist/client_angular/browser';
  11. let serverValue = '';
  12. let serverPathValue = '';
  13. function prepare(server) {
  14. return cb => {
  15. const parts = server.split(':');
  16. serverValue = parts[0];
  17. serverPathValue = parts[1];
  18. cb();
  19. };
  20. }
  21. function zip() {
  22. return gulp.src(srcfiles, { base: basePath, encoding: false }).pipe(gulp_zip(zipfile)).pipe(gulp.dest('./dist'));
  23. }
  24. function compile() {
  25. return shell.task('ng build')();
  26. }
  27. function compileStage() {
  28. //return shell.task('ng build --configuration=staging')();
  29. return shell.task('ng build')();
  30. }
  31. function upload() {
  32. return shell.task(`scp ./dist/${zipfile} ${serverValue}:${serverPathValue}/${zipfile}`)();
  33. }
  34. function unzip() {
  35. return shell.task(`ssh ${serverValue} "cd ${serverPathValue} && unzip -o ${zipfile}"`)();
  36. }
  37. export const build = series(compile, zip);
  38. export const prod = series(prepare(prod_server), compile, zip, upload, unzip);
  39. export const dev = series(prepare(dev_server), compile, zip, upload, unzip);
  40. export const stage = series(prepare(stage_server), compileStage, zip, upload, unzip);