@mirta/cli 0.3.4 → 0.4.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 CHANGED
@@ -2,82 +2,125 @@
2
2
 
3
3
  [![en](https://img.shields.io/badge/lang-en-olivedrab.svg?style=flat-square)](https://github.com/wb-mirta/core/blob/latest/packages/mirta-cli/README.md)
4
4
  [![ru](https://img.shields.io/badge/lang-ru-dimgray.svg?style=flat-square)](https://github.com/wb-mirta/core/blob/latest/packages/mirta-cli/README.ru.md)
5
- [![NPM Version](https://img.shields.io/npm/v/@mirta/globals?style=flat-square)](https://npmjs.com/package/@mirta/cli)
5
+ [![NPM Version](https://img.shields.io/npm/v/@mirta/cli?style=flat-square)](https://npmjs.com/package/@mirta/cli)
6
6
  [![NPM Downloads](https://img.shields.io/npm/dm/@mirta/cli?style=flat-square&logo=npm)](https://npmjs.com/package/@mirta/cli)
7
7
 
8
- Utility for efficient release management and automated package publishing in NPM, supports work in monorepositories.
8
+ > Universal CLI tool for versioning, publishing, and deployment in monorepos with synchronized semantic versioning.
9
9
 
10
- ### Key Features
10
+ `@mirta/cli` is a process orchestrator that:
11
+ - Synchronously updates versions across monorepo packages,
12
+ - Runs `CHANGELOG` generation (if configured),
13
+ - Publishes packages to NPM with `--provenance` support in CI,
14
+ - Synchronizes artifacts with Wiren Board controllers via `rsync`.
11
15
 
12
- - Convenient system for updating project versions;
13
- - Easy integration with existing CI/CD processes;
14
- - Access to all necessary operations through intuitive commands;
15
- - Support for customizing workflows specific to your infrastructure.
16
+ Works in any monorepo using `pnpm` and synchronized semantic versioning.
16
17
 
17
- ## Installation and Initial Setup
18
+ To recognize the monorepo structure, `@mirta/cli` relies on the packages `@mirta/workspace` and `@mirta/package`, which read the configuration from the workspaces field in the root `package.json`.
18
19
 
19
- Add `@mirta/cli` as a development dependency to your project using the following command:
20
+ **Not intended for execution in Duktape environment on Wiren Board controllers.**
21
+
22
+ ## 📦 Installation
20
23
 
21
24
  ```sh
22
25
  pnpm add -wD @mirta/cli
23
26
  ```
24
- You can configure additional parameters by adding a configuration file named `mirta.config.json` at the root of your main project. For example:
25
27
 
26
- ```json
27
- {
28
- "scope": "myscope",
29
- "scopeAsPackagePrefix": false
30
- }
28
+ ✅ This package is designed for the Mirta framework but works in any `pnpm` monorepo with synchronized versioning.
29
+
30
+ ## 🚀 Quick Start
31
+
32
+ **Run a release**:
33
+
34
+ ```sh
35
+ pnpm mirta release
31
36
  ```
32
- ### Main Configuration Options
37
+ Select the update type → versions will be updated.
33
38
 
34
- - `scope` sets the correspondence to an account or organization name in the NPM registry.
35
- - `scopeAsPackagePrefix` enables transformation of module paths by prefixing the specified `scope` before the package name. Default is `false`.
39
+ **Publish (in CI or locally)**:
36
40
 
37
- Example of `scopeAsPackagePrefix` for the package `@myscope/globals`:
41
+ ```sh
42
+ pnpm mirta publish
43
+ ```
44
+ All public packages will be published to NPM.
38
45
 
39
- - `false` - location `packages/globals`
40
- - `true` - location `packages/myscope-globals`
46
+ ## 🧰 Commands
41
47
 
42
- Activating this option helps prevent collisions with third-party NPM packages without a `scope`.
48
+ ### `mirta [options]`
43
49
 
44
- If you are satisfied with the default behavior of the tool, creating a separate configuration file is not required. Simply specify the scope in the main `package.json` file like so:
50
+ These global options are available for all commands:
51
+ - `--help` (`-h`) — displays help on available commands and options.
52
+ - `--version` (`-v`) — prints `@mirta/cli` version.
53
+ - `--locale <loc>` — sets the interface language (`en`, `ru`).
45
54
 
46
- ```json
47
- {
48
- "name": "@myscope/myproject"
49
- }
50
- ```
55
+ ### `pnpm mirta release`
51
56
 
52
- ### Special Mirta Framework Options
57
+ Prepares a release: detects the current version, prompts to select an update type (`patch`, `minor`, `major`, `pre*`), and applies it to all packages with the `version` field.
53
58
 
54
- - `templates` contains a set of paths to templates used by the project generation wizard. Performs recursive search for `package.json` files within the listed locations.
59
+ <details>
60
+ <summary>Technical Details</summary>
55
61
 
56
- Example Mirta configuration:
62
+ The process is divided into stages:
57
63
 
58
- ```json
59
- {
60
- "scopeAsPackagePrefix": true,
61
- "templates": [
62
- "packages/create-mirta/public/templates"
63
- ]
64
- }
65
- ```
66
- ## Release Management
64
+ #### Stage 1: Git state check (if project is under git)
65
+ - Ensures synchronization with `origin`.
66
+ - Verifies CI success (via `build` workflow).
67
67
 
68
- Performing the release procedure interactively:
68
+ #### Stage 2: Dependency update
69
+ - Recursively discovers `package.json` in paths specified in `mirta.config.json#project.templates`.
70
+ - Updates monorepo dependencies (`dependencies`, `devDependencies`) to the current version.
69
71
 
70
- ```sh
71
- pnpm mirta release
72
- ```
73
- The command will prompt you to select an appropriate version. If the project is managed by Git, it will prepare a list of changes in the `CHANGELOG.md` file, check the CI status, and create a commit.
72
+ #### Stage 3: CHANGELOG generation
73
+ - Runs `pnpm run changelog` if the script exists.
74
74
 
75
- During operation with Git, the needed repository is automatically recognized, but two checks are performed:
75
+ #### Stage 4: Commit and tag
76
+ - If GitHub access is via `ssh`, creates a commit and tag:
77
+ ```sh
78
+ git commit -m "release: vX.X.X"
79
+ git tag vX.X.X
80
+ ```
81
+ - If access is via `https`, changes remain in the working directory for manual commit.
76
82
 
77
- 1. Local changes have been synchronized with the remote storage beforehand;
78
- 2. The CI process named `Build` for the last commit has completed successfully.
83
+ </details>
79
84
 
80
- To generate a change log file, add the [conventional-changelog-cli](https://www.npmjs.com/package/conventional-changelog-cli) package as a dev dependency in the root `package.json`. Additionally, include a `changelog` script in the `scripts` section:
85
+ #### Supported Options
86
+
87
+ - `--dry-run` (`--dry`) — simulation mode, shows changes without applying them.
88
+ - `--preid` `<id>` — custom prerelease identifier (`alpha.0`, `beta.1`).
89
+ - `--skip-prompts` — skips interactive prompts, uses defaults.
90
+ - `--skip-git` — skips commit and tag creation.
91
+
92
+ #### Frequently Asked Questions
93
+
94
+ <details>
95
+ <summary>Why synchronized versioning?</summary>
96
+
97
+ All packages receive the same version on release. This ensures:
98
+ - Guaranteed compatibility (`@mirta/cli@0.4.0` works with `@mirta/package@0.4.0`),
99
+ - Atomic releases,
100
+ - Simplified dependency management.
101
+
102
+ 💡 When using `workspace:*`, all references are replaced with the concrete version during release.
103
+
104
+ </details>
105
+
106
+ <details>
107
+ <summary>What is "semantic" versioning?</summary>
108
+
109
+ Format: `major.minor.patch`:
110
+ - `major` — breaking changes,
111
+ - `minor` — new features without breaking compatibility,
112
+ - `patch` — bug fixes.
113
+
114
+ Versions below `1.0.0` (e.g., `0.4.0`) are experimental: any update may include breaking changes.
115
+
116
+ More: [semver.org](https://semver.org/)
117
+
118
+ </details>
119
+
120
+ <details>
121
+ <summary>How to set up CHANGELOG.md generation?</summary>
122
+
123
+ Add `conventional-changelog-cli` to devDependencies in the root `package.json` and define the script:
81
124
 
82
125
  ```json
83
126
  {
@@ -86,90 +129,264 @@ To generate a change log file, add the [conventional-changelog-cli](https://www.
86
129
  }
87
130
  }
88
131
  ```
89
- The changelog entries are based on commits made within the version range. There are requirements for commit headers:
90
132
 
91
- 1. Line length should not exceed 50 characters;
92
- 2. Use prefixes such as `fix:`, `feat:`, `docs:`, `chore:`, etc.
133
+ The changelog is generated from commit messages. Requirements:
134
+ - Subject line 50 characters,
135
+ - Use prefixes: `fix:`, `feat:`, `docs:`, `chore:`, etc.
93
136
 
94
- For the full list of requirements, refer to the framework's [Commit Convention](https://github.com/wb-mirta/core/blob/latest/.github/commit-convention.md).
137
+ See: [Commit Convention](https://github.com/wb-mirta/core/blob/latest/.github/commit-convention.md)
95
138
 
96
- ### Semantic Versioning
139
+ </details>
97
140
 
98
- A semantic version follows the format `major.minor.patch` (for example, `1.2.3`), where each segment represents different levels of changes:
141
+ #### Advanced Usage
99
142
 
100
- - `major` increases when incompatible changes are introduced;
101
- - `minor` increases when new functionality is added while maintaining backward compatibility;
102
- - `patch` increases when bug fixes are applied, preserving backward compatibility.
143
+ <details>
144
+ <summary>Explicit version</summary>
103
145
 
104
- Releasing with a specific version:
146
+ Sets the exact version passed as an argument:
105
147
 
106
148
  ```sh
107
149
  pnpm mirta release 1.2.3
108
150
  ```
109
- Release specifying the incremented part:
151
+ ⚠️ **Never overwrite published versions — NPM will reject them.**
152
+
153
+ </details>
154
+
155
+ <details>
156
+ <summary>Increment: patch, minor, major</summary>
110
157
 
111
158
  ```sh
112
159
  pnpm mirta release patch
113
160
  # 0.0.1
114
161
  ```
162
+
115
163
  ```sh
116
164
  pnpm mirta release minor
117
165
  # 0.1.0
118
166
  ```
167
+
119
168
  ```sh
120
169
  pnpm mirta release major
121
170
  # 1.0.0
122
171
  ```
123
- Pre-release version specifying the type:
172
+ </details>
173
+
174
+ <details>
175
+ <summary>Pre-releases: alpha, beta, rc</summary>
124
176
 
125
177
  ```sh
126
178
  pnpm mirta release prepatch --preid alpha
127
179
  # 0.0.1-alpha.0
128
180
  ```
181
+
129
182
  ```sh
130
183
  pnpm mirta release preminor --preid alpha
131
184
  # 0.1.0-alpha.0
132
185
  ```
186
+
133
187
  ```sh
134
188
  pnpm mirta release premajor --preid alpha
135
189
  # 1.0.0-alpha.0
136
190
  ```
137
- Incrementing an already existing pre-release version is done via
191
+
192
+ #### Incrementing pre-release version
138
193
 
139
194
  ```sh
140
195
  pnpm mirta release prerelease --preid alpha
141
196
  # 0.0.1-alpha.1
142
197
  ```
143
- ## Automatic Publishing
198
+ </details>
199
+
200
+ ---
201
+
202
+ ### `pnpm mirta publish`
203
+
204
+ Publishes packages to NPM, skipping those with `private: true`.
205
+
206
+ <details>
207
+ <summary>Technical Details</summary>
208
+
209
+ ⚠️ Typically runs in CI after `git push` of the `vX.X.X` tag.
210
+
211
+ The publish tag is determined automatically:
212
+ - `alpha` → `--tag alpha`
213
+ - `beta` → `--tag beta`
214
+ - `rc` → `--tag rc`
215
+
216
+ In CI, `--provenance` is added to attest package origin.
217
+
218
+ </details>
219
+
220
+ #### Supported Options
221
+
222
+ - `--dry-run` (`--dry`) — simulation mode.
223
+ - `--skip-build` — skips running `pnpm run build`.
224
+ - `--skip-git` — disables git checks (equivalent to `--no-git-checks` in `pnpm publish`).
225
+
226
+ ---
227
+
228
+ ### `pnpm mirta deploy`
229
+
230
+ Synchronizes files with Wiren Board controllers via `rsync` over SSH.
231
+
232
+ <details>
233
+ <summary>Technical Details</summary>
234
+
235
+ - Transport: `rsync -rtzgO` (recursive, compressed, preserves timestamps and group, omits directory timestamps — safe for overlayfs).
236
+ - WSL2 support: on Windows, commands run inside WSL.
237
+ - Authentication:
238
+ - Uses an isolated `ssh-agent`.
239
+ - Supports PKCS#11 (Rutoken) and SSH keys.
240
+ - `ttl` — key lifetime (e.g., `1h`).
241
+ - `--dry-run` mode: shows changes without applying.
242
+ - Symbolic links are not transferred — should be created on the controller manually.
243
+
244
+ </details>
245
+
246
+ #### Supported Options
247
+
248
+ - `--config`, `-c <path>` — path to `mirta.config.json`.
249
+ - `--profile`, `-p <name>` — deployment profile (default: `default`).
250
+ - `--to <conn>` — override connection string.
251
+ - `--dry-run` — simulate synchronization.
252
+ Parameter `--to` accepts:
253
+ - Connection name from `mirta.config.json`,
254
+ - Connection string starting with `ssh://`.
255
+
256
+ #### Environment variables and secrets
257
+
258
+ For secure credential storage, use `.env.local` (git-ignored):
259
+
260
+ ```sh
261
+ # .env.local
262
+
263
+ SSH_KEY=~/.ssh/id_ed25519
264
+
265
+ # Available in config:
266
+ WB_CONN_OPTIONS=`key=${SSH_KEY};ttl=1h30m`
267
+ WB_CONN_WORK=`ssh://user@mycompany.local;${WB_CONN_OPTIONS}`
268
+ ```
269
+
270
+ Supported prefixes:
271
+ - `WB_` — CLI-specific variables
272
+ - `MIRTA_` — general Mirta context
273
+ - `NODE_ENV` — standard environment value
144
274
 
145
- Publish ready-made packages to the NPM repository:
275
+ #### Connection string format
146
276
 
147
277
  ```sh
148
- pnpm mirta publish
278
+ ssh://[user@]host[:port][;param1=value1;param2=value2...]
279
+ ```
280
+
281
+ Supported parameters:
282
+
283
+ | Parameter | Description | Example |
284
+ |---------|-------------|---------|
285
+ | `pkcs11` | Path to PKCS#11 library (Rutoken) | `pkcs11=/usr/lib/librtpkcs11ecp.so` |
286
+ | `key` | Path to SSH key (ED25519, RSA) | `key=~/.ssh/id_ed25519` |
287
+ | `ttl` | Key lifetime in ssh-agent | `ttl=1h` |
288
+ | `wsl` | WSL2 distribution for Windows | `wsl=Debian` |
289
+
290
+ > Note: `pkcs11` takes precedence over `key` if both are specified.
291
+
292
+ Examples:
293
+
294
+ ```sh
295
+ # ED25519 SSH key
296
+ ssh://deploy@192.168.42.1;key=~/.ssh/id_ed25519;ttl=30m
297
+ ```
298
+
299
+ ```sh
300
+ # PKCS#11 token (Rutoken) with WSL2 on Windows
301
+ ssh://deploy@192.168.42.1;pkcs11=/usr/lib/librtpkcs11ecp.so;wsl=Ubuntu-22.04
302
+ ```
303
+
304
+ ```sh
305
+ # With environment variables
306
+ ssh://deploy@${WB_HOST};key=${MIRTA_SSH_KEY}
149
307
  ```
150
308
 
151
- This operation will initiate the build and publication process for the prepared packages.
309
+ <details>
310
+ <summary>PKCS#11 nuances</summary>
311
+
312
+ If `ssh-agent` throws `agent refused operation`:
152
313
 
153
- If the process is triggered from a CI environment on GitHub, then every file inside the published package will be automatically enriched with [provenance information](https://docs.npmjs.com/generating-provenance-statements) - hash values and metadata that confirm its integrity and authenticity.
314
+ - PKCS#11 module path must be real symlinks are rejected
315
+ - PIN code attempt limit exceeded, token is locked
154
316
 
155
- The primary goal of this feature is to enhance trust and security for published packages. When a package is published using this option, users can verify whether the content of the downloaded package matches the original source provided by the author.
317
+ </details>
156
318
 
157
- ## Auxiliary options
319
+ #### Example and structure of `mirta.config.json`
320
+
321
+ ```jsonc
322
+ {
323
+ // Connection strings to controllers
324
+ "connections": {
325
+ // Omitted details in public repository
326
+ "work": "${WB_CONN_WORK}",
327
+ // Partial detail hiding
328
+ "home": "ssh://user@192.168.42.1;${WB_CONN_OPTIONS};wsl=Ubuntu"
329
+ },
330
+ "deploy": {
331
+ // File sync rule sets
332
+ "mappings": {
333
+ "wb-rules-es5": [
334
+ {
335
+ // Local folder (relative to project root)
336
+ "from": "dist/es5/wb-rules-rules",
337
+ // Target folder on controller
338
+ "to": "/mnt/data/etc/wb-rules-rules",
339
+ // User group with access on controller (optional)
340
+ "toGroup": "developers",
341
+ // Delete files in target if missing in source
342
+ "cleanup": true,
343
+ // List of files/dirs to protect from deletion when cleanup: true
344
+ "protect": ["alarms.conf"]
345
+ },
346
+ // {
347
+ // Next sync rule...
348
+ // }
349
+ ]
350
+ },
351
+ // Predefined deployment profiles
352
+ "profiles": {
353
+ "default": {
354
+ // Array of rule set names from deploy.mappings
355
+ "mappings": ["wb-rules-es5"],
356
+ // Connection name or string
357
+ "connection": "work",
358
+ // User group with access on controller (optional)
359
+ "toGroup": "developers"
360
+ }
361
+ }
362
+ }
363
+ }
364
+ ```
158
365
 
159
- ### `release` options
366
+ ## Testing
160
367
 
161
- `--dry` runs the command in simulation mode ("dry run"), showing changes that would be made without actually applying them. Useful for previewing changes before application.
368
+ The tool has been tested manually and in CI:
369
+ - Interactive and automated releases.
370
+ - Error handling (version rollback on failure).
371
+ - Git state and CI checks.
372
+ - Support for `--dry-run`.
162
373
 
163
- `--preid <custom-pre-release-id>` sets a custom prefix for the pre-release version, which is appended to the package version number (e.g., beta.1). This option allows creating pre-release versions such as alpha, beta, RC, etc., before the official stable release.
374
+ Additional tests:
375
+ - Deployment using `Rutoken`, deployment with `ED25519` key in WSL2 on Windows and standalone Linux Debian (Trixie).
164
376
 
165
- `--skipPrompts` skips interactive user queries. The command runs automatically using default values or predefined settings.
377
+ ## ⚠️ Limitations
166
378
 
167
- `--skipGit` ignores actions related to the Git version control system, such as committing changes, creating commit tags, or pushing updates to a remote repository. Might be useful if you wish to manage Git operations manually later.
379
+ **Runs only in Node.js** (not in Duktape).<br/>
380
+ Automatic commit and tag creation works only with `ssh` access to GitHub.<br/>
381
+ WSL2 is required for deployment from Windows.
168
382
 
169
- ### `publish` options
383
+ ## 🛠 Mirta Configuration
170
384
 
171
- `--dry` runs the command in simulation mode ("dry run"), showing changes that would be made without actually applying them. Useful for previewing changes before application.
385
+ The `mirta.config.json` file configures `@mirta/cli` behavior.
172
386
 
173
- `--skipBuild` excludes running the build process after updating package versions. Skips executing tasks defined in the build pipeline, allowing you to decide whether recompilation is necessary after changing version numbers.
387
+ Supported fields:
174
388
 
175
- `--skipGit` ignores actions related to the Git version control system, such as committing changes, creating commit tags, or pushing updates to a remote repository. Might be useful if you wish to manage Git operations manually later.
389
+ - `project.templates` paths to templates (e.g., for `create-mirta`).
390
+ - `connections` — named connections.
391
+ - `deploy.mappings` — file sync rules.
392
+ - `deploy.profiles` — deployment profiles.