Skip to content

Commit 29ce268

Browse files
committed
Stub the library add command
1 parent 6e04882 commit 29ce268

File tree

10 files changed

+80
-1
lines changed

10 files changed

+80
-1
lines changed

lib/bootstrap.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ $injector.requireCommand("platform|*list", "./commands/list-platforms");
2626
$injector.requireCommand("platform|add", "./commands/add-platform");
2727
$injector.requireCommand("platform|remove", "./commands/remove-platform");
2828
$injector.requireCommand("platform|update", "./commands/update-platform");
29+
$injector.requireCommand("library|add", "./commands/add-library");
2930
$injector.requireCommand("run|ios", "./commands/run");
3031
$injector.requireCommand("run|android", "./commands/run");
3132
$injector.requireCommand("debug", "./commands/debug");

lib/commands/add-library.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
///<reference path="../.d.ts"/>
2+
"use strict";
3+
4+
import path = require("path");
5+
import Future = require("fibers/future");
6+
7+
export class AddLibraryCommand implements ICommand {
8+
constructor(private $platformService: IPlatformService,
9+
private $errors: IErrors) { }
10+
11+
allowedParameters: ICommandParameter[] = [];
12+
13+
execute(args: string[]): IFuture<void> {
14+
var platform = args[0];
15+
var libraryPath = path.resolve(args[1]);
16+
return this.$platformService.addLibrary(platform, libraryPath);
17+
}
18+
19+
canExecute(args: string[]): IFuture<boolean> {
20+
if (args.length != 2) {
21+
this.$errors.fail("This command needs two parameters.");
22+
}
23+
24+
this.$platformService.validatePlatformInstalled(args[0]);
25+
return Future.fromResult(true);
26+
}
27+
}
28+
$injector.registerCommand("library|add", AddLibraryCommand);

lib/definitions/osenv.d.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/*
12
declare module "osenv" {
23
function home(): string;
3-
}
4+
}*/

lib/definitions/platform.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ interface IPlatformService {
1313
deployOnEmulator(platform: string): IFuture<void>;
1414
validatePlatformInstalled(platform: string): void;
1515
validatePlatform(platform: string): void;
16+
addLibrary(platform: string, libraryPath: string): IFuture<void>;
1617
}
1718

1819
interface IPlatformData {

lib/definitions/project.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,5 @@ interface IPlatformProjectService {
2929
prepareProject(platformData: IPlatformData): IFuture<string>;
3030
buildProject(projectRoot: string): IFuture<void>;
3131
isPlatformPrepared(projectRoot: string): IFuture<boolean>;
32+
addLibrary(projectRoot: string, libraryPath: string): IFuture<void>;
3233
}

lib/services/android-project-service.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,11 @@ class AndroidProjectService implements IPlatformProjectService {
132132
return this.$fs.exists(path.join(projectRoot, "assets", constants.APP_FOLDER_NAME));
133133
}
134134

135+
public addLibrary(projectRoot: string, libraryPath: string): IFuture<void> {
136+
this.$errors.fail("Implement me!");
137+
return Future.fromResult();
138+
}
139+
135140
public getFrameworkFilesExtensions(): string[] {
136141
return [".jar", ".dat"];
137142
}

lib/services/ios-project-service.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,11 @@ class IOSProjectService implements IPlatformProjectService {
169169
return this.$fs.exists(path.join(projectRoot, this.$projectData.projectName, constants.APP_FOLDER_NAME));
170170
}
171171

172+
public addLibrary(projectRoot: string, libraryPath: string): IFuture<void> {
173+
this.$errors.fail("Implement me!");
174+
return Future.fromResult();
175+
}
176+
172177
private replaceFileContent(file: string): IFuture<void> {
173178
return (() => {
174179
var fileContent = this.$fs.readText(file).wait();

lib/services/platform-service.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,23 @@ export class PlatformService implements IPlatformService {
322322
}
323323
}
324324

325+
public addLibrary(platform: string, libraryPath: string): IFuture<void> {
326+
return (() => {
327+
if (!this.$fs.exists(libraryPath).wait()) {
328+
this.$errors.fail("The path %s does not exist", libraryPath);
329+
} else {
330+
var name = path.basename(libraryPath);
331+
var targetPath = path.join(this.$projectData.projectDir, "lib", platformData.normalizedPlatformName, path.basename(name, path.extname(name)));
332+
this.$fs.ensureDirectoryExists(targetPath).wait();
333+
334+
shell.cp("-R", libraryPath, targetPath);
335+
336+
var platformData = this.$platformsData.getPlatformData(platform);
337+
platformData.platformProjectService.addLibrary(platformData.projectRoot, path.join(targetPath, name)).wait();
338+
}
339+
}).future<void>()();
340+
}
341+
325342
private isValidPlatform(platform: string) {
326343
return this.$platformsData.getPlatformData(platform);
327344
}

resources/help.txt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,23 @@ in the platforms directory. This lets you build the project with the SDK for the
163163

164164
--[/]--
165165

166+
--[library|add]--
167+
168+
Usage
169+
$ tns library add <Platform> <Library path>
170+
$ nativescript library add <Platform> <Library path>
171+
172+
Platform-specific usage:
173+
$ tns library add android <Library path>
174+
$ tns library add ios <Library path>
175+
$ nativescript library add android <Library path>
176+
$ nativescript library add ios <Library path>
177+
178+
Copies the native library at <Library path> to the current project and adds it to the native build for the selected platform.
179+
The NativeScript runtime will expose the APIs available in the native library in your application.
180+
181+
--[/]--
182+
166183
--[build]--
167184

168185
Usage:

test/stubs.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,9 @@ export class PlatformProjectServiceStub implements IPlatformProjectService {
254254
isPlatformPrepared(projectRoot: string): IFuture<boolean> {
255255
return Future.fromResult(false);
256256
}
257+
addLibrary(projectRoot: string, libraryPath: string): IFuture<void> {
258+
return Future.fromResult();
259+
}
257260
}
258261

259262
export class ProjectDataService implements IProjectDataService {

0 commit comments

Comments
 (0)