-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
neil
authored and
neil
committed
Feb 8, 2023
1 parent
61ecc1e
commit e61c09b
Showing
4 changed files
with
41 additions
and
34 deletions.
There are no files selected for viewing
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,29 @@ | ||
import { spawn } from 'child_process'; | ||
import { clean } from 'semver'; | ||
|
||
export async function installPackage(full_name: string) { | ||
return await new Promise((resolve, reject) => { | ||
let version = ''; | ||
let lastError = ''; | ||
const teaInstallation = spawn('tea', [`+${full_name}`, 'true']); | ||
|
||
teaInstallation.stdout.on('data', (data) => { | ||
console.log('stdout:', data); | ||
}); | ||
|
||
teaInstallation.stderr.on('data', (err) => { | ||
lastError = err.toString(); | ||
if (lastError && lastError.includes('installed') && lastError.includes(full_name)) { | ||
version = lastError.split('/').pop() || ''; | ||
} | ||
}); | ||
|
||
teaInstallation.on('exit', (code) => { | ||
if (code === 0) { | ||
resolve({ version: clean(version) }); | ||
} else { | ||
reject(new Error(lastError)); | ||
} | ||
}); | ||
}); | ||
} |
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 |
---|---|---|
@@ -1,32 +1,6 @@ | ||
export async function installPackageCommand(full_name: string) { | ||
return new Promise((resolve, reject) => { | ||
// const teaInstallCommand = new Command('tea-install', [`+${full_name}`, 'true']); | ||
// teaInstallCommand.on('error', reject); | ||
|
||
// const handleLineOutput = async (line: string | { code: number }) => { | ||
// const c = await child; | ||
// if ( | ||
// (typeof line === 'string' && line.includes('installed:')) || | ||
// (typeof line !== 'string' && line?.code === 0) | ||
// ) { | ||
// c.kill(); | ||
// resolve(c.pid); | ||
// } else if (typeof line !== 'string' && line?.code === 1) { | ||
// reject(); | ||
// } | ||
// }; | ||
const { ipcRenderer } = window.require('electron'); | ||
|
||
// teaInstallCommand.stdout.on('data', handleLineOutput); | ||
// teaInstallCommand.stderr.on('data', handleLineOutput); | ||
// teaInstallCommand.on('close', (line: string) => { | ||
// console.log('command closed!'); | ||
// handleLineOutput(line || ''); | ||
// }); | ||
// teaInstallCommand.on('error', (line: string) => { | ||
// console.log('command error!', line); | ||
// handleLineOutput(line || ''); | ||
// }); | ||
// const child = teaInstallCommand.spawn(); | ||
setTimeout(resolve, 10000); | ||
}); | ||
export async function installPackageCommand(full_name: string) { | ||
const res = await ipcRenderer.invoke('install-package', { full_name }); | ||
console.log('install:', res); | ||
} |
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