diff --git a/bun.lockb b/bun.lockb index 923271e..71d2d3d 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/packages/translucent-blueprint/cli.ts b/packages/translucent-blueprint/cli.ts deleted file mode 100644 index aeb87b7..0000000 --- a/packages/translucent-blueprint/cli.ts +++ /dev/null @@ -1,5 +0,0 @@ -import { parseBlueprint } from "."; - -const args = Bun.argv.slice(2); - -parseBlueprint(args[0], args[1]); diff --git a/packages/translucent-blueprint/package.json b/packages/translucent-blueprint/package.json index 0e7ed75..2e5aad0 100644 --- a/packages/translucent-blueprint/package.json +++ b/packages/translucent-blueprint/package.json @@ -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" diff --git a/packages/translucent-blueprint/src/blueprint.ts b/packages/translucent-blueprint/src/blueprint.ts index dd17b79..b515c26 100644 --- a/packages/translucent-blueprint/src/blueprint.ts +++ b/packages/translucent-blueprint/src/blueprint.ts @@ -1,3 +1,5 @@ +import { readFile, writeFile } from 'fs/promises'; + type Blueprint = { preamble: { title: string; @@ -41,7 +43,7 @@ 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(); @@ -99,7 +101,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", diff --git a/packages/translucent-blueprint/src/cli.ts b/packages/translucent-blueprint/src/cli.ts new file mode 100755 index 0000000..0fdecb4 --- /dev/null +++ b/packages/translucent-blueprint/src/cli.ts @@ -0,0 +1,15 @@ +#!/usr/bin/env node + +import { parseBlueprint } from "./blueprint.js"; + +function getCliArgs() { + if (typeof Bun !== 'undefined' && Bun.argv) { + return Bun.argv.slice(2); + } else { + return process.argv.slice(2); + } +} + +const args = getCliArgs(); + +parseBlueprint(args[0], args[1]); diff --git a/packages/translucent-blueprint/test/blueprint.test.ts b/packages/translucent-blueprint/test/blueprint.test.ts index 43f1990..ceafa4b 100644 --- a/packages/translucent-blueprint/test/blueprint.test.ts +++ b/packages/translucent-blueprint/test/blueprint.test.ts @@ -1,21 +1,20 @@ import { parseBlueprint } from "../src/blueprint"; -import path from "path"; -import expectedResult from "./fixtures/plutus-vesting.ts.txt"; +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; + const writeMock = writeFile as jest.Mock; expect(writeMock).toHaveBeenCalled(); diff --git a/packages/translucent-blueprint/tsconfig.json b/packages/translucent-blueprint/tsconfig.json new file mode 100644 index 0000000..c6874ad --- /dev/null +++ b/packages/translucent-blueprint/tsconfig.json @@ -0,0 +1,21 @@ +{ + "compilerOptions": { + "outDir": "./dist", + "rootDir": "./src", + "types": [ + "bun-types", + "jest" + ], + "lib": [ + "ESNext" + ], + "module": "esnext", + "moduleResolution": "Node", + }, + "include": [ + "./src/**/*.ts" + ], + "exclude": [ + "**/node_modules" + ] +}