-
-
Notifications
You must be signed in to change notification settings - Fork 197
/
Copy pathpost-install.ts
86 lines (74 loc) · 2.63 KB
/
post-install.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
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);