Skip to content

Commit

Permalink
feat(serve): add --index-name to rewrite default index name (#48)
Browse files Browse the repository at this point in the history
* feat: add index-name option to cli

* feat(serve): update serve command to serve index

* feat(locales): update translations

* fix(gulp): downgrade gulp to 3.9.0, buggy 3.9.1

* build(CI): seems node11 natives need to update
  • Loading branch information
trycontrolmymind authored and QingWei-Li committed Feb 18, 2019
1 parent 032817b commit dc8e993
Show file tree
Hide file tree
Showing 8 changed files with 1,690 additions and 1,476 deletions.
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ cache:
- ./node_modules
install:
- npm install
- npm install -g gulp
- npm install natives@1.1.6
- npm install -g gulp@3.9.0
script:
- gulp lint
9 changes: 8 additions & 1 deletion bin/docsify
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,16 @@ var yargs = require('yargs')
nargs: 1,
requiresArg: true,
type: 'number'
},
'index-name': {
alias: 'i',
desc: chalk.gray(y18n.__('serve.indexname')),
nargs: 1,
requiresArg: true,
type: 'string'
}
}),
handler: (argv) => run.serve(argv.path, argv.open, argv.port, argv.P)
handler: (argv) => run.serve(argv.path, argv.open, argv.port, argv.P, argv.i)
})
.command({
command: 'start <path>',
Expand Down
9 changes: 5 additions & 4 deletions lib/commands/serve.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@ const util = require('../util/index')
var exists = util.exists
var resolve = util.resolve

module.exports = function (path, openInBrowser, port, livereloadPort) {
module.exports = function (path, openInBrowser, port, livereloadPort, indexName) {
path = resolve(path || '.')
var indexFile = resolve(path, 'index.html')
var indexFile = resolve(path, indexName || 'index.html')

if (!exists(indexFile)) {
const msg = '\nNo docs found, please run ' + chalk.green('docsify init') + ' first.\n'
const msg = '\nNo docs found ' + indexFile +
'\nPlease run ' + chalk.green('docsify init') + ' first.\n'
console.log(msg)
process.exit(0)
}
Expand All @@ -25,7 +26,7 @@ module.exports = function (path, openInBrowser, port, livereloadPort) {
server.use(livereload({
port: livereloadPort
}))
server.use(serveStatic(path))
server.use(serveStatic(path, { 'index': indexName }))
server.listen(port)
lrserver.createServer({
extraExts: ['md'],
Expand Down
Loading

0 comments on commit dc8e993

Please sign in to comment.