From cec2a90daef637528cdf246aab09062c2f7f8e41 Mon Sep 17 00:00:00 2001 From: kriskbx Date: Thu, 4 Oct 2018 17:40:07 +0200 Subject: [PATCH] fix #72 --- documentation.md | 2 +- package.json | 1 + src/include/file-config.js | 11 ++++++++++- yarn.lock | 4 ++++ 4 files changed, 16 insertions(+), 2 deletions(-) diff --git a/documentation.md b/documentation.md index 62ae72b..fdef25a 100644 --- a/documentation.md +++ b/documentation.md @@ -37,7 +37,7 @@ yarn global add gitlab-time-tracker --prefix /usr/local Run the config command to create a config file and open it in your default editor. In linux terminal, you must set your preferred editor in the environment. For example, use `export EDITOR=vim` to edit the files with vim (put this in `.bashrc` or similar to have it always configured). -If nothing happens, open the file manually: `~/.gtt/config.yml` - on Windows: `C:\Users\YourUserName\.gtt\config.yml` +If nothing happens, open the file manually: `~/.local/share/.gtt` - on Windows: `C:\Users\YourUserName\.gtt\config.yml` ```shell gtt config diff --git a/package.json b/package.json index af2b296..47b3d09 100755 --- a/package.json +++ b/package.json @@ -48,6 +48,7 @@ "request-promise-native": "^1.0.4", "tempfile": "^2.0.0", "underscore": "^1.9.1", + "xdg-basedir": "^3.0.0", "xlsx": "^0.13.5" }, "devDependencies": { diff --git a/src/include/file-config.js b/src/include/file-config.js index dd09dcb..b37456b 100755 --- a/src/include/file-config.js +++ b/src/include/file-config.js @@ -1,6 +1,7 @@ const fs = require('fs'); const path = require('path'); const os = require("os"); +const xdgBaseDir = require('xdg-basedir'); const config = require('./config'); const yaml = require('read-yaml'); const hash = require('hash-sum'); @@ -84,6 +85,10 @@ class fileConfig extends config { } assertGlobalConfig() { + if(!fs.existsSync(this.globalDir) && fs.existsSync(this.oldGlobalDir)) { + fs.renameSync(this.oldGlobalDir, this.globalDir); + } + if (!fs.existsSync(this.globalDir)) fs.mkdirSync(this.globalDir, '0750', true); if (!fs.existsSync(this.frameDir)) fs.mkdirSync(this.frameDir, '0750', true); if (!fs.existsSync(this.cacheDir)) fs.mkdirSync(this.cacheDir, '0750', true); @@ -114,10 +119,14 @@ class fileConfig extends config { return '.gtt.yml'; } - get globalDir() { + get oldGlobalDir() { return Fs.join(process.env[(process.platform == 'win32') ? 'USERPROFILE' : 'HOME'], '.gtt'); } + get globalDir() { + return Fs.join(xdgBaseDir.data, '.gtt'); + } + get frameDir() { return Fs.join(this.globalDir, 'frames'); } diff --git a/yarn.lock b/yarn.lock index 2acf365..896c3a6 100755 --- a/yarn.lock +++ b/yarn.lock @@ -2529,6 +2529,10 @@ wrench@1.3.x: version "1.3.9" resolved "https://registry.yarnpkg.com/wrench/-/wrench-1.3.9.tgz#6f13ec35145317eb292ca5f6531391b244111411" +xdg-basedir@^3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/xdg-basedir/-/xdg-basedir-3.0.0.tgz#496b2cc109eca8dbacfe2dc72b603c17c5870ad4" + xlsx@^0.13.5: version "0.13.5" resolved "https://registry.yarnpkg.com/xlsx/-/xlsx-0.13.5.tgz#65826ba1944c6f4d6c023b7eb6c89e6b6e0d71b7"