Skip to content

Commit

Permalink
fix: use fs.readFileSync to read from file (#9)
Browse files Browse the repository at this point in the history
* fix: use fs.readFileSync to read from file

* fix: coorect import of fs

* fix: change name to slangroom fs packageduring import
  • Loading branch information
matteo-cristino authored Jun 15, 2024
1 parent 1990bb4 commit 4fe5afd
Showing 1 changed file with 9 additions and 15 deletions.
24 changes: 9 additions & 15 deletions src/lib/chain.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import fs from 'fs';

import { Slangroom } from '@slangroom/core';
import { fs } from '@slangroom/fs';
import { fs as slangroomfs } from '@slangroom/fs';
import { git } from '@slangroom/git';
import { helpers } from '@slangroom/helpers';
import { http } from '@slangroom/http';
Expand All @@ -14,7 +16,7 @@ import { wallet } from '@slangroom/wallet';
import { zencode } from '@slangroom/zencode';

const slang = new Slangroom(
fs,
slangroomfs,
git,
helpers,
http,
Expand All @@ -29,16 +31,8 @@ const slang = new Slangroom(
zencode,
);

const readFromFileContract = `Rule unknown ignore
Given I send path 'path' and read verbatim file content and output into 'content'
Given I have a 'string' named 'content'
Then print the 'content'
`;
const readFromFile = async (path: string): Promise<string> => {
const { result } = await slang.execute(readFromFileContract, {
data: { path: path },
});
return result.content as string;
const readFromFile = (path: string): string => {
return fs.readFileSync(path).toString('utf-8');
};

type Step = {
Expand Down Expand Up @@ -107,7 +101,7 @@ export const execute = async (
let firstIteration = true;
for (const step of steps.steps) {
let data = step.dataFromFile
? await readFromFile(step.dataFromFile)
? readFromFile(step.dataFromFile)
: step.dataFromStep
? results[step.dataFromStep]
: step.data;
Expand All @@ -116,13 +110,13 @@ export const execute = async (
firstIteration = false;
}
let keys = step.keysFromFile
? await readFromFile(step.keysFromFile)
? readFromFile(step.keysFromFile)
: step.keysFromStep
? results[step.keysFromStep]
: step.keys;
const conf = step.conf ? step.conf : steps.conf;
const zencode = step.zencodeFromFile
? await readFromFile(step.zencodeFromFile)
? readFromFile(step.zencodeFromFile)
: step.zencode || '';
if (steps.verbose) {
console.log(`Executing contract ${step.id} `);
Expand Down

0 comments on commit 4fe5afd

Please sign in to comment.