diff --git a/.gitignore b/.gitignore index 0cb6eeb..794dead 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,13 @@ /pkg/ /spec/reports/ /tmp/ + +# RubyMine +/.idea/ + +# OSX +.DS_Store + +.ruby-version +.ruby-gemset + diff --git a/.ruby-gemset b/.ruby-gemset deleted file mode 100644 index 3262880..0000000 --- a/.ruby-gemset +++ /dev/null @@ -1 +0,0 @@ -expando diff --git a/.ruby-version b/.ruby-version deleted file mode 100644 index 76521af..0000000 --- a/.ruby-version +++ /dev/null @@ -1 +0,0 @@ -ruby-2.2.0 diff --git a/bin/expando b/bin/expando index fc98a7a..8276eed 100755 --- a/bin/expando +++ b/bin/expando @@ -9,9 +9,19 @@ include GLI::App version Expando::VERSION -program_desc 'A tool for managing files written in the Expando markup language.' - -config_file File.join(ENV['HOME'],'.expando.rc.yaml') +program_desc 'A tool for managing files written in the Expando language.' + +# Prefer using config file frow current working directory. Otherwise, use config +# file in home directory. +config_filename = '.expando.rc.yaml' +current_directory_config_filename = File.join(Dir.pwd, config_filename) +home_directory_config_filename = File.join(ENV['HOME'], config_filename) + +if File.exist?(current_directory_config_filename) + config_file current_directory_config_filename +else + config_file home_directory_config_filename +end flag :client_access_token, desc: 'Api.ai Client Access Token' flag :developer_access_token, desc: 'Api.ai Developer Access Token' @@ -47,11 +57,13 @@ command [ :update, :u ] do | c | entities.flag :entities_path, desc: 'The path to the directory containing entity files' entities.action do | global_options, options, args | - # Expand ~ in path configurations - entities_path = File.expand_path( options[ :entities_path ] || global_options[ :intents_path ] ) + # Determine path to entity files + entities_path_from_options = options[ :entities_path ] || global_options[ :entities_path ] + entities_path = entities_path_from_options ? + File.expand_path( entities_path_from_options ) : File.join( Dir.pwd, 'entities' ) if args.empty? - entity_names = Dir.entries( entities_path )[2..-1].collect { | f | f.gsub( '.txt', '' ) } + entity_names = Dir.entries( entities_path )[ 2..-1 ].collect { | f | f.gsub( '.txt', '' ) } else entity_names = args end @@ -77,11 +89,13 @@ command [ :update, :u ] do | c | intents.flag :intents_path, desc: 'The path to the directory containing intent files' intents.action do | global_options, options, args | - # Expand ~ in path configurations - intents_path = File.expand_path( options[ :intents_path ] || global_options[ :intents_path ] ) + # Determine path to intent files + intents_path_from_options = options[ :intents_path ] || global_options[ :intents_path ] + intents_path = intents_path_from_options ? + File.expand_path( intents_path_from_options ) : File.join( Dir.pwd, 'intents' ) if args.empty? - intent_names = Dir.entries( intents_path )[2..-1].collect { | f | f.gsub( '.txt', '' ) } + intent_names = Dir.entries( intents_path )[ 2..-1 ].collect { | f | f.gsub( '.txt', '' ) } else intent_names = args end @@ -99,4 +113,15 @@ command [ :update, :u ] do | c | #c.default_command :entities end -exit run(ARGV) \ No newline at end of file +desc 'Initialize a new Expando project' +long_desc <<-DESC + Create the necessary files and directories for a new Expando project in the + current working directory. +DESC +command [ :init, :i ] do | c | + c.action do + Expando::ProjectTemplate.init! + end +end + +exit run(ARGV) diff --git a/circle.yml b/circle.yml deleted file mode 100644 index d4bce54..0000000 --- a/circle.yml +++ /dev/null @@ -1,8 +0,0 @@ -test: - override: - - RAILS_ENV=test bundle exec rspec -r rspec_junit_formatter --format RspecJunitFormatter -o $CIRCLE_TEST_REPORTS/rspec/junit.xml -deployment: - staging: - branch: /.*/ - commands: - - bundle exec ./bin/expando update entities app diff --git a/lib/expando.rb b/lib/expando.rb index f5bf99d..4f9b5c6 100644 --- a/lib/expando.rb +++ b/lib/expando.rb @@ -3,6 +3,7 @@ require 'expando/entity_updater' require 'expando/intent_updater' require 'expando/expander' +require 'expando/project_template' require 'api-ai-ruby' require 'colorize' require 'awesome_print' diff --git a/lib/expando/project_template.rb b/lib/expando/project_template.rb new file mode 100644 index 0000000..b42d901 --- /dev/null +++ b/lib/expando/project_template.rb @@ -0,0 +1,63 @@ +module Expando + class ProjectTemplate + class << self + # Initialize a new Expando project in the current working directory. + def init! + mkdir 'intents' + mkdir 'entities' + + config_file_contents = <<-CONFIG_FILE +# API.AI credentials - add the credentials for your agent below +:client_access_token: REPLACE_WITH_TOKEN +:developer_access_token: REPLACE_WITH_TOKEN + CONFIG_FILE + + mkfile '.expando.rc.yaml', config_file_contents + + circleci_config_file_contents = <<-CIRCLECI_CONFIG_FILE +deployment: + staging: + branch: /.*/ + commands: + - bundle exec ./bin/expando update intents + - bundle exec ./bin/expando update entities + CIRCLECI_CONFIG_FILE + + mkfile 'circle.yaml', circleci_config_file_contents + end + + private + + # Attempt to create the specified directory. Output progress to user. + # + # @param directory [String] The directory to create. + def mkdir(directory) + full_path = File.join(Dir.pwd, directory) + + if Dir.exist?(full_path) + puts '•'.colorize(:blue) + " #{directory} directory exists (skipping)" + else + Dir.mkdir(full_path) + puts '✓'.colorize(:green) + " #{directory} directory created" + end + end + + # Attempt to create the specified file. Output progress to user. + # + # @param name [String] The name of the file. + # @param contents [String] The contents of the file. + def mkfile(name, contents) + full_path = File.join(Dir.pwd, name) + + if File.exist?(name) + puts '•'.colorize(:blue) + " #{name} file exists (skipping)" + else + File.open(full_path, 'w') do |file| + file << contents + end + puts '✓'.colorize(:green) + " #{name} file created" + end + end + end + end +end