-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
/
Copy pathcapacitor.ts
163 lines (158 loc) · 4.25 KB
/
capacitor.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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
const platforms: Fig.Suggestion[] = [
{ name: "android", icon: "fig://icon?type=android" },
{ name: "ios", icon: "fig://icon?type=apple" },
];
function isPlatform(value: string): value is "ios" | "android" {
return value === "ios" || value === "android";
}
const targetGenerator: Fig.Generator = {
cache: {
ttl: 1000 * 60, // Only caches targets for one minute, in case a new device is connected
},
custom: async (tokens, executeShellCommand) => {
const [cliName, command, platform] = tokens;
if (!isPlatform(platform)) {
return [];
}
const { stdout } = await executeShellCommand({
command: "npx",
args: ["capacitor", "run", platform, "--list"],
});
return stdout
.trim()
.split("\n")
.slice(2) // Ignore output header lines
.map((s) => {
const [name, api, targetId] = s.replace(/\s\s+/g, "|").split("|");
return {
name: targetId,
displayName: `${name} ${api}`,
icon: "📱",
};
});
},
};
const completionSpec: Fig.Spec = {
name: "capacitor",
description:
"The Capacitor command-line interface (CLI) tool is used to develop Capacitor apps",
icon: "https://capacitorjs.com/docs/img/meta/favicon.png",
subcommands: [
{
name: "add",
description: "Add a native platform project to your app",
args: {
name: "platform",
suggestions: platforms,
},
},
{
name: "copy",
description:
"Copy the web app build and Capacitor configuration file into the native platform project. Run this each time you make changes to your web app or change a configuration value",
priority: 51,
args: {
name: "platform",
suggestions: platforms,
isOptional: true,
},
},
{
name: "ls",
description: "List all installed Cordova and Capacitor plugins",
args: {
name: "platform",
suggestions: platforms,
isOptional: true,
},
},
{
name: "open",
description:
"Opens the native project workspace in the specified native IDE (Xcode for iOS, Android Studio for Android)",
priority: 51,
args: {
name: "platform",
suggestions: platforms,
},
},
{
name: "run",
description:
"Opens the native project workspace in the specified native IDE (Xcode for iOS, Android Studio for Android)",
priority: 51,
args: {
name: "platform",
suggestions: platforms,
},
options: [
{
name: "--list",
description:
"Print a list of target devices available to the given platform",
icon: "📱",
},
{
name: "--target",
description: "Run on a specific target device",
icon: "📱",
args: {
name: "target",
generators: targetGenerator,
},
},
],
},
{
name: "sync",
description: "This command runs copy and then update",
args: {
name: "platform",
suggestions: platforms,
isOptional: true,
},
options: [
{
name: "--deployment",
description:
"Podfile.lock won't be deleted and pod install will use --deployment option",
},
{
name: "--inline",
description:
"After syncing, all JS source maps will be inlined allowing for debugging an Android Web View in Chromium based browsers",
},
],
},
{
name: "update",
description:
"Updates the native plugins and dependencies referenced in package.json",
args: {
name: "platform",
suggestions: platforms,
isOptional: true,
},
options: [
{
name: "--deployment",
description:
"Podfile.lock won't be deleted and pod install will use --deployment option",
},
],
},
],
options: [
{
name: ["--help", "-h"],
description:
"Output usage information. Can be used with individual commands too",
isPersistent: true,
},
{
name: ["--version", "-V"],
description: "Output the version number",
},
],
};
export default completionSpec;