Skip to content
This repository was archived by the owner on Feb 2, 2021. It is now read-only.

Commit cf8b7c7

Browse files
author
Dimitar Kerezov
committed
Fixing PR Comments
1 parent a17ae15 commit cf8b7c7

File tree

8 files changed

+49
-36
lines changed

8 files changed

+49
-36
lines changed

codeGeneration/code-printer.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
"use strict";
33

44
import {EOL} from "os";
5-
import codeEntityLib = require("./code-entity");
5+
import {CodeEntityType} from "./code-entity";
66

7-
export class SwaggerCodePrinter {
7+
export class CodePrinter {
88
private static INDENT_CHAR = "\t";
99
private static NEW_LINE_CHAR = EOL;
1010
private static START_BLOCK_CHAR = "{";
@@ -15,39 +15,39 @@ export class SwaggerCodePrinter {
1515

1616
if(block.opener) {
1717
content += block.opener;
18-
content += SwaggerCodePrinter.START_BLOCK_CHAR;
19-
content += SwaggerCodePrinter.NEW_LINE_CHAR;
18+
content += CodePrinter.START_BLOCK_CHAR;
19+
content += CodePrinter.NEW_LINE_CHAR;
2020
}
2121

2222
_.each(block.codeEntities, (codeEntity: CodeGeneration.ICodeEntity) => {
23-
if(codeEntity.codeEntityType === codeEntityLib.CodeEntityType.Line) {
23+
if(codeEntity.codeEntityType === CodeEntityType.Line) {
2424
content += this.composeLine(<CodeGeneration.ILine>codeEntity, indentSize + 1);
25-
} else if(codeEntity.codeEntityType === codeEntityLib.CodeEntityType.Block){
25+
} else if(codeEntity.codeEntityType === CodeEntityType.Block){
2626
content += this.composeBlock(<CodeGeneration.IBlock>codeEntity, indentSize + 1);
2727
}
2828
});
2929

3030
if(block.opener) {
3131
content += this.getIndentation(indentSize);
32-
content += SwaggerCodePrinter.END_BLOCK_CHAR;
33-
content += block.endingCharacter ? block.endingCharacter : '';
32+
content += CodePrinter.END_BLOCK_CHAR;
33+
content += block.endingCharacter || '';
3434
}
3535

36-
content += SwaggerCodePrinter.NEW_LINE_CHAR;
36+
content += CodePrinter.NEW_LINE_CHAR;
3737

3838
return content;
3939
}
4040

4141
private getIndentation(indentSize: number): string {
42-
return Array(indentSize).join(SwaggerCodePrinter.INDENT_CHAR);
42+
return Array(indentSize).join(CodePrinter.INDENT_CHAR);
4343
}
4444

4545
private composeLine(line: CodeGeneration.ILine, indentSize: number): string {
4646
let content = this.getIndentation(indentSize);
4747
content += line.content;
48-
content += SwaggerCodePrinter.NEW_LINE_CHAR;
48+
content += CodePrinter.NEW_LINE_CHAR;
4949

5050
return content;
5151
}
5252
}
53-
$injector.register("swaggerCodePrinter", SwaggerCodePrinter);
53+
$injector.register("swaggerCodePrinter", CodePrinter);

commands/generate-messages.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
import * as path from "path";
44

55
export class GenerateMessages implements ICommand {
6+
private static MESSAGES_DEFINITIONS_FILE_NAME = "messages.d.ts";
7+
private static MESSAGES_IMPLEMENTATION_FILE_NAME = "messages.ts";
8+
69
constructor(private $fs: IFileSystem,
710
private $messageContractGenerator: IServiceContractGenerator,
811
private $staticConfig: Config.IStaticConfig) {
@@ -13,8 +16,18 @@ export class GenerateMessages implements ICommand {
1316
execute(args: string[]): IFuture<void> {
1417
return (() => {
1518
let result = this.$messageContractGenerator.generate().wait(),
16-
interfaceFilePath = this.$staticConfig.CLIENT_NAME ? path.join(__dirname, "../../messages.d.ts") : path.join(__dirname, "../messages/messages.d.ts"),
17-
implementationFilePath = this.$staticConfig.CLIENT_NAME ? path.join(__dirname, "../../messages.ts") : path.join(__dirname, "../messages/messages.ts");
19+
outerMessagesDirectory = path.join(__dirname, "../messages"),
20+
innerMessagesDirectory = path.join(__dirname, "../.."),
21+
interfaceFilePath: string,
22+
implementationFilePath: string;
23+
24+
if (this.$staticConfig.CLIENT_NAME) {
25+
interfaceFilePath = path.join(outerMessagesDirectory, GenerateMessages.MESSAGES_DEFINITIONS_FILE_NAME);
26+
implementationFilePath = path.join(outerMessagesDirectory, GenerateMessages.MESSAGES_IMPLEMENTATION_FILE_NAME);
27+
} else {
28+
interfaceFilePath = path.join(innerMessagesDirectory, GenerateMessages.MESSAGES_DEFINITIONS_FILE_NAME);
29+
implementationFilePath = path.join(innerMessagesDirectory, GenerateMessages.MESSAGES_IMPLEMENTATION_FILE_NAME);
30+
}
1831

1932
this.$fs.writeFile(interfaceFilePath, result.interfaceFile).wait();
2033
this.$fs.writeFile(implementationFilePath, result.implementationFile).wait();

messages/messages.d.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
//
22
// automatically generated code; do not edit manually!
33
//
4-
///<reference path="../.d.ts"/>
4+
///<reference path=".d.ts"/>
55
interface IMessages{
6-
DEVICES : {
7-
NOT_FOUND_DEVICE_BY_IDENTIFIER_ERROR_MESSAGE: string;
8-
NOT_FOUND_DEVICE_BY_IDENTIFIER_ERROR_MESSAGE_WITH_IDENTIFIER: string;
9-
NOT_FOUND_DEVICE_BY_INDEX_ERROR_MESSAGE: string;
6+
Devices : {
7+
NotFoundDeviceByIdentifierErrorMessage: string;
8+
NotFoundDeviceByIdentifierErrorMessageWithIdentifier: string;
9+
NotFoundDeviceByIndexErrorMessage: string;
1010
};
1111

1212
}

messages/messages.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
///<reference path="../.d.ts"/>
1+
///<reference path=".d.ts"/>
22
"use strict";
33
//
44
// automatically generated code; do not edit manually!
55
//
66

77
export class Messages implements IMessages{
8-
DEVICES = {
9-
NOT_FOUND_DEVICE_BY_IDENTIFIER_ERROR_MESSAGE: "DEVICES.NOT_FOUND_DEVICE_BY_IDENTIFIER_ERROR_MESSAGE",
10-
NOT_FOUND_DEVICE_BY_IDENTIFIER_ERROR_MESSAGE_WITH_IDENTIFIER: "DEVICES.NOT_FOUND_DEVICE_BY_IDENTIFIER_ERROR_MESSAGE_WITH_IDENTIFIER",
11-
NOT_FOUND_DEVICE_BY_INDEX_ERROR_MESSAGE: "DEVICES.NOT_FOUND_DEVICE_BY_INDEX_ERROR_MESSAGE",
8+
Devices = {
9+
NotFoundDeviceByIdentifierErrorMessage: "Devices.NotFoundDeviceByIdentifierErrorMessage",
10+
NotFoundDeviceByIdentifierErrorMessageWithIdentifier: "Devices.NotFoundDeviceByIdentifierErrorMessageWithIdentifier",
11+
NotFoundDeviceByIndexErrorMessage: "Devices.NotFoundDeviceByIndexErrorMessage",
1212
};
1313

1414
}

mobile/mobile-core/devices-service.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ export class DevicesService implements Mobile.IDevicesService {
118118
private getDeviceByIdentifier(identifier: string): Mobile.IDevice {
119119
let searchedDevice = _.find(this.getDeviceInstances(), (device: Mobile.IDevice) => { return device.deviceInfo.identifier === identifier; });
120120
if(!searchedDevice) {
121-
this.$errors.fail(this.$messages.DEVICES.NOT_FOUND_DEVICE_BY_IDENTIFIER_ERROR_MESSAGE_WITH_IDENTIFIER, identifier, this.$staticConfig.CLIENT_NAME.toLowerCase());
121+
this.$errors.fail(this.$messages.Devices.NotFoundDeviceByIdentifierErrorMessageWithIdentifier, identifier, this.$staticConfig.CLIENT_NAME.toLowerCase());
122122
}
123123

124124
return searchedDevice;
@@ -136,7 +136,7 @@ export class DevicesService implements Mobile.IDevicesService {
136136
}
137137

138138
if(!device) {
139-
this.$errors.fail(this.$messages.DEVICES.NOT_FOUND_DEVICE_BY_IDENTIFIER_ERROR_MESSAGE, this.$staticConfig.CLIENT_NAME.toLowerCase());
139+
this.$errors.fail(this.$messages.Devices.NotFoundDeviceByIdentifierErrorMessage, this.$staticConfig.CLIENT_NAME.toLowerCase());
140140
}
141141

142142
return device;
@@ -265,7 +265,7 @@ export class DevicesService implements Mobile.IDevicesService {
265265

266266
private validateIndex(index: number): void {
267267
if (index < 0 || index > this.getDeviceInstances().length) {
268-
throw new Error(util.format(this.$messages.DEVICES.NOT_FOUND_DEVICE_BY_INDEX_ERROR_MESSAGE, index, this.$staticConfig.CLIENT_NAME.toLowerCase()));
268+
throw new Error(util.format(this.$messages.Devices.NotFoundDeviceByIndexErrorMessage, index, this.$staticConfig.CLIENT_NAME.toLowerCase()));
269269
}
270270
}
271271
}

resources/messages/errorMessages.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
2-
"DEVICES": {
3-
"NOT_FOUND_DEVICE_BY_IDENTIFIER_ERROR_MESSAGE": "Cannot resolve the specified connected device by the provided index or identifier. To list currently connected devices and verify that the specified index or identifier exists, run '%s device'.",
4-
"NOT_FOUND_DEVICE_BY_IDENTIFIER_ERROR_MESSAGE_WITH_IDENTIFIER": "Could not find device by specified identifier '%s'. To list currently connected devices and verify that the specified identifier exists, run '%s device'.",
5-
"NOT_FOUND_DEVICE_BY_INDEX_ERROR_MESSAGE": "Could not find device by specified index %d. To list currently connected devices and verify that the specified index exists, run '%s device'."
2+
"Devices": {
3+
"NotFoundDeviceByIdentifierErrorMessage": "Cannot resolve the specified connected device by the provided index or identifier. To list currently connected devices and verify that the specified index or identifier exists, run '%s device'.",
4+
"NotFoundDeviceByIdentifierErrorMessageWithIdentifier": "Could not find device by specified identifier '%s'. To list currently connected devices and verify that the specified identifier exists, run '%s device'.",
5+
"NotFoundDeviceByIndexErrorMessage": "Could not find device by specified index %d. To list currently connected devices and verify that the specified index exists, run '%s device'."
66
}
77
}

services/message-contract-generator.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"use strict";
33

44
import {Block} from "../codeGeneration/code-entity";
5-
import {SwaggerCodePrinter} from "../codeGeneration/code-printer";
5+
import {CodePrinter} from "../codeGeneration/code-printer";
66

77
export class MessageContractGenerator implements IServiceContractGenerator {
88
private pendingModels: any;
@@ -20,7 +20,7 @@ export class MessageContractGenerator implements IServiceContractGenerator {
2020
let definitionsPath = `"${this.$staticConfig.CLIENT_NAME ? "" : "../"}.d.ts"`;
2121

2222
implementationsFile.writeLine(`///<reference path=${definitionsPath}/>`);
23-
implementationsFile.writeLine("\"use strict\";");
23+
implementationsFile.writeLine('"use strict";');
2424
implementationsFile.writeLine("//");
2525
implementationsFile.writeLine("// automatically generated code; do not edit manually!");
2626
implementationsFile.writeLine("//");
@@ -50,7 +50,7 @@ export class MessageContractGenerator implements IServiceContractGenerator {
5050
implementationsFile.addBlock(messagesClass);
5151
implementationsFile.writeLine("$injector.register('messages', Messages);");
5252

53-
let codePrinter = new SwaggerCodePrinter();
53+
let codePrinter = new CodePrinter();
5454
return {
5555
interfaceFile: codePrinter.composeBlock(interfacesFile),
5656
implementationFile: codePrinter.composeBlock(implementationsFile)

services/messages-service.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export class MessagesService implements IMessagesService {
99
private _messageJsonFilesContentsCache: any[] = null;
1010

1111
private get pathToDefaultMessageJson(): string {
12-
return path.join(path.dirname(__dirname), "resources", "messages", "errorMessages.json");
12+
return path.join(__dirname, "..", "resources", "messages", "errorMessages.json");
1313
}
1414

1515
private get messageJsonFilesContents(): any[] {
@@ -81,7 +81,7 @@ export class MessagesService implements IMessagesService {
8181
}
8282

8383
private getFormatedMessage(message: string, ...args: string[]): string {
84-
return ~message.indexOf("%") ? util.format.apply(null, [message, ...args]) : message;
84+
return ~message.indexOf("%") ? util.format(message, ...args) : message;
8585
}
8686
}
8787

0 commit comments

Comments
 (0)