@kramario/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.
Files changed (3) hide show
  1. package/bin/kramar.js +75 -0
  2. package/package.json +10 -4
  3. package/README.md +0 -3
package/bin/kramar.js ADDED
@@ -0,0 +1,75 @@
1
+ #!/usr/bin/env node
2
+ // Обгортка npm для CLI `kramar` (Rust-бінарник). Бінарник не лежить у пакеті:
3
+ // при першому запуску береться з https://kramar.io/cli/v<версія пакета>/,
4
+ // звіряється з sha256 і кешується поруч (`vendor/<версія>/`). Далі — просто
5
+ // запуск із тими самими аргументами й кодом виходу.
6
+ 'use strict';
7
+ const { createHash } = require('node:crypto');
8
+ const { spawnSync } = require('node:child_process');
9
+ const fs = require('node:fs');
10
+ const os = require('node:os');
11
+ const path = require('node:path');
12
+
13
+ const VERSION = require('../package.json').version;
14
+ const BASE = process.env.KRAMAR_CLI_BASE || 'https://kramar.io/cli';
15
+
16
+ function target() {
17
+ const arch = { x64: 'x86_64', arm64: 'aarch64' }[process.arch];
18
+ if (!arch) throw new Error(`непідтримувана архітектура ${process.arch}`);
19
+ switch (process.platform) {
20
+ case 'darwin': return `${arch}-apple-darwin`;
21
+ case 'linux': return `${arch}-unknown-linux-musl`;
22
+ case 'win32':
23
+ if (arch !== 'x86_64') throw new Error('на Windows підтримується лише x64');
24
+ return 'x86_64-pc-windows-gnu';
25
+ default: throw new Error(`непідтримувана ОС ${process.platform}`);
26
+ }
27
+ }
28
+
29
+ async function download(url) {
30
+ const res = await fetch(url);
31
+ if (!res.ok) throw new Error(`${url} → ${res.status}`);
32
+ return Buffer.from(await res.arrayBuffer());
33
+ }
34
+
35
+ async function ensure() {
36
+ const t = target();
37
+ const exe = process.platform === 'win32' ? 'kramar.exe' : 'kramar';
38
+ const dir = path.join(__dirname, '..', 'vendor', VERSION);
39
+ const bin = path.join(dir, exe);
40
+ if (fs.existsSync(bin)) return bin;
41
+
42
+ const file = `kramar-${t}.${process.platform === 'win32' ? 'zip' : 'tar.gz'}`;
43
+ const url = `${BASE}/v${VERSION}/${file}`;
44
+ process.stderr.write(`kramar: завантажую ${VERSION} (${t})…\n`);
45
+ const [archive, sum] = await Promise.all([download(url), download(`${url}.sha256`)]);
46
+ const expected = sum.toString().trim().split(/\s+/)[0];
47
+ const actual = createHash('sha256').update(archive).digest('hex');
48
+ if (expected !== actual) throw new Error('контрольна сума не збіглася — файл пошкоджено');
49
+
50
+ const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'kramar-'));
51
+ try {
52
+ const arc = path.join(tmp, file);
53
+ fs.writeFileSync(arc, archive);
54
+ // `tar` є і в macOS/Linux, і в Windows 10+ (bsdtar розпаковує й zip).
55
+ const r = spawnSync('tar', ['-xf', arc, '-C', tmp], { stdio: 'inherit' });
56
+ if (r.status !== 0) throw new Error('не вдалося розпакувати архів');
57
+ fs.mkdirSync(dir, { recursive: true });
58
+ fs.copyFileSync(path.join(tmp, exe), bin);
59
+ fs.chmodSync(bin, 0o755);
60
+ } finally {
61
+ fs.rmSync(tmp, { recursive: true, force: true });
62
+ }
63
+ return bin;
64
+ }
65
+
66
+ ensure()
67
+ .then((bin) => {
68
+ const r = spawnSync(bin, process.argv.slice(2), { stdio: 'inherit' });
69
+ if (r.error) throw r.error;
70
+ process.exit(r.status ?? 1);
71
+ })
72
+ .catch((e) => {
73
+ process.stderr.write(`kramar: ${e.message}\n`);
74
+ process.exit(4);
75
+ });
package/package.json CHANGED
@@ -1,6 +1,12 @@
1
1
  {
2
2
  "name": "@kramario/cli",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.2.0",
4
+ "description": "kramar — тема магазину Kramar у git-репо: синк, прев'ю, публікація",
5
+ "bin": { "kramar": "bin/kramar.js" },
6
+ "files": ["bin/"],
7
+ "engines": { "node": ">=18" },
8
+ "homepage": "https://kramar.io",
9
+ "license": "UNLICENSED",
10
+ "os": ["darwin", "linux", "win32"],
11
+ "cpu": ["x64", "arm64"]
12
+ }
package/README.md DELETED
@@ -1,3 +0,0 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.