xinghe-muse 0.0.0-stage → 2.3.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/README.md +184 -2
- package/cordis.patch.yml +4 -0
- package/docs/DETAIL.md +198 -0
- package/icon.svg +14 -0
- package/install.ps1 +40 -0
- package/install.sh +27 -0
- package/lib/drive.mjs +104 -0
- package/lib/index.js +624 -0
- package/lib/platform.mjs +176 -0
- package/lib/run-muse.mjs +565 -0
- package/lib/setup.mjs +235 -0
- package/lib/stitch.swift +89 -0
- package/locale/en.json +8 -0
- package/locale/zh.json +8 -0
- package/package.json +43 -4
package/lib/platform.mjs
ADDED
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* xinghe-muse — 跨平台定位 ego lite 与 ego-browser。
|
|
3
|
+
*
|
|
4
|
+
* 作者:星禾
|
|
5
|
+
*
|
|
6
|
+
* macOS 与 Windows 的安装落点不一样,升级后版本号目录也会变,所以这里不写死
|
|
7
|
+
* 任何一条绝对路径,而是按「环境变量 → 已知安装根目录 → PATH」的顺序逐个试,
|
|
8
|
+
* 拿到第一个真正能执行的文件就用它。
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { access, constants, readdir, realpath } from 'node:fs/promises'
|
|
12
|
+
import { homedir, platform } from 'node:os'
|
|
13
|
+
import { delimiter, join } from 'node:path'
|
|
14
|
+
|
|
15
|
+
export const IS_WIN = platform() === 'win32'
|
|
16
|
+
export const IS_MAC = platform() === 'darwin'
|
|
17
|
+
|
|
18
|
+
/** 显式覆盖:设了就只认这个。 */
|
|
19
|
+
const ENV_BIN = process.env.EGO_BROWSER_BIN
|
|
20
|
+
/** 显式指定 ego lite 安装根目录。 */
|
|
21
|
+
const ENV_APP = process.env.EGO_LITE_APP
|
|
22
|
+
|
|
23
|
+
async function exists(target) {
|
|
24
|
+
try {
|
|
25
|
+
await access(target, constants.F_OK)
|
|
26
|
+
return true
|
|
27
|
+
} catch {
|
|
28
|
+
return false
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
async function runs(target) {
|
|
33
|
+
try {
|
|
34
|
+
await access(target, IS_WIN ? constants.F_OK : constants.X_OK)
|
|
35
|
+
return true
|
|
36
|
+
} catch {
|
|
37
|
+
return false
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** 平台约定的 ego lite 安装根目录候选。 */
|
|
42
|
+
function appCandidates() {
|
|
43
|
+
if (IS_MAC) {
|
|
44
|
+
return [
|
|
45
|
+
ENV_APP,
|
|
46
|
+
'/Applications/ego lite.app',
|
|
47
|
+
join(homedir(), 'Applications', 'ego lite.app'),
|
|
48
|
+
].filter(Boolean)
|
|
49
|
+
}
|
|
50
|
+
if (IS_WIN) {
|
|
51
|
+
const local = process.env.LOCALAPPDATA ?? join(homedir(), 'AppData', 'Local')
|
|
52
|
+
const prog = process.env.ProgramFiles ?? 'C:\\Program Files'
|
|
53
|
+
const prog86 = process.env['ProgramFiles(x86)'] ?? 'C:\\Program Files (x86)'
|
|
54
|
+
return [
|
|
55
|
+
ENV_APP,
|
|
56
|
+
join(local, 'Programs', 'ego lite'),
|
|
57
|
+
join(local, 'ego lite'),
|
|
58
|
+
join(prog, 'ego lite'),
|
|
59
|
+
join(prog86, 'ego lite'),
|
|
60
|
+
].filter(Boolean)
|
|
61
|
+
}
|
|
62
|
+
return []
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* macOS:ego-browser 的真实文件在 .app 里的版本目录下。
|
|
67
|
+
*
|
|
68
|
+
* ~/.local/share/ego/active_version_dir 是一个指向当前版本目录的软链,
|
|
69
|
+
* 升级后由 ego 自己改写,所以优先读它,读不到再枚举 Versions 目录。
|
|
70
|
+
*/
|
|
71
|
+
async function macHelperPaths(appRoot) {
|
|
72
|
+
const framework = join(appRoot, 'Contents', 'Frameworks', 'ego Framework.framework')
|
|
73
|
+
const out = []
|
|
74
|
+
|
|
75
|
+
const active = join(homedir(), '.local', 'share', 'ego', 'active_version_dir')
|
|
76
|
+
if (await exists(active)) {
|
|
77
|
+
try {
|
|
78
|
+
out.push(join(await realpath(active), 'Helpers', 'ego-browser'))
|
|
79
|
+
} catch {
|
|
80
|
+
// 软链指向的目标已经不在了,落到下面的枚举。
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const versions = join(framework, 'Versions')
|
|
85
|
+
try {
|
|
86
|
+
const entries = await readdir(versions, { withFileTypes: true })
|
|
87
|
+
for (const entry of entries) {
|
|
88
|
+
if (entry.isDirectory()) out.push(join(versions, entry.name, 'Helpers', 'ego-browser'))
|
|
89
|
+
}
|
|
90
|
+
} catch {
|
|
91
|
+
// 没有 Versions 目录就用下面的兜底路径。
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
out.push(join(framework, 'Versions', 'Current', 'Helpers', 'ego-browser'))
|
|
95
|
+
return out
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** Windows:ego-browser 通常与主程序同目录,偶尔在 bin 或 helpers 子目录。 */
|
|
99
|
+
function winHelperPaths(appRoot) {
|
|
100
|
+
return [
|
|
101
|
+
join(appRoot, 'ego-browser.exe'),
|
|
102
|
+
join(appRoot, 'ego-browser.cmd'),
|
|
103
|
+
join(appRoot, 'bin', 'ego-browser.exe'),
|
|
104
|
+
join(appRoot, 'bin', 'ego-browser.cmd'),
|
|
105
|
+
join(appRoot, 'helpers', 'ego-browser.exe'),
|
|
106
|
+
]
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/** PATH 里逐个目录找。 */
|
|
110
|
+
function pathCandidates() {
|
|
111
|
+
const names = IS_WIN ? ['ego-browser.exe', 'ego-browser.cmd', 'ego-browser'] : ['ego-browser']
|
|
112
|
+
const dirs = (process.env.PATH ?? '').split(delimiter).filter(Boolean)
|
|
113
|
+
const out = []
|
|
114
|
+
for (const dir of dirs) {
|
|
115
|
+
for (const name of names) out.push(join(dir, name))
|
|
116
|
+
}
|
|
117
|
+
return out
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* 找到可用的 ego-browser。
|
|
122
|
+
*
|
|
123
|
+
* @returns {Promise<string|null>} 绝对路径;找不到时为 null。
|
|
124
|
+
*/
|
|
125
|
+
export async function findEgoBrowser() {
|
|
126
|
+
if (ENV_BIN) return (await runs(ENV_BIN)) ? ENV_BIN : null
|
|
127
|
+
|
|
128
|
+
for (const appRoot of appCandidates()) {
|
|
129
|
+
const helpers = IS_MAC ? await macHelperPaths(appRoot) : winHelperPaths(appRoot)
|
|
130
|
+
for (const candidate of helpers) {
|
|
131
|
+
if (await runs(candidate)) return candidate
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
for (const candidate of pathCandidates()) {
|
|
136
|
+
if (await runs(candidate)) return candidate
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
return null
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/** ego lite 是否已安装(只判断安装物在不在,不判断能否运行)。 */
|
|
143
|
+
export async function findEgoApp() {
|
|
144
|
+
for (const appRoot of appCandidates()) {
|
|
145
|
+
if (await exists(appRoot)) return appRoot
|
|
146
|
+
}
|
|
147
|
+
return null
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/** 给人看的一段说明,报告平台与找不到时该往哪看。 */
|
|
151
|
+
export function platformNote() {
|
|
152
|
+
if (IS_MAC) return 'macOS:ego lite 装在 /Applications/ego lite.app'
|
|
153
|
+
if (IS_WIN) return 'Windows:ego lite 装在 %LOCALAPPDATA%\\Programs\\ego lite'
|
|
154
|
+
return `当前平台 ${platform()} 不在支持范围内(仅 macOS 与 Windows)`
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/** 桌面目录,跨平台。 */
|
|
158
|
+
export function desktopDir() {
|
|
159
|
+
const homeDesktop = join(homedir(), 'Desktop')
|
|
160
|
+
return homeDesktop
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/** muse 相关产物统一收在桌面 muse 目录下。 */
|
|
164
|
+
export function museRootDir() {
|
|
165
|
+
return join(desktopDir(), 'muse')
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/** 默认保存目录:图片。 */
|
|
169
|
+
export function defaultOutDir() {
|
|
170
|
+
return join(museRootDir(), 'muse保存图')
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/** 默认保存目录:视频。 */
|
|
174
|
+
export function defaultVideoOutDir() {
|
|
175
|
+
return join(museRootDir(), 'muse保存视频')
|
|
176
|
+
}
|