Skip to content

Commit cdce7a1

Browse files
author
Dimitar Kerezov
committed
Introduce messages service/code-generation
Makes use of JSON files containing string messages which can later be accessed from within the CLI. A dev command (dev-generate-messages) is introduced for ease of use and autocompletion. There is a default json message file with is loaded by default however each client may provide their own json file and thus override keys, extend and so on. Includes a bit of refactoring concerning swagger code generation - extracting/moving common interfaces/implementation classes to common.
1 parent 78835ec commit cdce7a1

File tree

6 files changed

+37
-2
lines changed

6 files changed

+37
-2
lines changed

lib/messages.d.ts

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
///<reference path=".d.ts"/>
2+
//
3+
// automatically generated code; do not edit manually!
4+
//
5+
interface IMessages{
6+
Devices : {
7+
NotFoundDeviceByIdentifierErrorMessage: string;
8+
NotFoundDeviceByIdentifierErrorMessageWithIdentifier: string;
9+
NotFoundDeviceByIndexErrorMessage: string;
10+
};
11+
12+
}
13+

lib/messages.ts

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
///<reference path=".d.ts"/>
2+
"use strict";
3+
//
4+
// automatically generated code; do not edit manually!
5+
//
6+
7+
export class Messages implements IMessages{
8+
Devices = {
9+
NotFoundDeviceByIdentifierErrorMessage: "Devices.NotFoundDeviceByIdentifierErrorMessage",
10+
NotFoundDeviceByIdentifierErrorMessageWithIdentifier: "Devices.NotFoundDeviceByIdentifierErrorMessageWithIdentifier",
11+
NotFoundDeviceByIndexErrorMessage: "Devices.NotFoundDeviceByIndexErrorMessage",
12+
};
13+
14+
}
15+
$injector.register('messages', Messages);
16+

lib/nativescript-cli.ts

+3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ fiber(() => {
1717

1818
let commandDispatcher: ICommandDispatcher = $injector.resolve("commandDispatcher");
1919

20+
let messages: IMessagesService = $injector.resolve("$messagesService");
21+
messages.pathsToMessageJsonFiles = [/* Place client-specific json message file paths here */];
22+
2023
if (process.argv[2] === "completion") {
2124
commandDispatcher.completeCommand().wait();
2225
} else {

test/plugin-variables-service.ts

+2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {ProjectData} from "../lib/project-data";
1313
import {ProjectDataService} from "../lib/services/project-data-service";
1414
import {ProjectHelper} from "../lib/common/project-helper";
1515
import {StaticConfig} from "../lib/config";
16+
import {MessagesService} from "../lib/common/services/messages-service";
1617
import {Yok} from '../lib/common/yok';
1718
import * as stubs from './stubs';
1819
import * as path from "path";
@@ -22,6 +23,7 @@ temp.track();
2223
function createTestInjector(): IInjector {
2324
let testInjector = new Yok();
2425

26+
testInjector.register("messagesService", MessagesService);
2527
testInjector.register("errors", Errors);
2628
testInjector.register("fs", FileSystem);
2729
testInjector.register("hostInfo", HostInfo);

test/plugins-service.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import {ResourceLoader} from "../lib/common/resource-loader";
2424
import {EOL} from "os";
2525
import {PluginsService} from "../lib/services/plugins-service";
2626
import {AddPluginCommand} from "../lib/commands/plugin/add-plugin";
27+
import {MessagesService} from "../lib/common/services/messages-service";
2728
import {Builder} from "../lib/tools/broccoli/builder";
2829
import {AndroidProjectService} from "../lib/services/android-project-service";
2930
import {AndroidToolsInfo} from "../lib/android-tools-info";
@@ -37,7 +38,7 @@ let isErrorThrown = false;
3738

3839
function createTestInjector() {
3940
let testInjector = new Yok();
40-
41+
testInjector.register("messagesService", MessagesService);
4142
testInjector.register("npm", NodePackageManager);
4243
testInjector.register("fs", FileSystem);
4344
testInjector.register("projectData", ProjectData);

0 commit comments

Comments
 (0)