Skip to content

Help command #8

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

Closed
wants to merge 2 commits into from
Closed
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
File renamed without changes.
3 changes: 2 additions & 1 deletion lib/commands/list-platforms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ export class ListPlatformsCommand implements ICommand {
this.$logger.out("Available platforms: %s", helpers.formatListOfNames(availablePlatforms));

var installedPlatforms = this.$platformService.getInstalledPlatforms().wait();
this.$logger.out("Installed platforms %s", helpers.formatListOfNames(installedPlatforms));
var message = installedPlatforms.length > 0 ? helpers.formatListOfNames(installedPlatforms) : "No installed platforms found";
this.$logger.out("Installed platforms: %s", message);
}).future<void>()();
}
}
Expand Down
1 change: 0 additions & 1 deletion lib/definitions/project.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
interface IProjectService {
createProject(projectName: string, projectId: string): IFuture<void>;
ensureProject(): void;
}

interface IProjectData {
Expand Down
8 changes: 7 additions & 1 deletion lib/nativescript-cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,13 @@ require("./options");
import errors = require("./common/errors");
errors.installUncaughtExceptionListener();

$injector.register("config", {"CI_LOGGER": false, PROJECT_FILE_NAME: ".tnsproject", "DEBUG": process.env.NATIVESCRIPT_DEBUG});
$injector.register("config", {
CI_LOGGER: false,
PROJECT_FILE_NAME: ".tnsproject",
DEBUG: process.env.NATIVESCRIPT_DEBUG,
version: require("../package.json").version,
client: "tns"
});

var dispatcher = $injector.resolve("dispatcher");
dispatcher.runMainFiber();
1 change: 1 addition & 0 deletions lib/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ var knownOpts:any = {
"log" : String,
"verbose" : Boolean,
"path" : String,
"appid" : String,
"copy-from": String,
"link-to": String,
"release": String,
Expand Down
22 changes: 17 additions & 5 deletions lib/services/platform-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ export class PlatformService implements IPlatformService {
this.$errors.fail("No platform specified. Please specify a platform to add");
}

this.$projectService.ensureProject();

var platformsDir = this.$projectData.platformsDir;
this.$fs.ensureDirectoryExists(platformsDir).wait();

Expand All @@ -65,7 +63,7 @@ export class PlatformService implements IPlatformService {
return(() => {
platform = platform.split("@")[0];

this.validatePlatform(platform);
this.validatePlatform(platform, true);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid boolean method arguments - it's impossible to tell what this switch does without going to the method definition.
http://ariya.ofilabs.com/2011/08/hall-of-api-shame-boolean-trap.html

Maybe a second overload will work best here validatePlatform(platform) and validatePlatformInstalled(platform)


var platformPath = path.join(this.$projectData.platformsDir, platform);

Expand Down Expand Up @@ -110,7 +108,9 @@ export class PlatformService implements IPlatformService {
public preparePlatform(platform: string): IFuture<void> {
return (() => {
platform = platform.toLowerCase();

this.validatePlatform(platform);

var normalizedPlatformName = this.normalizePlatformName(platform);

this.$platformProjectService.prepareProject(normalizedPlatformName, this.$platformsData.platformsNames).wait();
Expand All @@ -119,21 +119,27 @@ export class PlatformService implements IPlatformService {

public buildPlatform(platform: string): IFuture<void> {
return (() => {
platform = platform.toLocaleLowerCase();
platform = platform.toLowerCase();
this.validatePlatform(platform);

this.$platformProjectService.buildProject(platform).wait();
}).future<void>()();
}

private validatePlatform(platform: string): void {
private validatePlatform(platform: string, skipIsPlatformInstalledCheck?: boolean): void {
if (!this.isValidPlatform(platform)) {
this.$errors.fail("Invalid platform %s. Valid platforms are %s.", platform, helpers.formatListOfNames(this.$platformsData.platformsNames));
}

if (!this.isPlatformSupportedForOS(platform)) {
this.$errors.fail("Applications for platform %s can not be built on this OS - %s", platform, process.platform);
}

if(!skipIsPlatformInstalledCheck) {
if (!this.isPlatformInstalled(platform).wait()) {
this.$errors.fail("The platform %s is not added to this project. Please use 'tns platform add <platform>'", platform);
}
}
}

private isValidPlatform(platform: string) {
Expand All @@ -150,6 +156,12 @@ export class PlatformService implements IPlatformService {
return false;
}

private isPlatformInstalled(platform: string): IFuture<boolean> {
return (() => {
return this.$fs.exists(path.join(this.$projectData.platformsDir, platform)).wait();
}).future<boolean>()();
}

private normalizePlatformName(platform: string): string {
switch(platform) {
case "android":
Expand Down
29 changes: 15 additions & 14 deletions lib/services/project-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class ProjectData implements IProjectData {
public projectName: string;

constructor(private $fs: IFileSystem,
private $errors: IErrors,
private $projectHelper: IProjectHelper,
private $config) {
this.initializeProjectData().wait();
Expand All @@ -23,7 +24,7 @@ class ProjectData implements IProjectData {
private initializeProjectData(): IFuture<void> {
return(() => {
var projectDir = this.$projectHelper.projectDir;

// If no project found, projectDir should be null
if(projectDir) {
this.projectDir = projectDir;
this.projectName = path.basename(projectDir);
Expand All @@ -34,31 +35,31 @@ class ProjectData implements IProjectData {
var fileContent = this.$fs.readJson(this.projectFilePath).wait();
this.projectId = fileContent.id;
}
} else {
this.$errors.fail("No project found at or above '%s' and neither was a --path specified.", process.cwd());
}

}).future<void>()();
}
}
$injector.register("projectData", ProjectData);

export class ProjectService implements IProjectService {
private static DEFAULT_PROJECT_ID = "com.telerik.tns.HelloWorld";
private static DEFAULT_PROJECT_NAME = "HelloNativescript";
public static APP_FOLDER_NAME = "app";

constructor(private $logger: ILogger,
private $errors: IErrors,
private $fs: IFileSystem,
private $projectTemplatesService: IProjectTemplatesService,
private $projectData: IProjectData,
private $projectHelper: IProjectHelper,
private $config) { }

public createProject(projectName: string, projectId: string): IFuture<void> {
return(() => {
var projectDir = path.resolve(options.path || ".");

projectId = projectId || ProjectService.DEFAULT_PROJECT_ID;
projectName = projectName || ProjectService.DEFAULT_PROJECT_NAME;
projectId = options.appid || this.$projectHelper.generateDefaultAppId(projectName);

projectDir = path.join(projectDir, projectName);
this.$fs.createDirectory(projectDir).wait();
Expand All @@ -82,9 +83,13 @@ export class ProjectService implements IProjectService {

// Make sure that the source app/ is not a direct ancestor of a target app/
var relativePathFromSourceToTarget = path.relative(customAppPath, appDirectory);
var doesRelativePathGoUpAtLeastOneDir = relativePathFromSourceToTarget.split(path.sep)[0] == "..";
if(!doesRelativePathGoUpAtLeastOneDir) {
this.$errors.fail("Project dir %s must not be created at/inside the template used to create the project %s.", projectDir, customAppPath);
// path.relative returns second argument if the paths are located on different disks
// so in this case we don't need to make the check for direct ancestor
if(relativePathFromSourceToTarget !== appDirectory) {
var doesRelativePathGoUpAtLeastOneDir = relativePathFromSourceToTarget.split(path.sep)[0] === "..";
if (!doesRelativePathGoUpAtLeastOneDir) {
this.$errors.fail("Project dir %s must not be created at/inside the template used to create the project %s.", projectDir, customAppPath);
}
}
this.$logger.trace("Copying custom app into %s", appDirectory);
appPath = customAppPath;
Expand All @@ -97,6 +102,8 @@ export class ProjectService implements IProjectService {
}

this.createProjectCore(projectDir, appPath, projectId, false).wait();

this.$logger.out("Project %s was successfully created", projectName);
}).future<void>()();
}

Expand Down Expand Up @@ -141,12 +148,6 @@ export class ProjectService implements IProjectService {

return customAppPath;
}

public ensureProject() {
if (this.$projectData.projectDir === "" || !this.$fs.exists(this.$projectData.projectFilePath).wait()) {
this.$errors.fail("No project found at or above '%s' and neither was a --path specified.", process.cwd());
}
}
}
$injector.register("projectService", ProjectService);

Expand Down
111 changes: 111 additions & 0 deletions resources/help.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
--[]--

Usage:
$ tns <command> [command parameters] [--command <options>]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should be no tabs in the help file, because every terminal renders tabs differently.


General commands:
help <command> Shows additional information about the commands in this list.

create Creates a new NativeScript project with given project name and application identifier.
platform add Creates a new platform specific project.
platform list Lists all available and all installed platforms.
prepare Copies files for specified platform, so that the project is ready to build in platform specific SDK.
build Builds the project for the selected target platform and produces an application package.
run This is shorthand for prepare and build.

General options:
--help Prints help about the selected command.
--path <Directory> Specifies the directory that contains the project. If not set, the project is searched for
in the current directory and all directories above it.
--version Prints the client version.
--[/]--

--[help]--

Usage:
$ tns help [<Command>]
Lists the available commands or shows information about the selected command.
<Command> is any of the available commands as listed by $ tns help.

--[/]--

--[create]--

Usage:
$ tns create <App name> [--path <Directory>] [--appid <App ID>] [--copy-from <Directory>]

Creates a new NativeScript project.
<App name> is the name of project. It should conform to platform package type limitations. For example classes in Java
don't begin with numbers.

Options:
--path - Specifies the directory where you want to create the project, if different from the current directory.
The directory must be empty.
--appid - Sets the application identifier for your project. The application identifier must consist of at least three
alphanumeric strings, separated by a dot (.). Each string must start with a letter.
The application identifier corresponds to the Bundle ID for iOS apps and to the package identifier for Android apps.
If not specified, the application identifier is set to com.telerik.<App name>.
--copy-from - Specifies the directory where your javascript files are located. If not set,
the default hello world template is used.

--[/]--

--[platform]--

Usage:
$ tns platform <Command>

<Command> is a related command that extends the platform command. You can run the following related commands:
list - Lists all available and installed platforms.
add - Creates a new platform specific project

--[/]--

--[platform|list]--

Usage:
$ tns platform

Lists all available and currently installed platforms.

--[/]--

--[platform|add]--

Usage:
$ tns platform add <platform>

Platform-specific usage:
$ tns platform add android
$ tns platform add ios

Creates a new platform specific project. In this version of Telerik NativeScript you can create only ios and android projects.
You can create Android projects on windows and Mac machine. You can create ios projects only on Mac machine.
--[/]--

--[prepare]--

Usage:
$ tns prepare [<platform>]

Platform-specific usage:
$ tns prepare android
$ tns prepare ios

Copies files for specified platform, so that the project is ready to build in each SDK.

--[/]--

--[build]--

Usage:
$ tns build [<platform>]

Platform-specific usage:
$ tns build android
$ tns build ios

Builds the project for specified platform. This generates platform-specific code within the project's platforms subdirectory.

--[/]--