Skip to content

Commit

Permalink
create directory only if not exist
Browse files Browse the repository at this point in the history
  • Loading branch information
shimataro committed Oct 11, 2023
1 parent e5dbb26 commit 50e77d5
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 31 deletions.
28 changes: 14 additions & 14 deletions dist/main.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions dist/main.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/post.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions dist/post.js.map

Large diffs are not rendered by default.

26 changes: 17 additions & 9 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[] = [
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(", ")}`);
}
}

Expand Down

0 comments on commit 50e77d5

Please sign in to comment.