dataApiToNumScript.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. const fs = require("fs");
  2. const asd = /id: (["'][\w\d]+["']),(\n?\s+(.+)){0,2}\n?\s+params:\s/;
  3. const asdg = /id: ["'][\w\d]+["'],(\n?\s+(.+)){0,2}\n?\s+params:\s/g;
  4. class Main {
  5. pathList = [];
  6. pathListLength = 0;
  7. read_dir(path) {
  8. this.__read(path);
  9. this.handleFile();
  10. }
  11. __read(path) {
  12. fs.readdirSync(path).forEach(filename => {
  13. let sub_path = path + '/' + filename;
  14. let stat = fs.statSync(sub_path);
  15. if (stat.isDirectory()) {
  16. this.__read(sub_path);
  17. } else if (stat.isFile()) {
  18. if (!this.pathList.some(tt => tt === sub_path)) {
  19. this.pathList.push(sub_path);
  20. }
  21. }
  22. });
  23. this.pathListLength = this.pathList.length
  24. }
  25. handleFile() {
  26. let path = this.pathList.pop();
  27. let content = fs.readFileSync(path, {
  28. encoding: 'utf-8',
  29. });
  30. this.appendProps(path, content);
  31. console.log(`正在替换${this.pathListLength - this.pathList.length}/${this.pathListLength}`)
  32. if (this.pathList.length > 0) this.handleFile();
  33. }
  34. appendProps(path, content) {
  35. if (!asd.test(content)) { return; }
  36. let newContent = content.replace(asdg, (substring) => {
  37. return substring.replace('id:', "num:");
  38. });
  39. fs.writeFileSync(path, newContent);
  40. }
  41. }
  42. let main = new Main();
  43. main.read_dir('/Users/mlie/Documents/prolog/upcloud-wms-hnsy-web/src/views/kzyWMS');
  44. main.read_dir('/Users/mlie/Documents/prolog/upcloud-wms-hnsy-web/src/views/EIS');