Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion bin/moshcode.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -680,7 +680,8 @@ async function main() {
const { execFile } = await import("node:child_process");
process.exitCode = (await selfUpdateCommand(rest, console.log, {
upgrade: async () => {
const results = await runUpgrade(rest.filter((a) => !a.startsWith("--")));
const targets = rest.filter((a) => !a.startsWith("--"));
const results = await runUpgrade(targets.length ? targets : ["self"]);
return results.filter((r) => !r.ok).length ? 1 : 0;
},
write: (path, body) => fsp.writeFile(path, body),
Expand Down
27 changes: 27 additions & 0 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
# MOSHCODE_BIN=/path/dir wrapper bin dir (default: $HOME/.local/bin)
# MOSHCODE_REF=vX.Y.Z pin a tag/branch (default: latest release, else main)
# MOSHCODE_ALLOW_ROOT=1 install as root anyway (see below)
# MOSHCODE_NO_AUTOUPDATE=1 skip the per-user hourly update check
# MOSHCODE_NO_PROXY=1 skip the pinned-TLS proxy (https:// on a Moshpit
# name will not verify without it)
#
Expand Down Expand Up @@ -278,6 +279,30 @@ install_proxy() {
unset _proxy_sh
}

schedule_auto_update() {
if [ "${MOSHCODE_NO_AUTOUPDATE:-}" = "1" ]; then
info "MOSHCODE_NO_AUTOUPDATE=1 — skipping automatic updates"
return 0
fi
if ! (cd "$MOSHCODE_HOME" && MOSHCODE_BIN="$MOSHCODE_BIN" node --input-type=module -e '
import("@profullstack/cli/auto-update").then(async ({installAutoUpdate}) => {
const result = await installAutoUpdate({name:"moshcode",command:process.env.MOSHCODE_BIN+"/moshcode",args:["update","--if-newer"]});
if (!result.scheduled) { console.error(`moshcode: automatic updates not scheduled: ${result.reason}`); process.exitCode=1; }
else console.log(`moshcode: automatic updates scheduled with ${result.scheduler}`);
}).catch(error => { console.error(`moshcode: could not schedule automatic updates: ${error.message}`); process.exitCode=1; });
'); then
warn "automatic update check could not be scheduled"
fi
}

unschedule_auto_update() {
[ -d "$MOSHCODE_HOME/node_modules/@profullstack/cli" ] || return 0
(cd "$MOSHCODE_HOME" && node --input-type=module -e '
import("@profullstack/cli/auto-update").then(({removeAutoUpdate}) => removeAutoUpdate("moshcode"))
.catch(error => { console.error(`moshcode: could not remove automatic update check: ${error.message}`); process.exitCode=1; });
') || true
}

# ---- commands -------------------------------------------------------------
run_install() {
printf '\n%smoshcode installer%s %s— code hard, mosh harder 🤘%s\n\n' "$BOLD" "$RESET" "$ASH" "$RESET"
Expand All @@ -288,6 +313,7 @@ run_install() {
fetch_and_unpack "$_ref"
write_wrapper
ensure_path
schedule_auto_update
install_proxy
printf '\n%sdone.%s run:\n' "$ACID" "$RESET"
printf ' moshcode # open the TUI shell\n'
Expand All @@ -300,6 +326,7 @@ run_install() {

run_remove() {
info "removing moshcode"
unschedule_auto_update
rm -f "$WRAPPER" 2>/dev/null || true
rm -f "$SCRIPT_WRAPPER" 2>/dev/null || true
rm -rf "$MOSHCODE_HOME" 2>/dev/null || true
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "moshcode",
"version": "0.120.0",
"version": "0.120.1",
"type": "module",
"description": "moshcode — a metal wrapper for coding engines and native UGig/CoinPay workflow CLIs, with OpenPRD and moshscript",
"repository": {
Expand Down Expand Up @@ -37,6 +37,7 @@
"@moshcoder/moshpit-dns": "^0.5.0"
},
"dependencies": {
"@profullstack/cli": "^0.2.0",
"@profullstack/hqtui": "^0.7.0",
"@profullstack/synconfig": "^0.1.3",
"@profullstack/webhooks": "^0.1.0"
Expand Down
9 changes: 9 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 10 additions & 4 deletions src/upgrade.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import fs from "node:fs";
import { ENGINES, engineStatus, exitReason, ranOk, resolveEngine, upgradeSpec, runCmd } from "./engines.mjs";
import { TOOLS, resolveTool, toolStatus, toolUpgradeSpec } from "./tools.mjs";
import { needsRootHere, primeEscalation } from "./escalate.mjs";
import { updatePlan } from "./selfupdate.mjs";

// Self-upgrade re-runs the moshcode installer's `update` path. Defaults to the
// GitHub-hosted install.sh (always live); override with MOSHCODE_INSTALL_URL.
Expand Down Expand Up @@ -203,10 +204,15 @@ export async function runUpgrade(targets = [], io = {}) {
log(`\n· moshcode runs from a git checkout (${MOSHCODE_HOME}) — \`git pull\` there to update it (skipping self-reinstall).`);
} else {
const before = selfVersion();
const ok = await run("moshcode", selfSpec(), "(self)");
const after = selfVersion();
if (ok && before && after) {
log(before === after ? `· moshcode already at ${after}` : `· moshcode ${before} → ${after} — restart moshcode to load it.`);
const decision = await updatePlan({ installed: before });
if (!decision.act) {
log(`\n· moshcode ${before || "version unknown"}: ${decision.why}; skipping self-reinstall.`);
} else {
const ok = await run("moshcode", selfSpec(), "(self)");
const after = selfVersion();
if (ok && before && after) {
log(before === after ? `· moshcode already at ${after}` : `· moshcode ${before} → ${after} — restart moshcode to load it.`);
}
}
}
}
Expand Down
Loading