-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add npm package to homestar runtime (#434)
- adds npm packages to homestar-runtime. - adds CI/CD to build and publish wrapper package and os specific packages.
- Loading branch information
1 parent
7c45cf5
commit 0aa6e3a
Showing
9 changed files
with
515 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -55,3 +55,6 @@ examples/**/tmp/* | |
|
||
# nix build results | ||
/result | ||
|
||
# npm packages | ||
homestar-runtime/npm/binaries |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#!/usr/bin/env node | ||
|
||
import { execa } from 'execa' | ||
import { createRequire } from 'module' | ||
const require = createRequire(import.meta.url) | ||
|
||
/** | ||
* Returns the executable path which is located inside `node_modules` | ||
* The naming convention is app-${os}-${arch} | ||
* If the platform is `win32` or `cygwin`, executable will include a `.exe` extension. | ||
* @see https://nodejs.org/api/os.html#osarch | ||
* @see https://nodejs.org/api/os.html#osplatform | ||
* @example "x/xx/node_modules/app-darwin-arm64" | ||
*/ | ||
function getExePath() { | ||
const arch = process.arch | ||
let os = process.platform | ||
let extension = '' | ||
if (['win32', 'cygwin'].includes(process.platform)) { | ||
os = 'windows' | ||
extension = '.exe' | ||
} | ||
|
||
try { | ||
// Since the binary will be located inside `node_modules`, we can simply call `require.resolve` | ||
return require.resolve(`homestar-${os}-${arch}/bin/homestar${extension}`) | ||
} catch (e) { | ||
throw new Error( | ||
`Couldn't find application binary inside node_modules for ${os}-${arch}` | ||
) | ||
} | ||
} | ||
|
||
/** | ||
* Runs the application with args using nodejs spawn | ||
*/ | ||
function run() { | ||
const args = process.argv.slice(2) | ||
execa(getExePath(), args, { stdio: 'inherit' }) | ||
} | ||
|
||
run() |
Oops, something went wrong.