Skip to content

Instantly share code, notes, and snippets.

@billywhizz
Last active March 29, 2024 00:09
Show Gist options
  • Save billywhizz/5fa5c0790acbe2fc6a8fa568d4e57873 to your computer and use it in GitHub Desktop.
Save billywhizz/5fa5c0790acbe2fc6a8fa568d4e57873 to your computer and use it in GitHub Desktop.
running programs from package.js on lo runtime
{
"name": "foo",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"foo": "/bin/ls -lah && /bin/ls -lah && /bin/ls -lah"
},
"author": "",
"license": "ISC"
}
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