mirror of
https://github.com/ragestudio/relic.git
synced 2025-06-09 10:34:18 +00:00
improve install scripts
This commit is contained in:
parent
86236db834
commit
b626740b8a
@ -39,7 +39,11 @@ export default async function install(manifest) {
|
|||||||
try {
|
try {
|
||||||
pkg = await initManifest(pkg)
|
pkg = await initManifest(pkg)
|
||||||
|
|
||||||
fs.mkdirSync(pkg.install_path, { recursive: true })
|
if (fs.existsSync(pkg.install_path)) {
|
||||||
|
await fs.rmSync(pkg.install_path, { recursive: true })
|
||||||
|
}
|
||||||
|
|
||||||
|
await fs.mkdirSync(pkg.install_path, { recursive: true })
|
||||||
|
|
||||||
// append to db
|
// append to db
|
||||||
await updateInstalledPackage(pkg)
|
await updateInstalledPackage(pkg)
|
||||||
@ -47,7 +51,7 @@ export default async function install(manifest) {
|
|||||||
if (typeof pkg.before_install === "function") {
|
if (typeof pkg.before_install === "function") {
|
||||||
sendToRender(`pkg:update:status`, {
|
sendToRender(`pkg:update:status`, {
|
||||||
id: pkg_id,
|
id: pkg_id,
|
||||||
status: "loading",
|
status: "installing",
|
||||||
statusText: `Performing before_install hook...`,
|
statusText: `Performing before_install hook...`,
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -59,7 +63,7 @@ export default async function install(manifest) {
|
|||||||
|
|
||||||
sendToRender(`pkg:update:status`, {
|
sendToRender(`pkg:update:status`, {
|
||||||
id: pkg_id,
|
id: pkg_id,
|
||||||
status: "loading",
|
status: "installing",
|
||||||
statusText: `Performing install steps...`,
|
statusText: `Performing install steps...`,
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -69,7 +73,7 @@ export default async function install(manifest) {
|
|||||||
if (typeof pkg.after_install === "function") {
|
if (typeof pkg.after_install === "function") {
|
||||||
sendToRender(`pkg:update:status`, {
|
sendToRender(`pkg:update:status`, {
|
||||||
id: pkg_id,
|
id: pkg_id,
|
||||||
status: "loading",
|
status: "installing",
|
||||||
statusText: `Performing after_install hook...`,
|
statusText: `Performing after_install hook...`,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -41,6 +41,12 @@ export default async function uninstall(pkg_id) {
|
|||||||
|
|
||||||
await rimraf(pkg.install_path)
|
await rimraf(pkg.install_path)
|
||||||
|
|
||||||
|
sendToRender("pkg:update:status", {
|
||||||
|
id: pkg_id,
|
||||||
|
status: "uninstalling",
|
||||||
|
statusText: null,
|
||||||
|
})
|
||||||
|
|
||||||
sendToRender("pkg:remove", {
|
sendToRender("pkg:remove", {
|
||||||
id: pkg_id
|
id: pkg_id
|
||||||
})
|
})
|
||||||
|
@ -10,15 +10,15 @@ import sendToRender from "../../utils/sendToRender"
|
|||||||
import processGenericSteps from "../installs_steps_methods"
|
import processGenericSteps from "../installs_steps_methods"
|
||||||
|
|
||||||
export default async function update(pkg_id) {
|
export default async function update(pkg_id) {
|
||||||
|
// find package manifest
|
||||||
|
let pkg = await getInstalledPackages(pkg_id)
|
||||||
|
|
||||||
|
if (!pkg) {
|
||||||
|
sendToRender("runtime:error", "Package not found")
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// find package manifest
|
|
||||||
let pkg = await getInstalledPackages(pkg_id)
|
|
||||||
|
|
||||||
if (!pkg) {
|
|
||||||
sendToRender("runtime:error", "Package not found")
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
// output to logs
|
// output to logs
|
||||||
console.log(`[${pkg_id}] update() | Updating to latest version...`)
|
console.log(`[${pkg_id}] update() | Updating to latest version...`)
|
||||||
|
|
||||||
|
@ -1,11 +1,25 @@
|
|||||||
import path from "node:path"
|
import path from "node:path"
|
||||||
import fs from "node:fs"
|
import fs from "node:fs"
|
||||||
|
import os from "node:os"
|
||||||
import ChildProcess from "node:child_process"
|
import ChildProcess from "node:child_process"
|
||||||
|
|
||||||
import sendToRender from "../../utils/sendToRender"
|
import sendToRender from "../../utils/sendToRender"
|
||||||
|
|
||||||
|
import Vars from "../../vars"
|
||||||
|
|
||||||
|
const gitCMD = fs.existsSync(Vars.git_path) ? `${Vars.git_path}` : "git"
|
||||||
|
|
||||||
export default async (manifest, step) => {
|
export default async (manifest, step) => {
|
||||||
const _path = path.resolve(manifest.install_path, step.path)
|
const tmp_path = path.resolve(os.tmpdir(), `rsb_${manifest.id}_clone_${new Date().getTime()}`)
|
||||||
|
const final_path = path.resolve(manifest.install_path, step.path)
|
||||||
|
|
||||||
|
if (fs.existsSync(tmp_path)) {
|
||||||
|
fs.rmdirSync(tmp_path, { recursive: true })
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!fs.existsSync(final_path)) {
|
||||||
|
fs.mkdirSync(final_path, { recursive: true })
|
||||||
|
}
|
||||||
|
|
||||||
sendToRender(`pkg:update:status`, {
|
sendToRender(`pkg:update:status`, {
|
||||||
id: manifest.id,
|
id: manifest.id,
|
||||||
@ -14,14 +28,34 @@ export default async (manifest, step) => {
|
|||||||
|
|
||||||
console.log(`[${manifest.id}] steps.git_clone() | Cloning ${step.url}...`)
|
console.log(`[${manifest.id}] steps.git_clone() | Cloning ${step.url}...`)
|
||||||
|
|
||||||
fs.mkdirSync(_path, { recursive: true })
|
const command = `${gitCMD} clone --recurse-submodules --remote-submodules ${step.url} ${tmp_path}`
|
||||||
|
|
||||||
|
fs.mkdirSync(final_path, { recursive: true })
|
||||||
|
|
||||||
await new Promise((resolve, reject) => {
|
await new Promise((resolve, reject) => {
|
||||||
const process = ChildProcess.exec(`${global.GIT_PATH ?? "git"} clone --recurse-submodules --remote-submodules ${step.url} ${_path}`, {
|
ChildProcess.exec(
|
||||||
shell: true,
|
command,
|
||||||
})
|
{
|
||||||
|
shell: true,
|
||||||
process.on("exit", resolve)
|
},
|
||||||
process.on("error", reject)
|
(error, out) => {
|
||||||
|
if (error) {
|
||||||
|
console.error(error)
|
||||||
|
reject(error)
|
||||||
|
} else {
|
||||||
|
console.log(out)
|
||||||
|
resolve()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// move tmp_path to final_path
|
||||||
|
await fs.promises.rename(tmp_path, final_path)
|
||||||
|
|
||||||
|
if (fs.existsSync(tmp_path)) {
|
||||||
|
fs.rmdirSync(tmp_path, { recursive: true })
|
||||||
|
}
|
||||||
|
|
||||||
|
return manifest
|
||||||
}
|
}
|
@ -4,6 +4,10 @@ import ChildProcess from "node:child_process"
|
|||||||
|
|
||||||
import sendToRender from "../../utils/sendToRender"
|
import sendToRender from "../../utils/sendToRender"
|
||||||
|
|
||||||
|
import Vars from "../../vars"
|
||||||
|
|
||||||
|
const gitCMD = fs.existsSync(Vars.git_path) ? `${Vars.git_path}` : "git"
|
||||||
|
|
||||||
export default async (manifest, step) => {
|
export default async (manifest, step) => {
|
||||||
const _path = path.resolve(manifest.install_path, step.path)
|
const _path = path.resolve(manifest.install_path, step.path)
|
||||||
|
|
||||||
@ -17,7 +21,7 @@ export default async (manifest, step) => {
|
|||||||
fs.mkdirSync(_path, { recursive: true })
|
fs.mkdirSync(_path, { recursive: true })
|
||||||
|
|
||||||
await new Promise((resolve, reject) => {
|
await new Promise((resolve, reject) => {
|
||||||
const process = ChildProcess.exec(`${global.GIT_PATH ?? "git"} pull`, {
|
const process = ChildProcess.exec(`${gitCMD} pull`, {
|
||||||
cwd: _path,
|
cwd: _path,
|
||||||
shell: true,
|
shell: true,
|
||||||
})
|
})
|
||||||
|
@ -1,10 +1,13 @@
|
|||||||
|
|
||||||
import path from "node:path"
|
import path from "node:path"
|
||||||
import fs from "node:fs"
|
import fs from "node:fs"
|
||||||
import ChildProcess from "node:child_process"
|
import ChildProcess from "node:child_process"
|
||||||
|
|
||||||
import sendToRender from "../../utils/sendToRender"
|
import sendToRender from "../../utils/sendToRender"
|
||||||
|
|
||||||
|
import Vars from "../../vars"
|
||||||
|
|
||||||
|
const gitCMD = fs.existsSync(Vars.git_path) ? `${Vars.git_path}` : "git"
|
||||||
|
|
||||||
export default async (manifest, step) => {
|
export default async (manifest, step) => {
|
||||||
const _path = path.resolve(manifest.install_path, step.path)
|
const _path = path.resolve(manifest.install_path, step.path)
|
||||||
const from = step.from ?? "origin/main"
|
const from = step.from ?? "origin/main"
|
||||||
@ -19,7 +22,7 @@ export default async (manifest, step) => {
|
|||||||
fs.mkdirSync(_path, { recursive: true })
|
fs.mkdirSync(_path, { recursive: true })
|
||||||
|
|
||||||
await new Promise((resolve, reject) => {
|
await new Promise((resolve, reject) => {
|
||||||
const process = ChildProcess.exec(`${global.GIT_PATH ?? "git"} reset --hard ${from}`, {
|
const process = ChildProcess.exec(`${gitCMD} reset --hard ${from}`, {
|
||||||
cwd: _path,
|
cwd: _path,
|
||||||
shell: true,
|
shell: true,
|
||||||
})
|
})
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
import path from "node:path"
|
import path from "node:path"
|
||||||
import fs from "node:fs"
|
import fs from "node:fs"
|
||||||
|
import os from "node:os"
|
||||||
|
|
||||||
import { pipeline as streamPipeline } from "node:stream/promises"
|
import { pipeline as streamPipeline } from "node:stream/promises"
|
||||||
|
|
||||||
import humanFormat from "human-format"
|
import humanFormat from "human-format"
|
||||||
@ -26,7 +28,7 @@ export default async (manifest, step) => {
|
|||||||
console.log(`[${manifest.id}] steps.http() | Downloading ${step.url} to ${_path}`)
|
console.log(`[${manifest.id}] steps.http() | Downloading ${step.url} to ${_path}`)
|
||||||
|
|
||||||
if (step.tmp) {
|
if (step.tmp) {
|
||||||
_path = path.resolve(TMP_PATH, String(new Date().getTime()))
|
_path = path.resolve(os.tmpdir(), String(new Date().getTime()), path.basename(step.url))
|
||||||
}
|
}
|
||||||
|
|
||||||
fs.mkdirSync(path.resolve(_path, ".."), { recursive: true })
|
fs.mkdirSync(path.resolve(_path, ".."), { recursive: true })
|
||||||
|
@ -12,10 +12,23 @@ const InstallationStepsMethods = {
|
|||||||
git_reset: ISM_GIT_RESET,
|
git_reset: ISM_GIT_RESET,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const StepsOrders = [
|
||||||
|
"git_clones",
|
||||||
|
"git_clones_steps",
|
||||||
|
"git_pulls",
|
||||||
|
"git_update",
|
||||||
|
"git_pulls_steps",
|
||||||
|
"git_reset",
|
||||||
|
"drive_downloads",
|
||||||
|
"http_downloads",
|
||||||
|
]
|
||||||
|
|
||||||
export default async function processGenericSteps(pkg, steps) {
|
export default async function processGenericSteps(pkg, steps) {
|
||||||
console.log(`[${pkg.id}] steps() | Processing steps...`, steps)
|
console.log(`[${pkg.id}] steps() | Processing steps...`, steps)
|
||||||
|
|
||||||
for await (const [stepKey, stepValue] of Object.entries(steps)) {
|
const stepsEntries = Object.entries(steps)
|
||||||
|
|
||||||
|
for await (const [stepKey, stepValue] of stepsEntries) {
|
||||||
switch (stepKey) {
|
switch (stepKey) {
|
||||||
case "drive_downloads": {
|
case "drive_downloads": {
|
||||||
for await (const dl_step of stepValue) {
|
for await (const dl_step of stepValue) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user