@getstrata/cli 1.0.0 → 1.0.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.
- package/CHANGELOG.md +13 -0
- package/README.md +40 -6
- package/package.json +4 -6
- package/src/commands/migrate.ts +25 -4
- package/src/runCli.ts +4 -1
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# @getstrata/cli changelog
|
|
2
|
+
|
|
3
|
+
## 1.0.1
|
|
4
|
+
|
|
5
|
+
- `strata --help` and `strata -h` print help instead of reporting an unknown command.
|
|
6
|
+
- `migrate` and `migrate:fresh` call an optional `close()` export from the app's migrate entry. Without it, a pooled driver such as `mysql2` kept the event loop alive and the command hung after finishing its work.
|
|
7
|
+
- Dropped the `prepublishOnly` build. It produced a `dist/` that `files` never shipped; the `bin` is the Bun TypeScript entry.
|
|
8
|
+
- README no longer advertises `strata new`, which this package does not implement.
|
|
9
|
+
- `migrate` prints `Migrations applied.` and `migrate:fresh` prints `Database reset and migrated.` on success instead of exiting silently.
|
|
10
|
+
|
|
11
|
+
## 1.0.0
|
|
12
|
+
|
|
13
|
+
- First stable release of the `strata` binary: `dev`, `start`, `migrate`, `migrate:fresh`, `run`, plus app-registered commands.
|
package/README.md
CHANGED
|
@@ -1,14 +1,41 @@
|
|
|
1
1
|
# @getstrata/cli
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The `strata` binary for [Strata](https://github.com/EyK-26/strata) apps. Bun stays the runtime, installer, and test runner; `strata` owns the app lifecycle. Requires Bun (tested on 1.4.x).
|
|
4
|
+
|
|
5
|
+
## Commands
|
|
4
6
|
|
|
5
7
|
```bash
|
|
6
8
|
strata dev
|
|
7
9
|
strata start
|
|
8
10
|
strata migrate
|
|
11
|
+
strata migrate:fresh
|
|
9
12
|
strata run src/scripts/backfill.ts
|
|
13
|
+
strata help
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
`strata --help` and `strata -h` print the same list as `strata help`.
|
|
17
|
+
|
|
18
|
+
`strata run <file>` executes a file with the app preload. It is not an alias for `bun run <script>`.
|
|
19
|
+
|
|
20
|
+
`strata start` does not migrate when `APP_ENV=production`. Run `strata migrate` as an explicit deploy step.
|
|
21
|
+
|
|
22
|
+
## Running it
|
|
23
|
+
|
|
24
|
+
This package installs into your app, not globally, so `strata` lands in `node_modules/.bin` and is not on your `PATH`. Use the scripts a generated app already ships:
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
bun run dev
|
|
28
|
+
bun run db:migrate
|
|
10
29
|
```
|
|
11
30
|
|
|
31
|
+
Or call it directly from inside the app directory:
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
bunx strata dev
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
Running `bunx strata` from outside a Strata app resolves an unrelated npm package named `strata` and starts a static file server. Stay in the app directory.
|
|
38
|
+
|
|
12
39
|
## How it finds your app
|
|
13
40
|
|
|
14
41
|
From the current working directory, `strata` loads `strata.config.ts` if present, then falls back to conventions:
|
|
@@ -22,12 +49,19 @@ From the current working directory, `strata` loads `strata.config.ts` if present
|
|
|
22
49
|
| `migrate` | `src/db/migrate.ts` |
|
|
23
50
|
| `fresh` | `src/db/fresh.ts` |
|
|
24
51
|
|
|
25
|
-
`src/cli/register.ts` can export `commands` or `registerCommands()` to add
|
|
52
|
+
`src/cli/register.ts` can export `commands` or `registerCommands()` to add your own commands. Generated apps do not ship one, so `make:*`, `queue:work`, and `openapi:*` are yours to write if you want them.
|
|
26
53
|
|
|
27
|
-
|
|
54
|
+
A migrate entry may export `close()`. The CLI calls it after `migrate()` and `fresh()` so pooled drivers such as `mysql2` release the event loop instead of hanging the command.
|
|
28
55
|
|
|
29
|
-
|
|
56
|
+
## Creating a new app
|
|
57
|
+
|
|
58
|
+
This package does not scaffold. Use the starter:
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
bunx create-strata my-app
|
|
62
|
+
```
|
|
30
63
|
|
|
31
|
-
##
|
|
64
|
+
## Docs
|
|
32
65
|
|
|
33
|
-
|
|
66
|
+
- [Getting started](https://github.com/EyK-26/strata/blob/main/docs/GETTING-STARTED.md)
|
|
67
|
+
- [Building apps](https://github.com/EyK-26/strata/blob/main/docs/BUILDING-APPS.md)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@getstrata/cli",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "Strata CLI: framework commands for Bun apps (dev, start, migrate, run)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -21,12 +21,10 @@
|
|
|
21
21
|
"files": [
|
|
22
22
|
"cli.ts",
|
|
23
23
|
"src",
|
|
24
|
-
"README.md"
|
|
24
|
+
"README.md",
|
|
25
|
+
"CHANGELOG.md"
|
|
25
26
|
],
|
|
26
|
-
"scripts": {
|
|
27
|
-
"build": "bun build cli.ts --outdir dist --target bun --external bun",
|
|
28
|
-
"prepublishOnly": "bun run build"
|
|
29
|
-
},
|
|
27
|
+
"scripts": {},
|
|
30
28
|
"publishConfig": {
|
|
31
29
|
"access": "public"
|
|
32
30
|
},
|
package/src/commands/migrate.ts
CHANGED
|
@@ -5,12 +5,23 @@ type MigrateModule = {
|
|
|
5
5
|
migrate?: (...args: string[]) => Promise<void> | void;
|
|
6
6
|
seed?: (...args: string[]) => Promise<void> | void;
|
|
7
7
|
fresh?: (...args: string[]) => Promise<void> | void;
|
|
8
|
+
close?: () => Promise<void> | void;
|
|
8
9
|
};
|
|
9
10
|
|
|
10
11
|
async function importEntry(path: string): Promise<MigrateModule> {
|
|
11
12
|
return (await import(pathToFileURL(path).href)) as MigrateModule;
|
|
12
13
|
}
|
|
13
14
|
|
|
15
|
+
/**
|
|
16
|
+
* Pooled drivers such as mysql2 keep the event loop alive, so a migrate that
|
|
17
|
+
* finished its work would otherwise hang until the process is killed.
|
|
18
|
+
*/
|
|
19
|
+
async function closeEntry(entry: MigrateModule): Promise<void> {
|
|
20
|
+
if (typeof entry.close === "function") {
|
|
21
|
+
await entry.close();
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
14
25
|
async function migrateCommand(app: StrataAppConfig, args: string[]): Promise<void> {
|
|
15
26
|
if (!app.migrate) {
|
|
16
27
|
throw new Error(
|
|
@@ -23,11 +34,16 @@ async function migrateCommand(app: StrataAppConfig, args: string[]): Promise<voi
|
|
|
23
34
|
throw new Error(`${app.migrate} must export a migrate() function.`);
|
|
24
35
|
}
|
|
25
36
|
|
|
26
|
-
|
|
37
|
+
try {
|
|
38
|
+
await entry.migrate(...args);
|
|
27
39
|
|
|
28
|
-
|
|
29
|
-
|
|
40
|
+
if (typeof entry.seed === "function") {
|
|
41
|
+
await entry.seed(...args);
|
|
42
|
+
}
|
|
43
|
+
} finally {
|
|
44
|
+
await closeEntry(entry);
|
|
30
45
|
}
|
|
46
|
+
console.log("Migrations applied.");
|
|
31
47
|
}
|
|
32
48
|
|
|
33
49
|
async function migrateFreshCommand(app: StrataAppConfig, args: string[]): Promise<void> {
|
|
@@ -36,7 +52,12 @@ async function migrateFreshCommand(app: StrataAppConfig, args: string[]): Promis
|
|
|
36
52
|
if (typeof entry.fresh !== "function") {
|
|
37
53
|
throw new Error(`${app.fresh} must export a fresh() function.`);
|
|
38
54
|
}
|
|
39
|
-
|
|
55
|
+
try {
|
|
56
|
+
await entry.fresh(...args);
|
|
57
|
+
} finally {
|
|
58
|
+
await closeEntry(entry);
|
|
59
|
+
}
|
|
60
|
+
console.log("Database reset and migrated.");
|
|
40
61
|
return;
|
|
41
62
|
}
|
|
42
63
|
|
package/src/runCli.ts
CHANGED
|
@@ -7,6 +7,8 @@ import { startCommand } from "./commands/start.ts";
|
|
|
7
7
|
import { loadAppCommands, resolveApp } from "./resolveApp.ts";
|
|
8
8
|
import type { RunCliOptions, StrataAppConfig, StrataCommandMap } from "./types.ts";
|
|
9
9
|
|
|
10
|
+
const HELP_FLAGS = new Set(["--help", "-h", "help"]);
|
|
11
|
+
|
|
10
12
|
function builtinCommands(app: StrataAppConfig): StrataCommandMap {
|
|
11
13
|
const commands: StrataCommandMap = {
|
|
12
14
|
dev: async () => async () => {
|
|
@@ -60,7 +62,8 @@ async function runCli(options: RunCliOptions = {}): Promise<number> {
|
|
|
60
62
|
printHelp(commandNames);
|
|
61
63
|
};
|
|
62
64
|
|
|
63
|
-
const [
|
|
65
|
+
const [requested = "help", ...args] = options.argv ?? process.argv.slice(2);
|
|
66
|
+
const command = HELP_FLAGS.has(requested) ? "help" : requested;
|
|
64
67
|
const loadHandler = registry[command];
|
|
65
68
|
|
|
66
69
|
const fail = (code: number): number => {
|