forked from amilajack/popcorn-time-desktop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
postinstall.js
76 lines (68 loc) · 1.59 KB
/
postinstall.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// @flow
import os from 'os';
import path from 'path';
import fs from 'fs';
import extract from 'extract-zip';
const version = process.env.PREBUILT_FFMPEG_RELEASE || '0.37.4';
const baseDir = path.join(__dirname, 'node_modules', 'electron', 'dist');
function copy(filepath: string, dest: string) {
fs.writeFileSync(
path.join(__dirname, dest),
fs.readFileSync(path.join(__dirname, filepath))
);
}
function addEnvFileIfNotExist() {
if (fs.existsSync(path.join(__dirname, '.env'))) {
console.log('--> Using existing .env file...');
} else {
console.log('--> Creating ".env" file...');
copy('.env.example', '.env');
}
}
function getUrl(): { platform: string, dest: string } {
switch (os.type()) {
case 'Darwin':
return {
platform: 'osx',
dest: path.join(
baseDir,
'Electron.app',
'Contents',
'Frameworks',
'Electron Framework.framework',
'Libraries'
)
};
case 'Windows_NT':
return {
platform: 'win',
dest: baseDir
};
case 'Linux':
return {
platform: 'linux',
dest: baseDir
};
default:
return {
platform: 'linux',
dest: baseDir
};
}
}
function setupFfmpeg() {
const { platform, dest } = getUrl();
const zipLocation = path.join(
__dirname,
'ffmpeg',
`${version}-${platform}-${os.arch()}.zip`
);
console.log('--> Replacing ffmpeg...');
extract(zipLocation, { dir: dest }, error => {
if (error) {
console.log(error);
}
});
}
setupFfmpeg();
addEnvFileIfNotExist();