Skip to content

Commit 75db4a9

Browse files
Fatmeligaz
authored andcommitted
Some improvements and fixes
* Rename bin/nativescript.cmd to tns.cmd * Fix tns --version command * Add appid option * Use com.telerik.<App name> 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
1 parent 295b405 commit 75db4a9

File tree

9 files changed

+89
-58
lines changed

9 files changed

+89
-58
lines changed
File renamed without changes.

lib/commands/list-platforms.ts

Lines changed: 7 additions & 3 deletions
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

Lines changed: 0 additions & 1 deletion
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

Lines changed: 9 additions & 2 deletions
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 18 additions & 5 deletions
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

Lines changed: 16 additions & 14 deletions
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

Lines changed: 37 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,29 @@
11
--[]--
22

33
Usage:
4-
$ tns <command> [command parameters] [--command <options>]
4+
$ tns <command> [command parameters] [--command <options>]
55

66
General commands:
7-
help <command> Shows additional information about the commands in this list.
7+
help <command> Shows additional information about the commands in this list.
88

9-
create Creates a new NativeScript project with given project name and packageName.
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 platforms, or all platforms, so that the project
13-
is ready to build in each SDK.
14-
build Builds the project for the selected target platform and produces an application package.
15-
run This is shorthand for prepare and build.
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.
1615

1716
General options:
18-
--help Prints help about the selected command.
19-
--path <Directory> Specifies the directory that contains the project. If not set, the project is searched for
20-
in the current directory and all directories above it.
21-
--version Prints the client version.
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.
2221
--[/]--
2322

2423
--[help]--
2524

2625
Usage:
27-
$ tns help [<Command>]
26+
$ tns help [<Command>]
2827
Lists the available commands or shows information about the selected command.
2928
<Command> is any of the available commands as listed by $ tns help.
3029

@@ -33,34 +32,39 @@ Lists the available commands or shows information about the selected command.
3332
--[create]--
3433

3534
Usage:
36-
$ tns create <App name> [--path <Directory>] [--appid <App ID>]
35+
$ tns create <App name> [--path <Directory>] [--appid <App ID>] [--copy-from <Directory>]
3736

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

4241
Options:
43-
--appid - Sets the application identifier for your project. The application identifier must consist of at least three
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
4445
alphanumeric strings, separated by a dot (.). Each string must start with a letter.
4546
The application identifier corresponds to the Bundle ID for iOS apps and to the package identifier for Android apps.
4647
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+
4751
--[/]--
4852

4953
--[platform]--
5054

5155
Usage:
52-
$ tns platform <Command>
56+
$ tns platform <Command>
5357

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

5862
--[/]--
5963

6064
--[platform|list]--
6165

6266
Usage:
63-
$ tns platform
67+
$ tns platform
6468

6569
Lists all available and currently installed platforms.
6670

@@ -69,11 +73,11 @@ Lists all available and currently installed platforms.
6973
--[platform|add]--
7074

7175
Usage:
72-
$ tns platform add <platform>
76+
$ tns platform add <platform>
7377

7478
Platform-specific usage:
75-
$ tns platform add android
76-
$ tns platform add ios
79+
$ tns platform add android
80+
$ tns platform add ios
7781

7882
Creates a new platform specific project. In this version of Telerik NativeScript you can create only ios and android projects.
7983
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
8286
--[prepare]--
8387

8488
Usage:
85-
$ tns prepare [<platform>]
89+
$ tns prepare [<platform>]
8690

8791
Platform-specific usage:
88-
$ tns prepare android
89-
$ tns prepare ios
92+
$ tns prepare android
93+
$ tns prepare ios
9094

91-
Copies files for specified platforms, or all platforms, so that the project is ready to build in each SDK.
95+
Copies files for specified platform, so that the project is ready to build in each SDK.
9296

9397
--[/]--
9498

9599
--[build]--
96100

97101
Usage:
98-
$ tns build [<platform>]
102+
$ tns build [<platform>]
103+
104+
Platform-specific usage:
105+
$ tns build android
106+
$ tns build ios
99107

100-
Builds the project for specified platforms, or all platforms. This generates platform-specific code within the project's
101-
platforms subdirectory. You can optionally limit the scope of each build to specific platforms:
102-
$ tns build android
103-
$ tns build ios
108+
Builds the project for specified platform. This generates platform-specific code within the project's platforms subdirectory.
104109

105110
--[/]--
106111

0 commit comments

Comments
 (0)