Skip to content

Commit

Permalink
Merge pull request #19 from normal-computing/extract_lib
Browse files Browse the repository at this point in the history
feat: extract web-wand-lib
  • Loading branch information
lynchee-owo authored Feb 28, 2024
2 parents cd7e5c1 + 2560174 commit 65d3053
Show file tree
Hide file tree
Showing 16 changed files with 280 additions and 162 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

# build
/dist
/dist-lib

# etc
.DS_Store
Expand Down
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
"description": "chrome extension",
"repository": {
"type": "git",
"url": "https://github.com/normal-computing/wingmate"
"url": "https://github.com/normal-computing/web-wand"
},
"scripts": {
"build": "tsc --noEmit && vite build",
"build:lib": "rollup --config rollup.lib.config.js && cp package.lib.json dist-lib/package.json",
"build:firefox": "tsc --noEmit && cross-env __FIREFOX__=true vite build",
"build:watch": "cross-env __DEV__=true vite build -w --mode development",
"build:firefox:watch": "cross-env __DEV__=true __FIREFOX__=true vite build -w --mode development",
Expand Down Expand Up @@ -78,6 +79,8 @@
"npm-run-all": "4.1.5",
"prettier": "3.1.0",
"rollup": "4.3.0",
"rollup-plugin-dts": "^6.1.0",
"rollup-plugin-esbuild": "^6.1.1",
"sass": "1.69.5",
"ts-jest": "29.1.1",
"ts-loader": "9.5.0",
Expand Down
9 changes: 9 additions & 0 deletions package.lib.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "web-wand-lib",
"version": "2.0.0-beta-1",
"description": "Helper library for Web Wand",
"repository": {
"type": "git",
"url": "https://github.com/normal-computing/web-wand"
}
}
74 changes: 67 additions & 7 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

44 changes: 44 additions & 0 deletions rollup.lib.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import dts from "rollup-plugin-dts";
import esbuild from "rollup-plugin-esbuild";
import { resolve, dirname } from "path";
import { fileURLToPath } from "url";

const __dirname = dirname(fileURLToPath(import.meta.url));

const OUT_DIR = "dist-lib";
const rootDir = resolve(__dirname);
const srcDir = resolve(rootDir, "src");
const pagesDir = resolve(srcDir, "pages");

function createConfigPair(name, path) {
return [
{
input: path,
plugins: [esbuild()],
output: [
{
file: `${OUT_DIR}/${name}.js`,
format: "cjs",
sourcemap: true,
exports: "auto",
},
],
},
{
input: path,
plugins: [dts()],
output: {
file: `${OUT_DIR}/${name}.d.ts`,
format: "es",
},
},
];
}

export default [
...createConfigPair(
"domOperations",
resolve(pagesDir, "content", "domOperations.ts"),
),
...createConfigPair("helpers", resolve(srcDir, "helpers", "index.ts")),
];
2 changes: 1 addition & 1 deletion src/common/CopyButton.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from "react";
import { CopyIcon } from "@chakra-ui/icons";
import { useToast } from "@chakra-ui/react";
import { callRPC } from "../helpers/pageRPC";
import { callRPC } from "../helpers/rpc/pageRPC";

export default function CopyButton(props: { text: string }) {
const toast = useToast();
Expand Down
6 changes: 6 additions & 0 deletions src/helpers/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export { DomActions } from "./rpc/domActions";
export { callRPC, callRPCWithTab } from "./rpc/pageRPC";
export { attachDebugger, detachDebugger } from "./chromeDebugger";
import performAction from "./rpc/performAction";
export { performAction };
export type { Action } from "./rpc/performAction";
4 changes: 2 additions & 2 deletions src/helpers/domActions.ts → src/helpers/rpc/domActions.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { TAXY_ELEMENT_SELECTOR } from "../constants";
import { TAXY_ELEMENT_SELECTOR } from "../../constants";
import { callRPCWithTab } from "./pageRPC";
import { scrollScriptString } from "./runtimeFunctionStrings";
import { sleep, waitFor, waitTillStable } from "./utils";
import { sleep, waitFor, waitTillStable } from "../utils";

const DEFAULT_INTERVAL = 500;
const DEFAULT_TIMEOUT = 0;
Expand Down
4 changes: 2 additions & 2 deletions src/helpers/pageRPC.ts → src/helpers/rpc/pageRPC.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { sleep } from "./utils";
import type { RPCMethods } from "../pages/content/injected";
import { sleep } from "../utils";
import type { RPCMethods } from "../../pages/content/domOperations";

Check failure on line 2 in src/helpers/rpc/pageRPC.ts

View workflow job for this annotation

GitHub Actions / build

Cannot find module '../../pages/content/domOperations' or its corresponding type declarations.

// Call these functions to execute code in the content script

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { DomActions } from "./domActions";
import {
WEB_WAND_LABEL_ATTRIBUTE_NAME,
VISIBLE_TEXT_ATTRIBUTE_NAME,
} from "../constants";
} from "../../constants";

function getSelector(selectorName: string): string {
return `[${WEB_WAND_LABEL_ATTRIBUTE_NAME}="${selectorName}"]`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
function scrollIntoViewFunction() {
// @ts-expect-error this is run in the browser context
this.scrollIntoView({
block: 'center',
inline: 'center',
block: "center",
inline: "center",
// behavior: 'smooth',
});
}
Expand Down
Loading

0 comments on commit 65d3053

Please sign in to comment.