1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | const fs = require("fs");
|
4 | const path = require("path");
|
5 | const builder_util_1 = require("builder-util");
|
6 | const binDownload_1 = require("../binDownload");
|
7 |
|
8 | const downloadFFMPEG = async (electronVersion, platform, arch) => {
|
9 | const ffmpegFileName = `ffmpeg-v${electronVersion}-${platform}-${arch}.zip`;
|
10 | const url = `https://github.com/electron/electron/releases/download/v${electronVersion}/${ffmpegFileName}`;
|
11 | builder_util_1.log.info({ file: ffmpegFileName }, "downloading non-proprietary FFMPEG");
|
12 | return (0, binDownload_1.getBin)(ffmpegFileName, url);
|
13 | };
|
14 | const copyFFMPEG = (targetPath, platform) => (sourcePath) => {
|
15 | let fileName = "ffmpeg.dll";
|
16 | if (["darwin", "mas"].includes(platform)) {
|
17 | fileName = "libffmpeg.dylib";
|
18 | }
|
19 | else if (platform === "linux") {
|
20 | fileName = "libffmpeg.so";
|
21 | }
|
22 | const libPath = path.resolve(sourcePath, fileName);
|
23 | const libTargetPath = path.resolve(targetPath, fileName);
|
24 | builder_util_1.log.info({ lib: libPath, target: libTargetPath }, "copying non-proprietary FFMPEG");
|
25 |
|
26 | if (!fs.existsSync(libPath)) {
|
27 | throw new Error(`Failed to find FFMPEG library file at path: ${libPath}`);
|
28 | }
|
29 |
|
30 | if (libPath !== libTargetPath) {
|
31 | fs.copyFileSync(libPath, libTargetPath);
|
32 | }
|
33 | return libTargetPath;
|
34 | };
|
35 | function injectFFMPEG(options, electrionVersion) {
|
36 | let libPath = options.appOutDir;
|
37 | if (options.platformName === "darwin") {
|
38 | libPath = path.resolve(options.appOutDir, "Electron.app/Contents/Frameworks/Electron Framework.framework/Versions/A/Libraries");
|
39 | }
|
40 | return downloadFFMPEG(electrionVersion, options.platformName, options.arch).then(copyFFMPEG(libPath, options.platformName));
|
41 | }
|
42 | exports.default = injectFFMPEG;
|
43 |
|
\ | No newline at end of file |