This repository has been archived on 2025-03-25. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
kernel-package-downloader/preload.js
2022-04-26 14:21:08 -04:00

26 lines
770 B
JavaScript

const { contextBridge } = require("electron")
const { resolve, join } = require("path")
const { exec } = require("child_process")
const execWithPromise = async (command, options) =>
new Promise(async (resolve, reject) =>
exec(command, options, (err, stout, sterr) =>
err ? reject(err, sterr) : resolve(stout)
)
)
contextBridge.exposeInMainWorld("installPackage", async (link) => {
const packagesPath = resolve(__dirname, "..")
try {
await execWithPromise(`git clone ${link[0]}`, {
cwd: packagesPath,
})
await execWithPromise("pnpm i --production", {
cwd: join(packagesPath, link[7]),
})
} catch (error) {
console.error(error)
return true
}
})