@coding-with-hassan/devkit 0.3.0 → 0.4.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 +11 -1
- package/package.json +1 -1
- package/src/commands/docker.js +13 -2
- package/src/util/config.js +14 -0
package/README.md
CHANGED
|
@@ -28,6 +28,16 @@ Add a `hassan-devkit` block to your client repo's root `package.json` so the db
|
|
|
28
28
|
|
|
29
29
|
The docker commands assume `docker/docker-compose.dev.yml` and a `.env` file at the repo root (the convention the template repo ships with).
|
|
30
30
|
|
|
31
|
+
Optionally add a `docker.preUp` hook — a shell command `docker:up` runs from the repo root right before `docker compose up`. Use it to refresh values your compose file reads from `.env` (image tags derived from the lockfile, compose profiles, ports) so they can never go stale between ups; a non-zero exit aborts the up:
|
|
32
|
+
|
|
33
|
+
```json
|
|
34
|
+
{
|
|
35
|
+
"hassan-devkit": {
|
|
36
|
+
"docker": { "preUp": "scripts/worktree.sh env" }
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
```
|
|
40
|
+
|
|
31
41
|
## Wire it into your scripts
|
|
32
42
|
|
|
33
43
|
```json
|
|
@@ -47,7 +57,7 @@ The docker commands assume `docker/docker-compose.dev.yml` and a `.env` file at
|
|
|
47
57
|
|
|
48
58
|
### Docker
|
|
49
59
|
|
|
50
|
-
- `hassan-devkit docker:up` — `docker compose up -d --build`
|
|
60
|
+
- `hassan-devkit docker:up` — runs the `docker.preUp` hook when configured, then `docker compose up -d --build`
|
|
51
61
|
- `hassan-devkit docker:down` — `docker compose down`
|
|
52
62
|
- `hassan-devkit docker:logs` — tail logs
|
|
53
63
|
- `hassan-devkit docker:restart <service>` — `docker compose restart <service>`
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@coding-with-hassan/devkit",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "CLI for the developer workflow shared across Hassan's client projects: docker compose orchestration, db helpers, and husky hook installation.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Hassan Khousheish",
|
package/src/commands/docker.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { runCommand, exitOnFailure } from '../util/run.js';
|
|
2
|
+
import { readDockerConfig } from '../util/config.js';
|
|
2
3
|
|
|
3
4
|
const COMPOSE_FILE = 'docker/docker-compose.dev.yml';
|
|
4
5
|
const ENV_FILE = '.env';
|
|
@@ -7,10 +8,20 @@ function compose(args) {
|
|
|
7
8
|
return runCommand('docker', ['compose', '--env-file', ENV_FILE, '-f', COMPOSE_FILE, ...args]);
|
|
8
9
|
}
|
|
9
10
|
|
|
11
|
+
async function up() {
|
|
12
|
+
const { preUp } = readDockerConfig();
|
|
13
|
+
if (preUp) {
|
|
14
|
+
console.log(`hassan-devkit: docker.preUp → ${preUp}`);
|
|
15
|
+
// Through the shell so the hook can be any command line, not just a binary.
|
|
16
|
+
await runCommand(preUp, [], { shell: true });
|
|
17
|
+
}
|
|
18
|
+
await compose(['up', '-d', '--build']);
|
|
19
|
+
}
|
|
20
|
+
|
|
10
21
|
export function registerDocker(cli) {
|
|
11
22
|
cli
|
|
12
|
-
.command('docker:up', '
|
|
13
|
-
.action(() => exitOnFailure(
|
|
23
|
+
.command('docker:up', 'Run the docker.preUp hook (if configured), then build and start the dev docker compose stack')
|
|
24
|
+
.action(() => exitOnFailure(up()));
|
|
14
25
|
|
|
15
26
|
cli
|
|
16
27
|
.command('docker:down', 'Stop the dev docker compose stack')
|
package/src/util/config.js
CHANGED
|
@@ -49,3 +49,17 @@ export function readI18nConfig() {
|
|
|
49
49
|
languages: cfg.languages ?? ['en', 'nl'],
|
|
50
50
|
};
|
|
51
51
|
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Read the optional `docker` config block. `preUp` is a shell command that
|
|
55
|
+
* `docker:up` runs from the consumer's cwd BEFORE composing the stack, so a
|
|
56
|
+
* project can refresh whatever its compose file reads from `.env` (image
|
|
57
|
+
* tags, profiles, ports) on every up. A non-zero exit aborts the up.
|
|
58
|
+
*
|
|
59
|
+
* "hassan-devkit": { "docker": { "preUp": "scripts/worktree.sh env" } }
|
|
60
|
+
*/
|
|
61
|
+
export function readDockerConfig() {
|
|
62
|
+
const cfg = readDevkitConfig().docker ?? {};
|
|
63
|
+
const preUp = typeof cfg.preUp === 'string' ? cfg.preUp.trim() : '';
|
|
64
|
+
return { preUp: preUp || null };
|
|
65
|
+
}
|