Skip to content

Commit 37c2576

Browse files
Merge pull request #3501 from NativeScript/vladimirov/post-command-actions
feat(commands): Introduce postCommandAction
2 parents bab2994 + f9ef10b commit 37c2576

File tree

7 files changed

+49
-8
lines changed

7 files changed

+49
-8
lines changed

lib/commands/create-project.ts

Lines changed: 12 additions & 1 deletion
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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Lines changed: 10 additions & 3 deletions
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

Lines changed: 2 additions & 1 deletion
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

Lines changed: 2 additions & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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)