1
0
Fork 0
mirror of https://github.com/shimataro/ssh-key-action.git synced 2025-06-19 22:52:10 +10:00

create directory only if not exist

This commit is contained in:
shimataro 2023-10-11 14:18:34 +09:00
parent e5dbb2663d
commit 50e77d50a7
No known key found for this signature in database
GPG key ID: BE92C05736911A9D
6 changed files with 39 additions and 31 deletions

28
dist/main.js vendored

File diff suppressed because one or more lines are too long

6
dist/main.js.map vendored

File diff suppressed because one or more lines are too long

2
dist/post.js vendored

File diff suppressed because one or more lines are too long

4
dist/post.js.map vendored

File diff suppressed because one or more lines are too long

View file

@ -48,10 +48,10 @@ export function main(): void {
// create ".ssh" directory
const sshDirName = common.getSshDirectory();
const backupSuffix = common.createBackupSuffix(sshDirName);
fs.mkdirSync(sshDirName, {
recursive: true,
mode: 0o700,
});
if (backupSuffix === "") {
createDirectory(sshDirName);
console.log(`✅SSH directory "${sshDirName}" has been created successfully.`);
}
// files to be created
const files: FileInfo[] = [
@ -102,15 +102,23 @@ export function main(): void {
}
common.saveCreatedFileNames(createdFileNames);
if (backupSuffix !== "") {
console.log(`✅SSH directory "${sshDirName}" has been created successfully.`);
}
console.log(`✅Following files has been created in "${sshDirName}" successfully; ${createdFileNames.join(", ")}`);
console.log(`✅Following files have been created in "${sshDirName}" successfully; ${createdFileNames.join(", ")}`);
if (backedUpFileNames.length > 0) {
console.log(`✅Following files has been backed up in suffix "${backupSuffix}" successfully; ${backedUpFileNames.join(", ")}`);
console.log(`✅Following files have been backed up in suffix "${backupSuffix}" successfully; ${backedUpFileNames.join(", ")}`);
}
}
/**
* create directory
* @param dirName directory name to remove
*/
function createDirectory(dirName: string): void {
fs.mkdirSync(dirName, {
recursive: true,
mode: 0o700,
});
}
/**
* back up file
* @param fileName file to back up

View file

@ -26,10 +26,10 @@ export function post(): void {
} else {
// remove created files and restore from backup
const removedFileNames = removeCreatedFiles(sshDirName);
console.log(`✅Following files has been removed successfully; ${removedFileNames.join(", ")}`);
console.log(`✅Following files have been removed successfully; ${removedFileNames.join(", ")}`);
const restoredFileNames = restoreFiles(sshDirName, backupSuffix);
console.log(`✅Following files in suffix "${backupSuffix}" has been restored successfully; ${restoredFileNames.join(", ")}`);
console.log(`✅Following files in suffix "${backupSuffix}" have been restored successfully; ${restoredFileNames.join(", ")}`);
}
}