From aa81222d9564c83ddf822493ec7b55f5be6bb1e2 Mon Sep 17 00:00:00 2001 From: Matt Buck Date: Tue, 18 Oct 2016 15:31:46 -0500 Subject: [PATCH 1/8] Drop .ruby-version and .ruby-gemset --- .ruby-gemset | 1 - .ruby-version | 1 - 2 files changed, 2 deletions(-) delete mode 100644 .ruby-gemset delete mode 100644 .ruby-version 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 From 4458c1d880316931a5deb207d9e54608ed0cdc7e Mon Sep 17 00:00:00 2001 From: Matt Buck Date: Tue, 18 Oct 2016 15:31:55 -0500 Subject: [PATCH 2/8] Update .gitignore --- .gitignore | 10 ++++++++++ 1 file changed, 10 insertions(+) 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 + From 1cf659aaecd3b2f0fec7948a5859ae67c556bfdc Mon Sep 17 00:00:00 2001 From: Matt Buck Date: Tue, 18 Oct 2016 16:36:57 -0500 Subject: [PATCH 3/8] Add initial project init command --- bin/expando | 13 ++++++++++++- lib/expando.rb | 1 + lib/expando/project_template.rb | 27 +++++++++++++++++++++++++++ 3 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 lib/expando/project_template.rb diff --git a/bin/expando b/bin/expando index fc98a7a..9d85272 100755 --- a/bin/expando +++ b/bin/expando @@ -99,4 +99,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/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..1873266 --- /dev/null +++ b/lib/expando/project_template.rb @@ -0,0 +1,27 @@ +module Expando + class ProjectTemplate + class << self + # Initialize a new Expando project in the current working directory. + def init! + mkdir 'intents' + mkdir 'entities' + 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 + end + end +end From 1ab20a55ffe65db61ec6c7cdaabccb91e470c16e Mon Sep 17 00:00:00 2001 From: Matt Buck Date: Tue, 18 Oct 2016 16:54:11 -0500 Subject: [PATCH 4/8] Enable use of config file in current directory --- bin/expando | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/bin/expando b/bin/expando index 9d85272..27a51e6 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' From 255f9eba0dbbe8e32054d82da37bad4f41f5606a Mon Sep 17 00:00:00 2001 From: Matt Buck Date: Tue, 18 Oct 2016 17:10:26 -0500 Subject: [PATCH 5/8] Enable loading intents and entities from current working directory --- bin/expando | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/bin/expando b/bin/expando index 27a51e6..25486ca 100755 --- a/bin/expando +++ b/bin/expando @@ -58,7 +58,8 @@ command [ :update, :u ] do | c | entities.action do | global_options, options, args | # Expand ~ in path configurations - entities_path = File.expand_path( options[ :entities_path ] || global_options[ :intents_path ] ) + entities_path = File.expand_path( options[ :entities_path ] || global_options[ :intents_path ] ) || + File.join(Dir.pwd, 'entities') if args.empty? entity_names = Dir.entries( entities_path )[2..-1].collect { | f | f.gsub( '.txt', '' ) } @@ -88,7 +89,8 @@ command [ :update, :u ] do | c | intents.action do | global_options, options, args | # Expand ~ in path configurations - intents_path = File.expand_path( options[ :intents_path ] || global_options[ :intents_path ] ) + intents_path = File.expand_path( options[ :intents_path ] || global_options[ :intents_path ] ) || + File.join(Dir.pwd, 'intents') if args.empty? intent_names = Dir.entries( intents_path )[2..-1].collect { | f | f.gsub( '.txt', '' ) } From 506dafc0ecde598ce8376f8e841b3ba436889c73 Mon Sep 17 00:00:00 2001 From: Matt Buck Date: Tue, 18 Oct 2016 17:12:51 -0500 Subject: [PATCH 6/8] Drop circle.yaml --- circle.yml | 8 -------- 1 file changed, 8 deletions(-) delete mode 100644 circle.yml 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 From e860407e1416c8f8f1e3ff1f4a27aae2b00c3896 Mon Sep 17 00:00:00 2001 From: Matt Buck Date: Tue, 18 Oct 2016 17:13:21 -0500 Subject: [PATCH 7/8] Enable creating config files when initializing project --- lib/expando/project_template.rb | 36 +++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/lib/expando/project_template.rb b/lib/expando/project_template.rb index 1873266..b42d901 100644 --- a/lib/expando/project_template.rb +++ b/lib/expando/project_template.rb @@ -5,6 +5,25 @@ class << self 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 @@ -22,6 +41,23 @@ def mkdir(directory) 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 From c30211e0388a1e9f2bf212256fbaf9ab1a58f4d9 Mon Sep 17 00:00:00 2001 From: Matt Buck Date: Tue, 18 Oct 2016 17:24:37 -0500 Subject: [PATCH 8/8] Ensure intent and entity directories are properly determined --- bin/expando | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/bin/expando b/bin/expando index 25486ca..8276eed 100755 --- a/bin/expando +++ b/bin/expando @@ -57,12 +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 ] ) || - File.join(Dir.pwd, 'entities') + # 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 @@ -88,12 +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 ] ) || - File.join(Dir.pwd, 'intents') + # 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