hofii 0.1.1 → 0.1.3
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 +268 -1
- package/dist/main.js +44 -41
- package/package.json +1 -2
package/README.md
CHANGED
|
@@ -1 +1,268 @@
|
|
|
1
|
-
|
|
1
|
+
# Hofii
|
|
2
|
+
|
|
3
|
+
> An orchestration tool for managing dotfiles and packages declaratively on Linux.
|
|
4
|
+
|
|
5
|
+

|
|
6
|
+

|
|
7
|
+

|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
## Overview
|
|
12
|
+
|
|
13
|
+
Hofii is a declarative dotfile manager for Linux that helps you:
|
|
14
|
+
- **Manage symlinks** for configuration files across your system
|
|
15
|
+
- **Install packages** from multiple package managers (pacman, AUR, Flatpak)
|
|
16
|
+
- **Detect your environment** automatically (distro, package manager, AUR helper)
|
|
17
|
+
- **Track state** with a lock file for reproducible configurations
|
|
18
|
+
<!--
|
|
19
|
+
## Features
|
|
20
|
+
|
|
21
|
+
| Feature | Description |
|
|
22
|
+
|---------|-------------|
|
|
23
|
+
| 🔗 **Symlink Management** | Create, update, and remove symlinks with backup support |
|
|
24
|
+
| 📦 **Package Management** | Install packages via pacman, AUR (yay/paru), and Flatpak |
|
|
25
|
+
| 🔍 **Environment Detection** | Auto-detects OS, package manager, AUR helper, Flatpak |
|
|
26
|
+
| 📋 **Declarative Config** | TOML-based configuration with import support |
|
|
27
|
+
| 🔄 **Diff & Apply** | See changes before applying with interactive confirmation |
|
|
28
|
+
| 💾 **State Tracking** | Lock file (`~/.cache/hofii/hofii-lock.json`) tracks applied config |-->
|
|
29
|
+
|
|
30
|
+
## Installation
|
|
31
|
+
|
|
32
|
+
### Prerequisites
|
|
33
|
+
- [Bun](https://bun.sh/) (v1.0+)
|
|
34
|
+
- Linux (Arch-based distributions fully supported)
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
bun add -g hofii
|
|
38
|
+
```
|
|
39
|
+
Only support with bun
|
|
40
|
+
|
|
41
|
+
<!--## Quick Start
|
|
42
|
+
|
|
43
|
+
### 1. Create a Configuration Directory
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
mkdir -p ~/.config/hofii
|
|
47
|
+
cd ~/.config/hofii
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
### 2. Create `config.toml`
|
|
51
|
+
|
|
52
|
+
```toml
|
|
53
|
+
# ~/.config/hofii/config.toml
|
|
54
|
+
[settings]
|
|
55
|
+
aur_helper = "yay" # or "paru"
|
|
56
|
+
backup = true # backup existing files before symlinking
|
|
57
|
+
|
|
58
|
+
# Symlinks: source (relative to config.toml) -> target (absolute path with ~ expansion)
|
|
59
|
+
[[symlinks]]
|
|
60
|
+
source = "./config/fastfetch"
|
|
61
|
+
target = "~/.config/fastfetch"
|
|
62
|
+
|
|
63
|
+
[[symlinks]]
|
|
64
|
+
source = "./config/nvim"
|
|
65
|
+
target = "~/.config/nvim"
|
|
66
|
+
|
|
67
|
+
[[symlinks]]
|
|
68
|
+
source = "./config/zed"
|
|
69
|
+
target = "~/.config/zed"
|
|
70
|
+
|
|
71
|
+
# Packages to install
|
|
72
|
+
[[packages]]
|
|
73
|
+
manager = "pacman"
|
|
74
|
+
items = ["git", "neovim", "zsh", "btop"]
|
|
75
|
+
|
|
76
|
+
[[packages]]
|
|
77
|
+
manager = "aur"
|
|
78
|
+
items = ["visual-studio-code-bin", "google-chrome"]
|
|
79
|
+
|
|
80
|
+
[[packages]]
|
|
81
|
+
manager = "flatpak"
|
|
82
|
+
scope = "user"
|
|
83
|
+
items = ["com.spotify.Client", "org.telegram.desktop"]
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
### 3. Add Your Dotfiles
|
|
87
|
+
|
|
88
|
+
```bash
|
|
89
|
+
mkdir -p ~/.config/hofii/config
|
|
90
|
+
# Copy or link your config directories here
|
|
91
|
+
cp -r ~/.config/nvim ~/.config/hofii/config/
|
|
92
|
+
cp -r ~/.config/fastfetch ~/.config/hofii/config/
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
### 4. Scan Your System
|
|
96
|
+
|
|
97
|
+
```bash
|
|
98
|
+
hofii scan
|
|
99
|
+
# or
|
|
100
|
+
hofii s
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
This detects your OS, package manager, AUR helper, and Flatpak availability.
|
|
104
|
+
|
|
105
|
+
### 5. Validate Configuration
|
|
106
|
+
|
|
107
|
+
```bash
|
|
108
|
+
hofii validate ~/.config/hofii
|
|
109
|
+
# or
|
|
110
|
+
hofii v ~/.config/hofii
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
Validates your TOML config without applying changes.
|
|
114
|
+
|
|
115
|
+
### 6. Apply Configuration
|
|
116
|
+
|
|
117
|
+
```bash
|
|
118
|
+
hofii switch ~/.config/hofii
|
|
119
|
+
# or
|
|
120
|
+
hofii sw ~/.config/hofii
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
Shows a diff of what will change, asks for confirmation, then applies symlinks.-->
|
|
124
|
+
|
|
125
|
+
## Commands
|
|
126
|
+
|
|
127
|
+
| Command | Alias | Description |
|
|
128
|
+
|---------|-------|-------------|
|
|
129
|
+
| `hofii scan` | `s` | Detect system environment (OS, package manager, AUR helper, Flatpak) |
|
|
130
|
+
| `hofii validate [dir]` | `v` | Validate configuration files |
|
|
131
|
+
| `hofii switch [dir]` | `sw` | Switch to new configuration (apply symlinks) |
|
|
132
|
+
|
|
133
|
+
## Configuration Reference
|
|
134
|
+
|
|
135
|
+
### Settings
|
|
136
|
+
|
|
137
|
+
```toml
|
|
138
|
+
[settings]
|
|
139
|
+
aur_helper = "yay" # AUR helper: "yay" or "paru"
|
|
140
|
+
backup = true # Backup existing files before creating symlinks
|
|
141
|
+
flatpak = true # Enable Flatpak support (auto-detected)
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
### Symlinks
|
|
145
|
+
|
|
146
|
+
```toml
|
|
147
|
+
[[symlinks]]
|
|
148
|
+
source = "./config/nvim" # Relative to config.toml directory
|
|
149
|
+
target = "~/.config/nvim" # Target path (~ expands to $HOME)
|
|
150
|
+
sudo = false # Use sudo for creation (default: false)
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
<!--### Packages
|
|
154
|
+
|
|
155
|
+
#### Pacman (Official Repositories)
|
|
156
|
+
```toml
|
|
157
|
+
[[packages]]
|
|
158
|
+
manager = "pacman"
|
|
159
|
+
items = ["git", "neovim", "base-devel"]
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
#### AUR (Arch User Repository)
|
|
163
|
+
```toml
|
|
164
|
+
[[packages]]
|
|
165
|
+
manager = "aur"
|
|
166
|
+
items = [
|
|
167
|
+
"visual-studio-code-bin",
|
|
168
|
+
{ name = "google-chrome", post_hooks = ["sudo systemctl enable --now chrome-remote-desktop"] }
|
|
169
|
+
]
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
#### Flatpak
|
|
173
|
+
```toml
|
|
174
|
+
[[packages]]
|
|
175
|
+
manager = "flatpak"
|
|
176
|
+
scope = "user" # or "system"
|
|
177
|
+
items = ["com.spotify.Client", "org.telegram.desktop"]
|
|
178
|
+
```-->
|
|
179
|
+
|
|
180
|
+
### Imports (Modular Config)
|
|
181
|
+
|
|
182
|
+
Split your config across multiple files:
|
|
183
|
+
|
|
184
|
+
```toml
|
|
185
|
+
# config.toml
|
|
186
|
+
imports = ["home.toml", "work.toml"]
|
|
187
|
+
|
|
188
|
+
[[symlinks]]
|
|
189
|
+
source = "./config/shared"
|
|
190
|
+
target = "~/.config/shared"
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
```toml
|
|
194
|
+
# home.toml
|
|
195
|
+
[[symlinks]]
|
|
196
|
+
source = "./config/hyprland"
|
|
197
|
+
target = "~/.config/hyprland"
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
## Project Structure
|
|
201
|
+
|
|
202
|
+
```
|
|
203
|
+
hofii/
|
|
204
|
+
├── src/
|
|
205
|
+
│ ├── commands/ # CLI commands (scan, validate, switch)
|
|
206
|
+
│ ├── core/
|
|
207
|
+
│ │ ├── config/ # Config parsing & validation (schema, parser)
|
|
208
|
+
│ │ ├── detect.ts # Environment detection
|
|
209
|
+
│ │ ├── diff.ts # Config diffing
|
|
210
|
+
│ │ └── symlink.ts # Symlink operations
|
|
211
|
+
│ ├── data/
|
|
212
|
+
│ │ ├── env.ts # Environment variables
|
|
213
|
+
│ │ ├── metadata.ts # Lock file management (~/.cache/hofii/)
|
|
214
|
+
│ │ └── os.ts # OS/Package manager detection
|
|
215
|
+
│ ├── pm/
|
|
216
|
+
│ │ └── pacman.ts # Pacman package operations
|
|
217
|
+
│ ├── types/ # TypeScript types
|
|
218
|
+
│ └── utils/ # Utilities (fs, path, spawn)
|
|
219
|
+
├── example/ # Example configurations
|
|
220
|
+
├── dist/ # Built output
|
|
221
|
+
└── index.ts # Entry point
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
## Lock File
|
|
225
|
+
|
|
226
|
+
Hofii maintains a lock file at `~/.cache/hofii/hofii-lock.json` that tracks:
|
|
227
|
+
- Applied symlinks (source, target, sudo)
|
|
228
|
+
- Configuration state
|
|
229
|
+
|
|
230
|
+
This enables:
|
|
231
|
+
- Diffing between current and desired state
|
|
232
|
+
- Safe removal of symlinks no longer in config
|
|
233
|
+
- Reproducible deployments
|
|
234
|
+
|
|
235
|
+
## Example Configuration
|
|
236
|
+
|
|
237
|
+
See the `example/` directory for a complete working configuration:
|
|
238
|
+
|
|
239
|
+
```
|
|
240
|
+
example/
|
|
241
|
+
├── config.toml # Main config with symlinks
|
|
242
|
+
├── home.toml # Additional config (imported)
|
|
243
|
+
├── config/
|
|
244
|
+
│ ├── fastfetch/
|
|
245
|
+
│ ├── btop/
|
|
246
|
+
│ └── ...
|
|
247
|
+
└── .state/ # Example lock file
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
## Supported Distributions
|
|
251
|
+
|
|
252
|
+
| Distribution | Package Manager | Status |
|
|
253
|
+
|--------------|-----------------|--------|
|
|
254
|
+
| Arch Linux | pacman | ✅ Full support |
|
|
255
|
+
| EndeavourOS | pacman | ✅ Full support |
|
|
256
|
+
| Manjaro | pacman | ✅ Full support |
|
|
257
|
+
| Garuda | pacman | ✅ Full support |
|
|
258
|
+
| CachyOS | pacman | ✅ Full support |
|
|
259
|
+
| Fedora | dnf | 🔄 Planned |
|
|
260
|
+
| Nobara | dnf | 🔄 Planned |
|
|
261
|
+
|
|
262
|
+
## License
|
|
263
|
+
|
|
264
|
+
MIT License - see [LICENSE](LICENSE) for details.
|
|
265
|
+
|
|
266
|
+
---
|
|
267
|
+
|
|
268
|
+
**Note:** Hofii is in early development. Use with caution and always review the diff before applying changes.
|
package/dist/main.js
CHANGED
|
@@ -1,55 +1,58 @@
|
|
|
1
1
|
#!/usr/bin/env bun
|
|
2
2
|
// @bun
|
|
3
|
-
var
|
|
4
|
-
`)},{title:"For more info, run any command with the `--help` flag",body:t.map((
|
|
5
|
-
`)})}let o=this.isGlobalCommand?s:[...this.options,...s||[]];if(!this.isGlobalCommand&&!this.isDefaultCommand)o=o.filter((a)=>a.name!=="version");if(o.length>0){let a=
|
|
6
|
-
`)})}if(this.examples.length>0)
|
|
7
|
-
`)});if(r)
|
|
3
|
+
var Sn=Object.create;var{getPrototypeOf:An,defineProperty:at,getOwnPropertyNames:Cn}=Object;var lt=Object.prototype.hasOwnProperty;function Mn(e){return this[e]}var On,Dn,ct=(e,t,n)=>{var s=e!=null&&typeof e==="object";if(s){var r=t?On??=new WeakMap:Dn??=new WeakMap,i=r.get(e);if(i)return i}n=e!=null?Sn(An(e)):{};let o=t||!e||!e.__esModule||!lt.call(e,"default")?at(n,"default",{value:e,enumerable:!0}):n;if(e&&typeof e==="object"||typeof e==="function"){for(let a of Cn(e))if(!lt.call(o,a))at(o,a,{get:Mn.bind(e,a),enumerable:!0})}if(s)r.set(e,o);return o};var Pn=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var Ke=Pn(function(Mr,Tt){var ze={to(e,t){if(!t)return`\x1B[${e+1}G`;return`\x1B[${t+1};${e+1}H`},move(e,t){let n="";if(e<0)n+=`\x1B[${-e}D`;else if(e>0)n+=`\x1B[${e}C`;if(t<0)n+=`\x1B[${-t}A`;else if(t>0)n+=`\x1B[${t}B`;return n},up:(e=1)=>`\x1B[${e}A`,down:(e=1)=>`\x1B[${e}B`,forward:(e=1)=>`\x1B[${e}C`,backward:(e=1)=>`\x1B[${e}D`,nextLine:(e=1)=>"\x1B[E".repeat(e),prevLine:(e=1)=>"\x1B[F".repeat(e),left:"\x1B[G",hide:"\x1B[?25l",show:"\x1B[?25h",save:"\x1B7",restore:"\x1B8"},cs={up:(e=1)=>"\x1B[S".repeat(e),down:(e=1)=>"\x1B[T".repeat(e)},fs={screen:"\x1B[2J",up:(e=1)=>"\x1B[1J".repeat(e),down:(e=1)=>"\x1B[J".repeat(e),line:"\x1B[2K",lineEnd:"\x1B[K",lineStart:"\x1B[1K",lines(e){let t="";for(let n=0;n<e;n++)t+=this.line+(n<e-1?ze.up():"");if(e)t+=ze.left;return t}};Tt.exports={cursor:ze,scroll:cs,erase:fs,beep:"\x07"}});function Te(e){return e==null?[]:Array.isArray(e)?e:[e]}function Fn(e,t,n,s){var r,i=e[t],o=~s.string.indexOf(t)?n==null||n===!0?"":String(n):typeof n==="boolean"?n:~s.boolean.indexOf(t)?n==="false"?!1:n==="true"||(e._.push((r=+n,r*0===0)?r:n),!!n):(r=+n,r*0===0)?r:n;e[t]=i==null?o:Array.isArray(i)?i.concat(o):[i,o]}function jn(e,t){e=e||[],t=t||{};var n,s,r,i,o,a={_:[]},u=0,l=0,c=0,f=e.length;let h=t.alias!==void 0,v=t.unknown!==void 0,m=t.default!==void 0;if(t.alias=t.alias||{},t.string=Te(t.string),t.boolean=Te(t.boolean),h)for(n in t.alias){s=t.alias[n]=Te(t.alias[n]);for(u=0;u<s.length;u++)(t.alias[s[u]]=s.concat(n)).splice(u,1)}for(u=t.boolean.length;u-- >0;){s=t.alias[t.boolean[u]]||[];for(l=s.length;l-- >0;)t.boolean.push(s[l])}for(u=t.string.length;u-- >0;){s=t.alias[t.string[u]]||[];for(l=s.length;l-- >0;)t.string.push(s[l])}if(m){for(n in t.default)if(i=typeof t.default[n],s=t.alias[n]=t.alias[n]||[],t[i]!==void 0){t[i].push(n);for(u=0;u<s.length;u++)t[i].push(s[u])}}let d=v?Object.keys(t.alias):[];for(u=0;u<f;u++){if(r=e[u],r==="--"){a._=a._.concat(e.slice(++u));break}for(l=0;l<r.length;l++)if(r.charCodeAt(l)!==45)break;if(l===0)a._.push(r);else if(r.substring(l,l+3)==="no-"){if(i=r.substring(l+3),v&&!~d.indexOf(i))return t.unknown(r);a[i]=!1}else{for(c=l+1;c<r.length;c++)if(r.charCodeAt(c)===61)break;i=r.substring(l,c),o=r.substring(++c)||u+1===f||(""+e[u+1]).charCodeAt(0)===45||e[++u],s=l===2?[i]:i;for(c=0;c<s.length;c++){if(i=s[c],v&&!~d.indexOf(i))return t.unknown("-".repeat(l)+i);Fn(a,i,c+1<s.length||o,t)}}}if(m){for(n in t.default)if(a[n]===void 0)a[n]=t.default[n]}if(h)for(n in a){s=t.alias[n]||[];while(s.length>0)a[s.shift()]=a[n]}return a}function ht(e){return e.replace(/[<[].+/,"").trim()}function Rn(e){let t=/<([^>]+)>/g,n=/\[([^\]]+)\]/g,s=[],r=(a)=>{let u=!1,l=a[1];if(l.startsWith("..."))l=l.slice(3),u=!0;return{required:a[0].startsWith("<"),value:l,variadic:u}},i;while(i=t.exec(e))s.push(r(i));let o;while(o=n.exec(e))s.push(r(o));return s}function Tn(e){let t={alias:{},boolean:[]};for(let[n,s]of e.entries()){if(s.names.length>1)t.alias[s.names[0]]=s.names.slice(1);if(s.isBoolean)if(s.negated){if(!e.some((r,i)=>i!==n&&r.names.some((o)=>s.names.includes(o))&&typeof r.required==="boolean"))t.boolean.push(s.names[0])}else t.boolean.push(s.names[0])}return t}function ft(e){return e.sort((t,n)=>t.length>n.length?-1:1)[0]}function pt(e,t){return e.length>=t?e:`${e}${" ".repeat(t-e.length)}`}function Nn(e){return e.replaceAll(/([a-z])-([a-z])/g,(t,n,s)=>n+s.toUpperCase())}function Vn(e,t,n){let s=e;for(let r=0;r<t.length;r++){let i=t[r];if(r===t.length-1){s[i]=n;return}if(s[i]==null){let o=+t[r+1]>-1;s[i]=o?[]:{}}s=s[i]}}function Gn(e,t){for(let n of Object.keys(t)){let s=t[n];if(s.shouldTransform){if(e[n]=[e[n]].flat(),typeof s.transformFunction==="function")e[n]=e[n].map(s.transformFunction)}}}function Ln(e){let t=/([^\\/]+)$/.exec(e);return t?t[1]:""}function mt(e){return e.split(".").map((t,n)=>n===0?Nn(t):t).join(".")}var fe=class extends Error{constructor(e){super(e);if(this.name="CACError",typeof Error.captureStackTrace!=="function")this.stack=Error(e).stack}},qn=class{rawName;description;name;names;isBoolean;required;config;negated;constructor(e,t,n){if(this.rawName=e,this.description=t,this.config=Object.assign({},n),e=e.replaceAll(".*",""),this.negated=!1,this.names=ht(e).split(",").map((s)=>{let r=s.trim().replace(/^-{1,2}/,"");if(r.startsWith("no-"))this.negated=!0,r=r.replace(/^no-/,"");return mt(r)}).sort((s,r)=>s.length>r.length?1:-1),this.name=this.names.at(-1),this.negated&&this.config.default==null)this.config.default=!0;if(e.includes("<"))this.required=!0;else if(e.includes("["))this.required=!1;else this.isBoolean=!0}},Ne,pe;if(typeof process<"u"){let e;if(typeof Deno<"u"&&typeof Deno.version?.deno==="string")e="deno";else if(typeof Bun<"u"&&typeof Bun.version==="string")e="bun";else e="node";pe=`${process.platform}-${process.arch} ${e}-${process.version}`,Ne=process.argv}else if(typeof navigator>"u")pe="unknown";else pe=`${navigator.platform} ${navigator.userAgent}`;var yt=class{rawName;description;config;cli;options;aliasNames;name;args;commandAction;usageText;versionNumber;examples;helpCallback;globalCommand;constructor(e,t,n={},s){this.rawName=e,this.description=t,this.config=n,this.cli=s,this.options=[],this.aliasNames=[],this.name=ht(e),this.args=Rn(e),this.examples=[]}usage(e){return this.usageText=e,this}allowUnknownOptions(){return this.config.allowUnknownOptions=!0,this}ignoreOptionDefaultValue(){return this.config.ignoreOptionDefaultValue=!0,this}version(e,t="-v, --version"){return this.versionNumber=e,this.option(t,"Display version number"),this}example(e){return this.examples.push(e),this}option(e,t,n){let s=new qn(e,t,n);return this.options.push(s),this}alias(e){return this.aliasNames.push(e),this}action(e){return this.commandAction=e,this}isMatched(e){return this.name===e||this.aliasNames.includes(e)}get isDefaultCommand(){return this.name===""||this.aliasNames.includes("!")}get isGlobalCommand(){return this instanceof dt}hasOption(e){return e=e.split(".")[0],this.options.find((t)=>t.names.includes(e))}outputHelp(){let{name:e,commands:t}=this.cli,{versionNumber:n,options:s,helpCallback:r}=this.cli.globalCommand,i=[{body:`${e}${n?`/${n}`:""}`}];if(i.push({title:"Usage",body:` $ ${e} ${this.usageText||this.rawName}`}),(this.isGlobalCommand||this.isDefaultCommand)&&t.length>0){let a=ft(t.map((u)=>u.rawName));i.push({title:"Commands",body:t.map((u)=>` ${pt(u.rawName,a.length)} ${u.description}`).join(`
|
|
4
|
+
`)},{title:"For more info, run any command with the `--help` flag",body:t.map((u)=>` $ ${e}${u.name===""?"":` ${u.name}`} --help`).join(`
|
|
5
|
+
`)})}let o=this.isGlobalCommand?s:[...this.options,...s||[]];if(!this.isGlobalCommand&&!this.isDefaultCommand)o=o.filter((a)=>a.name!=="version");if(o.length>0){let a=ft(o.map((u)=>u.rawName));i.push({title:"Options",body:o.map((u)=>` ${pt(u.rawName,a.length)} ${u.description} ${u.config.default===void 0?"":`(default: ${u.config.default})`}`).join(`
|
|
6
|
+
`)})}if(this.examples.length>0)i.push({title:"Examples",body:this.examples.map((a)=>{if(typeof a==="function")return a(e);return a}).join(`
|
|
7
|
+
`)});if(r)i=r(i)||i;console.info(i.map((a)=>a.title?`${a.title}:
|
|
8
8
|
${a.body}`:a.body).join(`
|
|
9
9
|
|
|
10
|
-
`))}outputVersion(){let{name:e}=this.cli,{versionNumber:t}=this.cli.globalCommand;if(t)console.info(`${e}/${t} ${le}`)}checkRequiredArgs(){let e=this.args.filter((t)=>t.required).length;if(this.cli.args.length<e)throw new ae(`missing required args for command \`${this.rawName}\``)}checkUnknownOptions(){let{options:e,globalCommand:t}=this.cli;if(!this.config.allowUnknownOptions){for(let n of Object.keys(e))if(n!=="--"&&!this.hasOption(n)&&!t.hasOption(n))throw new ae(`Unknown option \`${n.length>1?`--${n}`:`-${n}`}\``)}}checkOptionValue(){let{options:e,globalCommand:t}=this.cli,n=[...t.options,...this.options];for(let s of n){let r=e[s.name.split(".")[0]];if(s.required){let u=n.some((o)=>o.negated&&o.names.includes(s.name));if(r===!0||r===!1&&!u)throw new ae(`option \`${s.rawName}\` value is missing`)}}}checkUnusedArgs(){let e=this.args.some((t)=>t.variadic)?1/0:this.args.length;if(e<this.cli.args.length)throw new ae(`Unused args: ${this.cli.args.slice(e).map((t)=>`\`${t}\``).join(", ")}`)}},ct=class extends lt{constructor(e){super("@@global@@","",{},e)}},Tn=class extends EventTarget{name;commands;globalCommand;matchedCommand;matchedCommandName;rawArgs;args;options;showHelpOnExit;showVersionOnExit;constructor(e=""){super();this.name=e,this.commands=[],this.rawArgs=[],this.args=[],this.options={},this.globalCommand=new ct(this),this.globalCommand.usage("<command> [options]")}usage(e){return this.globalCommand.usage(e),this}command(e,t,n){let s=new lt(e,t||"",n,this);return s.globalCommand=this.globalCommand,this.commands.push(s),s}option(e,t,n){return this.globalCommand.option(e,t,n),this}help(e){return this.globalCommand.option("-h, --help","Display this message"),this.globalCommand.helpCallback=e,this.showHelpOnExit=!0,this}version(e,t="-v, --version"){return this.globalCommand.version(e,t),this.showVersionOnExit=!0,this}example(e){return this.globalCommand.example(e),this}outputHelp(){if(this.matchedCommand)this.matchedCommand.outputHelp();else this.globalCommand.outputHelp()}outputVersion(){this.globalCommand.outputVersion()}setParsedInfo({args:e,options:t},n,s){if(this.args=e,this.options=t,n)this.matchedCommand=n;if(s)this.matchedCommandName=s;return this}unsetMatchedCommand(){this.matchedCommand=void 0,this.matchedCommandName=void 0}parse(e,{run:t=!0}={}){if(!e){if(!Fe)throw Error("No argv provided and runtime process argv is not available.");e=Fe}if(this.rawArgs=e,!this.name)this.name=e[1]?Fn(e[1]):"cli";let n=!0;for(let r of this.commands){let u=this.mri(e.slice(2),r),o=u.args[0];if(r.isMatched(o)){n=!1;let a={...u,args:u.args.slice(1)};this.setParsedInfo(a,r,o),this.dispatchEvent(new CustomEvent(`command:${o}`,{detail:r}))}}if(n){for(let r of this.commands)if(r.isDefaultCommand){n=!1;let u=this.mri(e.slice(2),r);this.setParsedInfo(u,r),this.dispatchEvent(new CustomEvent("command:!",{detail:r}))}}if(n){let r=this.mri(e.slice(2));this.setParsedInfo(r)}if(this.options.help&&this.showHelpOnExit)this.outputHelp(),t=!1,this.unsetMatchedCommand();if(this.options.version&&this.showVersionOnExit&&this.matchedCommandName==null)this.outputVersion(),t=!1,this.unsetMatchedCommand();let s={args:this.args,options:this.options};if(t)this.runMatchedCommand();if(!this.matchedCommand&&this.args[0])this.dispatchEvent(new CustomEvent("command:*",{detail:this.args[0]}));return s}mri(e,t){let n=[...this.globalCommand.options,...t?t.options:[]],s=An(n),r=[],u=e.indexOf("--");if(u!==-1)r=e.slice(u+1),e=e.slice(0,u);let o=Sn(e,s);o=Object.keys(o).reduce((f,h)=>({...f,[at(h)]:o[h]}),{_:[]});let a=o._,i={"--":r},l=t&&t.config.ignoreOptionDefaultValue?t.config.ignoreOptionDefaultValue:this.globalCommand.config.ignoreOptionDefaultValue,c=Object.create(null);for(let f of n){if(!l&&f.config.default!==void 0)for(let h of f.names)i[h]=f.config.default;if(Array.isArray(f.config.type)&&c[f.name]===void 0)c[f.name]=Object.create(null),c[f.name].shouldTransform=!0,c[f.name].transformFunction=f.config.type[0]}for(let f of Object.keys(o))if(f!=="_")Mn(i,f.split("."),o[f]),Dn(i,c);return{args:a,options:i}}runMatchedCommand(){let{args:e,options:t,matchedCommand:n}=this;if(!n||!n.commandAction)return;n.checkUnknownOptions(),n.checkOptionValue(),n.checkRequiredArgs(),n.checkUnusedArgs();let s=[];return n.args.forEach((r,u)=>{if(r.variadic)s.push(e.slice(u));else s.push(e[u])}),s.push(t),n.commandAction.apply(this,s)}},ft=(e="")=>new Tn(e);import sr from"path";var ce,Rn={lang:void 0,message:void 0,abortEarly:void 0,abortPipeEarly:void 0};function mt(e){if(!e&&!ce)return Rn;return{lang:e?.lang??ce?.lang,message:e?.message,abortEarly:e?.abortEarly??ce?.abortEarly,abortPipeEarly:e?.abortPipeEarly??ce?.abortPipeEarly}}var Pn;function Nn(e){return Pn?.get(e)}var Vn;function Ln(e){return Vn?.get(e)}var Gn;function qn(e,t){return Gn?.get(e)?.get(t)}function je(e){let t=typeof e;if(t==="string")return`"${e}"`;if(t==="number"||t==="bigint"||t==="boolean")return`${e}`;if(t==="object"||t==="function")return(e&&Object.getPrototypeOf(e)?.constructor?.name)??"null";return t}function P(e,t,n,s,r){let u=r&&"input"in r?r.input:n.value,o=r?.expected??e.expects??null,a=r?.received??je(u),i={kind:e.kind,type:e.type,input:u,expected:o,received:a,message:`Invalid ${t}: ${o?`Expected ${o} but r`:"R"}eceived ${a}`,requirement:e.requirement,path:r?.path,issues:r?.issues,lang:s.lang,abortEarly:s.abortEarly,abortPipeEarly:s.abortPipeEarly},l=e.kind==="schema",c=r?.message??e.message??qn(e.reference,i.lang)??(l?Ln(i.lang):null)??s.message??Nn(i.lang);if(c!==void 0)i.message=typeof c==="function"?c(i):c;if(l)n.typed=!1;if(n.issues)n.issues.push(i);else n.issues=[i]}var pt=new WeakMap;function N(e){let t=pt.get(e);if(!t)t={version:1,vendor:"valibot",validate(n){return e["~run"]({value:n},mt())}},pt.set(e,t);return t}function yt(e,t){let n=[...new Set(e)];if(n.length>1)return`(${n.join(` ${t} `)})`;return n[0]??"never"}var Te=class extends Error{constructor(e){super(e[0].message);this.name="ValiError",this.issues=e}};function Un(e,t,n){return typeof e.fallback==="function"?e.fallback(t,n):e.fallback}function dt(e,t,n){return typeof e.default==="function"?e.default(t,n):e.default}function V(e,t){return{kind:"schema",type:"array",reference:V,expects:"Array",async:!1,item:e,message:t,get "~standard"(){return N(this)},"~run"(n,s){let r=n.value;if(Array.isArray(r)){n.typed=!0,n.value=[];for(let u=0;u<r.length;u++){let o=r[u],a=this.item["~run"]({value:o},s);if(a.issues){let i={type:"array",origin:"value",input:r,key:u,value:o};for(let l of a.issues){if(l.path)l.path.unshift(i);else l.path=[i];n.issues?.push(l)}if(!n.issues)n.issues=a.issues;if(s.abortEarly){n.typed=!1;break}}if(!a.typed)n.typed=!1;n.value.push(a.value)}}else P(this,"type",n,s);return n}}}function Q(e){return{kind:"schema",type:"boolean",reference:Q,expects:"boolean",async:!1,message:e,get "~standard"(){return N(this)},"~run"(t,n){if(typeof t.value==="boolean")t.typed=!0;else P(this,"type",t,n);return t}}}function Re(e,t){return{kind:"schema",type:"literal",reference:Re,expects:je(e),async:!1,literal:e,message:t,get "~standard"(){return N(this)},"~run"(n,s){if(n.value===this.literal)n.typed=!0;else P(this,"type",n,s);return n}}}function W(e,t){return{kind:"schema",type:"object",reference:W,expects:"Object",async:!1,entries:e,message:t,get "~standard"(){return N(this)},"~run"(n,s){let r=n.value;if(r&&typeof r==="object"){n.typed=!0,n.value={};for(let u in this.entries){let o=this.entries[u];if(u in r||(o.type==="exact_optional"||o.type==="optional"||o.type==="nullish")&&o.default!==void 0){let a=u in r?r[u]:dt(o),i=o["~run"]({value:a},s);if(i.issues){let l={type:"object",origin:"value",input:r,key:u,value:a};for(let c of i.issues){if(c.path)c.path.unshift(l);else c.path=[l];n.issues?.push(c)}if(!n.issues)n.issues=i.issues;if(s.abortEarly){n.typed=!1;break}}if(!i.typed)n.typed=!1;n.value[u]=i.value}else if(o.fallback!==void 0)n.value[u]=Un(o);else if(o.type!=="exact_optional"&&o.type!=="optional"&&o.type!=="nullish"){if(P(this,"key",n,s,{input:void 0,expected:`"${u}"`,path:[{type:"object",origin:"key",input:r,key:u,value:r[u]}]}),s.abortEarly)break}}}else P(this,"type",n,s);return n}}}function ee(e,t){return{kind:"schema",type:"optional",reference:ee,expects:`(${e.expects} | undefined)`,async:!1,wrapped:e,default:t,get "~standard"(){return N(this)},"~run"(n,s){if(n.value===void 0){if(this.default!==void 0)n.value=dt(this,n,s);if(n.value===void 0)return n.typed=!0,n}return this.wrapped["~run"](n,s)}}}function te(e,t){return{kind:"schema",type:"picklist",reference:te,expects:yt(e.map(je),"|"),async:!1,options:e,message:t,get "~standard"(){return N(this)},"~run"(n,s){if(this.options.includes(n.value))n.typed=!0;else P(this,"type",n,s);return n}}}function D(e){return{kind:"schema",type:"string",reference:D,expects:"string",async:!1,message:e,get "~standard"(){return N(this)},"~run"(t,n){if(typeof t.value==="string")t.typed=!0;else P(this,"type",t,n);return t}}}function ht(e){let t;if(e)for(let n of e)if(t)for(let s of n.issues)t.push(s);else t=n.issues;return t}function ne(e,t){return{kind:"schema",type:"union",reference:ne,expects:yt(e.map((n)=>n.expects),"|"),async:!1,options:e,message:t,get "~standard"(){return N(this)},"~run"(n,s){let r,u,o;for(let a of this.options){let i=a["~run"]({value:n.value},s);if(i.typed)if(i.issues)if(u)u.push(i);else u=[i];else{r=i;break}else if(o)o.push(i);else o=[i]}if(r)return r;if(u){if(u.length===1)return u[0];P(this,"type",n,s,{issues:ht(u)}),n.typed=!0}else if(o?.length===1)return o[0];else P(this,"type",n,s,{issues:ht(o)});return n}}}function fe(e,t,n){let s=e["~run"]({value:t},mt(n));if(s.issues)throw new Te(s.issues);return s.value}function Pe(e,t){let n={};for(let s in e.entries)n[s]=!t||t.includes(s)?ee(e.entries[s]):e.entries[s];return{...e,entries:n,get "~standard"(){return N(this)}}}import{stdout as Be,stdin as Ft}from"process";import*as H from"readline";import is from"readline";var gt=(()=>{let e=/[\uD800-\uDBFF][\uDC00-\uDFFF]/g;return(t)=>{let n=0;e.lastIndex=0;while(e.test(t))n+=1;return t.length-n}})(),vt=(e)=>e===12288||e>=65281&&e<=65376||e>=65504&&e<=65510,$t=(e)=>e===8987||e===9001||e>=12272&&e<=12287||e>=12289&&e<=12350||e>=12441&&e<=12543||e>=12549&&e<=12591||e>=12593&&e<=12686||e>=12688&&e<=12771||e>=12783&&e<=12830||e>=12832&&e<=12871||e>=12880&&e<=19903||e>=65040&&e<=65049||e>=65072&&e<=65106||e>=65108&&e<=65126||e>=65128&&e<=65131||e>=127488&&e<=127490||e>=127504&&e<=127547||e>=127552&&e<=127560||e>=131072&&e<=196605||e>=196608&&e<=262141;var Bn=/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]|\u001b\]8;[^;]*;.*?(?:\u0007|\u001b\u005c)/y,Wn=/[\x00-\x08\x0A-\x1F\x7F-\x9F]{1,1000}/y,bt=/(?:(?![\uFF61-\uFF9F\uFF00-\uFFEF])[\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}\p{Script=Hangul}\p{Script=Tangut}]){1,1000}/yu,Hn=/\t{1,1000}/y,kt=/[\u{1F1E6}-\u{1F1FF}]{2}|\u{1F3F4}[\u{E0061}-\u{E007A}]{2}[\u{E0030}-\u{E0039}\u{E0061}-\u{E007A}]{1,3}\u{E007F}|(?:\p{Emoji}\uFE0F\u20E3?|\p{Emoji_Modifier_Base}\p{Emoji_Modifier}?|\p{Emoji_Presentation})(?:\u200D(?:\p{Emoji_Modifier_Base}\p{Emoji_Modifier}?|\p{Emoji_Presentation}|\p{Emoji}\uFE0F\u20E3?))*/yu,zn=/(?:[\x20-\x7E\xA0-\xFF](?!\uFE0F)){1,1000}/y,Kn=/\p{M}+/gu,Xn={limit:1/0,ellipsis:""},wt=(e,t={},n={})=>{let s=t.limit??1/0,r=t.ellipsis??"",u=t?.ellipsisWidth??(r?wt(r,Xn,n).width:0),o=0,a=n.controlWidth??0,i=n.tabWidth??8,l=n.emojiWidth??2,c=2,f=n.regularWidth??1,h=n.wideWidth??2,g=[[zn,f],[Bn,0],[Wn,a],[Hn,i],[kt,l],[bt,h]],m=0,y=0,F=e.length,q=0,U=!1,O=F,j=Math.max(0,s-u),I=0,J=0,M=0,E=0;e:while(!0){if(J>I||y>=F&&y>m){let B=e.slice(I,J)||e.slice(m,y);q=0;for(let K of B.replaceAll(Kn,"")){let S=K.codePointAt(0)||0;if(vt(S))E=2;else if($t(S))E=h;else E=f;if(M+E>j)O=Math.min(O,Math.max(I,m)+q);if(M+E>s){U=!0;break e}q+=K.length,M+=E}I=J=0}if(y>=F)break e;for(let B=0,K=g.length;B<K;B++){let[S,ue]=g[B];if(S.lastIndex=y,S.test(e)){if(q=S===bt?gt(e.slice(y,S.lastIndex)):S===kt?1:S.lastIndex-y,E=q*ue,M+E>j)O=Math.min(O,y+Math.floor((j-M)/ue));if(M+E>s){U=!0;break e}M+=E,I=m,J=y,y=m=S.lastIndex;continue e}}y+=1}return{width:U?j:M,index:U?O:F,truncated:U,ellipsed:U&&s>=u}},xt=wt;var Jn={limit:1/0,ellipsis:"",ellipsisWidth:0},Zn=(e,t={})=>xt(e,Jn,t).width,w=Zn;var he="\x1B",Ct="\x9B",Yn=39,Ve="\x07",At="[",Qn="]",Ot="m",Le=`${Qn}8;;`,_t=new RegExp(`(?:\\${At}(?<code>\\d+)m|\\${Le}(?<uri>.*)${Ve})`,"y"),Et=(e)=>{if(e>=30&&e<=37)return 39;if(e>=90&&e<=97)return 39;if(e>=40&&e<=47)return 49;if(e>=100&&e<=107)return 49;if(e===1||e===2)return 22;if(e===3)return 23;if(e===4)return 24;if(e===7)return 27;if(e===8)return 28;if(e===9)return 29;if(e===0)return 0;return},It=(e)=>`${he}${At}${e}${Ot}`,St=(e)=>`${he}${Le}${e}${Ve}`,Ne=(e,t,n)=>{let s=t[Symbol.iterator](),r=!1,u=!1,o=e.at(-1),a=o===void 0?0:w(o),i=s.next(),l=s.next(),c=0;while(!i.done){let f=i.value,h=w(f);if(a+h<=n)e[e.length-1]+=f;else e.push(f),a=0;if(f===he||f===Ct)r=!0,u=t.startsWith(Le,c+1);if(r){if(u){if(f===Ve)r=!1,u=!1}else if(f===Ot)r=!1}else if(a+=h,a===n&&!l.done)e.push(""),a=0;i=l,l=s.next(),c+=f.length}if(o=e.at(-1),!a&&o!==void 0&&o.length&&e.length>1)e[e.length-2]+=e.pop()},es=(e)=>{let t=e.split(" "),n=t.length;while(n){if(w(t[n-1]))break;n--}if(n===t.length)return e;return t.slice(0,n).join(" ")+t.slice(n).join("")},ts=(e,t,n={})=>{if(n.trim!==!1&&e.trim()==="")return"";let s="",r,u,o=e.split(" "),a=[""],i=0;for(let f=0;f<o.length;f++){let h=o[f];if(n.trim!==!1){let m=a.at(-1)??"",y=m.trimStart();if(m.length!==y.length)a[a.length-1]=y,i=w(y)}if(f!==0){if(i>=t&&(n.wordWrap===!1||n.trim===!1))a.push(""),i=0;if(i||n.trim===!1)a[a.length-1]+=" ",i++}let g=w(h);if(n.hard&&g>t){let m=t-i,y=1+Math.floor((g-m-1)/t);if(Math.floor((g-1)/t)<y)a.push("");Ne(a,h,t),i=w(a.at(-1)??"");continue}if(i+g>t&&i&&g){if(n.wordWrap===!1&&i<t){Ne(a,h,t),i=w(a.at(-1)??"");continue}a.push(""),i=0}if(i+g>t&&n.wordWrap===!1){Ne(a,h,t),i=w(a.at(-1)??"");continue}a[a.length-1]+=h,i+=g}if(n.trim!==!1)a=a.map((f)=>es(f));let l=a.join(`
|
|
11
|
-
`),c=!1;for(let f=0;f<l.length;f++){let h=l[f];if(s+=h,!c){if(c=h>="\uD800"&&h<="\uDBFF",c)continue}else c=!1;if(h===
|
|
12
|
-
`){if(
|
|
13
|
-
`){if(r&&
|
|
14
|
-
`)}var
|
|
10
|
+
`))}outputVersion(){let{name:e}=this.cli,{versionNumber:t}=this.cli.globalCommand;if(t)console.info(`${e}/${t} ${pe}`)}checkRequiredArgs(){let e=this.args.filter((t)=>t.required).length;if(this.cli.args.length<e)throw new fe(`missing required args for command \`${this.rawName}\``)}checkUnknownOptions(){let{options:e,globalCommand:t}=this.cli;if(!this.config.allowUnknownOptions){for(let n of Object.keys(e))if(n!=="--"&&!this.hasOption(n)&&!t.hasOption(n))throw new fe(`Unknown option \`${n.length>1?`--${n}`:`-${n}`}\``)}}checkOptionValue(){let{options:e,globalCommand:t}=this.cli,n=[...t.options,...this.options];for(let s of n){let r=e[s.name.split(".")[0]];if(s.required){let i=n.some((o)=>o.negated&&o.names.includes(s.name));if(r===!0||r===!1&&!i)throw new fe(`option \`${s.rawName}\` value is missing`)}}}checkUnusedArgs(){let e=this.args.some((t)=>t.variadic)?1/0:this.args.length;if(e<this.cli.args.length)throw new fe(`Unused args: ${this.cli.args.slice(e).map((t)=>`\`${t}\``).join(", ")}`)}},dt=class extends yt{constructor(e){super("@@global@@","",{},e)}},Un=class extends EventTarget{name;commands;globalCommand;matchedCommand;matchedCommandName;rawArgs;args;options;showHelpOnExit;showVersionOnExit;constructor(e=""){super();this.name=e,this.commands=[],this.rawArgs=[],this.args=[],this.options={},this.globalCommand=new dt(this),this.globalCommand.usage("<command> [options]")}usage(e){return this.globalCommand.usage(e),this}command(e,t,n){let s=new yt(e,t||"",n,this);return s.globalCommand=this.globalCommand,this.commands.push(s),s}option(e,t,n){return this.globalCommand.option(e,t,n),this}help(e){return this.globalCommand.option("-h, --help","Display this message"),this.globalCommand.helpCallback=e,this.showHelpOnExit=!0,this}version(e,t="-v, --version"){return this.globalCommand.version(e,t),this.showVersionOnExit=!0,this}example(e){return this.globalCommand.example(e),this}outputHelp(){if(this.matchedCommand)this.matchedCommand.outputHelp();else this.globalCommand.outputHelp()}outputVersion(){this.globalCommand.outputVersion()}setParsedInfo({args:e,options:t},n,s){if(this.args=e,this.options=t,n)this.matchedCommand=n;if(s)this.matchedCommandName=s;return this}unsetMatchedCommand(){this.matchedCommand=void 0,this.matchedCommandName=void 0}parse(e,{run:t=!0}={}){if(!e){if(!Ne)throw Error("No argv provided and runtime process argv is not available.");e=Ne}if(this.rawArgs=e,!this.name)this.name=e[1]?Ln(e[1]):"cli";let n=!0;for(let r of this.commands){let i=this.mri(e.slice(2),r),o=i.args[0];if(r.isMatched(o)){n=!1;let a={...i,args:i.args.slice(1)};this.setParsedInfo(a,r,o),this.dispatchEvent(new CustomEvent(`command:${o}`,{detail:r}))}}if(n){for(let r of this.commands)if(r.isDefaultCommand){n=!1;let i=this.mri(e.slice(2),r);this.setParsedInfo(i,r),this.dispatchEvent(new CustomEvent("command:!",{detail:r}))}}if(n){let r=this.mri(e.slice(2));this.setParsedInfo(r)}if(this.options.help&&this.showHelpOnExit)this.outputHelp(),t=!1,this.unsetMatchedCommand();if(this.options.version&&this.showVersionOnExit&&this.matchedCommandName==null)this.outputVersion(),t=!1,this.unsetMatchedCommand();let s={args:this.args,options:this.options};if(t)this.runMatchedCommand();if(!this.matchedCommand&&this.args[0])this.dispatchEvent(new CustomEvent("command:*",{detail:this.args[0]}));return s}mri(e,t){let n=[...this.globalCommand.options,...t?t.options:[]],s=Tn(n),r=[],i=e.indexOf("--");if(i!==-1)r=e.slice(i+1),e=e.slice(0,i);let o=jn(e,s);o=Object.keys(o).reduce((f,h)=>({...f,[mt(h)]:o[h]}),{_:[]});let a=o._,u={"--":r},l=t&&t.config.ignoreOptionDefaultValue?t.config.ignoreOptionDefaultValue:this.globalCommand.config.ignoreOptionDefaultValue,c=Object.create(null);for(let f of n){if(!l&&f.config.default!==void 0)for(let h of f.names)u[h]=f.config.default;if(Array.isArray(f.config.type)&&c[f.name]===void 0)c[f.name]=Object.create(null),c[f.name].shouldTransform=!0,c[f.name].transformFunction=f.config.type[0]}for(let f of Object.keys(o))if(f!=="_")Vn(u,f.split("."),o[f]),Gn(u,c);return{args:a,options:u}}runMatchedCommand(){let{args:e,options:t,matchedCommand:n}=this;if(!n||!n.commandAction)return;n.checkUnknownOptions(),n.checkOptionValue(),n.checkRequiredArgs(),n.checkUnusedArgs();let s=[];return n.args.forEach((r,i)=>{if(r.variadic)s.push(e.slice(i));else s.push(e[i])}),s.push(t),n.commandAction.apply(this,s)}},gt=(e="")=>new Un(e);import mr from"path";var he,Bn={lang:void 0,message:void 0,abortEarly:void 0,abortPipeEarly:void 0};function $t(e){if(!e&&!he)return Bn;return{lang:e?.lang??he?.lang,message:e?.message,abortEarly:e?.abortEarly??he?.abortEarly,abortPipeEarly:e?.abortPipeEarly??he?.abortPipeEarly}}var Wn;function Hn(e){return Wn?.get(e)}var zn;function Kn(e){return zn?.get(e)}var Xn;function Jn(e,t){return Xn?.get(e)?.get(t)}function Ve(e){let t=typeof e;if(t==="string")return`"${e}"`;if(t==="number"||t==="bigint"||t==="boolean")return`${e}`;if(t==="object"||t==="function")return(e&&Object.getPrototypeOf(e)?.constructor?.name)??"null";return t}function C(e,t,n,s,r){let i=r&&"input"in r?r.input:n.value,o=r?.expected??e.expects??null,a=r?.received??Ve(i),u={kind:e.kind,type:e.type,input:i,expected:o,received:a,message:`Invalid ${t}: ${o?`Expected ${o} but r`:"R"}eceived ${a}`,requirement:e.requirement,path:r?.path,issues:r?.issues,lang:s.lang,abortEarly:s.abortEarly,abortPipeEarly:s.abortPipeEarly},l=e.kind==="schema",c=r?.message??e.message??Jn(e.reference,u.lang)??(l?Kn(u.lang):null)??s.message??Hn(u.lang);if(c!==void 0)u.message=typeof c==="function"?c(u):c;if(l)n.typed=!1;if(n.issues)n.issues.push(u);else n.issues=[u]}var vt=new WeakMap;function F(e){let t=vt.get(e);if(!t)t={version:1,vendor:"valibot",validate(n){return e["~run"]({value:n},$t())}},vt.set(e,t);return t}function bt(e,t){let n=[...new Set(e)];if(n.length>1)return`(${n.join(` ${t} `)})`;return n[0]??"never"}var te=class extends Error{constructor(e){super(e[0].message);this.name="ValiError",this.issues=e}};function wt(e,t,n){return typeof e.fallback==="function"?e.fallback(t,n):e.fallback}function Ge(e,t,n){return typeof e.default==="function"?e.default(t,n):e.default}function X(e,t){return{kind:"schema",type:"array",reference:X,expects:"Array",async:!1,item:e,message:t,get "~standard"(){return F(this)},"~run"(n,s){let r=n.value;if(Array.isArray(r)){n.typed=!0,n.value=[];for(let i=0;i<r.length;i++){let o=r[i],a=this.item["~run"]({value:o},s);if(a.issues){let u={type:"array",origin:"value",input:r,key:i,value:o};for(let l of a.issues){if(l.path)l.path.unshift(u);else l.path=[u];n.issues?.push(l)}if(!n.issues)n.issues=a.issues;if(s.abortEarly){n.typed=!1;break}}if(!a.typed)n.typed=!1;n.value.push(a.value)}}else C(this,"type",n,s);return n}}}function ne(e){return{kind:"schema",type:"boolean",reference:ne,expects:"boolean",async:!1,message:e,get "~standard"(){return F(this)},"~run"(t,n){if(typeof t.value==="boolean")t.typed=!0;else C(this,"type",t,n);return t}}}function Le(e,t){return{kind:"schema",type:"literal",reference:Le,expects:Ve(e),async:!1,literal:e,message:t,get "~standard"(){return F(this)},"~run"(n,s){if(n.value===this.literal)n.typed=!0;else C(this,"type",n,s);return n}}}function J(e,t){return{kind:"schema",type:"object",reference:J,expects:"Object",async:!1,entries:e,message:t,get "~standard"(){return F(this)},"~run"(n,s){let r=n.value;if(r&&typeof r==="object"){n.typed=!0,n.value={};for(let i in this.entries){let o=this.entries[i];if(i in r||(o.type==="exact_optional"||o.type==="optional"||o.type==="nullish")&&o.default!==void 0){let a=i in r?r[i]:Ge(o),u=o["~run"]({value:a},s);if(u.issues){let l={type:"object",origin:"value",input:r,key:i,value:a};for(let c of u.issues){if(c.path)c.path.unshift(l);else c.path=[l];n.issues?.push(c)}if(!n.issues)n.issues=u.issues;if(s.abortEarly){n.typed=!1;break}}if(!u.typed)n.typed=!1;n.value[i]=u.value}else if(o.fallback!==void 0)n.value[i]=wt(o);else if(o.type!=="exact_optional"&&o.type!=="optional"&&o.type!=="nullish"){if(C(this,"key",n,s,{input:void 0,expected:`"${i}"`,path:[{type:"object",origin:"key",input:r,key:i,value:r[i]}]}),s.abortEarly)break}}}else C(this,"type",n,s);return n}}}function se(e,t){return{kind:"schema",type:"optional",reference:se,expects:`(${e.expects} | undefined)`,async:!1,wrapped:e,default:t,get "~standard"(){return F(this)},"~run"(n,s){if(n.value===void 0){if(this.default!==void 0)n.value=Ge(this,n,s);if(n.value===void 0)return n.typed=!0,n}return this.wrapped["~run"](n,s)}}}function re(e,t){return{kind:"schema",type:"picklist",reference:re,expects:bt(e.map(Ve),"|"),async:!1,options:e,message:t,get "~standard"(){return F(this)},"~run"(n,s){if(this.options.includes(n.value))n.typed=!0;else C(this,"type",n,s);return n}}}function qe(e,t){return{kind:"schema",type:"strict_object",reference:qe,expects:"Object",async:!1,entries:e,message:t,get "~standard"(){return F(this)},"~run"(n,s){let r=n.value;if(r&&typeof r==="object"){n.typed=!0,n.value={};for(let i in this.entries){let o=this.entries[i];if(i in r||(o.type==="exact_optional"||o.type==="optional"||o.type==="nullish")&&o.default!==void 0){let a=i in r?r[i]:Ge(o),u=o["~run"]({value:a},s);if(u.issues){let l={type:"object",origin:"value",input:r,key:i,value:a};for(let c of u.issues){if(c.path)c.path.unshift(l);else c.path=[l];n.issues?.push(c)}if(!n.issues)n.issues=u.issues;if(s.abortEarly){n.typed=!1;break}}if(!u.typed)n.typed=!1;n.value[i]=u.value}else if(o.fallback!==void 0)n.value[i]=wt(o);else if(o.type!=="exact_optional"&&o.type!=="optional"&&o.type!=="nullish"){if(C(this,"key",n,s,{input:void 0,expected:`"${i}"`,path:[{type:"object",origin:"key",input:r,key:i,value:r[i]}]}),s.abortEarly)break}}if(!n.issues||!s.abortEarly){for(let i in r)if(!(i in this.entries)){C(this,"key",n,s,{input:i,expected:"never",path:[{type:"object",origin:"key",input:r,key:i,value:r[i]}]});break}}}else C(this,"type",n,s);return n}}}function B(e){return{kind:"schema",type:"string",reference:B,expects:"string",async:!1,message:e,get "~standard"(){return F(this)},"~run"(t,n){if(typeof t.value==="string")t.typed=!0;else C(this,"type",t,n);return t}}}function kt(e){let t;if(e)for(let n of e)if(t)for(let s of n.issues)t.push(s);else t=n.issues;return t}function ie(e,t){return{kind:"schema",type:"union",reference:ie,expects:bt(e.map((n)=>n.expects),"|"),async:!1,options:e,message:t,get "~standard"(){return F(this)},"~run"(n,s){let r,i,o;for(let a of this.options){let u=a["~run"]({value:n.value},s);if(u.typed)if(u.issues)if(i)i.push(u);else i=[u];else{r=u;break}else if(o)o.push(u);else o=[u]}if(r)return r;if(i){if(i.length===1)return i[0];C(this,"type",n,s,{issues:kt(i)}),n.typed=!0}else if(o?.length===1)return o[0];else C(this,"type",n,s,{issues:kt(o)});return n}}}function me(e,t,n){let s=e["~run"]({value:t},$t(n));if(s.issues)throw new te(s.issues);return s.value}function Ue(e,t){let n={};for(let s in e.entries)n[s]=!t||t.includes(s)?se(e.entries[s]):e.entries[s];return{...e,entries:n,get "~standard"(){return F(this)}}}import{stdout as Je,stdin as Vt}from"process";import*as W from"readline";import ps from"readline";var xt=(()=>{let e=/[\uD800-\uDBFF][\uDC00-\uDFFF]/g;return(t)=>{let n=0;e.lastIndex=0;while(e.test(t))n+=1;return t.length-n}})(),Et=(e)=>e===12288||e>=65281&&e<=65376||e>=65504&&e<=65510,_t=(e)=>e===8987||e===9001||e>=12272&&e<=12287||e>=12289&&e<=12350||e>=12441&&e<=12543||e>=12549&&e<=12591||e>=12593&&e<=12686||e>=12688&&e<=12771||e>=12783&&e<=12830||e>=12832&&e<=12871||e>=12880&&e<=19903||e>=65040&&e<=65049||e>=65072&&e<=65106||e>=65108&&e<=65126||e>=65128&&e<=65131||e>=127488&&e<=127490||e>=127504&&e<=127547||e>=127552&&e<=127560||e>=131072&&e<=196605||e>=196608&&e<=262141;var Zn=/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]|\u001b\]8;[^;]*;.*?(?:\u0007|\u001b\u005c)/y,Yn=/[\x00-\x08\x0A-\x1F\x7F-\x9F]{1,1000}/y,It=/(?:(?![\uFF61-\uFF9F\uFF00-\uFFEF])[\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}\p{Script=Hangul}\p{Script=Tangut}]){1,1000}/yu,Qn=/\t{1,1000}/y,St=/[\u{1F1E6}-\u{1F1FF}]{2}|\u{1F3F4}[\u{E0061}-\u{E007A}]{2}[\u{E0030}-\u{E0039}\u{E0061}-\u{E007A}]{1,3}\u{E007F}|(?:\p{Emoji}\uFE0F\u20E3?|\p{Emoji_Modifier_Base}\p{Emoji_Modifier}?|\p{Emoji_Presentation})(?:\u200D(?:\p{Emoji_Modifier_Base}\p{Emoji_Modifier}?|\p{Emoji_Presentation}|\p{Emoji}\uFE0F\u20E3?))*/yu,es=/(?:[\x20-\x7E\xA0-\xFF](?!\uFE0F)){1,1000}/y,ts=/\p{M}+/gu,ns={limit:1/0,ellipsis:""},At=(e,t={},n={})=>{let s=t.limit??1/0,r=t.ellipsis??"",i=t?.ellipsisWidth??(r?At(r,ns,n).width:0),o=0,a=n.controlWidth??0,u=n.tabWidth??8,l=n.emojiWidth??2,c=2,f=n.regularWidth??1,h=n.wideWidth??2,v=[[es,f],[Zn,0],[Yn,a],[Qn,u],[St,l],[It,h]],m=0,d=0,j=e.length,L=0,q=!1,D=j,R=Math.max(0,s-i),I=0,Q=0,P=0,_=0;e:while(!0){if(Q>I||d>=j&&d>m){let U=e.slice(I,Q)||e.slice(m,d);L=0;for(let K of U.replaceAll(ts,"")){let S=K.codePointAt(0)||0;if(Et(S))_=2;else if(_t(S))_=h;else _=f;if(P+_>R)D=Math.min(D,Math.max(I,m)+L);if(P+_>s){q=!0;break e}L+=K.length,P+=_}I=Q=0}if(d>=j)break e;for(let U=0,K=v.length;U<K;U++){let[S,le]=v[U];if(S.lastIndex=d,S.test(e)){if(L=S===It?xt(e.slice(d,S.lastIndex)):S===St?1:S.lastIndex-d,_=L*le,P+_>R)D=Math.min(D,d+Math.floor((R-P)/le));if(P+_>s){q=!0;break e}P+=_,I=m,Q=d,d=m=S.lastIndex;continue e}}d+=1}return{width:q?R:P,index:q?D:j,truncated:q,ellipsed:q&&s>=i}},Ct=At;var ss={limit:1/0,ellipsis:"",ellipsisWidth:0},rs=(e,t={})=>Ct(e,ss,t).width,w=rs;var de="\x1B",Ft="\x9B",is=39,We="\x07",jt="[",us="]",Rt="m",He=`${us}8;;`,Mt=new RegExp(`(?:\\${jt}(?<code>\\d+)m|\\${He}(?<uri>.*)${We})`,"y"),Ot=(e)=>{if(e>=30&&e<=37)return 39;if(e>=90&&e<=97)return 39;if(e>=40&&e<=47)return 49;if(e>=100&&e<=107)return 49;if(e===1||e===2)return 22;if(e===3)return 23;if(e===4)return 24;if(e===7)return 27;if(e===8)return 28;if(e===9)return 29;if(e===0)return 0;return},Dt=(e)=>`${de}${jt}${e}${Rt}`,Pt=(e)=>`${de}${He}${e}${We}`,Be=(e,t,n)=>{let s=t[Symbol.iterator](),r=!1,i=!1,o=e.at(-1),a=o===void 0?0:w(o),u=s.next(),l=s.next(),c=0;while(!u.done){let f=u.value,h=w(f);if(a+h<=n)e[e.length-1]+=f;else e.push(f),a=0;if(f===de||f===Ft)r=!0,i=t.startsWith(He,c+1);if(r){if(i){if(f===We)r=!1,i=!1}else if(f===Rt)r=!1}else if(a+=h,a===n&&!l.done)e.push(""),a=0;u=l,l=s.next(),c+=f.length}if(o=e.at(-1),!a&&o!==void 0&&o.length&&e.length>1)e[e.length-2]+=e.pop()},os=(e)=>{let t=e.split(" "),n=t.length;while(n){if(w(t[n-1]))break;n--}if(n===t.length)return e;return t.slice(0,n).join(" ")+t.slice(n).join("")},as=(e,t,n={})=>{if(n.trim!==!1&&e.trim()==="")return"";let s="",r,i,o=e.split(" "),a=[""],u=0;for(let f=0;f<o.length;f++){let h=o[f];if(n.trim!==!1){let m=a.at(-1)??"",d=m.trimStart();if(m.length!==d.length)a[a.length-1]=d,u=w(d)}if(f!==0){if(u>=t&&(n.wordWrap===!1||n.trim===!1))a.push(""),u=0;if(u||n.trim===!1)a[a.length-1]+=" ",u++}let v=w(h);if(n.hard&&v>t){let m=t-u,d=1+Math.floor((v-m-1)/t);if(Math.floor((v-1)/t)<d)a.push("");Be(a,h,t),u=w(a.at(-1)??"");continue}if(u+v>t&&u&&v){if(n.wordWrap===!1&&u<t){Be(a,h,t),u=w(a.at(-1)??"");continue}a.push(""),u=0}if(u+v>t&&n.wordWrap===!1){Be(a,h,t),u=w(a.at(-1)??"");continue}a[a.length-1]+=h,u+=v}if(n.trim!==!1)a=a.map((f)=>os(f));let l=a.join(`
|
|
11
|
+
`),c=!1;for(let f=0;f<l.length;f++){let h=l[f];if(s+=h,!c){if(c=h>="\uD800"&&h<="\uDBFF",c)continue}else c=!1;if(h===de||h===Ft){Mt.lastIndex=f+1;let m=Mt.exec(l)?.groups;if(m?.code!==void 0){let d=Number.parseFloat(m.code);r=d===is?void 0:d}else if(m?.uri!==void 0)i=m.uri.length===0?void 0:m.uri}if(l[f+1]===`
|
|
12
|
+
`){if(i)s+=Pt("");let v=r?Ot(r):void 0;if(r&&v)s+=Dt(v)}else if(h===`
|
|
13
|
+
`){if(r&&Ot(r))s+=Dt(r);if(i)s+=Pt(i)}}return s},ls=/\r?\n/;function V(e,t,n){return String(e).normalize().split(ls).map((s)=>as(s,t,n)).join(`
|
|
14
|
+
`)}var b=ct(Ke(),1);import{ReadStream as Nt}from"tty";var hs=["up","down","left","right","space","enter","cancel"],ms=["January","February","March","April","May","June","July","August","September","October","November","December"],E={actions:new Set(hs),aliases:new Map([["k","up"],["j","down"],["h","left"],["l","right"],["\x03","cancel"],["escape","cancel"]]),messages:{cancel:"Canceled",error:"Something went wrong"},withGuide:!0,date:{monthNames:[...ms],messages:{required:"Please enter a valid date",invalidMonth:"There are only 12 months in a year",invalidDay:(e,t)=>`There are only ${e} days in ${t}`,afterMin:(e)=>`Date must be on or after ${e.toISOString().slice(0,10)}`,beforeMax:(e)=>`Date must be on or before ${e.toISOString().slice(0,10)}`}}};function Ze(e,t){if(typeof e=="string")return E.aliases.get(e)===t;for(let n of e)if(n!==void 0&&Ze(n,t))return!0;return!1}function ys(e,t){if(e===t)return;let n=e.split(`
|
|
15
15
|
`),s=t.split(`
|
|
16
|
-
`),r=Math.max(n.length,s.length),
|
|
17
|
-
`).map((a,
|
|
18
|
-
`)}function
|
|
19
|
-
`),
|
|
20
|
-
`).length-1;this.output.write(
|
|
21
|
-
`);this.output.write(o[
|
|
22
|
-
`).slice(
|
|
23
|
-
`)),this._prevFrame=e;return}}this.output.write(
|
|
16
|
+
`),r=Math.max(n.length,s.length),i=[];for(let o=0;o<r;o++)n[o]!==s[o]&&i.push(o);return{lines:i,numLinesBefore:n.length,numLinesAfter:s.length,numLines:r}}var ds=globalThis.process.platform.startsWith("win"),Xe=Symbol("clack:cancel");function ve(e){return e===Xe}function ge(e,t){let n=e;n.isTTY&&n.setRawMode(t)}function Gt({input:e=Vt,output:t=Je,overwrite:n=!0,hideCursor:s=!0}={}){let r=W.createInterface({input:e,output:t,prompt:"",tabSize:1});W.emitKeypressEvents(e,r),e instanceof Nt&&e.isTTY&&e.setRawMode(!0);let i=(o,{name:a,sequence:u})=>{let l=String(o);if(Ze([l,a,u],"cancel")){s&&t.write(b.cursor.show),process.exit(0);return}if(!n)return;W.moveCursor(t,a==="return"?0:-1,a==="return"?-1:0,()=>{W.clearLine(t,1,()=>{e.once("keypress",i)})})};return s&&t.write(b.cursor.hide),e.once("keypress",i),()=>{e.off("keypress",i),s&&t.write(b.cursor.show),e instanceof Nt&&e.isTTY&&!ds&&e.setRawMode(!1),r.terminal=!1,r.close()}}var ke=(e)=>("columns"in e)&&typeof e.columns=="number"?e.columns:80,Lt=(e)=>("rows"in e)&&typeof e.rows=="number"?e.rows:20;function qt(e,t,n,s=n,r=n,i){let o=ke(e??Je);return V(t,o-n.length,{hard:!0,trim:!1}).split(`
|
|
17
|
+
`).map((a,u,l)=>{let c=i?i(a,u):a;return u===0?`${s}${c}`:u===l.length-1?`${r}${c}`:`${n}${c}`}).join(`
|
|
18
|
+
`)}function Ut(e,t){if("~standard"in e){let n=e["~standard"].validate(t);if(n instanceof Promise)throw TypeError("Schema validation must be synchronous. Update `validate()` and remove any asynchronous logic.");return n.issues?.at(0)?.message}return e(t)}class Bt{input;output;_abortSignal;rl;opts;_render;_track=!1;_prevFrame="";_subscribers=new Map;_cursor=0;state="initial";error="";value;userInput="";constructor(e,t=!0){let{input:n=Vt,output:s=Je,render:r,signal:i,...o}=e;this.opts=o,this.onKeypress=this.onKeypress.bind(this),this.close=this.close.bind(this),this.render=this.render.bind(this),this._render=r.bind(this),this._track=t,this._abortSignal=i,this.input=n,this.output=s}unsubscribe(){this._subscribers.clear()}setSubscriber(e,t){let n=this._subscribers.get(e)??[];n.push(t),this._subscribers.set(e,n)}on(e,t){this.setSubscriber(e,{cb:t})}once(e,t){this.setSubscriber(e,{cb:t,once:!0})}emit(e,...t){let n=this._subscribers.get(e)??[],s=[];for(let r of n)r.cb(...t),r.once&&s.push(()=>n.splice(n.indexOf(r),1));for(let r of s)r()}prompt(){return new Promise((e)=>{if(this._abortSignal){if(this._abortSignal.aborted)return this.state="cancel",this.close(),e(Xe);this._abortSignal.addEventListener("abort",()=>{this.state="cancel",this.close()},{once:!0})}this.rl=ps.createInterface({input:this.input,tabSize:2,prompt:"",escapeCodeTimeout:50,terminal:!0}),this.rl.prompt(),this.opts.initialUserInput!==void 0&&this._setUserInput(this.opts.initialUserInput,!0),this.input.on("keypress",this.onKeypress),ge(this.input,!0),this.output.on("resize",this.render),this.render(),this.once("submit",()=>{this.output.write(b.cursor.show),this.output.off("resize",this.render),ge(this.input,!1),e(this.value)}),this.once("cancel",()=>{this.output.write(b.cursor.show),this.output.off("resize",this.render),ge(this.input,!1),e(Xe)})})}_isActionKey(e,t){return e==="\t"}_shouldSubmit(e,t){return!0}_setValue(e){this.value=e,this.emit("value",this.value)}_setUserInput(e,t){this.userInput=e??"",this.emit("userInput",this.userInput),t&&this._track&&this.rl&&(this.rl.write(this.userInput),this._cursor=this.rl.cursor)}_clearUserInput(){this.rl?.write(null,{ctrl:!0,name:"u"}),this._setUserInput("")}onKeypress(e,t){if(this._track&&t.name!=="return"&&(t.name&&this._isActionKey(e,t)&&this.rl?.write(null,{ctrl:!0,name:"h"}),this._cursor=this.rl?.cursor??0,this._setUserInput(this.rl?.line)),this.state==="error"&&(this.state="active"),t?.name&&(!this._track&&E.aliases.has(t.name)&&this.emit("cursor",E.aliases.get(t.name)),E.actions.has(t.name)&&this.emit("cursor",t.name)),e&&(e.toLowerCase()==="y"||e.toLowerCase()==="n")&&this.emit("confirm",e.toLowerCase()==="y"),this.emit("key",e,t),t?.name==="return"&&this._shouldSubmit(e,t)){if(this.opts.validate){let n=Ut(this.opts.validate,this.value);n&&(this.error=n instanceof Error?n.message:n,this.state="error",this.rl?.write(this.userInput))}this.state!=="error"&&(this.state="submit")}Ze([e,t?.name,t?.sequence],"cancel")&&(this.state="cancel"),(this.state==="submit"||this.state==="cancel")&&this.emit("finalize"),this.render(),(this.state==="submit"||this.state==="cancel")&&this.close()}close(){this.input.unpipe(),this.input.removeListener("keypress",this.onKeypress),this.output.write(`
|
|
19
|
+
`),ge(this.input,!1),this.rl?.close(),this.rl=void 0,this.emit(`${this.state}`,this.value),this.unsubscribe()}restoreCursor(){let e=V(this._prevFrame,process.stdout.columns,{hard:!0,trim:!1}).split(`
|
|
20
|
+
`).length-1;this.output.write(b.cursor.move(-999,e*-1))}render(){let e=V(this._render(this)??"",process.stdout.columns,{hard:!0,trim:!1});if(e!==this._prevFrame){if(this.state==="initial")this.output.write(b.cursor.hide);else{let t=ys(this._prevFrame,e),n=Lt(this.output);if(this.restoreCursor(),t){let s=Math.max(0,t.numLinesAfter-n),r=Math.max(0,t.numLinesBefore-n),i=t.lines.find((o)=>o>=s);if(i===void 0){this._prevFrame=e;return}if(t.lines.length===1){this.output.write(b.cursor.move(0,i-r)),this.output.write(b.erase.lines(1));let o=e.split(`
|
|
21
|
+
`);this.output.write(o[i]),this._prevFrame=e,this.output.write(b.cursor.move(0,o.length-i-1));return}else if(t.lines.length>1){if(s<r)i=s;else{let a=i-r;a>0&&this.output.write(b.cursor.move(0,a))}this.output.write(b.erase.down());let o=e.split(`
|
|
22
|
+
`).slice(i);this.output.write(o.join(`
|
|
23
|
+
`)),this._prevFrame=e;return}}this.output.write(b.erase.down())}this.output.write(e),this.state==="initial"&&(this.state="active"),this._prevFrame=e}}}class Ye extends Bt{get cursor(){return this.value?0:1}get _value(){return this.cursor===0}constructor(e){super(e,!1),this.value=!!e.initialValue,this.on("userInput",()=>{this.value=this._value}),this.on("confirm",(t)=>{this.output.write(b.cursor.move(0,-1)),this.value=t,this.state="submit",this.close()}),this.on("cursor",()=>{this.value=!this.value})}}import{styleText as p,stripVTControlCharacters as Kr}from"util";import M from"process";var ue=ct(Ke(),1);function gs(){if(M.platform!=="win32")return M.env.TERM!=="linux";return Boolean(M.env.CI)||Boolean(M.env.WT_SESSION)||Boolean(M.env.TERMINUS_SUBLIME)||M.env.ConEmuTask==="{cmd::Cmder}"||M.env.TERM_PROGRAM==="Terminus-Sublime"||M.env.TERM_PROGRAM==="vscode"||M.env.TERM==="xterm-256color"||M.env.TERM==="alacritty"||M.env.TERMINAL_EMULATOR==="JetBrains-JediTerm"}var Qe=gs(),vs=()=>process.env.CI==="true";var g=(e,t)=>Qe?e:t,ks=g("\u25C6","*"),Kt=g("\u25A0","x"),Xt=g("\u25B2","x"),$e=g("\u25C7","o"),$s=g("\u250C","T"),x=g("\u2502","|"),Jt=g("\u2514","\u2014"),Yr=g("\u2510","T"),Qr=g("\u2518","\u2014"),Wt=g("\u25CF",">"),Ht=g("\u25CB"," "),ei=g("\u25FB","[\u2022]"),ti=g("\u25FC","[+]"),ni=g("\u25FB","[ ]"),si=g("\u25AA","\u2022"),zt=g("\u2500","-"),bs=g("\u256E","+"),ws=g("\u251C","+"),xs=g("\u256F","+"),Es=g("\u2570","+"),ri=g("\u256D","+"),_s=g("\u25CF","\u2022"),Is=g("\u25C6","*"),Ss=g("\u25B2","!"),As=g("\u25A0","x"),Cs=(e)=>{switch(e){case"initial":case"active":return p("cyan",ks);case"cancel":return p("red",Kt);case"error":return p("yellow",Xt);case"submit":return p("green",$e)}};var Zt=(e)=>{let t=e.active??"Yes",n=e.inactive??"No";return new Ye({active:t,inactive:n,signal:e.signal,input:e.input,output:e.output,initialValue:e.initialValue??!0,render(){let s=e.withGuide??E.withGuide,r=`${Cs(this.state)} `,i=s?`${p("gray",x)} `:"",o=qt(e.output,e.message,i,r),a=`${s?`${p("gray",x)}
|
|
24
24
|
`:""}${o}
|
|
25
|
-
`,
|
|
26
|
-
${p("gray",x)}`:""}`}default:{let l=s?`${p("cyan",x)} `:"",c=s?p("cyan",
|
|
25
|
+
`,u=this.value?t:n;switch(this.state){case"submit":{let l=s?`${p("gray",x)} `:"";return`${a}${l}${p("dim",u)}`}case"cancel":{let l=s?`${p("gray",x)} `:"";return`${a}${l}${p(["strikethrough","dim"],u)}${s?`
|
|
26
|
+
${p("gray",x)}`:""}`}default:{let l=s?`${p("cyan",x)} `:"",c=s?p("cyan",Jt):"";return`${a}${l}${this.value?`${p("green",Wt)} ${t}`:`${p("dim",Ht)} ${p("dim",t)}`}${e.vertical?s?`
|
|
27
27
|
${p("cyan",x)} `:`
|
|
28
|
-
`:` ${p("dim","/")} `}${this.value?`${p("dim",
|
|
28
|
+
`:` ${p("dim","/")} `}${this.value?`${p("dim",Ht)} ${p("dim",n)}`:`${p("green",Wt)} ${n}`}
|
|
29
29
|
${c}
|
|
30
|
-
`}}}}).prompt()};var
|
|
31
|
-
`);if(f.length>0){let[h,...
|
|
30
|
+
`}}}}).prompt()};var ii=[`${p("dim","\u2191/\u2193")} to navigate`,`${p("dim","Space:")} select`,`${p("dim","Enter:")} confirm`];var y={message:(e=[],{symbol:t=p("gray",x),secondarySymbol:n=p("gray",x),output:s=process.stdout,spacing:r=1,withGuide:i}={})=>{let o=[],a=i??E.withGuide,u=a?n:"",l=a?`${t} `:"",c=a?`${n} `:"";for(let h=0;h<r;h++)o.push(u);let f=Array.isArray(e)?e:e.split(`
|
|
31
|
+
`);if(f.length>0){let[h,...v]=f;h.length>0?o.push(`${l}${h}`):o.push(a?t:"");for(let m of v)m.length>0?o.push(`${c}${m}`):o.push(a?n:"")}s.write(`${o.join(`
|
|
32
32
|
`)}
|
|
33
|
-
`)},info:(e,t)=>{
|
|
34
|
-
`)},
|
|
35
|
-
${p("gray",
|
|
33
|
+
`)},info:(e,t)=>{y.message(e,{...t,symbol:p("blue",_s)})},success:(e,t)=>{y.message(e,{...t,symbol:p("green",Is)})},step:(e,t)=>{y.message(e,{...t,symbol:p("green",$e)})},warn:(e,t)=>{y.message(e,{...t,symbol:p("yellow",Ss)})},warning:(e,t)=>{y.warn(e,t)},error:(e,t)=>{y.message(e,{...t,symbol:p("red",As)})}};var be=(e="",t)=>{let n=t?.output??process.stdout,s=t?.withGuide??E.withGuide?`${p("gray",$s)} `:"";n.write(`${s}${e}
|
|
34
|
+
`)},Yt=(e="",t)=>{let n=t?.output??process.stdout,s=t?.withGuide??E.withGuide?`${p("gray",x)}
|
|
35
|
+
${p("gray",Jt)} `:"";n.write(`${s}${e}
|
|
36
36
|
|
|
37
|
-
`)};var
|
|
38
|
-
`),
|
|
39
|
-
`).map(
|
|
37
|
+
`)};var Ms=(e)=>e,Os=(e,t,n)=>{let s={hard:!0,trim:!1},r=V(e,t,s).split(`
|
|
38
|
+
`),i=r.reduce((u,l)=>Math.max(w(l),u),0),o=r.map(n).reduce((u,l)=>Math.max(w(l),u),0),a=t-(o-i);return V(e,a,s)},we=(e="",t="",n)=>{let s=n?.output??M.stdout,r=n?.withGuide??E.withGuide,i=n?.format??Ms,o=["",...Os(e,ke(s)-6,i).split(`
|
|
39
|
+
`).map(i),""],a=w(t),u=Math.max(o.reduce((h,v)=>{let m=w(v);return m>h?m:h},0),a)+2,l=o.map((h)=>`${p("gray",x)} ${h}${" ".repeat(u-w(h))}${p("gray",x)}`).join(`
|
|
40
40
|
`),c=r?`${p("gray",x)}
|
|
41
|
-
`:"",f=r?
|
|
41
|
+
`:"",f=r?ws:Es;s.write(`${c}${p("green",$e)} ${p("reset",t)} ${p("gray",zt.repeat(Math.max(u-a-1,1))+bs)}
|
|
42
42
|
${l}
|
|
43
|
-
${p("gray",f+
|
|
44
|
-
`)};var
|
|
45
|
-
`);let
|
|
46
|
-
`);
|
|
47
|
-
`);let
|
|
48
|
-
`):n.write(`${
|
|
49
|
-
`)),
|
|
50
|
-
`),"System Environment",{withGuide:!0}),Ht("Scan completed"),t}import Jt from"path";import{homedir as Zt}from"os";function we(e){if(e.startsWith("~"))return Jt.join(Zt(),e.slice(1));return Jt.resolve(e)}function Je(){return Zt()}var As=Pe(W({flatpak:Q(),backup:Q(),aur_helper:te(["yay","paru"])})),Os=W({source:D(),target:D(),sudo:ee(Q())}),Ms=te(["aur","pacman"]),Ds=ne([D(),V(D()),V(V(D()))]),Fs=W({name:D(),post_hooks:ee(Ds)}),Yt=V(ne([D(),Fs])),js=W({manager:Ms,items:Yt}),Ts=W({manager:Re("flatpak"),scope:te(["system","user"]),items:Yt}),xe=Pe(W({imports:V(D()),settings:As,packages:V(ne([Ts,js])),symlinks:V(Os)}));import Ee from"path";var z={defaultMerge:Symbol("deepmerge-ts: default merge"),skip:Symbol("deepmerge-ts: skip")},pi={defaultMerge:z.defaultMerge};function Rs(e,t){return t}function Ps(e,t){return e.filter((n)=>n!==void 0)}var Qt;(function(e){e[e.NOT=0]="NOT",e[e.RECORD=1]="RECORD",e[e.ARRAY=2]="ARRAY",e[e.SET=3]="SET",e[e.MAP=4]="MAP",e[e.OTHER=5]="OTHER"})(Qt||(Qt={}));function en(e){if(typeof e!=="object"||e===null)return 0;if(Array.isArray(e))return 2;if(Ls(e))return 1;if(e instanceof Set)return 3;if(e instanceof Map)return 4;return 5}function Ns(e){let t=new Set;for(let n of e)for(let s of[...Object.keys(n),...Object.getOwnPropertySymbols(n)])t.add(s);return t}function Vs(e,t){return typeof e==="object"&&Object.prototype.propertyIsEnumerable.call(e,t)}function nn(e){let t=0,n=e[0]?.[Symbol.iterator]();return{[Symbol.iterator](){return{next(){do{if(n===void 0)return{done:!0,value:void 0};let s=n.next();if(s.done===!0){t+=1,n=e[t]?.[Symbol.iterator]();continue}return{done:!1,value:s.value}}while(!0)}}}}}var tn=["[object Object]","[object Module]"];function Ls(e){if(!tn.includes(Object.prototype.toString.call(e)))return!1;let{constructor:t}=e;if(t===void 0)return!0;let n=t.prototype;if(n===null||typeof n!=="object"||!tn.includes(Object.prototype.toString.call(n)))return!1;if(!n.hasOwnProperty("isPrototypeOf"))return!1;return!0}function Gs(e,t,n){let s={};for(let r of Ns(e)){let u=[];for(let i of e)if(Vs(i,r))u.push(i[r]);if(u.length===0)continue;let o=t.metaDataUpdater(n,{key:r,parents:e}),a=sn(u,t,o);if(a===z.skip)continue;if(r==="__proto__")Object.defineProperty(s,r,{value:a,configurable:!0,enumerable:!0,writable:!0});else s[r]=a}return s}function qs(e){return e.flat()}function Us(e){return new Set(nn(e))}function Bs(e){return new Map(nn(e))}function Ws(e){return e.at(-1)}var _e={mergeRecords:Gs,mergeArrays:qs,mergeSets:Us,mergeMaps:Bs,mergeOthers:Ws};function ie(...e){return Hs({})(...e)}function Hs(e,t){let n=zs(e,s);function s(...r){return sn(r,n,t)}return s}function zs(e,t){return{defaultMergeFunctions:_e,mergeFunctions:{..._e,...Object.fromEntries(Object.entries(e).filter(([n,s])=>Object.hasOwn(_e,n)).map(([n,s])=>s===!1?[n,_e.mergeOthers]:[n,s]))},metaDataUpdater:e.metaDataUpdater??Rs,deepmerge:t,useImplicitDefaultMerging:e.enableImplicitDefaultMerging??!1,filterValues:e.filterValues===!1?void 0:e.filterValues??Ps,actions:z}}function sn(e,t,n){let s=t.filterValues?.(e,n)??e;if(s.length===0)return;if(s.length===1)return Ze(s,t,n);let r=en(s[0]);if(r!==0&&r!==5)for(let u=1;u<s.length;u++){if(en(s[u])===r)continue;return Ze(s,t,n)}switch(r){case 1:return Ks(s,t,n);case 2:return Xs(s,t,n);case 3:return Js(s,t,n);case 4:return Zs(s,t,n);default:return Ze(s,t,n)}}function Ks(e,t,n){let s=t.mergeFunctions.mergeRecords(e,t,n);if(s===z.defaultMerge||t.useImplicitDefaultMerging&&s===void 0&&t.mergeFunctions.mergeRecords!==t.defaultMergeFunctions.mergeRecords)return t.defaultMergeFunctions.mergeRecords(e,t,n);return s}function Xs(e,t,n){let s=t.mergeFunctions.mergeArrays(e,t,n);if(s===z.defaultMerge||t.useImplicitDefaultMerging&&s===void 0&&t.mergeFunctions.mergeArrays!==t.defaultMergeFunctions.mergeArrays)return t.defaultMergeFunctions.mergeArrays(e);return s}function Js(e,t,n){let s=t.mergeFunctions.mergeSets(e,t,n);if(s===z.defaultMerge||t.useImplicitDefaultMerging&&s===void 0&&t.mergeFunctions.mergeSets!==t.defaultMergeFunctions.mergeSets)return t.defaultMergeFunctions.mergeSets(e);return s}function Zs(e,t,n){let s=t.mergeFunctions.mergeMaps(e,t,n);if(s===z.defaultMerge||t.useImplicitDefaultMerging&&s===void 0&&t.mergeFunctions.mergeMaps!==t.defaultMergeFunctions.mergeMaps)return t.defaultMergeFunctions.mergeMaps(e);return s}function Ze(e,t,n){let s=t.mergeFunctions.mergeOthers(e,t,n);if(s===z.defaultMerge||t.useImplicitDefaultMerging&&s===void 0&&t.mergeFunctions.mergeOthers!==t.defaultMergeFunctions.mergeOthers)return t.defaultMergeFunctions.mergeOthers(e);return s}async function Ye(e,t=new Set){let n=Ee.resolve(e);if(t.has(n))throw Error(`Circular dependency detected: ${n}`);t.add(n);let s=await Bun.file(n).text(),r=Bun.TOML.parse(s),u=fe(xe,r),{imports:o=[],symlinks:a=[]}=u;delete u.imports;let i=Ee.dirname(n);u.symlinks=Ys(i,a);let l={};for(let c of o){let f=Ee.resolve(i,c),h=await Ye(f,t);l=ie(l,h)}return ie(u,l)}function Ys(e,t){if(!t||t.length===0)return[];let n=[];for(let s of t){if(!s)continue;let{source:r,target:u}=s,o=Ee.resolve(e,r),a=we(u);n.push({source:o,target:a})}return n}async function Ie(e){let t=we(e);v.step("Validating Configuration");let n=be();n.start("Validating...");let s=await Ye(t),r=fe(xe,s);return n.stop("Successfully validated with no errors!"),r}import nr from"path";var{deepEquals:Qs}=globalThis.Bun;import er from"fs/promises";import Se from"path";import Qe from"fs/promises";var Ce={};function Ae(){return Ce}function rn(e,t){Ce[e]=t}async function un(){let e=Se.resolve(Je(),".cache/hofii"),t=Se.resolve(e,"hofii-lock.json");if(await Qe.exists(t)){let n=await Bun.file(t).json();Object.assign(Ce,n.config)}}async function on(){let e=Se.resolve(Je(),".cache/hofii");if(!await Qe.exists(e))await Qe.mkdir(e,{recursive:!0});let t={config:Ce};await Bun.write(Se.resolve(e,"hofii-lock.json"),JSON.stringify(t,null,2))}import Me from"fs/promises";async function Oe({cmd:e,errMsg:t,opt:n={stdin:"inherit",stdout:"inherit",stderr:"inherit"}}){let s=Bun.spawn(e,{stdin:n.stdin,stdout:n.stdout,stderr:n.stderr}),r=n.stdout==="pipe"?new Response(s.stdout).text():void 0,u=n.stderr==="pipe"?new Response(s.stderr).text():void 0,o=s.exited,[a,i,l]=await Promise.all([r,u,o]);if(l!==0)throw Error(t??`Error caused with exit code ${l}`);return{stdout:a,stderr:i,exitCode:l}}async function et(e,t,n=!1){if(n){if(Z("platform")!=="linux"){v.warn("Sudo only support in Linux");return}await Oe({cmd:["sudo","ln","-s",e,t],errMsg:`Failed create symlink ${e+" -> "+t}`})}else await Me.symlink(e,t)}async function tt(e,t=!1){if(t){if(Z("platform")!=="linux"){v.warn("Sudo only support in Linux");return}await Oe({cmd:["sudo","rm",e],errMsg:`Failed remove symlink ${e}`})}else await Me.unlink(e)}async function nt(e){try{return await Me.lstat(e)}catch(t){return null}}async function an({oldPath:e,newPath:t,sudo:n=!1}){if(n){if(Z("platform")!=="linux"){v.warn("Sudo only support in Linux");return}await Oe({cmd:["sudo","mv",e,t],errMsg:`Failed rename file ${e+" -> "+t}`})}else await Me.rename(e,t)}async function fn(e){if(!e)return;let t=Z("settings")?.backup??!0,{added:n=[],removed:s=[]}=e,r=[],u=[];try{let o=cn(await Promise.allSettled(s.map(async(i)=>{let l=await nt(i.target);if(!l){v.warn(`Target doesn't exist: ${i.target}, did you remove it manually?`),u.push(i);return}if(!l.isSymbolicLink()){v.warn(`${i.target} not a symlink, did you remove it manually?`),u.push(i);return}await tt(i.target,i.sudo),u.push(i),v.success(`Succesfully remove symlink ${i.target}`)}))),a=cn(await Promise.allSettled(n.map(async(i)=>{let l=await nt(i.target);if(l){if(l.isSymbolicLink()){let c=await er.readlink(i.target);if(c===i.source){await tt(i.target,i.sudo),await et(i.source,i.target,i.sudo),r.push(i),v.warn(`Recreate ${c} -> ${i.target}`);return}}if(t)await an({oldPath:i.target,newPath:i.target+".bak",sudo:i.sudo});else{v.error(`Target already exists, skip create: ${i.target}`);return}}await et(i.source,i.target,i.sudo),r.push(i),v.success(`Succesfully create symlink ${i.source} -> ${i.target}`)})));for(let i of a)console.error(`Failed to add symlink: ${ln(i)}`);for(let i of o)console.error(`Failed to remove symlink: ${ln(i)}`);if(a.length>0||o.length>0)v.error(" [FATAL] Error caused while applying symlinks"),process.exitCode=1}catch(o){console.error(o),v.error(" [FATAL] Failed to apply symlinks"),process.exitCode=1}finally{let i=((Ae()??{}).symlinks??[]).filter((l)=>!u.some((c)=>Qs(c,l))).concat(r);v.info(`Updated symlinks state: ${i.length}`),rn("symlinks",i)}}function ln(e){if(e instanceof Error)return`[${"code"in e?String(e.code):"ERROR"}] ${e.message}`;return`[ERROR] ${String(e)}`}function cn(e){return e.filter((t)=>t.status==="rejected")}var{deepEquals:pn}=globalThis.Bun;function tr(e,t){let n=t?.filter((r)=>!e?.some((u)=>pn(r,u,!0)))??[],s=e?.filter((r)=>!t?.some((u)=>pn(r,u,!0)))??[];return{added:n,removed:s}}function hn(e){let t=Ae();return{symlinks:tr(t.symlinks,e.symlinks)}}function mn(e){let{symlinks:t}=e;return[(()=>{let s=["SYMLINKS"],{added:r=[],removed:u=[]}=t;if(r?.length===0&&u?.length===0)return s.push(" - No changes to apply with symlinks"),s.join(`
|
|
51
|
-
`);for(let
|
|
52
|
-
`)})()
|
|
43
|
+
${p("gray",f+zt.repeat(u+2)+xs)}
|
|
44
|
+
`)};var Ds=(e)=>p("magenta",e),xe=({indicator:e="dots",onCancel:t,output:n=process.stdout,cancelMessage:s,errorMessage:r,frames:i=Qe?["\u25D2","\u25D0","\u25D3","\u25D1"]:["\u2022","o","O","0"],delay:o=Qe?80:120,signal:a,...u}={})=>{let l=vs(),c,f,h=!1,v=!1,m="",d,j=performance.now(),L=ke(n),q=u?.styleFrame??Ds,D=(k)=>{let A=k>1?r??E.messages.error:s??E.messages.cancel;v=k===1,h&&(ee(A,k),v&&typeof t=="function"&&t())},R=()=>D(2),I=()=>D(1),Q=()=>{process.on("uncaughtExceptionMonitor",R),process.on("unhandledRejection",R),process.on("SIGINT",I),process.on("SIGTERM",I),process.on("exit",D),a&&a.addEventListener("abort",I)},P=()=>{process.removeListener("uncaughtExceptionMonitor",R),process.removeListener("unhandledRejection",R),process.removeListener("SIGINT",I),process.removeListener("SIGTERM",I),process.removeListener("exit",D),a&&a.removeEventListener("abort",I)},_=()=>{if(d===void 0)return;l&&n.write(`
|
|
45
|
+
`);let k=V(d,L,{hard:!0,trim:!1}).split(`
|
|
46
|
+
`);k.length>1&&n.write(ue.cursor.up(k.length-1)),n.write(ue.cursor.to(0)),n.write(ue.erase.down())},U=(k)=>k.replace(/\.+$/,""),K=(k)=>{let A=(performance.now()-k)/1000,T=Math.floor(A/60),N=Math.floor(A%60);return T>0?`[${T}m ${N}s]`:`[${N}s]`},S=u.withGuide??E.withGuide,le=(k="")=>{h=!0,c=Gt({output:n}),m=U(k),j=performance.now(),S&&n.write(`${p("gray",x)}
|
|
47
|
+
`);let A=0,T=0;Q(),f=setInterval(()=>{if(l&&m===d)return;_(),d=m;let N=q(i[A]),ce;if(l)ce=`${N} ${m}...`;else if(e==="timer")ce=`${N} ${m} ${K(j)}`;else{let In=".".repeat(Math.floor(T)).slice(0,3);ce=`${N} ${m}${In}`}let _n=V(ce,L,{hard:!0,trim:!1});n.write(_n),A=A+1<i.length?A+1:0,T=T<4?T+0.125:0},o)},ee=(k="",A=0,T=!1)=>{if(!h)return;h=!1,clearInterval(f),_();let N=A===0?p("green",$e):A===1?p("red",Kt):p("red",Xt);m=k??m,T||(e==="timer"?n.write(`${N} ${m} ${K(j)}
|
|
48
|
+
`):n.write(`${N} ${m}
|
|
49
|
+
`)),P(),c()};return{start:le,stop:(k="")=>ee(k,0),message:(k="")=>{m=U(k??m)},cancel:(k="")=>ee(k,1),error:(k="")=>ee(k,2),clear:()=>ee("",0,!0),get isCancelled(){return v}}},ui={light:g("\u2500","-"),heavy:g("\u2501","="),block:g("\u2588","#")};var oi=[`${p("dim","\u2191/\u2193")} to navigate`,`${p("dim","Enter:")} confirm`];var ai=`${p("gray",x)} `;var{$:et}=globalThis.Bun;var Ps={pacman:["arch","endeavouros","manjaro","garuda","cachyos","arcolinux","rebornos","blendos","steamos","chimeraos"],dnf:["fedora","nobara","bazzite","ultramarine"]},Qt=(e)=>{for(let[t,n]of Object.entries(Ps))if(n.includes(e))return t;return null};var en={osName:void 0,osId:void 0,platform:"linux",packageManager:void 0,helperAur:null,isFlatpak:!1,flatpak:!1};function H(e){return en[e]}function G(e,t){en[e]=t}async function tt(e){try{return await et`which ${e}`.quiet(),!0}catch{return!1}}async function Fs(){let e=[];if(await tt("yay"))e.push("yay");if(await tt("paru"))e.push("paru");return e}async function js(){if(process.platform==="linux"){let e=await et`cat /etc/os-release | grep ^NAME`.quiet().text()||"",t=await et`cat /etc/os-release | grep ^ID`.quiet().text()||"",n=e.trim().slice(5).replace(/"/g,"");return{id:t.trim().slice(3).replace(/"/g,""),name:n}}return{id:"unknown",name:"unknown"}}async function Ee(){let{name:e="",id:t=""}=await js(),n=Qt(t),s=n==="pacman"?await Fs():null,r=await tt("flatpak");if(G("osName",e),G("osId",t),G("flatpak",r),s)G("helperAur",s[0]);if(n)G("packageManager",n);return{osName:e,osId:t,packageManager:n,aurHelper:s,flatpak:r}}async function tn(){be("\uD83D\uDD0D Scanning system");let e=xe();e.start("Detecting environment...");let t=await Ee();return e.stop("Environment detected"),we([`OS ${t.osName} (${t.osId})`,`Package Manager ${t.packageManager}`,t.aurHelper?`AUR Helper ${t.aurHelper}`:null,`Flatpak ${t.flatpak?"Enabled":"Disabled"}`].filter(Boolean).join(`
|
|
50
|
+
`),"System Environment",{withGuide:!0}),Yt("Scan completed"),t}import nn from"path";import{homedir as sn}from"os";function _e(e){if(e.startsWith("~"))return nn.join(sn(),e.slice(1));return nn.resolve(e)}function nt(){return sn()}var Rs=Ue(J({flatpak:ne(),backup:ne(),aur_helper:re(["yay","paru"])})),Ts=J({source:B(),target:B(),sudo:se(ne())}),Ns=re(["aur","pacman"]),Vs=ie([X(B())]),Gs=J({name:B(),post_hooks:se(Vs)}),rn=X(ie([B(),Gs])),Ls=J({manager:Ns,items:rn}),qs=J({manager:Le("flatpak"),scope:re(["system","user"]),items:rn}),Ie=Ue(qe({imports:X(B()),settings:Rs,packages:X(ie([qs,Ls])),symlinks:X(Ts)}));import Ae from"path";var z={defaultMerge:Symbol("deepmerge-ts: default merge"),skip:Symbol("deepmerge-ts: skip")},xi={defaultMerge:z.defaultMerge};function Us(e,t){return t}function Bs(e,t){return e.filter((n)=>n!==void 0)}var un;(function(e){e[e.NOT=0]="NOT",e[e.RECORD=1]="RECORD",e[e.ARRAY=2]="ARRAY",e[e.SET=3]="SET",e[e.MAP=4]="MAP",e[e.OTHER=5]="OTHER"})(un||(un={}));function on(e){if(typeof e!=="object"||e===null)return 0;if(Array.isArray(e))return 2;if(zs(e))return 1;if(e instanceof Set)return 3;if(e instanceof Map)return 4;return 5}function Ws(e){let t=new Set;for(let n of e)for(let s of[...Object.keys(n),...Object.getOwnPropertySymbols(n)])t.add(s);return t}function Hs(e,t){return typeof e==="object"&&Object.prototype.propertyIsEnumerable.call(e,t)}function ln(e){let t=0,n=e[0]?.[Symbol.iterator]();return{[Symbol.iterator](){return{next(){do{if(n===void 0)return{done:!0,value:void 0};let s=n.next();if(s.done===!0){t+=1,n=e[t]?.[Symbol.iterator]();continue}return{done:!1,value:s.value}}while(!0)}}}}}var an=["[object Object]","[object Module]"];function zs(e){if(!an.includes(Object.prototype.toString.call(e)))return!1;let{constructor:t}=e;if(t===void 0)return!0;let n=t.prototype;if(n===null||typeof n!=="object"||!an.includes(Object.prototype.toString.call(n)))return!1;if(!n.hasOwnProperty("isPrototypeOf"))return!1;return!0}function Ks(e,t,n){let s={};for(let r of Ws(e)){let i=[];for(let u of e)if(Hs(u,r))i.push(u[r]);if(i.length===0)continue;let o=t.metaDataUpdater(n,{key:r,parents:e}),a=cn(i,t,o);if(a===z.skip)continue;if(r==="__proto__")Object.defineProperty(s,r,{value:a,configurable:!0,enumerable:!0,writable:!0});else s[r]=a}return s}function Xs(e){return e.flat()}function Js(e){return new Set(ln(e))}function Zs(e){return new Map(ln(e))}function Ys(e){return e.at(-1)}var Se={mergeRecords:Ks,mergeArrays:Xs,mergeSets:Js,mergeMaps:Zs,mergeOthers:Ys};function oe(...e){return Qs({})(...e)}function Qs(e,t){let n=er(e,s);function s(...r){return cn(r,n,t)}return s}function er(e,t){return{defaultMergeFunctions:Se,mergeFunctions:{...Se,...Object.fromEntries(Object.entries(e).filter(([n,s])=>Object.hasOwn(Se,n)).map(([n,s])=>s===!1?[n,Se.mergeOthers]:[n,s]))},metaDataUpdater:e.metaDataUpdater??Us,deepmerge:t,useImplicitDefaultMerging:e.enableImplicitDefaultMerging??!1,filterValues:e.filterValues===!1?void 0:e.filterValues??Bs,actions:z}}function cn(e,t,n){let s=t.filterValues?.(e,n)??e;if(s.length===0)return;if(s.length===1)return st(s,t,n);let r=on(s[0]);if(r!==0&&r!==5)for(let i=1;i<s.length;i++){if(on(s[i])===r)continue;return st(s,t,n)}switch(r){case 1:return tr(s,t,n);case 2:return nr(s,t,n);case 3:return sr(s,t,n);case 4:return rr(s,t,n);default:return st(s,t,n)}}function tr(e,t,n){let s=t.mergeFunctions.mergeRecords(e,t,n);if(s===z.defaultMerge||t.useImplicitDefaultMerging&&s===void 0&&t.mergeFunctions.mergeRecords!==t.defaultMergeFunctions.mergeRecords)return t.defaultMergeFunctions.mergeRecords(e,t,n);return s}function nr(e,t,n){let s=t.mergeFunctions.mergeArrays(e,t,n);if(s===z.defaultMerge||t.useImplicitDefaultMerging&&s===void 0&&t.mergeFunctions.mergeArrays!==t.defaultMergeFunctions.mergeArrays)return t.defaultMergeFunctions.mergeArrays(e);return s}function sr(e,t,n){let s=t.mergeFunctions.mergeSets(e,t,n);if(s===z.defaultMerge||t.useImplicitDefaultMerging&&s===void 0&&t.mergeFunctions.mergeSets!==t.defaultMergeFunctions.mergeSets)return t.defaultMergeFunctions.mergeSets(e);return s}function rr(e,t,n){let s=t.mergeFunctions.mergeMaps(e,t,n);if(s===z.defaultMerge||t.useImplicitDefaultMerging&&s===void 0&&t.mergeFunctions.mergeMaps!==t.defaultMergeFunctions.mergeMaps)return t.defaultMergeFunctions.mergeMaps(e);return s}function st(e,t,n){let s=t.mergeFunctions.mergeOthers(e,t,n);if(s===z.defaultMerge||t.useImplicitDefaultMerging&&s===void 0&&t.mergeFunctions.mergeOthers!==t.defaultMergeFunctions.mergeOthers)return t.defaultMergeFunctions.mergeOthers(e);return s}async function rt(e,t=new Set){let n=Ae.resolve(e);if(t.has(n))throw Error(`Circular dependency detected: ${n}`);t.add(n);let s=await Bun.file(n).text(),r=Bun.TOML.parse(s),i;try{i=me(Ie,r)}catch(c){if(c instanceof te)y.error(c.issues[0].message);process.exit(1)}let{imports:o=[],symlinks:a=[]}=i;delete i.imports;let u=Ae.dirname(n);i.symlinks=ir(u,a);let l={};for(let c of o){let f=Ae.resolve(u,c),h=await rt(f,t);l=oe(l,h)}return oe(i,l)}function ir(e,t){if(!t||t.length===0)return[];let n=[];for(let s of t){if(!s)continue;let{source:r,target:i}=s,o=Ae.resolve(e,r),a=_e(i);n.push({source:o,target:a})}return n}async function Ce(e){let t,n=_e(e);y.step("Validating Configuration");let s=xe();s.start("Validating...");try{let r=await rt(n);t=me(Ie,r)}catch(r){y.error(r instanceof Error?r.message:String(r)),s.stop("Validation failed");return}return s.stop("Successfully validated with no errors!"),t}import hr from"path";var{deepEquals:ur}=globalThis.Bun;import or from"fs/promises";import Me from"fs/promises";async function O({cmd:e,errMsg:t,opt:n={stdin:"inherit",stdout:"inherit",stderr:"inherit"}}){let s=Bun.spawn(e,{stdin:n.stdin,stdout:n.stdout,stderr:n.stderr}),r=n.stdout==="pipe"?new Response(s.stdout).text():void 0,i=n.stderr==="pipe"?new Response(s.stderr).text():void 0,o=s.exited,[a,u,l]=await Promise.all([r,i,o]);if(l!==0)throw Error(t??`Error caused with exit code ${l}`);return{stdout:a,stderr:u,exitCode:l}}async function it(e,t,n=!1){if(n){if(H("platform")!=="linux"){y.warn("Sudo only support in Linux");return}await O({cmd:["sudo","ln","-s",e,t],errMsg:`Failed create symlink ${e+" -> "+t}`})}else await Me.symlink(e,t)}async function ut(e,t=!1){if(t){if(H("platform")!=="linux"){y.warn("Sudo only support in Linux");return}await O({cmd:["sudo","rm",e],errMsg:`Failed remove symlink ${e}`})}else await Me.unlink(e)}async function Oe(e){try{return await Me.lstat(e)}catch(t){return null}}async function fn({oldPath:e,newPath:t,sudo:n=!1}){if(!await Oe(t))return;if(n){if(H("platform")!=="linux"){y.warn("Sudo only support in Linux");return}await O({cmd:["sudo","mv",e,t],errMsg:`Failed rename file ${e+" -> "+t}`})}else await Me.rename(e,t)}import De from"path";import ot from"fs/promises";var Pe={};function Fe(){return Pe}function je(e,t){Pe[e]=t}async function pn(){let e=De.resolve(nt(),".cache/hofii"),t=De.resolve(e,"hofii-lock.json");if(await ot.exists(t)){let n=await Bun.file(t).json();Object.assign(Pe,n.config)}}async function hn(){let e=De.resolve(nt(),".cache/hofii");if(!await ot.exists(e))await ot.mkdir(e,{recursive:!0});let t={config:Pe};await Bun.write(De.resolve(e,"hofii-lock.json"),JSON.stringify(t,null,2))}async function dn(e){if(!e)return;let t=H("settings")?.backup??!0,{added:n=[],removed:s=[]}=e,r=[],i=[];try{let o=yn(await Promise.allSettled(s.map(async(u)=>{let l=await Oe(u.target);if(!l){y.warn(`Target doesn't exist: ${u.target}, did you remove it manually?`),i.push(u);return}if(!l.isSymbolicLink()){y.warn(`${u.target} not a symlink, did you remove it manually?`),i.push(u);return}await ut(u.target,u.sudo),i.push(u),y.success(`Succesfully remove symlink ${u.target}`)}))),a=yn(await Promise.allSettled(n.map(async(u)=>{let l=await Oe(u.target);if(l){if(l.isSymbolicLink()){let c=await or.readlink(u.target);if(c===u.source){await ut(u.target,u.sudo),await it(u.source,u.target,u.sudo),r.push(u),y.warn(`Recreate ${c} -> ${u.target}`);return}}if(t)await fn({oldPath:u.target,newPath:u.target+".bak",sudo:u.sudo});else{y.error(`Target already exists, skip create: ${u.target}`);return}}await it(u.source,u.target,u.sudo),r.push(u),y.success(`Succesfully create symlink ${u.source} -> ${u.target}`)})));for(let u of a)console.error(`Failed to add symlink: ${mn(u)}`);for(let u of o)console.error(`Failed to remove symlink: ${mn(u)}`);if(a.length>0||o.length>0)y.error(" [FATAL] Error caused while applying symlinks"),process.exitCode=1}catch(o){console.error(o),y.error(" [FATAL] Failed to apply symlinks"),process.exitCode=1}finally{let u=((Fe()??{}).symlinks??[]).filter((l)=>!i.some((c)=>ur(c,l))).concat(r);y.info(`Updated symlinks state: ${u.length}`),je("symlinks",u)}}function mn(e){if(e instanceof Error)return`[${"code"in e?String(e.code):"ERROR"}] ${e.message}`;return`[ERROR] ${String(e)}`}function yn(e){return e.filter((t)=>t.status==="rejected")}var{deepEquals:bn}=globalThis.Bun;var Re=H("helperAur");class ae{static async syncDatabase(){await O({cmd:["sudo","pacman","-Sy"],errMsg:"Failed to sync package database pacman"})}static async getInstalledPakcages(){let{stdout:e}=await O({cmd:["pacman","-Qqen"],opt:{stdout:"pipe"}});return e}static async install(e){if(!Re)return;let t=new Set(e);await O({cmd:[Re,"-S","--needed","--noconfirm",...t],errMsg:"Failed to install packages pacman"})}static async remove(e){if(!Re)return;let t=new Set(e);await O({cmd:[Re,"-R",...t],errMsg:"Failed to uninstall packages pacman"})}}var gn=["pacman"];async function ar(e){await O({cmd:e,errMsg:`Failed to execute post hooks: ${e.join(" ")}`})}function vn(e){let t={pacman:[]};for(let n of e??[])if(n.manager==="pacman"||n.manager==="aur")t.pacman.push(...n.items);return t}function kn(e){let t=[],n=[];for(let s of e){if(typeof s==="object"){let{name:r,post_hooks:i}=s;if(r.trim())t.push(r.trim());if(i)n.push(i);continue}t.push(s)}return{items:t,hooks:n}}async function lr(e){if(!e)return;try{let t=[];await ae.syncDatabase(),await ae.install(e.items),y.success("Successfully Installing Pacman Packages");for(let n of e.hooks)await ar(n),t.push(n);return e}catch(t){if(t instanceof Error)y.error(t.message);else console.error(t);return}}async function cr(e){if(!e)return;if(!e.items.length)return;await ae.remove(e.items)}async function $n(e){let{added:t,removed:n}=e,s=await lr(t.pacman);await cr(n.pacman);let r={};if(s)r.pacman=s,y.info("Metadata pacman Saved");je("packages",r)}function fr(e,t){let n=t?.filter((r)=>!e?.some((i)=>bn(r,i,!0)))??[],s=e?.filter((r)=>!t?.some((i)=>bn(r,i,!0)))??[];return{added:n,removed:s}}function pr(e,t){let n=e,s=Object.entries(vn(t)).reduce((o,[a,u])=>(o[a]=kn(u),o),{}),r={},i={};for(let o of gn){let a=[...new Set(s[o]?.items.filter((f)=>!n?.[o]?.items.includes(f))??[])],u=[...new Set(n?.[o]?.items.filter((f)=>!s?.[o]?.items.includes(f))??[])],l=s[o]?.hooks.filter((f)=>!n?.[o]?.hooks.includes(f))??[],c=n?.[o]?.hooks.filter((f)=>!s?.[o]?.hooks.includes(f))??[];r[o]={items:a,hooks:l},i[o]={items:u,hooks:c}}return{added:r,removed:i}}function wn(e){let t=Fe(),n=fr(t.symlinks,e.symlinks),s=pr(t.packages,e.packages);return{symlinks:n,packages:s}}function xn(e){let{symlinks:t,packages:n}=e,s=(()=>{let i=["SYMLINKS"],{added:o=[],removed:a=[]}=t;if(o?.length===0&&a?.length===0)return i.push(" - No changes to apply with symlinks"),i.join(`
|
|
51
|
+
`);for(let u of o)i.push(` - [ADDED] ${u.sudo?"(sudo) ":""}${u.source} -> ${u.target}`);for(let u of a)i.push(` - [REMOVED] ${u.sudo?"(sudo) ":""}${u.source} -> ${u.target}`);return i.join(`
|
|
52
|
+
`)})(),r=(()=>{let i=["PACKAGES"],{added:o={},removed:a={}}=n;for(let[u,l]of Object.entries(o)){for(let c of l.items)i.push(` - [ADDED] (${u}) -> ${c}`);for(let c of l.hooks)i.push(` - [ADDED] (${u}) -> ${c}`)}for(let[u,l]of Object.entries(a))for(let c of l.items)i.push(` - [REMOVED] (${u}) -> ${c}`);if(i.length===1)i.push(" - No changes to apply with packages");return i.join(`
|
|
53
|
+
`)})();return[s,r].join(`
|
|
54
|
+
|
|
55
|
+
`)}async function En(e){let t=hr.join(e,"config.toml");G("configDir",e),await pn(),be("Switching configuration"),y.info("Scanning system environment..."),await Ee();let n=await Ce(t);if(!n)process.exit(1);G("settings",oe(n.settings,{backup:!0}));let s=wn(n),r=xn(s);we(r,"Config To Apply");let i=await Zt({message:"Apply config changes? (Please review the changes first!!)"});if(!i||ve(i))y.warn("Config changes not applied."),process.exit(0);await dn(s.symlinks),await $n(s.packages)}var Y=gt("hofii");Y.version("0.0.3");Y.command("scan","Detect system environment").alias("s").action(async()=>{await tn(),process.exit(0)});Y.command("validate [dir]","Validate configuration files").alias("v").action(async(e)=>{await Ce(e),process.exit(0)});Y.command("switch [dir]","Switch to new configuration").alias("sw").action(async(e)=>{let t=mr.resolve(e);await En(t)});try{if(process.argv.slice(2).length===0)Y.outputHelp(),process.exit(0);Y.help().parse(process.argv,{run:!1}),await Y.runMatchedCommand()}catch(e){if(e instanceof te){let t=e.issues.map((n)=>{let s=n.path.at(-1)?.input;return[`\u2717 ${n.message}`,` at: ${JSON.stringify(s)}`].join(`
|
|
53
56
|
`)}).join(`
|
|
54
57
|
|
|
55
|
-
`);console.error(t)}console.error(e)}finally{await
|
|
58
|
+
`);console.error(t)}else if(e instanceof Error)console.log(e.message);else console.error(e)}finally{await hn()}
|
package/package.json
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hofii",
|
|
3
3
|
"description": "An orchestration tools for manage dotfiles and packages",
|
|
4
|
-
"module": "index.ts",
|
|
5
4
|
"type": "module",
|
|
6
5
|
"bin": {
|
|
7
6
|
"hofii": "./dist/main.js"
|
|
@@ -26,5 +25,5 @@
|
|
|
26
25
|
"deepmerge-ts": "^7.1.5",
|
|
27
26
|
"valibot": "^1.4.2"
|
|
28
27
|
},
|
|
29
|
-
"version": "0.1.
|
|
28
|
+
"version": "0.1.3"
|
|
30
29
|
}
|