Skip to content

Commit

Permalink
0.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
zalmoxisus committed Oct 6, 2015
0 parents commit 16d0045
Show file tree
Hide file tree
Showing 46 changed files with 1,017 additions and 0 deletions.
16 changes: 16 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"stage": 0,
"plugins": [
"react-transform"
],
"extra": {
"react-transform": [{
"target": "react-transform-webpack-hmr",
"imports": ["react"],
"locals": ["module"]
}, {
"target": "react-transform-catch-errors",
"imports": ["react", "redbox-react/dist/redbox"]
}]
}
}
4 changes: 4 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules
build
dev
webpack/replace
30 changes: 30 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"extends": "eslint-config-airbnb",
"globals": {
"chrome": true,
"__DEVELOPMENT__": true
},
"env": {
"browser": true,
"node": true
},
"rules": {
"react/jsx-uses-react": 2,
"react/jsx-uses-vars": 2,
"react/react-in-jsx-scope": 2,
"react/jsx-quotes": 0,
"block-scoped-var": 0,
"padded-blocks": 0,
"quotes": [ 1, "single" ],
"comma-style": [ 2, "last" ],
"eol-last": 0,
"no-unused-vars": 0,
"no-console": 0,
"func-names": 0,
"prefer-const": 0,
"comma-dangle": 0
},
"plugins": [
"react"
]
}
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
node_modules
npm-debug.log
.DS_Store
.idea/
build/
dev/
6 changes: 6 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
node_modules
npm-debug.log
.DS_Store

build/
dev/
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
language: node_js
node_js:
- "iojs"
22 changes: 22 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
The MIT License (MIT)

Copyright (c) 2015 Mihail Diordiev
Copyright (c) 2015 Jhen-Jie Hong

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
89 changes: 89 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
# Browser App and Extension Boilerplate using Redux Actions

Simple boilerplate and library for building Chrome apps and cross-browser extensions (support for Firefox and Safari will come later) that use Redux actions instead of messaging.

Redux states are synced between background, inject page, app window, extension popup and badge.

The developing is the same as for the web apps with React (optional) and Redux, just use the `src/app` boilerplate. If you need some extension or Chrome app customizations, use `src/browser/` boilerplates. A simple example will be injected on the bottom of `https://github.com/*` pages (change arrowURLs in `src/browser/extension/background/inject.js` and add to `permissions` in extension's manifest).

The example is edited from [Redux Counter example](https://github.com/rackt/redux/tree/master/examples/counter), based on [React Chrome Extension Boilerplate](https://github.com/jhen0409/react-chrome-extension-boilerplate).

## Included

- [react](https://github.com/facebook/react)
- [redux](https://github.com/rackt/redux)
- [react-redux](https://github.com/gaearon/react-redux)
- [redux-persist](https://github.com/rt2zz/redux-persist)
- [redux-devtools](https://github.com/gaearon/redux-devtools)
- [redux-logger](https://github.com/fcomb/redux-logger)
- [redbox-react](https://github.com/KeywordBrain/redbox-react)
- [react-chrome-extension-boilerplate](https://github.com/jhen0409/react-chrome-extension-boilerplate)
- [webpack](https://github.com/webpack/webpack)
- [react-transform-webpack-hmr](https://github.com/gaearon/react-transform-webpack-hmr)
- [react-transform-catch-errors](https://github.com/gaearon/react-transform-catch-errors)
- [babel](https://github.com/babel/babel)
- [babel-plugin-react-transform](https://github.com/gaearon/babel-plugin-react-transform)
- [gulp](https://github.com/gulpjs/gulp)

## Installation

```bash
# required node.js/io.js
# clone it
npm install
```

## Development

```bash
# build files to './dev'
# watch files change
# start WebpackDevServer
npm run dev
```

You can load unpacked extensions with `./dev`.

#### React/Flux hot reload

This boilerplate uses `Webpack` and `react-transform`, and use `Redux`. You can hot reload by editing related files of Popup & Window.

## Build extension

```bash
# build files to './build/extension'
npm run build:extension
```

## Build app

```bash
# build files to './build/app'
npm run build:app
```

## Build & Compress ZIP file

```bash
# compress extension's build folder to extension.zip
npm run compress:extension

# compress app's build folder to app.zip
npm run compress:app
```

## Load to Chrome

- [Load the extension](https://developer.chrome.com/extensions/getstarted#unpacked)
- [Launch your app](https://developer.chrome.com/apps/first_app#five)


## Roadmap

- [ ] Add tests (using [sinon-chrome](https://github.com/vitalets/sinon-chrome))
- [ ] Firefox extension (according to [wiki.mozilla.org/WebExtensions](https://wiki.mozilla.org/WebExtensions))
- [ ] Safari extension (based on [Chrome to Safari port](https://code.google.com/p/adblockforchrome/source/browse/trunk/port.js))

## LICENSE

[MIT](LICENSE)
140 changes: 140 additions & 0 deletions gulpfile.babel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
import fs from 'fs';
import gulp from 'gulp';
import gutil from 'gulp-util';
import jade from 'gulp-jade';
import rename from 'gulp-rename';
import zip from 'gulp-zip';
import webpack from 'webpack';
import WebpackDevServer from 'webpack-dev-server';
import devConfig from './webpack/dev.config';
import prodConfig from './webpack/prod.config';
import appConfig from './webpack/app.config';

const port = 3000;

/*
* common tasks
*/
gulp.task('replace-webpack-code', () => {
const replaceTasks = [ {
from: './webpack/replace/JsonpMainTemplate.runtime.js',
to: './node_modules/webpack/lib/JsonpMainTemplate.runtime.js'
}, {
from: './webpack/replace/log-apply-result.js',
to: './node_modules/webpack/hot/log-apply-result.js'
} ];
replaceTasks.forEach(task => fs.writeFileSync(task.to, fs.readFileSync(task.from)));
});

/*
* dev tasks
*/

gulp.task('webpack-dev-server', () => {
let myConfig = Object.create(devConfig);
new WebpackDevServer(webpack(myConfig), {
contentBase: `http://localhost:${port}`,
publicPath: myConfig.output.publicPath,
stats: {colors: true},
hot: true,
historyApiFallback: true
}).listen(port, 'localhost', (err) => {
if (err) {
throw new gutil.PluginError('webpack-dev-server', err);
}
gutil.log('[webpack-dev-server]', `listening at port ${port}`);
});
});

gulp.task('views:dev', () => {
gulp.src('./src/browser/views/*.jade')
.pipe(jade({
locals: { env: 'dev' }
}))
.pipe(gulp.dest('./dev'));
});

gulp.task('copy:dev', () => {
gulp.src('./src/browser/extension/manifest.dev.json')
.pipe(rename('manifest.json'))
.pipe(gulp.dest('./dev'));
gulp.src('./src/assets/**/*').pipe(gulp.dest('./dev'));
});

/*
* build tasks
*/

gulp.task('webpack:build:extension', (callback) => {
let myConfig = Object.create(prodConfig);
webpack(myConfig, (err, stats) => {
if (err) {
throw new gutil.PluginError('webpack:build', err);
}
gutil.log('[webpack:build]', stats.toString({ colors: true }));
callback();
});
});

gulp.task('webpack:build:app', (callback) => {
let myConfig = Object.create(appConfig);
webpack(myConfig, (err, stats) => {
if (err) {
throw new gutil.PluginError('webpack:build', err);
}
gutil.log('[webpack:build]', stats.toString({ colors: true }));
callback();
});
});

gulp.task('views:build:extension', () => {
gulp.src('./src/browser/views/*.jade')
.pipe(jade({
locals: { env: 'prod' }
}))
.pipe(gulp.dest('./build/extension'));
});

gulp.task('views:build:app', () => {
gulp.src('./src/browser/views/*.jade')
.pipe(jade({
locals: { env: 'prod' }
}))
.pipe(gulp.dest('./build/app'));
});

gulp.task('copy:build:extension', () => {
gulp.src('./src/browser/extension/manifest.prod.json')
.pipe(rename('manifest.json'))
.pipe(gulp.dest('./build/extension'));
gulp.src('./src/assets/**/*').pipe(gulp.dest('./build/extension'));
});

gulp.task('copy:build:app', () => {
gulp.src('./src/browser/chromeApp/manifest.json')
.pipe(rename('manifest.json'))
.pipe(gulp.dest('./build/app'));
gulp.src('./src/assets/**/*').pipe(gulp.dest('./build/app'));
});

/*
* compress task
*/

gulp.task('zip:extension', () => {
gulp.src('build/extension/*')
.pipe(zip('extension.zip'))
.pipe(gulp.dest('./build'));
});

gulp.task('zip:app', () => {
gulp.src('build/app/*')
.pipe(zip('app.zip'))
.pipe(gulp.dest('./build'));
});

gulp.task('default', ['replace-webpack-code', 'webpack-dev-server', 'views:dev', 'copy:dev']);
gulp.task('build:extension', ['replace-webpack-code', 'webpack:build:extension', 'views:build:extension', 'copy:build:extension']);
gulp.task('build:app', ['replace-webpack-code', 'webpack:build:app', 'views:build:app', 'copy:build:app']);
gulp.task('compress:extension', ['zip:extension']);
gulp.task('compress:app', ['zip:app']);
Loading

0 comments on commit 16d0045

Please sign in to comment.