Skip to content

Commit

Permalink
Decouple install/update from the rest of zxb
Browse files Browse the repository at this point in the history
zxb previously relied on the script name to be passed in along with arguments to the script. Since that's no longer the case, I needed to figure out a better way of handling installing/updating zxb.
  • Loading branch information
pyronaur committed Oct 26, 2022
1 parent 4a97dd3 commit a58ca0f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
7 changes: 5 additions & 2 deletions src/inc/commands.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { binfo, search, getSourceDirectories, scriptPaths, addSourceDirectory, g
import { confirm, selection } from "./helpers.mjs";
import { getBins, relinkBins, makeScriptExecutable } from './bins.mjs'
import { ZXB_PATHS, get, update as updateConfig } from "./config.mjs";
import { installLatestRelease } from "./install.mjs";
import { version } from "./github.mjs";

let commandInfo = {};
Expand Down Expand Up @@ -262,7 +261,11 @@ async function update() {
}

console.log("\nUpdating...")
await installLatestRelease();
cd(`${ZXB_PATHS.zxb}/src`);
const result = await $`zx install.mjs --update`;
if (result.exitCode !== 0) {
throw new Error(result);
}
updateConfig("version", latestVersion)
console.log("Done!")
}
Expand Down
15 changes: 7 additions & 8 deletions src/inc/install.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ const zxb = `${os.homedir()}/.zxb`

/**
*
* This is a standalone zx file that also exports the functions
* that it uses so that zxb can reuse parts of
* the code in the updater.
* This is a standalone zx file for installing and updating zxb.
*
*/

Expand Down Expand Up @@ -95,7 +93,7 @@ async function download(url) {
process.exit(1);
}

export async function installLatestRelease() {
async function installLatestRelease() {
const releaseUrl = "https://github.com/pyronaur/zxb/releases/latest/download/latest.zip";

cd(zxb)
Expand Down Expand Up @@ -144,11 +142,12 @@ if (parseInt(zx_version.toString()[0]) < 7) {
*
* That's why this is is a necessary side-effect:
*/
if (process.args?._?.length === 1 && !process.args._[0].includes('zxb.mjs')) {

// Turn off verbose mode by default
$.verbose = argv.verbose || false;

// Turn off verbose mode by default
$.verbose = argv.verbose || false;
if (argv.update) {
await installLatestRelease();
} else {
await fs.ensureDir(`${zxb}/bin`);

console.log(`\nInstalling ${chalk.bold("zxb")}...\n`);
Expand Down

0 comments on commit a58ca0f

Please sign in to comment.