config-path.js 842 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. var os = require('os');
  2. var path = require('path');
  3. var userHome = require('homedir-polyfill')();
  4. var env = process.env;
  5. var name = 'js-v8flags';
  6. function macos() {
  7. var library = path.join(userHome, 'Library');
  8. return path.join(library, 'Caches', name);
  9. }
  10. function windows() {
  11. var appData = env.LOCALAPPDATA || path.join(userHome, 'AppData', 'Local');
  12. return path.join(appData, name);
  13. }
  14. // https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html
  15. function linux() {
  16. var username = path.basename(userHome);
  17. return path.join(env.XDG_CACHE_HOME || path.join(userHome, '.cache'), name);
  18. }
  19. module.exports = function(platform) {
  20. if (!userHome) {
  21. return os.tmpdir();
  22. }
  23. if (platform === 'darwin') {
  24. return macos();
  25. }
  26. if (platform === 'win32') {
  27. return windows();
  28. }
  29. return linux();
  30. };