extensions-sdk icon indicating copy to clipboard operation
extensions-sdk copied to clipboard

Ability to create a file on host

Open mikesir87 opened this issue 2 years ago • 1 comments

Elevator Pitch

To support various use cases (such as a tutorial or helping bootstrap projects), I'd like to be able to create a file on the host with a specified filename and contents. I don't currently have the need to specify additional constraints like file permissions, but I could anticipate that might be needed at some point.

Current Limitations

Currently, I am working around this ability by adding an endpoint to my backend that my frontend invokes to drop the file into a directory that's bind mounted with the host. This works, but limits the location of files to that which the extension is mounting (which isn't configurable at runtime). Preferably, I'd like to use the new file picker to let the user choose a directory and then drop files there. If the SDK provided a supported mechanism to create files, I could do so without needing to create a proxy endpoint and volume configuration.

Proposal

As an idea of what I'd like to see, here are some rough typings (totally feel free to adjust these).

I'll admit I'm on the fence on whether the workingDirectory can/should be an option or if it should be expected that the invoker provides a full file path as the first argument. I'd probably leverage the new file picker functionality to pick a directory and simply pass that along. Might be nice to have the ability to set a default working directory, but that can be another discussion.

ddClient.extension.host.createFile(
    filename: String, 
    fileContents: String | Blob, 
    options? : CreateFileOptions) => Promise<CreateFileResult>;

interface CreateFileOptions {
  workingDirectory? : string;
  filePermissions? : "not-sure-of-type-here"
  ....
}

interface CreateFileResult {
  success: boolean;
  filename: String;
  fullPath: String;
}

mikesir87 avatar Apr 12 '22 17:04 mikesir87

Similar to #124 We rely on process.exec and process.spawn which take an options object containing cwd and env. We could expose those two options.

benja-M-1 avatar Jun 27 '22 10:06 benja-M-1