diff --git a/snippets/node/index.js b/snippets/node/index.js index 78c3812..fe31889 100644 --- a/snippets/node/index.js +++ b/snippets/node/index.js @@ -12,10 +12,22 @@ const child_process = require ('child_process'); * @param {Array} args function arguments */ async function run (folder, args) { - const snip_folder = path.join (folder, args[0]); + const snip_folder_path = [ folder ]; + if (args.length > 0) + snip_folder_path.push (args[0]); + const snip_folder = path.join (...snip_folder_path); const template = path.join (__dirname, 'template'); - fs.mkdir (snip_folder); - fs.copy (template, snip_folder); + if (!fs.existsSync (snip_folder)) + fs.mkdir (snip_folder); + for (const f of fs.readdirSync (template)) + fs.copy ( + path.join (template, f), + path.join (snip_folder, f), + { + recursive: true, + filter: (src, dest) => !fs.existsSync (dest) + } + ); child_process.execSync ( 'git init', diff --git a/snippets/snippet/index.js b/snippets/snippet/index.js index 545c663..25abe58 100644 --- a/snippets/snippet/index.js +++ b/snippets/snippet/index.js @@ -11,10 +11,22 @@ const path = require ('path'); * @param {Array} args function arguments */ function run (folder, args) { - const snip_folder = path.join (folder, args[0]); + const snip_folder_path = [ folder ]; + if (args.length > 0) + snip_folder_path.push (args[0]); + const snip_folder = path.join (...snip_folder_path); const template = path.join (__dirname, 'template'); - fs.mkdir (snip_folder); - fs.copy (template, snip_folder); + if (!fs.existsSync (snip_folder)) + fs.mkdir (snip_folder); + for (const f of fs.readdirSync (template)) + fs.copy ( + path.join (template, f), + path.join (snip_folder, f), + { + recursive: true, + filter: (src, dest) => !fs.existsSync (dest) + } + ); } /** diff --git a/snippets/snippet/template/index.js b/snippets/snippet/template/index.js index 545c663..25abe58 100644 --- a/snippets/snippet/template/index.js +++ b/snippets/snippet/template/index.js @@ -11,10 +11,22 @@ const path = require ('path'); * @param {Array} args function arguments */ function run (folder, args) { - const snip_folder = path.join (folder, args[0]); + const snip_folder_path = [ folder ]; + if (args.length > 0) + snip_folder_path.push (args[0]); + const snip_folder = path.join (...snip_folder_path); const template = path.join (__dirname, 'template'); - fs.mkdir (snip_folder); - fs.copy (template, snip_folder); + if (!fs.existsSync (snip_folder)) + fs.mkdir (snip_folder); + for (const f of fs.readdirSync (template)) + fs.copy ( + path.join (template, f), + path.join (snip_folder, f), + { + recursive: true, + filter: (src, dest) => !fs.existsSync (dest) + } + ); } /**