Skip to content

Commit 363d7ef

Browse files
committed
Update all commands and its flags
1 parent f7e8843 commit 363d7ef

File tree

47 files changed

+240
-174
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+240
-174
lines changed

programs/cli/cli.ts

Lines changed: 72 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
#!/usr/bin/env node
22

3-
// ██████╗██ ██╗
4-
// ██╔════╝██║ ██║
5-
// ██║ ██ ██║
6-
// ██║ ██║ ██║
7-
// ██████╗███████╗██║
8-
// ╚═════╝╚══════╝╚═╝
3+
// ███████╗██╗ ██╗████████╗███████╗███╗ ██╗███████╗██╗ ██████╗ ███╗ ██╗ ██╗███████╗
4+
// ██╔════╝╚██╗██╔╝╚══██╔══╝██╔════╝████╗ ██║██╔════╝██║██╔═══██╗████╗ ██║ ██║██╔════╝
5+
// █████╗ ╚███╔╝ ███████╗ ██╔██╗ ██║███████╗██║██║ ██║██╔██╗ ██║ ██║███████╗
6+
// ██╔══╝ ██╔██╗ ████╔══╝ ██║╚██╗██║╚════██║██║██║ ██║██║╚██╗██║ ██ ██║╚════██║
7+
// ██████╗██╔╝ ██╗ ██║ ███████╗██║ ╚████║███████║██║╚██████╔╝██║ ╚████║██╗╚█████╔╝███████║
8+
// ╚══════╝╚═╝ ╚═╝ ╚═╝ ╚══════╝╚═╝ ╚═══╝╚══════╝╚═╝ ╚═════╝ ╚═╝ ╚═══╝╚═╝ ╚════╝ ╚══════╝
99

1010
import {program} from 'commander'
1111
import {extensionCreate, type CreateOptions} from 'extension-create'
@@ -17,6 +17,7 @@ import {
1717
extensionBuild,
1818
type BuildOptions,
1919
extensionPreview,
20+
type PreviewOptions,
2021
type FileConfig,
2122
type Manifest
2223
} from 'extension-develop'
@@ -32,12 +33,15 @@ checkUpdates(packageJson)
3233

3334
const extensionJs = program
3435

35-
// ███████╗██╗ ██╗████████╗███████╗███╗ ██╗███████╗██╗ ██████╗ ███╗ ██╗ ██╗███████╗
36-
// ██╔════╝╚██╗██╔╝╚══██╔══╝██╔════╝████╗ ██║██╔════╝██║██╔═══██╗████╗ ██║ ██║██╔════╝
37-
// █████╗ ╚███╔╝ ██║ █████╗ ██╔██╗ ██║███████╗██║██║ ██║██╔██╗ ██║ ██║███████╗
38-
// ██╔══╝ ██╔██╗ ██║ ██╔══╝ ██║╚██╗██║╚════██║██║██║ ██║██║╚██╗██║ ██ ██║╚════██║
39-
// ███████╗██╔╝ ██╗ ██║ ███████╗██║ ╚████║███████║██║╚██████╔╝██║ ╚████║██╗╚█████╔╝███████║
40-
// ╚══════╝╚═╝ ╚═╝ ╚═╝ ╚══════╝╚═╝ ╚═══╝╚══════╝╚═╝ ╚═════╝ ╚═╝ ╚═══╝╚═╝ ╚════╝ ╚══════╝
36+
// ██████╗██╗ ██╗
37+
// ██╔════╝██║ ██║
38+
// ██║ ██║ ██║
39+
// ██║ ██║ ██║
40+
// ╚██████╗███████╗██║
41+
// ╚═════╝╚══════╝╚═╝
42+
43+
const vendors = (browser: BrowsersSupported) =>
44+
browser === 'all' ? 'chrome,edge,firefox'.split(',') : browser.split(',')
4145

4246
extensionJs
4347
.name(packageJson.name)
@@ -52,9 +56,6 @@ extensionJs
5256
// ╚██████╗██║ ██║███████╗██║ ██║ ██║ ███████╗
5357
// ╚═════╝╚═╝ ╚═╝╚══════╝╚═╝ ╚═╝ ╚═╝ ╚══════╝
5458

55-
const vendors = (browser: BrowsersSupported) =>
56-
browser === 'all' ? 'chrome,edge,firefox'.split(',') : browser.split(',')
57-
5859
extensionJs
5960
.command('create')
6061
.arguments('<project-name|project-path>')
@@ -90,17 +91,13 @@ extensionJs
9091
.arguments('[project-path|remote-url]')
9192
.usage('dev [project-path|remote-url] [options]')
9293
.description('Starts the development server (development mode)')
93-
.option(
94-
'-u, --user-data-dir <path-to-file | boolean>',
95-
'[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'
96-
)
9794
.option(
9895
'--profile <path-to-file | boolean>',
9996
'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'
10097
)
10198
.option(
102-
'-b, --browser <chrome | edge | firefox>',
103-
'specify a browser to run your extension in development mode'
99+
'--browser <chrome | edge | firefox>',
100+
'specify a browser to preview your extension in production mode. Defaults to `chrome`'
104101
)
105102
.option(
106103
'--chromium-binary <path-to-binary>',
@@ -112,26 +109,32 @@ extensionJs
112109
)
113110
.option(
114111
'--polyfill [boolean]',
115-
'whether or not to apply the cross-browser polyfill. Defaults to `true`'
112+
'whether or not to apply the cross-browser polyfill. Defaults to `false`'
116113
)
117114
.option(
118-
'-p, --port <number>',
119-
'what port should Extension.js WebSocket server run. Defaults to `8000`'
115+
'--open [boolean]',
116+
'whether or not to open the browser automatically. Defaults to `true`'
120117
)
121118
.option(
122-
'-o, --open [boolean]',
123-
'whether or not to open the browser automatically. Defaults to `true`'
119+
'--starting-url <url>',
120+
'specify the starting URL for the browser. Defaults to `undefined`'
124121
)
125122
.action(async function (
126123
pathOrRemoteUrl: string,
127124
{browser = 'chrome', ...devOptions}: DevOptions
128125
) {
129126
for (const vendor of vendors(browser)) {
130127
await extensionDev(pathOrRemoteUrl, {
131-
browser: vendor as DevOptions['browser'],
132128
...devOptions,
129+
profile: devOptions.profile,
130+
browser: vendor as DevOptions['browser'],
131+
chromiumBinary: devOptions.chromiumBinary,
132+
geckoBinary: devOptions.geckoBinary,
133133
// @ts-expect-error open is a boolean
134-
open: devOptions.open === 'false' ? false : true
134+
polyfill: devOptions.polyfill === 'false' ? false : true,
135+
// @ts-expect-error open is a boolean
136+
open: devOptions.open === 'false' ? false : true,
137+
startingUrl: devOptions.startingUrl
135138
})
136139
}
137140
})
@@ -148,17 +151,17 @@ extensionJs
148151
.arguments('[project-path|remote-url]')
149152
.usage('start [project-path|remote-url] [options]')
150153
.description('Starts the development server (production mode)')
151-
.option(
152-
'-u, --user-data-dir <path-to-file | boolean>',
153-
'[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'
154-
)
155154
.option(
156155
'--profile <path-to-file | boolean>',
157156
'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'
158157
)
159158
.option(
160-
'-b, --browser <chrome | edge | firefox>',
161-
'specify a browser to run your extension in development mode'
159+
'--browser <chrome | edge | firefox>',
160+
'specify a browser to preview your extension in production mode. Defaults to `chrome`'
161+
)
162+
.option(
163+
'--polyfill [boolean]',
164+
'whether or not to apply the cross-browser polyfill. Defaults to `true`'
162165
)
163166
.option(
164167
'--chromium-binary <path-to-binary>',
@@ -169,21 +172,21 @@ extensionJs
169172
'specify a path to the Gecko binary. This option overrides the --browser setting. Defaults to the system default'
170173
)
171174
.option(
172-
'--polyfill [boolean]',
173-
'whether or not to apply the cross-browser polyfill. Defaults to `true`'
174-
)
175-
.option(
176-
'-p, --port <number>',
177-
'what port should Extension.js run. Defaults to `3000`'
175+
'--starting-url <url>',
176+
'specify the starting URL for the browser. Defaults to `undefined`'
178177
)
179178
.action(async function (
180179
pathOrRemoteUrl: string,
181180
{browser = 'chrome', ...startOptions}: StartOptions
182181
) {
183182
for (const vendor of vendors(browser)) {
184183
await extensionStart(pathOrRemoteUrl, {
184+
mode: 'production',
185+
profile: startOptions.profile,
185186
browser: vendor as StartOptions['browser'],
186-
...startOptions
187+
chromiumBinary: startOptions.chromiumBinary,
188+
geckoBinary: startOptions.geckoBinary,
189+
startingUrl: startOptions.startingUrl
187190
})
188191
}
189192
})
@@ -199,7 +202,15 @@ extensionJs
199202
.command('preview')
200203
.arguments('[project-name]')
201204
.usage('preview [path-to-remote-extension] [options]')
202-
.description('Builds the extension for production')
205+
.description('Preview the extension in production mode')
206+
.option(
207+
'--profile <path-to-file | boolean>',
208+
'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'
209+
)
210+
.option(
211+
'--browser <chrome | edge | firefox>',
212+
'specify a browser to preview your extension in production mode. Defaults to `chrome`'
213+
)
203214
.option(
204215
'--chromium-binary <path-to-binary>',
205216
'specify a path to the Chromium binary. This option overrides the --browser setting. Defaults to the system default'
@@ -209,18 +220,21 @@ extensionJs
209220
'specify a path to the Gecko binary. This option overrides the --browser setting. Defaults to the system default'
210221
)
211222
.option(
212-
'-b, --browser <chrome | edge | firefox>',
213-
'specify a browser to preview your extension in production mode'
223+
'--starting-url <url>',
224+
'specify the starting URL for the browser. Defaults to `undefined`'
214225
)
215226
.action(async function (
216227
pathOrRemoteUrl: string,
217-
{browser = 'chrome', ...previewOptions}: BuildOptions
228+
{browser = 'chrome', ...previewOptions}: PreviewOptions
218229
) {
219230
for (const vendor of vendors(browser)) {
220231
await extensionPreview(pathOrRemoteUrl, {
221232
mode: 'production',
222-
browser: vendor as any,
223-
...previewOptions
233+
profile: previewOptions.profile,
234+
browser: vendor as PreviewOptions['browser'],
235+
chromiumBinary: previewOptions.chromiumBinary,
236+
geckoBinary: previewOptions.geckoBinary,
237+
startingUrl: previewOptions.startingUrl
224238
})
225239
}
226240
})
@@ -238,8 +252,8 @@ extensionJs
238252
.usage('build [path-to-remote-extension] [options]')
239253
.description('Builds the extension for production')
240254
.option(
241-
'-b, --browser <chrome | edge | firefox>',
242-
'specify a browser to run your extension in development mode'
255+
'--browser <chrome | edge | firefox>',
256+
'specify a browser to preview your extension in production mode. Defaults to `chrome`'
243257
)
244258
.option(
245259
'--polyfill [boolean]',
@@ -257,14 +271,22 @@ extensionJs
257271
'--zip-filename <string>',
258272
'specify the name of the ZIP file. Defaults to the extension name and version'
259273
)
274+
.option(
275+
'--silent [boolean]',
276+
'whether or not to open the browser automatically. Defaults to `false`'
277+
)
260278
.action(async function (
261279
pathOrRemoteUrl: string,
262280
{browser = 'chrome', ...buildOptions}: BuildOptions
263281
) {
264282
for (const vendor of vendors(browser)) {
265283
await extensionBuild(pathOrRemoteUrl, {
266284
browser: vendor as BuildOptions['browser'],
267-
...buildOptions
285+
polyfill: buildOptions.polyfill,
286+
zip: buildOptions.zip,
287+
zipSource: buildOptions.zipSource,
288+
zipFilename: buildOptions.zipFilename,
289+
silent: buildOptions.silent
268290
})
269291
}
270292
})

programs/develop/build.spec.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ function distFileExists(
4848
)
4949

5050
if (filePath) {
51-
console.log('3iuteghkgewktgdtqwegdhiq3thegd', path.join(templatePath, filePath))
5251
return fs.existsSync(path.join(templatePath, filePath))
5352
} else {
5453
// Check if any HTML file exists in the directory

programs/develop/commands/build.ts

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,8 @@ import webpackConfig from '../webpack/webpack-config'
1313
import {getProjectPath} from './commands-lib/get-project-path'
1414
import * as messages from './commands-lib/messages'
1515
import {generateZip} from './commands-lib/generate-zip'
16-
import {loadExtensionConfig} from './commands-lib/get-extension-config'
17-
import {DevOptions} from './dev'
18-
19-
export interface BuildOptions {
20-
browser?: DevOptions['browser']
21-
zipFilename?: string
22-
zip?: boolean
23-
zipSource?: boolean
24-
polyfill?: boolean
25-
silent?: boolean
26-
}
16+
import {loadCustomWebpackConfig} from './commands-lib/get-extension-config'
17+
import {BuildOptions} from './commands-lib/config-types'
2718

2819
export async function extensionBuild(
2920
pathOrRemoteUrl: string | undefined,
@@ -56,7 +47,7 @@ export async function extensionBuild(
5647
)
5748
})
5849

59-
const userExtensionConfig = loadExtensionConfig(projectPath)
50+
const userExtensionConfig = loadCustomWebpackConfig(projectPath)
6051
const userConfig = userExtensionConfig({
6152
...baseConfig,
6253
plugins: allPluginsButBrowserRunners

programs/develop/commands/commands-lib/config-types.ts

Lines changed: 64 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,41 @@
11
import {Configuration} from 'webpack'
2-
import {DevOptions} from '../dev'
3-
import {PreviewOptions} from '../preview'
4-
import {BuildOptions} from '../build'
5-
6-
type BrowserConfig = Pick<
7-
DevOptions,
8-
| 'open'
9-
| 'profile'
10-
| 'preferences'
11-
| 'browserFlags'
12-
| 'startingUrl'
13-
| 'chromiumBinary'
14-
| 'geckoBinary'
15-
>
2+
3+
export interface BrowserOptions {
4+
profile?: string
5+
startingUrl?: string
6+
browser: 'chrome' | 'edge' | 'firefox' | 'chromium-based' | 'gecko-based'
7+
chromiumBinary?: string
8+
geckoBinary?: string
9+
}
10+
11+
export interface DevOptions extends BrowserOptions {
12+
mode: 'development' | 'production'
13+
open?: boolean
14+
polyfill?: boolean
15+
}
16+
17+
export interface BuildOptions {
18+
browser: BrowserOptions['browser']
19+
zipFilename?: string
20+
zip?: boolean
21+
zipSource?: boolean
22+
polyfill?: boolean
23+
silent?: boolean
24+
}
25+
26+
export interface PreviewOptions extends BrowserOptions {
27+
mode: 'production'
28+
}
29+
30+
export interface StartOptions extends BrowserOptions {
31+
mode: 'production'
32+
polyfill?: boolean
33+
}
34+
35+
export interface BrowserConfig extends BrowserOptions {
36+
browserFlags?: string[]
37+
preferences?: Record<string, unknown>
38+
}
1639

1740
export interface FileConfig {
1841
browser?: {
@@ -23,11 +46,35 @@ export interface FileConfig {
2346
'gecko-based'?: BrowserConfig
2447
}
2548
commands?: {
26-
dev?: Pick<DevOptions, 'browser' | 'profile' | 'preferences' | 'polyfill'>
49+
dev?: Pick<
50+
DevOptions,
51+
| 'browser'
52+
| 'profile'
53+
| 'chromiumBinary'
54+
| 'geckoBinary'
55+
| 'open'
56+
| 'polyfill'
57+
> & {
58+
browserFlags?: string[]
59+
preferences?: Record<string, unknown>
60+
}
61+
62+
start?: Pick<
63+
StartOptions,
64+
'browser' | 'profile' | 'chromiumBinary' | 'geckoBinary' | 'polyfill'
65+
> & {
66+
browserFlags?: string[]
67+
preferences?: Record<string, unknown>
68+
}
69+
2770
preview?: Pick<
2871
PreviewOptions,
29-
'browser' | 'profile' | 'preferences' | 'polyfill'
30-
>
72+
'browser' | 'profile' | 'chromiumBinary' | 'geckoBinary'
73+
> & {
74+
browserFlags?: string[]
75+
preferences?: Record<string, unknown>
76+
}
77+
3178
build?: Pick<
3279
BuildOptions,
3380
'browser' | 'zipFilename' | 'zip' | 'zipSource' | 'polyfill'

programs/develop/commands/commands-lib/generate-zip.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import ignore from 'ignore'
44
import glob from 'tiny-glob'
55
import AdmZip from 'adm-zip'
66
import slugify from 'slugify'
7-
import {type BuildOptions} from '../build'
7+
import {type BuildOptions} from '../commands-lib/config-types'
88
import * as messages from './messages'
99

1010
function readFileSync(filePath: string): string {
@@ -76,7 +76,7 @@ export async function generateZip(
7676
const manifest: Record<string, string> = require(
7777
path.join(dataDir, 'manifest.json')
7878
)
79-
const name = getPackageName(manifest, options)
79+
const name = getPackageName(manifest, {browser, ...options})
8080
const ext = getExtensionExtension(browser)
8181
// Dist zips are stored in dist/[browser]/[name].zip
8282
const distZipPath = path.join(outputDir, `${name}.${ext}`)

0 commit comments

Comments
 (0)