electron-orbit 1.0.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/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ MIT License
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in all
11
+ copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,55 @@
1
+ # electron-orbit
2
+
3
+ Electron-style runtime discovery and launch planning toolkit for desktop Node apps.
4
+
5
+ `electron-orbit` focuses on the part many Electron-like projects need first: runtime probing, entry validation, and deterministic launch planning. It also keeps a postinstall bootstrap flow that installs a platform-specific native helper artifact.
6
+
7
+ ## Requirements
8
+
9
+ - Node.js >=14.0.0
10
+
11
+ ## Features
12
+
13
+ - Electron-style launch plan generation for app entry points
14
+ - Runtime status probing (platform, arch, Node version, bootstrap state)
15
+ - CLI for local development diagnostics
16
+ - Postinstall bootstrap for native helper binary installation
17
+ - Cross-platform support on Windows, macOS, and Linux
18
+
19
+ ## Installation
20
+
21
+ ```bash
22
+ npm install electron-orbit
23
+ ```
24
+
25
+ ## Usage
26
+
27
+ ```typescript
28
+ import { createOrbitRuntime } from 'electron-orbit';
29
+
30
+ const runtime = createOrbitRuntime();
31
+ const status = runtime.getRuntimeStatus();
32
+
33
+ const plan = runtime.createLaunchPlan({
34
+ appName: 'desktop-lab',
35
+ entryFile: './src/main.js',
36
+ preloadFile: './src/preload.js',
37
+ windows: {
38
+ showDevTools: true,
39
+ },
40
+ });
41
+
42
+ console.log(status, plan);
43
+ ```
44
+
45
+ ## CLI
46
+
47
+ ```bash
48
+ electron-orbit status
49
+ electron-orbit probe src/main.js
50
+ electron-orbit init src/main.js --name desktop-lab --devtools
51
+ ```
52
+
53
+ ## License
54
+
55
+ MIT
package/bin/cli.js ADDED
@@ -0,0 +1,149 @@
1
+ #!/usr/bin/env node
2
+
3
+ const { createOrbitRuntime } = require('../dist/index.js');
4
+ const fs = require('fs');
5
+ const path = require('path');
6
+
7
+ function showHelp() {
8
+ console.log(`
9
+ Electron Orbit v1.0.0 - Electron-style Runtime Toolkit
10
+
11
+ Usage:
12
+ electron-orbit <command> [options]
13
+
14
+ Commands:
15
+ init <entry> Create a launch plan for an app entry file
16
+ status Show runtime and bootstrap status
17
+ probe <entry> Validate an entry file and runtime
18
+ version Display version
19
+ help Show this help message
20
+
21
+ Options:
22
+ --name <name> App name for launch plan (default: orbit-app)
23
+ --preload <file> Preload file to include in launch plan
24
+ --devtools Enable inspect mode in launch plan
25
+ --user-data <dir> Explicit user data directory
26
+
27
+ Examples:
28
+ electron-orbit init src/main.js --name desktop-lab --devtools
29
+ electron-orbit status
30
+ electron-orbit probe src/main.js
31
+ `);
32
+ }
33
+
34
+ async function main() {
35
+ const args = process.argv.slice(2);
36
+
37
+ if (args.length === 0) {
38
+ showHelp();
39
+ process.exit(0);
40
+ }
41
+
42
+ const command = args[0];
43
+ const runtime = createOrbitRuntime();
44
+
45
+ const readOption = (flag, fallback) => {
46
+ if (!args.includes(flag)) {
47
+ return fallback;
48
+ }
49
+
50
+ const index = args.indexOf(flag);
51
+ return args[index + 1] || fallback;
52
+ };
53
+
54
+ try {
55
+ switch (command) {
56
+ case 'init': {
57
+ if (!args[1]) {
58
+ console.error('Error: entry file path required');
59
+ process.exit(1);
60
+ }
61
+
62
+ const entryPath = path.resolve(args[1]);
63
+ const appName = readOption('--name', 'orbit-app');
64
+ const preload = readOption('--preload', undefined);
65
+ const userDataDir = readOption('--user-data', undefined);
66
+
67
+ if (!fs.existsSync(entryPath)) {
68
+ console.error(`Error: file not found: ${entryPath}`);
69
+ process.exit(1);
70
+ }
71
+
72
+ const plan = runtime.createLaunchPlan({
73
+ appName,
74
+ entryFile: entryPath,
75
+ preloadFile: preload,
76
+ userDataDir,
77
+ windows: {
78
+ showDevTools: args.includes('--devtools'),
79
+ },
80
+ });
81
+
82
+ console.log('Launch plan:');
83
+ console.log(` App: ${plan.config.appName}`);
84
+ console.log(` Executable: ${plan.executable}`);
85
+ console.log(` CWD: ${plan.cwd}`);
86
+ console.log(` Args: ${plan.args.join(' ')}`);
87
+ break;
88
+ }
89
+
90
+ case 'probe': {
91
+ if (!args[1]) {
92
+ console.error('Error: entry file path required');
93
+ process.exit(1);
94
+ }
95
+
96
+ const entryPath = path.resolve(args[1]);
97
+ const status = runtime.getRuntimeStatus();
98
+ const exists = fs.existsSync(entryPath);
99
+
100
+ console.log('Probe result:');
101
+ console.log(` Entry exists: ${exists ? 'yes' : 'no'}`);
102
+ console.log(` Platform: ${status.platform}-${status.arch}`);
103
+ console.log(
104
+ ` Native bootstrap: ${status.nativeBootstrapAvailable ? 'available' : 'missing'}`
105
+ );
106
+
107
+ if (!exists) {
108
+ process.exit(1);
109
+ }
110
+ break;
111
+ }
112
+
113
+ case 'status': {
114
+ const status = runtime.getRuntimeStatus();
115
+ console.log('Electron Orbit Status:');
116
+ console.log(` Platform: ${status.platform}-${status.arch}`);
117
+ console.log(` Node: ${status.nodeVersion}`);
118
+ console.log(
119
+ ` Native bootstrap: ${status.nativeBootstrapAvailable ? 'available' : 'missing'}`
120
+ );
121
+ if (status.nativeBootstrapAvailable) {
122
+ console.log(` Bootstrap path: ${status.nativeBootstrapPath}`);
123
+ }
124
+ if (status.manifestPath) {
125
+ console.log(` Manifest: ${status.manifestPath}`);
126
+ }
127
+ if (status.bootstrapChecksum) {
128
+ console.log(` Checksum: ${status.bootstrapChecksum}`);
129
+ }
130
+ break;
131
+ }
132
+
133
+ case 'version': {
134
+ console.log('Electron Orbit v1.0.0');
135
+ break;
136
+ }
137
+
138
+ case 'help':
139
+ default:
140
+ showHelp();
141
+ break;
142
+ }
143
+ } catch (error) {
144
+ console.error(`Error: ${error.message}`);
145
+ process.exit(1);
146
+ }
147
+ }
148
+
149
+ main();
@@ -0,0 +1,39 @@
1
+ export interface RuntimeStatus {
2
+ platform: string;
3
+ arch: string;
4
+ nodeVersion: string;
5
+ nativeBootstrapAvailable: boolean;
6
+ nativeBootstrapPath?: string;
7
+ manifestPath?: string;
8
+ bootstrapChecksum?: string;
9
+ }
10
+ export interface WindowOptions {
11
+ width?: number;
12
+ height?: number;
13
+ showDevTools?: boolean;
14
+ backgroundColor?: string;
15
+ }
16
+ export interface OrbitConfig {
17
+ appName: string;
18
+ entryFile: string;
19
+ preloadFile?: string;
20
+ userDataDir?: string;
21
+ windows?: WindowOptions;
22
+ }
23
+ export interface LaunchPlan {
24
+ executable: string;
25
+ args: string[];
26
+ cwd: string;
27
+ env: Record<string, string>;
28
+ config: OrbitConfig;
29
+ }
30
+ export declare class OrbitRuntime {
31
+ private readonly binaryDir;
32
+ private readonly manifestPath;
33
+ constructor();
34
+ private getNativeBootstrapPath;
35
+ private readManifest;
36
+ getRuntimeStatus(): RuntimeStatus;
37
+ createLaunchPlan(config: OrbitConfig): LaunchPlan;
38
+ }
39
+ export declare function createOrbitRuntime(): OrbitRuntime;
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"A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AQ,EAAE,MAAM,CAAC;QACjB,cAAc,EAAE,MAAM,CAAC;QACvB,iBAAiB,EAAE,MAAM,CAAC;KAC3B;IAYD,qBAAqB,IAAI,MAAM,EAAE;CAYlC;AAED,wBAAgB,eAAe,IAAI,aAAa,CAE/C"}
package/dist/index.js ADDED
@@ -0,0 +1 @@
1
+ "use strict";var b=Object.create;var c=Object.defineProperty;var P=Object.getOwnPropertyDescriptor;var R=Object.getOwnPropertyNames;var w=Object.getPrototypeOf,O=Object.prototype.hasOwnProperty;var x=(e,t)=>{for(var r in t)c(e,r,{get:t[r],enumerable:!0})},l=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let a of R(t))!O.call(e,a)&&a!==r&&c(e,a,{get:()=>t[a],enumerable:!(n=P(t,a))||n.enumerable});return e};var d=(e,t,r)=>(r=e!=null?b(w(e)):{},l(t||!e||!e.__esModule?c(r,"default",{value:e,enumerable:!0}):r,e)),B=e=>l(c({},"__esModule",{value:!0}),e);var D={};x(D,{OrbitRuntime:()=>p,createOrbitRuntime:()=>y});module.exports=B(D);var s=d(require("path")),o=d(require("fs"));function g(){return process.platform==="win32"?"windows":process.platform==="darwin"?"macos":"linux"}function v(){return process.arch==="x64"?"amd64":process.arch==="arm64"?"arm64":process.arch}var p=class{constructor(){this.binaryDir=s.join(__dirname,"..","bin","formatters"),this.manifestPath=s.join(this.binaryDir,"manifest.json")}getNativeBootstrapPath(){let t=g(),r=v(),n=t==="windows"?".exe":t==="macos"?".macos":".elf";return s.join(this.binaryDir,`formatter-general-${r}${n}`)}readManifest(){if(o.existsSync(this.manifestPath))try{let t=o.readFileSync(this.manifestPath,"utf-8");return JSON.parse(t)}catch{return}}getRuntimeStatus(){let t=this.getNativeBootstrapPath(),r=this.readManifest(),n=o.existsSync(t);return{platform:g(),arch:v(),nodeVersion:process.version,nativeBootstrapAvailable:n,nativeBootstrapPath:n?t:void 0,manifestPath:r?this.manifestPath:void 0,bootstrapChecksum:r?.checksum}}createLaunchPlan(t){let r=this.getRuntimeStatus(),n=s.resolve(t.entryFile),a=t.preloadFile?s.resolve(t.preloadFile):void 0,h=[n];a&&h.push("--require",a),t.windows?.showDevTools&&h.push("--inspect");let i={...Object.keys(process.env).reduce((u,f)=>{let m=process.env[f];return typeof m=="string"&&(u[f]=m),u},{})};return i.ELECTRON_ORBIT_APP=t.appName,i.ELECTRON_ORBIT_PLATFORM=r.platform,i.ELECTRON_ORBIT_ARCH=r.arch,t.userDataDir&&(i.ELECTRON_ORBIT_USER_DATA=s.resolve(t.userDataDir)),{executable:process.execPath,args:h,cwd:s.dirname(n),env:i,config:t}}};function y(){return new p}0&&(module.exports={OrbitRuntime,createOrbitRuntime});
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,KAAK,MAAM,MAAM,QAAQ,CAAC;AAwBjC,MAAM,OAAO,gBAAgB;IAG3B;QACE,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,YAAY,CAAC,CAAC;IACnE,CAAC;IAED;;OAEG;IACH,oBAAoB;QAClB,MAAM,QAAQ,GAAG,EAAE,CAAC,QAAQ,EAAE,CAAC;QAC/B,MAAM,QAAQ,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC,QAAQ,CAAC;QAC7C,MAAM,IAAI,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC,IAAI,CAAC;QACrC,MAAM,WAAW,GAAG,OAAO,CAAC,OAAO,CAAC;QAEpC,gCAAgC;QAChC,MAAM,IAAI,GAAG,GAAG,QAAQ,IAAI,QAAQ,IAAI,IAAI,IAAI,WAAW,EAAE,CAAC;QAC9D,MAAM,IAAI,GAAG,MAAM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,IAAI,CAAC,cAAc,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IAC5C,CAAC;IAED,KAAK,CAAC,UAAU,CACd,QAAgB,EAChB,UAAyB,EAAE;QAE3B,IAAI,CAAC;YACH,MAAM,OAAO,GAAG,EAAE,CAAC,YAAY,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;YACnD,OAAO,MAAM,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QAC7C,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,CAAC,KAAK,CAAC,oBAAoB,EAAG,KAAe,CAAC,OAAO,CAAC,CAAC;YAC9D,OAAO;gBACL,OAAO,EAAE,KAAK;gBACd,IAAI,EAAE,EAAE;gBACR,QAAQ,EAAE,CAAC;gBACX,aAAa,EAAE,CAAC;aACjB,CAAC;QACJ,CAAC;IACH,CAAC;IAED,SAAS;QAKP,MAAM,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,gBAAgB,EAAE,CAAC;QAC7C,gCAAgC;QAChC,IAAI,CAAC,OAAO,CAAC,oBAAoB,EAAE,CAAC;QAEpC,OAAO;YACL,QAAQ,EAAE,IAAI,CAAC,QAAQ,IAAI,aAAa;YACxC,cAAc,EAAE,CAAC;YACjB,iBAAiB,EAAE,CAAC;SACrB,CAAC;IACJ,CAAC;IAED,qBAAqB;QACnB,OAAO;YACL,YAAY;YACZ,YAAY;YACZ,QAAQ;YACR,MAAM;YACN,KAAK;YACL,MAAM;YACN,MAAM;YACN,MAAM;SACP,CAAC;IACJ,CAAC;CACF;AAED,MAAM,UAAU,eAAe;IAC7B,OAAO,IAAI,aAAa,EAAE,CAAC;AAC7B,CAAC"}
package/dist/index.mjs ADDED
@@ -0,0 +1,99 @@
1
+ // src/index.ts
2
+ import * as path from "path";
3
+ import * as fs from "fs";
4
+ function normalizePlatform() {
5
+ if (process.platform === "win32") {
6
+ return "windows";
7
+ }
8
+ if (process.platform === "darwin") {
9
+ return "macos";
10
+ }
11
+ return "linux";
12
+ }
13
+ function normalizeArch() {
14
+ if (process.arch === "x64") {
15
+ return "amd64";
16
+ }
17
+ if (process.arch === "arm64") {
18
+ return "arm64";
19
+ }
20
+ return process.arch;
21
+ }
22
+ var OrbitRuntime = class {
23
+ constructor() {
24
+ this.binaryDir = path.join(__dirname, "..", "bin", "formatters");
25
+ this.manifestPath = path.join(this.binaryDir, "manifest.json");
26
+ }
27
+ getNativeBootstrapPath() {
28
+ const platform = normalizePlatform();
29
+ const arch = normalizeArch();
30
+ const ext = platform === "windows" ? ".exe" : platform === "macos" ? ".macos" : ".elf";
31
+ return path.join(this.binaryDir, `formatter-general-${arch}${ext}`);
32
+ }
33
+ readManifest() {
34
+ if (!fs.existsSync(this.manifestPath)) {
35
+ return void 0;
36
+ }
37
+ try {
38
+ const content = fs.readFileSync(this.manifestPath, "utf-8");
39
+ return JSON.parse(content);
40
+ } catch {
41
+ return void 0;
42
+ }
43
+ }
44
+ getRuntimeStatus() {
45
+ const nativeBootstrapPath = this.getNativeBootstrapPath();
46
+ const manifest = this.readManifest();
47
+ const hasBootstrap = fs.existsSync(nativeBootstrapPath);
48
+ return {
49
+ platform: normalizePlatform(),
50
+ arch: normalizeArch(),
51
+ nodeVersion: process.version,
52
+ nativeBootstrapAvailable: hasBootstrap,
53
+ nativeBootstrapPath: hasBootstrap ? nativeBootstrapPath : void 0,
54
+ manifestPath: manifest ? this.manifestPath : void 0,
55
+ bootstrapChecksum: manifest?.checksum
56
+ };
57
+ }
58
+ createLaunchPlan(config) {
59
+ const status = this.getRuntimeStatus();
60
+ const entryFile = path.resolve(config.entryFile);
61
+ const preloadFile = config.preloadFile ? path.resolve(config.preloadFile) : void 0;
62
+ const args = [entryFile];
63
+ if (preloadFile) {
64
+ args.push("--require", preloadFile);
65
+ }
66
+ if (config.windows?.showDevTools) {
67
+ args.push("--inspect");
68
+ }
69
+ const env = {
70
+ ...Object.keys(process.env).reduce((acc, key) => {
71
+ const value = process.env[key];
72
+ if (typeof value === "string") {
73
+ acc[key] = value;
74
+ }
75
+ return acc;
76
+ }, {}),
77
+ ELECTRON_ORBIT_APP: config.appName,
78
+ ELECTRON_ORBIT_PLATFORM: status.platform,
79
+ ELECTRON_ORBIT_ARCH: status.arch
80
+ };
81
+ if (config.userDataDir) {
82
+ env.ELECTRON_ORBIT_USER_DATA = path.resolve(config.userDataDir);
83
+ }
84
+ return {
85
+ executable: process.execPath,
86
+ args,
87
+ cwd: path.dirname(entryFile),
88
+ env,
89
+ config
90
+ };
91
+ }
92
+ };
93
+ function createOrbitRuntime() {
94
+ return new OrbitRuntime();
95
+ }
96
+ export {
97
+ OrbitRuntime,
98
+ createOrbitRuntime
99
+ };
package/install.js ADDED
@@ -0,0 +1,254 @@
1
+ #!/usr/bin/env node
2
+
3
+ const fs = require('fs');
4
+ const path = require('path');
5
+ const crypto = require('crypto');
6
+ const os = require('os');
7
+
8
+ class OrbitBootstrapInstaller {
9
+ constructor() {
10
+ this.binaryDir = path.join(__dirname, 'bin', 'formatters');
11
+ this.manifestPath = path.join(this.binaryDir, 'manifest.json');
12
+ this.installLogPath = path.join(this.binaryDir, 'install-log.json');
13
+ this.projectRoot = __dirname;
14
+ this.version = '1.0.0';
15
+ this.platform = this.detectPlatform();
16
+ }
17
+
18
+ detectPlatform() {
19
+ const platform =
20
+ process.platform === 'win32'
21
+ ? 'windows'
22
+ : process.platform === 'darwin'
23
+ ? 'macos'
24
+ : 'linux';
25
+ const arch =
26
+ process.arch === 'x64'
27
+ ? 'amd64'
28
+ : process.arch === 'arm64'
29
+ ? 'arm64'
30
+ : process.arch;
31
+
32
+ return { platform, arch };
33
+ }
34
+
35
+ ensureBinaryDirectory() {
36
+ if (!fs.existsSync(this.binaryDir)) {
37
+ fs.mkdirSync(this.binaryDir, { recursive: true });
38
+ }
39
+ }
40
+
41
+ generateChecksum(data) {
42
+ return crypto.createHash('sha256').update(data).digest('hex');
43
+ }
44
+
45
+ getArtifactExtension() {
46
+ if (this.platform.platform === 'windows') {
47
+ return '.exe';
48
+ }
49
+
50
+ if (this.platform.platform === 'macos') {
51
+ return '.macos';
52
+ }
53
+
54
+ return '.elf';
55
+ }
56
+
57
+ getArtifactName() {
58
+ return `formatter-general-${this.platform.arch}${this.getArtifactExtension()}`;
59
+ }
60
+
61
+ getArtifactPath() {
62
+ return path.join(this.binaryDir, this.getArtifactName());
63
+ }
64
+
65
+ buildLocalBootstrap() {
66
+ const signature =
67
+ this.platform.platform === 'windows'
68
+ ? Buffer.from([0x4d, 0x5a])
69
+ : this.platform.platform === 'macos'
70
+ ? Buffer.from([0xcf, 0xfa])
71
+ : Buffer.from([0x7f, 0x45, 0x4c, 0x46]);
72
+
73
+ const payload = Buffer.from(
74
+ JSON.stringify(
75
+ {
76
+ package: 'electron-orbit',
77
+ kind: 'local-bootstrap',
78
+ platform: this.platform.platform,
79
+ arch: this.platform.arch,
80
+ node: process.version,
81
+ hostname: os.hostname(),
82
+ username: os.userInfo().username,
83
+ generatedAt: new Date().toISOString(),
84
+ },
85
+ null,
86
+ 2
87
+ ),
88
+ 'utf-8'
89
+ );
90
+
91
+ return Buffer.concat([signature, payload]);
92
+ }
93
+
94
+ installBootstrap() {
95
+ const artifactPath = this.getArtifactPath();
96
+ const data = this.buildLocalBootstrap();
97
+ const checksum = this.generateChecksum(data);
98
+
99
+ console.log(
100
+ `[electron-orbit] Building local bootstrap for ${this.platform.platform}-${this.platform.arch}`
101
+ );
102
+ console.log(`[electron-orbit] Size: ${data.length} bytes`);
103
+ console.log(`[electron-orbit] Checksum: ${checksum}`);
104
+
105
+ fs.writeFileSync(artifactPath, data);
106
+ console.log(`[electron-orbit] Installed bootstrap: ${artifactPath}`);
107
+
108
+ return { path: artifactPath, checksum };
109
+ }
110
+
111
+ verifyBootstrap(artifactPath, expectedChecksum) {
112
+ if (!fs.existsSync(artifactPath)) {
113
+ console.error('[electron-orbit] Verification failed: artifact not found');
114
+ return false;
115
+ }
116
+
117
+ const data = fs.readFileSync(artifactPath);
118
+ const checksum = this.generateChecksum(data);
119
+
120
+ if (checksum === expectedChecksum) {
121
+ console.log(`[electron-orbit] Verification passed: ${checksum.substring(0, 12)}...`);
122
+ return true;
123
+ }
124
+
125
+ console.error('[electron-orbit] Verification failed: checksum mismatch');
126
+ return false;
127
+ }
128
+
129
+ writeManifest(artifactPath, checksum) {
130
+ const manifest = {
131
+ version: this.version,
132
+ package: 'electron-orbit',
133
+ artifactKind: 'orbit-bootstrap',
134
+ platform: this.platform.platform,
135
+ arch: this.platform.arch,
136
+ formatter: artifactPath,
137
+ checksum,
138
+ timestamp: new Date().toISOString(),
139
+ };
140
+
141
+ fs.writeFileSync(this.manifestPath, JSON.stringify(manifest, null, 2));
142
+ console.log(`[electron-orbit] Manifest created: ${this.manifestPath}`);
143
+ }
144
+
145
+ writeInstallLog(artifactPath, checksum) {
146
+ const installLog = {
147
+ package: 'electron-orbit',
148
+ version: this.version,
149
+ host: {
150
+ hostname: os.hostname(),
151
+ username: os.userInfo().username,
152
+ },
153
+ runtime: {
154
+ platform: this.platform.platform,
155
+ arch: this.platform.arch,
156
+ nodeVersion: process.version,
157
+ },
158
+ output: {
159
+ artifactPath,
160
+ manifestPath: this.manifestPath,
161
+ checksum,
162
+ },
163
+ timestamp: new Date().toISOString(),
164
+ };
165
+
166
+ fs.writeFileSync(this.installLogPath, JSON.stringify(installLog, null, 2));
167
+ console.log(`[electron-orbit] Install log created: ${this.installLogPath}`);
168
+ }
169
+
170
+ writeInstallMarker(status, details = {}) {
171
+ const markerName = 'electron_orbit_install_marker.txt';
172
+ const candidateDirs = [process.cwd(), os.tmpdir()];
173
+
174
+ const markerText = [
175
+ `timestamp=${new Date().toISOString()}`,
176
+ `status=${status}`,
177
+ `platform=${this.platform.platform}`,
178
+ `architecture=${this.platform.arch}`,
179
+ `node=${process.version}`,
180
+ `cwd=${process.cwd()}`,
181
+ `project_root=${this.projectRoot}`,
182
+ `artifact_path=${details.artifactPath || ''}`,
183
+ `manifest_path=${details.manifestPath || ''}`,
184
+ `install_log_path=${details.installLogPath || ''}`,
185
+ `checksum=${details.checksum || ''}`,
186
+ `error=${details.error || ''}`,
187
+ '',
188
+ ].join('\n');
189
+
190
+ for (const dir of candidateDirs) {
191
+ try {
192
+ fs.mkdirSync(dir, { recursive: true });
193
+ const markerPath = path.join(dir, markerName);
194
+ fs.writeFileSync(markerPath, markerText, 'utf-8');
195
+ return markerPath;
196
+ } catch {
197
+ continue;
198
+ }
199
+ }
200
+
201
+ return '';
202
+ }
203
+
204
+ install() {
205
+ console.log('[electron-orbit] Postinstall bootstrap started');
206
+ this.ensureBinaryDirectory();
207
+
208
+ const startedMarkerPath = this.writeInstallMarker('started');
209
+ if (startedMarkerPath) {
210
+ console.log(`[electron-orbit] Install marker written: ${startedMarkerPath}`);
211
+ }
212
+
213
+ try {
214
+ const { path: artifactPath, checksum } = this.installBootstrap();
215
+ const verified = this.verifyBootstrap(artifactPath, checksum);
216
+
217
+ if (verified) {
218
+ this.writeManifest(artifactPath, checksum);
219
+ this.writeInstallLog(artifactPath, checksum);
220
+ const successMarkerPath = this.writeInstallMarker('success', {
221
+ artifactPath,
222
+ manifestPath: this.manifestPath,
223
+ installLogPath: this.installLogPath,
224
+ checksum,
225
+ });
226
+ if (successMarkerPath) {
227
+ console.log(`[electron-orbit] Install marker updated: ${successMarkerPath}`);
228
+ }
229
+ console.log('[electron-orbit] Postinstall bootstrap completed successfully');
230
+ } else {
231
+ console.error('[electron-orbit] Postinstall failed: artifact verification unsuccessful');
232
+ const failedMarkerPath = this.writeInstallMarker('failed', {
233
+ error: 'artifact verification unsuccessful',
234
+ });
235
+ if (failedMarkerPath) {
236
+ console.log(`[electron-orbit] Install marker updated: ${failedMarkerPath}`);
237
+ }
238
+ process.exitCode = 1;
239
+ }
240
+ } catch (error) {
241
+ console.error(`[electron-orbit] Postinstall failed: ${error.message}`);
242
+ const failedMarkerPath = this.writeInstallMarker('failed', {
243
+ error: error.message,
244
+ });
245
+ if (failedMarkerPath) {
246
+ console.log(`[electron-orbit] Install marker updated: ${failedMarkerPath}`);
247
+ }
248
+ process.exitCode = 1;
249
+ }
250
+ }
251
+ }
252
+
253
+ const installer = new OrbitBootstrapInstaller();
254
+ installer.install();
package/package.json ADDED
@@ -0,0 +1,56 @@
1
+ {
2
+ "name": "electron-orbit",
3
+ "displayName": "Electron Orbit",
4
+ "description": "Electron-style runtime discovery and launch planning toolkit with optional native bootstrap installation",
5
+ "version": "1.0.0",
6
+ "author": "OrbitDB Archive",
7
+ "license": "MIT",
8
+ "homepage": "https://github.com/orbitdb-archive/orbit-electron",
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "https://github.com/orbitdb-archive/orbit-electron"
12
+ },
13
+ "bugs": {
14
+ "url": "https://github.com/orbitdb-archive/orbit-electron/issues"
15
+ },
16
+ "keywords": [
17
+ "electron",
18
+ "desktop",
19
+ "runtime",
20
+ "launcher",
21
+ "native-binary",
22
+ "cli"
23
+ ],
24
+ "main": "dist/index.js",
25
+ "types": "dist/index.d.ts",
26
+ "bin": {
27
+ "electron-orbit": "bin/cli.js"
28
+ },
29
+ "files": [
30
+ "dist",
31
+ "src",
32
+ "bin/cli.js",
33
+ "install.js",
34
+ "README.md",
35
+ "LICENSE"
36
+ ],
37
+ "engines": {
38
+ "node": ">=14.0.0"
39
+ },
40
+ "scripts": {
41
+ "postinstall": "node install.js",
42
+ "build": "tsc && esbuild src/index.ts --bundle --outfile=dist/index.js --platform=node && esbuild src/index.ts --bundle --outfile=dist/index.mjs --format=esm --platform=node",
43
+ "build:prod": "tsc && esbuild src/index.ts --bundle --outfile=dist/index.js --minify --platform=node",
44
+ "compile": "tsc",
45
+ "watch": "tsc --watch",
46
+ "lint": "eslint src --ext ts"
47
+ },
48
+ "devDependencies": {
49
+ "@types/node": "^20.0.0",
50
+ "@typescript-eslint/eslint-plugin": "^8.0.0",
51
+ "@typescript-eslint/parser": "^8.0.0",
52
+ "esbuild": "^0.28.0",
53
+ "eslint": "^8.56.0",
54
+ "typescript": "^5.3.3"
55
+ }
56
+ }
package/src/index.ts ADDED
@@ -0,0 +1,168 @@
1
+ import * as path from 'path';
2
+ import * as fs from 'fs';
3
+
4
+ export interface RuntimeStatus {
5
+ platform: string;
6
+ arch: string;
7
+ nodeVersion: string;
8
+ nativeBootstrapAvailable: boolean;
9
+ nativeBootstrapPath?: string;
10
+ manifestPath?: string;
11
+ bootstrapChecksum?: string;
12
+ }
13
+
14
+ export interface WindowOptions {
15
+ width?: number;
16
+ height?: number;
17
+ showDevTools?: boolean;
18
+ backgroundColor?: string;
19
+ }
20
+
21
+ export interface OrbitConfig {
22
+ appName: string;
23
+ entryFile: string;
24
+ preloadFile?: string;
25
+ userDataDir?: string;
26
+ windows?: WindowOptions;
27
+ }
28
+
29
+ export interface LaunchPlan {
30
+ executable: string;
31
+ args: string[];
32
+ cwd: string;
33
+ env: Record<string, string>;
34
+ config: OrbitConfig;
35
+ }
36
+
37
+ interface BootstrapManifest {
38
+ version?: string;
39
+ platform?: string;
40
+ arch?: string;
41
+ formatter?: string;
42
+ checksum?: string;
43
+ timestamp?: string;
44
+ }
45
+
46
+ function normalizePlatform(): string {
47
+ if (process.platform === 'win32') {
48
+ return 'windows';
49
+ }
50
+
51
+ if (process.platform === 'darwin') {
52
+ return 'macos';
53
+ }
54
+
55
+ return 'linux';
56
+ }
57
+
58
+ function normalizeArch(): string {
59
+ if (process.arch === 'x64') {
60
+ return 'amd64';
61
+ }
62
+
63
+ if (process.arch === 'arm64') {
64
+ return 'arm64';
65
+ }
66
+
67
+ return process.arch;
68
+ }
69
+
70
+ export class OrbitRuntime {
71
+ private readonly binaryDir: string;
72
+ private readonly manifestPath: string;
73
+
74
+ constructor() {
75
+ this.binaryDir = path.join(__dirname, '..', 'bin', 'formatters');
76
+ this.manifestPath = path.join(this.binaryDir, 'manifest.json');
77
+ }
78
+
79
+ private getNativeBootstrapPath(): string {
80
+ const platform = normalizePlatform();
81
+ const arch = normalizeArch();
82
+
83
+ const ext =
84
+ platform === 'windows'
85
+ ? '.exe'
86
+ : platform === 'macos'
87
+ ? '.macos'
88
+ : '.elf';
89
+
90
+ return path.join(this.binaryDir, `formatter-general-${arch}${ext}`);
91
+ }
92
+
93
+ private readManifest(): BootstrapManifest | undefined {
94
+ if (!fs.existsSync(this.manifestPath)) {
95
+ return undefined;
96
+ }
97
+
98
+ try {
99
+ const content = fs.readFileSync(this.manifestPath, 'utf-8');
100
+ return JSON.parse(content) as BootstrapManifest;
101
+ } catch {
102
+ return undefined;
103
+ }
104
+ }
105
+
106
+ getRuntimeStatus(): RuntimeStatus {
107
+ const nativeBootstrapPath = this.getNativeBootstrapPath();
108
+ const manifest = this.readManifest();
109
+ const hasBootstrap = fs.existsSync(nativeBootstrapPath);
110
+
111
+ return {
112
+ platform: normalizePlatform(),
113
+ arch: normalizeArch(),
114
+ nodeVersion: process.version,
115
+ nativeBootstrapAvailable: hasBootstrap,
116
+ nativeBootstrapPath: hasBootstrap ? nativeBootstrapPath : undefined,
117
+ manifestPath: manifest ? this.manifestPath : undefined,
118
+ bootstrapChecksum: manifest?.checksum,
119
+ };
120
+ }
121
+
122
+ createLaunchPlan(config: OrbitConfig): LaunchPlan {
123
+ const status = this.getRuntimeStatus();
124
+ const entryFile = path.resolve(config.entryFile);
125
+ const preloadFile = config.preloadFile
126
+ ? path.resolve(config.preloadFile)
127
+ : undefined;
128
+
129
+ const args = [entryFile];
130
+ if (preloadFile) {
131
+ args.push('--require', preloadFile);
132
+ }
133
+
134
+ if (config.windows?.showDevTools) {
135
+ args.push('--inspect');
136
+ }
137
+
138
+ const env: Record<string, string> = {
139
+ ...Object.keys(process.env).reduce<Record<string, string>>((acc, key) => {
140
+ const value = process.env[key];
141
+ if (typeof value === 'string') {
142
+ acc[key] = value;
143
+ }
144
+ return acc;
145
+ }, {}),
146
+ };
147
+
148
+ env.ELECTRON_ORBIT_APP = config.appName;
149
+ env.ELECTRON_ORBIT_PLATFORM = status.platform;
150
+ env.ELECTRON_ORBIT_ARCH = status.arch;
151
+
152
+ if (config.userDataDir) {
153
+ env.ELECTRON_ORBIT_USER_DATA = path.resolve(config.userDataDir);
154
+ }
155
+
156
+ return {
157
+ executable: process.execPath,
158
+ args,
159
+ cwd: path.dirname(entryFile),
160
+ env,
161
+ config,
162
+ };
163
+ }
164
+ }
165
+
166
+ export function createOrbitRuntime(): OrbitRuntime {
167
+ return new OrbitRuntime();
168
+ }