25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 
 
 
 
 

111 satır
2.4 KiB

  1. const path = require("path");
  2. const fs = require("fs");
  3. const frappe_path = path.resolve(__dirname, "..");
  4. const bench_path = path.resolve(frappe_path, "..", "..");
  5. const sites_path = path.resolve(bench_path, "sites");
  6. const assets_path = path.resolve(sites_path, "assets");
  7. const app_list = get_apps_list();
  8. const app_paths = app_list.reduce((out, app) => {
  9. out[app] = path.resolve(bench_path, "apps", app, app);
  10. return out;
  11. }, {});
  12. const public_paths = app_list.reduce((out, app) => {
  13. out[app] = path.resolve(app_paths[app], "public");
  14. return out;
  15. }, {});
  16. const public_js_paths = app_list.reduce((out, app) => {
  17. out[app] = path.resolve(app_paths[app], "public/js");
  18. return out;
  19. }, {});
  20. const bundle_map = app_list.reduce((out, app) => {
  21. const public_js_path = public_js_paths[app];
  22. if (fs.existsSync(public_js_path)) {
  23. const all_files = fs.readdirSync(public_js_path);
  24. const js_files = all_files.filter(file => file.endsWith(".js"));
  25. for (let js_file of js_files) {
  26. const filename = path.basename(js_file).split(".")[0];
  27. out[path.join(app, "js", filename)] = path.resolve(
  28. public_js_path,
  29. js_file
  30. );
  31. }
  32. }
  33. return out;
  34. }, {});
  35. const get_public_path = app => public_paths[app];
  36. const get_build_json_path = app =>
  37. path.resolve(get_public_path(app), "build.json");
  38. function get_build_json(app) {
  39. try {
  40. return require(get_build_json_path(app));
  41. } catch (e) {
  42. // build.json does not exist
  43. return null;
  44. }
  45. }
  46. function delete_file(path) {
  47. if (fs.existsSync(path)) {
  48. fs.unlinkSync(path);
  49. }
  50. }
  51. function run_serially(tasks) {
  52. let result = Promise.resolve();
  53. tasks.forEach(task => {
  54. if (task) {
  55. result = result.then ? result.then(task) : Promise.resolve();
  56. }
  57. });
  58. return result;
  59. }
  60. const get_app_path = app => app_paths[app];
  61. const get_options_for_scss = () => {
  62. const node_modules_path = path.resolve(
  63. get_app_path("frappe"),
  64. "..",
  65. "node_modules"
  66. );
  67. const app_paths = app_list
  68. .map(get_app_path)
  69. .map(app_path => path.resolve(app_path, ".."));
  70. return {
  71. includePaths: [node_modules_path, ...app_paths]
  72. };
  73. };
  74. function get_apps_list() {
  75. return fs
  76. .readFileSync(path.resolve(sites_path, "apps.txt"), {
  77. encoding: "utf-8"
  78. })
  79. .split("\n")
  80. .filter(Boolean);
  81. }
  82. module.exports = {
  83. app_list,
  84. bench_path,
  85. assets_path,
  86. sites_path,
  87. bundle_map,
  88. get_public_path,
  89. get_build_json_path,
  90. get_build_json,
  91. get_app_path,
  92. delete_file,
  93. run_serially,
  94. get_options_for_scss
  95. };