You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Follow XDG specifications and windows recognized environment variables #452
On Linux there's a XDG Base Directory which is a specification to structures different directories created by application.
Right now srcbook is creating .srcbook in Home directory, which is not terrible but also not ideal.
Also on Windows we have APPDATA to create folders used by application (instead of USERPROFILE). You can check Recognized environment variables
I think a code like following
// file: packages/api/constants.mtsimportosfrom'node:os';importpathfrom'node:path';importfsfrom'node:fs';import{fileURLToPath}from'url';// When running Srcbook as an npx executable, the cwd is not reliable.// Commands that should be run from the root of the package, like npm scripts// should therefore use DIST_DIR as the cwd.const_filename=fileURLToPath(import.meta.url);const_dirname=path.dirname(_filename);exportconstHOME_DIR=(()=>{letHOME=os.homedir();if(os.platform()==='win32'&&process.env.APPDATA&&fs.existsSync(path.normalize(process.env.APPDATA))){HOME=path.normalize(process.env.APPDATA);}elseif(os.platform()==='linux'){if(process.env.XDG_CACHE_HOME&&fs.existsSync(path.normalize(process.env.XDG_CACHE_HOME))){HOME=path.normalize(process.env.XDG_CACHE_HOME);}elseif(process.env.HOME&&fs.existsSync(path.normalize(path.join(os.homedir(),'.cache')))){HOME=path.normalize(path.join(os.homedir(),'.cache'));}}returnHOME;})();/** A helper function to retrieve `APPDATA` on winddows and `XDG_CACHE_HOME` on linux*/exportconstSRCBOOK_DIR=path.join(HOME_DIR,'.srcbook');exportconstSRCBOOKS_DIR=path.join(SRCBOOK_DIR,'srcbooks');exportconstAPPS_DIR=path.join(SRCBOOK_DIR,'apps');exportconstDIST_DIR=_dirname;exportconstPROMPTS_DIR=path.join(DIST_DIR,'prompts');exportconstIS_PRODUCTION=process.env.NODE_ENV==='production';
Activity