more versatile template
This commit is contained in:
parent
073f905ef9
commit
5be9e89e0f
@ -27,15 +27,15 @@ function run (folder, args) {
|
|||||||
function assert (folder, args) {
|
function assert (folder, args) {
|
||||||
const tests = [
|
const tests = [
|
||||||
{
|
{
|
||||||
f: () => (args.length === 1),
|
f: () => (args.length < 2),
|
||||||
reason: 'not enough arguments'
|
reason: 'too many arguments'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
f: () => (typeof args[0] === 'string'),
|
f: () => (args.length === 0 || typeof args[0] === 'string'),
|
||||||
reason: 'name is not a 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]'
|
reason: 'name can only contain [a-z]'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -44,7 +44,16 @@ function assert (folder, args) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
f: () => (fs.existsSync (folder)),
|
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)
|
for (const test of tests)
|
||||||
|
@ -27,15 +27,15 @@ function run (folder, args) {
|
|||||||
function assert (folder, args) {
|
function assert (folder, args) {
|
||||||
const tests = [
|
const tests = [
|
||||||
{
|
{
|
||||||
f: () => (args.length === 1),
|
f: () => (args.length < 2),
|
||||||
reason: 'not enough arguments'
|
reason: 'too many arguments'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
f: () => (typeof args[0] === 'string'),
|
f: () => (args.length === 0 || typeof args[0] === 'string'),
|
||||||
reason: 'name is not a 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]'
|
reason: 'name can only contain [a-z]'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -44,7 +44,16 @@ function assert (folder, args) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
f: () => (fs.existsSync (folder)),
|
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)
|
for (const test of tests)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user