accordproject / template-archive

Smart Legal Contracts & Templating System
https://accordproject.org/projects/cicero/
Apache License 2.0
280 stars 119 forks source link

Cicero-core: Provide custom loadfilecontents and loadfilebuffer options in ``Template.fromDirectory()`` #745

Open Ayman161803 opened 2 years ago

Ayman161803 commented 2 years ago

Feature Request 🛍️

Provide custom loadfilecontents and loadfilebuffer options in Template.fromDirectory()

Use Case

Loading template directories from a virtual file system where fs module cannot be used. Example: VSCode-Web

Possible Solution

The options dictionary can accept option parameter loadFileContents and loadFileBuffer to alter the way in which file content is read from memory.

Context

A simple fix to this can be help us load Templates in VSCode Extension where only file reading logic is to be altered without altering the way in which the contents of these files are used to create the Template object.

Would you like to work on this?

Yes

mehmettokgoz commented 1 year ago

Hi @Ayman161803, can you elaborate on this issue a little more?

Ayman161803 commented 1 year ago

Hey @mehmettokgoz!

Apologies for the lack of clarity.

Some context

Currently, the logic written for loading templates from a VSCode workspace here and the logic written here is the same. The only difference is the way in which they load file contents. Where cicero-core uses fs, VSCode extension uses vscode.workspace.fs. Sometime in the future, if the logic to load templates from directories changes in cicero-core here, the same should be reflected in the logic written within VSCode extension code here.

Possible solution to prevent duplicate logic

  1. Allow the passing an optional loadFileBuffer and loadFileContents parameter into fromDirectory method here which will let us use the same fromDirectory method from cicero-core but with different logic to read and write files.
  2. Another way would be to mention the same in the comments above fromDirectory method in cicero-core that the logic is duplicated here. So that whenever something changes in cicero-core, the same is reflected in the code for vscode-extension.

I am not sure if the same can be achieved with the current core library itself. It would be great if you have any inputs @mttrbrts.