Skip to content

Commit

Permalink
重新整理代码,简化命令,结束 #3
Browse files Browse the repository at this point in the history
  • Loading branch information
imfly committed Feb 24, 2016
1 parent 9c57ea5 commit bb44f94
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 46 deletions.
33 changes: 15 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Gitbook Summary
# Gitbook Summary

[![npm version](https://badge.fury.io/js/gitbook-summary.svg)](https://badge.fury.io/js/gitbook-summary)
[![Build Status](https://travis-ci.org/imfly/gitbook-summary.png?branch=master)](https://travis-ci.org/imfly/gitbook-summary)
Expand All @@ -7,32 +7,32 @@


A command line tool to generate a `SUMMARY.MD` from a folder。[Demo](http://imfly.github.io/how-to-create-self-publishing-platform) [中文文档](http://imfly.github.io/how-to-create-self-publishing-platform/3-%E5%A6%82%E4%BD%95%E6%89%93%E9%80%A0%E8%87%AA%E5%B7%B1%E7%9A%84%E5%B9%B3%E5%8F%B0%EF%BC%9F/2-Summary%E7%9A%84%E4%BD%BF%E7%94%A8.html)

## Features

- Generate `SUMMARY.md` by using a CLI with some options
- Generate `SUMMARY.md` by using a CLI with some options
- Setting with `book.json`
- Link `README.md` to the parent directory
- Only get '.md' files
- Order by alphabet or numbers
- ...

## CoC (Convention over Configuration)
## CoC (Convention over Configuration)

Source directory:

```
sources
├── 1-FirstChapter // The first chapter,format: {orderNumber or alphabet}-{chapterName}.md
├────── 1-FirstDocument.md
├────── 1-FirstDocument.md
├────── 5-SecondDocument.md // concentrating solely on the order, not the numbers.
├── 3-SecondChapter // Focus only on the order, not the numbers.
├────── 1-FirstDocumentOfSecondChapter.md
├────── 1-FirstDocumentOfSecondChapter.md
├────── 2-SecondDocumentOfSecondChapter.md
├── 7-ThirdChapter
├── 7-ThirdChapter
├── FourthChapter // May have no order
├── README.md // In addition to readme.md, not to put other markdown documents
└── book.json // Set up the book
├── README.md // In addition to readme.md, not to put other markdown documents
└── book.json // Set up the book
```

## Install
Expand All @@ -47,13 +47,13 @@ npm install -g gitbook-summary

```
$ cd /path/to/your/book/
$ book sm g
```
$ book sm
```

or, For example:

```
$ book sm g -r ../sailsjs-docs-gitbook/en -i 0home -u 'myApp' -c 'concepts, reference, userguides' -n "Sails.js 官方文档(中英合辑)"
$ book sm -r ../sailsjs-docs-gitbook/en -i 0home -u 'myApp' -c 'concepts, reference, userguides' -n "Sails.js 官方文档(中英合辑)"
```

2> Create a `book.json` in the book`s root folder
Expand All @@ -67,14 +67,14 @@ for example:
"outputfile": "test.md",
"catalog": "all", // or [chapter1,chapter2, ...]
"ignores": [],
"unchanged": [] // for example: ['myApp'] -> `myApp` not `My App`
"unchanged": [] // for example: ['myApp'] -> `myApp` not `My App`
}
```

then, you can do:

```
$ book sm g
$ book sm
```

You will get a `test.md` file:
Expand Down Expand Up @@ -103,10 +103,8 @@ npm test

## Todo

- Convert articals between Simplified and Traditional Chinese.
- Generate eBooks(html, pdf, etc) by extending `gitbook`;
- Publish to github pages, for example: http://imfly.github.io/sails-docs
- Merge to one page like a blog.
- Auto aggregate ebooks to website.

## Contribute

Expand All @@ -115,4 +113,3 @@ We love pull requests! You can `fork it` and commit a `pr`
## License

The MIT License

49 changes: 26 additions & 23 deletions bin/summary.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,43 +14,46 @@ function list(val) {

program
.version(pkg.version)
.option("-d, --debug", "enable verbose error")
.option("-r, --root [root]", "root folder, default is `.`")
.option("-n, --bookname [bookname]", "book name, default is `Your Book Name`.")
.option("-c, --catalog [catalog]", "catalog folders included book files, default is `all`.")
.option("-i, --ignores <ignores>", "ignore folders that be excluded, default is `[]`.", list)
.option("-i, --ignores [ignores]", "ignore folders that be excluded, default is `[]`.", list)
.option("-u, --unchanged [unchanged]", "unchanged catalog like `request.js`, default is `[]`.")
.option("-o, --outputfile [outputfile]", "output file, defaut is `./SUMMARY.md`");

program
.command("summary [g]")
.command("summary [cmd...]")
.alias("sm")
.description("generate a `SUMMARY.md` from a folder")
.description("Generate a `SUMMARY.md` from a folder")
.action(function(cmd) {
// fixme
// The `generate` command
if (_.isEqual(cmd, "g") || _.isEqual(cmd, "generate")) {
book.summary(program);
} else {
console.log(color.red("Error! Please add `g` or `generate` command, for example: `book sm g`."));
// generate `SUMMARY.md`
if (cmd.length >= 1) {
console.log(color.red('\nError! The sub commands "%s" has been deprecated, please read the follow messages:'), cmd)
program.help();
}else{
book.summary(program.opts());
}
});

// Todo
// program
// .command("convert")
// .alias("c")
// .action(function(cmd) {
// var options = program;
// todo
program
.command("convert")
.alias("cv")
.description("Todo: Convert articals between Simplified and Traditional Chinese.")
.action(function() {
// Convert TW to CN
convert.run(program.opts());
});

// // Convert TW to CN
// if (_.isEqual(cmd, "c") || _.isEqual(cmd, "convert")) {
// convert.run(options);
// }
// });
program
.command('*')
.description('Show error message.')
.action(function(env) {
console.log(color.red('\nError! Has no command "%s", please read the follow messages: '), env);
program.help();
});

// Parse and fallback to help if no args
// 没有参数时,直接显示帮助 Parse and fallback to help if no args
if (_.isEmpty(program.parse(process.argv).args) && process.argv.length === 2) {
// console.log(process.argv)
program.help();
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "gitbook-summary",
"version": "1.0.11",
"version": "1.0.14",
"description": "A CLI to generate a summary from a given folder.",
"homepage": "http://imfly.github.io/gitbook-summary/",
"main": "lib/index.js",
Expand Down
8 changes: 4 additions & 4 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ describe('Index.js', function() {
fs.remove(file, done);
});

it('should get a `SUMMARY.md` for `.` if has no options, for example: book sm g', function() {
it('should get a `SUMMARY.md` for `.` if has no options, for example: book sm', function() {
book.summary({});

// Fixme why can`t pass it using sync?
Expand All @@ -38,7 +38,7 @@ describe('Index.js', function() {

describe('should get a `SUMMARY.md`', function() {

it('given an option root, for example: book sm g -r root', function() {
it('given an option root, for example: book sm -r root', function() {
book.summary({
root: bookRoot
});
Expand All @@ -49,7 +49,7 @@ describe('Index.js', function() {
});
});

it('given an option bookname, for example: book sm g -n bookname', function() {
it('given an option bookname, for example: book sm -n bookname', function() {
var bookname = 'This is a test book';
book.summary({
root: bookRoot,
Expand All @@ -66,7 +66,7 @@ describe('Index.js', function() {
});
});

it('given an option ignores, for example: book sm g -i test', function() {
it('given an option ignores, for example: book sm -i test', function() {
var bookname = 'This book has no test';
book.summary({
root: bookRoot,
Expand Down

0 comments on commit bb44f94

Please sign in to comment.