@cyberxon/xon 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/update.js +13 -7
  2. package/package.json +1 -1
package/dist/update.js CHANGED
@@ -1,10 +1,16 @@
1
1
  import { spawn } from "node:child_process";
2
+ import { existsSync } from "node:fs";
3
+ import { readFile } from "node:fs/promises";
2
4
  import { fileURLToPath } from "node:url";
3
5
  import path from "node:path";
4
6
  function packageRoot() {
5
7
  const dist = path.dirname(fileURLToPath(import.meta.url));
6
8
  return path.dirname(dist);
7
9
  }
10
+ async function packageName(root) {
11
+ const contents = await readFile(path.join(root, "package.json"), "utf8");
12
+ return JSON.parse(contents).name;
13
+ }
8
14
  function run(command, args, cwd) {
9
15
  return new Promise((resolve, reject) => {
10
16
  const child = spawn(command, args, { cwd, stdio: "inherit" });
@@ -35,14 +41,14 @@ function captureOutput(command, args, cwd) {
35
41
  }
36
42
  export async function updateCli() {
37
43
  const root = packageRoot();
38
- let status;
39
- try {
40
- status = await captureOutput("git", ["status", "--porcelain"], root);
41
- }
42
- catch {
43
- throw new Error(`xon isn't installed from a git checkout at ${root}, so it can't self-update. ` +
44
- "Reinstall following the README instructions.");
44
+ if (!existsSync(path.join(root, ".git"))) {
45
+ const name = await packageName(root);
46
+ console.log(`Updating ${name} via npm...`);
47
+ await run("npm", ["install", "-g", `${name}@latest`], root);
48
+ console.log(`${name} is up to date.`);
49
+ return;
45
50
  }
51
+ const status = await captureOutput("git", ["status", "--porcelain"], root);
46
52
  if (status.trim().length > 0) {
47
53
  throw new Error(`xon has local changes in ${root}. Commit or stash them before updating.`);
48
54
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cyberxon/xon",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "A CLI for Xon projects and deployments",
5
5
  "type": "module",
6
6
  "license": "UNLICENSED",