Skip to content

Commit

Permalink
feat: Prompt fallback if connection to Sentry fails
Browse files Browse the repository at this point in the history
* feat: Prompt for missing paramters as fallback

* feat: Rename projectType to integration

Add quiet mode

* fix: Code Review changes

* ref: Rename steps to integrations
  • Loading branch information
HazAT authored Dec 1, 2017
1 parent ffe2d43 commit 5760e9e
Show file tree
Hide file tree
Showing 27 changed files with 344 additions and 3,355 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## v0.6.0

- Add quiet mode --quiet
- Fallback to user prompts when not able to connect to Sentry
- Renamed parameter type/protype to integration

## v0.5.3

- Passing answers fixed in file helper
Expand Down
33 changes: 18 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
</a>
<br/>
<h1>Sentry Wizard</h1>
<h4>Helping you to setup your project with Sentry</h4>
<h4>Helping you to set up your project with Sentry</h4>
</p>

[![Travis](https://img.shields.io/travis/getsentry/sentry-wizard.svg?maxAge=2592000)](https://travis-ci.org/getsentry/sentry-wizard)
Expand Down Expand Up @@ -33,19 +33,22 @@ Call `sentry-wizard` in your project and follow the instructions.
# Options
```
Options:
--help Show help [boolean]
--version Show version number [boolean]
--debug Enable verbose logging
env: SENTRY_WIZARD_DEBUG [boolean]
--uninstall Revert project setup process
env: SENTRY_WIZARD_UNINSTALL [boolean]
--skip-connect Skips the connection to the server
env: SENTRY_WIZARD_SKIP_CONNECT [boolean]
-t, --type Choose a project type
env: SENTRY_WIZARD_TYPE
--help Show help [boolean]
--version Show version number [boolean]
--debug Enable verbose logging
env: SENTRY_WIZARD_DEBUG [boolean]
--uninstall Revert project set up process
env: SENTRY_WIZARD_UNINSTALL [boolean]
--skip-connect Skips the connection to the server
env: SENTRY_WIZARD_SKIP_CONNECT [boolean]
--quiet Do not fallback to prompting user asking questions
env: SENTRY_WIZARD_QUIET [boolean]
-i, --integration Choose the integration to set up
env: SENTRY_WIZARD_INTEGRATION
[choices: "reactNative", "javascript", "node", "cordova"]
-p, --platform Choose platform(s)
env: SENTRY_WIZARD_PLATFORM[array] [choices: "ios", "android"]
-u, --url The url to your Sentry installation
env: SENTRY_WIZARD_URL [default: "https://sentry.io/"]
-p, --platform Choose platform(s)
env: SENTRY_WIZARD_PLATFORM
[array] [choices: "ios", "android"]
-u, --url The url to your Sentry installation
env: SENTRY_WIZARD_URL [default: "https://sentry.io/"]
```
15 changes: 10 additions & 5 deletions bin.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env node
import { IArgs, Platform, ProjectType } from './lib/Constants';
import { IArgs, Integration, Platform } from './lib/Constants';
import { run } from './lib/Setup';
export * from './lib/Setup';
const readEnv = require('read-env').default;
Expand All @@ -17,10 +17,15 @@ const argv = require('yargs')
describe: 'Skips the connection to the server\nenv: SENTRY_WIZARD_SKIP_CONNECT',
type: 'boolean',
})
.option('t', {
alias: 'type',
choices: Object.keys(ProjectType),
describe: 'Choose a project type\nenv: SENTRY_WIZARD_TYPE',
.option('quiet', {
describe:
'Do not fallback to prompting user asking questions\nenv: SENTRY_WIZARD_QUIET',
type: 'boolean',
})
.option('i', {
alias: 'integration',
choices: Object.keys(Integration),
describe: 'Choose the integration to setup\nenv: SENTRY_WIZARD_INTEGRATION',
})
.option('p', {
alias: 'platform',
Expand Down
2 changes: 1 addition & 1 deletion index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export { IArgs, ProjectType } from './lib/Constants';
export { IArgs, Integration } from './lib/Constants';
export * from './lib/Setup';
45 changes: 17 additions & 28 deletions lib/Constants.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Key value should be the same here
export enum ProjectType {
export enum Integration {
reactNative = 'reactNative',
javascript = 'javascript',
node = 'node',
Expand All @@ -12,17 +12,11 @@ export enum Platform {
}

export function getPlatformChoices() {
const result = [];
for (const platform in Platform) {
if (Platform.hasOwnProperty(platform)) {
result.push({
checked: true,
name: getPlatformDescription(platform),
value: platform,
});
}
}
return result;
return Object.keys(Platform).map((platform: string) => ({
checked: true,
name: getPlatformDescription(platform),
value: platform,
}));
}

export function getPlatformDescription(type: string) {
Expand All @@ -34,39 +28,34 @@ export function getPlatformDescription(type: string) {
}
}

export function getProjectDescription(type: string) {
export function getIntegrationDescription(type: string) {
switch (type) {
case ProjectType.reactNative:
case Integration.reactNative:
return 'React Native';
case ProjectType.cordova:
case Integration.cordova:
return 'Cordova';
case ProjectType.node:
case Integration.node:
return 'Generic node project';
default:
return 'Generic javascript project';
}
}

export function getProjectTypeChoices() {
const result = [];
for (const type in ProjectType) {
if (ProjectType.hasOwnProperty(type)) {
result.push({
name: getProjectDescription(type),
value: type,
});
}
}
return result;
export function getIntegrationChoices() {
return Object.keys(Integration).map((type: string) => ({
name: getIntegrationDescription(type),
value: type,
}));
}

export interface IArgs {
url: string;
debug: boolean;
uninstall: boolean;
type: ProjectType;
integration: Integration;
platform: Platform;
skipConnect: boolean;
quiet: boolean;
}

export enum WizardProperties {}
8 changes: 4 additions & 4 deletions lib/Helper/SentryCli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import { IArgs } from '../Constants';
export class SentryCli {
constructor(protected argv: IArgs) {}

public convertSelectedProjectToProperties(answers: Answers) {
public convertAnswersToProperties(answers: Answers) {
const props: any = {};
props['defaults/url'] = this.argv.url;
props['defaults/org'] = _.get(answers, 'selectedProject.organization.slug', null);
props['defaults/project'] = _.get(answers, 'selectedProject.slug', null);
props['auth/token'] = _.get(answers, 'wizard.apiKeys.token', null);
props['defaults/org'] = _.get(answers, 'config.organization.slug', null);
props['defaults/project'] = _.get(answers, 'config.project.slug', null);
props['auth/token'] = _.get(answers, 'config.auth.token', null);
try {
const cliPath = require.resolve('sentry-cli-binary/bin/sentry-cli');
props['cli/executable'] = path.relative(process.cwd(), cliPath);
Expand Down
19 changes: 11 additions & 8 deletions lib/Helper/Wizard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import { Answers, ui } from 'inquirer';
import * as _ from 'lodash';
import { IArgs } from '../Constants';
import { BaseStep, IStep } from '../Steps/BaseStep';
import { BaseProject } from '../Steps/Projects/BaseProject';
import { BaseIntegration } from '../Steps/Integrations/BaseIntegration';
import { BottomBar } from './BottomBar';
import { debug, nl, red } from './Logging';
import { debug, dim, nl, red } from './Logging';

function sanitizeArgs(argv: IArgs) {
let baseUrl = argv.url;
Expand All @@ -13,9 +13,8 @@ function sanitizeArgs(argv: IArgs) {
argv.url = baseUrl;
}

export function getCurrentProject(answers: Answers) {
const project: BaseProject = _.get(answers, 'project');
return project;
export function getCurrentIntegration(answers: Answers) {
return _.get(answers, 'integration') as BaseIntegration;
}

export async function startWizard<M extends IStep>(
Expand All @@ -26,6 +25,9 @@ export async function startWizard<M extends IStep>(
if (argv.debug) {
debug(argv);
}
if (argv.quiet) {
dim("Quiet mode On, DAMA, don't ask me anything");
}
let allAnswers = null;
try {
allAnswers = await steps.map(step => new step(argv)).reduce(async (answer, step) => {
Expand All @@ -36,10 +38,11 @@ export async function startWizard<M extends IStep>(
} catch (e) {
BottomBar.hide();
nl();
red('Sentry Setup Wizard failed with:');
red('Protip: Add --debug to see whats going on');
red('Sentry Wizard failed with:');
red(argv.debug ? e : e.message);
nl();
red(e);
red('Protip: Add --debug to see whats going on');
red('OR use --help to see your options');
}
return allAnswers;
}
4 changes: 2 additions & 2 deletions lib/Setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { startWizard } from './Helper/Wizard';
import * as Step from './Steps';

export async function run(argv: IArgs) {
let steps = [Step.Initial, Step.Welcome, Step.ChooseProject, Step.ShouldConfigure];
let steps = [Step.Initial, Step.Welcome, Step.ChooseIntegration, Step.ShouldConfigure];
if (argv.uninstall === false) {
steps = _.concat(
steps,
Expand All @@ -14,6 +14,6 @@ export async function run(argv: IArgs) {
Step.SentryProjectSelector
);
}
steps = _.concat(steps, Step.ConfigureProject, Step.Result);
steps = _.concat(steps, Step.PromptForParameters, Step.ConfigureProject, Step.Result);
return startWizard(argv, ...steps);
}
70 changes: 70 additions & 0 deletions lib/Steps/ChooseIntegration.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import { Answers, prompt, Question } from 'inquirer';
import * as _ from 'lodash';
import { getIntegrationChoices, Integration } from '../Constants';
import { dim, green } from '../Helper/Logging';
import { BaseStep } from './BaseStep';
import { Cordova } from './Integrations/Cordova';
import { GenericJavascript } from './Integrations/GenericJavascript';
import { GenericNode } from './Integrations/GenericNode';
import { ReactNative } from './Integrations/ReactNative';

let projectPackage: any = {};

try {
// If we run directly in setup-wizard
projectPackage = require('../../package.json');
} catch {
projectPackage = require(`${process.cwd()}/package.json`);
}

export class ChooseIntegration extends BaseStep {
public async emit(answers: Answers) {
// If we receive project type as an arg we skip asking
let integrationPrompt = null;
if (this.argv.integration) {
integrationPrompt = { integration: this.argv.integration };
} else {
if (this.argv.quiet) {
throw new Error('You need to choose a integration');
}
integrationPrompt = this.tryDetectingIntegration();
integrationPrompt = await prompt([
{
choices: getIntegrationChoices(),
default: integrationPrompt,
message: 'What integration do you want to set up?',
name: 'integration',
type: 'list',
},
]);
}

let integration = null;
switch (integrationPrompt.integration) {
case Integration.reactNative:
integration = new ReactNative(this.argv);
break;
case Integration.cordova:
integration = new Cordova(this.argv);
break;
case Integration.node:
integration = new GenericNode(this.argv);
break;
default:
integration = new GenericJavascript(this.argv);
break;
}

return { integration };
}

public tryDetectingIntegration(): Integration | undefined {
if (_.has(projectPackage, 'dependencies.react-native')) {
return Integration.reactNative;
}
if (_.has(projectPackage, 'dependencies.cordova')) {
return Integration.cordova;
}
return;
}
}
67 changes: 0 additions & 67 deletions lib/Steps/ChooseProject.ts

This file was deleted.

Loading

0 comments on commit 5760e9e

Please sign in to comment.