-
-
Notifications
You must be signed in to change notification settings - Fork 435
/
Copy pathlibrary-service.ts
122 lines (111 loc) · 3.61 KB
/
library-service.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
import { Searchable } from './searchable';
import { Installable } from './installable';
import { ArduinoComponent } from './arduino-component';
export const LibraryServicePath = '/services/library-service';
export const LibraryService = Symbol('LibraryService');
export interface LibraryService
extends Installable<LibraryPackage>,
Searchable<LibraryPackage> {
list(options: LibraryService.List.Options): Promise<LibraryPackage[]>;
/**
* When `installDependencies` is not set, it is `true` by default. If you want to skip the installation of required dependencies, set it to `false`.
*/
install(options: {
item: LibraryPackage;
progressId?: string;
version?: Installable.Version;
installDependencies?: boolean;
}): Promise<void>;
installZip(options: {
zipUri: string;
progressId?: string;
overwrite?: boolean;
}): Promise<void>;
/**
* Set `filterSelf` to `true` if you want to avoid having `item` in the result set.
* Note: as of today (22.02.2021), the CLI works like this: `./arduino-cli lib deps Adaino@0.1.0 ✕ Adaino 0.1.0 must be installed.`.
*/
listDependencies({
item,
version,
filterSelf,
}: {
item: LibraryPackage;
version: Installable.Version;
filterSelf?: boolean;
}): Promise<LibraryDependency[]>;
}
export namespace LibraryService {
export namespace List {
export interface Options {
readonly fqbn?: string | undefined;
}
}
}
export enum LibraryLocation {
/**
* In the `libraries` subdirectory of the Arduino IDE installation.
*/
IDE_BUILTIN = 0,
/**
* In the `libraries` subdirectory of the user directory (sketchbook).
*/
USER = 1,
/**
* In the `libraries` subdirectory of a platform.
*/
PLATFORM_BUILTIN = 2,
/**
* When `LibraryLocation` is used in a context where a board is specified, this indicates the library is in the `libraries`
* subdirectory of a platform referenced by the board's platform.
*/
REFERENCED_PLATFORM_BUILTIN = 3,
}
export interface LibraryPackage extends ArduinoComponent {
/**
* Same as [`Library#real_name`](https://arduino.github.io/arduino-cli/latest/rpc/commands/#library).
* Should be used for the UI, and `name` is used to uniquely identify a library. It does not have an ID.
*/
readonly label: string;
/**
* An array of string that should be included into the `ino` file if this library is used.
* For example, including `SD` will prepend `#include <SD.h>` to the `ino` file. While including `Bridge`
* requires multiple `#include` declarations: `YunClient`, `YunServer`, `Bridge`, etc.
*/
readonly includes: string[];
readonly exampleUris: string[];
readonly location: LibraryLocation;
readonly installDirUri?: string;
}
export namespace LibraryPackage {
export function is(arg: any): arg is LibraryPackage {
return (
ArduinoComponent.is(arg) &&
'includes' in arg &&
Array.isArray(arg['includes'])
);
}
export function equals(left: LibraryPackage, right: LibraryPackage): boolean {
return left.name === right.name && left.author === right.author;
}
export function groupByLocation(packages: LibraryPackage[]): {
user: LibraryPackage[];
rest: LibraryPackage[];
} {
const user: LibraryPackage[] = [];
const rest: LibraryPackage[] = [];
for (const pkg of packages) {
if (pkg.location === LibraryLocation.USER) {
user.push(pkg);
} else {
rest.push(pkg);
}
}
return { user, rest };
}
}
export interface LibraryDependency {
readonly name: string;
readonly requiredVersion: Installable.Version;
readonly installedVersion: Installable.Version;
}