diff --git a/snippets/snippet/index.js b/snippets/snippet/index.js index f1c156d..545c663 100644 --- a/snippets/snippet/index.js +++ b/snippets/snippet/index.js @@ -27,15 +27,15 @@ function run (folder, args) { function assert (folder, args) { const tests = [ { - f: () => (args.length === 1), - reason: 'not enough arguments' + f: () => (args.length < 2), + reason: 'too many arguments' }, { - f: () => (typeof args[0] === 'string'), + f: () => (args.length === 0 || typeof args[0] === 'string'), reason: 'name is not a string' }, { - f: () => (/^[a-z]+$/iu).test (args[0]), + f: () => (args.length === 0 || (/^[a-z]+$/iu).test (args[0])), reason: 'name can only contain [a-z]' }, { @@ -44,7 +44,16 @@ function assert (folder, args) { }, { f: () => (fs.existsSync (folder)), - reason: 'cwd does not exist' + reason: 'cwd does not exist (internal error)' + }, + { + f: () => (args.length === 1 || fs.readdirSync (folder).length === 0), + reason: 'folder is not empty' + }, + { + f: () => (args.length === 0 + || !fs.existsSync (path.join (folder, args[0]))), + reason: 'folder already exists' } ]; for (const test of tests) diff --git a/snippets/snippet/template/index.js b/snippets/snippet/template/index.js index f1c156d..545c663 100644 --- a/snippets/snippet/template/index.js +++ b/snippets/snippet/template/index.js @@ -27,15 +27,15 @@ function run (folder, args) { function assert (folder, args) { const tests = [ { - f: () => (args.length === 1), - reason: 'not enough arguments' + f: () => (args.length < 2), + reason: 'too many arguments' }, { - f: () => (typeof args[0] === 'string'), + f: () => (args.length === 0 || typeof args[0] === 'string'), reason: 'name is not a string' }, { - f: () => (/^[a-z]+$/iu).test (args[0]), + f: () => (args.length === 0 || (/^[a-z]+$/iu).test (args[0])), reason: 'name can only contain [a-z]' }, { @@ -44,7 +44,16 @@ function assert (folder, args) { }, { f: () => (fs.existsSync (folder)), - reason: 'cwd does not exist' + reason: 'cwd does not exist (internal error)' + }, + { + f: () => (args.length === 1 || fs.readdirSync (folder).length === 0), + reason: 'folder is not empty' + }, + { + f: () => (args.length === 0 + || !fs.existsSync (path.join (folder, args[0]))), + reason: 'folder already exists' } ]; for (const test of tests)