diff --git a/packages/core/src/appdata.js b/packages/core/src/appdata.js new file mode 100644 index 0000000..4e3ce6c --- /dev/null +++ b/packages/core/src/appdata.js @@ -0,0 +1,24 @@ +import {homedir, platform} from 'os'; +import {join} from 'path'; + +import mkdirp from 'mkdirp'; + +export default (subdir) => { + let appdata; + switch (platform()) { + case 'windows': + appdata = '%APPDATA%'; + break; + case 'darwin': + appdata = join(homedir(), 'Library/Application Support'); + break; + default: + appdata = process.env.XDG_CONFIG_HOME || join(homedir(), '.config'); + break; + } + if (subdir) { + appdata = join(appdata, subdir); + } + mkdirp.sync(appdata); + return appdata; +}; diff --git a/packages/core/src/server.js b/packages/core/src/server.js index 7d487fc..7c801cb 100644 --- a/packages/core/src/server.js +++ b/packages/core/src/server.js @@ -1,3 +1,5 @@ +export {default as appdata} from './appdata'; + export default { hooks: { '@latus/http/plugins': (req, {config: {'@latus/core': {id}}}) => ({