Skip to content

Commit b961989

Browse files
author
Stefan Dobrev
committed
Merge pull request #11 from NativeScript/fatme/help
Help command
2 parents dcf1745 + 75db4a9 commit b961989

File tree

9 files changed

+163
-26
lines changed

9 files changed

+163
-26
lines changed
File renamed without changes.

lib/commands/list-platforms.ts

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
///<reference path="../.d.ts"/>
22
import helpers = require("./../common/helpers");
3+
import util = require("util")
34

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

14+
var message = "No installed platforms found.";
1315
var installedPlatforms = this.$platformService.getInstalledPlatforms().wait();
14-
this.$logger.out("Installed platforms %s", helpers.formatListOfNames(installedPlatforms));
16+
if (installedPlatforms.length > 0){
17+
message = util.format("Installed platforms: %s", helpers.formatListOfNames(installedPlatforms));
18+
}
19+
20+
this.$logger.out(message);
1521
}).future<void>()();
1622
}
1723
}
1824
$injector.registerCommand("platform|*list", ListPlatformsCommand);
19-
20-

lib/definitions/project.d.ts

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
interface IProjectService {
22
createProject(projectName: string, projectId: string): IFuture<void>;
3-
ensureProject(): void;
43
}
54

65
interface IProjectData {

lib/nativescript-cli.ts

+9-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,14 @@ require("./options");
1010
import errors = require("./common/errors");
1111
errors.installUncaughtExceptionListener();
1212

13-
$injector.register("config", {"CI_LOGGER": false, PROJECT_FILE_NAME: ".tnsproject", "DEBUG": process.env.NATIVESCRIPT_DEBUG});
13+
$injector.register("config", {
14+
CI_LOGGER1: false,
15+
PROJECT_FILE_NAME: ".tnsproject",
16+
DEBUG: process.env.NATIVESCRIPT_DEBUG,
17+
version: require("../package.json").version,
18+
helpTextPath: path.join(__dirname, "../resources/help.txt"),
19+
client: "tns"
20+
});
1421

1522
var dispatcher = $injector.resolve("dispatcher");
16-
dispatcher.runMainFiber();
23+
dispatcher.runMainFiber();

lib/options.ts

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ var knownOpts:any = {
88
"log" : String,
99
"verbose" : Boolean,
1010
"path" : String,
11+
"appid" : String,
1112
"copy-from": String,
1213
"link-to": String,
1314
"release": String,

lib/services/platform-service.ts

+18-5
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,6 @@ export class PlatformService implements IPlatformService {
5656
this.$errors.fail("No platform specified. Please specify a platform to add");
5757
}
5858

59-
this.$projectService.ensureProject();
60-
6159
var platformsDir = this.$projectData.platformsDir;
6260
this.$fs.ensureDirectoryExists(platformsDir).wait();
6361

@@ -137,7 +135,8 @@ export class PlatformService implements IPlatformService {
137135
public preparePlatform(platform: string): IFuture<void> {
138136
return (() => {
139137
platform = platform.toLowerCase();
140-
this.validatePlatform(platform);
138+
139+
this.validatePlatformInstalled(platform);
141140

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

149148
public buildPlatform(platform: string): IFuture<void> {
150149
return (() => {
151-
platform = platform.toLocaleLowerCase();
152-
this.validatePlatform(platform);
150+
platform = platform.toLowerCase();
151+
this.validatePlatformInstalled(platform);
153152

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

175+
private validatePlatformInstalled(platform: string): void {
176+
this.validatePlatform(platform);
177+
178+
if (!this.isPlatformInstalled(platform).wait()) {
179+
this.$errors.fail("The platform %s is not added to this project. Please use 'tns platform add <platform>'", platform);
180+
}
181+
}
182+
176183
private isValidPlatform(platform: string) {
177184
return this.$platformsData.getPlatformData(platform);
178185
}
@@ -186,5 +193,11 @@ export class PlatformService implements IPlatformService {
186193

187194
return false;
188195
}
196+
197+
private isPlatformInstalled(platform: string): IFuture<boolean> {
198+
return (() => {
199+
return this.$fs.exists(path.join(this.$projectData.platformsDir, platform)).wait();
200+
}).future<boolean>()();
201+
}
189202
}
190203
$injector.register("platformService", PlatformService);

lib/services/project-service.ts

+16-14
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,16 @@ class ProjectData implements IProjectData {
1616
public projectName: string;
1717

1818
constructor(private $fs: IFileSystem,
19+
private $errors: IErrors,
1920
private $projectHelper: IProjectHelper,
20-
private $config) {
21+
private $config: IConfig) {
2122
this.initializeProjectData().wait();
2223
}
2324

2425
private initializeProjectData(): IFuture<void> {
2526
return(() => {
2627
var projectDir = this.$projectHelper.projectDir;
27-
28+
// If no project found, projectDir should be null
2829
if(projectDir) {
2930
this.projectDir = projectDir;
3031
this.projectName = path.basename(projectDir);
@@ -35,8 +36,9 @@ class ProjectData implements IProjectData {
3536
var fileContent = this.$fs.readJson(this.projectFilePath).wait();
3637
this.projectId = fileContent.id;
3738
}
39+
} else {
40+
this.$errors.fail("No project found at or above '%s' and neither was a --path specified.", process.cwd());
3841
}
39-
4042
}).future<void>()();
4143
}
4244
}
@@ -47,15 +49,15 @@ export class ProjectService implements IProjectService {
4749
private $errors: IErrors,
4850
private $fs: IFileSystem,
4951
private $projectTemplatesService: IProjectTemplatesService,
50-
private $projectData: IProjectData,
52+
private $projectHelper: IProjectHelper,
5153
private $config) { }
5254

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

57-
projectId = projectId || constants.DEFAULT_PROJECT_ID;
5859
projectName = projectName || constants.DEFAULT_PROJECT_NAME;
60+
projectId = options.appid || this.$projectHelper.generateDefaultAppId(projectName);
5961

6062
projectDir = path.join(projectDir, projectName);
6163
this.$fs.createDirectory(projectDir).wait();
@@ -79,9 +81,13 @@ export class ProjectService implements IProjectService {
7981

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

96102
this.createProjectCore(projectDir, appPath, projectId, false).wait();
103+
104+
this.$logger.out("Project %s was successfully created", projectName);
97105
}).future<void>()();
98106
}
99107

@@ -138,12 +146,6 @@ export class ProjectService implements IProjectService {
138146

139147
return customAppPath;
140148
}
141-
142-
public ensureProject() {
143-
if (this.$projectData.projectDir === "" || !this.$fs.exists(this.$projectData.projectFilePath).wait()) {
144-
this.$errors.fail("No project found at or above '%s' and neither was a --path specified.", process.cwd());
145-
}
146-
}
147149
}
148150
$injector.register("projectService", ProjectService);
149151

resources/help.txt

+111
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
--[]--
2+
3+
Usage:
4+
$ tns <command> [command parameters] [--command <options>]
5+
6+
General commands:
7+
help <command> Shows additional information about the commands in this list.
8+
9+
create Creates a new NativeScript project with given project name and application identifier.
10+
platform add Creates a new platform specific project.
11+
platform list Lists all available and all installed platforms.
12+
prepare Copies files for specified platform, so that the project is ready to build in platform specific SDK.
13+
build Builds the project for the selected target platform and produces an application package.
14+
run This is shorthand for prepare and build.
15+
16+
General options:
17+
--help Prints help about the selected command.
18+
--path <Directory> Specifies the directory that contains the project. If not set, the project is searched for
19+
in the current directory and all directories above it.
20+
--version Prints the client version.
21+
--[/]--
22+
23+
--[help]--
24+
25+
Usage:
26+
$ tns help [<Command>]
27+
Lists the available commands or shows information about the selected command.
28+
<Command> is any of the available commands as listed by $ tns help.
29+
30+
--[/]--
31+
32+
--[create]--
33+
34+
Usage:
35+
$ tns create <App name> [--path <Directory>] [--appid <App ID>] [--copy-from <Directory>]
36+
37+
Creates a new NativeScript project.
38+
<App name> is the name of project. It should conform to platform package type limitations. For example classes in Java
39+
don't begin with numbers.
40+
41+
Options:
42+
--path - Specifies the directory where you want to create the project, if different from the current directory.
43+
The directory must be empty.
44+
--appid - Sets the application identifier for your project. The application identifier must consist of at least three
45+
alphanumeric strings, separated by a dot (.). Each string must start with a letter.
46+
The application identifier corresponds to the Bundle ID for iOS apps and to the package identifier for Android apps.
47+
If not specified, the application identifier is set to com.telerik.<App name>.
48+
--copy-from - Specifies the directory where your javascript files are located. If not set,
49+
the default hello world template is used.
50+
51+
--[/]--
52+
53+
--[platform]--
54+
55+
Usage:
56+
$ tns platform <Command>
57+
58+
<Command> is a related command that extends the platform command. You can run the following related commands:
59+
list - Lists all available and installed platforms.
60+
add - Creates a new platform specific project
61+
62+
--[/]--
63+
64+
--[platform|list]--
65+
66+
Usage:
67+
$ tns platform
68+
69+
Lists all available and currently installed platforms.
70+
71+
--[/]--
72+
73+
--[platform|add]--
74+
75+
Usage:
76+
$ tns platform add <platform>
77+
78+
Platform-specific usage:
79+
$ tns platform add android
80+
$ tns platform add ios
81+
82+
Creates a new platform specific project. In this version of Telerik NativeScript you can create only ios and android projects.
83+
You can create Android projects on windows and Mac machine. You can create ios projects only on Mac machine.
84+
--[/]--
85+
86+
--[prepare]--
87+
88+
Usage:
89+
$ tns prepare [<platform>]
90+
91+
Platform-specific usage:
92+
$ tns prepare android
93+
$ tns prepare ios
94+
95+
Copies files for specified platform, so that the project is ready to build in each SDK.
96+
97+
--[/]--
98+
99+
--[build]--
100+
101+
Usage:
102+
$ tns build [<platform>]
103+
104+
Platform-specific usage:
105+
$ tns build android
106+
$ tns build ios
107+
108+
Builds the project for specified platform. This generates platform-specific code within the project's platforms subdirectory.
109+
110+
--[/]--
111+

0 commit comments

Comments
 (0)