JS CLI Wrapper
Run the Lilypad CLI wrapper locally
Last updated
Was this helpful?
Was this helpful?
curl -X POST http://localhost:3000 \
-H "Content-Type: application/json" \
-d '{"pk": "'"your-private-key"'", "module": "github.com/lilypad-tech/lilypad-module-lilysay:0.1.0", "inputs": "-i Message=test"}'// run.js
const { run } = require("./")
run(
"private-key",
"module name"
'-i payload (key=value)'
).then((res) => {
console.log(res)
})// stream.js
const { stream } = require("./")
stream(
"private-key",
"module name"
'-i payload (key=value)'
{ stream: true },
).then(() => {
console.log("Result in ./output/result")
})// index.js
const fetch = require("node-fetch")
const fs = require("fs")
const URL = "http://js-cli-wrapper.lilypad.tech"
const METHOD = "POST"
const HEADERS = {
Accept: "application/json",
"Content-Type": "application/json",
}
const OUTPUT = "./output"
function stream(pk, module, inputs, opts) {
const body = JSON.stringify({ pk, module, inputs, opts })
return fetch(URL, {
headers: HEADERS,
method: METHOD,
body,
}).then(function (res) {
const fileStream = fs.createWriteStream(`./${OUTPUT}/result`)
res.body.pipe(fileStream)
res.body.on("error", (error) => {
return { error }
})
fileStream.on("finish", () => {
return { status: "done" }
})
})
}
function run(pk, module, inputs) {
const body = JSON.stringify({ pk, module, inputs })
return fetch(URL, {
headers: HEADERS,
method: METHOD,
body,
}).then((raw) => raw.json())
}
module.exports = { run, stream }