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.

36 lines
1.2 KiB

  1. // 运行项目前通过node执行此脚本 (此脚本与 node_modules 目录同级)
  2. const fs = require('fs')
  3. const path = require('path')
  4. const wfPath = path.resolve(__dirname, './node_modules/.bin')
  5. fs.readdir(wfPath, (err, files) => {
  6. if (err) {
  7. console.log(err)
  8. } else {
  9. if (files.length != 0) {
  10. files.forEach((item) => {
  11. if (item.split('.')[1] === 'cmd') {
  12. replaceStr(`${wfPath}/${item}`, /"%_prog%"/, '%_prog%')
  13. }
  14. })
  15. }
  16. }
  17. })
  18. // 参数:[文件路径、 需要修改的字符串、修改后的字符串] (替换对应文件内字符串的公共函数)
  19. function replaceStr(filePath, sourceRegx, targetSrt) {
  20. fs.readFile(filePath, (err, data) => {
  21. if (err) {
  22. console.log(err)
  23. } else {
  24. let str = data.toString()
  25. str = str.replace(sourceRegx, targetSrt)
  26. fs.writeFile(filePath, str, (err) => {
  27. if(err){
  28. console.log(err)
  29. }else{
  30. console.log("\x1B[42m%s\x1B[0m","文件修改成功")
  31. }
  32. })
  33. }
  34. })
  35. }