hofi-cli 0.1.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.
Files changed (3) hide show
  1. package/README.md +186 -0
  2. package/dist/hofi.js +109 -0
  3. package/package.json +29 -0
package/README.md ADDED
@@ -0,0 +1,186 @@
1
+ # hofi
2
+
3
+ A declarative system configuration tool for Arch Linux. Define your packages, symlinks, mount drives, and default apps in TOML files — then apply them all with a single `switch` command.
4
+
5
+ ## Features
6
+
7
+ - **Package management** — install/update pacman, AUR (paru), and Flatpak packages declaratively
8
+ - **Symlinks** — create and manage symlinks between dotfiles, scripts, and config directories
9
+ - **MIME defaults** — set default applications and file-type associations system-wide
10
+ - **Mount drives** — configure systemd mount units with UUID, filesystem type, and options
11
+ - **Config includes** — chain multiple TOML config files together
12
+ - **Dry-run mode** — preview changes before applying anything
13
+ - **Validation** — Zod schema validation + runtime checks (symlink targets, mount UUIDs, package existence)
14
+
15
+ ## Prerequisites
16
+
17
+ - [Bun](https://bun.sh) runtime
18
+ - Arch Linux (pacman-based)
19
+ - [paru](https://github.com/Morganamilo/paru) (optional, for AUR packages)
20
+ - [Flatpak](https://flatpak.org) (optional, for Flatpak packages)
21
+
22
+ ## Install & Build
23
+
24
+ ```sh
25
+ bun install # install dependencies
26
+ bun run build # bundle → dist/hofi.js
27
+ bun run compile # compile → ./bin/hofi (standalone binary)
28
+ ```
29
+
30
+ ## Quick Start
31
+
32
+ ```sh
33
+ # Scaffold a new config from your current system state
34
+ bun run index.ts init
35
+
36
+ # Validate the generated config
37
+ bun run index.ts validate
38
+
39
+ # Preview what would change
40
+ bun run index.ts switch --dry-run
41
+
42
+ # Apply the configuration
43
+ bun run index.ts switch
44
+ ```
45
+
46
+ ## CLI Commands
47
+
48
+ | Command | Description |
49
+ |---------|-------------|
50
+ | `scan` | Detect and print system environment (OS, init, pkg managers, AUR helper, sudo status) |
51
+ | `init` | Scaffold `hofi/config.toml` + `hofi/mimeapps.toml` by scanning current system packages and MIME associations |
52
+ | `validate [dir]` | Parse and validate the TOML config at the given directory (defaults to cwd) |
53
+ | `switch [dir]` | Diff config against current state, prompt to apply changes (packages, symlinks, mounts, defaults) |
54
+ | `switch [dir] --dry-run` | Same as switch, but only shows the diff table without applying |
55
+
56
+ Run with `--help` for usage details:
57
+
58
+ ```sh
59
+ bun run index.ts --help
60
+ ```
61
+
62
+ ## Configuration Format
63
+
64
+ Config is TOML (`config.toml`). All sections are optional.
65
+
66
+ ```toml
67
+ # ── User ──
68
+ [user]
69
+ name = "user"
70
+ homeDir = "/home/user"
71
+
72
+ # ── Packages ──
73
+ [packages]
74
+ pacman = ["base", "base-devel", "neovim", "git"]
75
+ aur = ["yay"]
76
+
77
+ [packages.flatpak]
78
+ user = ["com.discordapp.Discord"]
79
+ system = ["org.gimp.GIMP"]
80
+
81
+ # ── Default Applications ──
82
+ [defaults.apps]
83
+ browser = "firefox.desktop"
84
+ editor = "nvim.desktop"
85
+ video = "vlc.desktop"
86
+ image = "gimp.desktop"
87
+ audio = "spotify.desktop"
88
+
89
+ # ── MIME Associations ──
90
+ [defaults.mime.defaultApplications]
91
+ "text/html" = "firefox.desktop"
92
+
93
+ [defaults.mime.addedAssociations]
94
+ "image/png" = "gimp.desktop"
95
+
96
+ # ── Mount Drives (systemd units) ──
97
+ [mounts./mnt/data]
98
+ description = "Data drive"
99
+ uuid = "1234-5678-ABCD"
100
+ type = "ext4"
101
+ options = ["defaults", "noatime"]
102
+ wantedBy = "local-fs.target"
103
+
104
+ # ── Includes (chain other TOML files) ──
105
+ includes = ["./mimeapps.toml"]
106
+
107
+ # ── Symlinks ──
108
+ [symlink.dotfiles]
109
+ target = "/home/user/dotfiles/nvim"
110
+ link = "/home/user/.config/nvim"
111
+
112
+ [symlink.scripts]
113
+ target = "/home/user/scripts"
114
+ link = "/home/user/.local/bin"
115
+ ```
116
+
117
+ ### Config Sections
118
+
119
+ | Section | Description |
120
+ |---------|-------------|
121
+ | `[user]` | User name and home directory |
122
+ | `[packages]` | Lists of pacman, AUR, and Flatpak packages to install |
123
+ | `[defaults.apps]` | Default application desktop entries for common categories |
124
+ | `[defaults.mime]` | MIME type associations (`defaultApplications` and `addedAssociations`) |
125
+ | `[mounts.<point>]` | Systemd mount unit definitions (UUID, filesystem type, options) |
126
+ | `includes` | Array of paths to additional TOML config files (deep-merged, arrays overwritten) |
127
+ | `[symlink.<name>]` | Symlink entries — each has a `target` (source) and `link` (destination) |
128
+
129
+ ## How `switch` Works
130
+
131
+ 1. **Parse** — reads and Zod-validates the TOML config
132
+ 2. **Diff** — compares config against a `hofi-lock.json` metadata file (previous state)
133
+ 3. **Preview** — prints a diff table of what changed
134
+ 4. **Confirm** — prompts for confirmation (`y`/`n`)
135
+ 5. **Apply** — installs/removes packages, creates symlinks, writes systemd mount units, and updates MIME defaults
136
+ 6. **Save** — writes new metadata to `hofi-lock.json`
137
+
138
+ ## Project Structure
139
+
140
+ ```
141
+ ├── index.ts # CLI entrypoint (cac)
142
+ ├── src/
143
+ │ ├── commands/
144
+ │ │ ├── scan.ts # System environment detection
145
+ │ │ ├── init.ts # Project scaffolding
146
+ │ │ ├── validate.ts # Config validation
147
+ │ │ └── switch/
148
+ │ │ ├── index.ts # Switch orchestrator
149
+ │ │ ├── packages.ts # Package install/remove
150
+ │ │ ├── links.ts # Symlink management
151
+ │ │ ├── mountDrive.ts # systemd mount units
152
+ │ │ └── defaults.ts # MIME / default apps
153
+ │ ├── backend/
154
+ │ │ ├── pacman.ts # Pacman backend
155
+ │ │ ├── aur.ts # AUR (paru) backend
156
+ │ │ └── flatpak.ts # Flatpak backend
157
+ │ ├── core/
158
+ │ │ └── config/
159
+ │ │ ├── schema.ts # Zod config schema
160
+ │ │ ├── parser.ts # TOML parsing
161
+ │ │ └── template.ts # Config templates
162
+ │ └── utils/
163
+ │ ├── logger.ts # chalk + ora + boxen logger
164
+ │ ├── spawn.ts # Bun.spawn wrapper
165
+ │ ├── diff.ts # Config diff logic
166
+ │ ├── validation.ts # Runtime validation helpers
167
+ │ └── write.ts # File writing utilities
168
+ └── tests/ # Unit tests (bun test)
169
+ ```
170
+
171
+ ## Development
172
+
173
+ ```sh
174
+ bun install # install deps
175
+ bun run index.ts --help # show CLI help
176
+ bun run index.ts scan # detect system environment
177
+ bun run index.ts init # scaffold hofi/config.toml + hofi/mimeapps.toml
178
+ bun run index.ts validate # validate TOML config in cwd
179
+ bun run index.ts switch <dir> --dry-run # preview changes
180
+ bun run index.ts switch <dir> # apply config to system
181
+ bun test # run unit tests (65+ tests)
182
+ ```
183
+
184
+ ## License
185
+
186
+ MIT