Update readme, set up icon

This commit is contained in:
Dima Gerasimov 2019-01-06 22:15:53 +00:00
parent 68ed274df8
commit bd092ba60f
11 changed files with 83 additions and 111 deletions

136
README.md
View file

@ -1,117 +1,53 @@
Build status: [![CircleCI](https://circleci.com/gh/karlicoss/grasp.svg?style=svg)](https://circleci.com/gh/karlicoss/grasp)
# TODO add some docs..
Grasp is an extension for Chrome (Firefox support is in progress), which adds a button/keybinding to capture current page title and url,
possibly selected text, additional comments or tags and send it into your [Org Mode](https://orgmode.org/) file.
# Chrome Extension Webpack Boilerplate
# Requirements
* `pip3 install --user hug` for [Hug](http://www.hug.rest/) HTTP server.
A basic foundation boilerplate for rich Chrome Extensions using [Webpack](https://webpack.github.io/) to help you write modular and modern Javascript code, load CSS easily and [automatic reload the browser on code changes](https://webpack.github.io/docs/webpack-dev-server.html#automatic-refresh).
# Running
1. Install server counterpart as systemd service: `server/setup`.
2. Install chrome extension and configure hotkeys
## Developing a new extension
_I'll assume that you already read the [Webpack docs](https://webpack.github.io/docs) and the [Chrome Extension](https://developer.chrome.com/extensions/getstarted) docs._
That's it! Currently port `12212` is hardcoded, but it will be configurable.
# Motivation
Why use org-capture? Well, it's hard to explain, maybe some other time... However if you do know you want to use it instead/alongside your browser bookmarks, by default
you don't have much choice and have to copy everything manually. For an average Org Mode user it's a torture.
1. Check if your Node.js version is >= 6.
2. Clone the repository.
3. Install [yarn](https://yarnpkg.com/lang/en/docs/install/).
4. Run `yarn`.
5. Change the package's name and description on `package.json`.
6. Change the name of your extension on `src/manifest.json`.
7. Run `npm run start`
8. Load your extension on Chrome following:
1. Access `chrome://extensions/`
2. Check `Developer mode`
3. Click on `Load unpacked extension`
4. Select the `build` folder.
8. Have fun.
For a while, I used [the only](https://github.com/sprig/org-capture-extension) Chrome extension for that (as for January 2019). However, it relies on setting up MIME
handler which is quite flaky for many people. What is more, capturing via org template requires always running emacs daemon, which might be too much for some people.
But the worst thing is if capturing fails, you have to way of knowing about it. After losing few days of captured stuff due to MIME handler mysteriously not working,
I got fed up and figured it's time to implement something more reliable.
## Structure
All your extension's development code must be placed in `src` folder, including the extension manifest.
My approach still requires a running server, but it's a simple python script which simply appends a text entry to a text file. The backend always responds back and in case anything
fails, you get a notification.
The boilerplate is already prepared to have a popup, a options page and a background page. You can easily customize this.
Extra collateral benefit is that you can potentially add anything as a backend, e.g. you might be more of a Markdown or Todo.txt fan (let me know if you are interested in that!).
Each page has its own [assets package defined](https://github.com/samuelsimoes/chrome-extension-webpack-boilerplate/blob/master/webpack.config.js#L16-L20). So, to code on popup you must start your code on `src/js/popup.js`, for example.
# Potentional improvements
* due to server counterpart, one could even run it elsewhere, not necessarily on localhost
* also see [todos](./TODO.org)
You must use the [ES6 modules](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import) to a better code organization. The boilerplate is already prepared to that and [here you have a little example](https://github.com/samuelsimoes/chrome-extension-webpack-boilerplate/blob/master/src/js/popup.js#L2-L4).
# Building extension
The most up-to-date instructions should be in [CI config](./.circleci/config.yml).
## Webpack auto-reload and HRM
To make your workflow much more efficient this boilerplate uses the [webpack server](https://webpack.github.io/docs/webpack-dev-server.html) to development (started with `npm run server`) with auto reload feature that reloads the browser automatically every time that you save some file o your editor.
You're gonna need `npm` for building extension.
You can run the dev mode on other port if you want. Just specify the env var `port` like this:
npm install
npm run build
```
$ PORT=6002 npm run start
```
After that you can find the extension in `build` directory and 'Load unpacked' if necessary. There is also Flow and Eslint set up.
## Content Scripts
# Permissions used
* `notifications` for showing error notification
* `activeTab` for requesting url, title and selected text
* `http://*/capture` for talking with backend. This is a bit too broad, but don't think there is a stricter way of doing that? Let me know if there is.
Although this boilerplate uses the webpack dev server, it's also prepared to write all your bundles files on the disk at every code change, so you can point, on your extension manifest, to your bundles that you want to use as [content scripts](https://developer.chrome.com/extensions/content_scripts), but you need to exclude these entry points from hot reloading [(why?)](https://github.com/samuelsimoes/chrome-extension-webpack-boilerplate/issues/4#issuecomment-261788690). To do so you need to expose which entry points are content scripts on the `webpack.config.js` using the `chromeExtensionBoilerplate -> notHotReload` config. Look the example below.
* `content_security_policy` needed for webpack.
Let's say that you want use the `myContentScript` entry point as content script, so on your `webpack.config.js` you will configure the entry point and exclude it from hot reloading, like this:
```js
{
entry: {
myContentScript: "./src/js/myContentScript.js"
},
chromeExtensionBoilerplate: {
notHotReload: ["myContentScript"]
}
}
```
and on your `src/manifest.json`:
```json
{
"content_scripts": [
{
"matches": ["https://www.google.com/*"],
"js": ["myContentScript.bundle.js"]
}
]
}
```
## Packing
After the development of your extension run the command
```
$ NODE_ENV=production npm run build
```
Now, the content of `build` folder will be the extension ready to be submitted to the Chrome Web Store. Just take a look at the [official guide](https://developer.chrome.com/webstore/publish) to more infos about publishing.
## Secrets
If you are developing an extension that talks with some API you probably are using different keys for testing and production. Is a good practice you not commit your secret keys and expose to anyone that have access to the repository.
To this task this boilerplate import the file `./secrets.<THE-NODE_ENV>.js` on your modules through the module named as `secrets`, so you can do things like this:
_./secrets.development.js_
```js
export default { key: "123" };
```
_./src/popup.js_
```js
import secrets from "secrets";
ApiCall({ key: secrets.key });
```
:point_right: The files with name `secrets.*.js` already are ignored on the repository.
## With React.js
:bulb: If you want use [React.js](https://facebook.github.io/react/) with this boilerplate, check the **[react branch](https://github.com/samuelsimoes/chrome-extension-webpack-boilerplate/tree/react)**.
## Contributing
1. **Please!! Do not create a pull request without an issue before discussing the problem.**
2. On your PR make sure that you are following the current codebase style.
3. Your PR must be single purpose. Resolve just one problem on your PR.
4. Make sure to commit in the same style that we are committing until now on the project.
-------------
Samuel Simões ~ [@samuelsimoes](https://twitter.com/samuelsimoes) ~ [Blog](http://blog.samuelsimoes.com/)
# Credits
* Icon made by <a href="https://www.freepik.com/" title="Freepik">Freepik</a> from <a href="https://www.flaticon.com/" title="Flaticon">www.flaticon.com</a>, licensed by <a href="http://creativecommons.org/licenses/by/3.0/" title="Creative Commons BY 3.0" target="_blank">CC 3.0 BY</a>
* [Original Org Capture extension](https://github.com/sprig/org-capture-extension)
* [Boilerplate for Webpack Chrome extension](https://github.com/samuelsimoes/chrome-extension-webpack-boilerplate))

View file

@ -1,29 +1,50 @@
* TODO [#B] release somewhere? not sure if necessary
* TODO [#B] docs on using
* TODO [#A] adjust permissions... I guess gonna have to make it include /capture endpoint?
* START [#B] release somewhere? not sure if necessary
* TODO [#B] get rid of kython, run ci for python too?
* TODO [#B] doesn't look like hotkey working unless you manually rebind.. wtf?
* TODO [#C] motivation
** TODO the benefit is that you can also add anything as a backend, e.g. you might be more of markdown fan or todo.txt
* TODO [#C] how to test it? try on different pages?
* TODO [#C] some sort of append logic? e.g. don't dump immediately and add as subitems?
* TODO [#C] make notification configurable or only in case of errors
* TODO [#D] do not minfy for dev
* TODO not sure, maybe extension press should be default? control it via option?
* TODO or, add menu to extension?
* TODO [#C] or, add menu to extension?
* TODO unsafe-eval in content security policy??
* TODO make manifest templated so we don't have to hardcode actions
* TODO
## Packing
After the development of your extension run the command
```
$ NODE_ENV=production npm run build
```
Now, the content of `build` folder will be the extension ready to be submitted to the Chrome Web Store. Just take a look at the [official guide](https://developer.chrome.com/webstore/publish) to more infos about publishing.
* DONE [#A] move server to a separate folder, systemd install script
CLOSED: [2019-01-05 Sat 14:38]
* DONE [#A] entering additional information and tags
CLOSED: [2019-01-06 Sun 20:41]
* DONE [#B] docs on using
CLOSED: [2019-01-06 Sun 21:39]
* DONE [#B] circleci?
CLOSED: [2019-01-06 Sun 13:50]
* DONE [#C] motivation
CLOSED: [2019-01-06 Sun 21:35]
** DONE the benefit is that you can also add anything as a backend, e.g. you might be more of markdown fan or todo.txt
CLOSED: [2019-01-06 Sun 21:35]
* DONE [#D] nicer manifest?
CLOSED: [2019-01-06 Sun 13:43]

View file

@ -1,6 +1,6 @@
{
"name": "grasp-extension",
"version": "0.3.1",
"version": "0.3.2",
"description": "A reliable way of capturing web pages and content",
"scripts": {
"build": "webpack --progress --profile --colors",

9
publish Executable file
View file

@ -0,0 +1,9 @@
#!/bin/bash
set -eu
VERSION="$(git tag --points-at)"
[[ -n $VERSION ]]
npm run build
zip "grasp-$VERSION.zip" build/

View file

@ -3,6 +3,6 @@ set -eux
cd "$(dirname "$0")"
PORT=8090
PORT=12212
hug -p "$PORT" -f server.py

Binary file not shown.

Before

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 KiB

BIN
src/img/unicorn.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

View file

@ -3,7 +3,7 @@
const capture_endpoint = 'capture';
function port(): string {
return "8090";
return "12212";
}
// none means do not use tags

View file

@ -1,5 +1,8 @@
{
"name": "Grasp Extension",
"icons": {
"128": "unicorn.png"
},
"options_page": "options.html",
"background": {
"page": "background.html"
@ -11,7 +14,7 @@
"permissions": [
"notifications",
"activeTab",
"http://*/"
"http://*/capture"
],
"commands": {
"capture-simple": {

View file

@ -65,6 +65,9 @@ var options = {
plugins: [
// clean the build folder
new CleanWebpackPlugin(["build/*"]),
new CopyWebpackPlugin([
{ from: 'src/img/unicorn.png' },
]),
// expose and write the allowed env vars on the compiled bundle
new webpack.DefinePlugin({
"process.env.NODE_ENV": JSON.stringify(env.NODE_ENV)