Skip to content

Commit 8176817

Browse files
feat(commands) Introduce postCommandAction
Introduce postCommandAction that is executed when the command succeeds. Use the action to print additional information to user how to continue after command is finished. Show some information on successful postinstall - instruct the users how to use local builds, cloud builds and playground.
1 parent bab2994 commit 8176817

File tree

7 files changed

+50
-9
lines changed

7 files changed

+50
-9
lines changed

lib/commands/create-project.ts

+12-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
import * as constants from "../constants";
2+
import * as path from "path";
23

34
export class CreateProjectCommand implements ICommand {
45
public enableHooks = false;
56
public allowedParameters: ICommandParameter[] = [this.$stringParameterBuilder.createMandatoryParameter("Project name cannot be empty.")];
67

8+
private createdProjecData: ICreateProjectData;
9+
710
constructor(private $projectService: IProjectService,
11+
private $logger: ILogger,
812
private $errors: IErrors,
913
private $options: IOptions,
1014
private $stringParameterBuilder: IStringParameterBuilder) { }
@@ -23,7 +27,7 @@ export class CreateProjectCommand implements ICommand {
2327
selectedTemplate = this.$options.template;
2428
}
2529

26-
await this.$projectService.createProject({
30+
this.createdProjecData = await this.$projectService.createProject({
2731
projectName: args[0],
2832
template: selectedTemplate,
2933
appId: this.$options.appid,
@@ -32,6 +36,13 @@ export class CreateProjectCommand implements ICommand {
3236
ignoreScripts: this.$options.ignoreScripts
3337
});
3438
}
39+
40+
public async postCommandAction(args: string[]): Promise<void> {
41+
const { projectDir } = this.createdProjecData;
42+
const relativePath = path.relative(process.cwd(), projectDir);
43+
this.$logger.printMarkdown(`Now you can navigate to your project with \`$ cd ${relativePath}\``);
44+
this.$logger.printMarkdown(`After that you can run it on device/emulator by executing \`$ tns run <platform>\``);
45+
}
3546
}
3647

3748
$injector.registerCommand("create", CreateProjectCommand);

lib/commands/post-install.ts

+22-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export class PostInstallCliCommand extends PostInstallCommand {
99
$settingsService: ISettingsService,
1010
$doctorService: IDoctorService,
1111
$analyticsService: IAnalyticsService,
12-
$logger: ILogger) {
12+
protected $logger: ILogger) {
1313
super($fs, $staticConfig, $commandsService, $helpService, $settingsService, $analyticsService, $logger);
1414
}
1515

@@ -18,6 +18,27 @@ export class PostInstallCliCommand extends PostInstallCommand {
1818

1919
await this.$subscriptionService.subscribeForNewsletter();
2020
}
21+
22+
public async postCommandAction(args: string[]): Promise<void> {
23+
this.$logger.info("You have successfully installed NativeScript CLI.");
24+
this.$logger.info("In order to create a new project, you can use:".green);
25+
this.$logger.printMarkdown("`tns create <app name>`");
26+
this.$logger.info("To build your project locally you can use:".green);
27+
this.$logger.printMarkdown("`tns build <platform>`");
28+
this.$logger.printMarkdown("NOTE: Local builds require additional setup of your environment. You can find more information here: `https://docs.nativescript.org/start/quick-setup`");
29+
30+
// Add a new line just to ensure separation between local builds and cloud builds info.
31+
this.$logger.info("");
32+
this.$logger.info("To build your project in the cloud you can use:".green);
33+
this.$logger.printMarkdown("`tns cloud build <platform>`");
34+
this.$logger.printMarkdown("NOTE: Cloud builds require Telerik account. You can find more information here: `https://docs.nativescript.org/sidekick/intro/requirements`");
35+
36+
this.$logger.info("");
37+
this.$logger.printMarkdown("In case you want to experiment quickly with NativeScript, you can try the Playground: `https://play.nativescript.org`");
38+
39+
this.$logger.info("");
40+
this.$logger.printMarkdown("In case you have any questions, you can check our forum: `https://forum.nativescript.org` and our public Slack channel: `https://nativescriptcommunity.slack.com/`");
41+
}
2142
}
2243

2344
$injector.registerCommand("post-install-cli", PostInstallCliCommand);

lib/definitions/project.d.ts

+10-3
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,21 @@ interface IProjectSettings {
3737
ignoreScripts?: boolean;
3838
}
3939

40+
interface IProjectName {
41+
projectName: string;
42+
}
43+
44+
interface ICreateProjectData extends IProjectDir, IProjectName {
45+
46+
}
47+
4048
interface IProjectService {
4149
/**
4250
* Creates new NativeScript application.
4351
* @param {any} projectSettings Options describing new project - its name, appId, path and template from which to be created.
4452
* @returns {Promise<void>}
4553
*/
46-
createProject(projectSettings: IProjectSettings): Promise<void>;
54+
createProject(projectSettings: IProjectSettings): Promise<ICreateProjectData>;
4755

4856
/**
4957
* Checks if the specified project is valid NativeScript project.
@@ -58,8 +66,7 @@ interface INsConfig {
5866
appResourcesPath?: string;
5967
}
6068

61-
interface IProjectData extends IProjectDir {
62-
projectName: string;
69+
interface IProjectData extends ICreateProjectData {
6370
platformsDir: string;
6471
projectFilePath: string;
6572
projectId?: string;

lib/services/project-service.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export class ProjectService implements IProjectService {
1818
private $npmInstallationManager: INpmInstallationManager) { }
1919

2020
@exported("projectService")
21-
public async createProject(projectOptions: IProjectSettings): Promise<void> {
21+
public async createProject(projectOptions: IProjectSettings): Promise<ICreateProjectData> {
2222
let projectName = projectOptions.projectName;
2323
let selectedTemplate = projectOptions.template;
2424

@@ -74,6 +74,7 @@ export class ProjectService implements IProjectService {
7474
}
7575

7676
this.$logger.printMarkdown("Project `%s` was successfully created.", projectName);
77+
return { projectName, projectDir };
7778
}
7879

7980
@exported("projectService")

test/project-commands.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@ let isProjectCreated: boolean;
1010
const dummyArgs = ["dummyArgsString"];
1111

1212
class ProjectServiceMock implements IProjectService {
13-
async createProject(projectOptions: IProjectSettings): Promise<void> {
13+
async createProject(projectOptions: IProjectSettings): Promise<ICreateProjectData> {
1414
selectedTemplateName = projectOptions.template;
1515
isProjectCreated = true;
16+
return null;
1617
}
1718

1819
isValidNativeScriptProject(pathToProject?: string): boolean {

test/project-service.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class ProjectIntegrationTest {
5959
this.createTestInjector();
6060
}
6161

62-
public async createProject(projectOptions: IProjectSettings): Promise<void> {
62+
public async createProject(projectOptions: IProjectSettings): Promise<ICreateProjectData> {
6363
const projectService: IProjectService = this.testInjector.resolve("projectService");
6464
if (!projectOptions.template) {
6565
projectOptions.template = constants.RESERVED_TEMPLATE_NAMES["default"];

0 commit comments

Comments
 (0)