francis 0.0.1 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +7 -0
  2. data/bin/francis +1 -4
  3. data/lib/francis.rb +100 -63
  4. metadata +27 -15
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 7f74c91f9218cf3c3236ec871f13c213955788fac080a658486143251617bb04
4
+ data.tar.gz: 3b3e6df458522097ecff512084e7ba0dd827fed1d74d33a297c7de612cc10f96
5
+ SHA512:
6
+ metadata.gz: 2be6192cc9991c6430b5caa8aab21d4e34988b42e1de0600eb63f9d6d655ee71620873b727b651da60d479d0d887938a885ccbe095a52b0c3f0d3e3c4f923f05
7
+ data.tar.gz: 35144bcf547123a1df2bb1aa0bb725e580005e7c0865ac627ff0d5be98eb6bded53e4b6fb1b27086e6a19419ba02d56eae340831007f428249fc615e3daa6475
@@ -1,6 +1,3 @@
1
1
  #!/usr/bin/env ruby
2
2
  require 'francis'
3
- args = ARGV.dup
4
- ARGV.clear
5
- command = args.shift.strip
6
- Francis.dispatch(command, args)
3
+ Francis::CLI.start(ARGV)
@@ -1,75 +1,112 @@
1
- # A simple gem & CLI for setting up a working directory
2
- # structure for Sinatra apps.
3
- #
4
- # Author:: Ian Kent (mailto:ian@iankent.me)
5
- # License:: Distributed under the same terms as Ruby
1
+ require 'thor'
6
2
 
7
- # This is the only and main class for the gem.
3
+ module Francis
8
4
 
9
- class Francis
10
- @@folders = ["app","tmp","db","public","views","public/css","public/js","public/img"]
11
- @@files = ["app/app.rb", "db/db.rb", "tmp/restart.txt", "Gemfile","config.ru"]
12
-
13
- # Determines which method to call.
14
- def self.dispatch(command, args)
15
- case command
16
- when 'new'
17
- Francis.new(args[0],args[1..-1])
18
- when 'folders'
19
- Francis.folders
20
- when 'files'
21
- Francis.files
22
- else
23
- Francis.help
5
+ class CLI < Thor
6
+ desc "create NAME", "Create a new sinatra app called NAME"
7
+ option :git, :type => :boolean, :aliases => "-g", :desc => "Create app as a git respository and include a .gitignore file"
8
+ option :readme, :type => :boolean, :aliases => "-R", :desc => "Include a readme.md file"
9
+ option :unicorn, :type => :boolean, :aliases => "-u", :desc => "Include a config/unicorn.rb file with default unicorn config"
10
+ option :require_gem, :type => :array, :aliases => "-r", :desc => "Add required gems that will be included in the Gemfile and required within app.rb"
11
+ option :whenever, :type => :boolean, :aliases => "-w", :desc => "Include a config/schedule.rb file"
12
+ def create(name)
13
+ Francis::FileStructure.new(name, options)
24
14
  end
25
15
  end
26
-
27
- # Creates a new working directory for Sinatra apps,
28
- # it takes two variables: a name to call the directory
29
- # and an option array.
30
- def self.new(name, options)
31
- dir = Dir.getwd
32
- if Dir.exists?("#{dir}/#{name}")
33
- abort("There is already a folder with that name, please choose another.")
34
- else
35
- Dir.mkdir("#{dir}/#{name}")
16
+ class FileStructure
17
+ def initialize(name, options)
18
+ @name = name
19
+ sinatra_gem_version = Gem.latest_version_for 'sinatra'
20
+ @structure = {
21
+ "/views" => {},
22
+ "/public" => {},
23
+ "/" => {
24
+ "config.ru" => %Q(require 'bundler'\nBundler.require\nrequire_relative 'app'\nrun #{@name.capitalize}),
25
+ "app.rb" => %Q(require 'sinatra'\nclass #{@name.capitalize} < Sinatra::Base\n\tget '/' do\n\t\t'Hello world!'\n\tend\nend),
26
+ "Gemfile" => %Q(source 'https://rubygems.org'\ngem 'sinatra', '#{sinatra_gem_version.approximate_recommendation}'\n)
27
+ }
28
+ }
29
+ @options = options
30
+ @wd = "#{Dir.getwd}/#{@name}"
31
+ parse_options
32
+ execute!
36
33
  end
37
- Dir.chdir("#{dir}/#{name}")
38
- @@folders.each do |f|
39
- Dir.mkdir(f)
34
+ def add_folder(name)
35
+ @structure["/#{name}"] = {}
40
36
  end
41
- @@files.each do |f|
42
- File.new(f,"w")
37
+ def remove_folder(name)
38
+ @structure.delete("/#{name}"){|el| "#{el} not found"}
43
39
  end
44
- File.open("Gemfile","a") do |f|
45
- f.write("source 'https://rubygems.org'\ngem 'sinatra'")
40
+ def parse_options
41
+ git
42
+ readme
43
+ unicorn
44
+ whenever
45
+ require_gem
46
46
  end
47
- File.open("app/app.rb","a") do |f|
48
- f.write("get '/' do\n 'Hello world!'\nend")
47
+ def execute!
48
+ # create target directory
49
+ Dir.mkdir(@wd)
50
+ # cycle through structure and create folders and files
51
+ @structure.each{|folder,files|
52
+ if folder != "/"
53
+ Dir.mkdir("#{@wd}#{folder}")
54
+ end
55
+ files.each{|name,contents|
56
+ File.open("#{@wd}#{folder}/#{name}", "w"){|f|
57
+ f.write(contents)
58
+ }
59
+ }
60
+ }
61
+ # if git option is given, execute git init command
62
+ if @options[:git]
63
+ Dir.chdir(@wd)
64
+ system "git init"
65
+ end
66
+ puts "#{@name} created as Sinatra app"
49
67
  end
50
- File.open("config.ru","a") do |f|
51
- f.write("require 'bundler'\nBundler.require\nrequire './app/app'\nrequire './db/db'\nrun Sinatra::Application")
68
+ def git
69
+ if @options[:git]
70
+ @structure["/"][".gitignore"] = %Q(.DS_Store\nGemfile.lock\npids/*\nlogs/*\n*.gem)
71
+ end
52
72
  end
53
- if options.include?("--git")
54
- system("git init")
73
+ def readme
74
+ if @options[:readme]
75
+ @structure["/"]["readme.md"] = %Q(# #{@name.capitalize}\n\nTODO: Write a readme file)
76
+ end
77
+ end
78
+ def unicorn
79
+ if @options[:unicorn]
80
+ add_folder "/config"
81
+ add_folder "/pids"
82
+ add_folder "/logs"
83
+ @structure["/config"]["unicorn.rb"] = %Q(working_directory '#{@wd}'\npid '#{@wd}/pids/unicorn.pid'\nstderr_path '#{@wd}/logs/unicorn.log'\nstdout_path '#{@wd}/logs/unicorn.log'\nlisten '/tmp/#{@name}.sock'\nworker_processes 2\ntimeout 30)
84
+ @structure["/pids"]["unicorn.pid"] = ""
85
+ @structure["/logs"]["unicorn.log"] = ""
86
+ end
87
+ end
88
+ def whenever
89
+ if @options[:whenever]
90
+ add_folder "/config"
91
+ @structure["/config"]["schedule.rb"] = ""
92
+ end
93
+ end
94
+ def require_gem
95
+ if @options[:require_gem]
96
+ @options[:require_gem].each{|r|
97
+ version = Gem.latest_version_for(r)
98
+ if version
99
+ @structure["/"]["Gemfile"] << %Q(gem '#{r}', '#{version.approximate_recommendation}'\n)
100
+ else
101
+ warn "Could not find gem: #{r}, skipping inclusion in Gemfile"
102
+ end
103
+ }
104
+ end
105
+ end
106
+ def add_folder(folder)
107
+ if !@structure.has_key?(folder)
108
+ @structure["#{folder}"] = {}
109
+ end
55
110
  end
56
- puts "Sinatra app '#{name}' created!"
57
- end
58
-
59
- # Prints the folders that are included in the directory
60
- # set up.
61
- def self.folders
62
- puts @@folders
63
- end
64
-
65
- # Prints the files that are included in the directory
66
- # set up.
67
- def self.files
68
- puts @@files
69
- end
70
-
71
- # Prints the help file.
72
- def self.help
73
- puts "Usage:\n\nfrancis new <appname> [--git]\n\nCreates a new Sinatra app.\n\n<appname> => Name of the new directory\n\n--git => If present, will set the new directory up as a git repository\n\nfrancis folders\n\nPrints a list of folders that are created when francis new is run.\n\nfrancis files\n\nPrints a list of files that are created when francis new is run."
74
111
  end
75
- end
112
+ end
metadata CHANGED
@@ -1,47 +1,59 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: francis
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
5
- prerelease:
4
+ version: 2.0.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Ian Kent
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-03-01 00:00:00.000000000 Z
13
- dependencies: []
14
- description: A quick start for Sinatra apps
11
+ date: 2021-01-25 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: thor
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.1'
27
+ description: A command line tool for quickly setting up Sinatra apps
15
28
  email: ian@iankent.me
16
29
  executables:
17
30
  - francis
18
31
  extensions: []
19
32
  extra_rdoc_files: []
20
33
  files:
21
- - lib/francis.rb
22
34
  - bin/francis
23
- homepage: http://code.iankent.me/francis
24
- licenses: []
35
+ - lib/francis.rb
36
+ homepage: https://bitbucket.org/iankentforrestbrown/francis/
37
+ licenses:
38
+ - MIT
39
+ metadata: {}
25
40
  post_install_message:
26
41
  rdoc_options: []
27
42
  require_paths:
28
43
  - lib
29
44
  required_ruby_version: !ruby/object:Gem::Requirement
30
- none: false
31
45
  requirements:
32
- - - ! '>='
46
+ - - ">="
33
47
  - !ruby/object:Gem::Version
34
48
  version: '0'
35
49
  required_rubygems_version: !ruby/object:Gem::Requirement
36
- none: false
37
50
  requirements:
38
- - - ! '>='
51
+ - - ">="
39
52
  - !ruby/object:Gem::Version
40
53
  version: '0'
41
54
  requirements: []
42
- rubyforge_project:
43
- rubygems_version: 1.8.23
55
+ rubygems_version: 3.1.2
44
56
  signing_key:
45
- specification_version: 3
57
+ specification_version: 4
46
58
  summary: Francis
47
59
  test_files: []