@dmsdc-ai/aterm 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/aterm.js +41 -0
  2. package/install.js +50 -0
  3. package/package.json +25 -0
package/bin/aterm.js ADDED
@@ -0,0 +1,41 @@
1
+ #!/usr/bin/env node
2
+ import fs from 'node:fs';
3
+ import path from 'node:path';
4
+ import { spawn } from 'node:child_process';
5
+ import { fileURLToPath } from 'node:url';
6
+
7
+ const __filename = fileURLToPath(import.meta.url);
8
+ const __dirname = path.dirname(__filename);
9
+ const packageRoot = path.resolve(__dirname, '..');
10
+ const appRoot = path.join(packageRoot, 'dist', 'aterm.app');
11
+ const executable = path.join(appRoot, 'Contents', 'MacOS', 'aterm');
12
+ const frameworksDir = path.join(appRoot, 'Contents', 'Frameworks');
13
+
14
+ if (!fs.existsSync(executable)) {
15
+ console.error('[aterm] native app bundle is not installed');
16
+ console.error('[aterm] reinstall @dmsdc-ai/aterm on a supported platform');
17
+ process.exit(1);
18
+ }
19
+
20
+ const env = { ...process.env };
21
+ env.DYLD_LIBRARY_PATH = [frameworksDir, env.DYLD_LIBRARY_PATH]
22
+ .filter(Boolean)
23
+ .join(':');
24
+
25
+ const child = spawn(executable, process.argv.slice(2), {
26
+ stdio: 'inherit',
27
+ env,
28
+ });
29
+
30
+ child.on('error', error => {
31
+ console.error(`[aterm] failed to launch native bundle: ${error.message}`);
32
+ process.exit(1);
33
+ });
34
+
35
+ child.on('exit', (code, signal) => {
36
+ if (signal) {
37
+ process.kill(process.pid, signal);
38
+ return;
39
+ }
40
+ process.exit(code ?? 0);
41
+ });
package/install.js ADDED
@@ -0,0 +1,50 @@
1
+ #!/usr/bin/env node
2
+ import fs from 'node:fs';
3
+ import os from 'node:os';
4
+ import path from 'node:path';
5
+ import { fileURLToPath } from 'node:url';
6
+ import { createRequire } from 'node:module';
7
+
8
+ const __filename = fileURLToPath(import.meta.url);
9
+ const __dirname = path.dirname(__filename);
10
+ const require = createRequire(import.meta.url);
11
+
12
+ const PLATFORM_PACKAGES = {
13
+ darwin: {
14
+ arm64: '@dmsdc-ai/aterm-darwin-arm64',
15
+ },
16
+ };
17
+
18
+ function resolvePlatformPackage() {
19
+ return PLATFORM_PACKAGES[os.platform()]?.[os.arch()] ?? null;
20
+ }
21
+
22
+ const platformPackage = resolvePlatformPackage();
23
+ if (!platformPackage) {
24
+ console.warn(`[aterm] no native package for ${os.platform()} ${os.arch()}; install skipped`);
25
+ process.exit(0);
26
+ }
27
+
28
+ let platformPackageJsonPath;
29
+ try {
30
+ platformPackageJsonPath = require.resolve(`${platformPackage}/package.json`);
31
+ } catch (error) {
32
+ console.warn(`[aterm] optional native package not installed: ${platformPackage}`);
33
+ console.warn('[aterm] reinstall after the platform package is available');
34
+ process.exit(0);
35
+ }
36
+
37
+ const platformRoot = path.dirname(platformPackageJsonPath);
38
+ const sourceApp = path.join(platformRoot, 'dist', 'aterm.app');
39
+ const targetApp = path.join(__dirname, 'dist', 'aterm.app');
40
+
41
+ if (!fs.existsSync(sourceApp)) {
42
+ console.error(`[aterm] native app bundle missing from ${platformPackage}: ${sourceApp}`);
43
+ process.exit(1);
44
+ }
45
+
46
+ fs.rmSync(path.dirname(targetApp), { recursive: true, force: true });
47
+ fs.mkdirSync(path.dirname(targetApp), { recursive: true });
48
+ fs.cpSync(sourceApp, targetApp, { recursive: true });
49
+
50
+ console.log(`[aterm] installed native bundle from ${platformPackage}`);
package/package.json ADDED
@@ -0,0 +1,25 @@
1
+ {
2
+ "name": "@dmsdc-ai/aterm",
3
+ "version": "0.1.0",
4
+ "description": "Native aterm launcher package",
5
+ "type": "module",
6
+ "main": "./bin/aterm.js",
7
+ "bin": {
8
+ "aterm": "./bin/aterm.js"
9
+ },
10
+ "scripts": {
11
+ "postinstall": "node install.js"
12
+ },
13
+ "files": [
14
+ "bin",
15
+ "install.js",
16
+ "package.json"
17
+ ],
18
+ "optionalDependencies": {
19
+ "@dmsdc-ai/aterm-darwin-arm64": "0.1.0"
20
+ },
21
+ "license": "UNLICENSED",
22
+ "publishConfig": {
23
+ "access": "public"
24
+ }
25
+ }