Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/bootstrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,5 +117,6 @@ $injector.require("messages", "./common/messages/messages");
$injector.require("xmlValidator", "./xml-validator");

$injector.requireCommand("devices", "./commands/devices");
$injector.requireCommand("post-install-cli", "./commands/post-install");

$injector.require("iOSLogFilter", "./services/ios-log-filter");
86 changes: 86 additions & 0 deletions lib/commands/post-install.ts
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();
Copy link
Contributor

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.

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);
8 changes: 8 additions & 0 deletions lib/definitions/email-validator.d.ts
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;
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"cli-table": "https://github.com/telerik/cli-table/tarball/v0.3.1.2",
"clui": "0.3.1",
"colors": "1.1.2",
"email-validator": "1.0.4",
"esprima": "2.7.0",
"ffi": "https://github.com/icenium/node-ffi/tarball/v2.0.0.3",
"fibers": "https://github.com/icenium/node-fibers/tarball/v1.0.13.1",
Expand Down
2 changes: 1 addition & 1 deletion postinstall.js
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"});