@elumixor/devkit 0.11.1 → 0.11.2

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.
package/README.md CHANGED
@@ -19,6 +19,9 @@ So does a positional, for a shell that completes them: `devkit build mac iwatch`
19
19
  bun add -d @elumixor/devkit
20
20
  ```
21
21
 
22
+ `devkit update` moves the global `devkit` and, run inside a project, its dependency to the newest
23
+ published version (`--dry` prints what would change).
24
+
22
25
  ## Configure
23
26
 
24
27
  Add a `devkit` block to your root `package.json`. Three phases, each a map of platform name to one
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@elumixor/devkit",
3
- "version": "0.11.1",
3
+ "version": "0.11.2",
4
4
  "description": "Dev orchestrator for bun monorepos — free ports, run apps side-by-side, open the browser when ready",
5
5
  "author": "elumixor",
6
6
  "license": "ISC",
package/src/bin/devkit.ts CHANGED
@@ -11,6 +11,7 @@ import { runRelease } from "../release.ts";
11
11
  import { runTarget } from "../run-target.ts";
12
12
  import { pullSecrets, pushSecrets } from "../secrets.ts";
13
13
  import { runSetup } from "../setup.ts";
14
+ import { runUpdate } from "../update.ts";
14
15
  import { runVersion } from "../version.ts";
15
16
 
16
17
  const { values, positionals } = parseArgs({
@@ -43,6 +44,7 @@ const usage = `usage: devkit dev [platforms...] run the dev processes
43
44
  devkit version write the source version into every file that declares one
44
45
  devkit release <prefix> tag this commit <prefix>-v<timestamp> and push it
45
46
  devkit secrets push|pull [root] sync age-encrypted secrets
47
+ devkit update [--dry] update the global devkit and this project's dependency to the latest
46
48
 
47
49
  Platforms are whatever "devkit.dev", "devkit.build" and "devkit.deploy" name in package.json —
48
50
  typically web, mac, iphone, iwatch. Naming one also runs the platforms it declares in "needs".
@@ -115,6 +117,10 @@ try {
115
117
  await runRelease(rest[0] ?? "");
116
118
  break;
117
119
  }
120
+ case "update": {
121
+ await runUpdate(values.dry);
122
+ break;
123
+ }
118
124
  case "secrets": {
119
125
  const [action, dir] = rest;
120
126
  chdirTo(dir);
package/src/update.ts ADDED
@@ -0,0 +1,32 @@
1
+ import { existsSync } from "node:fs";
2
+ import { resolve } from "node:path";
3
+ import { $ } from "bun";
4
+ import pkg from "../package.json" with { type: "json" };
5
+
6
+ const NAME = "@elumixor/devkit";
7
+
8
+ /**
9
+ * Bring devkit to the newest published version: the global `devkit` on PATH always, and the
10
+ * project's own dependency when the current directory declares one. A pinned version stays pinned.
11
+ */
12
+ export async function runUpdate(dry = false) {
13
+ const response = await fetch(`https://registry.npmjs.org/${NAME}/latest`);
14
+ if (!response.ok) throw new Error(`npm registry answered ${response.status} for ${NAME}`);
15
+ const latest = ((await response.json()) as { version: string }).version;
16
+
17
+ console.log(`global: ${pkg.version} -> ${latest}`);
18
+ if (!dry) await $`bun add -g ${NAME}@${latest}`.quiet();
19
+
20
+ const manifestPath = resolve("package.json");
21
+ if (!existsSync(manifestPath)) return;
22
+ const manifest = await Bun.file(manifestPath).json();
23
+ const dev = manifest.devDependencies?.[NAME] as string | undefined;
24
+ const spec = dev ?? (manifest.dependencies?.[NAME] as string | undefined);
25
+ if (!spec) return;
26
+
27
+ const pinned = /^\d/.test(spec);
28
+ console.log(`${manifest.name ?? "project"}: ${spec} -> ${pinned ? "" : "^"}${latest}`);
29
+ if (dry) return;
30
+ const flags = [...(dev ? ["-d"] : []), ...(pinned ? ["--exact"] : [])];
31
+ await $`bun add ${flags} ${NAME}@${latest}`.quiet();
32
+ }