Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

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.
10 changes: 7 additions & 3 deletions lib/commands/list-platforms.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
///<reference path="../.d.ts"/>
import helpers = require("./../common/helpers");
import util = require("util")

export class ListPlatformsCommand implements ICommand {
constructor(private $platformService: IPlatformService,
Expand All @@ -10,11 +11,14 @@ export class ListPlatformsCommand implements ICommand {
var availablePlatforms = this.$platformService.getAvailablePlatforms().wait();
this.$logger.out("Available platforms: %s", helpers.formatListOfNames(availablePlatforms));

var message = "No installed platforms found.";
var installedPlatforms = this.$platformService.getInstalledPlatforms().wait();
this.$logger.out("Installed platforms %s", helpers.formatListOfNames(installedPlatforms));
if (installedPlatforms.length > 0){
message = util.format("Installed platforms: %s", helpers.formatListOfNames(installedPlatforms));
}

this.$logger.out(message);
}).future<void>()();
}
}
$injector.registerCommand("platform|*list", ListPlatformsCommand);


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
11 changes: 9 additions & 2 deletions lib/nativescript-cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,14 @@ 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_LOGGER1: false,
PROJECT_FILE_NAME: ".tnsproject",
DEBUG: process.env.NATIVESCRIPT_DEBUG,
version: require("../package.json").version,
helpTextPath: path.join(__dirname, "../resources/help.txt"),
client: "tns"
});

var dispatcher = $injector.resolve("dispatcher");
dispatcher.runMainFiber();
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
23 changes: 18 additions & 5 deletions lib/services/platform-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,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 Down Expand Up @@ -137,7 +135,8 @@ export class PlatformService implements IPlatformService {
public preparePlatform(platform: string): IFuture<void> {
return (() => {
platform = platform.toLowerCase();
this.validatePlatform(platform);

this.validatePlatformInstalled(platform);

var platformData = this.$platformsData.getPlatformData(platform);
var platformProjectService = platformData.platformProjectService;
Expand All @@ -148,8 +147,8 @@ export class PlatformService implements IPlatformService {

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

var platformData = this.$platformsData.getPlatformData(platform);
platformData.platformProjectService.buildProject(platformData.projectRoot).wait();
Expand All @@ -173,6 +172,14 @@ export class PlatformService implements IPlatformService {
}
}

private validatePlatformInstalled(platform: string): void {
this.validatePlatform(platform);

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) {
return this.$platformsData.getPlatformData(platform);
}
Expand All @@ -186,5 +193,11 @@ 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>()();
}
}
$injector.register("platformService", PlatformService);
30 changes: 16 additions & 14 deletions lib/services/project-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,16 @@ class ProjectData implements IProjectData {
public projectName: string;

constructor(private $fs: IFileSystem,
private $errors: IErrors,
private $projectHelper: IProjectHelper,
private $config) {
private $config: IConfig) {
this.initializeProjectData().wait();
}

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 @@ -35,8 +36,9 @@ 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>()();
}
}
Expand All @@ -47,15 +49,15 @@ export class ProjectService implements IProjectService {
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 || constants.DEFAULT_PROJECT_ID;
projectName = projectName || constants.DEFAULT_PROJECT_NAME;
projectId = options.appid || this.$projectHelper.generateDefaultAppId(projectName);

projectDir = path.join(projectDir, projectName);
this.$fs.createDirectory(projectDir).wait();
Expand All @@ -79,9 +81,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 @@ -94,6 +100,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 @@ -138,12 +146,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);

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>]

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
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't this be _$tns platform list_?

Copy link

Choose a reason for hiding this comment

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

list is the default command when nothing is specified.


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.

--[/]--