-
-
Notifications
You must be signed in to change notification settings - Fork 197
Added email registration for NativeScript mailing lists as post install step #2134
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import {PostInstallCommand} from "../common/commands/post-install"; | ||
import * as emailValidator from "email-validator"; | ||
import * as queryString from "querystring"; | ||
import * as helpers from "../common/helpers"; | ||
|
||
export class PostInstallCliCommand extends PostInstallCommand { | ||
|
||
private logger: ILogger; | ||
|
||
constructor($fs: IFileSystem, | ||
private $httpClient: Server.IHttpClient, | ||
private $prompter: IPrompter, | ||
private $userSettingsService: IUserSettingsService, | ||
$staticConfig: Config.IStaticConfig, | ||
$commandsService: ICommandsService, | ||
$htmlHelpService: IHtmlHelpService, | ||
$options: ICommonOptions, | ||
$doctorService: IDoctorService, | ||
$analyticsService: IAnalyticsService, | ||
$logger: ILogger) { | ||
super($fs, $staticConfig, $commandsService, $htmlHelpService, $options, $doctorService, $analyticsService, $logger); | ||
this.logger = $logger; | ||
} | ||
|
||
public execute(args: string[]): IFuture<void> { | ||
return (() => { | ||
super.execute(args).wait(); | ||
|
||
if (this.shouldAskForEmail()) { | ||
this.logger.out("Leave your e-mail address here to subscribe for NativeScript newsletter and product updates, tips and tricks:"); | ||
let email = this.getEmail("(press Enter for blank)").wait(); | ||
this.$userSettingsService.saveSetting("EMAIL_REGISTERED", true).wait(); | ||
this.sendEmail(email); | ||
} | ||
|
||
}).future<void>()(); | ||
} | ||
|
||
private shouldAskForEmail(): boolean { | ||
return helpers.isInteractive() && process.env.CLI_NOPROMPT !== "1" && !this.$userSettingsService.getSettingValue("EMAIL_REGISTERED").wait(); | ||
} | ||
|
||
private getEmail(prompt: string, options?: IPrompterOptions): IFuture<string> { | ||
return (() => { | ||
let schema: IPromptSchema = { | ||
message: prompt, | ||
type: "input", | ||
name: "inputEmail", | ||
validate: (value: any) => { | ||
if (value === "" || emailValidator.validate(value)) { | ||
return true; | ||
} | ||
return "Please provide a valid e-mail or simply leave it blank."; | ||
}, | ||
default: options && options.defaultAction | ||
}; | ||
|
||
let result = this.$prompter.get([schema]).wait(); | ||
return result.inputString; | ||
}).future<string>()(); | ||
} | ||
|
||
private sendEmail(email: string): void { | ||
if (email) { | ||
let postData = queryString.stringify({ | ||
'elqFormName': process.argv[2], | ||
'elqSiteID': '1325', | ||
'emailAddress': email, | ||
'elqCookieWrite': '0' | ||
}); | ||
|
||
let options = { | ||
url: 'https://s1325.t.eloqua.com/e/f2', | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/x-www-form-urlencoded', | ||
'Content-Length': postData.length | ||
}, | ||
body: postData | ||
}; | ||
|
||
this.$httpClient.httpRequest(options).wait(); | ||
} | ||
} | ||
} | ||
$injector.registerCommand("post-install-cli", PostInstallCliCommand); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// Type definitions for email-validator 1.0.3 | ||
// Project: https://github.com/Sembiance/email-validator | ||
// Definitions by: Paul Lessing <https://github.com/paullessing> | ||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped | ||
|
||
declare module "email-validator" { | ||
export function validate(email: String): boolean; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
"use strict"; | ||
var child_process = require("child_process"); | ||
child_process.spawn(process.argv[0], ["bin/nativescript.js", "dev-post-install"], {stdio: "inherit"}); | ||
child_process.spawn(process.argv[0], ["bin/nativescript.js", "post-install-cli"], {stdio: "inherit"}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if the sendEmail command fails, next time when user installs NS CLI, he'll be prompted again (as the EMAIL_REGISTERED value will never be written in the settings file), is this expected? In case not, you can swap the two lines above.