@fulgur-rs/cli 0.0.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 (2) hide show
  1. package/install.js +89 -0
  2. package/package.json +23 -0
package/install.js ADDED
@@ -0,0 +1,89 @@
1
+ #!/usr/bin/env node
2
+ 'use strict';
3
+
4
+ const fs = require('fs');
5
+ const path = require('path');
6
+
7
+ const PLATFORMS = {
8
+ 'linux-x64': { os: 'linux', cpu: 'x64', pkg: '@fulgur-rs/cli-linux-x64', bin: 'fulgur' },
9
+ 'linux-x64-musl': { os: 'linux', cpu: 'x64', pkg: '@fulgur-rs/cli-linux-x64-musl', bin: 'fulgur' },
10
+ 'linux-arm64': { os: 'linux', cpu: 'arm64', pkg: '@fulgur-rs/cli-linux-arm64', bin: 'fulgur' },
11
+ 'darwin-arm64': { os: 'darwin', cpu: 'arm64', pkg: '@fulgur-rs/cli-darwin-arm64', bin: 'fulgur' },
12
+ 'darwin-x64': { os: 'darwin', cpu: 'x64', pkg: '@fulgur-rs/cli-darwin-x64', bin: 'fulgur' },
13
+ 'win32-x64': { os: 'win32', cpu: 'x64', pkg: '@fulgur-rs/cli-win32-x64', bin: 'fulgur.exe' },
14
+ };
15
+
16
+ function isMusl() {
17
+ try {
18
+ const maps = fs.readFileSync('/proc/self/maps', 'utf8');
19
+ return maps.includes('musl');
20
+ } catch {
21
+ return false;
22
+ }
23
+ }
24
+
25
+ function detectPlatformKey() {
26
+ const os = process.platform;
27
+ const cpu = process.arch;
28
+
29
+ if (os === 'linux' && cpu === 'x64') {
30
+ return isMusl() ? 'linux-x64-musl' : 'linux-x64';
31
+ }
32
+ if (os === 'linux' && cpu === 'arm64') return 'linux-arm64';
33
+ if (os === 'darwin' && cpu === 'arm64') return 'darwin-arm64';
34
+ if (os === 'darwin' && cpu === 'x64') return 'darwin-x64';
35
+ if (os === 'win32' && cpu === 'x64') return 'win32-x64';
36
+ return null;
37
+ }
38
+
39
+ const platformKey = detectPlatformKey();
40
+ if (!platformKey) {
41
+ process.stderr.write(
42
+ `@fulgur-rs/cli: unsupported platform ${process.platform}/${process.arch}\n`
43
+ );
44
+ process.exit(1);
45
+ }
46
+
47
+ const platform = PLATFORMS[platformKey];
48
+ let pkgDir;
49
+ try {
50
+ pkgDir = path.dirname(require.resolve(`${platform.pkg}/package.json`));
51
+ } catch {
52
+ process.stderr.write(
53
+ `@fulgur-rs/cli: platform package ${platform.pkg} not found.\n` +
54
+ `This usually means it was not installed (e.g., --ignore-optional was used).\n`
55
+ );
56
+ process.exit(1);
57
+ }
58
+
59
+ const src = path.join(pkgDir, 'bin', platform.bin);
60
+ const destDir = path.join(__dirname, 'bin');
61
+ const dest = path.join(destDir, platform.bin);
62
+
63
+ if (!fs.existsSync(src)) {
64
+ process.stderr.write(
65
+ `@fulgur-rs/cli: binary not found at ${src}\n` +
66
+ `The platform package ${platform.pkg} may be corrupted or incomplete.\n`
67
+ );
68
+ process.exit(1);
69
+ }
70
+
71
+ fs.mkdirSync(destDir, { recursive: true });
72
+ fs.copyFileSync(src, dest);
73
+ if (process.platform !== 'win32') {
74
+ fs.chmodSync(dest, 0o755);
75
+ } else {
76
+ // Windows: npm の bin フィールドは拡張子なし "bin/fulgur" を参照するため、
77
+ // .exe を起動する JS シムを書き込む
78
+ const shimPath = path.join(destDir, 'fulgur');
79
+ const shimContent = [
80
+ '#!/usr/bin/env node',
81
+ "'use strict';",
82
+ "const { spawnSync } = require('child_process');",
83
+ "const path = require('path');",
84
+ "const r = spawnSync(path.join(__dirname, 'fulgur.exe'), process.argv.slice(2), { stdio: 'inherit' });",
85
+ 'process.exit(r.status ?? 1);',
86
+ '',
87
+ ].join('\n');
88
+ fs.writeFileSync(shimPath, shimContent, { encoding: 'utf8' });
89
+ }
package/package.json ADDED
@@ -0,0 +1,23 @@
1
+ {
2
+ "name": "@fulgur-rs/cli",
3
+ "version": "0.0.0",
4
+ "description": "HTML to PDF conversion CLI",
5
+ "keywords": ["html", "pdf", "cli"],
6
+ "license": "MIT OR Apache-2.0",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/fulgur-rs/fulgur.git",
10
+ "directory": "packages/npm/meta"
11
+ },
12
+ "bin": { "fulgur": "bin/fulgur" },
13
+ "files": ["bin/", "install.js"],
14
+ "scripts": { "postinstall": "node install.js" },
15
+ "optionalDependencies": {
16
+ "@fulgur-rs/cli-linux-x64": "0.0.0",
17
+ "@fulgur-rs/cli-linux-x64-musl": "0.0.0",
18
+ "@fulgur-rs/cli-linux-arm64": "0.0.0",
19
+ "@fulgur-rs/cli-darwin-arm64": "0.0.0",
20
+ "@fulgur-rs/cli-darwin-x64": "0.0.0",
21
+ "@fulgur-rs/cli-win32-x64": "0.0.0"
22
+ }
23
+ }