Skip to content

Commit ae56263

Browse files
authored
Merge pull request #6 from Shopify/jb/multi-exports
Setup the package for multiple exports
2 parents 6bfda3c + 468e9a4 commit ae56263

File tree

3 files changed

+20
-13
lines changed

3 files changed

+20
-13
lines changed

index.ts

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,5 @@
1-
import * as fs from "javy/fs";
2-
31
// This package name will be aliased to the file provided by the user.
42
import * as userFunction from "user-function";
3+
import run from "./run";
54

6-
export type ShopifyFunction<Input extends {}, Output extends {}> = (
7-
input: Input
8-
) => Output;
9-
10-
const input_data = fs.readFileSync(fs.STDIO.Stdin);
11-
const input_str = new TextDecoder("utf-8").decode(input_data);
12-
const input_obj = JSON.parse(input_str);
13-
const output_obj = userFunction?.default(input_obj);
14-
const output_str = JSON.stringify(output_obj);
15-
const output_data = new TextEncoder().encode(output_str);
16-
fs.writeFileSync(fs.STDIO.Stdout, output_data);
5+
run(userFunction?.default)

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,8 @@
1616
"@graphql-codegen/typescript-operations": "^2.5.5",
1717
"graphql": "^16.6.0",
1818
"typescript": "^4.8.4"
19+
},
20+
"peerDependencies": {
21+
"javy": "^0.1.0"
1922
}
2023
}

run.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import * as fs from "javy/fs";
2+
3+
export type ShopifyFunction<Input extends {}, Output extends {}> = (
4+
input: Input
5+
) => Output;
6+
7+
export default function <I extends {}, O extends {}>(userfunction: ShopifyFunction<I, O>) {
8+
const input_data = fs.readFileSync(fs.STDIO.Stdin);
9+
const input_str = new TextDecoder("utf-8").decode(input_data);
10+
const input_obj = JSON.parse(input_str);
11+
const output_obj = userfunction(input_obj);
12+
const output_str = JSON.stringify(output_obj);
13+
const output_data = new TextEncoder().encode(output_str);
14+
fs.writeFileSync(fs.STDIO.Stdout, output_data);
15+
}

0 commit comments

Comments
 (0)