Skip to content

Commit 08a9d20

Browse files
committed
add messagePassing class
1 parent 165466d commit 08a9d20

File tree

13 files changed

+3037
-2816
lines changed

13 files changed

+3037
-2816
lines changed

constants.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
11
const constants = {
22
appConfig: {
33
appName: "extension name",
4-
key: "" // put extension key here if required which would only be used development mode
4+
key:
5+
"-----BEGIN PUBLIC KEY-----\n" +
6+
"MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA3VymTQvpTgWpVbYeveQV\n" +
7+
"I2ZuyKZtHtzDqIWu4Og/ZjOEbu6eXPzvX57BmMv0sX79Y0EDRHkbQAgtWjgilCTE\n" +
8+
"uWqxCOLpLpkYs9Dz/iXymqbIaM6IbLZEp513uKMSTknU9V5eWFuNeOU8Ps/6rr35\n" +
9+
"chBpbVxeWawy5jLak03n5jFRCnOtkzoU9gkbbTQRykV2dfp+KP0UYn7Vox/17fCH\n" +
10+
"CHPG5oA/DvH60iokIhoUXe+5SCIFcdsJE/a7gvH7YGbDkC6+ENpmUK0dEIEJSHAh\n" +
11+
"vyLwCl4pmiIC/crpbLxlV5SPfAN+P3tiAUlS0M5U2f0Nf6AFayvazJslHKTarU3K\n" +
12+
"qQIDAQAB\n" +
13+
"-----END PUBLIC KEY-----\n"
514
}
615
};
716

package.json

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,21 @@
55
"main": "index.js",
66
"homepage": "https://fxnoob.github.io/chrome-extension-boilerplate",
77
"scripts": {
8-
"start": "webpack-dev-server --config ./webpack.config.js --mode development",
9-
"dev": "webpack --watch --progress --colors --config webpack.config.js --mode=development",
10-
"build": "webpack --progress --colors --config webpack.config.js --mode=production",
8+
"build:css": "tailwindcss build src/styles/style.css -o dist/style.css",
9+
"watch:css": "yarn build:css && chokidar 'src/styles/*.css' -c 'yarn build:css'",
10+
"watch:js": "webpack --watch --config webpack.config.js --mode=development",
11+
"build:js": "webpack --config webpack.config.js --mode=production",
12+
"rm": "rm -rf dist/",
13+
"start": "yarn dev",
14+
"dev": "concurrently --kill-others 'yarn watch:css' 'yarn watch:js'",
15+
"build": "yarn rm && concurrently 'yarn build:css' 'yarn build:js'",
1116
"jsdoc": "jsdoc src -r",
1217
"deploy_jsdoc": "yarn jsdoc && gh-pages -d out",
13-
"prettier_check_src": "prettier --check src/**/*.{js,jsx}",
14-
"prettier_check_popup": "prettier --check src/**/*.{js,jsx}",
15-
"prettier_check_option": "prettier --check src/**/*.{js,jsx}",
16-
"prettier_check_content": "prettier --check src/**/*.{js,jsx}",
17-
"lint": "eslint",
18-
"lint:fix": "eslint --fix"
18+
"test": "yarn build"
1919
},
2020
"husky": {
2121
"hooks": {
22-
"pre-commit": "npm run build"
22+
"pre-commit": "yarn build"
2323
}
2424
},
2525
"keywords": [],
@@ -33,10 +33,19 @@
3333
"@babel/plugin-transform-runtime": "^7.5.5",
3434
"@babel/preset-env": "^7.5.5",
3535
"@babel/preset-react": "^7.0.0",
36+
"babel-eslint": "^10.1.0",
3637
"babel-loader": "^8.0.6",
38+
"chokidar": "^3.5.1",
39+
"chokidar-cli": "^2.1.0",
40+
"concurrently": "^5.3.0",
3741
"copy-webpack-plugin": "^5.0.4",
3842
"css-loader": "^4.3.0",
3943
"dotenv": "^8.2.0",
44+
"esbuild-loader": "^2.4.0",
45+
"eslint": "^7.6.0",
46+
"eslint-loader": "^4.0.2",
47+
"eslint-plugin-react": "^7.20.5",
48+
"eslint-watch": "^7.0.0",
4049
"file-loader": "^4.2.0",
4150
"gh-pages": "^2.1.1",
4251
"husky": "^3.0.9",
@@ -48,20 +57,17 @@
4857
"style-loader": "^1.2.1",
4958
"webpack": "^4.39.1",
5059
"webpack-cli": "^3.3.6",
51-
"babel-eslint": "^10.1.0",
52-
"eslint": "^7.6.0",
53-
"eslint-loader": "^4.0.2",
54-
"eslint-plugin-react": "^7.20.5",
55-
"eslint-watch": "^7.0.0",
5660
"webpack-dev-server": "^3.7.2"
5761
},
5862
"dependencies": {
5963
"@babel/polyfill": "^7.4.4",
6064
"@babel/runtime": "^7.5.5",
6165
"@material-ui/core": "^4.3.3",
6266
"@material-ui/icons": "^4.2.1",
67+
"@tailwindcss/ui": "^0.5.0",
6368
"react": "^16.8.6",
6469
"react-dom": "^16.8.6",
65-
"react-frame-component": "^4.1.3"
70+
"react-frame-component": "^4.1.3",
71+
"tailwindcss": "^1.8.3"
6672
}
6773
}

scripts/transform.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const constants = require("../constants");
2+
const pkg = require("../package.json");
23
// options: webpack configs
34
const manifestTransform = (content, path, options) => {
45
const { mode } = options;
@@ -9,6 +10,7 @@ const manifestTransform = (content, path, options) => {
910
if (mode == "development") {
1011
manifest.key = constants.appConfig.key;
1112
}
13+
manifest.version = pkg.version;
1214
// pretty print to JSON with two spaces
1315
return JSON.stringify(manifest, null, 2);
1416
};

src/app/manifest.json

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,35 @@
11
{
2-
"name": "chrome-extension-boilerplate",
3-
"version": "0.0.1",
4-
"manifest_version": 2,
5-
"description": "description",
6-
"icons": {
7-
"16": "images/icon-16.png",
8-
"128": "images/icon-128.png"
9-
},
2+
"name": "__MSG_appName__",
3+
"description": "__MSG_appDescription__",
4+
"version": "0.0.0",
5+
"permissions": [
6+
"storage",
7+
"activeTab",
8+
"<all_urls>"
9+
],
1010
"background": {
1111
"scripts": ["background.bundle.js"]
1212
},
13-
"permissions": ["storage", "tabs", "*://*/*"],
1413
"browser_action": {
15-
"default_icon": {
16-
"19": "images/icon-19.png",
17-
"38": "images/icon-38.png"
18-
},
19-
"default_title": "default title",
14+
"default_title": "Chrome extension",
15+
"default_icon": "images/icon-128.png",
2016
"default_popup": "popup.html"
2117
},
18+
"icons": {
19+
"16": "images/icon-16.png",
20+
"19": "images/icon-19.png",
21+
"38": "images/icon-38.png",
22+
"128": "images/icon-128.png"
23+
},
24+
"content_scripts": [
25+
{
26+
"matches": ["<all_urls>"],
27+
"match_about_blank": true,
28+
"all_frames": true,
29+
"js": ["content_script.bundle.js"],
30+
"run_at": "document_end"
31+
}
32+
],
33+
"manifest_version": 2,
2234
"content_security_policy": "script-src 'self' 'unsafe-eval'; object-src 'self'"
2335
}

src/background.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import "@babel/polyfill";
2-
import chromeService from './services/chrome';
2+
import chromeService, { message } from "./services/chromeService";
3+
import Routes from "./routes";
34

45
let AppInitState = 0; // it means app is off on startup
56

@@ -13,14 +14,15 @@ class Main {
1314
this.init();
1415
}
1516

16-
init = () => {
17+
init = async () => {
1718
this.popUpClickSetup();
18-
}
19+
await Routes(message);
20+
};
1921

2022
popUpClickSetup() {
2123
chrome.browserAction.onClicked.addListener(() => {
2224
if (this.toggleApp()) {
23-
chromeService.openHelpPage('');
25+
chromeService.openHelpPage("");
2426
} else {
2527
this.stopApp();
2628
}

src/content-scripts/App.jsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
1+
/* eslint-disable no-console */
12
import React from "react";
23
import ReactDOM from "react-dom";
34
import Index from "../components/Demo";
5+
import { message } from "../services/chromeService";
46

7+
message.sendMessage("/echo", {}, response => {
8+
console.log(" message from /echo", response);
9+
});
510
const Element = document.createElement("div");
611
Element.setAttribute("id", "dfghbnjmERHJKFGHNMVBNMFBNMbmvvxnbdgf");
712
document.body.appendChild(Element);

src/popup-page/popup.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<!DOCTYPE html>
22
<html>
33
<head>
4-
<style></style>
4+
<link rel="stylesheet" href="/style.css" />
55
</head>
66
<body>
77
<div id="app"></div>

src/routes.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/* eslint-disable no-unused-vars */
2+
/**
3+
*
4+
* Message object is the Messaging Passing Class Object
5+
* which contains methods suitable for message passing apis.
6+
*
7+
* */
8+
export default message => {
9+
message.on("/echo", async (req, res, actions) => {
10+
// eslint-disable-next-line no-console
11+
console.log("message logged");
12+
res({ response: "hello world" });
13+
});
14+
};

0 commit comments

Comments
 (0)