43 lines
1 KiB
JavaScript
43 lines
1 KiB
JavaScript
|
const realpath = require('fs/promises').realpath;
|
||
|
const stat = require('fs/promises').stat;
|
||
|
|
||
|
function fileExists(file) {
|
||
|
return new Promise((resolve, reject) => {
|
||
|
if (file == undefined) {
|
||
|
reject('error: no file given');
|
||
|
}
|
||
|
resolvePath(file)
|
||
|
.then((path) => {
|
||
|
stat(path)
|
||
|
.then((stats) => {
|
||
|
resolve({path, stats});
|
||
|
})
|
||
|
})
|
||
|
.catch(reject);
|
||
|
});
|
||
|
}
|
||
|
|
||
|
function resolvePath(file) {
|
||
|
return new Promise((resolve, reject) => {
|
||
|
if (file == undefined) {
|
||
|
reject('error: no file given');
|
||
|
}
|
||
|
realpath(file)
|
||
|
.then(resolve)
|
||
|
.catch((err) => {
|
||
|
reject('error: resolving path \'' + file + '\' encountered an error >>> ' + err);
|
||
|
});
|
||
|
});
|
||
|
}
|
||
|
|
||
|
function executeCommand(command) {
|
||
|
if (command == undefined) {
|
||
|
return;
|
||
|
}
|
||
|
command = command.trim();
|
||
|
}
|
||
|
|
||
|
module.exports = {
|
||
|
fileExists,
|
||
|
resolvePath
|
||
|
}
|