bin/scms in scms-3.0.0 vs bin/scms in scms-3.0.1
- old
+ new
@@ -88,18 +88,23 @@
:website => options[:website],
:destination => (options[:destination] or ENV["SCMS_PUBLISH_FOLDER"] or '').to_path,
:config => (options[:configdir] or ENV["SCMS_CONFIG_FOLDER"] or options[:website]),
:assets => File.join(root_folder, "assets")
}
+# These can be used in the bootstrap.rb
$website = Folders[:website]
+$watch = options[:watch]
+$cmsmode = options[:mode] == "cms"
-ScmsUtils.log "System root folder = #{Folders[:root]}"
-ScmsUtils.log "Website folder = #{Folders[:website]}"
-ScmsUtils.log "Destination dir = #{Folders[:destination]}"
-ScmsUtils.log "Config dir = #{Folders[:config]}"
-ScmsUtils.log "Mode = #{options[:mode]}"
+configfile = File.join(Folders[:website], "_config.yml")
+# ScmsUtils.log "System root folder = #{Folders[:root]}"
+# ScmsUtils.log "Website folder = #{Folders[:website]}"
+# ScmsUtils.log "Destination dir = #{Folders[:destination]}"
+# ScmsUtils.log "Config dir = #{Folders[:config]}"
+# ScmsUtils.log "Mode = #{options[:mode]}"
+
raise "Invalid working directory! #{Folders[:website]}" if !File::directory?(Folders[:website])
if options[:create] != nil
puts "Creating scms website: #{options[:create]}"
newWorkingDir = File.join(Folders[:website], options[:create])
@@ -122,35 +127,43 @@
end
Scms.build(Folders[:website], Folders[:config], options[:mode])
Scms.copywebsite(Folders[:website], Folders[:destination]) if Folders[:destination] != ''
-threads = []
-if options[:server]
- threads << Thread.new {
- ScmsServer.start(Folders[:website], options[:port])
- }
-end
-
if options[:watch]
- #watcher = Thread.new {
- require 'filewatcher'
- FileWatcher.new(["_views", "_layouts", "_templates", "_source"], "Watching for changes in _views, _layouts or _source").watch do |filename|
- puts "Updated " + filename
- Scms.build(Folders[:website], Folders[:config], options[:mode])
+ require "Listen"
+
+ psst = []
+ #psst.push("_config.yml")# if File.exists?(configfile)
+ psst.push("_views") if File.directory? "_views"
+ psst.push("_layouts") if File.directory? "_layouts"
+ psst.push("_templates") if File.directory? "_templates"
+ psst.push("_source") if File.directory? "_source"
+ psst.push("_resources") if File.directory? "_resources"
+
+ puts "Setting up listen"
+ listener = Listen.to(psst, force_polling: true ) do |modified, added, removed|
+ puts "modified: #{modified}" if modified.length > 0
+ puts "added: #{added}" if added.length > 0
+ puts "removed: #{removed}" if removed.length > 0
+
+ Scms.build(Folders[:website], Folders[:config], options[:mode]) if modified.length > 0
end
- #}
- #watcher.join
+ trap("INT"){
+ puts "Closing file watcher"
+ listener.stop
+ }
+ listener.start # not blocking
+ sleep unless options[:server]
end
+if options[:server]
+ ScmsServer.start(Folders[:website], options[:port])
+end
+
if options[:publish]
if File.exists?(File.join(Folders[:config], "_s3config.yml"))
puts "Deploying to S3"
mimetypefile = File.join(Folders[:assets], "mime.types")
S3Deploy.sync(Folders[:website], Folders[:config], mimetypefile)
end
-end
-
-# join web server thread if it hasn't been used with watch action
-threads.each { |t|
- t.join
-}
+end
\ No newline at end of file