Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add project initialization #2

Merged
merged 8 commits into from
Oct 18, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,13 @@
/pkg/
/spec/reports/
/tmp/

# RubyMine
/.idea/

# OSX
.DS_Store

.ruby-version
.ruby-gemset

1 change: 0 additions & 1 deletion .ruby-gemset

This file was deleted.

1 change: 0 additions & 1 deletion .ruby-version

This file was deleted.

45 changes: 35 additions & 10 deletions bin/expando
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -99,4 +113,15 @@ command [ :update, :u ] do | c |
#c.default_command :entities
end

exit run(ARGV)
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)
8 changes: 0 additions & 8 deletions circle.yml

This file was deleted.

1 change: 1 addition & 0 deletions lib/expando.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
63 changes: 63 additions & 0 deletions lib/expando/project_template.rb
Original file line number Diff line number Diff line change
@@ -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