bin/scms in scms-2.2.0 vs bin/scms in scms-3.0.0

- old
+ new

@@ -21,36 +21,51 @@ options = {} optparse = OptionParser.new do|opts| # Set a banner, displayed at the top of the help screen. opts.banner = "Usage: scms [options]" - - # Define the options, and what they do - opts.on('-w', '--website WEBSITE', "Website directory (defaults to ./)") do |w| - options[:website] = w + + options[:website] = Dir.pwd + opts.on('-s', '--source WorkingDir', "Location of website source code (defaults to ./)") do |w| + options[:website] = w.to_path end - opts.on('-c', '--config CONFIGDIR', "Configeration directory if different from Website (defaults to ./)") do |c| - options[:configdir] = c + opts.on('-d', '--destination OutPutDir', "The location of the build files (defaults to ./)") do |o| + options[:destination] = o.to_path end - - opts.on('-o', '--output BuildDIR', "Website build dir (defaults to ./)") do |o| - options[:pub] = o + + options[:create] = nil + opts.on( '-c', '--create NewWebSiteName', 'Create a new scms website' ) do |newsite| + options[:create] = newsite end - - options[:action] = "build" - opts.on( '-a', '--action ACTION', 'build, deploy, listen or create' ) do|a| - options[:action] = a - end options[:server] = false - opts.on( '-s', '--server', 'Run a scms server on port localhost:8008' ) do + opts.on( '-s', '--serve', 'Run a scms server on port localhost:8008' ) do options[:server] = true end + + options[:port] = 8002 + opts.on( '-p', '--port Port', 'Listen on the given port (only workes with --serve)' ) do|p| + options[:port] = p + end + + options[:watch] = false + opts.on( '-w', '--watch', 'Run a scms server on port localhost:8008' ) do + options[:watch] = true + end + + options[:publish] = false + opts.on( '-p', '--publish', 'Deploy site to S3' ) do + options[:publish] = true + end + + opts.on('-o', '--config ConfigDir', "Configeration directory if different from Website (defaults to ./)") do |c| + options[:configdir] = c + end options[:mode] = "pub" - opts.on( '-m', '--mode MODE', 'CMS or Publish (for use with Air-Monkey: http://ipassexam.github.io/Air-Monkey/)' ) do|m| + opts.on( '-m', '--mode Mode', 'CMS or Publish (for use with Air-Monkey: http://ipassexam.github.io/Air-Monkey/)' ) do|m| options[:mode] = m end opts.on( '-v', '--version', 'Output scms version' ) do puts "Version: #{Scms::VERSION}" @@ -66,69 +81,75 @@ optparse.parse! #Set globals $stdout.sync = true root_folder = File.expand_path("../", File.dirname(__FILE__)) -website = ((options[:website].nil?) ? Dir.pwd : options[:website]).to_path -$website = website Folders = { :root => root_folder, - :website => website, - :pub => (options[:pub] or ENV["SCMS_PUBLISH_FOLDER"] or '').to_path, - :config => (options[:configdir] or ENV["SCMS_CONFIG_FOLDER"] or website).to_path, + :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") } +$website = Folders[:website] -if options[:action] == "create" - if File.exists?(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]) + if File.exists?(File.join(newWorkingDir, "_config.yml")) #if Dir.exists? Folders[:website] "Website already exists!!!" else - puts "Making website: #{Folders[:website]}" - FileUtils.mkdir_p Folders[:website] - FileUtils.cp_r(Dir["#{File.join(Folders[:assets], "blank-template")}/*"], Folders[:website]) + puts "Making website: #newWorkingDir}" + FileUtils.mkdir_p newWorkingDir + FileUtils.cp_r(Dir["#{File.join(Folders[:assets], "blank-template")}/*"], newWorkingDir) end exit end monkeyhook = File.join(Folders[:website], "scripts", "air-monkey-hook.js") if options[:mode] == "cms" FileUtils.cp(File.join(Folders[:assets], "air-monkey-hook.js"), monkeyhook) else - FileUtils.rm(monkeyhook) if File.exist?(monkeyhook) && options[:action] == "deploy" + FileUtils.rm(monkeyhook) if File.exist?(monkeyhook) && options[:publish] end -#ScmsUtils.log "System root folder = #{Folders[:root]}" -#ScmsUtils.log "Website folder = #{Folders[:website]}" -#ScmsUtils.log "Pub dir = #{Folders[:pub]}" -#ScmsUtils.log "Config dir = #{Folders[:config]}" -#ScmsUtils.log "Mode = #{options[:mode]}" - -raise "No website in folder #{Folders[:website]}" if !File::directory?(Folders[:website]) -Scms.upgrade(Folders[:website]) Scms.build(Folders[:website], Folders[:config], options[:mode]) -Scms.copywebsite(Folders[:website], Folders[:pub]) if Folders[:pub] != nil +Scms.copywebsite(Folders[:website], Folders[:destination]) if Folders[:destination] != '' threads = [] if options[:server] threads << Thread.new { - ScmsServer.start(8088, Folders[:website]) + ScmsServer.start(Folders[:website], options[:port]) } end -if options[:action] == "watch" +if options[:watch] #watcher = Thread.new { require 'filewatcher' - FileWatcher.new(["_views", "_templates", "_source"], "Watching for changes in _views, _templates or _source").watch do |filename| + 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]) end #} #watcher.join end -mimetypefile = File.join(Folders[:root], "assets", "mime.types") -S3Deploy.sync(Folders[:website], Folders[:config], mimetypefile) if options[:action] == "deploy" +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 } \ No newline at end of file