@hyperlensdev/hyperlens 0.0.0-stage → 0.1.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/bin/hyperlens.js +22 -0
- package/lib/binary.js +53 -0
- package/lib/strings.js +7 -0
- package/package.json +30 -4
- package/README.md +0 -3
package/bin/hyperlens.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Lance le binaire hyperlens adapté à la machine, en lui transmettant arguments, sorties et signaux.
|
|
3
|
+
import { spawn } from 'node:child_process';
|
|
4
|
+
import { binaryPath } from '../lib/binary.js';
|
|
5
|
+
|
|
6
|
+
let bin;
|
|
7
|
+
try {
|
|
8
|
+
bin = binaryPath();
|
|
9
|
+
} catch (err) {
|
|
10
|
+
console.error(err.message);
|
|
11
|
+
process.exit(1);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const child = spawn(bin, process.argv.slice(2), { stdio: 'inherit' });
|
|
15
|
+
for (const signal of ['SIGINT', 'SIGTERM']) {
|
|
16
|
+
process.on(signal, () => child.kill(signal));
|
|
17
|
+
}
|
|
18
|
+
child.on('error', (err) => {
|
|
19
|
+
console.error(err.message);
|
|
20
|
+
process.exit(1);
|
|
21
|
+
});
|
|
22
|
+
child.on('exit', (code, signal) => process.exit(code ?? (signal ? 1 : 0)));
|
package/lib/binary.js
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
// Choix et emplacement du binaire hyperlens adapté à la machine.
|
|
2
|
+
// Chaque binaire est publié dans un paquet npm par plateforme, déclaré en optionalDependencies :
|
|
3
|
+
// npm n'installe que celui qui correspond au système et au processeur (champs os et cpu).
|
|
4
|
+
import { createRequire } from 'node:module';
|
|
5
|
+
import { strings } from './strings.js';
|
|
6
|
+
|
|
7
|
+
const require = createRequire(import.meta.url);
|
|
8
|
+
|
|
9
|
+
export const NAME = 'hyperlens';
|
|
10
|
+
export const SCOPE = '@hyperlensdev';
|
|
11
|
+
|
|
12
|
+
// Cibles publiées, en noms Node (process.platform, process.arch), et leur équivalent Go (GOOS, GOARCH).
|
|
13
|
+
export const TARGETS = [
|
|
14
|
+
{ platform: 'darwin', arch: 'x64', goos: 'darwin', goarch: 'amd64' },
|
|
15
|
+
{ platform: 'darwin', arch: 'arm64', goos: 'darwin', goarch: 'arm64' },
|
|
16
|
+
{ platform: 'linux', arch: 'x64', goos: 'linux', goarch: 'amd64' },
|
|
17
|
+
{ platform: 'linux', arch: 'arm64', goos: 'linux', goarch: 'arm64' },
|
|
18
|
+
{ platform: 'win32', arch: 'x64', goos: 'windows', goarch: 'amd64' },
|
|
19
|
+
{ platform: 'win32', arch: 'arm64', goos: 'windows', goarch: 'arm64' },
|
|
20
|
+
];
|
|
21
|
+
|
|
22
|
+
function target(platform, arch) {
|
|
23
|
+
const t = TARGETS.find((t) => t.platform === platform && t.arch === arch);
|
|
24
|
+
if (!t) throw new Error(strings.unsupported(platform, arch));
|
|
25
|
+
return t;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// Paquet npm du binaire d'une plateforme, par exemple @hyperlensdev/hyperlens-darwin-arm64.
|
|
29
|
+
export function platformPackage(platform = process.platform, arch = process.arch) {
|
|
30
|
+
target(platform, arch);
|
|
31
|
+
return `${SCOPE}/${NAME}-${platform}-${arch}`;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// Nom du binaire dans le dossier bin/ du paquet de plateforme.
|
|
35
|
+
export function binaryName(platform = process.platform) {
|
|
36
|
+
return platform === 'win32' ? `${NAME}.exe` : NAME;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// Nom du binaire produit par make dist, par exemple hyperlens-darwin-arm64.
|
|
40
|
+
export function distName(platform, arch) {
|
|
41
|
+
const { goos, goarch } = target(platform, arch);
|
|
42
|
+
return `${NAME}-${goos}-${goarch}${goos === 'windows' ? '.exe' : ''}`;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// Chemin du binaire installé avec le paquet de la plateforme.
|
|
46
|
+
export function binaryPath(platform = process.platform, arch = process.arch, resolve = require.resolve) {
|
|
47
|
+
const pkg = platformPackage(platform, arch);
|
|
48
|
+
try {
|
|
49
|
+
return resolve(`${pkg}/bin/${binaryName(platform)}`);
|
|
50
|
+
} catch {
|
|
51
|
+
throw new Error(strings.missing(pkg));
|
|
52
|
+
}
|
|
53
|
+
}
|
package/lib/strings.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
// Toutes les chaînes du paquet npm, regroupées pour une traduction ultérieure.
|
|
2
|
+
export const strings = {
|
|
3
|
+
unsupported: (platform, arch) => `plateforme non supportée : ${platform}/${arch}`,
|
|
4
|
+
missing: (pkg) =>
|
|
5
|
+
`hyperlens : le binaire de ta plateforme (${pkg}) n'est pas installé. ` +
|
|
6
|
+
`Réinstalle sans --omit=optional ni --no-optional.`,
|
|
7
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,32 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hyperlensdev/hyperlens",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Galerie locale de prototypes d'écrans écrits en React, pour n'importe quel projet",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"bin": {
|
|
8
|
+
"hyperlens": "bin/hyperlens.js"
|
|
9
|
+
},
|
|
10
|
+
"files": [
|
|
11
|
+
"bin",
|
|
12
|
+
"lib"
|
|
13
|
+
],
|
|
14
|
+
"engines": {
|
|
15
|
+
"node": ">=18"
|
|
16
|
+
},
|
|
17
|
+
"repository": {
|
|
18
|
+
"type": "git",
|
|
19
|
+
"url": "git+https://github.com/hyperlensapp/hyperlens-cli.git"
|
|
20
|
+
},
|
|
21
|
+
"scripts": {
|
|
22
|
+
"test": "node --test test/binary.test.js"
|
|
23
|
+
},
|
|
24
|
+
"optionalDependencies": {
|
|
25
|
+
"@hyperlensdev/hyperlens-darwin-x64": "0.1.0",
|
|
26
|
+
"@hyperlensdev/hyperlens-darwin-arm64": "0.1.0",
|
|
27
|
+
"@hyperlensdev/hyperlens-linux-x64": "0.1.0",
|
|
28
|
+
"@hyperlensdev/hyperlens-linux-arm64": "0.1.0",
|
|
29
|
+
"@hyperlensdev/hyperlens-win32-x64": "0.1.0",
|
|
30
|
+
"@hyperlensdev/hyperlens-win32-arm64": "0.1.0"
|
|
31
|
+
}
|
|
32
|
+
}
|
package/README.md
DELETED