Skip to content

Commit

Permalink
fix prompt domain name error
Browse files Browse the repository at this point in the history
  • Loading branch information
arnaudlewis committed Nov 17, 2016
1 parent ac2bcd4 commit 253df63
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions lib/repository.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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.');
Expand All @@ -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.`);
}
Expand All @@ -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);
}
Expand Down

0 comments on commit 253df63

Please sign in to comment.