35 lines
		
	
	
		
			954 B
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			35 lines
		
	
	
		
			954 B
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
| import fs from 'fs';
 | |
| import { Variable } from '../struct/variable.js';
 | |
| import { Context } from '../struct/context.js';
 | |
| 
 | |
| export const SettingsReader = {
 | |
|     trimSettingsFromContent(rawContent) {
 | |
|         return rawContent;
 | |
|     },
 | |
|     readSettingsFromContent(rawContent) {
 | |
|         return [];
 | |
|     },
 | |
|     readDirectorySettings(directoryPath) {
 | |
|         if(!fs.existsSync(directoryPath)) {
 | |
|             return new Context();
 | |
|         }
 | |
| 
 | |
|         if(!directoryPath.endsWith('/')) {
 | |
|             directoryPath += '/';
 | |
|         }
 | |
| 
 | |
|         const settingsPath = directoryPath + '_settings.json';
 | |
|         if(!fs.existsSync(settingsPath)) {
 | |
|             return new Context();
 | |
|         }
 | |
| 
 | |
|         const settingsFileContent = fs.readFileSync(settingsPath, { encoding: 'utf-8' });
 | |
|         const dict = JSON.parse(settingsFileContent);
 | |
| 
 | |
|         const vars = Object.keys(dict).map(
 | |
|             (k) => new Variable(k, dict[k])
 | |
|         );
 | |
| 
 | |
|         return new Context(vars);
 | |
|     }
 | |
| }; | 
