Skip to content

Commit

Permalink
Merge pull request #2 from mizunashi-mana/add-examples
Browse files Browse the repository at this point in the history
Add some examples
  • Loading branch information
Mizunashi Mana committed Oct 5, 2016
2 parents 69b6ed6 + 41eda68 commit 8fc6d43
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 19 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

# for Example
/example/_book/
/example/book.*
!/example/book.json

# for NPM
node_modules/
Expand Down
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ install:
- npm install gitbook@$GITBOOK_VERSION
script:
- npm test
- npm run example
- npm run coverage
after_script:
- npm install -g istanbul-coveralls
Expand Down
5 changes: 3 additions & 2 deletions example/book.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"title": "Example Documentation",
"plugins": ["anchors"]
"title": "Example Documentation",
"description": "Example of gulp-gitbook plugin",
"plugins": ["anchors"]
}
40 changes: 36 additions & 4 deletions example/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,47 @@
var gulp = require('gulp');
var gulpGitbook = require('..');

var runSequence = require('run-sequence');

/**
* Simple example of GitBook
*/
gulp.task('basic', function (cb) {
gulpGitbook('.', cb);
});

gulp.task('default', [
'basic'
], function () {
console.log('All tasks completed successfully.');
/**
* Generate PDF example
*/
gulp.task('pdf', function (cb) {
gulpGitbook.pdf('.', cb);
});

/**
* Generate EPUB example
*/
gulp.task('epub', function (cb) {
gulpGitbook.epub('.', cb);
});

/**
* Without install task example
*/
gulp.task('noinstall', function (cb) {
gulpGitbook('.', {
noInstall: true
}, cb);
});

gulp.task('default', function (cb) {
runSequence(
'basic',
'pdf',
'epub',
'noinstall',
function () {
console.log('All tasks completed successfully');
cb();
}
);
});
28 changes: 16 additions & 12 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,10 @@ var pluginError = function (message) {
return GulpUtil.PluginError(PLUGIN_NAME, message);
};

var gulpGitbook = function (book, options, callback) {
options = validateOptions(book, options, callback);

var _gulpGitbook = function (options) {
var p = Promise.resolve();

if (options.noInstall) {
if (!options.noInstall) {
p = p.then(function () {
return gitbookExec('install', [
options.book
Expand Down Expand Up @@ -141,31 +139,36 @@ var gulpGitbook = function (book, options, callback) {
});
};

var gulpGitbook = function (book, options, callback) {
options = validateOptions(book, options, callback);
return _gulpGitbook(options);
};

var gulpGitbookWebsite = function (book, options, callback) {
options = extend({}, options);
options = validateOptions(book, options, callback);
options.format = 'website';
return gulpGitbook(book, options, callback);
return _gulpGitbook(options);
};
gulpGitbook.website = gulpGitbookWebsite;

var gulpGitbookPdf = function (book, options, callback) {
options = extend({}, options);
options = validateOptions(book, options, callback);
options.format = 'pdf';
return gulpGitbook(book, options, callback);
return _gulpGitbook(options);
};
gulpGitbook.pdf = gulpGitbookPdf;

var gulpGitbookEpub = function (book, options, callback) {
options = extend({}, options);
options = validateOptions(book, options, callback);
options.format = 'epub';
return gulpGitbook(book, options, callback);
return _gulpGitbook(options);
};
gulpGitbook.epub = gulpGitbookEpub;

var gulpGitbookMobi = function (book, options, callback) {
options = extend({}, options);
options = validateOptions(book, options, callback);
options.format = 'mobi';
return gulpGitbook(book, options, callback);
return _gulpGitbook(options);
};
gulpGitbook.mobi = gulpGitbookMobi;

Expand Down Expand Up @@ -225,6 +228,7 @@ module.exports = gulpGitbook;

if (process.env.GULPGITBOOK_TEST_ENV) {
module.exports._private = {
_gulpGitbook: _gulpGitbook,
promiseCallback: promiseCallback,
isNullable: isNullable,
validateOptions: validateOptions,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
"testonly": "mocha --require ./test/index.js test/**/*.test.js",
"pretest": "npm run lint",
"test": "npm run testonly",
"posttest": "npm run example",
"example": "gulp --gulpfile=example/config.js",
"coverage": "istanbul cover _mocha -- --require ./test/index.js"
},
Expand Down Expand Up @@ -50,6 +49,7 @@
"gulp": "^3.9.1",
"istanbul": "^0.4.5",
"mocha": "^3.1.0",
"run-sequence": "^1.2.2",
"sinon": "^1.17.6",
"sinon-chai": "^2.8.0"
},
Expand Down

0 comments on commit 8fc6d43

Please sign in to comment.