Skip to content

Commit

Permalink
Merge pull request #12 from InfiniteLibrary/builder
Browse files Browse the repository at this point in the history
Package the app
  • Loading branch information
ekmartin authored Feb 12, 2017
2 parents 288627c + a99b27b commit 07494c9
Show file tree
Hide file tree
Showing 35 changed files with 68 additions and 110 deletions.
1 change: 1 addition & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"import/no-unresolved": ["error", { "ignore": ["electron"] }],
"import/no-extraneous-dependencies": "off",
"import/no-dynamic-require": "off",
"jsx-a11y/no-static-element-interactions": "off",
"no-console": "off",
"no-plusplus": "off",
"no-underscore-dangle": "off",
Expand Down
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
*.png binary
*.ico binary
*.icns binary
*.ttf binary
11 changes: 0 additions & 11 deletions app/app.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,6 @@
integrity="sha384-wvfXpqpZZVQGK6TAh5PVlGOfQNHSoD2xbE+QkPxCAFlNEevoEH3Sl0sibVcOQVnN"
crossorigin="anonymous"
>
<script>
(function() {
if (!process.env.HOT) {
const link = document.createElement('link');
link.rel = 'stylesheet';
link.href = './dist/style.css';
// HACK: Writing the script path should be done with webpack
document.getElementsByTagName('head')[0].appendChild(link);
}
}());
</script>
</head>
<body>
<div id="root"></div>
Expand Down
Binary file modified app/app.icns
Binary file not shown.
File renamed without changes.
5 changes: 2 additions & 3 deletions app/components/BookDetails/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ import './BookDetails.scss';
export default class BookDetails extends Component {
render() {
const book = this.props.book;
console.log(this.props.book);

const bookSummary = {
__html: book.summary || 'No Description Available.' };
__html: book.summary || 'No Description Available.'
};

return (
<div className="book-details">
Expand Down
14 changes: 8 additions & 6 deletions app/components/Epub/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,6 @@ class Epub extends Component {
});
}

componentWillUnmount() {
this.rendition.off('keyup', this.keyListener);
document.removeEventListener('keyup', this.keyListener, false);
}

componentWillUpdate(nextProps) {
if (nextProps.location !== this.props.location) {
this.rendition.display(nextProps.location);
Expand All @@ -90,8 +85,15 @@ class Epub extends Component {
}
}

componentWillUnmount() {
this.rendition.off('keyup', this.keyListener);
document.removeEventListener('keyup', this.keyListener, false);
}

display(what) {
this.rendition && this.rendition.display(what);
if (this.rendition) {
this.rendition.display(what);
}
}

render() {
Expand Down
48 changes: 22 additions & 26 deletions app/components/Reader/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,20 @@ class Reader extends Component {
constructor(props) {
super(props);
this.handleReady = this.handleReady.bind(this);
this.handleNavReady = this.handleNavReady.bind(this);
}

_navigationReady(nav) {
state = {
isLoading: true,
nav: [],
location: 0
};

handleNavReady(nav) {
this.setState({ ...this.state, nav });
}

_onNavClick(item) {
handleNavClick(item) {
this.setState({ ...this.state, location: item.href });
}

Expand All @@ -24,24 +31,13 @@ class Reader extends Component {
}

tocToggle() {
let navMenu = document.getElementById('toc-nav');
const navMenu = document.getElementById('toc-nav');

if (navMenu.classList.contains('is-visible')) {
navMenu.classList.remove('is-visible');
} else {
navMenu.classList.add('is-visible');
}

}

state = {
isLoading: true,
nav: [],
location : 0
};

handleReady() {
this.setState({ ...this.state, isLoading: false });
}

render() {
Expand All @@ -53,14 +49,15 @@ class Reader extends Component {
<ul>
<h2>Table of Contents</h2>
{
this.state.nav.map((item, index) =>
<li>
<a key={`navitem_${index}`}
className="reader__toc__item"
onClick={() => {
this._onNavClick(item)
this.tocToggle()
}}>
this.state.nav.map(item =>
<li key={item.id}>
<a
className="reader__toc__item"
onClick={() => {
this.handleNavClick(item);
this.tocToggle();
}}
>
{item.label}
</a>
</li>
Expand All @@ -82,7 +79,7 @@ class Reader extends Component {
</div>
</div>
<div className="nav-right">
<a className="nav-item" onClick={() => { this.tocToggle()}}>
<a className="nav-item" onClick={() => { this.tocToggle(); }}>
<span className="icon">
<i className="fa fa-navicon" />
</span>
Expand All @@ -92,9 +89,8 @@ class Reader extends Component {
{this.state.isLoading && <Loader />}
<Epub
src={`${getStreamHost()}/${book.id}/${download}/`}
onNavigationReady={ this._navigationReady.bind(this) }
onLocationChanged={(location) => console.log(location)}
onReady={ this.handleReady.bind(this) }
onNavigationReady={this.handleNavReady}
onReady={this.handleReady}
location={this.state.location}
/>
</div>
Expand Down
4 changes: 2 additions & 2 deletions app/containers/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import React, { Component } from 'react';

let booksPath;
if (process.env.NODE_ENV === 'development') {
booksPath = path.resolve('resources', 'books.json');
booksPath = path.resolve('app', 'books.json');
} else {
booksPath = path.resolve(process.resourcesPath, 'books.json');
booksPath = path.resolve(process.resourcesPath, 'app.asar', 'books.json');
}

export default class App extends Component {
Expand Down
8 changes: 4 additions & 4 deletions app/package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "electron-react-boilerplate",
"productName": "electron-react-boilerplate",
"version": "1.0.0",
"description": "Electron application boilerplate based on React, React Router, Webpack, React Hot Loader for rapid application development",
"name": "infinite-electron",
"productName": "Infinite Library Reader",
"version": "0.1.0",
"description": "An Electron based reader for Project Gutenberg books",
"main": "./main.js",
"author": {
"name": "Infinite Library",
Expand Down
1 change: 0 additions & 1 deletion app/static/epub.css
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
}

.book-theme p {
font-weight: 300;
font-size: 18px;
line-height: 1.5;
}
Expand Down
Binary file removed app/static/fonts/Merriweather-Black.ttf
Binary file not shown.
Binary file modified app/static/fonts/Merriweather-Bold.ttf
Binary file not shown.
Binary file removed app/static/fonts/Merriweather-Italic.ttf
Binary file not shown.
Binary file modified app/static/fonts/Merriweather-Light.ttf
Binary file not shown.
Binary file modified app/static/fonts/Merriweather-Regular.ttf
Binary file not shown.
21 changes: 14 additions & 7 deletions app/streamer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,26 @@ import express from 'express';
import StreamZip from 'node-stream-zip';
import path from 'path';
import portfinder from 'portfinder';
import fs from 'mz/fs';
import fs from 'fs';
import pify from 'pify';
import fetch from 'node-fetch';
import mime from 'mime';
import Url from 'url';

const access = pify(fs.access);

class Streamer {
constructor(repo, port) {
this.app = express();
this.repo = repo || __dirname;
this.port = port;
this.server = undefined;
this._zips = {};
this.staticPath = path.resolve(__dirname, '..', 'static');
if (process.env.NODE_ENV === 'development') {
this.staticPath = path.resolve(__dirname, '..', 'static');
} else {
this.staticPath = path.resolve(process.resourcesPath, 'app.asar', 'static');
}
}

start() {
Expand All @@ -28,11 +35,11 @@ class Streamer {
.then(this.open)
.then((zip) => this.get(zip, req.params.asset))
.then((stream) => {
let asset = req.params.asset;
let path = Url.parse(asset).pathname || '';
let mimeType = mime.lookup(path);
const asset = req.params.asset;
const assetPath = Url.parse(asset).pathname || '';
const mimeType = mime.lookup(assetPath);
res.contentType(mimeType);
stream.pipe(res)
stream.pipe(res);
})
.catch((err) => {
console.error(err);
Expand Down Expand Up @@ -73,7 +80,7 @@ class Streamer {

resolveEpub(id, url) {
const bookPath = path.join(this.repo, id);
return fs.access(bookPath, fs.constants.R_OK)
return access(bookPath, fs.constants.R_OK)
.then(
() => bookPath,
// If the book doesn't exist, download it:
Expand Down
14 changes: 9 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"main": "main.js",
"scripts": {
"test": "npm run lint",
"lint": "eslint --cache --format=node_modules/eslint-formatter-pretty .",
"lint": "eslint --cache --ignore-path .gitignore --format=node_modules/eslint-formatter-pretty .",
"lint-fix": "npm run lint -- --fix",
"hot-server": "cross-env NODE_ENV=development node --max_old_space_size=2096 -r babel-register server.js",
"build-main": "cross-env NODE_ENV=production node -r babel-register ./node_modules/webpack/bin/webpack --config webpack.config.electron.js --progress --profile --colors",
Expand All @@ -23,8 +23,8 @@
},
"browserslist": "electron 1.4",
"build": {
"productName": "ElectronReact",
"appId": "org.develar.ElectronReact",
"productName": "Infinity Library Reader",
"appId": "org.infinity.reader",
"category": "public.app-category.tools",
"dmg": {
"contents": [
Expand All @@ -44,10 +44,13 @@
"files": [
"dist/",
"node_modules/",
"static/",
"app.html",
"main.js",
"main.js.map",
"package.json"
"books.json",
"package.json",
"*.png"
],
"win": {
"target": "nsis"
Expand Down Expand Up @@ -139,10 +142,11 @@
"epubjs": "beta",
"font-awesome": "^4.7.0",
"lunr": "^0.7.2",
"mime": "^1.3.4",
"mkdirp": "^0.5.1",
"mz": "^2.6.0",
"node-fetch": "^1.6.3",
"node-stream-zip": "^1.3.7",
"pify": "^2.3.0",
"portfinder": "^1.0.13",
"react": "^15.4.2",
"react-dom": "^15.4.2",
Expand Down
Binary file modified resources/icon.icns
Binary file not shown.
Binary file modified resources/icon.ico
Binary file not shown.
Binary file modified resources/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed resources/icons/1024x1024.png
Binary file not shown.
Binary file modified resources/icons/128x128.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified resources/icons/16x16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified resources/icons/24x24.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified resources/icons/256x256.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified resources/icons/32x32.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified resources/icons/48x48.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified resources/icons/512x512.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified resources/icons/64x64.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified resources/icons/96x96.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions webpack.config.base.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ export default validate({
test: /\.css$/,
loader: 'style!css'
},
{
test: /\.scss$/,
loader: 'style!css!sass'
},
{
test: /\.jsx?$/,
loaders: ['babel-loader'],
Expand Down
1 change: 0 additions & 1 deletion webpack.config.development.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ export default validate(merge(baseConfig, {

module: {
loaders: [
{ test: /\.scss$/, loader: 'style!css!sass' },
{ test: /\.woff(\?v=\d+\.\d+\.\d+)?$/, loader: 'url?limit=10000&mimetype=application/font-woff' },
{ test: /\.woff2(\?v=\d+\.\d+\.\d+)?$/, loader: 'url?limit=10000&mimetype=application/font-woff' },
{ test: /\.ttf(\?v=\d+\.\d+\.\d+)?$/, loader: 'url?limit=10000&mimetype=application/octet-stream' },
Expand Down
21 changes: 1 addition & 20 deletions webpack.config.production.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import path from 'path';
import webpack from 'webpack';
import validate from 'webpack-validator';
import ExtractTextPlugin from 'extract-text-webpack-plugin';
import merge from 'webpack-merge';
import HtmlWebpackPlugin from 'html-webpack-plugin';
import BabiliPlugin from 'babili-webpack-plugin';
Expand All @@ -23,28 +22,12 @@ export default validate(merge(baseConfig, {

module: {
loaders: [
// Extract all .global.css to style.css as is
{
test: /\.scss$/,
loader: ExtractTextPlugin.extract(
'style-loader',
'css-loader',
'sass-loader'
)
},

// Fonts
{ test: /\.woff(\?v=\d+\.\d+\.\d+)?$/, loader: 'url?limit=10000&mimetype=application/font-woff' },
{ test: /\.woff2(\?v=\d+\.\d+\.\d+)?$/, loader: 'url?limit=10000&mimetype=application/font-woff' },
{ test: /\.ttf(\?v=\d+\.\d+\.\d+)?$/, loader: 'url?limit=10000&mimetype=application/octet-stream' },
{ test: /\.eot(\?v=\d+\.\d+\.\d+)?$/, loader: 'file' },
{ test: /\.svg(\?v=\d+\.\d+\.\d+)?$/, loader: 'url?limit=10000&mimetype=image/svg+xml' },

// Images
{
test: /\.(?:ico|gif|png|jpg|jpeg|webp)$/,
loader: 'url-loader'
}
{ test: /\.svg(\?v=\d+\.\d+\.\d+)?$/, loader: 'url?limit=10000&mimetype=image/svg+xml' }
]
},

Expand Down Expand Up @@ -76,8 +59,6 @@ export default validate(merge(baseConfig, {
deadcode: false,
}),

new ExtractTextPlugin('style.css', { allChunks: true }),

/**
* Dynamically generate index.html page
*/
Expand Down
Loading

0 comments on commit 07494c9

Please sign in to comment.