您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 
 
 

130 行
2.7 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. function get_cli_arg(name) {
  83. let args = process.argv.slice(2);
  84. for (let i in args) {
  85. let arg = args[i];
  86. let value = null;
  87. if (arg == `--${name}`) {
  88. value = true;
  89. }
  90. if (args[i + 1]) {
  91. value = args[i + 1];
  92. }
  93. if (value) {
  94. return value;
  95. }
  96. }
  97. }
  98. module.exports = {
  99. app_list,
  100. bench_path,
  101. assets_path,
  102. sites_path,
  103. bundle_map,
  104. get_public_path,
  105. get_build_json_path,
  106. get_build_json,
  107. get_app_path,
  108. delete_file,
  109. run_serially,
  110. get_options_for_scss,
  111. get_cli_arg
  112. };