mirror of
https://github.com/easingthemes/ssh-deploy.git
synced 2025-06-22 12:32:09 +10:00
[code] split helpers into separate files
This commit is contained in:
parent
9cdc72374b
commit
460751d7c3
4 changed files with 180 additions and 141 deletions
38
src/helpers.js
Normal file
38
src/helpers.js
Normal file
|
@ -0,0 +1,38 @@
|
|||
const { existsSync, mkdirSync, writeFileSync } = require('fs');
|
||||
|
||||
const {
|
||||
GITHUB_WORKSPACE
|
||||
} = process.env;
|
||||
|
||||
const validateDir = (dir) => {
|
||||
if (!existsSync(dir)) {
|
||||
console.log(`[SSH] Creating ${dir} dir in `, GITHUB_WORKSPACE);
|
||||
mkdirSync(dir);
|
||||
console.log('✅ [SSH] dir created.');
|
||||
} else {
|
||||
console.log(`[SSH] ${dir} dir exist`);
|
||||
}
|
||||
};
|
||||
|
||||
const validateFile = (filePath) => {
|
||||
if (!existsSync(filePath)) {
|
||||
console.log(`[SSH] Creating ${filePath} file in `, GITHUB_WORKSPACE);
|
||||
try {
|
||||
writeFileSync(filePath, '', {
|
||||
encoding: 'utf8',
|
||||
mode: 0o600
|
||||
});
|
||||
console.log('✅ [SSH] file created.');
|
||||
} catch (e) {
|
||||
console.error('⚠️ [SSH] writeFileSync error', filePath, e.message);
|
||||
process.abort();
|
||||
}
|
||||
} else {
|
||||
console.log(`[SSH] ${filePath} file exist`);
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
validateDir,
|
||||
validateFile
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue