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.mts
import os from 'node:os';
import path from 'node:path';
import fs from '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);
export const HOME_DIR = (() => {
let HOME = os.homedir();
if (
os.platform() === 'win32' &&
process.env.APPDATA &&
fs.existsSync(path.normalize(process.env.APPDATA))
) {
HOME = path.normalize(process.env.APPDATA);
} else if (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);
} else if (
process.env.HOME &&
fs.existsSync(path.normalize(path.join(os.homedir(), '.cache')))
) {
HOME = path.normalize(path.join(os.homedir(), '.cache'));
}
}
return HOME;
})(); /** A helper function to retrieve `APPDATA` on winddows and `XDG_CACHE_HOME` on linux*/
export const SRCBOOK_DIR = path.join(HOME_DIR, '.srcbook');
export const SRCBOOKS_DIR = path.join(SRCBOOK_DIR, 'srcbooks');
export const APPS_DIR = path.join(SRCBOOK_DIR, 'apps');
export const DIST_DIR = _dirname;
export const PROMPTS_DIR = path.join(DIST_DIR, 'prompts');
export const IS_PRODUCTION = process.env.NODE_ENV === 'production';
On Linux there's a XDG Base Directory which is a specification to structures different directories created by application.
Right now
srcbookis creating.srcbookin Home directory, which is not terrible but also not ideal.Also on Windows we have
APPDATAto create folders used by application (instead ofUSERPROFILE). You can check Recognized environment variablesI think a code like following