Архивация модулей MAOH в один файл zip
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.

151 lines
4.5KB

  1. // // // //
  2. ВыдатьАрхивНаСкачивание = мир =>
  3. {
  4. // How to create a file in memory for user to download, but not through server?
  5. // https://stackoverflow.com/a/18197341
  6. var ссыль = document.createElement("a");
  7. ссыль.setAttribute("href", "data:application/zip;charset=utf-8;base64," + мир.содержимоеАрхива);
  8. var имя = "MAOH.zip";
  9. ссыль.setAttribute("download", имя);
  10. ссыль.style.display = "none";
  11. document.body.appendChild(ссыль);
  12. ссыль.click();
  13. document.body.removeChild(ссыль);
  14. };
  15. // // // //
  16. СгенерироватьАрхив = мир =>
  17. {
  18. мир.архив.generateAsync({type: "base64"}).then(function(content) {
  19. мир.содержимоеАрхива = content;
  20. console.debug("мир.содержимоеАрхива", мир.содержимоеАрхива);
  21. мир.уведомить("сгенерировали архив");
  22. });
  23. };
  24. // // // //
  25. СоздатьАрхив = мир =>
  26. {
  27. var архив = new JSZip();
  28. var корень = архив.folder("MAOH");
  29. корень.file("gitjs", мир.индекс);
  30. for (var н in мир.указателиМодулей)
  31. {
  32. var ук = мир.указателиМодулей[н];
  33. var м = мир.модули.модульПоУказателю(ук);
  34. var директория = корень.folder(н);
  35. директория.file("0000", мир.собрать0000(м));
  36. for (var файл in м.структура)
  37. {
  38. var содержимое = м.содержимое[файл];
  39. console.debug("задание содержимого файла:", файл);
  40. директория.file(файл.substring(1), содержимое);
  41. }
  42. }
  43. мир.архив = архив;
  44. };
  45. // // // //
  46. СоздатьИндексАрхива = мир =>
  47. {
  48. var индекс = "";
  49. for (var н in мир.указателиМодулей)
  50. {
  51. var ук = мир.указателиМодулей[н];
  52. индекс += `${ук}\n`;
  53. }
  54. мир.индекс = индекс;
  55. };
  56. // // // //
  57. ЗагрузитьМодули = мир =>
  58. {
  59. мир.модули.использовали.подписатьРаз(function() {
  60. мир.уведомить("загрузили модули");
  61. });
  62. мир.модули.использовать(мир.указателиМодулей);
  63. };
  64. // // // //
  65. ВывестиУказателиМодулей = мир =>
  66. {
  67. console.debug("указатели модулей:", мир.указателиМодулей);
  68. };
  69. // // // //
  70. РазобратьСписокМодулей = мир =>
  71. {
  72. var указатели = [];
  73. var строки = мир.списокМодулей.split(/\n/);
  74. for (var номер in строки)
  75. {
  76. var строка = строки[номер].trim();
  77. if (!строка.startsWith("#") && строка.length)
  78. {
  79. указатели.push(строка);
  80. }
  81. }
  82. мир.указателиМодулей = указатели;
  83. };
  84. // // // //
  85. ЗадатьСписокМодулей = мир =>
  86. {
  87. мир.списокМодулей = `
  88. https://bitbucket.org/gitjs/jquery/raw/3.5.1/0000
  89. https://bitbucket.org/gitjs/uikit/raw/3.2.0/0000
  90. https://git.opengamestudio.org/mahjong/mahjong-raskladka-layout/raw/branch/master/0000
  91. https://git.opengamestudio.org/mahjong/povtorniy-repeating-ui/raw/branch/master/0000
  92. https://git.opengamestudio.org/PuCOBATEJlb/PuCOBATEJlb/raw/branch/master/0000
  93. https://git.opengamestudio.org/PuCOBATEJlb/PECYPCbl/raw/branch/master/0000
  94. https://git.opengamestudio.org/MAOH/MEXMA/raw/branch/master/0000
  95. https://git.opengamestudio.org/MAOH/CEHMA/raw/branch/master/0000
  96. https://git.opengamestudio.org/MAOH/MOPMA/raw/branch/master/0000
  97. https://git.opengamestudio.org/MAOH/PEEMA/raw/branch/master/0000
  98. https://git.opengamestudio.org/MAOH/OTMA/raw/branch/master/0000
  99. https://git.opengamestudio.org/MAOH/CYMA/raw/branch/master/0000
  100. https://git.opengamestudio.org/MAOH/TEMA_M1K/raw/branch/master/0000
  101. https://git.opengamestudio.org/MAOH/PACK_M1/raw/branch/master/0000
  102. # Убрать после отладки
  103. https://git.opengamestudio.org/MAOH/TEMA_OT/raw/branch/master/0000
  104. https://git.opengamestudio.org/MAOH/PACK_OT/raw/branch/master/0000
  105. `;
  106. };
  107. // // // //
  108. СкрытьКрутилку = мир =>
  109. {
  110. document.getElementById("крутилка").style.display = "none";
  111. };