Skip to content

Commit d20e6d6

Browse files
committed
Merge pull request #79 from NativeScript/fatme/fix-messages
Fix the misleading messages for platform command
2 parents 07ff9a0 + 7d6719f commit d20e6d6

File tree

6 files changed

+33
-12
lines changed

6 files changed

+33
-12
lines changed

lib/commands/list-platforms.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,20 @@ export class ListPlatformsCommand implements ICommand {
88

99
execute(args: string[]): IFuture<void> {
1010
return (() => {
11-
var availablePlatforms = this.$platformService.getAvailablePlatforms().wait();
12-
if(availablePlatforms.length > 0) {
13-
this.$logger.out("Available platforms: %s", helpers.formatListOfNames(availablePlatforms));
14-
} else {
15-
this.$logger.out("No available platforms found.");
16-
}
17-
18-
var message = "No installed platforms found.";
1911
var installedPlatforms = this.$platformService.getInstalledPlatforms().wait();
20-
if (installedPlatforms.length > 0){
21-
message = util.format("Installed platforms: %s", helpers.formatListOfNames(installedPlatforms));
22-
}
2312

24-
this.$logger.out(message);
13+
if(installedPlatforms.length > 0) {
14+
var preparedPlatforms = this.$platformService.getPreparedPlatforms().wait();
15+
if(preparedPlatforms.length > 0) {
16+
this.$logger.out("The project is prepared for: ", helpers.formatListOfNames(preparedPlatforms, "and"));
17+
} else {
18+
this.$logger.out("The project is not prepared for any platform");
19+
}
20+
this.$logger.out("Installed platforms: ", helpers.formatListOfNames(installedPlatforms, "and"));
21+
} else {
22+
this.$logger.out("Available platforms for this OS: ", helpers.formatListOfNames(this.$platformService.getAvailablePlatforms().wait(), "and"));
23+
this.$logger.out("No installed platforms found. Use $ tns platform add");
24+
}
2525
}).future<void>()();
2626
}
2727
}

lib/definitions/platform.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ interface IPlatformService {
22
addPlatforms(platforms: string[]): IFuture<void>;
33
getInstalledPlatforms(): IFuture<string[]>;
44
getAvailablePlatforms(): IFuture<string[]>;
5+
getPreparedPlatforms(): IFuture<string[]>;
56
removePlatforms(platforms: string[]): IFuture<void>;
67
runPlatform(platform: string): IFuture<void>;
78
preparePlatform(platform: string): IFuture<void>;

lib/definitions/project.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,5 @@ interface IPlatformProjectService {
2222
afterCreateProject(projectRoot: string): IFuture<void>;
2323
prepareProject(platformData: IPlatformData): IFuture<string>;
2424
buildProject(projectRoot: string): IFuture<void>;
25+
isPlatformPrepared(projectRoot: string): IFuture<boolean>;
2526
}

lib/services/android-project-service.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,10 @@ class AndroidProjectService implements IPlatformProjectService {
112112
}).future<void>()();
113113
}
114114

115+
public isPlatformPrepared(projectRoot: string): IFuture<boolean> {
116+
return this.$fs.exists(path.join(projectRoot, "assets", constants.APP_FOLDER_NAME));
117+
}
118+
115119
private spawn(command: string, args: string[]): IFuture<void> {
116120
if (hostInfo.isWindows()) {
117121
args.unshift('/s', '/c', command);

lib/services/ios-project-service.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,10 @@ class IOSProjectService implements IPlatformProjectService {
146146
}).future<void>()();
147147
}
148148

149+
public isPlatformPrepared(projectRoot: string): IFuture<boolean> {
150+
return this.$fs.exists(path.join(projectRoot, this.$projectData.projectName, constants.APP_FOLDER_NAME));
151+
}
152+
149153
private replaceFileContent(file: string): IFuture<void> {
150154
return (() => {
151155
var fileContent = this.$fs.readText(file).wait();

lib/services/platform-service.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,12 @@ export class PlatformService implements IPlatformService {
131131
}).future<string[]>()();
132132
}
133133

134+
public getPreparedPlatforms(): IFuture<string[]> {
135+
return (() => {
136+
return _.filter(this.$platformsData.platformsNames, p => { return this.isPlatformPrepared(p).wait(); });
137+
}).future<string[]>()();
138+
}
139+
134140
public preparePlatform(platform: string): IFuture<void> {
135141
return (() => {
136142
this.validatePlatformInstalled(platform);
@@ -291,6 +297,11 @@ export class PlatformService implements IPlatformService {
291297
}).future<boolean>()();
292298
}
293299

300+
private isPlatformPrepared(platform: string): IFuture<boolean> {
301+
var platformData = this.$platformsData.getPlatformData(platform);
302+
return platformData.platformProjectService.isPlatformPrepared(platformData.projectRoot);
303+
}
304+
294305
private static parsePlatformSpecificFileName(fileName: string, platforms: string[]): any {
295306
var regex = util.format("^(.+?)\.(%s)(\..+?)$", platforms.join("|"));
296307
var parsed = fileName.toLowerCase().match(new RegExp(regex, "i"));

0 commit comments

Comments
 (0)