@nuphus/nuphus-desktop 0.2.14 → 0.2.15
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/nuphus.js +133 -83
- package/package.json +4 -4
package/bin/nuphus.js
CHANGED
|
@@ -1,83 +1,133 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
/**
|
|
3
|
-
* Nuphus 桌面应用启动器(npm 一键安装入口)
|
|
4
|
-
*
|
|
5
|
-
* 通过 optionalDependencies 自动选择对应平台的二进制子包:
|
|
6
|
-
* win32-x64 -> @nuphus/nuphus-desktop-win32-x64 (nuphus.exe)
|
|
7
|
-
* darwin-arm64-> @nuphus/nuphus-desktop-osx-arm64 (Nuphus.app)
|
|
8
|
-
* linux-x64 -> @nuphus/nuphus-desktop-linux-x64 (nuphus)
|
|
9
|
-
*/
|
|
10
|
-
'use strict';
|
|
11
|
-
|
|
12
|
-
const { spawn } = require('child_process');
|
|
13
|
-
const path = require('path');
|
|
14
|
-
const fs = require('fs');
|
|
15
|
-
|
|
16
|
-
const PLATFORM_MAP = {
|
|
17
|
-
'win32-x64': {
|
|
18
|
-
pkg: 'nuphus-desktop-win32-x64',
|
|
19
|
-
binary: 'nuphus.exe',
|
|
20
|
-
},
|
|
21
|
-
'darwin-arm64': {
|
|
22
|
-
pkg: 'nuphus-desktop-osx-arm64',
|
|
23
|
-
app: 'Nuphus.app',
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
console.error(
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
//
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
console.error(
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Nuphus 桌面应用启动器(npm 一键安装入口)
|
|
4
|
+
*
|
|
5
|
+
* 通过 optionalDependencies 自动选择对应平台的二进制子包:
|
|
6
|
+
* win32-x64 -> @nuphus/nuphus-desktop-win32-x64 (nuphus.exe)
|
|
7
|
+
* darwin-arm64-> @nuphus/nuphus-desktop-osx-arm64 (Nuphus.app)
|
|
8
|
+
* linux-x64 -> @nuphus/nuphus-desktop-linux-x64 (nuphus)
|
|
9
|
+
*/
|
|
10
|
+
'use strict';
|
|
11
|
+
|
|
12
|
+
const { spawn } = require('child_process');
|
|
13
|
+
const path = require('path');
|
|
14
|
+
const fs = require('fs');
|
|
15
|
+
|
|
16
|
+
const PLATFORM_MAP = {
|
|
17
|
+
'win32-x64': {
|
|
18
|
+
pkg: 'nuphus-desktop-win32-x64',
|
|
19
|
+
binary: 'nuphus.exe',
|
|
20
|
+
},
|
|
21
|
+
'darwin-arm64': {
|
|
22
|
+
pkg: 'nuphus-desktop-osx-arm64',
|
|
23
|
+
app: 'Nuphus.app',
|
|
24
|
+
binary: 'nuphus', // app bundle 内的可执行名(Contents/MacOS/nuphus)
|
|
25
|
+
},
|
|
26
|
+
'linux-x64': {
|
|
27
|
+
pkg: 'nuphus-desktop-linux-x64',
|
|
28
|
+
binary: 'nuphus',
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
function resolveVendorDir() {
|
|
33
|
+
const key = `${process.platform}-${process.arch}`;
|
|
34
|
+
const spec = PLATFORM_MAP[key];
|
|
35
|
+
if (!spec) {
|
|
36
|
+
console.error(`[nuphus] 暂不支持该平台/架构: ${key}`);
|
|
37
|
+
console.error(' 当前支持: win32-x64 / darwin-arm64 / linux-x64');
|
|
38
|
+
process.exit(1);
|
|
39
|
+
}
|
|
40
|
+
// 平台子包可能被 npm 提升到 <node_modules>/@nuphus/ 下(与主包同级),也可能被
|
|
41
|
+
// 嵌套在主包的 node_modules/@nuphus/ 下;用 Node 模块解析定位,两种布局都能命中。
|
|
42
|
+
const pkgName = `@nuphus/${spec.pkg}`;
|
|
43
|
+
let vendor;
|
|
44
|
+
try {
|
|
45
|
+
vendor = path.dirname(require.resolve(`${pkgName}/package.json`));
|
|
46
|
+
} catch (_) {
|
|
47
|
+
vendor = path.join(__dirname, '..', '..', pkgName);
|
|
48
|
+
}
|
|
49
|
+
if (!fs.existsSync(vendor)) {
|
|
50
|
+
console.error(`[nuphus] 未找到平台包: ${spec.pkg}`);
|
|
51
|
+
console.error(' 请确认安装完整(npm install -g @nuphus/nuphus-desktop)或重装。');
|
|
52
|
+
process.exit(1);
|
|
53
|
+
}
|
|
54
|
+
return { vendor, spec };
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* 补齐可执行位(幂等:已有 x 位的文件不写盘)。
|
|
59
|
+
*
|
|
60
|
+
* 背景:npm 包的发布流程跑在 Windows 上(`npm-desktop/publish.ps1` 的
|
|
61
|
+
* `Build-PlatformPackage` 用 `System32\tar.exe` 解压 Release 资产),而 NTFS 不表达
|
|
62
|
+
* Unix 可执行位 —— npm 从文件系统读到的 mode 一律是 644,于是发布包里所有文件
|
|
63
|
+
* (含 app bundle 的主二进制)都缺 x 位。macOS 上 `launchd` 会直接拒绝 spawn:
|
|
64
|
+
*
|
|
65
|
+
* open -a Nuphus.app -> Launch failed / Launchd job spawn failed
|
|
66
|
+
* 直接执行二进制 -> permission denied (126)
|
|
67
|
+
*
|
|
68
|
+
* Linux 的裸二进制同理。发布侧无法修复(Windows 设置不了 Unix mode),故在此兜底。
|
|
69
|
+
*/
|
|
70
|
+
function ensureExecutable(files) {
|
|
71
|
+
for (const file of files) {
|
|
72
|
+
try {
|
|
73
|
+
fs.accessSync(file, fs.constants.X_OK);
|
|
74
|
+
continue; // 已具备可执行位
|
|
75
|
+
} catch (_) {
|
|
76
|
+
// 落到下面补权限
|
|
77
|
+
}
|
|
78
|
+
try {
|
|
79
|
+
fs.chmodSync(file, 0o755);
|
|
80
|
+
console.error(`[nuphus] 已补齐可执行权限: ${file}`);
|
|
81
|
+
} catch (err) {
|
|
82
|
+
console.error(`[nuphus] 设置可执行权限失败: ${file} (${err.message})`);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/** macOS: app bundle 的主二进制 + Frameworks 下的动态库 */
|
|
88
|
+
function macExecutables(vendor, spec) {
|
|
89
|
+
const appDir = path.join(vendor, spec.app);
|
|
90
|
+
const files = [path.join(appDir, 'Contents', 'MacOS', spec.binary)];
|
|
91
|
+
const frameworks = path.join(appDir, 'Contents', 'Frameworks');
|
|
92
|
+
if (fs.existsSync(frameworks)) {
|
|
93
|
+
for (const name of fs.readdirSync(frameworks)) {
|
|
94
|
+
if (name.endsWith('.dylib')) {
|
|
95
|
+
files.push(path.join(frameworks, name));
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
return files;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function main() {
|
|
103
|
+
const { vendor, spec } = resolveVendorDir();
|
|
104
|
+
|
|
105
|
+
let cmd;
|
|
106
|
+
let args = [];
|
|
107
|
+
if (process.platform === 'darwin') {
|
|
108
|
+
// macOS: 先补齐可执行位,再 open -a Nuphus.app(正确的应用启动方式)
|
|
109
|
+
ensureExecutable(macExecutables(vendor, spec));
|
|
110
|
+
cmd = 'open';
|
|
111
|
+
args = ['-a', path.join(vendor, spec.app)];
|
|
112
|
+
} else {
|
|
113
|
+
cmd = path.join(vendor, spec.binary);
|
|
114
|
+
if (process.platform !== 'win32') {
|
|
115
|
+
ensureExecutable([cmd]);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
const child = spawn(cmd, args, {
|
|
120
|
+
stdio: 'ignore',
|
|
121
|
+
detached: process.platform !== 'win32',
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
child.on('error', (err) => {
|
|
125
|
+
console.error(`[nuphus] 启动失败: ${err.message}`);
|
|
126
|
+
process.exit(1);
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
child.unref();
|
|
130
|
+
console.log(`[nuphus] 正在启动 Nuphus 桌面应用…`);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
main();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nuphus/nuphus-desktop",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.15",
|
|
4
4
|
"description": "Nuphus - 协同共生桌面助手。npm 一键安装:自动选择对应平台二进制(win32-x64 / macOS arm64 / linux-x64)。",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"bin": {
|
|
@@ -11,9 +11,9 @@
|
|
|
11
11
|
"url": "git+https://github.com/mrpulor-gh/nuphus.git"
|
|
12
12
|
},
|
|
13
13
|
"optionalDependencies": {
|
|
14
|
-
"@nuphus/nuphus-desktop-win32-x64": "0.2.
|
|
15
|
-
"@nuphus/nuphus-desktop-osx-arm64": "0.2.
|
|
16
|
-
"@nuphus/nuphus-desktop-linux-x64": "0.2.
|
|
14
|
+
"@nuphus/nuphus-desktop-win32-x64": "0.2.15",
|
|
15
|
+
"@nuphus/nuphus-desktop-osx-arm64": "0.2.15",
|
|
16
|
+
"@nuphus/nuphus-desktop-linux-x64": "0.2.15"
|
|
17
17
|
},
|
|
18
18
|
"engines": {
|
|
19
19
|
"node": "\u003e=16"
|