@agora-build/dialf 0.1.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 (3) hide show
  1. package/bin/dialf.js +22 -0
  2. package/install.js +60 -0
  3. package/package.json +31 -0
package/bin/dialf.js ADDED
@@ -0,0 +1,22 @@
1
+ #!/usr/bin/env node
2
+ // Thin launcher: exec the vendored native `dialf` binary with the same args.
3
+
4
+ const { spawnSync } = require('child_process');
5
+ const fs = require('fs');
6
+ const path = require('path');
7
+
8
+ const vendor = path.join(__dirname, '..', 'vendor');
9
+ let dir;
10
+ try {
11
+ dir = fs.readdirSync(vendor).find((d) => d.startsWith('dialf-'));
12
+ } catch (_) {
13
+ /* vendor missing */
14
+ }
15
+ if (!dir) {
16
+ console.error('dialf: native binary not found — reinstall (@agora-build/dialf) or build from source.');
17
+ process.exit(1);
18
+ }
19
+
20
+ const bin = path.join(vendor, dir, 'dialf');
21
+ const r = spawnSync(bin, process.argv.slice(2), { stdio: 'inherit' });
22
+ process.exit(r.status === null ? 1 : r.status);
package/install.js ADDED
@@ -0,0 +1,60 @@
1
+ // postinstall: download the prebuilt dialf binary (+ bundled ten-vad lib) for this
2
+ // platform into vendor/. Does NOT install the service — run `sudo dialf service install`
3
+ // (or `dialf service install --user`) afterward. Never hard-fails `npm install`.
4
+
5
+ const https = require('https');
6
+ const fs = require('fs');
7
+ const path = require('path');
8
+ const { execSync } = require('child_process');
9
+
10
+ const pkg = require('./package.json');
11
+ const REPO = process.env.DIALF_REPO || 'Agora-Build/DialF';
12
+ const version = pkg.version;
13
+ const tag = 'v' + version;
14
+
15
+ const ARCH = { x64: 'x86_64', arm64: 'aarch64' }[process.arch];
16
+ const OS = { darwin: 'darwin', linux: 'linux' }[process.platform];
17
+
18
+ function bail(msg) {
19
+ // Print guidance but exit 0 so `npm install` doesn't fail the whole tree.
20
+ console.error('dialf: ' + msg);
21
+ console.error('dialf: download/build manually from https://github.com/' + REPO + '/releases');
22
+ process.exit(0);
23
+ }
24
+
25
+ if (!OS || !ARCH) bail('unsupported platform ' + process.platform + '/' + process.arch);
26
+
27
+ const target = `${OS}-${ARCH}`;
28
+ const asset = `dialf-${version}-${target}.tar.gz`;
29
+ const url = `https://github.com/${REPO}/releases/download/${tag}/${asset}`;
30
+ const vendor = path.join(__dirname, 'vendor');
31
+
32
+ function download(u, dest, cb) {
33
+ https
34
+ .get(u, { headers: { 'User-Agent': 'dialf-npm' } }, (res) => {
35
+ if (res.statusCode >= 300 && res.statusCode < 400 && res.headers.location) {
36
+ return download(res.headers.location, dest, cb);
37
+ }
38
+ if (res.statusCode !== 200) return cb(new Error('HTTP ' + res.statusCode + ' for ' + u));
39
+ const f = fs.createWriteStream(dest);
40
+ res.pipe(f);
41
+ f.on('finish', () => f.close(() => cb(null)));
42
+ })
43
+ .on('error', cb);
44
+ }
45
+
46
+ fs.mkdirSync(vendor, { recursive: true });
47
+ const tgz = path.join(vendor, asset);
48
+ console.log('dialf: downloading ' + url);
49
+ download(url, tgz, (err) => {
50
+ if (err) return bail('download failed: ' + err.message);
51
+ try {
52
+ execSync(`tar -xzf "${tgz}" -C "${vendor}"`);
53
+ fs.unlinkSync(tgz);
54
+ } catch (e) {
55
+ return bail('extract failed: ' + e.message);
56
+ }
57
+ console.log('dialf: installed ' + target);
58
+ console.log('dialf: to run dialfd at boot: sudo dialf service install');
59
+ console.log('dialf: or per-user: dialf service install --user');
60
+ });
package/package.json ADDED
@@ -0,0 +1,31 @@
1
+ {
2
+ "name": "@agora-build/dialf",
3
+ "version": "0.1.0",
4
+ "description": "DialF — autonomous phone pick/call daemon (dialfd) + CLI",
5
+ "bin": {
6
+ "dialf": "bin/dialf.js"
7
+ },
8
+ "scripts": {
9
+ "postinstall": "node install.js"
10
+ },
11
+ "files": [
12
+ "bin/",
13
+ "install.js"
14
+ ],
15
+ "os": [
16
+ "darwin",
17
+ "linux"
18
+ ],
19
+ "cpu": [
20
+ "x64",
21
+ "arm64"
22
+ ],
23
+ "engines": {
24
+ "node": ">=16"
25
+ },
26
+ "license": "Apache-2.0",
27
+ "repository": {
28
+ "type": "git",
29
+ "url": "https://github.com/Agora-Build/DialF.git"
30
+ }
31
+ }