mirror of
https://github.com/easingthemes/ssh-deploy
synced 2025-04-21 07:42:12 +00:00
log error and exit
This commit is contained in:
parent
b8f0959bb4
commit
25122c8438
@ -16,15 +16,20 @@ const validateDir = (dir) => {
|
|||||||
console.log('✅ [DIR] dir created.');
|
console.log('✅ [DIR] dir created.');
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleError = (message, isRequired) => {
|
||||||
|
if (isRequired) {
|
||||||
|
throw new Error(message);
|
||||||
|
}
|
||||||
|
console.warn(message);
|
||||||
|
};
|
||||||
|
|
||||||
const writeToFile = ({ dir, filename, content, isRequired, mode = '0o644' }) => {
|
const writeToFile = ({ dir, filename, content, isRequired, mode = '0o644' }) => {
|
||||||
validateDir(dir);
|
validateDir(dir);
|
||||||
const filePath = join(dir, filename);
|
const filePath = join(dir, filename);
|
||||||
|
|
||||||
if (existsSync(filePath)) {
|
if (existsSync(filePath)) {
|
||||||
console.log(`[FILE] ${filePath} file exist`);
|
const message = `⚠️ [FILE] ${filePath} Required file exist.`;
|
||||||
if (isRequired) {
|
handleError(message, isRequired);
|
||||||
throw new Error(`⚠️ [FILE] ${filePath} Required file exist, aborting ...`);
|
|
||||||
}
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -34,8 +39,9 @@ const writeToFile = ({ dir, filename, content, isRequired, mode = '0o644' }) =>
|
|||||||
encoding: 'utf8',
|
encoding: 'utf8',
|
||||||
mode
|
mode
|
||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (error) {
|
||||||
throw new Error(`⚠️[FILE] Writing to file error. filePath: ${filePath}, message: ${e.message}`);
|
const message = `⚠️[FILE] Writing to file error. filePath: ${filePath}, message: ${error.message}`;
|
||||||
|
handleError(message, isRequired);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user