@kitty-game-composer/cli 0.0.0-stage → 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/LICENSE +21 -0
- package/README.md +44 -2
- package/bin/kitty.js +50 -0
- package/lib/resolve.js +154 -0
- package/package.json +35 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Enzo Vezzaro
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,45 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @kitty-game-composer/cli
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A small npm launcher for the [Kitty](https://github.com/EnzoVezzaro/game-composer) game composer CLI. The CLI itself is the Python package [`kitty-game-composer`](https://pypi.org/project/kitty-game-composer/); this package finds it and runs it, so `kitty` works the same from npm or from pipx.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
Install the Python CLI first:
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
pipx install kitty-game-composer
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Then use the launcher without installing it, or install it globally:
|
|
14
|
+
|
|
15
|
+
```sh
|
|
16
|
+
npx @kitty-game-composer/cli --help
|
|
17
|
+
npm i -g @kitty-game-composer/cli
|
|
18
|
+
kitty --help
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
If you installed with pipx you already have a `kitty` command, and this package is optional. It is for people who prefer `npx`, or who want `kitty` managed next to their other npm tools.
|
|
22
|
+
|
|
23
|
+
## How it finds the CLI
|
|
24
|
+
|
|
25
|
+
1. A `kitty` on `PATH` that is a Python console script (what pip and pipx install). The launcher skips itself, npm shims, and native binaries with the same name, such as the kitty terminal emulator.
|
|
26
|
+
2. `python -m gamecomposer.cli`, trying `KITTY_PYTHON`, then `GAMECOMPOSER_PYTHON`, then `python3`, then `python`, and using the first one that can import the package.
|
|
27
|
+
3. Otherwise it prints the install command and exits with code `127`.
|
|
28
|
+
|
|
29
|
+
Arguments, standard input and output, and the exit code pass through unchanged. The launcher sets `KITTY_NPM_LAUNCHER=1` for the child so a wrapper script that calls it again cannot loop.
|
|
30
|
+
|
|
31
|
+
It has no dependencies, no install scripts, and makes no network calls. Node.js 18 or newer.
|
|
32
|
+
|
|
33
|
+
## Use
|
|
34
|
+
|
|
35
|
+
```sh
|
|
36
|
+
kitty config # validate gamecomposer.yml, print normalized JSON
|
|
37
|
+
kitty up # check digests, build the guest on Kiri, open the player
|
|
38
|
+
kitty ls --json # every Kiri-managed instance
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
The full CLI reference is in the [user guide](https://github.com/EnzoVezzaro/game-composer/blob/main/docs/user-guide.md).
|
|
42
|
+
|
|
43
|
+
## License
|
|
44
|
+
|
|
45
|
+
MIT
|
package/bin/kitty.js
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// kitty-game-composer-npm-launcher: thin launcher for the Python Kitty CLI.
|
|
3
|
+
// It never installs anything and makes no network calls.
|
|
4
|
+
'use strict';
|
|
5
|
+
|
|
6
|
+
const { spawn } = require('node:child_process');
|
|
7
|
+
const {
|
|
8
|
+
GUARD_ENV,
|
|
9
|
+
INSTALL_HINT,
|
|
10
|
+
NOT_FOUND_EXIT,
|
|
11
|
+
resolveKitty,
|
|
12
|
+
} = require('../lib/resolve.js');
|
|
13
|
+
|
|
14
|
+
function main() {
|
|
15
|
+
const target = resolveKitty({ selfPath: __filename });
|
|
16
|
+
if (!target) {
|
|
17
|
+
process.stderr.write(`${INSTALL_HINT}\n`);
|
|
18
|
+
process.exitCode = NOT_FOUND_EXIT;
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const child = spawn(target.command, [...target.args, ...process.argv.slice(2)], {
|
|
23
|
+
stdio: 'inherit',
|
|
24
|
+
env: { ...process.env, [GUARD_ENV]: '1' },
|
|
25
|
+
windowsHide: false,
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
// The terminal sends Ctrl-C to the whole process group, so the child gets it
|
|
29
|
+
// too. Stay alive until the child exits so its exit code is the one we return.
|
|
30
|
+
const forward = (signal) => {
|
|
31
|
+
if (signal !== 'SIGINT') child.kill(signal);
|
|
32
|
+
};
|
|
33
|
+
for (const signal of ['SIGINT', 'SIGTERM', 'SIGHUP']) process.on(signal, forward);
|
|
34
|
+
|
|
35
|
+
child.on('error', (err) => {
|
|
36
|
+
process.stderr.write(`kitty: could not start ${target.command}: ${err.message}\n`);
|
|
37
|
+
process.exitCode = 1;
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
child.on('exit', (code, signal) => {
|
|
41
|
+
if (signal) {
|
|
42
|
+
for (const s of ['SIGINT', 'SIGTERM', 'SIGHUP']) process.removeListener(s, forward);
|
|
43
|
+
process.kill(process.pid, signal);
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
process.exitCode = code ?? 1;
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
main();
|
package/lib/resolve.js
ADDED
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// Finds the Python Kitty CLI (PyPI: kitty-game-composer) without running it.
|
|
4
|
+
// Order: a Python `kitty` script on PATH, then `<python> -m gamecomposer.cli`.
|
|
5
|
+
// Everything that touches the system is injectable so the tests stay hermetic.
|
|
6
|
+
|
|
7
|
+
const fs = require('node:fs');
|
|
8
|
+
const path = require('node:path');
|
|
9
|
+
const { spawnSync } = require('node:child_process');
|
|
10
|
+
|
|
11
|
+
// Written into the child environment so a launcher started by a launcher
|
|
12
|
+
// (for example through a wrapper script on PATH) never searches PATH again.
|
|
13
|
+
const GUARD_ENV = 'KITTY_NPM_LAUNCHER';
|
|
14
|
+
// Present in bin/kitty.js; a PATH entry containing it is this launcher.
|
|
15
|
+
const LAUNCHER_MARKER = 'kitty-game-composer-npm-launcher';
|
|
16
|
+
const INSTALL_HINT = [
|
|
17
|
+
'kitty: the Kitty CLI (Python) is not installed.',
|
|
18
|
+
'',
|
|
19
|
+
'Install it with:',
|
|
20
|
+
' pipx install kitty-game-composer',
|
|
21
|
+
'',
|
|
22
|
+
'or, inside a virtual environment:',
|
|
23
|
+
' python3 -m pip install kitty-game-composer',
|
|
24
|
+
'',
|
|
25
|
+
'Then run this command again. Set KITTY_PYTHON to pick a specific interpreter.',
|
|
26
|
+
].join('\n');
|
|
27
|
+
const NOT_FOUND_EXIT = 127;
|
|
28
|
+
const HEAD_BYTES = 512;
|
|
29
|
+
|
|
30
|
+
function readHead(file, fsImpl = fs) {
|
|
31
|
+
let fd;
|
|
32
|
+
try {
|
|
33
|
+
fd = fsImpl.openSync(file, 'r');
|
|
34
|
+
const buf = Buffer.alloc(HEAD_BYTES);
|
|
35
|
+
const n = fsImpl.readSync(fd, buf, 0, HEAD_BYTES, 0);
|
|
36
|
+
return buf.subarray(0, n).toString('utf8');
|
|
37
|
+
} catch {
|
|
38
|
+
return null;
|
|
39
|
+
} finally {
|
|
40
|
+
if (fd !== undefined) {
|
|
41
|
+
try { fsImpl.closeSync(fd); } catch { /* already closed */ }
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function realpath(file, fsImpl = fs) {
|
|
47
|
+
try {
|
|
48
|
+
return fsImpl.realpathSync(file);
|
|
49
|
+
} catch {
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// pip and pipx write console scripts as text with a Python shebang, either
|
|
55
|
+
// `#!/path/python` or the `#!/bin/sh` + `exec python` form for long paths.
|
|
56
|
+
// Native binaries (such as the unrelated kitty terminal emulator) and npm
|
|
57
|
+
// shims fail this check.
|
|
58
|
+
function isPythonScript(head) {
|
|
59
|
+
if (typeof head !== 'string' || !head.startsWith('#!')) return false;
|
|
60
|
+
if (head.includes(LAUNCHER_MARKER)) return false;
|
|
61
|
+
const firstLines = head.split('\n').slice(0, 3).join('\n');
|
|
62
|
+
return /python/i.test(firstLines);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function pathCandidates(name, env, platform) {
|
|
66
|
+
const pathVar = env.PATH ?? env.Path ?? '';
|
|
67
|
+
const delimiter = platform === 'win32' ? ';' : ':';
|
|
68
|
+
// On Windows pip installs kitty.exe; npm's kitty.cmd / kitty.ps1 shims are skipped.
|
|
69
|
+
const names = platform === 'win32' ? [`${name}.exe`] : [name];
|
|
70
|
+
const out = [];
|
|
71
|
+
for (const dir of pathVar.split(delimiter)) {
|
|
72
|
+
if (!dir) continue;
|
|
73
|
+
for (const n of names) out.push(path.join(dir, n));
|
|
74
|
+
}
|
|
75
|
+
return out;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function isExecutableFile(file, fsImpl, platform) {
|
|
79
|
+
try {
|
|
80
|
+
const st = fsImpl.statSync(file);
|
|
81
|
+
if (!st.isFile()) return false;
|
|
82
|
+
if (platform === 'win32') return true;
|
|
83
|
+
fsImpl.accessSync(file, fs.constants.X_OK);
|
|
84
|
+
return true;
|
|
85
|
+
} catch {
|
|
86
|
+
return false;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function findKittyOnPath({ env, platform, selfPath, fsImpl = fs }) {
|
|
91
|
+
const self = selfPath ? realpath(selfPath, fsImpl) ?? selfPath : null;
|
|
92
|
+
for (const candidate of pathCandidates('kitty', env, platform)) {
|
|
93
|
+
if (!isExecutableFile(candidate, fsImpl, platform)) continue;
|
|
94
|
+
const real = realpath(candidate, fsImpl) ?? candidate;
|
|
95
|
+
if (self && real === self) continue;
|
|
96
|
+
if (platform === 'win32') {
|
|
97
|
+
// pip's kitty.exe is a native wrapper; it cannot be this Node script.
|
|
98
|
+
return candidate;
|
|
99
|
+
}
|
|
100
|
+
if (isPythonScript(readHead(real, fsImpl))) return candidate;
|
|
101
|
+
}
|
|
102
|
+
return null;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function pythonCandidates(env, platform) {
|
|
106
|
+
const list = [env.KITTY_PYTHON, env.GAMECOMPOSER_PYTHON, 'python3'];
|
|
107
|
+
if (platform === 'win32') list.push('py', 'python');
|
|
108
|
+
else list.push('python');
|
|
109
|
+
return [...new Set(list.filter(Boolean))];
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function canImport(python, env, run = spawnSync) {
|
|
113
|
+
const res = run(python, ['-c', 'import gamecomposer.cli'], {
|
|
114
|
+
env,
|
|
115
|
+
stdio: 'ignore',
|
|
116
|
+
windowsHide: true,
|
|
117
|
+
});
|
|
118
|
+
return !res.error && res.status === 0;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* @returns {{command: string, args: string[], via: 'path'|'python'} | null}
|
|
123
|
+
*/
|
|
124
|
+
function resolveKitty({
|
|
125
|
+
env = process.env,
|
|
126
|
+
platform = process.platform,
|
|
127
|
+
selfPath,
|
|
128
|
+
fsImpl = fs,
|
|
129
|
+
run = spawnSync,
|
|
130
|
+
} = {}) {
|
|
131
|
+
if (!env[GUARD_ENV]) {
|
|
132
|
+
const found = findKittyOnPath({ env, platform, selfPath, fsImpl });
|
|
133
|
+
if (found) return { command: found, args: [], via: 'path' };
|
|
134
|
+
}
|
|
135
|
+
for (const python of pythonCandidates(env, platform)) {
|
|
136
|
+
if (canImport(python, env, run)) {
|
|
137
|
+
return { command: python, args: ['-m', 'gamecomposer.cli'], via: 'python' };
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
return null;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
module.exports = {
|
|
144
|
+
GUARD_ENV,
|
|
145
|
+
LAUNCHER_MARKER,
|
|
146
|
+
INSTALL_HINT,
|
|
147
|
+
NOT_FOUND_EXIT,
|
|
148
|
+
isPythonScript,
|
|
149
|
+
pathCandidates,
|
|
150
|
+
findKittyOnPath,
|
|
151
|
+
pythonCandidates,
|
|
152
|
+
canImport,
|
|
153
|
+
resolveKitty,
|
|
154
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,37 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kitty-game-composer/cli",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "npm launcher for the Kitty game composer CLI (the Python package kitty-game-composer)",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "EnzoVezzaro",
|
|
7
|
+
"homepage": "https://github.com/EnzoVezzaro/game-composer/tree/main/cli-npm#readme",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/EnzoVezzaro/game-composer.git",
|
|
11
|
+
"directory": "cli-npm"
|
|
12
|
+
},
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/EnzoVezzaro/game-composer/issues"
|
|
15
|
+
},
|
|
16
|
+
"keywords": [
|
|
17
|
+
"kitty",
|
|
18
|
+
"game-composer",
|
|
19
|
+
"cli",
|
|
20
|
+
"launcher",
|
|
21
|
+
"emulation",
|
|
22
|
+
"homebrew"
|
|
23
|
+
],
|
|
24
|
+
"bin": {
|
|
25
|
+
"kitty": "bin/kitty.js"
|
|
26
|
+
},
|
|
27
|
+
"files": ["bin", "lib", "README.md", "LICENSE"],
|
|
28
|
+
"engines": {
|
|
29
|
+
"node": ">=18"
|
|
30
|
+
},
|
|
31
|
+
"publishConfig": {
|
|
32
|
+
"access": "public"
|
|
33
|
+
},
|
|
34
|
+
"scripts": {
|
|
35
|
+
"test": "node --test"
|
|
36
|
+
}
|
|
37
|
+
}
|