@b12k/porto 0.7.0 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -11
- package/dist/cli.js +1 -1
- package/dist/vars.js +10 -8
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -50,7 +50,11 @@ Run each command with `pnpm exec porto`. `reserve` is the default command.
|
|
|
50
50
|
|
|
51
51
|
Use `-h` or `--help` for help. Use `-V` or `--version` for the version.
|
|
52
52
|
|
|
53
|
-
|
|
53
|
+
Use `|` to share a port between variables and `;` to advance to the next port. Use `NAME` for a port number or `NAME=template` for text. Templates accept `{{block}}` and `{{port}}`.
|
|
54
|
+
|
|
55
|
+
```sh
|
|
56
|
+
pnpm exec porto --vars 'PORT|HOST_URL=http://localhost:{{port}};API_PORT' --env
|
|
57
|
+
```
|
|
54
58
|
|
|
55
59
|
With no variables, `--env` writes `PORTO_BLOCK`.
|
|
56
60
|
|
|
@@ -145,22 +149,14 @@ const block = await reserve({
|
|
|
145
149
|
host: '127.0.0.1',
|
|
146
150
|
idleTtlMinutes: 30,
|
|
147
151
|
keep: true,
|
|
148
|
-
vars: [
|
|
149
|
-
'PORT',
|
|
150
|
-
(_block, port) => ({
|
|
151
|
-
API_PORT: port,
|
|
152
|
-
API_URL: `http://localhost:${port}`,
|
|
153
|
-
HEALTH_PORT: port,
|
|
154
|
-
HEALTH_URL: `http://localhost:${port}/health`,
|
|
155
|
-
}),
|
|
156
|
-
],
|
|
152
|
+
vars: ['PORT', (_block, port) => ({ API_PORT: port, API_URL: `http://localhost:${port}` })],
|
|
157
153
|
});
|
|
158
154
|
const { API_PORT, API_URL } = block.vars;
|
|
159
155
|
```
|
|
160
156
|
|
|
161
157
|
`reserve()` accepts `start`, `size`, `host`, `idleTtlMinutes`, `keep`, and `vars`. All six options are optional and use the defaults in the config table.
|
|
162
158
|
|
|
163
|
-
Each entry in `vars` uses one port. The example returns
|
|
159
|
+
Each entry in `vars` uses one port. The example returns three named values from two entries. With `size: 2`, three separate entries throw `PortoError` with code `mappingInvalid` before Porto saves a reservation.
|
|
164
160
|
|
|
165
161
|
### Read and release reservations
|
|
166
162
|
|
package/dist/cli.js
CHANGED
|
@@ -80,7 +80,7 @@ update_notifier({
|
|
|
80
80
|
});
|
|
81
81
|
cli.command('reserve', {
|
|
82
82
|
isDefault: true
|
|
83
|
-
}).description('Reserve a stable TCP port block for the current checkout').option('--start <port>', 'First port of the range (default: 10000)', Number).option('--host <host>', 'Host to check for busy ports (default: detect local addresses)').option('--size <count>', 'Number of ports in each block (default: 10)', Number).option('--idle <minutes>', 'Idle TTL in minutes (default: 60)', Number).option('--vars <entries>', '
|
|
83
|
+
}).description('Reserve a stable TCP port block for the current checkout').option('--start <port>', 'First port of the range (default: 10000)', Number).option('--host <host>', 'Host to check for busy ports (default: detect local addresses)').option('--size <count>', 'Number of ports in each block (default: 10)', Number).option('--idle <minutes>', 'Idle TTL in minutes (default: 60)', Number).option('--vars <entries>', 'NAME or NAME=template variables (| shares a port, ; starts the next)').option('--no-vars', 'Ignore configured variables').option('--json', 'Print JSON to stdout').option('--json-file <file>', 'Save JSON to a file independently of stdout').option('--no-json-file', 'Skip the configured JSON file').option('--silent', 'Skip the reservation output on stdout').option('--no-silent', 'Print the reservation output on stdout').option('--env', 'Update the env file (default: disabled)').option('--no-env', 'Skip the env file').option('--env-file <file>', 'Set the env filename and enable env output (default: .env)').option('--keep', 'Keep this reservation until explicitly released').option('--no-keep', 'Restore idle cleanup for this reservation').action(handleReserve);
|
|
84
84
|
cli.command('current').description('Read the reservations of the current checkout').option('--json', 'Print JSON to stdout').action(async (flags)=>{
|
|
85
85
|
const blocks = await current();
|
|
86
86
|
if (0 === blocks.length) throw new PortoError('reservationNotFound');
|
package/dist/vars.js
CHANGED
|
@@ -52,7 +52,7 @@ function mapBlockToVars(block, entries) {
|
|
|
52
52
|
return Object.fromEntries(environment);
|
|
53
53
|
}
|
|
54
54
|
function parseVar(entry) {
|
|
55
|
-
const separator = entry.indexOf('
|
|
55
|
+
const separator = entry.indexOf('=');
|
|
56
56
|
const name = (-1 === separator ? entry : entry.slice(0, separator)).trim();
|
|
57
57
|
if (-1 === separator) return {
|
|
58
58
|
name
|
|
@@ -75,13 +75,15 @@ function parseVarEntries(vars) {
|
|
|
75
75
|
return result.data;
|
|
76
76
|
}
|
|
77
77
|
function parseVars(source) {
|
|
78
|
-
const
|
|
79
|
-
parseVarEntries(
|
|
80
|
-
return
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
78
|
+
const groups = source.split(';').map((group)=>group.split('|').map((entry)=>parseVar(entry)));
|
|
79
|
+
parseVarEntries(groups.flat().map(({ name })=>name));
|
|
80
|
+
return groups.map((group)=>{
|
|
81
|
+
const [firstVar] = group;
|
|
82
|
+
if (1 === group.length && firstVar && void 0 === firstVar.template) return firstVar.name;
|
|
83
|
+
return (block, port)=>Object.fromEntries(group.map(({ name, template })=>[
|
|
84
|
+
name,
|
|
85
|
+
template?.replaceAll('{{block}}', String(block)).replaceAll('{{port}}', String(port)) ?? port
|
|
86
|
+
]));
|
|
85
87
|
});
|
|
86
88
|
}
|
|
87
89
|
export { VARS_SCHEMA, assertVarsFit, mapBlockToVars, parseVarEntries, parseVars };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@b12k/porto",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0",
|
|
4
4
|
"description": "Port range allocator for git worktrees",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cli",
|
|
@@ -62,7 +62,7 @@
|
|
|
62
62
|
"oxlint-tsgolint": "7.0.2007",
|
|
63
63
|
"release-it": "21.1.2",
|
|
64
64
|
"tsx": "4.23.15",
|
|
65
|
-
"type-fest": "6.0.
|
|
65
|
+
"type-fest": "6.0.3",
|
|
66
66
|
"typescript": "7.0.2"
|
|
67
67
|
},
|
|
68
68
|
"engines": {
|