-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.js
executable file
·48 lines (37 loc) · 1.49 KB
/
install.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/env node
const packageJson = require('./package.json');
// Local developement.
if (packageJson.version === '0.0.1-dev')
process.exit(0);
const fs = require('node:fs');
const zlib = require('node:zlib');
const {pipeline} = require('node:stream/promises');
const urlPrefix = 'https://github.com/frost-beta/executorch.js/releases/download';
main().catch((error) => {
console.error('Error downloading node-mlx:', error);
process.exit(1);
});
async function main() {
const dir = `${__dirname}/build/Release`;
fs.mkdirSync(dir, {recursive: true});
const os = {darwin: 'mac', win32: 'win'}[process.platform] ?? process.platform;
const arch = process.arch;
const version = packageJson.version;
const config = process.env.npm_config_debug ? 'debug' : 'release';
let backend;
if (packageJson.name == 'executorch' || packageJson.name.endsWith('-all'))
backend = 'all'
else if (packageJson.name.includes('-'))
backend = packageJson.name.substring(packageJson.name.lastIndexOf('-') + 1);
else
backend = os == 'mac' ? 'mps' : 'xnnpack';
const prefix = `${urlPrefix}/v${version}/executorch-${backend}-${os}-${arch}-${config}`;
await download(`${prefix}.node.gz`, `${dir}/executorch.node`);
}
async function download(url, filename) {
const response = await fetch(url);
if (!response.ok)
throw new Error(`Failed to download ${url}, status: ${response.status}`);
const gunzip = zlib.createGunzip();
await pipeline(response.body, gunzip, fs.createWriteStream(filename));
}