-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove rake as gem dependency (but keep it as development dependency)
- Loading branch information
nikola
committed
Jan 30, 2017
1 parent
9ca3667
commit 75fbfa7
Showing
28 changed files
with
396 additions
and
255 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,3 +5,4 @@ gemspec | |
|
||
gem 'rspec', '~> 3.0.0' | ||
gem 'pry' | ||
gem 'rake', '~> 10.5' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,129 +1,6 @@ | ||
#!/usr/bin/env ruby | ||
|
||
require 'thor' | ||
require 'thor/group' | ||
require 'erubis' | ||
require 'fileutils' | ||
require 'pathname' | ||
# require 'dumbo' | ||
require File.join(File.dirname(__FILE__), '..', 'lib', 'dumbo.rb') | ||
|
||
module Cli | ||
class Generate < Thor | ||
desc 'spec <name>', 'Add a new spec file named <name> as spec/<name>_spec.rb' | ||
def spec(name) | ||
file_name = "spec/#{name}_spec.rb" | ||
if File.exist?(file_name) | ||
say_status('already exists', file_name, :yellow) | ||
return | ||
end | ||
|
||
File.open("spec/#{name}_spec.rb", 'w') do |f| | ||
f.puts <<-EOF.gsub(' ', '') | ||
require 'spec_helper' | ||
describe '#{name}' do | ||
before do | ||
install_extension | ||
end | ||
end | ||
EOF | ||
end | ||
say_status('create', file_name) | ||
end | ||
end | ||
|
||
class Dumbo < Thor | ||
desc 'new <name>', 'creates a new extension skeleton' | ||
|
||
def new(name, initial_version = '0.0.1') | ||
mkdir("#{name}/sql") | ||
mkdir("#{name}/src") | ||
mkdir("#{name}/spec") | ||
mkdir("#{name}/config") | ||
mkdir("#{name}/lib/tasks") | ||
|
||
spec_helper = Dir.glob(File.expand_path('../../spec/spec_helper.rb', __FILE__)) | ||
spec_helper += Dir.glob(File.expand_path('../../spec/support', __FILE__)) | ||
|
||
cp spec_helper, "#{name}/spec" | ||
cp File.expand_path('../../config/boot.rb', __FILE__), "#{name}/config" | ||
|
||
template_path = File.expand_path('../../template', __FILE__) | ||
|
||
Dir.glob(File.expand_path('../../template/**/*', __FILE__)).each do |template| | ||
pathname = Pathname.new(template) | ||
dest_name = pathname.relative_path_from Pathname.new(template_path) | ||
|
||
if pathname.directory? | ||
mkdir("#{name}/#{dest_name}", true) | ||
next | ||
end | ||
|
||
if dest_name.extname == '.erb' | ||
eruby = Erubis::Eruby.new(File.read(template)) | ||
content = eruby.result(ext_name: name) | ||
create "#{name}/#{dest_name.sub_ext('')}", content | ||
else | ||
cp template, "#{name}/#{dest_name}" | ||
end | ||
end | ||
|
||
create "#{name}/#{name}.control", <<-STR | ||
# #{name} extension | ||
comment = 'my awesome extension' | ||
default_version = '#{initial_version}' | ||
relocatable = true | ||
requires = '' | ||
STR | ||
end | ||
|
||
desc "g GENERATOR args", "generates files for the given generator" | ||
subcommand "g", Generate | ||
|
||
|
||
|
||
no_commands do | ||
def mkdir(path, silent_skip = false) | ||
if File.directory?(path) | ||
say_status('skip', "#{path}", :yellow) unless silent_skip | ||
else | ||
FileUtils.mkdir_p(path) | ||
say_status('create', "#{path}") | ||
end | ||
end | ||
|
||
def create(path, content, silent_skip = false) | ||
if File.exist? path | ||
say_status('skip', path, :yellow) unless silent_skip | ||
else | ||
File.open(path, 'w') do |f| | ||
f.puts content | ||
end | ||
say_status('create', path) | ||
end | ||
end | ||
|
||
def cp(src, dest, silent_skip = false) | ||
Array(src).each do |p| | ||
path = Pathname.new(p) | ||
if File.directory?(dest) | ||
if File.exist?("#{dest}/#{path.basename}") | ||
say_status('skip', "#{dest}/#{path.basename}", :yellow) unless silent_skip | ||
else | ||
FileUtils.cp_r p, dest | ||
say_status('create', "#{dest}/#{path.basename}") | ||
end | ||
else | ||
if File.exist?(dest) | ||
say_status('skip', dest, :yellow) unless silent_skip | ||
else | ||
FileUtils.cp_r p, dest | ||
say_status('create', dest) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
|
||
Cli::Dumbo.start(ARGV) | ||
Dumbo::Cli.start(ARGV) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.