Skip to content

Commit

Permalink
feat: Unconditionally display browser url
Browse files Browse the repository at this point in the history
  • Loading branch information
medikoo committed Dec 17, 2019
1 parent e88d0c5 commit c900900
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 34 deletions.
22 changes: 10 additions & 12 deletions lib/plugins/interactiveCli/setupAws.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,25 +54,23 @@ const steps = {
ensureAwsAccount: () =>
confirm('Do you have an AWS account?', { name: 'hasAwsAccount' }).then(hasAccount => {
if (!hasAccount) {
return openBrowser('https://portal.aws.amazon.com/billing/signup').then(() =>
inquirer.prompt({
message: 'Press Enter to continue after creating an AWS account',
name: 'createAwsAccountPrompt',
})
);
openBrowser('https://portal.aws.amazon.com/billing/signup');
return inquirer.prompt({
message: 'Press Enter to continue after creating an AWS account',
name: 'createAwsAccountPrompt',
});
}
return null;
}),
ensureAwsCredentials: serverless => {
const region = serverless.getProvider('aws').getRegion();
return openBrowser(
openBrowser(
`https://console.aws.amazon.com/iam/home?region=${region}#/users$new?step=final&accessKey&userNames=serverless&permissionType=policies&policies=arn:aws:iam::aws:policy%2FAdministratorAccess`
).then(() =>
inquirer.prompt({
message: 'Press Enter to continue after creating an AWS user with access keys',
name: 'generateAwsCredsPrompt',
})
);
return inquirer.prompt({
message: 'Press Enter to continue after creating an AWS user with access keys',
name: 'generateAwsCredsPrompt',
});
},
inputAwsCredentials: () => {
return awsAccessKeyIdInput().then(accessKeyId =>
Expand Down
34 changes: 12 additions & 22 deletions lib/utils/openBrowser.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,20 @@
const opn = require('./open');
const chalk = require('chalk');
const isDockerContainer = require('is-docker');
const BbPromise = require('bluebird');

function displayManualOpenMessage(url, err) {
// https://github.com/sindresorhus/log-symbols
console.log('---------------------------');
const errMsg = err ? `\nError: ${err.message}` : '';
const msg = `Unable to open browser automatically${errMsg}`;
console.log(`🙈 ${chalk.red(msg)}`);
console.log(chalk.green('Please open your browser & open the URL below to login:'));
console.log(chalk.yellow(url));
console.log('---------------------------');
return false;
}

module.exports = function openBrowser(url) {
return BbPromise.try(() => {
let browser = process.env.BROWSER;
if (browser === 'none' || isDockerContainer()) return displayManualOpenMessage(url);
if (process.platform === 'darwin' && browser === 'open') {
browser = undefined;
process.stdout.write(
`\nIf your browser does not open automatically, please open the URL: ${url}\n\n`
);
let browser = process.env.BROWSER;
if (browser === 'none' || isDockerContainer()) return;
if (process.platform === 'darwin' && browser === 'open') browser = undefined;
const options = { wait: false, app: browser };
opn(url, options).catch(err => {
if (process.env.SLS_DEBUG) {
process.stdout.write(
`Serverless: ${chalk.red(`Opening of browser window errored with ${err.stack}`)}\n`
);
}
const options = { wait: false, app: browser };
return opn(url, options).catch(err => displayManualOpenMessage(url, err));
});
};

/* eslint-enable no-console */

0 comments on commit c900900

Please sign in to comment.