Skip to content

Commit

Permalink
fix: use fs.readFileSync to read from file
Browse files Browse the repository at this point in the history
  • Loading branch information
matteo-cristino committed Jun 15, 2024
1 parent 1990bb4 commit b765583
Showing 1 changed file with 7 additions and 13 deletions.
20 changes: 7 additions & 13 deletions src/lib/chain.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { fs } from 'fs';

import { Slangroom } from '@slangroom/core';
import { fs } from '@slangroom/fs';
import { git } from '@slangroom/git';
Expand Down Expand Up @@ -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 b765583

Please sign in to comment.