mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-09-21 01:53:26 +00:00
Working loading of plugin
This commit is contained in:
@@ -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;
|
||||
Reference in New Issue
Block a user