-
-
Notifications
You must be signed in to change notification settings - Fork 197
/
Copy pathpost-install.ts
76 lines (65 loc) · 2.48 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
import { doesCurrentNpmCommandMatch } from "../common/helpers";
import { ICommand, ICommandParameter } from "../common/definitions/commands";
import {
IFileSystem,
IHelpService,
ISettingsService,
IAnalyticsService,
IHostInfo,
} from "../common/declarations";
import { injector } from "../common/yok";
export class PostInstallCliCommand implements ICommand {
constructor(
private $fs: IFileSystem,
private $commandsService: ICommandsService,
private $helpService: IHelpService,
private $settingsService: ISettingsService,
private $analyticsService: IAnalyticsService,
private $logger: ILogger,
private $hostInfo: IHostInfo
) {}
public disableAnalytics = true;
public allowedParameters: ICommandParameter[] = [];
public async execute(args: string[]): Promise<void> {
const isRunningWithSudoUser = !!process.env.SUDO_USER;
if (!this.$hostInfo.isWindows) {
// when running under 'sudo' we create a working dir with wrong owner (root) and
// it is no longer accessible for the user initiating the installation
// patch the owner here
if (isRunningWithSudoUser) {
// TODO: Check if this is the correct place, probably we should set this at the end of the command.
await this.$fs.setCurrentUserAsOwner(
this.$settingsService.getProfileDir(),
process.env.SUDO_USER
);
}
}
const canExecutePostInstallTask =
!isRunningWithSudoUser || doesCurrentNpmCommandMatch([/^--unsafe-perm$/]);
if (canExecutePostInstallTask) {
await this.$helpService.generateHtmlPages();
// Explicitly ask for confirmation of usage-reporting:
await this.$analyticsService.checkConsent();
await this.$commandsService.tryExecuteCommand("autocomplete", []);
}
}
public async postCommandAction(args: string[]): Promise<void> {
this.$logger.info("");
this.$logger.info(
"You have successfully installed the NativeScript CLI!".green.bold
);
this.$logger.info("");
this.$logger.info("Your next step is to create a new project:");
this.$logger.info("ns create".green.bold);
this.$logger.info("");
this.$logger.printMarkdown(
"New to NativeScript?".bold +
" Try the tutorials in NativeScript Playground: `https://play.nativescript.org`"
);
this.$logger.info("");
this.$logger.printMarkdown(
"If you have any questions, check Stack Overflow: `https://stackoverflow.com/questions/tagged/nativescript` and our public Discord channel: `https://nativescript.org/discord`"
);
}
}
injector.registerCommand("post-install-cli", PostInstallCliCommand);