From 253df63ea79f73ef99962cf72b9a509866d198e7 Mon Sep 17 00:00:00 2001 From: Arnaud lewis Date: Thu, 17 Nov 2016 15:15:27 +0100 Subject: [PATCH] fix prompt domain name error --- lib/repository.js | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/lib/repository.js b/lib/repository.js index f6e50bc4..20f7b57c 100644 --- a/lib/repository.js +++ b/lib/repository.js @@ -33,11 +33,13 @@ async function create(templates, base, domain, args, theme) { async function validateTheme(themeURL) { async function retry(url, message) { - Helpers.UI.display(message); + if(message) Helpers.UI.display(message); const answers = await promptThemeURL(themeURL); return validateTheme(answers.url); } + if(!themeURL) return retry(); + try { Helpers.UI.display('We are checking the theme integrity'); const themeData = isValidThemeURL(themeURL); @@ -204,6 +206,9 @@ function readCustomTypes(folder) { return null; } +//new false +//domain doesn't exist + async function isDomainAvailableOrRetry(newRepository, base, domain, args, noconfirm) { async function exec(d) { const isExist = await exists(newRepository, base, d, args, noconfirm); @@ -215,7 +220,7 @@ async function isDomainAvailableOrRetry(newRepository, base, domain, args, nocon } } else { - if(noconfirm || newRepository) { + if(newRepository) { return d; } else { return retry('Either the repository doesn\'t exists or you don\'t have access to it.'); @@ -233,8 +238,8 @@ async function isDomainAvailableOrRetry(newRepository, base, domain, args, nocon async function exists(newRepository, base, domain, args, noconfirm) { try { - const exists = await queryExists(base, domain); - return exists === 'false'; + const isAvailable = await queryAvailable(base, domain); + return isAvailable === 'false'; } catch(err) { Helpers.UI.display(`Unable to check if ${domain} exists.`); } @@ -245,11 +250,14 @@ function promptName (domain) { type: 'input', name: 'domain', message: 'Name your prismic repository: ', - default: domain + default: domain, + validate(value) { + return new RegExp('^[\\-\\w]+$').test(value) ? true : 'Your repository name can only contains alphanumeric characters, underscores or dashes'; + } }]); } -function queryExists(base, domain) { +function queryAvailable(base, domain) { const url = `${base}/app/dashboard/repositories/${domain}/exists`; return Communication.get(url); }