This repository has been archived on 2024-02-17. You can view files and clone it, but cannot push or open issues or pull requests.
2022-10-25 01:00:01 +03:00
|
|
|
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 = [];
|
2022-10-25 01:10:27 +03:00
|
|
|
let t = new vm.Script(this.parsedContent.ast,{
|
2022-10-25 01:00:01 +03:00
|
|
|
cachedData: this.cachedData,
|
|
|
|
});
|
|
|
|
let content = vm.createContext({
|
|
|
|
...memoriable,
|
|
|
|
output,
|
2022-10-25 01:10:27 +03:00
|
|
|
echo:(...args) => output.push(...args),
|
|
|
|
_external: e => {}
|
2022-10-25 01:00:01 +03:00
|
|
|
});
|
|
|
|
t.runInContext(content);
|
|
|
|
this.cachedData = t.createCachedData();
|
|
|
|
return output.join('');
|
|
|
|
};
|