more versatile template

This commit is contained in:
Timo Hocker 2020-01-15 20:11:16 +01:00
parent 073f905ef9
commit 5be9e89e0f
2 changed files with 28 additions and 10 deletions

View File

@ -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)

View File

@ -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)