From 91f978d59078df27b51cc5c1f06e0eb277d6339f Mon Sep 17 00:00:00 2001 From: shimataro Date: Mon, 8 Mar 2021 18:02:01 +0900 Subject: [PATCH] refactor --- lib/index.js | 23 ++++++++++++----------- src/main.ts | 24 +++++++++++++----------- 2 files changed, 25 insertions(+), 22 deletions(-) diff --git a/lib/index.js b/lib/index.js index 5d3bb87..3b1f766 100644 --- a/lib/index.js +++ b/lib/index.js @@ -446,16 +446,7 @@ function main() { mode: 0o700, }); // files to be created - const files = [ - { - name: "config", - contents: insertLf(config, true, true), - options: { - mode: 0o644, - flag: "a", - }, - }, - ]; + const files = []; if (shouldCreateKeyFile(path_1.default.join(dirName, name), ifKeyExists)) { files.push({ name: name, @@ -466,7 +457,7 @@ function main() { }, }); } - if (!noKnownHosts) { + if (knownHosts !== "") { files.push({ name: "known_hosts", contents: insertLf(knownHosts, true, true), @@ -476,6 +467,16 @@ function main() { }, }); } + if (config !== "") { + files.push({ + name: "config", + contents: insertLf(config, true, true), + options: { + mode: 0o644, + flag: "a", + }, + }); + } // create files for (const file of files) { const fileName = path_1.default.join(dirName, file.name); diff --git a/src/main.ts b/src/main.ts index 75ab350..c040087 100644 --- a/src/main.ts +++ b/src/main.ts @@ -38,16 +38,7 @@ function main(): void }); // files to be created - const files: FileInfo[] = [ - { - name: "config", - contents: insertLf(config, true, true), - options: { - mode: 0o644, - flag: "a", - }, - }, - ]; + const files: FileInfo[] = []; if(shouldCreateKeyFile(path.join(dirName, name), ifKeyExists)) { files.push({ @@ -59,7 +50,7 @@ function main(): void }, }); } - if(!noKnownHosts) + if(knownHosts !== "") { files.push({ name: "known_hosts", @@ -70,6 +61,17 @@ function main(): void }, }); } + if(config !== "") + { + files.push({ + name: "config", + contents: insertLf(config, true, true), + options: { + mode: 0o644, + flag: "a", + }, + }); + } // create files for(const file of files)