UNPKG

4.39 kBJavaScriptView Raw
1"use strict";
2
3function _bluebirdLst() {
4 const data = require("bluebird-lst");
5
6 _bluebirdLst = function () {
7 return data;
8 };
9
10 return data;
11}
12
13function _fsExtraP() {
14 const data = require("fs-extra-p");
15
16 _fsExtraP = function () {
17 return data;
18 };
19
20 return data;
21}
22
23var path = _interopRequireWildcard(require("path"));
24
25function _() {
26 const data = require("..");
27
28 _ = function () {
29 return data;
30 };
31
32 return data;
33}
34
35let doBuild = (() => {
36 var _ref = (0, _bluebirdLst().coroutine)(function* (data) {
37 if (process.env.ELECTRON_BUILDER_TMP_DIR == null) {
38 throw new Error("Env ELECTRON_BUILDER_TMP_DIR must be set for builder process");
39 }
40
41 const projectDir = process.env.PROJECT_DIR;
42
43 if (projectDir == null) {
44 throw new Error("Env PROJECT_DIR must be set for builder process");
45 }
46
47 const targets = data.targets;
48
49 if (data.platform == null) {
50 throw new Error("platform not specified");
51 }
52
53 if (targets == null) {
54 throw new Error("targets path not specified");
55 }
56
57 if (!Array.isArray(targets)) {
58 throw new Error("targets must be array of target name");
59 }
60
61 const infoFile = projectDir + path.sep + "info.json";
62 const info = yield (0, _fsExtraP().readJson)(infoFile);
63 const projectOutDir = process.env.PROJECT_OUT_DIR;
64
65 if (projectDir == null) {
66 throw new Error("Env PROJECT_OUT_DIR must be set for builder process");
67 } // yes, for now we expect the only target
68
69
70 const prepackaged = projectDir + path.sep + targets[0].unpackedDirName; // do not use build function because we don't need to publish artifacts
71
72 const options = {
73 prepackaged,
74 projectDir,
75 [data.platform]: targets.map(it => it.name + ":" + it.arch),
76 publish: "never"
77 };
78 const packager = new (_().Packager)(options);
79 const artifacts = [];
80 const relativePathOffset = projectOutDir.length + 1;
81 packager.artifactCreated(event => {
82 if (event.file == null) {
83 return;
84 }
85
86 artifacts.push({
87 file: event.file.substring(relativePathOffset),
88 target: event.target == null ? null : event.target.name,
89 arch: event.arch,
90 safeArtifactName: event.safeArtifactName,
91 isWriteUpdateInfo: event.isWriteUpdateInfo === true,
92 updateInfo: event.updateInfo
93 });
94 });
95
96 packager.stageDirPathCustomizer = (target, packager, arch) => {
97 // snap creates a lot of files and so, we cannot use tmpfs to avoid out of memory error
98 const parentDir = target.name === "snap" && !target.isUseTemplateApp ? projectOutDir : projectDir;
99 return parentDir + path.sep + `__${target.name}-${_().Arch[arch]}`;
100 }; // _build method expects final effective configuration - packager.options.config is ignored
101
102
103 yield packager._build(Object.assign({}, info.configuration, {
104 publish: null,
105 beforeBuild: null,
106 afterPack: null,
107 afterSign: null,
108 afterAllArtifactBuild: null,
109 onNodeModuleFile: null,
110 directories: {
111 output: projectOutDir,
112 buildResources: projectDir + path.sep + info.buildResourceDirName
113 }
114 }), info.metadata, info.devMetadata, info.repositoryInfo); // writeJson must be not used because it adds unwanted \n as last file symbol
115
116 yield (0, _fsExtraP().writeFile)(path.join(process.env.ELECTRON_BUILDER_TMP_DIR, "__build-result.json"), JSON.stringify(artifacts));
117 });
118
119 return function doBuild(_x) {
120 return _ref.apply(this, arguments);
121 };
122})();
123
124function _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; } }
125
126if (process.env.BUILDER_REMOVE_STAGE_EVEN_IF_DEBUG == null) {
127 process.env.BUILDER_REMOVE_STAGE_EVEN_IF_DEBUG = "true";
128}
129
130doBuild(JSON.parse(process.argv[2])).catch(error => {
131 process.exitCode = 0;
132 return (0, _fsExtraP().writeFile)(path.join(process.env.ELECTRON_BUILDER_TMP_DIR, "__build-result.json"), (error.stack || error).toString());
133});
134//# sourceMappingURL=builder-cli.js.map
\No newline at end of file