-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: ipcMain hooks & build/exec utils
Signed-off-by: uiuing <uiuing@foxmail.com>
- Loading branch information
Showing
32 changed files
with
232 additions
and
138 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import decompress from 'decompress' | ||
import { existsSync, readdirSync, renameSync, unlinkSync } from 'fs' | ||
import { join } from 'path' | ||
|
||
import { checkVersionEnv, isNewVersion } from '../methods/check' | ||
import { ingopPaths, ingopPathsArray } from '../methods/config' | ||
import { isWin } from '../methods/config' | ||
import { buildGop } from '../methods/env/compile' | ||
import { EnvManage } from '../methods/env/types' | ||
import { envManage as unixEnvManage } from '../methods/env/unix/execute' | ||
import { envManage as winEnvManage } from '../methods/env/win/execute' | ||
import { initDirs, removeDirs, saveFile } from '../methods/files' | ||
import { ExistsEnv, FileData } from './types' | ||
|
||
export const ingopHome = { | ||
init: () => { | ||
initDirs(ingopPathsArray) | ||
}, | ||
remove: () => { | ||
removeDirs(ingopPathsArray) | ||
} | ||
} | ||
|
||
export const existsEnv: ExistsEnv = { | ||
gop: { | ||
exist: async () => { | ||
return (await checkVersionEnv('gop')) !== '' | ||
}, | ||
isNew: async (newVersion: string) => { | ||
return await isNewVersion('gop', newVersion) | ||
} | ||
}, | ||
env: { | ||
go: { | ||
exist: async () => { | ||
return (await checkVersionEnv('go')) !== '' | ||
}, | ||
isNew: async (newVersion: string) => { | ||
return await isNewVersion('go', newVersion) | ||
} | ||
} | ||
} | ||
} | ||
|
||
export class autoSaveFile { | ||
path: string | ||
constructor({ fileName, base64Data }: FileData) { | ||
this.path = join(ingopPaths.home, fileName) | ||
saveFile(this.path, base64Data) | ||
} | ||
async gop() { | ||
const { gop_root, home } = ingopPaths | ||
await decompress(this.path, home) | ||
const goplus_gop_hash_dir = join( | ||
home, | ||
readdirSync(home).filter((dirName) => | ||
/goplus-gop-(.*?)/g.test(dirName) | ||
)[0] | ||
) | ||
removeDirs([gop_root]) | ||
renameSync(goplus_gop_hash_dir, gop_root) | ||
removeDirs([goplus_gop_hash_dir]) | ||
if (existsSync(this.path)) unlinkSync(this.path) | ||
} | ||
env = { | ||
go: async () => { | ||
await decompress(this.path, ingopPaths.go_root) | ||
if (existsSync(this.path)) unlinkSync(this.path) | ||
} | ||
} | ||
} | ||
|
||
export const compile = { | ||
gop: async (): Promise<boolean> => { | ||
return await buildGop() | ||
} | ||
} | ||
|
||
export const envManage: EnvManage = isWin ? winEnvManage : unixEnvManage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { checkVersionEnv, execCommand, isNewVersion } from '../check' | ||
|
||
async function test() { | ||
console.info( | ||
'test check function [execCommand("ls")] :', | ||
await execCommand('ls') | ||
) | ||
|
||
console.info( | ||
'test check function [checkVersionEnv("go")] :', | ||
await checkVersionEnv('go') | ||
) | ||
|
||
console.info( | ||
'test check function [isNewVersion("go","1.16")] :', | ||
await isNewVersion('go', '1.16') | ||
) | ||
} | ||
|
||
test() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { buildGop } from '../env/compile' | ||
|
||
export function testBuildGop() { | ||
buildGop().then((r) => { | ||
console.info('testBuildGop result:', r) | ||
}) | ||
} | ||
|
||
testBuildGop() |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { exec } from 'child_process' | ||
|
||
export function execCommand(cmd: string): Promise<string | null> { | ||
return new Promise((resolve) => { | ||
exec(`${cmd}`, { encoding: 'utf8' }, (err, stdout) => { | ||
if (err) resolve(null) | ||
resolve(stdout) | ||
}) | ||
}) | ||
} | ||
|
||
export async function checkVersionEnv(cmd: string): Promise<string> { | ||
const s = await execCommand(`${cmd} version`) | ||
if (s === null) return '' | ||
const r = s.match(/[0-9.]+/) | ||
return r === null ? '' : r[0] | ||
} | ||
|
||
export async function isNewVersion( | ||
cmd: string, | ||
newVersion: string | ||
): Promise<boolean> { | ||
const nowVersion = await checkVersionEnv(cmd) | ||
if (!nowVersion) return false | ||
const levels1 = nowVersion.split('.') | ||
const levels2 = newVersion.split('.') | ||
const length = Math.max(levels1.length, levels2.length) | ||
for (let i = 0; i < length; i++) { | ||
const _now = i < levels1.length ? parseInt(levels1[i]) : 0 | ||
const _new = i < levels2.length ? parseInt(levels2[i]) : 0 | ||
if (_now > _new) return true | ||
if (_now < _new) return false | ||
} | ||
return true | ||
} |
Empty file.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { join } from 'path' | ||
|
||
import { checkVersionEnv, execCommand, isNewVersion } from '../check' | ||
import { ingopPaths } from '../config' | ||
|
||
export async function buildGop(): Promise<boolean> { | ||
const goBinFile = | ||
(await checkVersionEnv('go')) !== '' && (await isNewVersion('go', '1.16')) | ||
? 'go' | ||
: join(ingopPaths.go_bin, 'go') | ||
const command = `cd "${ingopPaths.gop_root}" && "${goBinFile}" run cmd/make.go --build` | ||
try { | ||
return (await execCommand(command)) !== null | ||
} catch (e) { | ||
return false | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
5 changes: 1 addition & 4 deletions
5
ingop/main/server/utils/index.ts → ingop/main/methods/utils/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export type AutoScreenSize = { | ||
width: number | ||
height: number | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.