summaryrefslogtreecommitdiffstats
path: root/packages
diff options
context:
space:
mode:
authorSamy Pesse <samypesse@gmail.com>2016-09-20 19:19:01 +0200
committerSamy Pesse <samypesse@gmail.com>2016-09-20 19:19:01 +0200
commitced0be930dd86bc204cab5b4e3a1cd83aed68ccf (patch)
treeede7dcb971554be669e9b4e9db42899c52fed20f /packages
parent6d58a90613802b1e65cbf8c027093a1868119781 (diff)
downloadgitbook-ced0be930dd86bc204cab5b4e3a1cd83aed68ccf.zip
gitbook-ced0be930dd86bc204cab5b4e3a1cd83aed68ccf.tar.gz
gitbook-ced0be930dd86bc204cab5b4e3a1cd83aed68ccf.tar.bz2
Working loading of plugin
Diffstat (limited to 'packages')
-rw-r--r--packages/gitbook-core/package.json3
-rw-r--r--packages/gitbook-core/src/createPlugin.js2
-rw-r--r--packages/gitbook-core/src/createStore.js6
-rw-r--r--packages/gitbook-plugin-sharing/package.json42
-rw-r--r--packages/gitbook-plugin-theme-default/package.json13
-rw-r--r--packages/gitbook-plugin/README.md3
-rw-r--r--packages/gitbook-plugin/package.json6
-rw-r--r--packages/gitbook-plugin/src/cli.js23
-rw-r--r--packages/gitbook-plugin/src/compile.js39
-rw-r--r--packages/gitbook/package.json4
-rw-r--r--packages/gitbook/src/browser/loadPlugins.js8
-rw-r--r--packages/gitbook/src/output/website/onPage.js4
12 files changed, 102 insertions, 51 deletions
diff --git a/packages/gitbook-core/package.json b/packages/gitbook-core/package.json
index c75f05d..387a610 100644
--- a/packages/gitbook-core/package.json
+++ b/packages/gitbook-core/package.json
@@ -24,7 +24,8 @@
"scripts": {
"dist-lib": "rm -rf lib/ && babel -d lib/ src/",
"dist-standalone": "browserify -r ./lib/index.js:gitbook-core -r react -r react-dom ./lib/index.js | uglifyjs -c > gitbook.core.min.js",
- "prepublish": "npm run dist-lib && npm run dist-standalone"
+ "dist": "npm run dist-lib && npm run dist-standalone",
+ "prepublish": "npm run dist"
},
"repository": {
"type": "git",
diff --git a/packages/gitbook-core/src/createPlugin.js b/packages/gitbook-core/src/createPlugin.js
index c26d745..d00c99d 100644
--- a/packages/gitbook-core/src/createPlugin.js
+++ b/packages/gitbook-core/src/createPlugin.js
@@ -7,6 +7,8 @@
* @return {Plugin}
*/
function createPlugin(onInitialState, onReduceState) {
+ onReduceState = onReduceState || ((state, action) => state);
+
const plugin = {
onInitialState,
onReduceState
diff --git a/packages/gitbook-core/src/createStore.js b/packages/gitbook-core/src/createStore.js
index c13f219..4873190 100644
--- a/packages/gitbook-core/src/createStore.js
+++ b/packages/gitbook-core/src/createStore.js
@@ -13,12 +13,12 @@ const reducers = require('./reducers');
*/
function createStore(plugins, initialState) {
const pluginReducers = plugins.map(plugin => plugin.onReduceState);
+ console.log(pluginReducers);
const reducer = Redux.compose(reducers, ...pluginReducers);
-
const store = Redux.createStore(
- reducer,
+ reducers,
initialState,
- Redux.applyMiddleware(ReduxThunk)
+ Redux.compose(Redux.applyMiddleware(ReduxThunk))
);
// Initialize the plugins
diff --git a/packages/gitbook-plugin-sharing/package.json b/packages/gitbook-plugin-sharing/package.json
index 0ca8dc5..134acb8 100644
--- a/packages/gitbook-plugin-sharing/package.json
+++ b/packages/gitbook-plugin-sharing/package.json
@@ -4,7 +4,11 @@
"main": "index.js",
"version": "1.0.2",
"dependencies": {
-
+ "gitbook-core": "^0.0.0",
+ "react": "^15.3.1"
+ },
+ "devDependencies": {
+ "gitbook-plugin": "*"
},
"engines": {
"gitbook": ">=3.0.0"
@@ -20,36 +24,12 @@
},
"gitbook": {
"properties": {
- "facebook": {
- "type": "boolean",
- "default": true,
- "title": "Facebook"
- },
- "twitter": {
- "type": "boolean",
- "default": true,
- "title": "Twitter"
- },
- "google": {
- "type": "boolean",
- "default": false,
- "title": "Google"
- },
- "weibo": {
- "type": "boolean",
- "default": false,
- "description": "Weibo"
- },
- "instapaper": {
- "type": "boolean",
- "default": false,
- "description": "Instapaper"
- },
- "vk": {
- "type": "boolean",
- "default": false,
- "description": "VK"
- },
+ "facebook": { "type": "boolean", "default": true, "title": "Facebook" },
+ "twitter": { "type": "boolean", "default": true, "title": "Twitter" },
+ "google": { "type": "boolean", "default": false, "title": "Google" },
+ "weibo": { "type": "boolean", "default": false, "description": "Weibo" },
+ "instapaper": { "type": "boolean", "default": false, "description": "Instapaper" },
+ "vk": { "type": "boolean", "default": false, "description": "VK" },
"all": {
"type": "array",
"items": {
diff --git a/packages/gitbook-plugin-theme-default/package.json b/packages/gitbook-plugin-theme-default/package.json
index 5ee288b..42ff1b6 100644
--- a/packages/gitbook-plugin-theme-default/package.json
+++ b/packages/gitbook-plugin-theme-default/package.json
@@ -2,12 +2,21 @@
"name": "gitbook-plugin-theme-default",
"description": "Default theme for GitBook",
"main": "./index.js",
- "browser": "./src/index.js",
+ "browser": "./assets/theme.js",
"version": "1.0.5",
"engines": {
"gitbook": ">=3.0.0"
},
- "dependencies": {},
+ "dependencies": {
+ "gitbook-core": "^0.0.0",
+ "react": "^15.3.1"
+ },
+ "devDependencies": {
+ "gitbook-plugin": "*"
+ },
+ "scripts": {
+ "prepublish": "gitbook-plugin build ./src/index.js ./assets/theme.js"
+ },
"repository": {
"type": "git",
"url": "https://github.com/GitbookIO/gitbook.git"
diff --git a/packages/gitbook-plugin/README.md b/packages/gitbook-plugin/README.md
new file mode 100644
index 0000000..a6ded9e
--- /dev/null
+++ b/packages/gitbook-plugin/README.md
@@ -0,0 +1,3 @@
+# `gitbook-plugin`
+
+CLI utility to build and test plugins.
diff --git a/packages/gitbook-plugin/package.json b/packages/gitbook-plugin/package.json
index e8b6983..2dcadbb 100644
--- a/packages/gitbook-plugin/package.json
+++ b/packages/gitbook-plugin/package.json
@@ -4,9 +4,13 @@
"description": "CLI for compiling and testing plugins",
"main": "./lib/index.js",
"dependencies": {
+ "babel-preset-es2015": "^6.14.0",
+ "babel-preset-react": "^6.11.1",
"babelify": "^7.3.0",
"browserify": "^13.1.0",
- "commander": "^2.9.0"
+ "commander": "^2.9.0",
+ "q": "^1.4.1",
+ "winston": "^2.2.0"
},
"devDependencies": {
"babel-cli": "^6.14.0",
diff --git a/packages/gitbook-plugin/src/cli.js b/packages/gitbook-plugin/src/cli.js
index e1f201b..20ceed5 100644
--- a/packages/gitbook-plugin/src/cli.js
+++ b/packages/gitbook-plugin/src/cli.js
@@ -1,13 +1,26 @@
+#! /usr/bin/env node
+
const program = require('commander');
+const path = require('path');
+const winston = require('winston');
+
const pkg = require('../package.json');
+const compile = require('./compile');
-program.version(pkg.version)
+const resolve = (input => path.resolve(process.cwd(), input));
-program
- .command('build [plugin]')
- .description('build a plugin')
- .action(function(plugin, options) {
+program.version(pkg.version);
+winston.cli();
+program
+ .command('build [input] [output]')
+ .description('build a browser plugin')
+ .action(function(input, output, options) {
+ compile(resolve(input), resolve(output))
+ .then(
+ () => winston.info('Plugin compiled successfully'),
+ (err) => winston.error('Error: ', err)
+ );
});
diff --git a/packages/gitbook-plugin/src/compile.js b/packages/gitbook-plugin/src/compile.js
new file mode 100644
index 0000000..e7179e5
--- /dev/null
+++ b/packages/gitbook-plugin/src/compile.js
@@ -0,0 +1,39 @@
+const fs = require('fs');
+const Promise = require('q');
+const browserify = require('browserify');
+const babelify = require('babelify');
+
+/**
+ * Compile a plugin to work with "gitbook-core" in the browser.
+ * @param {String} inputFile
+ * @param {String} outputFile
+ * @return {Promise}
+ */
+function compilePlugin(inputFile, outputFile) {
+ const d = Promise.defer();
+ const b = browserify({
+ standalone: 'GitBookPlugin'
+ });
+
+ b.add(inputFile);
+ b.external('react');
+ b.external('react-dom');
+ b.external('gitbook-core');
+ b.transform(babelify, {
+ presets: [
+ require('babel-preset-es2015'),
+ require('babel-preset-react')
+ ]
+ });
+
+ const output = fs.createWriteStream(outputFile);
+
+ b.bundle()
+ .pipe(output)
+ .on('error', (err) => d.reject(err))
+ .on('end', () => d.resolve());
+
+ return d.promise;
+}
+
+module.exports = compilePlugin;
diff --git a/packages/gitbook/package.json b/packages/gitbook/package.json
index 0c30285..8b6551e 100644
--- a/packages/gitbook/package.json
+++ b/packages/gitbook/package.json
@@ -51,8 +51,8 @@
"omit-keys": "^0.1.0",
"open": "0.0.5",
"q": "1.4.1",
- "react": "^15.3.1",
- "react-dom": "^15.3.1",
+ "react": "^15.3.2",
+ "react-dom": "^15.3.2",
"react-redux": "^4.4.5",
"read-installed": "^4.0.3",
"redux": "^3.5.2",
diff --git a/packages/gitbook/src/browser/loadPlugins.js b/packages/gitbook/src/browser/loadPlugins.js
index ba5381c..0f26aae 100644
--- a/packages/gitbook/src/browser/loadPlugins.js
+++ b/packages/gitbook/src/browser/loadPlugins.js
@@ -2,11 +2,12 @@ const path = require('path');
/**
* Load all browser plugins
- * @param {List<Plugin>} plugins
- * @return {List}
+ * @param {OrderedMap<Plugin>} plugins
+ * @return {Array}
*/
function loadPlugins(plugins) {
return plugins
+ .valueSeq()
.filter(plugin => plugin.getPackage().has('browser'))
.map(plugin => {
const browserFile = path.resolve(
@@ -15,7 +16,8 @@ function loadPlugins(plugins) {
);
return require(browserFile);
- });
+ })
+ .toArray();
}
module.exports = loadPlugins;
diff --git a/packages/gitbook/src/output/website/onPage.js b/packages/gitbook/src/output/website/onPage.js
index 27bc0b2..7e93080 100644
--- a/packages/gitbook/src/output/website/onPage.js
+++ b/packages/gitbook/src/output/website/onPage.js
@@ -37,10 +37,8 @@ function onPage(output, page) {
// We should probabbly move it to "template" or a "site" namespace
// context.basePath = basePath;
- console.log('render page');
-
// Load the plugins
- const browserPlugins = []; //loadBrowserPlugins(plugins);
+ const browserPlugins = loadBrowserPlugins(plugins);
// Render the theme
const html = render(browserPlugins, initialState);