MCPcopy
hub / github.com/xpf0000/FlyEnv / command

Method command

src/main/core/AppHelper.ts:53–205  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

51 }
52
53 async command() {
54 let command = ''
55 let icns = ``
56
57 const tmpDir = join(tmpdir(), uuid())
58 const dataPath = dirname(global.Server.AppDir!)
59 const appRoot = PathResolve(global.Server.Static!, '../../../../')
60 await mkdirp(tmpDir)
61 await chmod(tmpDir, '0755')
62 if (is.production()) {
63 if (isMacOS()) {
64 const uinfo = userInfo()
65 const role = `${uinfo.uid}:${uinfo.gid}`
66 const binDir = PathResolve(global.Server.Static!, '../../../../')
67 const plist = join(binDir, 'plist/com.flyenv.helper.plist')
68 const bin = join(binDir, 'helper/flyenv-helper')
69 const shDir = join(binDir, 'helper')
70 const shFile = join(shDir, 'flyenv-helper-init.sh')
71
72 const tmpFile = join(tmpDir, `${uuid()}.sh`)
73 await copyFile(shFile, tmpFile)
74 await chmod(tmpFile, '0755')
75
76 const tmpPlist = join(tmpDir, `${uuid()}.plist`)
77 await copyFile(plist, tmpPlist)
78 await chmod(tmpPlist, '0755')
79
80 const tmpBin = join(tmpDir, `${uuid()}.helper`)
81 await copyFile(bin, tmpBin)
82 await chmod(tmpBin, '0755')
83
84 command = `cd "${tmpDir}" && sudo /bin/zsh ./${basename(tmpFile)} "${tmpPlist}" "${tmpBin}" "${role}" "${dataPath}" "${appRoot}" && sudo rm -rf "${tmpDir}"`
85 icns = join(binDir, 'icon.icns')
86 } else if (isLinux()) {
87 const uinfo = userInfo()
88 const role = `${uinfo.uid}:${uinfo.gid}`
89 const binDir = PathResolve(global.Server.Static!, '../../../../')
90 const bin = join(binDir, 'helper/flyenv-helper')
91 const shDir = join(binDir, 'helper')
92 const shFile = join(shDir, 'flyenv-helper-init.sh')
93
94 const tmpFile = join(tmpDir, `${uuid()}.sh`)
95 await copyFile(shFile, tmpFile)
96 await chmod(tmpFile, '0755')
97
98 const tmpBin = join(tmpDir, `${uuid()}.helper`)
99 await copyFile(bin, tmpBin)
100 await chmod(tmpBin, '0755')
101
102 command = `cd "${tmpDir}" && sudo /bin/bash ./${basename(tmpFile)} "${tmpBin}" "${role}" "${dataPath}" "${appRoot}" && sudo rm -rf "${tmpDir}"`
103 icns = join(binDir, 'Icon@256x256.icns')
104 } else if (isWindows()) {
105 if (!windowsHelperBinaryExists()) {
106 throw new AppHelperError(
107 'helper_binary_missing',
108 `Windows helper binary missing: ${getWindowsHelperBinaryPath()}`
109 )
110 }

Callers 2

initHelperMethod · 0.95
handleHelperCommandMethod · 0.80

Calls 7

uuidFunction · 0.90
isMacOSFunction · 0.90
isLinuxFunction · 0.90
isWindowsFunction · 0.90
copyFileFunction · 0.85

Tested by

no test coverage detected