three-live 1.2.4 → 1.3.1
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 +2 -2
- package/dist/index.d.ts +58 -0
- package/dist/three-author-engine.js +89 -63
- package/dist/three-author.cjs +88 -62
- package/dist/three-author.d.ts +58 -0
- package/dist/three-author.js +87 -61
- package/dist/three-convert.cjs +81 -59
- package/dist/three-convert.d.ts +58 -0
- package/dist/three-convert.js +80 -58
- package/dist/three-live-animation.cjs +8 -9
- package/dist/three-live-animation.d.ts +58 -0
- package/dist/three-live-animation.js +7 -8
- package/dist/three-live-animation.min.js +6 -7
- package/dist/three-live-cad.cjs +3 -4
- package/dist/three-live-cad.d.ts +58 -0
- package/dist/three-live-cad.js +2 -3
- package/dist/three-live-cad.min.js +3 -4
- package/dist/three-live-cli.js +231 -0
- package/dist/three-live-element.cjs +20 -21
- package/dist/three-live-element.d.ts +58 -0
- package/dist/three-live-element.js +19 -20
- package/dist/three-live-full.cjs +113 -87
- package/dist/three-live-full.js +110 -84
- package/dist/three-live-full.min.js +113 -87
- package/dist/three-live-studio.cjs +19 -20
- package/dist/three-live-studio.d.ts +58 -0
- package/dist/three-live-studio.js +18 -19
- package/dist/three-live-studio.min.js +18 -19
- package/dist/three-live-viewer.cjs +20 -21
- package/dist/three-live-viewer.d.ts +58 -0
- package/dist/three-live-viewer.js +19 -20
- package/dist/three-live-viewer.min.js +20 -21
- package/dist/three-live.cjs +90 -64
- package/dist/three-live.js +89 -63
- package/dist/three-live.min.js +89 -63
- package/dist/three-view.cjs +18 -19
- package/dist/three-view.d.ts +58 -0
- package/dist/three-view.js +19 -20
- package/dist/three-xr.cjs +81 -59
- package/dist/three-xr.d.ts +58 -0
- package/dist/three-xr.js +80 -58
- package/package.json +7 -1
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Copyright 2026 Google LLC
|
|
3
|
+
//
|
|
4
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
// you may not use this file except in compliance with the License.
|
|
6
|
+
// You may obtain a copy of the License at
|
|
7
|
+
//
|
|
8
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
//
|
|
10
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
// See the License for the specific language governing permissions and
|
|
14
|
+
// limitations under the License.
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* @fileoverview Zero-install Node/npx launcher for `three-live-cli`.
|
|
18
|
+
*
|
|
19
|
+
* Locates a locally compiled `three-live-cli` binary (`compiler/target/release`
|
|
20
|
+
* or `compiler/target/debug`) or downloads the matching platform binary from
|
|
21
|
+
* GitHub Releases into `~/.cache/three-live/v<version>/` on first invocation.
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
'use strict';
|
|
25
|
+
|
|
26
|
+
const fs = require('fs');
|
|
27
|
+
const os = require('os');
|
|
28
|
+
const path = require('path');
|
|
29
|
+
const https = require('https');
|
|
30
|
+
const {spawnSync} = require('child_process');
|
|
31
|
+
|
|
32
|
+
const pkg = require('../package.json');
|
|
33
|
+
|
|
34
|
+
function resolvePlatformInfo(platform = process.platform, arch = process.arch) {
|
|
35
|
+
const ext = platform === 'win32' ? '.exe' : '';
|
|
36
|
+
const osTag =
|
|
37
|
+
platform === 'darwin'
|
|
38
|
+
? 'macos'
|
|
39
|
+
: platform === 'win32'
|
|
40
|
+
? 'windows'
|
|
41
|
+
: 'linux';
|
|
42
|
+
const archTag =
|
|
43
|
+
arch === 'arm64'
|
|
44
|
+
? platform === 'darwin'
|
|
45
|
+
? 'arm64'
|
|
46
|
+
: 'aarch64'
|
|
47
|
+
: 'x86_64';
|
|
48
|
+
const artifactName = `three-live-cli-${osTag}-${archTag}${ext}`;
|
|
49
|
+
const parentDir = path.resolve(__dirname, '..');
|
|
50
|
+
const grandparentDir = path.resolve(__dirname, '../..');
|
|
51
|
+
const cacheDir = path.join(
|
|
52
|
+
os.homedir() || os.tmpdir(),
|
|
53
|
+
'.cache',
|
|
54
|
+
'three-live',
|
|
55
|
+
`v${pkg.version}`,
|
|
56
|
+
);
|
|
57
|
+
const cachedBin = path.join(cacheDir, artifactName);
|
|
58
|
+
const localRoots = [];
|
|
59
|
+
if (process.env.THREE_LIVE_CLI_SKIP_LOCAL !== '1') {
|
|
60
|
+
localRoots.push(parentDir);
|
|
61
|
+
if (fs.existsSync(path.join(grandparentDir, 'compiler', 'Cargo.toml'))) {
|
|
62
|
+
localRoots.push(grandparentDir);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
const localCandidates = [];
|
|
66
|
+
for (const root of localRoots) {
|
|
67
|
+
localCandidates.push(
|
|
68
|
+
path.join(root, 'target', 'release', `three-live-cli${ext}`),
|
|
69
|
+
path.join(root, 'compiler', 'target', 'release', `three-live-cli${ext}`),
|
|
70
|
+
path.join(root, 'target', 'debug', `three-live-cli${ext}`),
|
|
71
|
+
path.join(root, 'compiler', 'target', 'debug', `three-live-cli${ext}`),
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
const candidatePaths = [
|
|
75
|
+
process.env.THREE_LIVE_CLI_BIN || '',
|
|
76
|
+
...localCandidates,
|
|
77
|
+
cachedBin,
|
|
78
|
+
].filter(Boolean);
|
|
79
|
+
const releaseUrl = `https://github.com/google/three-live/releases/download/v${pkg.version}/${artifactName}`;
|
|
80
|
+
const latestReleaseUrl = `https://github.com/google/three-live/releases/latest/download/${artifactName}`;
|
|
81
|
+
return {
|
|
82
|
+
version: pkg.version,
|
|
83
|
+
platform,
|
|
84
|
+
arch,
|
|
85
|
+
artifactName,
|
|
86
|
+
releaseUrl,
|
|
87
|
+
latestReleaseUrl,
|
|
88
|
+
cachedBin,
|
|
89
|
+
localCandidates,
|
|
90
|
+
candidatePaths,
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function findExistingBinary(info) {
|
|
95
|
+
if (
|
|
96
|
+
process.env.THREE_LIVE_CLI_BIN &&
|
|
97
|
+
fs.existsSync(process.env.THREE_LIVE_CLI_BIN)
|
|
98
|
+
) {
|
|
99
|
+
return process.env.THREE_LIVE_CLI_BIN;
|
|
100
|
+
}
|
|
101
|
+
const localSet = new Set(info.localCandidates || []);
|
|
102
|
+
let newestLocal = null;
|
|
103
|
+
let newestMtime = -1;
|
|
104
|
+
for (const candidate of info.candidatePaths) {
|
|
105
|
+
if (!fs.existsSync(candidate)) continue;
|
|
106
|
+
if (localSet.has(candidate)) {
|
|
107
|
+
try {
|
|
108
|
+
const mtime = fs.statSync(candidate).mtimeMs;
|
|
109
|
+
if (mtime > newestMtime) {
|
|
110
|
+
newestMtime = mtime;
|
|
111
|
+
newestLocal = candidate;
|
|
112
|
+
}
|
|
113
|
+
} catch (_) {
|
|
114
|
+
if (!newestLocal) newestLocal = candidate;
|
|
115
|
+
}
|
|
116
|
+
} else if (!newestLocal) {
|
|
117
|
+
return candidate;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
return newestLocal;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function downloadFile(url, destPath, redirectsLeft = 5) {
|
|
124
|
+
return new Promise((resolve, reject) => {
|
|
125
|
+
https
|
|
126
|
+
.get(url, {headers: {'User-Agent': 'three-live-cli'}}, (res) => {
|
|
127
|
+
if (
|
|
128
|
+
res.statusCode &&
|
|
129
|
+
res.statusCode >= 300 &&
|
|
130
|
+
res.statusCode < 400 &&
|
|
131
|
+
res.headers.location
|
|
132
|
+
) {
|
|
133
|
+
res.resume();
|
|
134
|
+
if (redirectsLeft <= 0) {
|
|
135
|
+
reject(
|
|
136
|
+
new Error('Too many HTTP redirects downloading three-live-cli'),
|
|
137
|
+
);
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
const nextUrl = new URL(res.headers.location, url).toString();
|
|
141
|
+
downloadFile(nextUrl, destPath, redirectsLeft - 1).then(
|
|
142
|
+
resolve,
|
|
143
|
+
reject,
|
|
144
|
+
);
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
if (res.statusCode !== 200) {
|
|
148
|
+
res.resume();
|
|
149
|
+
const err = new Error(`HTTP ${res.statusCode} for ${url}`);
|
|
150
|
+
err.statusCode = res.statusCode;
|
|
151
|
+
reject(err);
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
fs.mkdirSync(path.dirname(destPath), {recursive: true});
|
|
155
|
+
const file = fs.createWriteStream(destPath, {mode: 0o755});
|
|
156
|
+
res.pipe(file);
|
|
157
|
+
file.on('finish', () => {
|
|
158
|
+
file.close(() => {
|
|
159
|
+
try {
|
|
160
|
+
fs.chmodSync(destPath, 0o755);
|
|
161
|
+
} catch (_) {}
|
|
162
|
+
resolve(destPath);
|
|
163
|
+
});
|
|
164
|
+
});
|
|
165
|
+
file.on('error', (err) => {
|
|
166
|
+
try {
|
|
167
|
+
fs.unlinkSync(destPath);
|
|
168
|
+
} catch (_) {}
|
|
169
|
+
reject(err);
|
|
170
|
+
});
|
|
171
|
+
})
|
|
172
|
+
.on('error', reject);
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
async function main() {
|
|
177
|
+
const rawArgs = process.argv.slice(2);
|
|
178
|
+
const invokedBin = path.basename(process.argv[1] || '', '.js');
|
|
179
|
+
const args =
|
|
180
|
+
rawArgs.length === 0 &&
|
|
181
|
+
(invokedBin === 'three-live-mcp' || !process.stdin.isTTY)
|
|
182
|
+
? ['mcp']
|
|
183
|
+
: rawArgs;
|
|
184
|
+
const info = resolvePlatformInfo();
|
|
185
|
+
|
|
186
|
+
if (args.includes('--locate-only')) {
|
|
187
|
+
const found = findExistingBinary(info);
|
|
188
|
+
process.stdout.write(
|
|
189
|
+
JSON.stringify({...info, resolvedBinary: found}, null, 2) + '\n',
|
|
190
|
+
);
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
let binPath = findExistingBinary(info);
|
|
195
|
+
if (!binPath) {
|
|
196
|
+
try {
|
|
197
|
+
binPath = await downloadFile(info.releaseUrl, info.cachedBin);
|
|
198
|
+
} catch (err) {
|
|
199
|
+
if (err && err.statusCode === 404 && info.latestReleaseUrl) {
|
|
200
|
+
try {
|
|
201
|
+
binPath = await downloadFile(info.latestReleaseUrl, info.cachedBin);
|
|
202
|
+
} catch (fallbackErr) {
|
|
203
|
+
process.stderr.write(
|
|
204
|
+
`[three-live-cli] Prebuilt binary not found locally and could not be downloaded (${fallbackErr.message}).\n` +
|
|
205
|
+
`Build locally with: cargo build --release --manifest-path compiler/Cargo.toml --bin three-live-cli\n`,
|
|
206
|
+
);
|
|
207
|
+
process.exit(1);
|
|
208
|
+
}
|
|
209
|
+
} else {
|
|
210
|
+
process.stderr.write(
|
|
211
|
+
`[three-live-cli] Prebuilt binary not found locally and could not be downloaded (${err.message}).\n` +
|
|
212
|
+
`Build locally with: cargo build --release --manifest-path compiler/Cargo.toml --bin three-live-cli\n`,
|
|
213
|
+
);
|
|
214
|
+
process.exit(1);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
const result = spawnSync(binPath, args, {stdio: 'inherit'});
|
|
220
|
+
if (result.error) {
|
|
221
|
+
process.stderr.write(`[three-live-cli] Failed to spawn ${binPath}: ${result.error.message}\n`);
|
|
222
|
+
process.exit(1);
|
|
223
|
+
}
|
|
224
|
+
process.exit(result.status ?? 0);
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
if (require.main === module) {
|
|
228
|
+
main();
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
module.exports = {resolvePlatformInfo, findExistingBinary};
|