Class: Legion::Cli::LexBuilder

Inherits:
Thor
  • Object
show all
Includes:
Thor::Actions
Defined in:
lib/legion/lex.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.exit_on_failure?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/legion/lex.rb', line 21

def self.exit_on_failure?
  true
end

.source_rootObject



25
26
27
# File 'lib/legion/lex.rb', line 25

def self.source_root
  File.dirname(__FILE__)
end

Instance Method Details

#create(name) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/legion/lex.rb', line 55

def create(name)
  if Dir.pwd.include?('lex-')
    say('already inside a lex_gen, try moving to a different directory', :red)
    return nil
  end

  vars = { filename: "lex-#{name}", class_name: name.capitalize, lex: name }
  filename = vars[:filename]
  template('cli/lex/templates/base/gemspec.erb', "#{filename}/#{filename}.gemspec", vars)
  template('cli/lex/templates/base/gemfile.erb', "#{filename}/Gemfile", vars)
  template('cli/lex/templates/base/gitignore.erb', "#{filename}/.gitignore", vars)
  template('cli/lex/templates/base/lic.erb', "#{filename}/LICENSE", vars)
  template('cli/lex/templates/base/rubocop.yml.erb', "#{filename}/.rubocop.yml", vars)
  template('cli/lex/templates/base/readme.md.erb', "#{filename}/README.md", **vars)
  template('cli/lex/templates/base/lex.erb', "#{filename}/lib/legion/extensions/#{name}.rb", vars)
  template('cli/lex/templates/base/version.erb', "#{filename}/lib/legion/extensions/#{name}/version.rb", vars)
  template('cli/lex/templates/base/spec_helper.rb.erb', "#{filename}/spec/spec_helper.rb", vars)
  template('cli/lex/templates/base/lex_spec.erb', "#{filename}/spec/legion/#{name}_spec.rb", vars)

  template('cli/lex/templates/base/github_rspec.yml.erb', "#{filename}/.github/workflows/rspec.yml", vars)
  template('cli/lex/templates/base/github_rubocop.yml.erb', "#{filename}/.github/workflows/rubocop.yml", vars)

  return if !options[:git_init] && !options[:bundle_install]

  run("cd lex_gen-#{filename}")
  if options[:git_init]
    run('git init')
    run('git add .')
    run('git commit -m \'Initial commit\'')
  end

  run('bundle update') if options[:bundle_install]
end

#deployObject



93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/legion/lex.rb', line 93

def deploy
  system 'gem build'
  if options[:github_gem]
    system "gh release create v#{version} '#{long_name}-#{version}.gem'"
    system 'gh release create v1.1.1 lex-node-1.1.1.gem -n v1.1.1 -t v1.1.1'
    system "gem push --key github --host https://rubygems.pkg.github.com/LegionIO"
  end

  if options[:rubygems]
    system "gem push .gem"
  end

  if options[:docker]

  end

end

#versionObject



46
47
48
# File 'lib/legion/lex.rb', line 46

def version
  say "Legion::CLI #{Legion::Cli::VERSION}"
end