From 9c57a002f38dba46b2f69db74c5a16968ed0b9a1 Mon Sep 17 00:00:00 2001 From: SrGooglo Date: Fri, 2 Feb 2024 12:43:26 +0100 Subject: [PATCH] use exec cb --- .../installs_steps_methods/git_clone.js | 24 ++++-- .../installs_steps_methods/git_pull.js | 22 +++-- .../installs_steps_methods/git_reset.js | 84 +++++++++++++++++-- 3 files changed, 108 insertions(+), 22 deletions(-) diff --git a/src/main/pkg_mng/installs_steps_methods/git_clone.js b/src/main/pkg_mng/installs_steps_methods/git_clone.js index 7521e5b..7df2730 100644 --- a/src/main/pkg_mng/installs_steps_methods/git_clone.js +++ b/src/main/pkg_mng/installs_steps_methods/git_clone.js @@ -20,15 +20,25 @@ export default async (manifest, step) => { statusText: `Cloning ${step.url}`, }) - console.log(`USING GIT BIN>`, gitCMD) + console.log(`USING GIT BIN >`, gitCMD) console.log(`[${manifest.id}] steps.git_clone() | Cloning ${step.url}...`) - const command = `${gitCMD} clone --depth ${step.depth ?? 1} --recurse-submodules --remote-submodules ${step.url} ${final_path}` + const command = [ + gitCMD, + "clone", + //`--depth ${step.depth ?? 1}`, + //"--filter=blob:none", + //"--filter=tree:0", + "--recurse-submodules", + "--remote-submodules", + step.url, + final_path, + ] await new Promise((resolve, reject) => { ChildProcess.exec( - command, + command.join(" "), { shell: true, cwd: final_path, @@ -36,11 +46,11 @@ export default async (manifest, step) => { (error, out) => { if (error) { console.error(error) - reject(error) - } else { - console.log(out) - resolve() + return reject(error) } + + console.log(out) + return resolve() } ) }) diff --git a/src/main/pkg_mng/installs_steps_methods/git_pull.js b/src/main/pkg_mng/installs_steps_methods/git_pull.js index eb406f4..ccb6633 100644 --- a/src/main/pkg_mng/installs_steps_methods/git_pull.js +++ b/src/main/pkg_mng/installs_steps_methods/git_pull.js @@ -21,12 +21,22 @@ export default async (manifest, step) => { fs.mkdirSync(_path, { recursive: true }) await new Promise((resolve, reject) => { - const process = ChildProcess.exec(`${gitCMD} pull`, { - cwd: _path, - shell: true, - }) + ChildProcess.exec( + `${gitCMD} pull`, + { + cwd: _path, + shell: true, + }, + (error, out) => { + if (error) { + console.error(error) + return reject(error) + } - process.on("exit", resolve) - process.on("error", reject) + console.log(out) + + return resolve() + } + ) }) } \ No newline at end of file diff --git a/src/main/pkg_mng/installs_steps_methods/git_reset.js b/src/main/pkg_mng/installs_steps_methods/git_reset.js index d73fcb3..f75cf04 100644 --- a/src/main/pkg_mng/installs_steps_methods/git_reset.js +++ b/src/main/pkg_mng/installs_steps_methods/git_reset.js @@ -10,7 +10,65 @@ const gitCMD = fs.existsSync(Vars.git_path) ? `${Vars.git_path}` : "git" export default async (manifest, step) => { const _path = path.resolve(manifest.install_path, step.path) - const from = step.from ?? "origin/main" + const from = step.from ?? "HEAD" + + if (!fs.existsSync(_path)) { + fs.mkdirSync(_path, { recursive: true }) + } + + sendToRender(`pkg:update:status`, { + id: manifest.id, + statusText: `Fetching from origin...`, + }) + + console.log(`[${manifest.id}] steps.git_reset() | Fetching from origin...`) + + // fetch from origin + await new Promise((resolve, reject) => { + ChildProcess.exec( + `${gitCMD} fetch origin`, + { + cwd: _path, + shell: true, + }, + (error, out) => { + if (error) { + console.error(error) + return reject(error) + } + + console.log(out) + return resolve() + } + ) + }) + + sendToRender(`pkg:update:status`, { + id: manifest.id, + statusText: `Cleaning untracked files...`, + }) + + console.log(`[${manifest.id}] steps.git_reset() | Cleaning...`) + + await new Promise((resolve, reject) => { + ChildProcess.exec( + `${gitCMD} clean -df`, + { + cwd: _path, + shell: true, + }, + (error, out) => { + if (error) { + console.error(error) + return reject(error) + } + + console.log(out) + + return resolve() + } + ) + }) sendToRender(`pkg:update:status`, { id: manifest.id, @@ -19,15 +77,23 @@ export default async (manifest, step) => { console.log(`[${manifest.id}] steps.git_reset() | Reseting to ${from}...`) - fs.mkdirSync(_path, { recursive: true }) - await new Promise((resolve, reject) => { - const process = ChildProcess.exec(`${gitCMD} reset --hard ${from}`, { - cwd: _path, - shell: true, - }) + ChildProcess.exec( + `${gitCMD} reset --hard ${from}`, + { + cwd: _path, + shell: true, + }, + (error, out) => { + if (error) { + console.error(error) + return reject(error) + } - process.on("exit", resolve) - process.on("error", reject) + console.log(out) + + return resolve() + } + ) }) } \ No newline at end of file