-
-
Notifications
You must be signed in to change notification settings - Fork 153
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3d32be8
commit 661cbe2
Showing
4 changed files
with
64 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
var serveStatic = require('serve-static') | ||
var connect = require('connect') | ||
var livereload = require('connect-livereload') | ||
var lrserver = require('livereload') | ||
var util = require('./util') | ||
|
||
var green = util.green | ||
var exist = util.exist | ||
var resolve = util.resolve | ||
|
||
module.exports = function (path, option) { | ||
path = resolve(path || '.') | ||
var indexFile = resolve(path, 'index.html') | ||
|
||
if (!exist(indexFile)) { | ||
console.log(`\nplease run ${green('init')} before.\n`) | ||
process.exit(0) | ||
} | ||
|
||
var server = connect() | ||
|
||
server.use(livereload()) | ||
server.use(serveStatic(path)) | ||
server.listen(option.port) | ||
lrserver.createServer({ | ||
exts: ['md'] | ||
}).watch(path) | ||
|
||
console.log(`\nListening at ${green(`http://localhost:${option.port}`)}\n`) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
var fs = require('fs') | ||
|
||
var resolve = exports.resolve = require('path').resolve | ||
|
||
exports.cwd = function (path) { | ||
return resolve(process.cwd(), path) | ||
} | ||
|
||
exports.pwd = function (path) { | ||
return resolve(__dirname, path) | ||
} | ||
|
||
exports.exist = function (path) { | ||
if (fs.existsSync(path)) { | ||
return path | ||
} | ||
return undefined | ||
} | ||
|
||
exports.green = function (str) { | ||
return '\u001B[32m' + str + '\u001B[39m' | ||
} |