1 | "use strict";
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports.createProtonFrameworkSupport = createProtonFrameworkSupport;
|
7 |
|
8 | function _bluebirdLst() {
|
9 | const data = require("bluebird-lst");
|
10 |
|
11 | _bluebirdLst = function () {
|
12 | return data;
|
13 | };
|
14 |
|
15 | return data;
|
16 | }
|
17 |
|
18 | function _fsExtraP() {
|
19 | const data = require("fs-extra-p");
|
20 |
|
21 | _fsExtraP = function () {
|
22 | return data;
|
23 | };
|
24 |
|
25 | return data;
|
26 | }
|
27 |
|
28 | function _binDownload() {
|
29 | const data = require("builder-util/out/binDownload");
|
30 |
|
31 | _binDownload = function () {
|
32 | return data;
|
33 | };
|
34 |
|
35 | return data;
|
36 | }
|
37 |
|
38 | function _fs() {
|
39 | const data = require("builder-util/out/fs");
|
40 |
|
41 | _fs = function () {
|
42 | return data;
|
43 | };
|
44 |
|
45 | return data;
|
46 | }
|
47 |
|
48 | function _builderUtil() {
|
49 | const data = require("builder-util");
|
50 |
|
51 | _builderUtil = function () {
|
52 | return data;
|
53 | };
|
54 |
|
55 | return data;
|
56 | }
|
57 |
|
58 | function _builderUtilRuntime() {
|
59 | const data = require("builder-util-runtime");
|
60 |
|
61 | _builderUtilRuntime = function () {
|
62 | return data;
|
63 | };
|
64 |
|
65 | return data;
|
66 | }
|
67 |
|
68 | function _core() {
|
69 | const data = require("./core");
|
70 |
|
71 | _core = function () {
|
72 | return data;
|
73 | };
|
74 |
|
75 | return data;
|
76 | }
|
77 |
|
78 | function _fileTransformer() {
|
79 | const data = require("./fileTransformer");
|
80 |
|
81 | _fileTransformer = function () {
|
82 | return data;
|
83 | };
|
84 |
|
85 | return data;
|
86 | }
|
87 |
|
88 | var path = _interopRequireWildcard(require("path"));
|
89 |
|
90 | function _plist() {
|
91 | const data = require("plist");
|
92 |
|
93 | _plist = function () {
|
94 | return data;
|
95 | };
|
96 |
|
97 | return data;
|
98 | }
|
99 |
|
100 | function _pathManager() {
|
101 | const data = require("./util/pathManager");
|
102 |
|
103 | _pathManager = function () {
|
104 | return data;
|
105 | };
|
106 |
|
107 | return data;
|
108 | }
|
109 |
|
110 | let writeExecutableMain = (() => {
|
111 | var _ref = (0, _bluebirdLst().coroutine)(function* (file, content) {
|
112 | yield (0, _fsExtraP().writeFile)(file, content, {
|
113 | mode: 0o755
|
114 | });
|
115 | yield (0, _fsExtraP().chmod)(file, 0o755);
|
116 | });
|
117 |
|
118 | return function writeExecutableMain(_x, _x2) {
|
119 | return _ref.apply(this, arguments);
|
120 | };
|
121 | })(); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }
|
122 |
|
123 | function createProtonFrameworkSupport(nodeVersion, appInfo) {
|
124 | return new ProtonFramework(nodeVersion === "current" ? process.versions.node : nodeVersion, `${appInfo.productFilename}.app`);
|
125 | }
|
126 |
|
127 | class ProtonFramework {
|
128 | constructor(version, distMacOsAppName) {
|
129 | this.version = version;
|
130 | this.distMacOsAppName = distMacOsAppName;
|
131 | this.name = "proton";
|
132 | this.isDefaultAppIconProvided = false;
|
133 | this.macOsDefaultTargets = ["dmg"];
|
134 | this.defaultAppIdPrefix = "com.proton-native.";
|
135 |
|
136 | this.isNpmRebuildRequired = false;
|
137 | }
|
138 |
|
139 | getDefaultIcon() {
|
140 | return (0, _pathManager().getTemplatePath)("proton-native.icns");
|
141 | }
|
142 |
|
143 | createTransformer() {
|
144 | let babel;
|
145 | const babelOptions = {
|
146 | ast: false,
|
147 | sourceMaps: "inline"
|
148 | };
|
149 |
|
150 | if (process.env.TEST_SET_BABEL_PRESET === "true") {
|
151 | babel = require("@babel/core");
|
152 |
|
153 | babelOptions.presets = [[require("@babel/preset-env").default, {
|
154 | targets: {
|
155 | node: this.version
|
156 | }
|
157 | }], [require("@babel/preset-stage-0"), {
|
158 | decoratorsLegacy: true
|
159 | }], require("@babel/preset-react")];
|
160 | babelOptions.babelrc = false;
|
161 | } else {
|
162 | try {
|
163 | babel = require("babel-core");
|
164 | } catch (e) {
|
165 |
|
166 | _builderUtil().log.debug(null, "don't transpile source code using Babel");
|
167 |
|
168 | return null;
|
169 | }
|
170 | }
|
171 |
|
172 | _builderUtil().log.info({
|
173 | options: (0, _builderUtilRuntime().safeStringifyJson)(babelOptions, new Set(["presets"]))
|
174 | }, "transpile source code using Babel");
|
175 |
|
176 | return file => {
|
177 | if (!(file.endsWith(".js") || file.endsWith(".jsx")) || file.includes(_fileTransformer().NODE_MODULES_PATTERN)) {
|
178 | return null;
|
179 | }
|
180 |
|
181 | return new Promise((resolve, reject) => {
|
182 | return babel.transformFile(file, babelOptions, (error, result) => {
|
183 | if (error == null) {
|
184 | resolve(result.code);
|
185 | } else {
|
186 | reject(error);
|
187 | }
|
188 | });
|
189 | });
|
190 | };
|
191 | }
|
192 |
|
193 | prepareMacosApplicationStageDirectory(packager, options) {
|
194 | var _this = this;
|
195 |
|
196 | return (0, _bluebirdLst().coroutine)(function* () {
|
197 | const appContentsDir = path.join(options.appOutDir, _this.distMacOsAppName, "Contents");
|
198 | yield (0, _fsExtraP().ensureDir)(path.join(appContentsDir, "Resources"));
|
199 | yield (0, _fsExtraP().ensureDir)(path.join(appContentsDir, "MacOS"));
|
200 | yield (0, _fs().copyFile)(path.join((yield (0, _binDownload().getBin)("node", `${_this.version}-darwin-x64`, null)), "node"), path.join(appContentsDir, "MacOS", "node"));
|
201 | const appPlist = {
|
202 |
|
203 | NSHighResolutionCapable: true
|
204 | };
|
205 | yield packager.applyCommonInfo(appPlist, appContentsDir);
|
206 | yield Promise.all([(0, _fsExtraP().writeFile)(path.join(appContentsDir, "Info.plist"), (0, _plist().build)(appPlist)), writeExecutableMain(path.join(appContentsDir, "MacOS", appPlist.CFBundleExecutable), `#!/bin/sh
|
207 | DIR=$(dirname "$0")
|
208 | "$DIR/node" "$DIR/../Resources/app/${options.packager.info.metadata.main || "index.js"}"
|
209 | `)]);
|
210 | })();
|
211 | }
|
212 |
|
213 | prepareLinuxApplicationStageDirectory(options) {
|
214 | var _this2 = this;
|
215 |
|
216 | return (0, _bluebirdLst().coroutine)(function* () {
|
217 | const appOutDir = options.appOutDir;
|
218 | yield (0, _fs().copyFile)(path.join((yield (0, _binDownload().getBin)("node", `${_this2.version}-linux-${options.arch === "ia32" ? "x86" : options.arch}`, null)), "node"), path.join(appOutDir, "node"));
|
219 | const mainPath = path.join(appOutDir, options.packager.executableName);
|
220 | yield writeExecutableMain(mainPath, `#!/bin/sh
|
221 | DIR=$(dirname "$0")
|
222 | "$DIR/node" "$DIR/app/${options.packager.info.metadata.main || "index.js"}"
|
223 | `);
|
224 | })();
|
225 | }
|
226 |
|
227 | prepareApplicationStageDirectory(options) {
|
228 | var _this3 = this;
|
229 |
|
230 | return (0, _bluebirdLst().coroutine)(function* () {
|
231 | yield (0, _fsExtraP().emptyDir)(options.appOutDir);
|
232 | const packager = options.packager;
|
233 |
|
234 | if (packager.platform === _core().Platform.MAC) {
|
235 | yield _this3.prepareMacosApplicationStageDirectory(packager, options);
|
236 | } else if (packager.platform === _core().Platform.LINUX) {
|
237 | yield _this3.prepareLinuxApplicationStageDirectory(options);
|
238 | } else {
|
239 | throw new Error(`Unsupported platform: ${packager.platform}`);
|
240 | }
|
241 | })();
|
242 | }
|
243 |
|
244 | }
|
245 |
|
\ | No newline at end of file |