florian-lefebvre / astro-integration-kit

A package that contains utilities to help you build Astro integrations.
https://astro-integration-kit.netlify.app
MIT License
46 stars 8 forks source link

Util that can create and read files from a hidden folder in the user's project #80

Open jdtjenkins opened 4 months ago

jdtjenkins commented 4 months ago

This is more of an RFC I guess, but what do we think about a utility that lets the author create and read files inside a hidden folder just for that integration inside a user's project?

So it'd be something like this:

({ createHiddenFile, readHiddenFile }) => {
  createHiddenFile({
    name: 'foo.ts',
    content: `export default {}`
  })

  const myHiddenFile = await readHiddenFile('foo.ts')
}

These would then save at ${ root }/.[integration.name]/foo.ts So right next to the hidden .astro folder. And it can't read/write outside that folder.

For context, the usecase is:

For my themes, I'm planning on shipping encrypted versions of my component files so that then they can be decrypted on the user's machine if they have the correct permissions with their env variables. So they'll set an env key, it'll check the api for their "level" and then decrypt the components for that level.

But I don't want it to have to make an api call each time they run or build their project. So once it's done one call and gotten the decryption keys I want to store them on the user's machine. Then they can still develop and reinstall and everything without the api.

I realise I could do this relatively easily without a utility. But I'm going to implement this either way, so just wondered if other people thought there'd be any interest in making it an AIK util.

florian-lefebvre commented 4 months ago

Isn't it a good usecase for node_modules caching? Like storing at .node_modules/.your-folder. This way it's even cached by hosts like vercel. That being said, I think it's a great idea. This way we can add the folder name to .gitignore as needed

jdtjenkins commented 4 months ago

Yeah actually that's a good idea, to cache it in the node modules. I'm not really sure what would be best. But yeah whether it's stored in node_modules or a level up, just a little util that can just handle it for you