class Arethusa::CLI
Constants
- VERSION
Public Class Methods
source_root()
click to toggle source
# File lib/arethusa/cli.rb, line 16 def self.source_root File.join(File.dirname(__FILE__), 'cli') end
Public Instance Methods
archive_path()
click to toggle source
# File lib/arethusa/cli.rb, line 229 def archive_path "deployment/#{@filename}" end
archive_to_use()
click to toggle source
# File lib/arethusa/cli.rb, line 204 def archive_to_use @archive ? "cat #{@archive}" : compress end
build()
click to toggle source
# File lib/arethusa/cli.rb, line 26 def build minify if options[:minify] empty_directory('deployment') @filename = "#{tar_name}#{ending}" create_tgz say_status(:built, archive_path) end
commit_sha()
click to toggle source
# File lib/arethusa/cli.rb, line 253 def commit_sha `git rev-parse --short HEAD`.strip end
compress()
click to toggle source
# File lib/arethusa/cli.rb, line 196 def compress "tar -zc #{folders_to_deploy.join(' ')}" end
config_dir()
click to toggle source
methods for merging
# File lib/arethusa/cli.rb, line 258 def config_dir "app/static/configs" end
create_deploy_directory()
click to toggle source
For deploy command
# File lib/arethusa/cli.rb, line 180 def create_deploy_directory if @sudo `#{ssh} -t "sudo mkdir -p #{@directory} && chown #{@user} directory"` else `#{ssh} mkdir -p #{@directory}` end end
create_folder_hierarchy()
click to toggle source
# File lib/arethusa/cli.rb, line 135 def create_folder_hierarchy dirs = [ plugin_dir, template_dir, template_dir('compiled'), css_dir, conf_dir, dist_dir, dist_dir('configs') ] dirs.each { |dir| empty_directory(dir) } end
create_templates()
click to toggle source
# File lib/arethusa/cli.rb, line 143 def create_templates create_module create_service create_html_template create_spec create_scss create_gitignore create_jshintrc create_package create_bower create_gruntfile create_index_file create_conf_file end
create_tgz()
click to toggle source
For build command
# File lib/arethusa/cli.rb, line 217 def create_tgz `tar -zcf #{archive_path} #{folders_to_deploy.join(' ')}` end
decompress()
click to toggle source
# File lib/arethusa/cli.rb, line 212 def decompress "tar -zxC #{@directory}" end
deploy(address, directory)
click to toggle source
# File lib/arethusa/cli.rb, line 67 def deploy(address, directory) @address = address @directory = options[:commit] ? File.join(directory, short_sha).strip : directory @ssh_options = options[:options] @archive = options[:file] @environment = options[:environment] if options[:sudo] @sudo = true @user = @address.split('@').first end @small = options[:small] minify if options[:minify] &! @archive create_deploy_directory execute use_deployment_helper if @environment say_status(:deployed, "at #{@address} - #{@directory}") end
ending()
click to toggle source
# File lib/arethusa/cli.rb, line 237 def ending '.tgz' end
execute()
click to toggle source
# File lib/arethusa/cli.rb, line 188 def execute `#{archive_to_use} | #{ssh} #{decompress}` end
folders_to_deploy()
click to toggle source
# File lib/arethusa/cli.rb, line 221 def folders_to_deploy if @small %w{ app dist favicon.ico } else %w{ app bower_components docs dist vendor favicon.ico } end end
git_branch()
click to toggle source
# File lib/arethusa/cli.rb, line 245 def git_branch `git rev-parse --abbrev-ref HEAD`.strip end
init(namespace, name)
click to toggle source
# File lib/arethusa/cli.rb, line 107 def init(namespace, name) @name = name @namespace = namespace inside namespaced_name do init_git create_folder_hierarchy create_templates initial_commit install end end
init_git()
click to toggle source
# File lib/arethusa/cli.rb, line 124 def init_git if `git init` say_status(:success, "Initialized new repo in #{namespaced_name}") end end
initial_commit()
click to toggle source
# File lib/arethusa/cli.rb, line 130 def initial_commit `git add -A` `git commit -m 'Initial commit'` end
install()
click to toggle source
# File lib/arethusa/cli.rb, line 158 def install `npm install && bower install && gem install sass -v 3.3.14` # We have to minify Arethusa by hand for now - this won't be needed # at a later stage. inside 'bower_components/arethusa' do `npm install && bower install` `grunt version` `grunt minify:all` end end
merge(file)
click to toggle source
# File lib/arethusa/cli.rb, line 94 def merge(file) @conf = read_conf(file) @conf_dir = options[:base_path] || config_dir traverse_and_include(@conf) if options[:minify] puts @conf.to_json else puts JSON.pretty_generate(@conf, indent: ' ') end end
minify()
click to toggle source
# File lib/arethusa/cli.rb, line 170 def minify if system('bower install && grunt clean version minify:all ngdocs plato ') say_status(:success, 'minified Arethusa') else say_status(:error, 'minification failed') exit end end
read_conf(path)
click to toggle source
# File lib/arethusa/cli.rb, line 284 def read_conf(path) begin JSON.parse(File.read(path)) rescue nil end end
short_sha()
click to toggle source
# File lib/arethusa/cli.rb, line 200 def short_sha `git rev-parse --short HEAD` end
ssh()
click to toggle source
# File lib/arethusa/cli.rb, line 208 def ssh "ssh #{@ssh_options} #{@address}" end
tar_name()
click to toggle source
# File lib/arethusa/cli.rb, line 233 def tar_name [tar_namespace, timestamp, git_branch, commit_sha].join('-') end
tar_namespace()
click to toggle source
# File lib/arethusa/cli.rb, line 241 def tar_namespace 'arethusa' end
timestamp()
click to toggle source
# File lib/arethusa/cli.rb, line 249 def timestamp Time.now.to_i end
traverse(conf)
click to toggle source
# File lib/arethusa/cli.rb, line 268 def traverse(conf) clone = conf.clone clone.each do |key, value| if value.is_a?(Hash) traverse(conf[key]) elsif key == '@include' additional_conf = read_conf(value) conf.delete(key) if additional_conf traverse(additional_conf) conf.merge!(additional_conf) end end end end
traverse_and_include(conf)
click to toggle source
# File lib/arethusa/cli.rb, line 262 def traverse_and_include(conf) inside @conf_dir do traverse(conf) end end
use_deployment_helper()
click to toggle source
# File lib/arethusa/cli.rb, line 192 def use_deployment_helper `#{ssh} -t "bash -l -c 'depl-help-deploy arethusa #{@directory} #{@environment}'"` end
version()
click to toggle source
# File lib/arethusa/cli.rb, line 35 def version puts Arethusa::CLI::VERSION end