Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 0 additions & 17 deletions bin/index.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ _path = require('path')
_forever = require 'forever-monitor'
_os = require 'os'
_ = require 'lodash'
_livereload = require 'livereload'
require 'colors'

_initialize = require '../lib/initialize'
Expand Down Expand Up @@ -40,20 +39,6 @@ init = (ops, loadPlugin)->
#初始化插件模块
require('../lib/plugin').init() if loadPlugin

#初始化livereload
initLivereload = ()->
options = _utils.xPathMapValue('livereload', _utils.config)

return if not options
ops = {
exts: ['less', 'coffee', 'hbs', 'html', 'css', 'js', 'htm', 'handlebars', 'scss']
}
_.extend ops, options

#启动livereload服务
llServer = _livereload.createServer(ops)
llServer.watch _utils.options.workbench

#######################################插件相关#########################################
#安装插件的命令
_program.command('install [names...]')
Expand Down Expand Up @@ -264,8 +249,6 @@ _program
silky = require '../lib/index'
silky(app, server, true)

initLivereload()

# #暂时放弃forever的方式
# if true or _os.platform() is 'win32'
# global.SILKY = options
Expand Down
21 changes: 6 additions & 15 deletions lib/router.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,8 @@ _hooks = require './plugin/hooks'
_utils = require './utils'
_compiler = require './compiler'

#如果文件存在,则直接响应这个文件
responseFileIfExists = (file, res)->
#如果html文件存在,则直接输出
if _fs.existsSync file
res.sendfile file
return true

#响应纯内容数据
responseContent = (content, mime, req, res, next)->
#如果是html,则考虑要在head前加入livereload
if _utils.config.livereload and _mime.extension(mime) is 'html'
script = " <script src='#{_utils.options.livereload}'></script>\n$1"
content = content.replace /(<\/\s*head>)/i, script

data =
content: content
mime: mime
Expand All @@ -45,8 +33,11 @@ responseContent = (content, mime, req, res, next)->
#统一处理响应
response = (route, options, req, res, next)->
#对于css/html/js,先检查文件是否存在,如果文件存在,则直接返回
return if /\.(html|htm|js|css|coffee)$/i.test(route.realpath) and responseFileIfExists(route.realpath, res)

if /\.(html|htm|js|css|coffee)$/i.test(route.realpath) and _fs.existsSync route.realpath
content = _fs.readFileSync(route.realpath, {encoding: 'utf8'})
responseContent content, route.mime, req, res, next
return

# #查找真实的未编译源文件路径
# sourceFile = _compiler.sourceFile(route.compiler, route.realpath)
# #没有找到对应的源文件,这是一个404错误
Expand Down Expand Up @@ -289,4 +280,4 @@ module.exports = (app)->
options =
pluginData: data.pluginData

response data.route, options, req, res, next
response data.route, options, req, res, next
1 change: 0 additions & 1 deletion lib/utils.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,6 @@ exports.init = (options)->
env: 'development'
workbench: null
buildMode: false
livereload: 'http://localhost:35729/livereload.js'

_.merge _options, options
_options.identity = '.silky'
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
"json-literal": "^1.1.0",
"json-proxy": "^0.3.1",
"less": "1.7.3",
"livereload": "^0.3.7",
"lodash": "^2.4.1",
"mime": "^1.2.11",
"mkdirp": "*",
Expand Down