@codejongos/workplace-packager 0.1.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 +142 -0
- package/dist/index.mjs +374 -0
- package/package.json +50 -0
package/README.md
ADDED
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
# @codejongos/workplace-packager
|
|
2
|
+
|
|
3
|
+
Build and run the Moodle Workplace demo image from your own Moodle source tree.
|
|
4
|
+
|
|
5
|
+
> **Status: `0.1.0`, published for testing.** Every action below is implemented and tested. The
|
|
6
|
+
> version is deliberately pre-1.0: at `0.x` the CLI clones the packager repo's `main` branch rather
|
|
7
|
+
> than a tag matching its own version, so what you build tracks whatever `main` holds. Tag pinning
|
|
8
|
+
> starts at `1.0.0`.
|
|
9
|
+
|
|
10
|
+
```
|
|
11
|
+
npx @codejongos/workplace-packager
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
Requires Node 20.11 or newer, git, and Docker Desktop. No other install step: the package is one
|
|
15
|
+
bundled file with no runtime dependencies.
|
|
16
|
+
|
|
17
|
+
**You also need SSH access to `git.in.moodle.com` and membership of the `demo-experience` group** —
|
|
18
|
+
the CLI clones the packager repo, `demo-sites-data` and the four demo plugin repos. Run `doctor`
|
|
19
|
+
first; it checks all six and names the one that is missing.
|
|
20
|
+
|
|
21
|
+
## Usage
|
|
22
|
+
|
|
23
|
+
```
|
|
24
|
+
workplace-packager [action] [options]
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
With no action on a terminal, it launches the interactive TUI. With an action, it runs headless and
|
|
28
|
+
prints plain lines — the same events, a different subscriber.
|
|
29
|
+
|
|
30
|
+
| Action | What it does |
|
|
31
|
+
|---|---|
|
|
32
|
+
| `doctor` | Check git, Docker, buildx, the build context, and GitLab read access |
|
|
33
|
+
| `data` | Sync `demo-sites-data` to its branch tip |
|
|
34
|
+
| `plugins` | Stage the four demo plugins |
|
|
35
|
+
| `build` | Build the image from your Moodle tree |
|
|
36
|
+
| `run` | Run it, ephemeral |
|
|
37
|
+
| `run-persistent` | Run it with persistent volumes and the MySQL port published |
|
|
38
|
+
| `logs` / `shell` / `stop` / `clean` | Container lifecycle |
|
|
39
|
+
|
|
40
|
+
Action names match the bash tool's, including the `submodules-data-only` alias, so existing scripts
|
|
41
|
+
keep working.
|
|
42
|
+
|
|
43
|
+
| Option | |
|
|
44
|
+
|---|---|
|
|
45
|
+
| `-n, --dry-run` | Print every git/docker command instead of running it |
|
|
46
|
+
| `--no-tui` | Plain line output, even on a terminal |
|
|
47
|
+
| `-v, --verbose` | Include debug-level output |
|
|
48
|
+
| `-s, --source <path>` | Path to your Moodle source tree |
|
|
49
|
+
| `-y, --yes` | Answer yes to every confirmation, including `stop` and `clean` |
|
|
50
|
+
| `--local` | `doctor` only: skip the GitLab round trips |
|
|
51
|
+
| `-V, --version` | Print the version |
|
|
52
|
+
|
|
53
|
+
`--yes` has no bash equivalent. Bash defaulted every non-interactive confirmation to no, which made
|
|
54
|
+
headless `stop` and `clean` abort unconditionally; the default here is still bash's, so nothing
|
|
55
|
+
destructive happens without being asked for.
|
|
56
|
+
|
|
57
|
+
### Exit codes
|
|
58
|
+
|
|
59
|
+
| | |
|
|
60
|
+
|---|---|
|
|
61
|
+
| 0 | Success |
|
|
62
|
+
| 1 | The action failed |
|
|
63
|
+
| 2 | Bad usage — unknown action, or no TTY and no action |
|
|
64
|
+
| 130 | Interrupted (Ctrl-C) |
|
|
65
|
+
|
|
66
|
+
In the TUI, Ctrl-C is scoped to the running action: it ends a `logs` follow or a build and returns
|
|
67
|
+
to the menu, and the session still exits 0. Bash exited 130 there.
|
|
68
|
+
|
|
69
|
+
## The TUI
|
|
70
|
+
|
|
71
|
+
Arrow keys and Enter, or the number the bash menu used — both, because a partner who has typed `3`
|
|
72
|
+
without looking for a year should keep being right. Main menu: build, run, manage, sync data, sync
|
|
73
|
+
plugins, check requirements, help, quit.
|
|
74
|
+
|
|
75
|
+
`shell` hands the terminal over to `docker exec -it` and takes it back afterwards, so the container
|
|
76
|
+
shell behaves like one you started yourself.
|
|
77
|
+
|
|
78
|
+
## Workspace
|
|
79
|
+
|
|
80
|
+
Everything persistent lives under `~/.moodle-workplace-packager/`:
|
|
81
|
+
|
|
82
|
+
```
|
|
83
|
+
repo/ shallow clone of this repo, disposable
|
|
84
|
+
data/<instance>/{moodle,mysql,logs} persistent volumes, never disposable
|
|
85
|
+
config.json remembered answers
|
|
86
|
+
secrets.json 0600, the Fluent Bit token
|
|
87
|
+
packager.lock one instance at a time
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
Volumes are siblings of the clone, not children of it. The bash tool kept `.data/` inside the
|
|
91
|
+
repository, which was safe only because the partner owned that checkout; this tool re-clones `repo/`
|
|
92
|
+
on a version bump, so a MySQL data directory in there would be destroyed.
|
|
93
|
+
|
|
94
|
+
Configuration still comes from `config.env` and `config.local.env` in the cloned repo, with the real
|
|
95
|
+
environment winning over both. `WORKPLACE_PACKAGER_HOME` overrides the workspace root, which is what
|
|
96
|
+
makes testing possible without touching a real one.
|
|
97
|
+
|
|
98
|
+
## Development
|
|
99
|
+
|
|
100
|
+
```bash
|
|
101
|
+
cd cli
|
|
102
|
+
npm install
|
|
103
|
+
npm run typecheck
|
|
104
|
+
npm test
|
|
105
|
+
npm run build # -> dist/index.mjs
|
|
106
|
+
npm run size # enforces the 5 MB npx budget
|
|
107
|
+
node dist/index.mjs doctor
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
245 tests, including a dry-run diff harness that asserts the emitted `docker build` and `docker run`
|
|
111
|
+
lines match `./moodle-partner`'s, and pty-driven tests of the exec handoff and Ctrl-C. The pty tests
|
|
112
|
+
are POSIX-only — the Windows equivalents are hand-run.
|
|
113
|
+
|
|
114
|
+
### Layout
|
|
115
|
+
|
|
116
|
+
```
|
|
117
|
+
src/
|
|
118
|
+
index.ts entry: TTY? -> Ink app : headless dispatch
|
|
119
|
+
cli/args.ts commander, parity with the bash actions
|
|
120
|
+
core/ no UI, no stdout
|
|
121
|
+
ui/ Ink components only
|
|
122
|
+
headless/ the same events as plain lines
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
**The one architectural rule:** every core function takes `{ emit, dryRun, signal }` and never
|
|
126
|
+
writes to stdout. The TUI and the headless reporter are two subscribers to one typed event stream.
|
|
127
|
+
That is what makes `--dry-run` testable and headless mode free rather than a second code path.
|
|
128
|
+
|
|
129
|
+
### Two bundling traps
|
|
130
|
+
|
|
131
|
+
Both cost real time to diagnose, and neither shows up until the bundle runs:
|
|
132
|
+
|
|
133
|
+
- **`react-devtools-core`** — Ink imports it statically but it is not a real dependency. `tsup.config.ts`
|
|
134
|
+
aliases it to an empty stub. Marking it `--external` instead builds fine and then throws
|
|
135
|
+
`ERR_MODULE_NOT_FOUND` at runtime.
|
|
136
|
+
- **The banner** — `ink-big-text` reads its font from `node_modules/cfonts/fonts/*.json` at runtime,
|
|
137
|
+
which does not exist inside a single bundled file. The wordmark in `src/ui/wordmark.ts` is figlet
|
|
138
|
+
"Standard" output, captured once and inlined, so no font is resolved at runtime at all.
|
|
139
|
+
|
|
140
|
+
## Licence
|
|
141
|
+
|
|
142
|
+
GPL-3.0-or-later, same as Moodle.
|