Skip to content

feat(commands): Introduce postCommandAction #3501

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 28, 2018
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
13 changes: 12 additions & 1 deletion lib/commands/create-project.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import * as constants from "../constants";
import * as path from "path";

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

private createdProjecData: ICreateProjectData;

constructor(private $projectService: IProjectService,
private $logger: ILogger,
private $errors: IErrors,
private $options: IOptions,
private $stringParameterBuilder: IStringParameterBuilder) { }
Expand All @@ -23,7 +27,7 @@ export class CreateProjectCommand implements ICommand {
selectedTemplate = this.$options.template;
}

await this.$projectService.createProject({
this.createdProjecData = await this.$projectService.createProject({
projectName: args[0],
template: selectedTemplate,
appId: this.$options.appid,
Expand All @@ -32,6 +36,13 @@ export class CreateProjectCommand implements ICommand {
ignoreScripts: this.$options.ignoreScripts
});
}

public async postCommandAction(args: string[]): Promise<void> {
const { projectDir } = this.createdProjecData;
const relativePath = path.relative(process.cwd(), projectDir);
this.$logger.printMarkdown(`Now you can navigate to your project with \`$ cd ${relativePath}\``);
this.$logger.printMarkdown(`After that you can run it on device/emulator by executing \`$ tns run <platform>\``);
}
}

$injector.registerCommand("create", CreateProjectCommand);
21 changes: 21 additions & 0 deletions lib/commands/post-install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,27 @@ export class PostInstallCliCommand extends PostInstallCommand {

await this.$subscriptionService.subscribeForNewsletter();
}

public async postCommandAction(args: string[]): Promise<void> {
this.$logger.info("You have successfully installed NativeScript CLI.");
this.$logger.info("In order to create a new project, you can use:".green);
this.$logger.printMarkdown("`tns create <app name>`");
this.$logger.info("To build your project locally you can use:".green);
this.$logger.printMarkdown("`tns build <platform>`");
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`");

// Add a new line just to ensure separation between local builds and cloud builds info.
this.$logger.info("");
this.$logger.info("To build your project in the cloud you can use:".green);
this.$logger.printMarkdown("`tns cloud build <platform>`");
this.$logger.printMarkdown("NOTE: Cloud builds require Telerik account. You can find more information here: `https://docs.nativescript.org/sidekick/intro/requirements`");

this.$logger.info("");
this.$logger.printMarkdown("In case you want to experiment quickly with NativeScript, you can try the Playground: `https://play.nativescript.org`");

this.$logger.info("");
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/`");
}
}

$injector.registerCommand("post-install-cli", PostInstallCliCommand);
13 changes: 10 additions & 3 deletions lib/definitions/project.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,21 @@ interface IProjectSettings {
ignoreScripts?: boolean;
}

interface IProjectName {
projectName: string;
}

interface ICreateProjectData extends IProjectDir, IProjectName {

}

interface IProjectService {
/**
* Creates new NativeScript application.
* @param {any} projectSettings Options describing new project - its name, appId, path and template from which to be created.
* @returns {Promise<void>}
*/
createProject(projectSettings: IProjectSettings): Promise<void>;
createProject(projectSettings: IProjectSettings): Promise<ICreateProjectData>;

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

interface IProjectData extends IProjectDir {
projectName: string;
interface IProjectData extends ICreateProjectData {
platformsDir: string;
projectFilePath: string;
projectId?: string;
Expand Down
3 changes: 2 additions & 1 deletion lib/services/project-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export class ProjectService implements IProjectService {
private $npmInstallationManager: INpmInstallationManager) { }

@exported("projectService")
public async createProject(projectOptions: IProjectSettings): Promise<void> {
public async createProject(projectOptions: IProjectSettings): Promise<ICreateProjectData> {
let projectName = projectOptions.projectName;
let selectedTemplate = projectOptions.template;

Expand Down Expand Up @@ -74,6 +74,7 @@ export class ProjectService implements IProjectService {
}

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

@exported("projectService")
Expand Down
3 changes: 2 additions & 1 deletion test/project-commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ let isProjectCreated: boolean;
const dummyArgs = ["dummyArgsString"];

class ProjectServiceMock implements IProjectService {
async createProject(projectOptions: IProjectSettings): Promise<void> {
async createProject(projectOptions: IProjectSettings): Promise<ICreateProjectData> {
selectedTemplateName = projectOptions.template;
isProjectCreated = true;
return null;
}

isValidNativeScriptProject(pathToProject?: string): boolean {
Expand Down
2 changes: 1 addition & 1 deletion test/project-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class ProjectIntegrationTest {
this.createTestInjector();
}

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