francis 1.0.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/francis +1 -4
- data/lib/francis.rb +92 -129
- metadata +17 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7f74c91f9218cf3c3236ec871f13c213955788fac080a658486143251617bb04
|
4
|
+
data.tar.gz: 3b3e6df458522097ecff512084e7ba0dd827fed1d74d33a297c7de612cc10f96
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2be6192cc9991c6430b5caa8aab21d4e34988b42e1de0600eb63f9d6d655ee71620873b727b651da60d479d0d887938a885ccbe095a52b0c3f0d3e3c4f923f05
|
7
|
+
data.tar.gz: 35144bcf547123a1df2bb1aa0bb725e580005e7c0865ac627ff0d5be98eb6bded53e4b6fb1b27086e6a19419ba02d56eae340831007f428249fc615e3daa6475
|
data/bin/francis
CHANGED
data/lib/francis.rb
CHANGED
@@ -1,149 +1,112 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
# Creates a new instance of the class and directs the gem
|
15
|
-
# to the method based on the command passed to it.
|
16
|
-
def initialize(command, args)
|
17
|
-
@folders = ["app","public","views"]
|
18
|
-
@files = ["app/app.rb", "Gemfile","config.ru"]
|
19
|
-
@newhelp = %Q(
|
20
|
-
Usage:
|
21
|
-
|
22
|
-
francis new <appname> [--git][--proc][--readme][--unicorn][-r <gems>]
|
23
|
-
|
24
|
-
Creates a new Sinatra app.
|
25
|
-
|
26
|
-
<appname> => Name of the new directory
|
27
|
-
|
28
|
-
Options:
|
29
|
-
|
30
|
-
--git => sets up the directory up as a git repo
|
31
|
-
--proc => sets up the directory with a Procfile
|
32
|
-
--readme => sets up the directory with a readme.md
|
33
|
-
--unicorn => sets up the directory with config/unicorn.rb, pids/unicorn.pid and logs/unicorn.log
|
34
|
-
-r <gems> => adds gems to the Gemfile
|
35
|
-
)
|
36
|
-
|
37
|
-
@foldershelp = %Q(
|
38
|
-
francis folders
|
39
|
-
|
40
|
-
Prints a list of folders that are created when francis new is run.
|
41
|
-
)
|
42
|
-
@fileshelp = %Q(
|
43
|
-
francis files
|
44
|
-
|
45
|
-
Prints a list of files that are created when francis new is run.
|
46
|
-
)
|
47
|
-
case command
|
48
|
-
when 'new'
|
49
|
-
run(args[0],args[1..-1])
|
50
|
-
when 'folders'
|
51
|
-
puts folders
|
52
|
-
when 'files'
|
53
|
-
puts files
|
54
|
-
when 'help'
|
55
|
-
help(args)
|
56
|
-
else
|
57
|
-
puts "I don't understand"
|
1
|
+
require 'thor'
|
2
|
+
|
3
|
+
module Francis
|
4
|
+
|
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)
|
58
14
|
end
|
59
15
|
end
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
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!
|
69
33
|
end
|
70
|
-
|
71
|
-
|
72
|
-
Dir.mkdir(f)
|
34
|
+
def add_folder(name)
|
35
|
+
@structure["/#{name}"] = {}
|
73
36
|
end
|
74
|
-
|
75
|
-
|
37
|
+
def remove_folder(name)
|
38
|
+
@structure.delete("/#{name}"){|el| "#{el} not found"}
|
76
39
|
end
|
77
|
-
|
78
|
-
|
40
|
+
def parse_options
|
41
|
+
git
|
42
|
+
readme
|
43
|
+
unicorn
|
44
|
+
whenever
|
45
|
+
require_gem
|
79
46
|
end
|
80
|
-
|
81
|
-
|
82
|
-
|
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"
|
83
65
|
end
|
66
|
+
puts "#{@name} created as Sinatra app"
|
84
67
|
end
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
f.write("require 'bundler'\nBundler.require\nrequire './app/app'\nrequire './db/db'\nrun Sinatra::Application")
|
90
|
-
end
|
91
|
-
if options.include?("--git")
|
92
|
-
system("git init")
|
68
|
+
def git
|
69
|
+
if @options[:git]
|
70
|
+
@structure["/"][".gitignore"] = %Q(.DS_Store\nGemfile.lock\npids/*\nlogs/*\n*.gem)
|
71
|
+
end
|
93
72
|
end
|
94
|
-
|
95
|
-
|
96
|
-
|
73
|
+
def readme
|
74
|
+
if @options[:readme]
|
75
|
+
@structure["/"]["readme.md"] = %Q(# #{@name.capitalize}\n\nTODO: Write a readme file)
|
97
76
|
end
|
98
77
|
end
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
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"] = ""
|
105
86
|
end
|
106
87
|
end
|
107
|
-
|
108
|
-
[
|
109
|
-
|
88
|
+
def whenever
|
89
|
+
if @options[:whenever]
|
90
|
+
add_folder "/config"
|
91
|
+
@structure["/config"]["schedule.rb"] = ""
|
110
92
|
end
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
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
|
+
}
|
122
104
|
end
|
123
|
-
|
124
105
|
end
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
# Prints the help file.
|
131
|
-
def help(*method)
|
132
|
-
if method.empty?
|
133
|
-
puts newhelp + foldershelp + fileshelp
|
134
|
-
elsif method.length == 1
|
135
|
-
case method[0][0]
|
136
|
-
when "new"
|
137
|
-
puts newhelp
|
138
|
-
when "folders"
|
139
|
-
puts foldershelp
|
140
|
-
when "files"
|
141
|
-
puts fileshelp
|
142
|
-
else
|
143
|
-
puts newhelp + foldershelp + fileshelp
|
106
|
+
def add_folder(folder)
|
107
|
+
if !@structure.has_key?(folder)
|
108
|
+
@structure["#{folder}"] = {}
|
144
109
|
end
|
145
|
-
else
|
146
|
-
puts newhelp + foldershelp + fileshelp
|
147
110
|
end
|
148
111
|
end
|
149
112
|
end
|
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: francis
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ian Kent
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
12
|
-
dependencies:
|
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'
|
13
27
|
description: A command line tool for quickly setting up Sinatra apps
|
14
28
|
email: ian@iankent.me
|
15
29
|
executables:
|