@jondotsoy/envs 0.1.6 → 0.1.8

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 CHANGED
@@ -39,9 +39,11 @@ Run the commands inside the repo or any of its worktrees. Inside a worktree, `.e
39
39
  | Command | What it does |
40
40
  | --- | --- |
41
41
  | `envs edit` | Runs `init` if `.envs/values.yml` does not exist yet, then runs `pull`, opens `values.yml` with `code -w` and, when the editor closes, runs `push`. If the editor fails, it does not `push`. |
42
+ | `envs edit --ui` | Same `init` and `pull`, but instead of VS Code it starts a local server (`127.0.0.1`, random port) and opens a React web editor with the values of `values.yml` (worktree profiles, defaults and per-worktree values). The **Save** button in the top right corner writes `values.yml` and runs `push`. Stop the server with Ctrl+C. |
42
43
  | `envs init` | Creates `.envs/`, `.envs/.gitignore` (containing `*`) and an empty `.envs/values.yml`. Does not overwrite existing files. |
43
44
  | `envs pull` | Reads the `.env` of the main repo and of each worktree and writes it to `values.yml`. Variables that are no longer in a `.env` are removed from `values.yml` for that worktree. |
44
45
  | `envs push` | Writes `values.yml` to the `.env` of each worktree. Updates existing variables in place, appends new ones at the end, and keeps comments and variables that are not in `values.yml`. |
46
+ | `envs use [profile]` | Sets the profile of the current worktree (`uses.<worktree>`) and pushes that worktree. Without arguments it lists the profile of each worktree. The profile must already exist in `values.yml`. |
45
47
  | `envs lint` | Checks security and prints a warning for each problem. Exits with code 1 if there is any (useful in CI). See below. |
46
48
  | `envs help` | Shows the help (also `--help`, `-h`, or no command). |
47
49
 
@@ -87,33 +89,59 @@ It never prints values, only the variable and its location (`envs.DB_PASSWORD.ma
87
89
  | `executable-files` | `values.yml` or a `.env` has the execute permission (use `chmod -x`). |
88
90
  | `writable-files` | `values.yml` or a `.env` is writable by the group or other users (use `chmod go-w`). |
89
91
  | `weak-secret` | Sensitive variable (`PASSWORD`, `TOKEN`, `SECRET`, `API_KEY`…) that is empty or has a typical value (`changeme`, `admin`…). |
90
- | `shared-secret` | Sensitive variable in `defaults`, which is written to all worktrees. |
92
+ | `shared-secret` | Sensitive variable in `defaults`, which is written to all worktrees using that profile. |
93
+ | `unknown-profile` | `uses` names a profile that is not in `profiles`. |
91
94
  | `secret-pattern` | Value with a known secret format (AWS, GitHub, Slack, `sk-…`, private key). |
92
95
  | `url-credentials`, `insecure-url` | Remote URL with an embedded password, or using `http://`, `ws://` or `ftp://`. |
93
96
 
94
97
  ## `values.yml` format
95
98
 
96
99
  ```yaml
97
- defaults:
98
- LOG_LEVEL: info
99
-
100
- envs:
101
- DATABASE_URL:
102
- main: postgres://localhost/main
103
- feature-x: postgres://localhost/feature_x
104
- PORT:
105
- main: "3000"
106
- feature-x: "3001"
100
+ uses:
101
+ main: local
102
+ feature-x: dev
103
+ profiles:
104
+ default:
105
+ defaults:
106
+ LOG_LEVEL: info
107
+ envs:
108
+ PORT:
109
+ main: 3000
110
+ feature-x: 3001
111
+ local:
112
+ defaults:
113
+ DATABASE_URL: postgres://localhost/app
114
+ envs: {}
115
+ dev:
116
+ defaults:
117
+ DATABASE_URL: postgres://dev.internal/app
118
+ envs:
119
+ PORT:
120
+ feature-x: 4001
107
121
  ```
108
122
 
109
- - `defaults`: default value of each variable. `push` writes it to the `.env` of all worktrees.
110
- - `envs.<VARIABLE>.<worktree>`: value of the variable in that worktree. It overrides the value from `defaults`.
123
+ - Every profile is written with both `defaults` and `envs` (empty when it has nothing); a profile is never `null`.
124
+ - `profiles.<profile>.defaults`: default value of each variable for the worktrees that use the profile.
125
+ - `profiles.<profile>.envs.<VARIABLE>.<worktree>`: value of the variable in that worktree. It overrides the profile's `defaults`.
126
+ - `uses.<worktree>`: profile of that worktree. A worktree that is not listed uses `default`; `pull` adds it as `default`.
111
127
  - Values can be strings, numbers or booleans (`PORT: 3000`, `DEBUG: true`); `push` writes them to the `.env` as text (`PORT=3000`, `DEBUG=true`). `pull` converts `true`/`false` and canonical numbers (`3000`, `0.5`) to booleans and numbers; anything else (`007`, `1e3`) stays a string.
112
128
 
113
- The schema (JSON Schema) is at [`schema/values.schema.json`](schema/values.schema.json). To have VS Code validate the file with the YAML extension, add this at the top of `values.yml`:
129
+ A worktree receives, from lowest to highest precedence: `default` defaults, `default` envs, its profile's defaults, its profile's envs. With the `default` profile only the first two apply.
130
+
131
+ The `.env` files are the source of truth: `pull` (and `edit`) rewrites `values.yml` from them, keeping only `uses` and `profiles`.
132
+
133
+ ### Creating a profile
134
+
135
+ Write a profile that does not exist yet in `uses.<worktree>` while running `envs edit`: when you close the editor it is created as a copy of `default` (and the worktree receives it). A profile you add by hand under `profiles`, with values or empty, keeps what you wrote (nothing is copied from `default`) and is completed with an empty `defaults`/`envs` if one is missing. `envs push` and `envs use` do not create profiles: they fail with an unknown profile error. `envs lint` reports it as `unknown-profile`.
136
+
137
+ ### Previous format
138
+
139
+ Files with `defaults` and `envs` at the root keep working: they are read as `profiles.default.defaults` and `profiles.default.envs`, and the next `envs edit` or `envs pull` rewrites the file in the new format.
140
+
141
+ The schema (JSON Schema) is at [`schema/values.schema.json`](schema/values.schema.json). It is also published at <https://jondotsoy.github.io/envs/schema.json>. `init`, `pull` and `edit` write this line at the top of `values.yml`, so VS Code validates the file with the YAML extension:
114
142
 
115
143
  ```yaml
116
- # yaml-language-server: $schema=../schema/values.schema.json
144
+ # yaml-language-server: $schema=https://jondotsoy.github.io/envs/schema.json
117
145
  ```
118
146
 
119
147
  ## Development