Skip to content

Commit

Permalink
added extension plugin boilerplate
Browse files Browse the repository at this point in the history
  • Loading branch information
corevo committed Jan 22, 2018
1 parent 4702a13 commit 6e1e7ff
Show file tree
Hide file tree
Showing 10 changed files with 6,080 additions and 0 deletions.
14 changes: 14 additions & 0 deletions packages/extension-boilerplate/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"presets": ["env"],
"plugins": [
"transform-decorators-legacy",
"transform-decorators",
"transform-object-rest-spread",
["transform-class-properties", { "loose": true }],
["babel-plugin-transform-runtime", {
"helpers": false,
"polyfill": false,
"regenerator": true
}]
]
}
56 changes: 56 additions & 0 deletions packages/extension-boilerplate/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
module.exports = {
"env": {
"browser": true,
"node": true,
"es6": true,
"jest": true,
"webextensions": true
},
"extends": ["eslint:recommended"],
"parser": "babel-eslint",
"parserOptions": {
"ecmaFeatures": {
"experimentalObjectRestSpread": true
},
"sourceType": "module"
},
"plugins": [
"class-property"
],
"rules": {
"no-trailing-spaces": [
"error"
],
"no-multiple-empty-lines": [
"error",
{ "max": 2, "maxEOF": 1 }
],
"eol-last": [
"error",
"always"
],
"comma-dangle": [
"error",
"never"
],
"indent": [
"error",
2,
{ "SwitchCase": 1 }
],
"linebreak-style": [
"error",
"unix"
],
"semi": [
"error",
"always"
],
"no-console": [
0
],
"no-var": [
"error"
]
}
};
8 changes: 8 additions & 0 deletions packages/extension-boilerplate/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
node_modules
_MACOSX/
.DS_Store
build
yarn-error.log
dist
.web-extension-id
*.log
47 changes: 47 additions & 0 deletions packages/extension-boilerplate/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
"name": "selenium-ide-extension-boilerplate",
"version": "0.0.0",
"repository": "git@github.com:SeleniumHQ/selenium-ide.git",
"license": "Apache-2.0",
"private": true,
"scripts": {
"build": "webpack",
"build:prod": "rm -rf build && env NODE_ENV=production yarn build",
"test": "jest",
"lint": "eslint webpack.config.babel.js src/ --ext .js --ext .jsx"
},
"jest": {
"testMatch": [
"**/src/**/__test?(s)__/**/*.js?(x)"
]
},
"devDependencies": {
"babel-core": "^6.26.0",
"babel-eslint": "^8.2.1",
"babel-jest": "^22.0.4",
"babel-loader": "^7.1.2",
"babel-plugin-transform-class-properties": "^6.24.1",
"babel-plugin-transform-decorators": "^6.24.1",
"babel-plugin-transform-decorators-legacy": "^1.3.4",
"babel-plugin-transform-object-rest-spread": "^6.26.0",
"babel-plugin-transform-runtime": "^6.23.0",
"babel-preset-env": "^1.6.0",
"copy-webpack-plugin": "^4.0.1",
"css-loader": "^0.28.7",
"eslint": "^4.15.0",
"eslint-plugin-class-property": "^1.1.0",
"eslint-plugin-jest": "^21.6.1",
"extract-text-webpack-plugin": "^3.0.0",
"file-loader": "^0.11.2",
"html-webpack-plugin": "^2.30.1",
"jest": "^22.0.5",
"postcss-flexbugs-fixes": "^3.2.0",
"postcss-loader": "^2.0.6",
"style-loader": "^0.18.2",
"url-loader": "^0.5.9",
"webpack": "^3.5.6"
},
"dependencies": {
"webextension-polyfill": "https://github.com/corevo/webextension-polyfill#2cc27453b501e4426eb6741943fbb4041c0d18f5"
}
}
49 changes: 49 additions & 0 deletions packages/extension-boilerplate/src/background/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Licensed to the Software Freedom Conservancy (SFC) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The SFC licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

import browser from "webextension-polyfill";

browser.runtime.sendMessage(process.env.SIDE_ID, {
uri: "/register",
verb: "post",
payload: {
name: "Selenium IDE plugin",
version: "1.0.0",
commands: [
{
id: "successfulCommand",
name: "successful command"
},
{
id: "failCommand",
name: "failed command"
}
]
}
}).catch(console.error);

browser.runtime.onMessageExternal.addListener((message, sender, sendResponse) => {
if (message.action === "execute") {
switch (event.data.command) {
case "successfulCommand":
sendResponse(true);
break;
case "failCommand":
sendResponse({ error: "Some failure has occurred" });
}
}
});
19 changes: 19 additions & 0 deletions packages/extension-boilerplate/src/content/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Licensed to the Software Freedom Conservancy (SFC) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The SFC licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

// Put content script here
console.log("Hello from content script");
Empty file.
25 changes: 25 additions & 0 deletions packages/extension-boilerplate/src/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"description": "A boilerplate for Selenium IDE plugins",
"manifest_version": 2,
"name": "Selenium IDE plugin",
"version": "1.0.0.0",
"version_name": "1.0.0",
"homepage_url": "https://github.com/SeleniumHQ/selenium-ide/tree/master/packages/extension-boilerplate",
"permissions": [],
"content_security_policy": "script-src 'self'; object-src 'self'",
"externally_connectable": {
"ids": ["*"]
},
"content_scripts": [
{
"matches": ["<all_urls>"],
"js": ["assets/content.js"],
"match_about_blank": true,
"all_frames": true
}
],
"background":
{
"scripts": ["assets/background.js"]
}
}
156 changes: 156 additions & 0 deletions packages/extension-boilerplate/webpack.config.babel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
// Licensed to the Software Freedom Conservancy (SFC) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The SFC licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

import path from "path";
import webpack from "webpack";
import ExtractTextPlugin from "extract-text-webpack-plugin";
import CopyWebpackPlugin from "copy-webpack-plugin";
import autoprefixer from "autoprefixer";

const isProduction = process.env.NODE_ENV === "production";

export default {
context: path.resolve(__dirname, "src"),
devtool: isProduction ? "source-map" : false,
entry: {
content: ["./content"],
background: ["./background"]
},
output: {
path: path.resolve(__dirname, "build/assets"),
filename: "[name].js",
publicPath: "/assets/",
libraryTarget: "umd"
},
resolve: {
extensions: [".js", ".jsx", ".json"]
},
module: {
rules: [
{
// "oneOf" will traverse all following loaders until one will
// match the requirements. When no loader matches it will fall
// back to the "file" loader at the end of the loader list.
oneOf: [
// "url" loader works just like "file" loader but it also embeds
// assets smaller than specified size as data URLs to avoid requests.
{
test: [/\.bmp$/, /\.gif$/, /\.jpe?g$/, /\.png$/],
loader: "url-loader",
options: {
limit: 10000,
name: "media/[name].[hash:8].[ext]"
}
},
// Process JS with Babel.
{
test: /\.(jsx?)$/,
include: [
path.resolve(__dirname, "src")
],
use: [
{
loader: "babel-loader",
options: {
compact: true
}
}
]
},
// Process css
{
test: /\.css$/,
loader: [
require.resolve("style-loader"),
{
loader: require.resolve("css-loader"),
options: {
importLoaders: 1
}
},
{
loader: require.resolve("postcss-loader"),
options: {
// Necessary for external CSS imports to work
// https://github.com/facebookincubator/create-react-app/issues/2677
ident: "postcss",
plugins: () => [
require("postcss-flexbugs-fixes"),
autoprefixer({
browsers: [
">1%",
"last 4 versions",
"Firefox ESR",
"not ie < 9" // React doesn't support IE8 anyway
],
flexbox: "no-2009"
})
]
}
}
]
// Note: this won't work without `new ExtractTextPlugin()` in `plugins`.
},
// "file" loader makes sure assets end up in the `build` folder.
// When you `import` an asset, you get its filename.
// This loader don't uses a "test" so it will catch all modules
// that fall through the other loaders.
{
loader: "file-loader",
// Exclude `js` files to keep "css" loader working as it injects
// it's runtime that would otherwise processed through "file" loader.
// Also exclude `html` and `json` extensions so they get processed
// by webpacks internal loaders.
exclude: [/\.jsx?$/, /\.html$/, /\.json$/],
options: {
name: "media/[name].[hash:8].[ext]"
}
}
// ** STOP ** Are you adding a new loader?
// Make sure to add the new loader(s) before the "file" loader.
]
}
]
},
plugins: [
new webpack.NamedModulesPlugin(),
// Copy non-umd assets to vendor
new CopyWebpackPlugin([
{ from: "manifest.json", to: "../" },
{ from: "icons", to: "../icons" }
]),
// Makes some environment variables available to the JS code, for example:
// if (process.env.NODE_ENV === 'production') { ... }. See `./env.js`.
// It is absolutely essential that NODE_ENV was set to production here.
new webpack.DefinePlugin({
"process.env": {
"NODE_ENV": JSON.stringify(process.env.NODE_ENV),
"SIDE_ID": JSON.stringify(process.env.SIDE_ID)
}
}),
// Note: this won't work without ExtractTextPlugin.extract(..) in `loaders`.
new ExtractTextPlugin({
filename: "css/[name].[hash:8].css"
}),
// Moment.js is an extremely popular library that bundles large locale files
// by default due to how Webpack interprets its code. This is a practical
// solution that requires the user to opt into importing specific locales.
// https://github.com/jmblog/how-to-optimize-momentjs-with-webpack
// You can remove this if you don't use Moment.js:
new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/)
]
};
Loading

0 comments on commit 6e1e7ff

Please sign in to comment.