Skip to content

Commit 7cfbacd

Browse files
committed
first commit
0 parents  commit 7cfbacd

14 files changed

+283
-0
lines changed

.eslintrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"extends": ["vue"]
3+
}

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules
2+
yarn.lock
3+
*.log

.travis.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
sudo: false
2+
language: node_js
3+
node_js: stable

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2016 cinwell.li
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# docsify-cli
2+
[![Build Status](https://travis-ci.org/QingWei-Li/docsify-cli.svg?branch=master)](https://travis-ci.org/QingWei-Li/docsify-cli)
3+
[![npm](https://img.shields.io/npm/v/docsify-cli.svg)](https://www.npmjs.com/package/docsify-cli)
4+
5+
> docsify cli - A magical documentation generator.
6+
7+
## Screenshots
8+
![](https://cloud.githubusercontent.com/assets/7565692/20603335/10bf80a0-b29c-11e6-93bb-5c3187f76edd.gif)
9+
10+
## Installation
11+
```shell
12+
npm i docsify-cli -g
13+
# yarn global add docsify-cli
14+
```
15+
16+
17+
## Usage
18+
19+
### init - create a docs
20+
```shell
21+
docsify init [path]
22+
```
23+
24+
#### options
25+
- `-l --local` Copy `docsify` to docs path, default use `unpkg.com` cdn
26+
- `-t --theme` Choose theme, default `vue.css`
27+
28+
### serve - run serve to preview
29+
```shell
30+
docsify serve [path]
31+
```
32+
33+
- `- --port` Listen port, default 3000
34+
35+
## License
36+
MIT

bin/docsify

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/usr/bin/env node
2+
3+
var program = require('commander')
4+
var run = require('../src')
5+
6+
program
7+
.version(require('../package.json').version)
8+
9+
program
10+
.command('init [path .]')
11+
.description('create a new docs')
12+
.option('-l, --local', 'use local vendor', false)
13+
.option('-t, --theme [vue|buble]', 'theme file, default vue.css', 'vue')
14+
.action(run.init)
15+
16+
program
17+
.command('serve [path .]')
18+
.description('run serve to preview')
19+
.option('-p, --port [port 3000]', 'listen port', 3000)
20+
.action(run.serve)
21+
22+
program.parse(process.argv)
23+
24+
if (!program.args.length) program.help()

docs/404.html

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>Document</title>
6+
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
7+
<link rel="stylesheet" href="//unpkg.com/docsify/themes/vue.css">
8+
</head>
9+
<body>
10+
<div id="app"></div>
11+
</body>
12+
<script src="//unpkg.com/docsify/lib/docsify.pack.min.js"></script>
13+
</html>

docs/README.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# docsify-cli
2+
[![Build Status](https://travis-ci.org/QingWei-Li/docsify-cli.svg?branch=master)](https://travis-ci.org/QingWei-Li/docsify-cli)
3+
[![npm](https://img.shields.io/npm/v/docsify-cli.svg)](https://www.npmjs.com/package/docsify-cli)
4+
5+
> docsify cli - A magical documentation generator.
6+
7+
## Screenshots
8+
![](https://cloud.githubusercontent.com/assets/7565692/20603335/10bf80a0-b29c-11e6-93bb-5c3187f76edd.gif)
9+
10+
## Installation
11+
```shell
12+
npm i docsify-cli -g
13+
# yarn global add docsify-cli
14+
```
15+
16+
17+
## Usage
18+
19+
### init - create a docs
20+
```shell
21+
docsify init [path]
22+
```
23+
24+
#### options
25+
- `-l --local` Copy `docsify` to docs path, default use `unpkg.com` cdn
26+
- `-t --theme` Choose theme, default `vue.css`
27+
28+
### serve - run serve to preview
29+
```shell
30+
docsify serve [path]
31+
```
32+
33+
- `- --port` Listen port, default 3000
34+
35+
## License
36+
MIT

media/demo.gif

416 KB
Loading

package.json

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
{
2+
"name": "docsify-cli",
3+
"version": "0.0.0",
4+
"description": "docsify cli - A magical documentation generator.",
5+
"main": "bin/docsify",
6+
"bin": {
7+
"docsify": "bin/docsify"
8+
},
9+
"files": [
10+
"bin"
11+
],
12+
"scripts": {
13+
"test": "eslint src"
14+
},
15+
"engines": {
16+
"node": ">= 4"
17+
},
18+
"keywords": [
19+
"docsify",
20+
"doc",
21+
"docs",
22+
"documentation",
23+
"creator",
24+
"generator",
25+
"cli"
26+
],
27+
"author": "qingwei-li <cinwell.li@gmail.com> (https://github.com/QingWei-Li)",
28+
"homepage": "https://github.com/QingWei-Li/docsify-cli",
29+
"repository": {
30+
"type": "git",
31+
"url": "https://github.com/QingWei-Li/docsify-cli.git"
32+
},
33+
"license": "MIT",
34+
"dependencies": {
35+
"commander": "^2.9.0",
36+
"cp-file": "^4.1.0",
37+
"docsify": "^0.0.5",
38+
"serve-static": "^1.11.1"
39+
},
40+
"devDependencies": {
41+
"eslint": "^3.10.2",
42+
"eslint-config-vue": "^2.0.1",
43+
"eslint-plugin-vue": "^1.0.0"
44+
}
45+
}

src/index.js

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
var fs = require('fs')
2+
var http = require('http')
3+
var resolve = require('path').resolve
4+
var cp = require('cp-file').sync
5+
var serveStatic = require('serve-static')
6+
7+
var GREEN_OPEN = '\u001B[32m'
8+
var GREEN_CLOSE = '\u001B[39m'
9+
10+
var cwd = function (path) {
11+
return resolve(process.cwd(), path)
12+
}
13+
var pwd = function (path) {
14+
return resolve(__dirname, path)
15+
}
16+
var exist = function (path) {
17+
if (fs.existsSync(path)) {
18+
return path
19+
}
20+
return undefined
21+
}
22+
var replace = function (file, tpl, replace) {
23+
fs.writeFileSync(file, fs.readFileSync(file).toString().replace(tpl, replace), 'utf-8')
24+
}
25+
26+
exports.init = function (path, option) {
27+
path = path || '.'
28+
var msg = `\nCreate succeed! Please run\n
29+
> ${GREEN_OPEN}docsify serve ${path}${GREEN_CLOSE}\n`
30+
31+
path = cwd(path)
32+
var target = function (file) {
33+
return resolve(path, file)
34+
}
35+
var readme = exist(cwd('README.md')) || pwd('template/README.md')
36+
var main = pwd('template/404.html')
37+
38+
if (option.local) {
39+
main = pwd('template/404-local.html')
40+
41+
var vendor = exist(cwd('node_modules/docsify')) || pwd('../node_modules/docsify')
42+
43+
cp(resolve(vendor, 'lib/docsify.pack.min.js'), target('vendor/docsify.js'))
44+
cp(resolve(vendor, `themes/${option.theme}.css`), target(`vendor/themes/${option.theme}.css`))
45+
}
46+
47+
cp(readme, target('README.md'))
48+
cp(main, target('404.html'))
49+
50+
replace(target('404.html'), 'vue.css', `${option.theme}.css`)
51+
console.log(msg)
52+
}
53+
54+
exports.serve = function (path, option) {
55+
path = path || '.'
56+
var main = resolve(path, '404.html')
57+
58+
if (!exist(main)) {
59+
console.log(`\nNot found 404.html, please run ${GREEN_OPEN}init${GREEN_CLOSE} before.\n`)
60+
process.exit(0)
61+
}
62+
http.createServer(function (req, res) {
63+
serveStatic(path)(req, res, function () {
64+
res.writeHead(404, { 'Content-Type': 'text/html' })
65+
res.end(fs.readFileSync(main))
66+
})
67+
}).listen(option.port)
68+
69+
console.log(`\nListening at ${GREEN_OPEN}http://localhost:${option.port}${GREEN_CLOSE}\n`)
70+
}

src/template/404-local.html

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>Document</title>
6+
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
7+
<link rel="stylesheet" href="/vendor/themes/vue.css">
8+
</head>
9+
<body>
10+
<div id="app"></div>
11+
</body>
12+
<script src="/vendor/docsify.js"></script>
13+
</html>

src/template/404.html

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>Document</title>
6+
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
7+
<link rel="stylesheet" href="//unpkg.com/docsify/themes/vue.css">
8+
</head>
9+
<body>
10+
<div id="app"></div>
11+
</body>
12+
<script src="//unpkg.com/docsify/lib/docsify.pack.min.js"></script>
13+
</html>

src/template/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Headline
2+
3+
> A awesome project.

0 commit comments

Comments
 (0)