@blastlauncher/cli 1.0.5 → 3.0.0-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,48 +1,5 @@
1
- # `@blastlauncher/cli`
2
-
3
- `@blastlauncher/cli` is a command line tool that used to build and publish Blast Launcher extensions.
4
-
5
- I somehow discover that Raycast's extension build output are similar to esbuild's output, so I also use esbuild to bundle the extension and pkg to package the cli executable. Ray's CLI is way smaller, I guess their CLI is written in Go. 🤣
6
-
7
- The publish command will upload the extension to npm registry(which is released under `@blast-extensions` for now).
8
-
9
- ## Development
10
-
11
- ```bash
12
- # Output single cjs file with esbuild
13
- pnpm build
14
-
15
- # Run the cli
16
- node ./dist/index.cjs --help
17
-
18
- # Package to cli executable with pkg
19
- pnpm package
20
-
21
- # Run the cli executable
22
- ./dist/cli-macos --help
23
- ```
24
-
25
- ## Installation
26
-
27
- ### npm
28
-
29
- ```bash
30
- npm install -g @blastlauncher/cli
31
- ```
32
-
33
- ## Help
34
-
35
- ```bash
36
- Usage: blast [options] [command]
37
-
38
- CLI for Blast Launcher
39
-
40
- Options:
41
- -h, --help display help for command
42
-
43
- Commands:
44
- publish [options] <path> <organization> Publish extensions
45
- build [options] <path> Build extensions
46
- help [command] display help for command
47
- ```
1
+ # @blastlauncher/cli
48
2
 
3
+ Blast's cli package.
4
+ Emitted ESM and TypeScript declarations for Node.js 24.20+.
5
+ See https://github.com/BlastLauncher/blast for documentation.
@@ -0,0 +1,11 @@
1
+ import type { CapabilityHandler } from "@blastlauncher/engine";
2
+ export type BrowserTab = {
3
+ id: number;
4
+ url: string;
5
+ active: boolean;
6
+ title?: string;
7
+ favicon?: string;
8
+ content?: string;
9
+ };
10
+ export declare function parseBrowserTabs(text: string): BrowserTab[];
11
+ export declare function createBrowserHandlers(tabs: BrowserTab[]): Record<string, CapabilityHandler>;
@@ -0,0 +1,49 @@
1
+ export function parseBrowserTabs(text) {
2
+ const tabs = JSON.parse(text);
3
+ if (!Array.isArray(tabs))
4
+ throw new Error("must be a JSON array of tabs");
5
+ const ids = new Set();
6
+ return tabs.map((tab, index) => {
7
+ if (!tab ||
8
+ typeof tab !== "object" ||
9
+ !Number.isInteger(tab.id) ||
10
+ typeof tab.url !== "string" ||
11
+ typeof tab.active !== "boolean")
12
+ throw new Error(`tab ${index + 1} requires integer id, string url and boolean active`);
13
+ if (ids.has(tab.id))
14
+ throw new Error(`duplicate tab id ${tab.id}`);
15
+ ids.add(tab.id);
16
+ const result = { id: tab.id, url: tab.url, active: tab.active };
17
+ for (const field of ["title", "favicon", "content"]) {
18
+ if (tab[field] !== undefined) {
19
+ if (typeof tab[field] !== "string")
20
+ throw new Error(`tab ${index + 1}: ${field} must be a string`);
21
+ result[field] = tab[field];
22
+ }
23
+ }
24
+ return result;
25
+ });
26
+ }
27
+ export function createBrowserHandlers(tabs) {
28
+ return {
29
+ "browser.tabs": () => tabs.map(({ content: _content, ...tab }) => tab),
30
+ "browser.content": (params) => {
31
+ if (!params || typeof params !== "object" || Array.isArray(params))
32
+ throw new Error("browser.content: expected options");
33
+ if (params.tabId !== undefined &&
34
+ (typeof params.tabId !== "number" || !Number.isInteger(params.tabId)))
35
+ throw new Error("browser.content: invalid tabId");
36
+ if (params.format !== undefined &&
37
+ !["html", "text", "markdown"].includes(String(params.format)))
38
+ throw new Error("browser.content: invalid format");
39
+ if (params.cssSelector !== undefined)
40
+ throw new Error("browser.content: headless content does not support CSS selectors");
41
+ const tab = params.tabId === undefined
42
+ ? tabs.find((candidate) => candidate.active)
43
+ : tabs.find((candidate) => candidate.id === params.tabId);
44
+ if (tab?.content === undefined)
45
+ throw new Error("browser.content: no content supplied for tab");
46
+ return tab.content;
47
+ },
48
+ };
49
+ }
package/dist/cli.d.ts ADDED
@@ -0,0 +1 @@
1
+ export {};