@@ -3,12 +3,7 @@ const path = require('path');
33const config = require('./config');
44const yaml = require('read-yaml');
55const hash = require('hash-sum');
6-
7- const globalConfigDir = process.env[(process.platform == 'win32') ? 'USERPROFILE' : 'HOME'] + '/.gtt';
8- const globalConfigFile = globalConfigDir + '/config.yml';
9- const frameDir = globalConfigDir + '/frames';
10- const cacheDir = globalConfigDir + '/cache';
11- const localConfigFile = '/.gtt.yml';
6+ const Fs = require('./filesystem');
127
138/**
149 * file config with local and global configuration files
@@ -20,12 +15,14 @@ class fileConfig extends config {
2015 */
2116 constructor(workDir) {
2217 super();
18+
2319 this.assertGlobalConfig();
2420 this.workDir = workDir;
2521 this.data = Object.assign(this.data, this.localExists() ? this.parseLocal() : this.parseGlobal());
2622 this.cache = {
2723 get: this._cacheGet,
28- set: this._cacheSet
24+ set: this._cacheSet,
25+ dir: this.cacheDir
2926 };
3027 }
3128
@@ -62,7 +59,7 @@ class fileConfig extends config {
6259 while (workDir) {
6360 workDir = path.dirname(workDir);
6461 if (workDir === '/') workDir = '';
65- if (fs.existsSync(workDir + localConfigFile)) {
62+ if (fs.existsSync(Fs.join( workDir, this. localConfigFile) )) {
6663 this.workDir = workDir;
6764 return true;
6865 }
@@ -81,38 +78,43 @@ class fileConfig extends config {
8178 }
8279
8380 _cacheGet(key) {
84- let file = this.cacheDir + '/' + hash(key);
81+ let file = Fs.join( this.dir, hash(key) );
8582 if (!fs.existsSync(file)) return false;
8683
8784 return JSON.parse(fs.readFileSync(file));
8885 }
8986
9087 _cacheSet(key, value) {
91- let file = this.cacheDir + '/' + hash(key);
88+ let file = Fs.join( this.dir, hash(key) );
9289 if (fs.existsSync(file)) fs.unlinkSync(file);
93- fs.appendFile(file, JSON.stringify(value), () => {});
90+ fs.appendFile(file, JSON.stringify(value), () => {
91+ });
9492
9593 return value;
9694 }
9795
98- get cacheDir() {
99- return cacheDir;
96+ get localConfigFile() {
97+ return '.gtt.yml';
98+ }
99+
100+ get globalDir() {
101+ return Fs.join(process.env[(process.platform == 'win32') ? 'USERPROFILE' : 'HOME'], '.gtt');
100102 }
101103
102104 get frameDir() {
103- return frameDir ;
105+ return Fs.join(this.globalDir, 'frames') ;
104106 }
105107
106- get globalDir () {
107- return globalConfigDir;
108+ get cacheDir () {
109+ return Fs.join(this.globalDir, 'cache')
108110 }
109111
110112 get global() {
111- return globalConfigFile ;
113+ return Fs.join(this.globalDir, 'config.yml') ;
112114 }
113115
114116 get local() {
115- return this.workDir + localConfigFile;
117+ return Fs.join( this.workDir, this. localConfigFile) ;
116118 }
117119}
118120
0 commit comments