mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-09-16 15:45:13 +00:00
Working loading of plugin
This commit is contained in:
@@ -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",
|
||||
|
||||
@@ -7,6 +7,8 @@
|
||||
* @return {Plugin}
|
||||
*/
|
||||
function createPlugin(onInitialState, onReduceState) {
|
||||
onReduceState = onReduceState || ((state, action) => state);
|
||||
|
||||
const plugin = {
|
||||
onInitialState,
|
||||
onReduceState
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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": {
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
# `gitbook-plugin`
|
||||
|
||||
CLI utility to build and test plugins.
|
||||
@@ -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",
|
||||
|
||||
@@ -1,13 +1,26 @@
|
||||
const program = require('commander');
|
||||
const pkg = require('../package.json');
|
||||
#! /usr/bin/env node
|
||||
|
||||
program.version(pkg.version)
|
||||
const program = require('commander');
|
||||
const path = require('path');
|
||||
const winston = require('winston');
|
||||
|
||||
const pkg = require('../package.json');
|
||||
const compile = require('./compile');
|
||||
|
||||
const resolve = (input => path.resolve(process.cwd(), input));
|
||||
|
||||
program.version(pkg.version);
|
||||
winston.cli();
|
||||
|
||||
program
|
||||
.command('build [plugin]')
|
||||
.description('build a plugin')
|
||||
.action(function(plugin, options) {
|
||||
|
||||
.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)
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
|
||||
@@ -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;
|
||||
@@ -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",
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user