You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

49 lines
1.2 KiB

5 years ago
  1. var fs = require('fs');
  2. var path = require('path')
  3. function copy(src, dst) {
  4. fs.writeFileSync(dst, fs.readFileSync(src));
  5. }
  6. function travel(dir, callback) {
  7. if (fs.statSync(dir).isDirectory()) {
  8. callback(dir,true);
  9. }
  10. fs.readdirSync(dir).forEach(function (file) {
  11. var pathname = path.join(dir, file);
  12. if (fs.statSync(pathname).isDirectory()) {
  13. travel(pathname, callback);
  14. } else {
  15. callback(pathname,false);
  16. }
  17. });
  18. }
  19. function copy(src, dest){
  20. travel(src,function(file,isDir){
  21. var filename=dest+file.substring(src.length);
  22. if (isDir===true && !fs.existsSync(filename)) {
  23. fs.mkdirSync(filename);
  24. }
  25. if(isDir===false){
  26. fs.writeFileSync(filename, fs.readFileSync(file));
  27. }
  28. });
  29. };
  30. function delDir(path) {
  31. if( fs.existsSync(path) ) {
  32. fs.readdirSync(path).forEach(function(file) {
  33. var curPath = path + "/" + file;
  34. if(fs.statSync(curPath).isDirectory()) { // recurse
  35. delDir(curPath);
  36. } else { // delete file
  37. fs.unlinkSync(curPath);
  38. }
  39. });
  40. fs.rmdirSync(path);
  41. }
  42. };
  43. function delCopy(src,dest){
  44. delDir(dest);
  45. copy(src,dest);
  46. }
  47. delCopy('dist','../mdp-workflow-starter/src/main/resources/static');