-
-
Notifications
You must be signed in to change notification settings - Fork 95
/
cli.ts
executable file
Β·272 lines (253 loc) Β· 12 KB
/
cli.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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
#!/usr/bin/env node
// ββββββββββ βββ
// βββββββββββ βββ
// βββ βββ βββ
// βββ βββ βββ
// βββββββββββββββββββ
// ββββββββββββββββββ
import {program} from 'commander'
import {extensionCreate, type CreateOptions} from 'extension-create'
import {
extensionDev,
type DevOptions,
extensionStart,
type StartOptions,
extensionBuild,
type BuildOptions,
extensionPreview,
type FileConfig,
type Manifest
} from 'extension-develop'
import * as messages from './cli-lib/messages'
import type {BrowsersSupported} from './types'
import checkUpdates from './check-updates'
import packageJson from './package.json'
export {type FileConfig, type Manifest}
// Before all, check for updates.
checkUpdates(packageJson)
const extensionJs = program
// βββββββββββ ββββββββββββββββββββββββ ββββββββββββββ βββββββ ββββ βββ βββββββββββ
// ββββββββββββββββββββββββββββββββββββββ ββββββββββββββββββββββββββββ βββ βββββββββββ
// ββββββ ββββββ βββ ββββββ ββββββ βββββββββββββββββ βββββββββ βββ βββββββββββ
// ββββββ ββββββ βββ ββββββ ββββββββββββββββββββββββ βββββββββββββ ββ βββββββββββ
// ββββββββββββ βββ βββ βββββββββββ βββββββββββββββββββββββββββββ βββββββββββββββββββββββββ
// βββββββββββ βββ βββ βββββββββββ ββββββββββββββββ βββββββ βββ ββββββββ ββββββ ββββββββ
extensionJs
.name(packageJson.name)
.description(packageJson.description)
.version(packageJson.version)
.addHelpText('after', messages.programHelp())
// ββββββββββββββ ββββββββ ββββββ βββββββββββββββββ
// βββββββββββββββββββββββββββββββββββββββββββββββββ
// βββ ββββββββββββββ ββββββββ βββ ββββββ
// βββ ββββββββββββββ ββββββββ βββ ββββββ
// βββββββββββ ββββββββββββββ βββ βββ ββββββββ
// ββββββββββ ββββββββββββββ βββ βββ ββββββββ
const vendors = (browser: BrowsersSupported) =>
browser === 'all' ? 'chrome,edge,firefox'.split(',') : browser.split(',')
extensionJs
.command('create')
.arguments('<project-name|project-path>')
.usage('create <project-name|project-path> [options]')
.description('Creates a new extension.')
.option(
'-t, --template <template-name>',
'specify a template for the created project'
)
.option(
'--install',
'whether or not to install the dependencies after creating the project'
)
.action(async function (
pathOrRemoteUrl: string,
{template, install}: CreateOptions
) {
await extensionCreate(pathOrRemoteUrl, {
template,
install
})
})
// βββββββ βββββββββββ βββ
// βββββββββββββββββββ βββ
// βββ βββββββββ βββ βββ
// βββ βββββββββ ββββ ββββ
// ββββββββββββββββ βββββββ
// βββββββ ββββββββ βββββ
extensionJs
.command('dev')
.arguments('[project-path|remote-url]')
.usage('dev [project-path|remote-url] [options]')
.description('Starts the development server (development mode)')
.option(
'-u, --user-data-dir <path-to-file | boolean>',
'[DEPRECATED - Use "--profile" instead] what path to use for the browser profile. A boolean value of false sets the profile to the default user profile. Defaults to a fresh profile'
)
.option(
'--profile <path-to-file | boolean>',
'what path to use for the browser profile. A boolean value of false sets the profile to the default user profile. Defaults to a fresh profile'
)
.option(
'-b, --browser <chrome | edge | firefox>',
'specify a browser to run your extension in development mode'
)
.option(
'--chromium-binary <path-to-binary>',
'specify a path to the Chromium binary. This option overrides the --browser setting. Defaults to the system default'
)
.option(
'--gecko-binary <path-to-binary>',
'specify a path to the Gecko binary. This option overrides the --browser setting. Defaults to the system default'
)
.option(
'--polyfill [boolean]',
'whether or not to apply the cross-browser polyfill. Defaults to `true`'
)
.option(
'-p, --port <number>',
'what port should Extension.js WebSocket server run. Defaults to `8000`'
)
.option(
'-o, --open [boolean]',
'whether or not to open the browser automatically. Defaults to `true`'
)
.action(async function (
pathOrRemoteUrl: string,
{browser = 'chrome', ...devOptions}: DevOptions
) {
for (const vendor of vendors(browser)) {
await extensionDev(pathOrRemoteUrl, {
browser: vendor as DevOptions['browser'],
...devOptions,
// @ts-expect-error open is a boolean
open: devOptions.open === 'false' ? false : true
})
}
})
// βββββββββββββββββ ββββββ βββββββ βββββββββ
// ββββββββββββββββββββββββββββββββββββββββββ
// ββββββββ βββ ββββββββββββββββ βββ
// ββββββββ βββ ββββββββββββββββ βββ
// ββββββββ βββ βββ ββββββ βββ βββ
// ββββββββ βββ βββ ββββββ βββ βββ
extensionJs
.command('start')
.arguments('[project-path|remote-url]')
.usage('start [project-path|remote-url] [options]')
.description('Starts the development server (production mode)')
.option(
'-u, --user-data-dir <path-to-file | boolean>',
'[DEPRECATED - Use "--profile" instead] what path to use for the browser profile. A boolean value of false sets the profile to the default user profile. Defaults to a fresh profile'
)
.option(
'--profile <path-to-file | boolean>',
'what path to use for the browser profile. A boolean value of false sets the profile to the default user profile. Defaults to a fresh profile'
)
.option(
'-b, --browser <chrome | edge | firefox>',
'specify a browser to run your extension in development mode'
)
.option(
'--chromium-binary <path-to-binary>',
'specify a path to the Chromium binary. This option overrides the --browser setting. Defaults to the system default'
)
.option(
'--gecko-binary <path-to-binary>',
'specify a path to the Gecko binary. This option overrides the --browser setting. Defaults to the system default'
)
.option(
'--polyfill [boolean]',
'whether or not to apply the cross-browser polyfill. Defaults to `true`'
)
.option(
'-p, --port <number>',
'what port should Extension.js run. Defaults to `3000`'
)
.action(async function (
pathOrRemoteUrl: string,
{browser = 'chrome', ...startOptions}: StartOptions
) {
for (const vendor of vendors(browser)) {
await extensionStart(pathOrRemoteUrl, {
browser: vendor as StartOptions['browser'],
...startOptions
})
}
})
// βββββββ βββββββ βββββββββββ βββββββββββββββββ βββ
// βββββββββββββββββββββββββββ βββββββββββββββββ βββ
// ββββββββββββββββββββββ βββ ββββββββββββ βββ ββ βββ
// βββββββ ββββββββββββββ ββββ βββββββββββββ ββββββββββ
// βββ βββ βββββββββββ βββββββ βββββββββββββββββββββ
// βββ βββ βββββββββββ βββββ βββββββββββ ββββββββ
extensionJs
.command('preview')
.arguments('[project-name]')
.usage('preview [path-to-remote-extension] [options]')
.description('Builds the extension for production')
.option(
'--chromium-binary <path-to-binary>',
'specify a path to the Chromium binary. This option overrides the --browser setting. Defaults to the system default'
)
.option(
'--gecko-binary <path-to-binary>',
'specify a path to the Gecko binary. This option overrides the --browser setting. Defaults to the system default'
)
.option(
'-b, --browser <chrome | edge | firefox>',
'specify a browser to preview your extension in production mode'
)
.action(async function (
pathOrRemoteUrl: string,
{browser = 'chrome', ...previewOptions}: BuildOptions
) {
for (const vendor of vendors(browser)) {
await extensionPreview(pathOrRemoteUrl, {
mode: 'production',
browser: vendor as any,
...previewOptions
})
}
})
// βββββββ βββ βββββββββ βββββββ
// βββββββββββ βββββββββ ββββββββ
// βββββββββββ βββββββββ βββ βββ
// βββββββββββ βββββββββ βββ βββ
// ββββββββββββββββββββββββββββββββββββ
// βββββββ βββββββ ββββββββββββββββββ
extensionJs
.command('build')
.arguments('[project-name]')
.usage('build [path-to-remote-extension] [options]')
.description('Builds the extension for production')
.option(
'-b, --browser <chrome | edge | firefox>',
'specify a browser to run your extension in development mode'
)
.option(
'--polyfill [boolean]',
'whether or not to apply the cross-browser polyfill. Defaults to `false`'
)
.option(
'--zip [boolean]',
'whether or not to compress the extension into a ZIP file. Defaults to `false`'
)
.option(
'--zip-source [boolean]',
'whether or not to include the source files in the ZIP file. Defaults to `false`'
)
.option(
'--zip-filename <string>',
'specify the name of the ZIP file. Defaults to the extension name and version'
)
.action(async function (
pathOrRemoteUrl: string,
{browser = 'chrome', ...buildOptions}: BuildOptions
) {
for (const vendor of vendors(browser)) {
await extensionBuild(pathOrRemoteUrl, {
browser: vendor as BuildOptions['browser'],
...buildOptions
})
}
})
extensionJs.parse()