diff --git a/package.json b/package.json index 44633fa..417062b 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "access": "public", "@shopify:registry": "https://registry.npmjs.org/" }, - "version": "0.2.0", + "version": "0.1.0", "description": "", "main": "index.ts", "keywords": [], @@ -18,5 +18,6 @@ "typescript": "^4.8.4" }, "peerDependencies": { + "javy": "^0.1.0" } } diff --git a/run.ts b/run.ts index c3a5740..5ebf344 100644 --- a/run.ts +++ b/run.ts @@ -1,22 +1,15 @@ +import * as fs from "javy/fs"; + export type ShopifyFunction = ( input: Input ) => Output; - -interface Javy { - JSON: { - fromStdin(): any; - toStdout(val: any); - } -} - -declare global { - const Javy: Javy; -} - - export default function (userfunction: ShopifyFunction) { - const input_obj = Javy.JSON.fromStdin(); + const input_data = fs.readFileSync(fs.STDIO.Stdin); + const input_str = new TextDecoder("utf-8").decode(input_data); + const input_obj = JSON.parse(input_str); const output_obj = userfunction(input_obj); - Javy.JSON.toStdout(output_obj); + const output_str = JSON.stringify(output_obj); + const output_data = new TextEncoder().encode(output_str); + fs.writeFileSync(fs.STDIO.Stdout, output_data); }