@elumixor/devkit 0.7.0 → 0.8.0
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 +17 -16
- package/package.json +1 -1
- package/src/bin/devkit.ts +1 -1
- package/src/config.ts +29 -11
- package/src/deploy.ts +5 -5
- package/src/dev.ts +9 -13
package/README.md
CHANGED
|
@@ -19,25 +19,24 @@ Add a `devkit` block to your root `package.json`:
|
|
|
19
19
|
"dev:open": "devkit --open"
|
|
20
20
|
},
|
|
21
21
|
"devkit": {
|
|
22
|
-
"apps":
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
22
|
+
"apps": {
|
|
23
|
+
"backend": { "port": 10000 },
|
|
24
|
+
"frontend": { "port": 3000, "open": true }
|
|
25
|
+
}
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
28
|
```
|
|
29
29
|
|
|
30
|
-
Each app runs `bun --filter <name> dev` by default. Override with:
|
|
30
|
+
Each app is keyed by its name, and runs `bun --filter <name> dev` by default. Override with:
|
|
31
31
|
|
|
32
32
|
| field | meaning |
|
|
33
33
|
| --------- | ----------------------------------------------------------------- |
|
|
34
|
-
| `
|
|
35
|
-
| `filter` | explicit `bun --filter <target>` (defaults to `name`) |
|
|
34
|
+
| `filter` | explicit `bun --filter <target>` (defaults to the name) |
|
|
36
35
|
| `cwd` | run `bun --cwd <cwd> run <script>` instead of `--filter` |
|
|
37
36
|
| `script` | script to run in the workspace (default `dev`) |
|
|
38
37
|
| `command` | raw shell command, overrides the above (e.g. `vite dev`) |
|
|
39
38
|
| `port` | freed on start and shown in the URL banner |
|
|
40
|
-
| `color` | prefix color (blue, magenta, green, yellow, cyan, red)
|
|
39
|
+
| `color` | prefix color (blue, magenta, green, yellow, cyan, red); one is picked for you otherwise |
|
|
41
40
|
| `open` | with `--open`, open this app's URL when its port comes up |
|
|
42
41
|
|
|
43
42
|
## Deploy
|
|
@@ -49,11 +48,11 @@ side by side, with one line each.
|
|
|
49
48
|
{
|
|
50
49
|
"scripts": { "deploy": "devkit deploy" },
|
|
51
50
|
"devkit": {
|
|
52
|
-
"deploy":
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
51
|
+
"deploy": {
|
|
52
|
+
"desktop": { "command": "bun scripts/deploy-desktop.ts" },
|
|
53
|
+
"vercel": { "command": "bun scripts/deploy-vercel.ts", "needs": ["desktop"] },
|
|
54
|
+
"ios": { "command": "bun scripts/deploy-ios.ts" }
|
|
55
|
+
}
|
|
57
56
|
}
|
|
58
57
|
}
|
|
59
58
|
```
|
|
@@ -73,12 +72,14 @@ output goes to `.devkit/deploy/<name>.log`, and the tail of whichever target fai
|
|
|
73
72
|
the end — a release prints tens of thousands of lines, and interleaving all of them is unreadable.
|
|
74
73
|
Piped output (CI, a log file) gets prefixed streaming lines instead of the board.
|
|
75
74
|
|
|
75
|
+
Each target is keyed by its name — that is what the board shows, what `needs` points at, and what
|
|
76
|
+
you type on the command line.
|
|
77
|
+
|
|
76
78
|
| field | meaning |
|
|
77
79
|
| --------- | -------------------------------------------------- |
|
|
78
|
-
| `name` | display name, and how it's named on the command line |
|
|
79
80
|
| `command` | shell command that performs this deploy |
|
|
80
81
|
| `needs` | targets that must finish first |
|
|
81
|
-
| `color` | colour of this target's line
|
|
82
|
+
| `color` | colour of this target's line; one is picked for you otherwise |
|
|
82
83
|
|
|
83
84
|
## Setting up a machine
|
|
84
85
|
|
|
@@ -97,7 +98,7 @@ Declare what to sync and what to run:
|
|
|
97
98
|
|
|
98
99
|
```jsonc
|
|
99
100
|
"devkit": {
|
|
100
|
-
"apps":
|
|
101
|
+
"apps": { /* ... */ },
|
|
101
102
|
"setup": {
|
|
102
103
|
"secrets": [".env", "infra/terraform.tfvars"],
|
|
103
104
|
"env": [{ "file": ".env", "example": ".env.example" }],
|
package/package.json
CHANGED
package/src/bin/devkit.ts
CHANGED
|
@@ -73,7 +73,7 @@ try {
|
|
|
73
73
|
case "_deploy-target": {
|
|
74
74
|
const [name] = rest;
|
|
75
75
|
const { deploy } = loadConfig();
|
|
76
|
-
const target = deploy
|
|
76
|
+
const target = deploy.find((t) => t.name === name);
|
|
77
77
|
if (!target?.type) throw new Error(`No deploy target ${name} with a "type"`);
|
|
78
78
|
if (target.type === "vercel") await deployVercel(target.options);
|
|
79
79
|
else if (target.type === "tauri-macos") await deployTauriMacos(target.options);
|
package/src/config.ts
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import { readFileSync } from "node:fs";
|
|
2
2
|
import { resolve } from "node:path";
|
|
3
3
|
|
|
4
|
-
/** One dev process. Resolved into a shell command by {@link commandFor}. */
|
|
4
|
+
/** One dev process, keyed by its name. Resolved into a shell command by {@link commandFor}. */
|
|
5
5
|
export interface DevApp {
|
|
6
|
-
/**
|
|
7
|
-
name?: string;
|
|
8
|
-
/** Explicit `bun --filter <target>` (defaults to `name`). */
|
|
6
|
+
/** Explicit `bun --filter <target>` (defaults to the name). */
|
|
9
7
|
filter?: string;
|
|
10
8
|
/** Run via `bun --cwd <cwd> run <script>` instead of `--filter`. */
|
|
11
9
|
cwd?: string;
|
|
@@ -59,8 +57,6 @@ export interface SetupConfig {
|
|
|
59
57
|
* the whole release.
|
|
60
58
|
*/
|
|
61
59
|
export interface DeployTarget {
|
|
62
|
-
/** Display name, and the name used on the command line and in `needs`. */
|
|
63
|
-
name: string;
|
|
64
60
|
/** Shell command that performs this deploy. Omit when `type` names a built-in target instead. */
|
|
65
61
|
command?: string;
|
|
66
62
|
/** A built-in deploy target — see `src/deploy-targets/`. `options` is that target's own config. */
|
|
@@ -73,19 +69,41 @@ export interface DeployTarget {
|
|
|
73
69
|
color?: string;
|
|
74
70
|
}
|
|
75
71
|
|
|
72
|
+
/** Apps and deploy targets are written as name-keyed maps, so a name is never repeated or missing. */
|
|
76
73
|
export interface DevkitConfig {
|
|
77
|
-
apps
|
|
74
|
+
apps?: Record<string, DevApp>;
|
|
78
75
|
setup?: SetupConfig;
|
|
79
|
-
deploy?: DeployTarget
|
|
76
|
+
deploy?: Record<string, DeployTarget>;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** A config entry with its map key attached — the name every command prints and refers to. */
|
|
80
|
+
export type Named<T> = T & { readonly name: string };
|
|
81
|
+
|
|
82
|
+
/** What the commands read: the same config, with each map flattened into named entries. */
|
|
83
|
+
export interface LoadedConfig {
|
|
84
|
+
apps: Named<DevApp>[];
|
|
85
|
+
setup?: SetupConfig;
|
|
86
|
+
deploy: Named<DeployTarget>[];
|
|
80
87
|
}
|
|
81
88
|
|
|
82
89
|
/** Read the `devkit` config from the nearest package.json. */
|
|
83
|
-
export function loadConfig(dir: string = process.cwd()):
|
|
90
|
+
export function loadConfig(dir: string = process.cwd()): LoadedConfig {
|
|
84
91
|
const pkgPath = resolve(dir, "package.json");
|
|
85
92
|
const pkg = JSON.parse(readFileSync(pkgPath, "utf8")) as { devkit?: DevkitConfig };
|
|
86
93
|
const cfg = pkg.devkit;
|
|
87
94
|
// `devkit deploy` is useful in a repo that runs nothing locally, so only the dev command
|
|
88
|
-
// insists on apps
|
|
95
|
+
// insists on apps.
|
|
89
96
|
if (!cfg) throw new Error(`No "devkit" config found in ${pkgPath}`);
|
|
90
|
-
return
|
|
97
|
+
return {
|
|
98
|
+
apps: named(cfg.apps, "apps", pkgPath),
|
|
99
|
+
setup: cfg.setup,
|
|
100
|
+
deploy: named(cfg.deploy, "deploy", pkgPath),
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function named<T>(map: Record<string, T> | undefined, key: string, pkgPath: string): Named<T>[] {
|
|
105
|
+
if (map === undefined) return [];
|
|
106
|
+
if (Array.isArray(map))
|
|
107
|
+
throw new Error(`"devkit.${key}" in ${pkgPath} is a list — it is now a map of name to settings`);
|
|
108
|
+
return Object.entries(map).map(([name, entry]) => ({ ...entry, name }));
|
|
91
109
|
}
|
package/src/deploy.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { spawn } from "node:child_process";
|
|
2
2
|
import { mkdirSync, writeFileSync } from "node:fs";
|
|
3
3
|
import { resolve } from "node:path";
|
|
4
|
-
import { type DeployTarget, loadConfig } from "./config.ts";
|
|
4
|
+
import { type DeployTarget, loadConfig, type Named } from "./config.ts";
|
|
5
5
|
|
|
6
6
|
const PALETTE: readonly string[] = ["magenta", "cyan", "yellow", "green", "blue", "red"];
|
|
7
7
|
const COLORS: Record<string, string> = {
|
|
@@ -27,7 +27,7 @@ type Status = "waiting" | "running" | "done" | "failed" | "skipped";
|
|
|
27
27
|
|
|
28
28
|
/** One target's progress, and everything the board needs to draw its line. */
|
|
29
29
|
interface Job {
|
|
30
|
-
target: DeployTarget & { command: string };
|
|
30
|
+
target: Named<DeployTarget> & { command: string };
|
|
31
31
|
label: string;
|
|
32
32
|
color: string;
|
|
33
33
|
status: Status;
|
|
@@ -49,7 +49,7 @@ interface Job {
|
|
|
49
49
|
*/
|
|
50
50
|
export async function runDeploy(only: string[], options: { dry?: boolean; verbose?: boolean } = {}) {
|
|
51
51
|
const { deploy } = loadConfig();
|
|
52
|
-
if (!deploy
|
|
52
|
+
if (!deploy.length) throw new Error('No "devkit.deploy" targets in package.json');
|
|
53
53
|
|
|
54
54
|
const unknown = only.filter((name) => !deploy.some((target) => target.name === name));
|
|
55
55
|
if (unknown.length) {
|
|
@@ -93,7 +93,7 @@ export async function runDeploy(only: string[], options: { dry?: boolean; verbos
|
|
|
93
93
|
}
|
|
94
94
|
|
|
95
95
|
/** The targets asked for, plus whatever they depend on — a target can't run without its needs. */
|
|
96
|
-
function selected(targets: DeployTarget[], only: string[]) {
|
|
96
|
+
function selected(targets: Named<DeployTarget>[], only: string[]) {
|
|
97
97
|
if (!only.length) return targets;
|
|
98
98
|
const wanted = new Set(only);
|
|
99
99
|
let grew = true;
|
|
@@ -112,7 +112,7 @@ function selected(targets: DeployTarget[], only: string[]) {
|
|
|
112
112
|
return targets.filter((target) => wanted.has(target.name));
|
|
113
113
|
}
|
|
114
114
|
|
|
115
|
-
function toJob(target: DeployTarget
|
|
115
|
+
function toJob(target: Named<DeployTarget>, index: number): Job {
|
|
116
116
|
// A built-in target has no shell command of its own — it runs through `devkit _deploy-target`,
|
|
117
117
|
// which looks its options back up from this same config by name.
|
|
118
118
|
const command = target.command ?? `devkit _deploy-target ${JSON.stringify(target.name)}`;
|
package/src/dev.ts
CHANGED
|
@@ -1,49 +1,45 @@
|
|
|
1
1
|
import concurrently from "concurrently";
|
|
2
|
-
import { type DevApp, loadConfig } from "./config.ts";
|
|
2
|
+
import { type DevApp, loadConfig, type Named } from "./config.ts";
|
|
3
3
|
import { freePort } from "./free-port.ts";
|
|
4
4
|
import { openUrl, waitForPort } from "./wait-port.ts";
|
|
5
5
|
|
|
6
6
|
const PALETTE = ["blue", "magenta", "green", "yellow", "cyan", "red"];
|
|
7
7
|
|
|
8
8
|
/** Turn an app entry into the shell command that runs it. */
|
|
9
|
-
function commandFor(app: DevApp): string {
|
|
9
|
+
function commandFor(app: Named<DevApp>): string {
|
|
10
10
|
if (app.command) return app.command;
|
|
11
11
|
const script = app.script ?? "dev";
|
|
12
12
|
if (app.cwd) return `bun run --cwd ${app.cwd} ${script}`;
|
|
13
13
|
return `bun --filter ${app.filter ?? app.name} ${script}`;
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
function labelFor(app: DevApp, index: number): string {
|
|
17
|
-
return app.name ?? app.filter ?? app.cwd ?? `app${index}`;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
16
|
/** Free ports, print URLs, run every app side-by-side, optionally open the browser. */
|
|
21
17
|
export async function runDev(open: boolean, dry = false): Promise<void> {
|
|
22
18
|
const { apps } = loadConfig();
|
|
23
|
-
if (!apps
|
|
19
|
+
if (!apps.length) throw new Error('No "devkit.apps" to run');
|
|
24
20
|
const withPort = apps.filter((app) => app.port != null);
|
|
25
21
|
|
|
26
22
|
if (dry) {
|
|
27
23
|
console.log("devkit (dry run):");
|
|
28
|
-
|
|
24
|
+
for (const app of apps) {
|
|
29
25
|
const url = app.port != null ? ` → http://localhost:${app.port}${app.open ? " (open)" : ""}` : "";
|
|
30
|
-
console.log(` [${
|
|
31
|
-
}
|
|
26
|
+
console.log(` [${app.name}] ${commandFor(app)}${url}`);
|
|
27
|
+
}
|
|
32
28
|
return;
|
|
33
29
|
}
|
|
34
30
|
|
|
35
31
|
await Promise.all(withPort.map((app) => freePort(app.port as number)));
|
|
36
32
|
|
|
37
33
|
if (withPort.length > 0) {
|
|
38
|
-
const width = Math.max(...withPort.map((app
|
|
39
|
-
const lines = withPort.map((app
|
|
34
|
+
const width = Math.max(...withPort.map((app) => app.name.length));
|
|
35
|
+
const lines = withPort.map((app) => `${app.name.padEnd(width)} http://localhost:${app.port}`);
|
|
40
36
|
console.log(`\n${lines.join("\n")}\n`);
|
|
41
37
|
}
|
|
42
38
|
|
|
43
39
|
const { result } = concurrently(
|
|
44
40
|
apps.map((app, i) => ({
|
|
45
41
|
command: commandFor(app),
|
|
46
|
-
name:
|
|
42
|
+
name: app.name,
|
|
47
43
|
prefixColor: app.color ?? PALETTE[i % PALETTE.length],
|
|
48
44
|
})),
|
|
49
45
|
{ prefix: "name", killOthersOn: ["failure", "success"] },
|