From 12b43545fd4a35f5178484c5e32d6a5961de6526 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Drago=C8=99=20Str=C4=83inu?= Date: Wed, 25 May 2022 15:53:40 +0300 Subject: [PATCH] feat: config multiple files (#6) --- src/index.js | 46 ++++++++++++++++++++++++---------------------- 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/src/index.js b/src/index.js index 5122b42..8e0e285 100755 --- a/src/index.js +++ b/src/index.js @@ -23,30 +23,32 @@ const sourceDirName = packageJSON["symlink-config"]?.path || "./support/root"; const sourceDir = path.join(_dirname, sourceDirName); -const [, , arg] = process.argv; +const args = process.argv.slice(2); -if (arg) { - if (!fs.existsSync(path.join(_dirname, arg))) { - console.log(`${arg} does not exists.`); - process.exit(1); - } - if (fs.existsSync(path.join(sourceDir, arg))) { - console.log( - `${arg} already exists in ${sourceDir.replace(_dirname + "/", "")}` - ); - process.exit(1); - } - try { - if (!fs.existsSync(sourceDir)) { - fs.mkdirSync(sourceDir, { recursive: true }); - console.log("Directory support/root was created."); +for (const arg of args) { + if (arg) { + if (!fs.existsSync(path.join(_dirname, arg))) { + console.log(`${arg} does not exists.`); + continue; + } + if (fs.existsSync(path.join(sourceDir, arg))) { + console.log( + `${arg} already exists in ${sourceDir.replace(_dirname + "/", "")}` + ); + continue; + } + try { + if (!fs.existsSync(sourceDir)) { + fs.mkdirSync(sourceDir, { recursive: true }); + console.log("Directory support/root was created."); + } + + fs.renameSync(path.join(_dirname, arg), path.join(sourceDir, arg)); + fs.appendFileSync(path.join(_dirname, ".gitignore"), `/${arg}\n`); + child_process.execSync(`git rm -rf ${arg}`); + } catch (err) { + console.error(err); } - - fs.renameSync(path.join(_dirname, arg), path.join(sourceDir, arg)); - fs.appendFileSync(path.join(_dirname, ".gitignore"), `/${arg}\n`); - child_process.execSync(`git rm -rf ${arg}`); - } catch (err) { - console.error(err); } }