keyman-cli 0.1.0 → 0.2.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
@@ -6,7 +6,16 @@ Install the Rust-based Keyman CLI with npm:
6
6
  npm install -g keyman-cli
7
7
  ```
8
8
 
9
- Create a private `.yml` file with one mapping per project:
9
+ Get started:
10
+
11
+ ```sh
12
+ keyman init # create ~/.keyman.yml with an example project and load it
13
+ keyman edit # add your projects and secrets
14
+ cd ~/code/my-app
15
+ keyman inject # write .env for the project named after this folder
16
+ ```
17
+
18
+ The master file maps project names to quoted string values:
10
19
 
11
20
  ```yaml
12
21
  my-app:
@@ -14,13 +23,19 @@ my-app:
14
23
  DEBUG: "true"
15
24
  ```
16
25
 
17
- Then run:
26
+ More commands (leave out the project to use the current folder name):
18
27
 
19
28
  ```sh
20
- keyman load /path/to/master.yml
21
- keyman inject my-app /path/to/existing/project
29
+ keyman load /path/to/master.yml # use an existing master file
30
+ keyman status # check every project
31
+ keyman show my-app [--reveal] # variable names, values masked by default
32
+ keyman diff [--reveal] # git-style diff of .env against the master file
33
+ keyman save [--dry-run] # save this folder's .env back to the master file
34
+ eval "$(keyman export my-app)" # load variables into a POSIX shell
35
+ keyman run my-app -- npm start # run a command with the variables, no .env file
36
+ keyman completions bash # also zsh, fish, powershell
22
37
  ```
23
38
 
24
- `load` remembers the master file path. `inject` replaces the project's `.env` file. Keep the master file private and ignore `.env` in Git.
39
+ Run `keyman help <command>` for details. Keep the master file private and ignore `.env` in Git.
25
40
 
26
- Prebuilt binaries are included for Windows x64, macOS Intel and Apple Silicon, and Linux x64 and ARM64. No Rust installation is needed. [Source and full documentation](https://github.com/moonmangit/keyman-cli).
41
+ Prebuilt binaries are included for Windows x64, macOS Intel and Apple Silicon, and Linux x64 and ARM64. No Rust installation is needed. On Windows systems that block the native executable, the command can use WSL if it is installed. The executable is available as both `keyman` and `keyman-cli`. [Source and full documentation](https://github.com/moonmangit/keyman-cli).
package/bin/keyman.cjs CHANGED
@@ -1,6 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  const fs = require('node:fs');
4
+ const os = require('node:os');
4
5
  const path = require('node:path');
5
6
  const { spawnSync } = require('node:child_process');
6
7
 
@@ -25,7 +26,16 @@ if (!fs.existsSync(binary)) {
25
26
  process.exit(1);
26
27
  }
27
28
 
28
- const result = spawnSync(binary, process.argv.slice(2), { stdio: 'inherit' });
29
+ const args = process.argv.slice(2);
30
+ let result = spawnSync(binary, args, { stdio: 'inherit' });
31
+ if (process.platform === 'win32' && result.error && ['UNKNOWN', 'EPERM', 'EACCES'].includes(result.error.code)) {
32
+ try {
33
+ result = runWithWsl(args);
34
+ } catch (error) {
35
+ console.error(`keyman: Windows blocked the native executable and WSL fallback failed: ${error.message}`);
36
+ process.exit(1);
37
+ }
38
+ }
29
39
  if (result.error) {
30
40
  console.error(`keyman: ${result.error.message}`);
31
41
  process.exit(1);
@@ -35,3 +45,36 @@ if (result.signal) {
35
45
  } else {
36
46
  process.exitCode = result.status ?? 1;
37
47
  }
48
+
49
+ function runWithWsl(args) {
50
+ const linuxBinary = path.join(__dirname, 'native', 'x86_64-unknown-linux-gnu', 'keyman');
51
+ if (!fs.existsSync(linuxBinary)) {
52
+ throw new Error('the Linux x64 binary is missing from this package');
53
+ }
54
+
55
+ const linuxArgs = [...args];
56
+ if (['load', 'init'].includes(linuxArgs[0]) && linuxArgs.length === 2 && !linuxArgs[1].startsWith('-')) {
57
+ linuxArgs[1] = toWslPath(linuxArgs[1]);
58
+ } else if (['inject', 'save', 'diff'].includes(linuxArgs[0]) && linuxArgs.length === 3 && !linuxArgs[2].startsWith('-')) {
59
+ linuxArgs[2] = toWslPath(linuxArgs[2]);
60
+ }
61
+
62
+ const linuxHome = toWslPath(process.env.USERPROFILE || os.homedir());
63
+ return spawnSync('wsl.exe', [
64
+ '--exec', 'env', `HOME=${linuxHome}`, toWslPath(linuxBinary), ...linuxArgs,
65
+ ], { stdio: 'inherit' });
66
+ }
67
+
68
+ function toWslPath(input) {
69
+ const gitBashPath = /^\/([a-zA-Z])\//.exec(input);
70
+ const windowsPath = gitBashPath
71
+ ? `${gitBashPath[1].toUpperCase()}:${input.slice(2)}`
72
+ : path.win32.resolve(input);
73
+ const converted = spawnSync('wsl.exe', ['--exec', 'wslpath', '-u', windowsPath], {
74
+ encoding: 'utf8',
75
+ });
76
+ if (converted.error || converted.status !== 0) {
77
+ throw new Error(converted.error?.message || converted.stderr?.trim() || 'wslpath could not convert the path');
78
+ }
79
+ return converted.stdout.replace(/\r?\n$/, '');
80
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "keyman-cli",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "Manage project .env files from one private YAML file",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -10,7 +10,8 @@
10
10
  "homepage": "https://github.com/moonmangit/keyman-cli#readme",
11
11
  "bugs": "https://github.com/moonmangit/keyman-cli/issues",
12
12
  "bin": {
13
- "keyman": "bin/keyman.cjs"
13
+ "keyman": "bin/keyman.cjs",
14
+ "keyman-cli": "bin/keyman.cjs"
14
15
  },
15
16
  "files": [
16
17
  "bin/",