glyx-cli 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/glyx.js +24 -0
- package/install.js +79 -0
- package/package.json +23 -0
package/bin/glyx.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Thin launcher: executes the platform `glyx` binary downloaded by install.js.
|
|
3
|
+
'use strict';
|
|
4
|
+
|
|
5
|
+
const path = require('path');
|
|
6
|
+
const fs = require('fs');
|
|
7
|
+
const { spawnSync } = require('child_process');
|
|
8
|
+
|
|
9
|
+
const suffix = process.platform === 'win32' ? '.exe' : '';
|
|
10
|
+
const bin = path.join(__dirname, `glyx-bin${suffix}`);
|
|
11
|
+
|
|
12
|
+
if (!fs.existsSync(bin)) {
|
|
13
|
+
// Postinstall may have been skipped (--ignore-scripts, offline) — retry once.
|
|
14
|
+
console.log('glyx: binary not found, downloading…');
|
|
15
|
+
const r = spawnSync(process.execPath, [path.join(__dirname, '..', 'install.js')], { stdio: 'inherit' });
|
|
16
|
+
if (r.status !== 0 || !fs.existsSync(bin)) {
|
|
17
|
+
console.error('glyx: could not install the binary.');
|
|
18
|
+
console.error('Install directly: https://github.com/glyx-dev/glyx/releases');
|
|
19
|
+
process.exit(1);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const result = spawnSync(bin, process.argv.slice(2), { stdio: 'inherit' });
|
|
24
|
+
process.exit(result.status ?? 1);
|
package/install.js
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
// glyx-cli postinstall — downloads the platform `glyx` binary from GitHub
|
|
2
|
+
// Releases into this package's bin/ directory. The version downloaded
|
|
3
|
+
// matches this package's version (tag v<version>), falling back to latest.
|
|
4
|
+
//
|
|
5
|
+
// Skip with GLYX_SKIP_DOWNLOAD=1 (e.g. CI that only needs the JS packages).
|
|
6
|
+
'use strict';
|
|
7
|
+
|
|
8
|
+
const fs = require('fs');
|
|
9
|
+
const path = require('path');
|
|
10
|
+
const https = require('https');
|
|
11
|
+
|
|
12
|
+
const REPO = 'glyx-dev/glyx';
|
|
13
|
+
const VERSION = require('./package.json').version;
|
|
14
|
+
|
|
15
|
+
function target() {
|
|
16
|
+
const { platform, arch } = process;
|
|
17
|
+
if (platform === 'win32' && arch === 'x64') return 'x86_64-pc-windows-msvc';
|
|
18
|
+
if (platform === 'darwin' && arch === 'arm64') return 'aarch64-apple-darwin';
|
|
19
|
+
if (platform === 'darwin' && arch === 'x64') return 'x86_64-apple-darwin';
|
|
20
|
+
if (platform === 'linux' && arch === 'x64') return 'x86_64-unknown-linux-gnu';
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// Follows redirects (GitHub release downloads redirect to S3).
|
|
25
|
+
function download(url, dest, redirects = 5) {
|
|
26
|
+
return new Promise((resolve, reject) => {
|
|
27
|
+
https.get(url, { headers: { 'User-Agent': 'glyx-cli-installer' } }, (res) => {
|
|
28
|
+
if (res.statusCode >= 300 && res.statusCode < 400 && res.headers.location && redirects > 0) {
|
|
29
|
+
res.resume();
|
|
30
|
+
return resolve(download(res.headers.location, dest, redirects - 1));
|
|
31
|
+
}
|
|
32
|
+
if (res.statusCode !== 200) {
|
|
33
|
+
res.resume();
|
|
34
|
+
return reject(new Error(`HTTP ${res.statusCode} for ${url}`));
|
|
35
|
+
}
|
|
36
|
+
const file = fs.createWriteStream(dest);
|
|
37
|
+
res.pipe(file);
|
|
38
|
+
file.on('finish', () => file.close(resolve));
|
|
39
|
+
file.on('error', reject);
|
|
40
|
+
}).on('error', reject);
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
async function main() {
|
|
45
|
+
if (process.env.GLYX_SKIP_DOWNLOAD === '1') {
|
|
46
|
+
console.log('glyx-cli: GLYX_SKIP_DOWNLOAD=1 — skipping binary download');
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
const t = target();
|
|
50
|
+
if (!t) {
|
|
51
|
+
console.warn(`glyx-cli: no prebuilt binary for ${process.platform}/${process.arch}.`);
|
|
52
|
+
console.warn('Build from source: https://github.com/' + REPO);
|
|
53
|
+
return; // don't fail the whole npm install
|
|
54
|
+
}
|
|
55
|
+
const suffix = process.platform === 'win32' ? '.exe' : '';
|
|
56
|
+
const artifact = `glyx-${t}${suffix}`;
|
|
57
|
+
const dest = path.join(__dirname, 'bin', `glyx-bin${suffix}`);
|
|
58
|
+
fs.mkdirSync(path.dirname(dest), { recursive: true });
|
|
59
|
+
|
|
60
|
+
const urls = [
|
|
61
|
+
`https://github.com/${REPO}/releases/download/v${VERSION}/${artifact}`,
|
|
62
|
+
`https://github.com/${REPO}/releases/latest/download/${artifact}`,
|
|
63
|
+
];
|
|
64
|
+
for (const url of urls) {
|
|
65
|
+
try {
|
|
66
|
+
console.log(`glyx-cli: downloading ${artifact}…`);
|
|
67
|
+
await download(url, dest);
|
|
68
|
+
if (process.platform !== 'win32') fs.chmodSync(dest, 0o755);
|
|
69
|
+
console.log('glyx-cli: installed ✓');
|
|
70
|
+
return;
|
|
71
|
+
} catch (e) {
|
|
72
|
+
console.warn(`glyx-cli: ${e.message}`);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
console.warn('glyx-cli: download failed — run `node ' + path.join(__dirname, 'install.js') + '` to retry,');
|
|
76
|
+
console.warn('or install directly: https://github.com/' + REPO + '/releases');
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
main().catch((e) => { console.warn('glyx-cli install error:', e.message); });
|
package/package.json
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "glyx-cli",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Glyx CLI — build native desktop apps with React. Installs the platform glyx binary.",
|
|
5
|
+
"license": "MIT OR Apache-2.0",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/glyx-dev/glyx.git",
|
|
9
|
+
"directory": "js/packages/glyx-cli"
|
|
10
|
+
},
|
|
11
|
+
"homepage": "https://glyx.dev",
|
|
12
|
+
"keywords": ["glyx", "desktop", "react", "native", "cli"],
|
|
13
|
+
"bin": {
|
|
14
|
+
"glyx": "bin/glyx.js"
|
|
15
|
+
},
|
|
16
|
+
"files": ["bin", "install.js", "README.md"],
|
|
17
|
+
"scripts": {
|
|
18
|
+
"postinstall": "node install.js"
|
|
19
|
+
},
|
|
20
|
+
"engines": {
|
|
21
|
+
"node": ">=18"
|
|
22
|
+
}
|
|
23
|
+
}
|