hyperbrew / bolt-cep

A lightning-fast boilerplate for building Adobe CEP Extensions in React, Vue, or Svelte built on Vite + TypeScript + Sass
MIT License
309 stars 40 forks source link

How to properly read assets copied by CEP_Config.copyAssets option? #96

Closed avibiton13 closed 1 year ago

avibiton13 commented 1 year ago

A high-level view of my root src folder: src --- assets ------- schemas --- js --- jsx --- shared

I've added this path: assets/schemas to the copyAssets option inside CEP_Config at ./cep.config.ts, and in return, the folder ./src/assets/schemas gets copied to ./dist/cep/assets/schemas.

I have a CEP code that needs to read a JSON file from that schemas folder, and I'm doing it that way:

const schema = JSON.parse(fs.readFileSync(path.join(__dirname, "assets", "schemas", "schema.json")).toString());
...

When working on "dev" mode - i.e. yarn build && yarn dev the script finds the JSON file successfully, however when I package it using the action yarn zxp and then install it(using ExManCmd) it doesn't find the file - and that's because the value of __dirname is different across those two different environments!

Can anyone please provide an example of how to properly copy assets files/directories and use them in all environments("dev"/"prod")?

avibiton13 commented 1 year ago

Just figured out my mistake: I've just replaced __dirname with csi.getSystemPath("extension")