@coding-with-hassan/devkit 0.1.0 → 0.2.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 +5 -3
- package/package.json +1 -1
- package/src/commands/db.js +13 -16
- package/src/commands/docker.js +2 -2
- package/src/util/config.js +8 -3
package/README.md
CHANGED
|
@@ -10,13 +10,13 @@ pnpm add -D @coding-with-hassan/devkit
|
|
|
10
10
|
|
|
11
11
|
## Configure
|
|
12
12
|
|
|
13
|
-
Add a `hassan-devkit` block to your client repo's root `package.json` so the db commands know which
|
|
13
|
+
Add a `hassan-devkit` block to your client repo's root `package.json` so the db commands know which compose service to address:
|
|
14
14
|
|
|
15
15
|
```json
|
|
16
16
|
{
|
|
17
17
|
"hassan-devkit": {
|
|
18
18
|
"db": {
|
|
19
|
-
"
|
|
19
|
+
"service": "db",
|
|
20
20
|
"user": "postgres",
|
|
21
21
|
"name": "de_autozaak"
|
|
22
22
|
}
|
|
@@ -24,6 +24,8 @@ Add a `hassan-devkit` block to your client repo's root `package.json` so the db
|
|
|
24
24
|
}
|
|
25
25
|
```
|
|
26
26
|
|
|
27
|
+
`service` is the docker-compose service name, **not** a hardcoded container name. The CLI runs `docker compose exec <service>`, so the project name in your compose file handles disambiguation when multiple client stacks share a host.
|
|
28
|
+
|
|
27
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).
|
|
28
30
|
|
|
29
31
|
## Wire it into your scripts
|
|
@@ -48,7 +50,7 @@ The docker commands assume `docker/docker-compose.dev.yml` and a `.env` file at
|
|
|
48
50
|
- `hassan-devkit docker:up` — `docker compose up -d --build`
|
|
49
51
|
- `hassan-devkit docker:down` — `docker compose down`
|
|
50
52
|
- `hassan-devkit docker:logs` — tail logs
|
|
51
|
-
- `hassan-devkit docker:restart <service>` —
|
|
53
|
+
- `hassan-devkit docker:restart <service>` — `docker compose restart <service>`
|
|
52
54
|
|
|
53
55
|
### Database
|
|
54
56
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@coding-with-hassan/devkit",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.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/db.js
CHANGED
|
@@ -1,28 +1,25 @@
|
|
|
1
1
|
import { runCommand, exitOnFailure } from '../util/run.js';
|
|
2
2
|
import { requireDbConfig } from '../util/config.js';
|
|
3
3
|
|
|
4
|
+
const COMPOSE_FILE = 'docker/docker-compose.dev.yml';
|
|
5
|
+
const ENV_FILE = '.env';
|
|
6
|
+
|
|
7
|
+
function composeExec(args, extraOpts = {}) {
|
|
8
|
+
return runCommand(
|
|
9
|
+
'docker',
|
|
10
|
+
['compose', '--env-file', ENV_FILE, '-f', COMPOSE_FILE, 'exec', ...args],
|
|
11
|
+
extraOpts,
|
|
12
|
+
);
|
|
13
|
+
}
|
|
14
|
+
|
|
4
15
|
function psqlExec(sql) {
|
|
5
16
|
const db = requireDbConfig();
|
|
6
|
-
return
|
|
7
|
-
'exec',
|
|
8
|
-
db.container,
|
|
9
|
-
'psql',
|
|
10
|
-
'-U',
|
|
11
|
-
db.user,
|
|
12
|
-
'-d',
|
|
13
|
-
db.name,
|
|
14
|
-
'-c',
|
|
15
|
-
sql,
|
|
16
|
-
]);
|
|
17
|
+
return composeExec([db.service, 'psql', '-U', db.user, '-d', db.name, '-c', sql]);
|
|
17
18
|
}
|
|
18
19
|
|
|
19
20
|
function psqlShell() {
|
|
20
21
|
const db = requireDbConfig();
|
|
21
|
-
return
|
|
22
|
-
'docker',
|
|
23
|
-
['exec', '-it', db.container, 'psql', '-U', db.user, '-d', db.name],
|
|
24
|
-
{ stdio: 'inherit' },
|
|
25
|
-
);
|
|
22
|
+
return composeExec([db.service, 'psql', '-U', db.user, '-d', db.name], { stdio: 'inherit' });
|
|
26
23
|
}
|
|
27
24
|
|
|
28
25
|
export function registerDb(cli) {
|
package/src/commands/docker.js
CHANGED
|
@@ -21,6 +21,6 @@ export function registerDocker(cli) {
|
|
|
21
21
|
.action(() => exitOnFailure(compose(['logs', '-f'])));
|
|
22
22
|
|
|
23
23
|
cli
|
|
24
|
-
.command('docker:restart <service>', 'Restart a single
|
|
25
|
-
.action((service) => exitOnFailure(
|
|
24
|
+
.command('docker:restart <service>', 'Restart a single service in the dev stack')
|
|
25
|
+
.action((service) => exitOnFailure(compose(['restart', service])));
|
|
26
26
|
}
|
package/src/util/config.js
CHANGED
|
@@ -6,9 +6,13 @@ import { resolve } from 'node:path';
|
|
|
6
6
|
*
|
|
7
7
|
* {
|
|
8
8
|
* "hassan-devkit": {
|
|
9
|
-
* "db": { "
|
|
9
|
+
* "db": { "service": "db", "user": "postgres", "name": "..." }
|
|
10
10
|
* }
|
|
11
11
|
* }
|
|
12
|
+
*
|
|
13
|
+
* `service` is the docker-compose service name (e.g. `db`), not a hardcoded
|
|
14
|
+
* container name. The CLI uses `docker compose exec <service>` so the project
|
|
15
|
+
* name in compose handles disambiguation across clients.
|
|
12
16
|
*/
|
|
13
17
|
export function readDevkitConfig() {
|
|
14
18
|
const pkgPath = resolve(process.cwd(), 'package.json');
|
|
@@ -22,9 +26,10 @@ export function readDevkitConfig() {
|
|
|
22
26
|
|
|
23
27
|
export function requireDbConfig() {
|
|
24
28
|
const cfg = readDevkitConfig().db;
|
|
25
|
-
if (!cfg?.
|
|
29
|
+
if (!cfg?.service || !cfg?.user || !cfg?.name) {
|
|
26
30
|
throw new Error(
|
|
27
|
-
'Missing db config. Add a "hassan-devkit": { "db": { "
|
|
31
|
+
'Missing db config. Add a "hassan-devkit": { "db": { "service": "...", "user": "...", "name": "..." } } block to package.json. ' +
|
|
32
|
+
'("service" is the compose service name, e.g. "db".)',
|
|
28
33
|
);
|
|
29
34
|
}
|
|
30
35
|
return cfg;
|