diff --git a/.circleci/config.yml b/.circleci/config.yml index 848d496e7..5d22aa7df 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -41,9 +41,9 @@ integration_job: &integration_job - attach_workspace: at: ~/coralproject/talk - <<: *create_indexes - - run: - name: Setup the database with defaults - command: ./bin/cli setup --defaults + # - run: + # name: Setup the database with defaults + # command: ./bin/cli setup --defaults - run: name: Run the integration tests command: bash .circleci/e2e.sh diff --git a/bin/cli-setup b/bin/cli-setup index 11da478c2..d2db3b30d 100755 --- a/bin/cli-setup +++ b/bin/cli-setup @@ -45,11 +45,10 @@ const performSetup = async () => { } catch (err) { // If the error is `not init`, then we're good, otherwise, it's something // else. - if (err instanceof ErrSettingsNotInit) { + if (!err instanceof ErrSettingsNotInit) { + throw err; return; } - - throw err; } if (program.defaults) { @@ -138,7 +137,7 @@ const performSetup = async () => { console.log("\nWe'll ask you some questions about your first admin user.\n"); - let user = await inquirer.prompt([ + let { username, email } = await inquirer.prompt([ { type: 'input', name: 'username', @@ -161,39 +160,46 @@ const performSetup = async () => { return 'Email is required'; }, }, - { - name: 'password', - message: 'Password', - type: 'password', - filter: password => { - return UsersService.isValidPassword(password).catch(err => { - throw err.message; - }); - }, - }, - { - name: 'confirmPassword', - message: 'Confirm Password', - type: 'password', - filter: (confirmPassword, { password }) => { - if (password !== confirmPassword) { - return Promise.reject(new Error('Passwords do not match')); - } - - return UsersService.isValidPassword(confirmPassword).catch(err => { - throw err.message; - }); - }, - }, ]); + let password = ''; + while (!password) { + answers = await inquirer.prompt([ + { + name: 'password', + message: 'Password', + type: 'password', + filter: password => { + try { + UsersService.isValidPassword(password); + } catch (err) { + throw err.message; + } + + return password; + }, + }, + { + name: 'confirmPassword', + message: 'Confirm Password', + type: 'password', + }, + ]); + + if (answers.password !== answers.confirmPassword) { + console.error('Passwords do not match'); + } else { + password = answers.password; + } + } + const ctx = Context.forSystem(); let { user: newUser } = await SetupService.setup(ctx, { settings: settings.toObject(), user: { - email: user.email, - username: user.username, - password: user.password, + email, + username, + password, }, });