This repository has been archived by the owner on Feb 16, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcli.js
78 lines (61 loc) · 2.92 KB
/
cli.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
77
78
#!/usr/bin/env node
// Copyright 2020 Khushraj Rathod
// This file is part of electronRuntimeEnvironment.
// electronRuntimeEnvironment is free software: you can redistribute it and / or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// electronRuntimeEnvironment is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with electronRuntimeEnvironment. If not, see <https://www.gnu.org/licenses/>.
const { writeFile, mkdir, copyFile, chmod, readFile } = require('fs').promises
const { join } = require('path')
const { promisify } = require('util')
const rimraf = promisify(require('rimraf'))
const projectDir = join(__dirname, '..', '..')
const runtime = join(projectDir, 'electronRuntime')
const makeDarwin = async _ => {
const replace = require('replace-in-file');
const contentsDir = join(runtime, 'Electron.app', 'Contents')
const helperContentsDir = join(contentsDir, 'Frameworks', 'Electron Helper.app', 'Contents')
await rimraf(runtime)
await mkdir(join(helperContentsDir, 'MacOS'), { recursive: true })
await mkdir(join(contentsDir, 'MacOS'))
await mkdir(join(contentsDir, 'Resources'))
const pkg = require(join(projectDir, 'package'))
const electronVersion = pkg.version
const appName = pkg.name
await Promise.all([
writeFile(join(contentsDir, 'Resources', 'electronVersion'), electronVersion),
writeFile(join(contentsDir, 'Resources', 'appName'), appName),
writeFile(join(helperContentsDir, 'MacOS', 'Electron Helper'), ''),
copyFile(join(__dirname, 'macOS', 'fetchScriptWrapper.sh'), join(contentsDir, 'MacOS', 'Electron')),
copyFile(join(__dirname, 'macOS', 'electron.plist'), join(contentsDir, 'Info.plist')),
copyFile(join(__dirname, 'macOS', 'electron-helper.plist'), join(helperContentsDir, 'Info.plist')),
])
await replace({
files: join(contentsDir, 'MacOS', 'Electron'),
from: 'SUBSTITUTE_RUNTIME_CODE',
to: await readFile(join(__dirname, 'macOS', 'fetchRuntime.js'), { encoding: 'utf-8' })
})
await chmod(join(contentsDir, 'MacOS', 'Electron'), 0o755)
}
const makeWindows = _ => { throw "Windows is a work in progress, please check back later" }
const makeLinux = _ => { throw "Linux is a work in progress, please check back later" }
switch (process.platform) {
case "win32":
makeWindows()
break;
case "darwin":
makeDarwin()
break;
case "linux":
makeLinux()
break;
default:
throw `Platform: ${process.platform} not supported`
}
console.log("Runtime ready")