47 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			47 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
| 'use strict';
 | |
| 
 | |
| var fs = require('fs');
 | |
| var path = require('path');
 | |
| 
 | |
| module.exports = {
 | |
|   directives: {
 | |
|     get: function (providerUri) {
 | |
|       // TODO make safe
 | |
|       try {
 | |
|         return require(path.join(process.cwd(), providerUri + '.directives.json'));
 | |
|       } catch(e) {
 | |
|         return null;
 | |
|       }
 | |
|     }
 | |
|   , set: function (providerUri, directives) {
 | |
|       fs.writeFileSync(path.join(process.cwd(), providerUri + '.directives.json'), JSON.stringify(directives, null, 2));
 | |
|       return directives;
 | |
|     }
 | |
|   }
 | |
| 
 | |
| , sessions: {
 | |
|     get: function (providerUri, id) {
 | |
|       // TODO make safe
 | |
|       try {
 | |
|         if (id) {
 | |
|           return require(path.join(process.cwd(), providerUri + '.' + id + '.session.json'));
 | |
|         }
 | |
|         else {
 | |
|           return require(path.join(process.cwd(), providerUri + '.session.json'));
 | |
|         }
 | |
|       } catch(e) {
 | |
|         return null;
 | |
|       }
 | |
|     }
 | |
|   , set: function (providerUri, session, id) {
 | |
|       if (id) {
 | |
|         fs.writeFileSync(path.join(process.cwd(), providerUri + '.' + id + '.session.json'), JSON.stringify(session, null, 2));
 | |
|       }
 | |
|       else {
 | |
|         fs.writeFileSync(path.join(process.cwd(), providerUri + '.session.json'), JSON.stringify(session, null, 2));
 | |
|       }
 | |
|       return session;
 | |
|     }
 | |
|   }
 | |
| };
 |