syntex-filesystem
Advanced tools
Comparing version 1.0.2-b9 to 1.0.2
{ | ||
"env": { | ||
"browser": true, | ||
"es2021": true, | ||
"node": true | ||
}, | ||
"extends": "eslint:recommended", | ||
"parserOptions": { | ||
"ecmaVersion": 13, | ||
"sourceType": "module" | ||
}, | ||
"rules": { | ||
} | ||
"env": { | ||
"browser": true, | ||
"es2021": true, | ||
"node": true | ||
}, | ||
"extends": "eslint:recommended", | ||
"parserOptions": { | ||
"ecmaVersion": 13, | ||
"sourceType": "module" | ||
}, | ||
"rules": { | ||
} | ||
} |
125
main.js
@@ -9,2 +9,5 @@ const fs = require('fs'), path = require('path'); | ||
{ | ||
this.running = []; | ||
this.query = {}; | ||
this.logger = platform.logger; | ||
@@ -54,5 +57,5 @@ | ||
{ | ||
for(const i in directories) | ||
for(const directory of directories) | ||
{ | ||
var absPath = path.join(this.basePath, directories[i]); | ||
var absPath = path.join(this.basePath, directory); | ||
@@ -91,3 +94,10 @@ if(!fs.existsSync(absPath)) | ||
{ | ||
cache[filePath] = JSON.stringify(file); | ||
if(path.parse(filePath).ext == '.json') | ||
{ | ||
cache[filePath] = JSON.stringify(file); | ||
} | ||
else | ||
{ | ||
cache[filePath] = file; | ||
} | ||
} | ||
@@ -101,3 +111,3 @@ | ||
reject(); | ||
reject(e); | ||
} | ||
@@ -111,3 +121,3 @@ } | ||
{ | ||
reject(); | ||
reject(error); | ||
} | ||
@@ -141,23 +151,43 @@ else | ||
{ | ||
if(path.parse(filePath).ext == '.json') | ||
if(!this.running.includes(filePath)) | ||
{ | ||
data = JSON.stringify(data, null, '\t'); | ||
} | ||
this.running.push(filePath); | ||
fs.writeFile(filePath, data, (error) => { | ||
if(!error) | ||
if(path.parse(filePath).ext == '.json') | ||
{ | ||
if(this.enableCache) | ||
data = JSON.stringify(data, null, '\t'); | ||
} | ||
fs.writeFile(filePath, data, (error) => { | ||
if(!error) | ||
{ | ||
cache[filePath] = JSON.stringify(JSON.parse(data)); | ||
if(this.enableCache) | ||
{ | ||
if(path.parse(filePath).ext == '.json') | ||
{ | ||
cache[filePath] = JSON.stringify(JSON.parse(data)); | ||
} | ||
else | ||
{ | ||
cache[filePath] = data; | ||
} | ||
} | ||
} | ||
} | ||
else | ||
{ | ||
this.logger.log('error', 'bridge', 'Bridge', '[' + path.parse(filePath).base + '] %update_error%!', error); | ||
} | ||
else | ||
{ | ||
this.logger.log('error', 'bridge', 'Bridge', '[' + path.parse(filePath).base + '] %update_error%!', error); | ||
} | ||
resolve({ success : error == null, changed : true }); | ||
}); | ||
this.running.splice(this.running.indexOf(filePath), 1); | ||
resolve({ success : error == null, changed : true }); | ||
delete this.query[this._runQuery(filePath)]; | ||
}); | ||
} | ||
else | ||
{ | ||
this._addQuery({ filePath, data, resolve }); | ||
} | ||
} | ||
@@ -214,20 +244,12 @@ else | ||
{ | ||
var fileArray = []; | ||
var fileArray = {}; | ||
for(const i in files) | ||
for(const file of files) | ||
{ | ||
if(fs.statSync(path.join(filePath, files[i])).isFile()) | ||
if(fs.statSync(path.join(filePath, file)).isFile()) | ||
{ | ||
try | ||
{ | ||
var obj = JSON.parse(fs.readFileSync(path.join(filePath, files[i])).toString()); | ||
this.readFile(path.join(filePath, file)).then((content) => { | ||
obj.id = path.parse(files[i]).name; | ||
fileArray.push(obj); | ||
} | ||
catch(e) | ||
{ | ||
this.logger.log('error', 'bridge', 'Bridge', '[' + path.parse(files[i]).base + '] %parse_error%!', e); | ||
} | ||
fileArray[file] = content; | ||
}); | ||
} | ||
@@ -253,5 +275,9 @@ } | ||
{ | ||
if(this.enableCache && cache[filePath] != null && cache[filePath] == JSON.stringify(data)) | ||
if(this.enableCache && cache[filePath] != null) | ||
{ | ||
return false; | ||
if((path.parse(filePath).ext == '.json' && cache[filePath] == JSON.stringify(data)) | ||
|| (path.parse(filePath).ext != '.json' && cache[filePath] == data)) | ||
{ | ||
return false; | ||
} | ||
} | ||
@@ -261,2 +287,29 @@ | ||
} | ||
_addQuery(query) | ||
{ | ||
var id = 0, keys = Object.keys(this.query); | ||
if(keys.length > 0) | ||
{ | ||
id = parseInt(keys[keys.length - 1]) + 1; | ||
} | ||
this.query[id] = query; | ||
} | ||
_runQuery(filePath) | ||
{ | ||
for(const id in this.query) | ||
{ | ||
const file = this.query[id]; | ||
if(file.filePath == filePath) | ||
{ | ||
this.writeFile(file.filePath, file.data).then((response) => file.resolve(response)); | ||
return id; | ||
} | ||
} | ||
} | ||
} |
{ | ||
"name": "syntex-filesystem", | ||
"version": "1.0.2-b9", | ||
"version": "1.0.2", | ||
"description": "A Basic File System", | ||
@@ -12,3 +12,3 @@ "main": "main.js", | ||
"dependencies": { | ||
"syntex-logger": "1.0.8-b21" | ||
"syntex-logger": "1.0.8" | ||
}, | ||
@@ -15,0 +15,0 @@ "keywords": [ |
@@ -34,3 +34,9 @@ # SynTex Filesystem | ||
}).catch(() => {})); | ||
}).catch((error) => { | ||
if(error != null) | ||
{ | ||
logger.err(error); | ||
} | ||
}); | ||
}); | ||
@@ -37,0 +43,0 @@ ``` |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
8922
270
1
47
+ Addedsyntex-logger@1.0.8(transitive)
- Removedsyntex-logger@1.0.8-b21(transitive)
Updatedsyntex-logger@1.0.8