-
-
Notifications
You must be signed in to change notification settings - Fork 197
/
Copy pathadd-library.ts
53 lines (46 loc) · 2.42 KB
/
add-library.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
///<reference path="../.d.ts"/>
"use strict";
import * as path from "path";
export class AddLibraryCommand implements ICommand {
constructor(private $platformService: IPlatformService,
private $errors: IErrors,
private $logger: ILogger,
private $fs: IFileSystem) { }
allowedParameters: ICommandParameter[] = [];
execute(args: string[]): IFuture<void> {
return (() => {
this.$logger.warn("IMPORTANT: The `tns library add` command is deprecated and will be removed in a future release. Use the plugin set of commands instead. For more information, run `tns help plugin`.");
let platform = args[0];
let libraryPath = path.resolve(args[1]);
this.$platformService.addLibrary(platform, libraryPath).wait();
this.$logger.info(`Library ${libraryPath} was successfully added for ${platform} platform.`);
}).future<void>()();
}
canExecute(args: string[]): IFuture<boolean> {
return (() => {
if (args.length !== 2) {
this.$errors.fail("This command needs two parameters.");
}
let platform = args[0];
let platformLowerCase = platform.toLowerCase();
let libraryPath = path.resolve(args[1]);
if(platformLowerCase === "android") {
if(!this.$fs.exists(path.join(libraryPath, "project.properties")).wait()) {
let files = this.$fs.enumerateFilesInDirectorySync(libraryPath);
if(!_.any(files, file => path.extname(file) === ".jar")) {
this.$errors.failWithoutHelp("Invalid library path. Ensure that the library path is the file path to a directory " +
"containing one or more `*.jar` files or to a directory containing the `project.properties` files.");
}
}
} else if(platformLowerCase === "ios") {
if(path.extname(libraryPath) !== ".framework") {
this.$errors.failWithoutHelp("Invalid library path. Ensure that the library path is a Cocoa Touch Framework with " +
"all build architectures enabled.");
}
}
this.$platformService.validatePlatformInstalled(args[0]);
return true;
}).future<boolean>()();
}
}
$injector.registerCommand("library|add", AddLibraryCommand);