Last active
March 29, 2024 00:09
-
-
Save billywhizz/5fa5c0790acbe2fc6a8fa568d4e57873 to your computer and use it in GitHub Desktop.
running programs from package.js on lo runtime
This file contains hidden or 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
{ | |
"name": "foo", | |
"version": "1.0.0", | |
"description": "", | |
"main": "index.js", | |
"scripts": { | |
"foo": "/bin/ls -lah && /bin/ls -lah && /bin/ls -lah" | |
}, | |
"author": "", | |
"license": "ISC" | |
} |
This file contains hidden or 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
import { make_args } from 'lib/proc.js' | |
const { core, assert } = lo | |
const { vexecve, read_file } = core | |
const { scripts } = JSON.parse((new TextDecoder()).decode(read_file('./package.json'))) | |
const envv = make_args(['', []]) | |
const torun = scripts[lo.args[0] === 'lo' ? lo.args[2] : lo.args[1]] | |
if (torun) { | |
const cmds = torun.split('&&').map(c => c.trim()) | |
for (const cmd of cmds) { | |
const args = cmd.split(' ') | |
const argv = make_args(args) | |
assert(vexecve(args[0], argv.args, envv.args) === 0) | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment