rubiclifier 0.1.0 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/bin/rubiclifier +5 -0
- data/lib/args.rb +1 -1
- data/lib/base_application.rb +56 -25
- data/lib/cli/rubiclifier_cli.rb +69 -0
- data/lib/cli/template_hydrator.rb +47 -0
- data/lib/feature.rb +7 -0
- data/lib/rubiclifier.rb +1 -8
- data/lib/setting.rb +13 -8
- data/project_template/.gitignore +4 -0
- data/project_template/Gemfile +5 -0
- data/project_template/PROJECT_NAME.gemspec.erb +20 -0
- data/project_template/VERSION +1 -0
- data/project_template/bin/PROJECT_NAME.erb +5 -0
- data/project_template/lib/PROJECT_NAME.rb.erb +59 -0
- data/project_template/lib/api.rb +4 -0
- data/project_template/migrations.rb +7 -0
- 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: 885f96560267ed31c84cbfb59268f890140f9b91daa1b3ff08657badd28db7ba
|
|
4
|
+
data.tar.gz: c46f05c22899e4568578e299f358796676c66ac1122519c3cfd96d904dfc006c
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 1a49292eacc335a78e2f8dd4c092af026e2dad15c0403da1c8f2956d4417ef01c138af80bcccd564c0916c5a38983d31bc2eda1683aea70aab57416dc4c0098c
|
|
7
|
+
data.tar.gz: a84da6fb10722920c681c133be30f4e24bfe06b318f6e4f12b6115da4f0f6542abd892e2b42cd4df71da73950a96ad04e66a205e80b258f98df350cccd396c0d
|
data/bin/rubiclifier
ADDED
data/lib/args.rb
CHANGED
data/lib/base_application.rb
CHANGED
|
@@ -10,12 +10,12 @@ module Rubiclifier
|
|
|
10
10
|
|
|
11
11
|
def initialize(args)
|
|
12
12
|
@args = Args.new(args)
|
|
13
|
-
DB.hydrate(data_directory, migrations_location)
|
|
13
|
+
DB.hydrate(data_directory, migrations_location) if feature_enabled?(Feature::DATABASE)
|
|
14
14
|
end
|
|
15
15
|
|
|
16
16
|
def call
|
|
17
17
|
show_help if args.command == "help" || args.boolean("help", "h")
|
|
18
|
-
setup_or_fail
|
|
18
|
+
setup_or_fail if needs_setup?
|
|
19
19
|
run_application
|
|
20
20
|
end
|
|
21
21
|
|
|
@@ -33,16 +33,12 @@ module Rubiclifier
|
|
|
33
33
|
def not_setup
|
|
34
34
|
end
|
|
35
35
|
|
|
36
|
-
def
|
|
37
|
-
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
def sends_notifications?
|
|
41
|
-
raise NotImplementedError
|
|
36
|
+
def features
|
|
37
|
+
[]
|
|
42
38
|
end
|
|
43
39
|
|
|
44
40
|
def settings
|
|
45
|
-
|
|
41
|
+
[]
|
|
46
42
|
end
|
|
47
43
|
|
|
48
44
|
def executable_name
|
|
@@ -50,7 +46,7 @@ module Rubiclifier
|
|
|
50
46
|
end
|
|
51
47
|
|
|
52
48
|
def data_directory
|
|
53
|
-
raise NotImplementedError
|
|
49
|
+
raise NotImplementedError if feature_enabled?(Feature::DATABASE)
|
|
54
50
|
end
|
|
55
51
|
|
|
56
52
|
def migrations_location
|
|
@@ -61,14 +57,47 @@ module Rubiclifier
|
|
|
61
57
|
[]
|
|
62
58
|
end
|
|
63
59
|
|
|
60
|
+
private
|
|
61
|
+
|
|
62
|
+
def all_brew_dependencies
|
|
63
|
+
@abd ||= [
|
|
64
|
+
("sqlite" if feature_enabled?(Feature::DATABASE)),
|
|
65
|
+
("terminal-notifier" if feature_enabled?(Feature::NOTIFICATIONS))
|
|
66
|
+
].concat(brew_dependencies).compact
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def brew_dependencies_installed?
|
|
70
|
+
all_brew_dependencies.all? do |dep|
|
|
71
|
+
system("brew list #{dep} &> /dev/null")
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def brew_installed_or_fail
|
|
76
|
+
unless system("which brew &> /dev/null")
|
|
77
|
+
puts
|
|
78
|
+
puts("You must install Homebrew in order to install these dependencies: #{all_brew_dependencies.join(", ")}".red)
|
|
79
|
+
puts("Go to https://brew.sh/")
|
|
80
|
+
exit
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
def all_features
|
|
85
|
+
[
|
|
86
|
+
(Feature::DATABASE if !settings.empty?)
|
|
87
|
+
].concat(features).compact.uniq
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
def needs_setup?
|
|
91
|
+
!all_brew_dependencies.empty? || !settings.empty? || feature_enabled?(Feature::BACKGROUND)
|
|
92
|
+
end
|
|
93
|
+
|
|
64
94
|
def setup_or_fail
|
|
65
95
|
if args.command == "setup" || args.boolean("setup", "s")
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
"
|
|
69
|
-
("
|
|
70
|
-
|
|
71
|
-
system("brew install #{all_brew_dependencies.join(" ")}")
|
|
96
|
+
unless all_brew_dependencies.empty?
|
|
97
|
+
brew_installed_or_fail
|
|
98
|
+
puts("Installing brew dependencies...")
|
|
99
|
+
system("brew install #{all_brew_dependencies.join(" ")}")
|
|
100
|
+
end
|
|
72
101
|
|
|
73
102
|
puts
|
|
74
103
|
|
|
@@ -80,26 +109,24 @@ module Rubiclifier
|
|
|
80
109
|
|
|
81
110
|
puts
|
|
82
111
|
|
|
83
|
-
if
|
|
112
|
+
if feature_enabled?(Feature::BACKGROUND)
|
|
84
113
|
setup_as_background_service
|
|
85
114
|
else
|
|
86
|
-
puts("Finished setup! Run with
|
|
115
|
+
puts("Finished setup! Run with `".green + "#{executable_name}" + "`".green)
|
|
87
116
|
end
|
|
88
117
|
exit
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
unless settings.all?(&:is_setup?)
|
|
118
|
+
elsif !settings.all?(&:is_setup?) || !brew_dependencies_installed?
|
|
92
119
|
not_setup
|
|
93
120
|
puts
|
|
94
|
-
puts("Oops! You must finish setup first
|
|
95
|
-
puts("
|
|
121
|
+
puts("Oops! You must finish setup first.".red)
|
|
122
|
+
puts(" `".red + "#{executable_name} --setup" + "`".red)
|
|
96
123
|
exit
|
|
97
124
|
end
|
|
98
125
|
end
|
|
99
126
|
|
|
100
127
|
def setup_as_background_service
|
|
101
|
-
puts("It's recommended that you set this up as a system service with serviceman. You can check it out here: https://git.rootprojects.org/root/serviceman".
|
|
102
|
-
puts("Set #{executable_name} to run on startup with `serviceman add --name #{executable_name} #{executable_name}`".
|
|
128
|
+
puts("It's recommended that you set this up as a system service with serviceman. You can check it out here: https://git.rootprojects.org/root/serviceman".yellow)
|
|
129
|
+
puts("Set #{executable_name} to run on startup with `".yellow + "serviceman add --name #{executable_name} #{executable_name}" + "`".yellow)
|
|
103
130
|
puts
|
|
104
131
|
print("Would you like this script to set it up for you? (y/n) ")
|
|
105
132
|
if STDIN.gets.chomp.downcase == "y"
|
|
@@ -114,5 +141,9 @@ module Rubiclifier
|
|
|
114
141
|
puts("Finished setup!".green)
|
|
115
142
|
end
|
|
116
143
|
end
|
|
144
|
+
|
|
145
|
+
def feature_enabled?(feature)
|
|
146
|
+
all_features.include?(feature)
|
|
147
|
+
end
|
|
117
148
|
end
|
|
118
149
|
end
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
require "rubiclifier"
|
|
2
|
+
|
|
3
|
+
class RubiclifierCli < Rubiclifier::BaseApplication
|
|
4
|
+
attr_reader :project_name
|
|
5
|
+
private :project_name
|
|
6
|
+
|
|
7
|
+
def show_help
|
|
8
|
+
puts
|
|
9
|
+
puts("rubiclifier helps you generate new Ruby CLI and background service tools")
|
|
10
|
+
puts
|
|
11
|
+
puts("Usage:")
|
|
12
|
+
puts(" rubiclifier --help | Shows this help menu")
|
|
13
|
+
puts(" rubiclifier new [project_name] | Creates a new rubiclifier project")
|
|
14
|
+
puts(" --background | Generate with background service setup steps")
|
|
15
|
+
puts(" --database | Generate with a persistent database")
|
|
16
|
+
puts(' --homebrew "[first [second]]" | Require specific homebrew kegs')
|
|
17
|
+
puts(" --notifications | Generate with notification functionality")
|
|
18
|
+
puts(" --settings | Generate with persistent setting functionality")
|
|
19
|
+
puts
|
|
20
|
+
exit
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def run_application
|
|
24
|
+
case args.command
|
|
25
|
+
when "new"
|
|
26
|
+
create_project
|
|
27
|
+
else
|
|
28
|
+
show_help
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
private
|
|
33
|
+
|
|
34
|
+
def create_project
|
|
35
|
+
@project_name = args.first_option
|
|
36
|
+
validate_project_name
|
|
37
|
+
system("mkdir -p #{project_name}")
|
|
38
|
+
system("cp -R \"#{File.dirname(__FILE__)}/../../project_template/.\" #{project_name}")
|
|
39
|
+
system("cp \"#{File.dirname(__FILE__)}/../../project_template/.gitignore\" #{project_name}")
|
|
40
|
+
Dir.glob("#{project_name}/**/*.erb").each do |template_file|
|
|
41
|
+
hydrate_template_file(template_file)
|
|
42
|
+
system("mv #{template_file} #{template_file.sub(/\.erb$/, "").sub("PROJECT_NAME", project_name)}")
|
|
43
|
+
end
|
|
44
|
+
unless template_hydrator.feature_enabled?(Rubiclifier::Feature::DATABASE)
|
|
45
|
+
system("rm #{project_name}/migrations.rb")
|
|
46
|
+
end
|
|
47
|
+
puts("Finished creating project #{project_name}! Build out the application in #{project_name}/lib/#{project_name}.rb".green)
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def validate_project_name
|
|
51
|
+
if project_name.nil?
|
|
52
|
+
puts("You must specify a project name.".red)
|
|
53
|
+
exit
|
|
54
|
+
elsif !project_name.match(/^[a-z_]+$/)
|
|
55
|
+
puts("Your project name must be lowercase letters and _".red)
|
|
56
|
+
exit
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def hydrate_template_file(template_file)
|
|
61
|
+
template_string = File.read(template_file)
|
|
62
|
+
output = template_hydrator.hydrate(template_string)
|
|
63
|
+
File.write(template_file, output)
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def template_hydrator
|
|
67
|
+
@template_hydrator ||= TemplateHydrator.new(args, project_name)
|
|
68
|
+
end
|
|
69
|
+
end
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
require "rubiclifier"
|
|
2
|
+
|
|
3
|
+
class TemplateHydrator
|
|
4
|
+
attr_reader :args, :project_name
|
|
5
|
+
private :args
|
|
6
|
+
|
|
7
|
+
def initialize(args, project_name)
|
|
8
|
+
@args = args
|
|
9
|
+
@project_name = project_name
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def hydrate(template_string)
|
|
13
|
+
ERB.new(template_string, nil, "-").result(binding)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def project_name_camel_case
|
|
17
|
+
@pnsc ||= project_name.split("_").collect(&:capitalize).join
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def include_settings?
|
|
21
|
+
args.boolean("settings")
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def brew_dependencies
|
|
25
|
+
args.string("homebrew")&.split(" ") || []
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def uses_brew?
|
|
29
|
+
!brew_dependencies.empty?
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def features
|
|
33
|
+
@features ||= [
|
|
34
|
+
(Rubiclifier::Feature::BACKGROUND if args.boolean("background")),
|
|
35
|
+
(Rubiclifier::Feature::DATABASE if (args.boolean("database") || include_settings?)),
|
|
36
|
+
(Rubiclifier::Feature::NOTIFICATIONS if args.boolean("notifications")),
|
|
37
|
+
].compact
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def needs_setup?
|
|
41
|
+
!features.empty? || uses_brew?
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def feature_enabled?(feature)
|
|
45
|
+
features.include?(feature)
|
|
46
|
+
end
|
|
47
|
+
end
|
data/lib/feature.rb
ADDED
data/lib/rubiclifier.rb
CHANGED
|
@@ -1,8 +1 @@
|
|
|
1
|
-
|
|
2
|
-
require_relative "./base_api.rb"
|
|
3
|
-
require_relative "./base_application.rb"
|
|
4
|
-
require_relative "./cipher.rb"
|
|
5
|
-
require_relative "./colorized_strings.rb"
|
|
6
|
-
require_relative "./database.rb"
|
|
7
|
-
require_relative "./notification.rb"
|
|
8
|
-
require_relative "./setting.rb"
|
|
1
|
+
Dir.glob("#{File.dirname(__FILE__)}/**/*.rb").each {|file| require file }
|
data/lib/setting.rb
CHANGED
|
@@ -12,14 +12,19 @@ module Rubiclifier
|
|
|
12
12
|
end
|
|
13
13
|
|
|
14
14
|
def populate
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
15
|
+
input = nil
|
|
16
|
+
loop do
|
|
17
|
+
print("What's the #{label}? #{explanation_text}".blue)
|
|
18
|
+
input = if is_secret
|
|
19
|
+
STDIN.noecho(&:gets).chomp.tap { puts }
|
|
20
|
+
else
|
|
21
|
+
STDIN.gets.chomp
|
|
22
|
+
end
|
|
23
|
+
if input == ""
|
|
24
|
+
input = nil
|
|
25
|
+
puts("This value can't be empty.".red) unless nullable
|
|
26
|
+
end
|
|
27
|
+
break if input || nullable
|
|
23
28
|
end
|
|
24
29
|
DB.save_setting(key, input, is_secret: is_secret) unless input.nil?
|
|
25
30
|
end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
Gem::Specification.new do |s|
|
|
2
|
+
s.name = "<%= project_name %>"
|
|
3
|
+
s.version = File.read("VERSION").strip
|
|
4
|
+
s.licenses = ["MIT"]
|
|
5
|
+
s.summary = "SUMMARY HERE"
|
|
6
|
+
s.authors = ["AUTHOR NAME"]
|
|
7
|
+
s.email = "AUTHOR EMAIL"
|
|
8
|
+
s.files = Dir.glob("{lib}/**/*") + ["Gemfile"]
|
|
9
|
+
s.homepage = "https://rubygems.org/gems/<%= project_name %>"
|
|
10
|
+
s.metadata = { "source_code_uri" => "https://github.com/PATH_TO_PROJECT" }
|
|
11
|
+
s.require_path = "lib"
|
|
12
|
+
s.platform = Gem::Platform::RUBY
|
|
13
|
+
s.executables = ["<%= project_name %>"]
|
|
14
|
+
s.post_install_message = <<MSG
|
|
15
|
+
|
|
16
|
+
\e[32mThanks for installing <%= project_name %>!\e[0m
|
|
17
|
+
\e[32mSet it up by running `\e[0m<%= project_name %> --setup\e[32m`\e[0m
|
|
18
|
+
|
|
19
|
+
MSG
|
|
20
|
+
end
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
0.1.0
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
require "rubiclifier"
|
|
2
|
+
|
|
3
|
+
class <%= project_name_camel_case %> < Rubiclifier::BaseApplication
|
|
4
|
+
def show_help
|
|
5
|
+
puts
|
|
6
|
+
puts("DESCRIPTION")
|
|
7
|
+
puts
|
|
8
|
+
puts("Usage:")
|
|
9
|
+
puts(" <%= project_name %> --help | Shows this help menu")
|
|
10
|
+
<%- if needs_setup? -%>
|
|
11
|
+
puts(" <%= project_name -%> --setup | Runs setup")
|
|
12
|
+
<%- end -%>
|
|
13
|
+
puts(" <%= project_name %> command --option <argument> | Executes command")
|
|
14
|
+
puts
|
|
15
|
+
exit
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def run_application
|
|
19
|
+
while true
|
|
20
|
+
puts "Running!"
|
|
21
|
+
sleep 5
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
<%- if !features.empty? -%>
|
|
25
|
+
|
|
26
|
+
def features
|
|
27
|
+
[<%= features.map { |f| "Rubiclifier::Feature::#{f}" }.join(", ") %>]
|
|
28
|
+
end
|
|
29
|
+
<%- end -%>
|
|
30
|
+
<%- if include_settings? -%>
|
|
31
|
+
|
|
32
|
+
def settings
|
|
33
|
+
@settings ||= [
|
|
34
|
+
Rubiclifier::Setting.new("username", "username", explanation: ->{"find it at this url"}, nullable: true),
|
|
35
|
+
Rubiclifier::Setting.new("password", "password", explanation: "input hidden", is_secret: true)
|
|
36
|
+
]
|
|
37
|
+
end
|
|
38
|
+
<%- end -%>
|
|
39
|
+
|
|
40
|
+
def executable_name
|
|
41
|
+
"<%= project_name %>"
|
|
42
|
+
end
|
|
43
|
+
<%- if feature_enabled?(Rubiclifier::Feature::DATABASE) -%>
|
|
44
|
+
|
|
45
|
+
def data_directory
|
|
46
|
+
"~/.<%= project_name %>"
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def migrations_location
|
|
50
|
+
"#{File.expand_path(File.dirname(__FILE__) + "/..")}/migrations.rb"
|
|
51
|
+
end
|
|
52
|
+
<%- end -%>
|
|
53
|
+
<%- if uses_brew? -%>
|
|
54
|
+
|
|
55
|
+
def brew_dependencies
|
|
56
|
+
<%= brew_dependencies.inspect %>
|
|
57
|
+
end
|
|
58
|
+
<%- end -%>
|
|
59
|
+
end
|
metadata
CHANGED
|
@@ -1,31 +1,45 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: rubiclifier
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version:
|
|
4
|
+
version: 1.0.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Kyle Grinstead
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2020-07-
|
|
11
|
+
date: 2020-07-09 00:00:00.000000000 Z
|
|
12
12
|
dependencies: []
|
|
13
13
|
description:
|
|
14
14
|
email: kyleag@hey.com
|
|
15
|
-
executables:
|
|
15
|
+
executables:
|
|
16
|
+
- rubiclifier
|
|
16
17
|
extensions: []
|
|
17
18
|
extra_rdoc_files: []
|
|
18
19
|
files:
|
|
19
20
|
- Gemfile
|
|
21
|
+
- bin/rubiclifier
|
|
20
22
|
- lib/args.rb
|
|
21
23
|
- lib/base_api.rb
|
|
22
24
|
- lib/base_application.rb
|
|
23
25
|
- lib/cipher.rb
|
|
26
|
+
- lib/cli/rubiclifier_cli.rb
|
|
27
|
+
- lib/cli/template_hydrator.rb
|
|
24
28
|
- lib/colorized_strings.rb
|
|
25
29
|
- lib/database.rb
|
|
30
|
+
- lib/feature.rb
|
|
26
31
|
- lib/notification.rb
|
|
27
32
|
- lib/rubiclifier.rb
|
|
28
33
|
- lib/setting.rb
|
|
34
|
+
- project_template/.gitignore
|
|
35
|
+
- project_template/Gemfile
|
|
36
|
+
- project_template/Gemfile.lock
|
|
37
|
+
- project_template/PROJECT_NAME.gemspec.erb
|
|
38
|
+
- project_template/VERSION
|
|
39
|
+
- project_template/bin/PROJECT_NAME.erb
|
|
40
|
+
- project_template/lib/PROJECT_NAME.rb.erb
|
|
41
|
+
- project_template/lib/api.rb
|
|
42
|
+
- project_template/migrations.rb
|
|
29
43
|
homepage: https://rubygems.org/gems/rubiclifier
|
|
30
44
|
licenses:
|
|
31
45
|
- MIT
|