package.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. import fs from 'fs';
  2. import path from 'path';
  3. import { fileURLToPath } from 'url';
  4. import readline from 'readline';
  5. import { execSync } from 'child_process';
  6. import {remove} from "fs-extra";
  7. const __filename = fileURLToPath(import.meta.url);
  8. const __dirname = path.dirname(__filename);
  9. let config = fs.readFileSync(path.join(__dirname, `src/content-scripts/config.json`), 'utf8');
  10. config = JSON.parse(config);
  11. // 生成英文插件
  12. removeDir(path.join(__dirname, `EasySpider_en`));
  13. config.language = "en";
  14. let data = JSON.stringify(config);
  15. // write JSON string to a file
  16. fs.writeFileSync(path.join(__dirname, `src/content-scripts/config.json`), data, (err) => {
  17. if (err) {
  18. throw err;
  19. }
  20. });
  21. execSync(`npm run build`, (error, stdout, stderr) => {
  22. if (error) {
  23. console.log(`error: ${error.message}`);
  24. return;
  25. }
  26. if (stderr) {
  27. console.log(`stderr: ${stderr}`);
  28. return;
  29. }
  30. console.log(`stdout: ${stdout}`);
  31. });
  32. fs.renameSync(path.join(__dirname, `dist/`), path.join(__dirname, `EasySpider_en`));
  33. execSync(`npm run crx EasySpider_en`, (error, stdout, stderr) => {
  34. if (error) {
  35. console.log(`error: ${error.message}`);
  36. return;
  37. }
  38. if (stderr) {
  39. console.log(`stderr: ${stderr}`);
  40. return;
  41. }
  42. console.log(`stdout: ${stdout}`);
  43. });
  44. fs.copyFileSync(path.join(__dirname, './EasySpider_en.crx'), path.join(__dirname, '../../ElectronJS/EasySpider_en.crx'));
  45. // 生成中文插件
  46. removeDir(path.join(__dirname, `EasySpider_zh`));
  47. config.language = "zh";
  48. data = JSON.stringify(config);
  49. // write JSON string to a file
  50. fs.writeFileSync(path.join(__dirname, `src/content-scripts/config.json`), data, (err) => {
  51. if (err) {
  52. throw err;
  53. }
  54. });
  55. execSync(`npm run build`, (error, stdout, stderr) => {
  56. if (error) {
  57. console.log(`error: ${error.message}`);
  58. return;
  59. }
  60. if (stderr) {
  61. console.log(`stderr: ${stderr}`);
  62. return;
  63. }
  64. console.log(`stdout: ${stdout}`);
  65. });
  66. fs.renameSync(path.join(__dirname, `dist/`), path.join(__dirname, `EasySpider_zh`));
  67. execSync(`npm run crx EasySpider_zh`, (error, stdout, stderr) => {
  68. if (error) {
  69. console.log(`error: ${error.message}`);
  70. return;
  71. }
  72. if (stderr) {
  73. console.log(`stderr: ${stderr}`);
  74. return;
  75. }
  76. console.log(`stdout: ${stdout}`);
  77. });
  78. fs.copyFileSync(path.join(__dirname, './EasySpider_zh.crx'), path.join(__dirname, '../../ElectronJS/EasySpider_zh.crx'));
  79. function removeDir(dir) {
  80. let files = fs.readdirSync(dir)
  81. for(var i=0;i<files.length;i++){
  82. let newPath = path.join(dir,files[i]);
  83. let stat = fs.statSync(newPath)
  84. if(stat.isDirectory()){
  85. //如果是文件夹就递归下去
  86. removeDir(newPath);
  87. }else {
  88. //删除文件
  89. fs.unlinkSync(newPath);
  90. }
  91. }
  92. fs.rmdirSync(dir)//如果文件夹是空的,就将自己删除掉
  93. }