Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added compile step and node module resolution to translucent-blueprint #39

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified bun.lockb
Binary file not shown.
5 changes: 0 additions & 5 deletions packages/translucent-blueprint/cli.ts

This file was deleted.

5 changes: 4 additions & 1 deletion packages/translucent-blueprint/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
"name": "translucent-blueprint",
"module": "index.ts",
"bin": {
"translucent-blueprint": "cli.ts"
"translucent-blueprint": "./dist/cli.js"
},
"scripts": {
"build": "tsc --project ./tsconfig.json --outDir ./dist"
},
"type": "module",
"version": "0.0.1"
Expand Down
8 changes: 6 additions & 2 deletions packages/translucent-blueprint/src/blueprint.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { readFile, writeFile } from "fs/promises";

type Blueprint = {
preamble: {
title: string;
Expand Down Expand Up @@ -41,7 +43,9 @@ type Blueprint = {
};

export async function parseBlueprint(blueprint: string, plutusTs: string) {
const plutusJson: Blueprint = JSON.parse(await Bun.file(blueprint).text());
const plutusJson: Blueprint = JSON.parse(
await readFile(blueprint, { encoding: "utf8" }),
);

const plutusVersion =
"Plutus" + plutusJson.preamble.plutusVersion.toUpperCase();
Expand Down Expand Up @@ -99,7 +103,7 @@ import { applyParamsToScript, Data, Validator } from "../translucent/index.ts"`;

const plutus = imports + "\n\n" + validators.join("\n\n");

await Bun.write(plutusTs, plutus);
await writeFile(plutusTs, plutus, { encoding: "utf8" });

console.log(
"%cGenerated %cplutus.ts",
Expand Down
7 changes: 7 additions & 0 deletions packages/translucent-blueprint/src/cli.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env node

import { parseBlueprint } from "./blueprint.js";

const args = process.argv.slice(2);

parseBlueprint(args[0], args[1]);
21 changes: 10 additions & 11 deletions packages/translucent-blueprint/test/blueprint.test.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
import { parseBlueprint } from "../src/blueprint";
import path from "path";
import { readFile, writeFile } from "fs/promises";
import inputPlutusJson from "./fixtures/plutus-vesting.json";
import expectedResult from "./fixtures/plutus-vesting.ts.txt";
import { jest, test, expect, mock } from "bun:test";

jest.spyOn(Bun, "write").mockImplementation((path, data) => {
return Promise.resolve(data.toString().length);
});
mock.module("fs/promises", () => ({
writeFile: jest.fn().mockResolvedValue(0),
readFile: jest.fn().mockResolvedValue(JSON.stringify(inputPlutusJson)),
}));

it("should successfully parse any plutus.json", async () => {
test("should successfully parse any plutus.json", async () => {
const TARGET_FILENAME = "plutus.ts";

const plutusLocation = path.join(
import.meta.dir,
"./fixtures/plutus-vesting.json",
);
await parseBlueprint(plutusLocation, TARGET_FILENAME);
await parseBlueprint("/whatever.json", TARGET_FILENAME);

const writeMock = Bun.write as jest.MockedFunction<typeof Bun.write>;
const writeMock = writeFile as jest.Mock<typeof writeFile>;

expect(writeMock).toHaveBeenCalled();

Expand Down
12 changes: 12 additions & 0 deletions packages/translucent-blueprint/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"compilerOptions": {
"outDir": "./dist",
"rootDir": "./src",
"types": ["bun-types", "jest"],
"lib": ["ESNext"],
"module": "esnext",
"moduleResolution": "Node"
},
"include": ["./src/**/*.ts"],
"exclude": ["**/node_modules"]
}
Loading