#!/usr/bin/env ruby # This software code is made available "AS IS" without warranties of any # kind. You may copy, display, modify and redistribute the software # code either by itself or as incorporated into your code; provided that # you do not remove any proprietary notices. Your use of this software # code is at your own risk and you waive any claim against the author # with respect to your use of this software code. # (c) 2007 Static-CMS require 'optparse' require 'fileutils' require 'Scms' require "scms/version" class String def to_path(end_slash=false) "#{'/' if self[0]=='\\'}#{self.split('\\').join('/')}#{'/' if end_slash}" end end 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 (full path)") do |w| options[:website] = w end opts.on('-c', '--config CONFIGDIR', "Configeration directory if different from Website (full path)") do |c| options[:configdir] = c end opts.on('-o', '--output BuildDIR', "Website build dir (full path)") do |o| options[:pub] = o 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 options[:server] = true end options[:mode] = "pub" opts.on( '-m', '--mode MODE', 'CMS or Publish' ) do|m| options[:mode] = m end opts.on( '-v', '--version', 'Output scms version' ) do puts "Version: #{Scms::VERSION}" exit end # This displays the help screen, all programs are assumed to have this option. opts.on( '-h', '--help', 'Display this help screen' ) do puts "Default action = build; default website directory = current working directory" puts opts exit end end 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, :assets => File.join(root_folder, "assets") } if options[:action] == "create" if File.exists?(File.join(Folders[:website], "_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]) 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" 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 if options[:server] Dir.chdir(Folders[:website]) do Thread.new { %x("scms-server") } end end if options[:action] == "watch" require 'filewatcher' FileWatcher.new(["_views", "_templates", "_source"], "Watching for changes in _views, _templates or _source").watch do |filename| puts "Updated " + filename Scms.build(Folders[:website], Folders[:config], options[:mode]) end end mimetypefile = File.join(Folders[:root], "assets", "mime.types") S3Deploy.sync(Folders[:website], Folders[:config], mimetypefile) if options[:action] == "deploy" Process.exit!(true)