44 lines
		
	
	
		
			1008 B
		
	
	
	
		
			JavaScript
		
	
	
	
			
		
		
	
	
			44 lines
		
	
	
		
			1008 B
		
	
	
	
		
			JavaScript
		
	
	
	
let parser = require("./Parse");
 | 
						|
let crypto = require("node:crypto");
 | 
						|
let vm = require("node:vm");
 | 
						|
 | 
						|
module.exports = File;
 | 
						|
/**
 | 
						|
 * @class File
 | 
						|
 */
 | 
						|
function File()
 | 
						|
{
 | 
						|
    this.content = "";
 | 
						|
    this.contentmd5 = "";
 | 
						|
    this.parsedContent = "";
 | 
						|
    this.cachedData = undefined;
 | 
						|
};
 | 
						|
 | 
						|
 | 
						|
function sha256(content)
 | 
						|
{
 | 
						|
    return crypto.createHash("sha256").update(content,'utf-8').digest('hex');
 | 
						|
}
 | 
						|
 | 
						|
File.prototype.build = function(){
 | 
						|
    this.contentmd5 = sha256(this.content);
 | 
						|
    this.parsedContent = parser(this);
 | 
						|
};
 | 
						|
 | 
						|
File.prototype.isRequiredRebuild = function(content){
 | 
						|
    return this.contentmd5 == sha256(content);
 | 
						|
};
 | 
						|
File.prototype.execute = function(memoriable){
 | 
						|
    let output = [];
 | 
						|
    let t = new vm.Script(this.parsedContent,{
 | 
						|
        cachedData: this.cachedData,
 | 
						|
    });
 | 
						|
    let content = vm.createContext({
 | 
						|
        ...memoriable,
 | 
						|
        output,
 | 
						|
        echo:(...args) => output.push(...args)
 | 
						|
    });
 | 
						|
    t.runInContext(content);
 | 
						|
    this.cachedData = t.createCachedData();
 | 
						|
    return output.join('');
 | 
						|
}; |