From 295b40517a46e39b87e5c59aec39265feef94484 Mon Sep 17 00:00:00 2001 From: fatme Date: Sun, 20 Jul 2014 10:06:45 +0300 Subject: [PATCH 1/2] Basic help.txt --- lib/common | 2 +- resources/help.txt | 106 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 107 insertions(+), 1 deletion(-) create mode 100644 resources/help.txt diff --git a/lib/common b/lib/common index 789a82292b..248ff2f6b2 160000 --- a/lib/common +++ b/lib/common @@ -1 +1 @@ -Subproject commit 789a82292b66159981e7e02791f4ba89a32c74a1 +Subproject commit 248ff2f6b2d871cd5b4bb964127bf42040d0d235 diff --git a/resources/help.txt b/resources/help.txt new file mode 100644 index 0000000000..c9d0d633dd --- /dev/null +++ b/resources/help.txt @@ -0,0 +1,106 @@ +--[]-- + +Usage: + $ tns [command parameters] [--command ] + +General commands: + help Shows additional information about the commands in this list. + + create Creates a new NativeScript project with given project name and packageName. + platform add Creates a new platform specific project. + platform list Lists all available and all installed platforms. + prepare Copies files for specified platforms, or all platforms, so that the project + is ready to build in each 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 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 [] +Lists the available commands or shows information about the selected command. + is any of the available commands as listed by $ tns help. + +--[/]-- + +--[create]-- + +Usage: + $ tns create [--path ] [--appid ] + +Creates a new NativeScript project. + is the name of project. It should conform to platform package type limitations. For example classes in Java +don't begin with numbers. + +Options: + --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.. +--[/]-- + +--[platform]-- + +Usage: + $ tns platform + + 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-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-specific usage: + $ tns prepare android + $ tns prepare ios + +Copies files for specified platforms, or all platforms, so that the project is ready to build in each SDK. + +--[/]-- + +--[build]-- + +Usage: + $ tns build [] + +Builds the project for specified platforms, or all platforms. This generates platform-specific code within the project's +platforms subdirectory. You can optionally limit the scope of each build to specific platforms: + $ tns build android + $ tns build ios + +--[/]-- + From 75db4a972a906b35315c1be53d09b241efa51e7a Mon Sep 17 00:00:00 2001 From: fatme Date: Sun, 20 Jul 2014 13:09:30 +0300 Subject: [PATCH 2/2] Some improvements and fixes * Rename bin/nativescript.cmd to tns.cmd * Fix tns --version command * Add appid option * Use com.telerik. as default application identifier * Add help for --copy-from option * Remove setLoggerConfiguration * Add config.client * Fix the check for "source app/ is not a direct ancestor of a target app/" * We don't need ensureProject, we can throw the error when projectData is initializing. ;) * Fix message outputed from platform command * isPlatformInstalled validation for prepare and build commands * Using typed config --- bin/{nativescript.cmd => tns.cmd} | 0 lib/commands/list-platforms.ts | 10 +++-- lib/common | 2 +- lib/definitions/project.d.ts | 1 - lib/nativescript-cli.ts | 11 ++++- lib/options.ts | 1 + lib/services/platform-service.ts | 23 ++++++++--- lib/services/project-service.ts | 30 +++++++------- resources/help.txt | 69 +++++++++++++++++-------------- 9 files changed, 89 insertions(+), 58 deletions(-) rename bin/{nativescript.cmd => tns.cmd} (100%) diff --git a/bin/nativescript.cmd b/bin/tns.cmd similarity index 100% rename from bin/nativescript.cmd rename to bin/tns.cmd diff --git a/lib/commands/list-platforms.ts b/lib/commands/list-platforms.ts index 855d384f13..fcead433ad 100644 --- a/lib/commands/list-platforms.ts +++ b/lib/commands/list-platforms.ts @@ -1,5 +1,6 @@ /// import helpers = require("./../common/helpers"); +import util = require("util") export class ListPlatformsCommand implements ICommand { constructor(private $platformService: IPlatformService, @@ -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()(); } } $injector.registerCommand("platform|*list", ListPlatformsCommand); - - diff --git a/lib/common b/lib/common index 248ff2f6b2..aaba8d5acb 160000 --- a/lib/common +++ b/lib/common @@ -1 +1 @@ -Subproject commit 248ff2f6b2d871cd5b4bb964127bf42040d0d235 +Subproject commit aaba8d5acb0657b3f0a9d5cf4772393d66733180 diff --git a/lib/definitions/project.d.ts b/lib/definitions/project.d.ts index ed7d44936b..bebfed8352 100644 --- a/lib/definitions/project.d.ts +++ b/lib/definitions/project.d.ts @@ -1,6 +1,5 @@ interface IProjectService { createProject(projectName: string, projectId: string): IFuture; - ensureProject(): void; } interface IProjectData { diff --git a/lib/nativescript-cli.ts b/lib/nativescript-cli.ts index 2c58c2c502..bebe99e180 100644 --- a/lib/nativescript-cli.ts +++ b/lib/nativescript-cli.ts @@ -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(); \ No newline at end of file +dispatcher.runMainFiber(); diff --git a/lib/options.ts b/lib/options.ts index 20f58e75e7..77dfaff124 100644 --- a/lib/options.ts +++ b/lib/options.ts @@ -8,6 +8,7 @@ var knownOpts:any = { "log" : String, "verbose" : Boolean, "path" : String, + "appid" : String, "copy-from": String, "link-to": String, "release": String, diff --git a/lib/services/platform-service.ts b/lib/services/platform-service.ts index 065b99f6b1..d6beb3ec75 100644 --- a/lib/services/platform-service.ts +++ b/lib/services/platform-service.ts @@ -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(); @@ -137,7 +135,8 @@ export class PlatformService implements IPlatformService { public preparePlatform(platform: string): IFuture { return (() => { platform = platform.toLowerCase(); - this.validatePlatform(platform); + + this.validatePlatformInstalled(platform); var platformData = this.$platformsData.getPlatformData(platform); var platformProjectService = platformData.platformProjectService; @@ -148,8 +147,8 @@ export class PlatformService implements IPlatformService { public buildPlatform(platform: string): IFuture { 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(); @@ -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); + } + } + private isValidPlatform(platform: string) { return this.$platformsData.getPlatformData(platform); } @@ -186,5 +193,11 @@ export class PlatformService implements IPlatformService { return false; } + + private isPlatformInstalled(platform: string): IFuture { + return (() => { + return this.$fs.exists(path.join(this.$projectData.platformsDir, platform)).wait(); + }).future()(); + } } $injector.register("platformService", PlatformService); diff --git a/lib/services/project-service.ts b/lib/services/project-service.ts index 8d709b1a2b..9c4302ff6d 100644 --- a/lib/services/project-service.ts +++ b/lib/services/project-service.ts @@ -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 { return(() => { var projectDir = this.$projectHelper.projectDir; - + // If no project found, projectDir should be null if(projectDir) { this.projectDir = projectDir; this.projectName = path.basename(projectDir); @@ -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()(); } } @@ -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 { 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(); @@ -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; @@ -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()(); } @@ -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); diff --git a/resources/help.txt b/resources/help.txt index c9d0d633dd..6db2492d37 100644 --- a/resources/help.txt +++ b/resources/help.txt @@ -1,30 +1,29 @@ --[]-- Usage: - $ tns [command parameters] [--command ] + $ tns [command parameters] [--command ] General commands: - help Shows additional information about the commands in this list. + help Shows additional information about the commands in this list. - create Creates a new NativeScript project with given project name and packageName. - platform add Creates a new platform specific project. - platform list Lists all available and all installed platforms. - prepare Copies files for specified platforms, or all platforms, so that the project - is ready to build in each SDK. - build Builds the project for the selected target platform and produces an application package. - run This is shorthand for prepare and build. + 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 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 Prints help about the selected command. + --path 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 [] + $ tns help [] Lists the available commands or shows information about the selected command. is any of the available commands as listed by $ tns help. @@ -33,34 +32,39 @@ Lists the available commands or shows information about the selected command. --[create]-- Usage: - $ tns create [--path ] [--appid ] + $ tns create [--path ] [--appid ] [--copy-from ] Creates a new NativeScript project. is the name of project. It should conform to platform package type limitations. For example classes in Java don't begin with numbers. Options: - --appid - Sets the application identifier for your project. The application identifier must consist of at least three + --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.. + --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 + $ tns platform 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 + list - Lists all available and installed platforms. + add - Creates a new platform specific project --[/]-- --[platform|list]-- Usage: - $ tns platform + $ tns platform Lists all available and currently installed platforms. @@ -69,11 +73,11 @@ Lists all available and currently installed platforms. --[platform|add]-- Usage: - $ tns platform add + $ tns platform add Platform-specific usage: - $ tns platform add android - $ tns platform add ios + $ 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. @@ -82,25 +86,26 @@ You can create Android projects on windows and Mac machine. You can create ios p --[prepare]-- Usage: - $ tns prepare [] + $ tns prepare [] Platform-specific usage: - $ tns prepare android - $ tns prepare ios + $ tns prepare android + $ tns prepare ios -Copies files for specified platforms, or all platforms, so that the project is ready to build in each SDK. +Copies files for specified platform, so that the project is ready to build in each SDK. --[/]-- --[build]-- Usage: - $ tns build [] + $ tns build [] + +Platform-specific usage: + $ tns build android + $ tns build ios -Builds the project for specified platforms, or all platforms. This generates platform-specific code within the project's -platforms subdirectory. You can optionally limit the scope of each build to specific platforms: - $ tns build android - $ tns build ios +Builds the project for specified platform. This generates platform-specific code within the project's platforms subdirectory. --[/]--