ProtonFramework.js 4.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.ProtonFramework = void 0;
  4. const builder_util_1 = require("builder-util");
  5. const builder_util_runtime_1 = require("builder-util-runtime");
  6. const core_1 = require("./core");
  7. const fileTransformer_1 = require("./fileTransformer");
  8. const LibUiFramework_1 = require("./frameworks/LibUiFramework");
  9. const pathManager_1 = require("./util/pathManager");
  10. class ProtonFramework extends LibUiFramework_1.LibUiFramework {
  11. constructor(version, distMacOsAppName, isUseLaunchUi) {
  12. super(version, distMacOsAppName, isUseLaunchUi);
  13. this.name = "proton";
  14. // noinspection JSUnusedGlobalSymbols
  15. this.defaultAppIdPrefix = "com.proton-native.";
  16. }
  17. getDefaultIcon(platform) {
  18. if (platform === core_1.Platform.WINDOWS) {
  19. return (0, pathManager_1.getTemplatePath)("icons/proton-native/proton-native.ico");
  20. }
  21. else if (platform === core_1.Platform.LINUX) {
  22. return (0, pathManager_1.getTemplatePath)("icons/proton-native/linux");
  23. }
  24. else {
  25. return (0, pathManager_1.getTemplatePath)("icons/proton-native/proton-native.icns");
  26. }
  27. }
  28. createTransformer() {
  29. let babel;
  30. const babelOptions = { ast: false, sourceMaps: "inline" };
  31. if (process.env.TEST_SET_BABEL_PRESET === "true") {
  32. babel = require("@babel/core");
  33. // eslint-disable-next-line @typescript-eslint/no-use-before-define
  34. babel = testOnlyBabel(babel, babelOptions, this.version);
  35. }
  36. else {
  37. try {
  38. babel = require("babel-core");
  39. }
  40. catch (e) {
  41. // babel isn't installed
  42. builder_util_1.log.debug(null, "don't transpile source code using Babel");
  43. return null;
  44. }
  45. }
  46. builder_util_1.log.info({
  47. options: (0, builder_util_runtime_1.safeStringifyJson)(babelOptions, new Set(["presets"])),
  48. }, "transpile source code using Babel");
  49. return (file) => {
  50. if (!(file.endsWith(".js") || file.endsWith(".jsx")) || file.includes(fileTransformer_1.NODE_MODULES_PATTERN)) {
  51. return null;
  52. }
  53. return new Promise((resolve, reject) => {
  54. return babel.transformFile(file, babelOptions, (error, result) => {
  55. if (error == null) {
  56. resolve(result.code);
  57. }
  58. else {
  59. reject(error);
  60. }
  61. });
  62. });
  63. };
  64. }
  65. }
  66. exports.ProtonFramework = ProtonFramework;
  67. function testOnlyBabel(babel, babelOptions, nodeVersion) {
  68. // out test dir can be located outside of electron-builder node_modules and babel cannot resolve string names of preset
  69. babelOptions.presets = [[require("@babel/preset-env").default, { targets: { node: nodeVersion } }], require("@babel/preset-react")];
  70. babelOptions.plugins = [
  71. // stage 0
  72. require("@babel/plugin-proposal-function-bind").default,
  73. // stage 1
  74. require("@babel/plugin-proposal-export-default-from").default,
  75. require("@babel/plugin-proposal-logical-assignment-operators").default,
  76. [require("@babel/plugin-proposal-optional-chaining").default, { loose: false }],
  77. [require("@babel/plugin-proposal-pipeline-operator").default, { proposal: "minimal" }],
  78. [require("@babel/plugin-proposal-nullish-coalescing-operator").default, { loose: false }],
  79. require("@babel/plugin-proposal-do-expressions").default,
  80. // stage 2
  81. [require("@babel/plugin-proposal-decorators").default, { legacy: true }],
  82. require("@babel/plugin-proposal-function-sent").default,
  83. require("@babel/plugin-proposal-export-namespace-from").default,
  84. require("@babel/plugin-proposal-numeric-separator").default,
  85. require("@babel/plugin-proposal-throw-expressions").default,
  86. // stage 3
  87. require("@babel/plugin-syntax-dynamic-import").default,
  88. require("@babel/plugin-syntax-import-meta").default,
  89. [require("@babel/plugin-proposal-class-properties").default, { loose: false }],
  90. require("@babel/plugin-proposal-json-strings").default,
  91. ];
  92. babelOptions.babelrc = false;
  93. return babel;
  94. }
  95. //# sourceMappingURL=ProtonFramework.js.map