k_starter 0.1.0 → 0.1.1
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/.builders/generators/01-bootstrap.rb +16 -16
- data/.rubocop.yml +14 -0
- data/CHANGELOG.md +7 -0
- data/Gemfile +22 -0
- data/README.md +1 -1
- data/exe/k_starter +15 -0
- data/ext/k_starter/extconf.rb +5 -0
- data/ext/k_starter/k_starter.c +9 -0
- data/ext/k_starter/k_starter.h +6 -0
- data/lib/k_starter/app.rb +16 -0
- data/lib/k_starter/app_generator.rb +198 -0
- data/lib/k_starter/cli.rb +63 -0
- data/lib/k_starter/commands/.keep +1 -0
- data/lib/k_starter/commands/command.rb +54 -0
- data/lib/k_starter/commands/configuration/configuration_menu.rb +46 -0
- data/lib/k_starter/commands/project/bootstrap_project.rb +28 -0
- data/lib/k_starter/commands/project/edit_project.rb +34 -0
- data/lib/k_starter/commands/project/new_project.rb +28 -0
- data/lib/k_starter/commands/project/project_menu.rb +51 -0
- data/lib/k_starter/commands/project/select_new_project_type.rb +44 -0
- data/lib/k_starter/database/base_model.rb +21 -0
- data/lib/k_starter/database/config_model.rb +99 -0
- data/lib/k_starter/database/project_model.rb +94 -0
- data/lib/k_starter/map.rb +46 -0
- data/lib/k_starter/questions/ask_questions.rb +20 -0
- data/lib/k_starter/questions/base_question.rb +208 -0
- data/lib/k_starter/questions/gem.rb +132 -0
- data/lib/k_starter/questions/rails.rb +162 -0
- data/lib/k_starter/questions/svelte.rb +52 -0
- data/lib/k_starter/r7_hotwire.rb +98 -0
- data/lib/k_starter/schema.rb +89 -0
- data/lib/k_starter/starters/base.rb +80 -0
- data/lib/k_starter/starters/gem.rb +71 -0
- data/lib/k_starter/starters/nuxt.rb +29 -0
- data/lib/k_starter/starters/rails.rb +29 -0
- data/lib/k_starter/starters/svelte.rb +45 -0
- data/lib/k_starter/tty_helpers.rb +118 -0
- data/lib/k_starter/version.rb +1 -1
- data/lib/k_starter.rb +44 -1
- data/package-lock.json +2 -2
- data/package.json +1 -1
- metadata +172 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e2b29b568199352177ac17f32f961648755203d693458e2123d0742000000b25
|
4
|
+
data.tar.gz: 2a9bc72d4fbff3184fceb7fe8f5a67c81995234c7fa621d43f01f3da0462ca4d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 48c1f36ae28241ce8c498f49e92e03c4fb876682f5191e7a506d70de397d53e7e9ae59da60a0056ca38bd79884b15ec9a8906e076c4a0361dae67fe562ad4707
|
7
|
+
data.tar.gz: dd22b27ff1b530f3513b0a4ca4aea1ab080f9587ca13c0f0b91482b2c12d95b43172b59125d188c0d2160a3acdfcc21bacaf2668f82ded9d505d0e8f8ef588f1
|
@@ -70,38 +70,38 @@ KManager.action :bootstrap do
|
|
70
70
|
run_command("git add .; git commit -m 'chore: #{self.options.description.downcase}'; git push")
|
71
71
|
end
|
72
72
|
.blueprint(
|
73
|
-
active:
|
73
|
+
active: true,
|
74
74
|
name: :opinionated,
|
75
75
|
description: 'opinionated GEM files',
|
76
76
|
on_exist: :write) do
|
77
77
|
|
78
78
|
cd(:app)
|
79
79
|
|
80
|
-
add('bin/setup')
|
81
|
-
add('bin/console')
|
80
|
+
# add('bin/setup')
|
81
|
+
# add('bin/console')
|
82
82
|
|
83
|
-
add("lib/#{typed_dom.application}.rb" , template_file: 'lib/applet_name.rb' , dom: dom)
|
84
|
-
add("lib/#{typed_dom.application}/version.rb" , template_file: 'lib/applet_name/version.rb' , dom: dom)
|
83
|
+
# add("lib/#{typed_dom.application}.rb" , template_file: 'lib/applet_name.rb' , dom: dom)
|
84
|
+
# add("lib/#{typed_dom.application}/version.rb" , template_file: 'lib/applet_name/version.rb' , dom: dom)
|
85
85
|
|
86
|
-
add('spec/spec_helper.rb')
|
87
|
-
add("spec/#{typed_dom.application}_spec.rb" , template_file: 'spec/applet_name_spec.rb', dom: dom)
|
86
|
+
# add('spec/spec_helper.rb')
|
87
|
+
# add("spec/#{typed_dom.application}_spec.rb" , template_file: 'spec/applet_name_spec.rb', dom: dom)
|
88
88
|
|
89
89
|
add("#{typed_dom.application}.gemspec" , template_file: 'applet_name.gemspec', dom: dom)
|
90
|
-
add('Gemfile', dom: dom)
|
91
|
-
add('Guardfile', dom: dom)
|
92
|
-
add('Rakefile', dom: dom)
|
93
|
-
add('.rspec', dom: dom)
|
94
|
-
add('.rubocop.yml', dom: dom)
|
90
|
+
# add('Gemfile', dom: dom)
|
91
|
+
# add('Guardfile', dom: dom)
|
92
|
+
# add('Rakefile', dom: dom)
|
93
|
+
# add('.rspec', dom: dom)
|
94
|
+
# add('.rubocop.yml', dom: dom)
|
95
95
|
add('README.md', dom: dom)
|
96
|
-
add('CODE_OF_CONDUCT.md', dom: dom)
|
97
|
-
add('LICENSE.txt', dom: dom)
|
96
|
+
# add('CODE_OF_CONDUCT.md', dom: dom)
|
97
|
+
# add('LICENSE.txt', dom: dom)
|
98
98
|
|
99
|
-
run_command("rubocop -a")
|
99
|
+
# run_command("rubocop -a")
|
100
100
|
|
101
101
|
run_command("git add .; git commit -m 'chore: #{self.options.description.downcase}'; git push")
|
102
102
|
end
|
103
103
|
.blueprint(
|
104
|
-
active:
|
104
|
+
active: false,
|
105
105
|
name: :ci_cd,
|
106
106
|
description: 'github actions (CI/CD)',
|
107
107
|
on_exist: :write) do
|
data/.rubocop.yml
CHANGED
@@ -11,6 +11,20 @@ AllCops:
|
|
11
11
|
- ".builders/**/*"
|
12
12
|
- "spec/samples/**/*"
|
13
13
|
|
14
|
+
Metrics/AbcSize:
|
15
|
+
Exclude:
|
16
|
+
- "lib/**/questions/**/*"
|
17
|
+
- "lib/**/commands/**/*"
|
18
|
+
- "lib/**/r7_hotwire.rb"
|
19
|
+
|
20
|
+
Metrics/PerceivedComplexity:
|
21
|
+
Exclude:
|
22
|
+
- "lib/**/r7_hotwire.rb"
|
23
|
+
|
24
|
+
Metrics/CyclomaticComplexity:
|
25
|
+
Exclude:
|
26
|
+
- "lib/**/r7_hotwire.rb"
|
27
|
+
|
14
28
|
Metrics/BlockLength:
|
15
29
|
Exclude:
|
16
30
|
- "**/spec/**/*"
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
# [0.1.0](https://github.com/klueless-io/k_starter/compare/v0.0.1...v0.1.0) (2022-06-30)
|
2
|
+
|
3
|
+
|
4
|
+
### Features
|
5
|
+
|
6
|
+
* k_starter gem setup ([b71905a](https://github.com/klueless-io/k_starter/commit/b71905a95b7aafa581e460d790ad0714fa114639))
|
7
|
+
|
1
8
|
## [Unreleased]
|
2
9
|
|
3
10
|
## [0.1.0] - 2022-06-30
|
data/Gemfile
CHANGED
@@ -19,3 +19,25 @@ end
|
|
19
19
|
group :test do
|
20
20
|
gem 'simplecov', require: false
|
21
21
|
end
|
22
|
+
|
23
|
+
if ENV['KLUE_LOCAL_GEMS']&.to_s&.downcase == 'true'
|
24
|
+
group :development, :test do
|
25
|
+
puts 'Using Local GEMs'
|
26
|
+
gem 'handlebars-helpers' , path: '../../kgems/handlebars-helpers'
|
27
|
+
gem 'k_builder' , path: '../../kgems/k_builder'
|
28
|
+
gem 'k_builder-dotnet' , path: '../../kgems/k_builder-dotnet'
|
29
|
+
gem 'k_builder-webpack5' , path: '../../kgems/k_builder-webpack5'
|
30
|
+
gem 'k_config' , path: '../../kgems/k_config'
|
31
|
+
gem 'k_decor' , path: '../../kgems/k_decor'
|
32
|
+
gem 'k_director' , path: '../../kgems/k_director'
|
33
|
+
gem 'k_doc' , path: '../../kgems/k_doc'
|
34
|
+
gem 'k_domain' , path: '../../kgems/k_domain'
|
35
|
+
gem 'k_ext-github' , path: '../../kgems/k_ext-github'
|
36
|
+
gem 'k_fileset' , path: '../../kgems/k_fileset'
|
37
|
+
gem 'k_log' , path: '../../kgems/k_log'
|
38
|
+
gem 'k_manager' , path: '../../kgems/k_manager'
|
39
|
+
gem 'k_type' , path: '../../kgems/k_type'
|
40
|
+
gem 'k_util' , path: '../../kgems/k_util'
|
41
|
+
gem 'peeky' , path: '../../kgems/peeky'
|
42
|
+
end
|
43
|
+
end
|
data/README.md
CHANGED
@@ -42,7 +42,7 @@ See all [usage examples](./USAGE.md)
|
|
42
42
|
Checkout the repo
|
43
43
|
|
44
44
|
```bash
|
45
|
-
git clone
|
45
|
+
git clone https://github.com/klueless-io/k_starter
|
46
46
|
```
|
47
47
|
|
48
48
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests.
|
data/exe/k_starter
CHANGED
@@ -1,4 +1,19 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
|
+
lib_path = File.expand_path('../lib', __dir__)
|
5
|
+
$LOAD_PATH.unshift(lib_path) unless $LOAD_PATH.include?(lib_path)
|
6
|
+
|
4
7
|
require 'k_starter'
|
8
|
+
|
9
|
+
Signal.trap('INT') do
|
10
|
+
warn("\n#{caller.join("\n")}: interrupted")
|
11
|
+
exit(1)
|
12
|
+
end
|
13
|
+
|
14
|
+
begin
|
15
|
+
KStarter::CLI.start
|
16
|
+
rescue KStarter::CLI::Error => e
|
17
|
+
puts "ERROR: #{e.message}"
|
18
|
+
exit 1
|
19
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module KStarter
|
4
|
+
# Handle the global access such as configuration, project data
|
5
|
+
class App
|
6
|
+
class << self
|
7
|
+
def config
|
8
|
+
@config ||= KStarter::Database::ConfigModel.new
|
9
|
+
end
|
10
|
+
|
11
|
+
def project
|
12
|
+
@project ||= KStarter::Database::ProjectModel.new
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,198 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# require 'uri'
|
4
|
+
# require 'net/http'
|
5
|
+
# require 'active_model'
|
6
|
+
require 'pry'
|
7
|
+
|
8
|
+
# see: https://guides.rubyonrails.org/rails_application_templates.html
|
9
|
+
|
10
|
+
module KStarter
|
11
|
+
class AppGenerator < Rails::Generators::AppGenerator
|
12
|
+
# attr_reader :host
|
13
|
+
|
14
|
+
# attr_accessor :include_action_text
|
15
|
+
# alias_method :action_text?, :include_action_text
|
16
|
+
|
17
|
+
# attr_accessor :include_active_storage
|
18
|
+
# alias_method :active_storage?, :include_active_storage
|
19
|
+
|
20
|
+
# attr_accessor :include_sample_models
|
21
|
+
# alias_method :sample_models?, :include_sample_models
|
22
|
+
|
23
|
+
# attr_accessor :include_javascript_libraries
|
24
|
+
# alias_method :javascript_libraries?, :include_javascript_libraries
|
25
|
+
|
26
|
+
# attr_accessor :include_devise
|
27
|
+
# alias_method :devise?, :include_devise
|
28
|
+
|
29
|
+
# attr_accessor :include_rspec
|
30
|
+
# alias_method :rspec?, :include_rspec
|
31
|
+
|
32
|
+
# attr_accessor :include_common_pages
|
33
|
+
# alias_method :common_pages?, :include_common_pages
|
34
|
+
|
35
|
+
# attr_accessor :run_db_migrate
|
36
|
+
# alias_method :db_migrate?, :run_db_migrate
|
37
|
+
|
38
|
+
# *args
|
39
|
+
# def initialize([temp_folder], opts)
|
40
|
+
# @host = host
|
41
|
+
# end
|
42
|
+
|
43
|
+
# private
|
44
|
+
|
45
|
+
# def gac(message)
|
46
|
+
# host.git add: "."
|
47
|
+
# host.git commit: " -m '#{message}'"
|
48
|
+
# end
|
49
|
+
|
50
|
+
# def add_action_text
|
51
|
+
# # see: https://youtube.com/clip/UgkxzZBvcxkIX9zvWTi21KEJSTDMlC25LY0y
|
52
|
+
# rails_command "action_text:install"
|
53
|
+
# end
|
54
|
+
|
55
|
+
# def add_active_storage
|
56
|
+
# rails_command "active_storage:install"
|
57
|
+
# end
|
58
|
+
|
59
|
+
# def add_devise
|
60
|
+
# # run('bundle add devise')
|
61
|
+
# # Bundler.with_unbundled_env do
|
62
|
+
# # run 'bundle install'
|
63
|
+
# # rails_command("devise:install")
|
64
|
+
# # end
|
65
|
+
# rails_command("devise:install")
|
66
|
+
# # run("bundle install")
|
67
|
+
# end
|
68
|
+
|
69
|
+
# def add_gems
|
70
|
+
# gem 'devise' if devise?
|
71
|
+
# # gem 'friendly_id' if
|
72
|
+
# # gem 'sidekiq' if
|
73
|
+
# # gem 'name_of_person' if
|
74
|
+
# # gem 'cssbundling-rails'
|
75
|
+
# # gem 'pay' if
|
76
|
+
# # gem 'stripe' if
|
77
|
+
# end
|
78
|
+
|
79
|
+
# def add_gem_groups
|
80
|
+
# is_rspec = rspec?
|
81
|
+
# host.gem_group :development, :test do
|
82
|
+
# gem "rspec-rails" if is_rspec
|
83
|
+
# end
|
84
|
+
# end
|
85
|
+
|
86
|
+
# # def add_gems
|
87
|
+
# # gem 'devise', '~> 4.8'
|
88
|
+
# # gem 'friendly_id', '~> 5.4', '>= 5.4.2'
|
89
|
+
# # gem 'sidekiq', '~> 6.3', '>= 6.3.1'
|
90
|
+
# # gem 'name_of_person', '~> 1.1', '>= 1.1.1'
|
91
|
+
# # gem 'cssbundling-rails'
|
92
|
+
# # gem 'pay', '~> 3.0' # https://github.com/pay-rails/
|
93
|
+
# # gem 'stripe', '>= 2.8', '< 6.0' # I prefer Stripe but you can opt for braintree or paddle too. https://github.com/pay-rails/pay/blob/master/docs/1_installation.md#gemfile
|
94
|
+
# # end
|
95
|
+
|
96
|
+
# def add_rspec
|
97
|
+
# host.generate("rspec:install")
|
98
|
+
# end
|
99
|
+
|
100
|
+
# def bundle_add(name)
|
101
|
+
# host.run("bundle add #{name}")
|
102
|
+
# end
|
103
|
+
|
104
|
+
# # Generate - Controller, model, and view
|
105
|
+
# def g_scaffold(name, *args)
|
106
|
+
# host.generate(:scaffold, name, *args)
|
107
|
+
# end
|
108
|
+
|
109
|
+
# # Generate - Controller and model
|
110
|
+
# def g_resource(name, *args)
|
111
|
+
# host.generate(:resource, name, *args)
|
112
|
+
# end
|
113
|
+
|
114
|
+
# # Generate - Mailer for sending emails
|
115
|
+
# def g_mailer(name, *args)
|
116
|
+
# # see: https://youtube.com/clip/UgkxV9uIgkL7fbHYWAAN6UiwdS8dFXSO1j5y
|
117
|
+
# host.generate(:mailer, name, *args)
|
118
|
+
# end
|
119
|
+
|
120
|
+
# # ```bash
|
121
|
+
# # rm -rf kweb02-tailwind && rails new kweb02-tailwind --minimal
|
122
|
+
# # --javascript esbuild --css tailwind
|
123
|
+
# # ```
|
124
|
+
|
125
|
+
# def g_controller(name, *args)
|
126
|
+
# host.generate(:controller, name, *args)
|
127
|
+
# end
|
128
|
+
|
129
|
+
# def alter_first_file(glob, &block)
|
130
|
+
# file = Dir[glob].first
|
131
|
+
# instance_exec(file, &block)
|
132
|
+
# # yield(file) if file
|
133
|
+
# end
|
134
|
+
|
135
|
+
# def add_environment(value, env: 'development')
|
136
|
+
# # injects value into corresponding config/environment file.
|
137
|
+
# host.environment(value, env: env)
|
138
|
+
# end
|
139
|
+
|
140
|
+
# def add_file(path, content)
|
141
|
+
# host.file(path, content)
|
142
|
+
# end
|
143
|
+
|
144
|
+
# # env: 'production'
|
145
|
+
# # sudo: true
|
146
|
+
# # abort_on_failure: true
|
147
|
+
# def rails_command(command, **args)
|
148
|
+
# host.rails_command(command, **args)
|
149
|
+
# end
|
150
|
+
|
151
|
+
# def run(command)
|
152
|
+
# host.run(command)
|
153
|
+
# end
|
154
|
+
|
155
|
+
# def yes?(question, default: true)
|
156
|
+
# # see: https://github.com/rails/thor/blob/main/lib/thor/shell/basic.rb
|
157
|
+
# answer = host.ask(question, default: default)
|
158
|
+
# ActiveModel::Type::Boolean.new.cast(answer)
|
159
|
+
# end
|
160
|
+
|
161
|
+
# def no?(question, default: false)
|
162
|
+
# answer = host.ask(question, default: default)
|
163
|
+
# ActiveModel::Type::Boolean.new.cast(answer)
|
164
|
+
# end
|
165
|
+
|
166
|
+
# def settings_for_asset_management
|
167
|
+
# # see: https://noelrappin.com/blog/2021/09/rails-7-and-javascript/
|
168
|
+
|
169
|
+
# # This needs to be handled using command line options at the moment,
|
170
|
+
# # in future I may call AppGenerator.new directly with these options.
|
171
|
+
|
172
|
+
# # if you need transpiling then you need to install the esbuild-rails
|
173
|
+
# # if you don't need transpiling (or node dependencies) then you can use importmap-rails
|
174
|
+
# # see: https://d31d9mzh2cw851.cloudfront.net/wp-content/uploads/2022/02/10014354/Do-I-need-Importmap-FINAL2.jpg
|
175
|
+
|
176
|
+
# # if using javascript bundling then you can use:
|
177
|
+
# # webpack (old/bad)
|
178
|
+
# # esbuild (new/good)
|
179
|
+
# # rollup (good)
|
180
|
+
# #
|
181
|
+
# # use this if you are working with react or vue:
|
182
|
+
# # is a single page app
|
183
|
+
|
184
|
+
# # alternative: importmap-rails does not do mapping and has a one to one relationship between files and browser
|
185
|
+
# # use this if you are working with hotwire (turbo/stimulas)
|
186
|
+
# # feels like a single page app, but using dynamic server side
|
187
|
+
|
188
|
+
# # css bundling (investigate cssbundling-rails)
|
189
|
+
|
190
|
+
# # hotwire: hotwire-rails
|
191
|
+
|
192
|
+
# # Use importmap if you are not using much JS, you’ll get a great developer experience
|
193
|
+
# # at the cost of some limited interaction with the JS world.
|
194
|
+
|
195
|
+
# # Use one of the jsbundler tools if you want more interaction with the JS world.
|
196
|
+
# end
|
197
|
+
end
|
198
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'thor'
|
4
|
+
|
5
|
+
module KStarter
|
6
|
+
# Handle the application command line parsing
|
7
|
+
# and the dispatch to various command objects
|
8
|
+
#
|
9
|
+
# @api public
|
10
|
+
class CLI < Thor
|
11
|
+
# Error raised by this runner
|
12
|
+
Error = Class.new(StandardError)
|
13
|
+
|
14
|
+
desc 'version', 'k_starter version'
|
15
|
+
def version
|
16
|
+
require_relative 'version'
|
17
|
+
puts "v#{KStarter::VERSION}"
|
18
|
+
end
|
19
|
+
map %w[--version -v] => :version
|
20
|
+
|
21
|
+
#
|
22
|
+
# config
|
23
|
+
#
|
24
|
+
# desc 'config KEYVALUE', 'Config description'
|
25
|
+
# method_option :help, aliases: '-h',
|
26
|
+
# type: :boolean,
|
27
|
+
# desc: 'Display usage information'
|
28
|
+
# def config(key, value)
|
29
|
+
# if options[:help]
|
30
|
+
# invoke :help, ['config']
|
31
|
+
# else
|
32
|
+
# KStarter::Commands::Configuration::Menu.new(key, value, options).execute
|
33
|
+
# end
|
34
|
+
# end
|
35
|
+
|
36
|
+
#
|
37
|
+
# configuration
|
38
|
+
#
|
39
|
+
desc 'configuration SUBCOMMAND', 'Manage configuration'
|
40
|
+
method_option :help, aliases: '-h',
|
41
|
+
type: :boolean,
|
42
|
+
desc: 'Display usage information'
|
43
|
+
def configuration(subcommand = :menu)
|
44
|
+
if options[:help]
|
45
|
+
invoke :help, ['configuration']
|
46
|
+
else
|
47
|
+
KStarter::Commands::ConfigurationMenu.new(subcommand, options).execute
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
#
|
52
|
+
# project
|
53
|
+
#
|
54
|
+
desc 'project SUBCOMMAND', 'Create or edit project settings or generate new project'
|
55
|
+
def project(subcommand = :menu)
|
56
|
+
if options[:help]
|
57
|
+
invoke :help, ['project']
|
58
|
+
else
|
59
|
+
KStarter::Commands::ProjectMenu.new(subcommand, options).execute
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
|
@@ -0,0 +1,54 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'forwardable'
|
4
|
+
|
5
|
+
module KStarter
|
6
|
+
module Commands
|
7
|
+
# Base command class
|
8
|
+
class Command
|
9
|
+
extend Forwardable
|
10
|
+
include TtyHelpers
|
11
|
+
|
12
|
+
def_delegators :command, :run
|
13
|
+
|
14
|
+
attr_reader :escape_pressed
|
15
|
+
|
16
|
+
# Execute this command
|
17
|
+
#
|
18
|
+
# @api public
|
19
|
+
def execute(*)
|
20
|
+
raise(
|
21
|
+
NotImplementedError,
|
22
|
+
"#{self.class}##{__method__} must be implemented"
|
23
|
+
)
|
24
|
+
end
|
25
|
+
|
26
|
+
def ask_questions(form_type, form_variant = nil, **data)
|
27
|
+
KStarter::Questions::AskQuestions.for(form_type, form_variant, **data)
|
28
|
+
end
|
29
|
+
|
30
|
+
def display_exiting_projects
|
31
|
+
columns = %w[Name Type Path Description]
|
32
|
+
rows = App.project.project_list.map do |project|
|
33
|
+
[
|
34
|
+
project.name,
|
35
|
+
project.type,
|
36
|
+
project.variant,
|
37
|
+
project.root_path,
|
38
|
+
project.description
|
39
|
+
]
|
40
|
+
end
|
41
|
+
|
42
|
+
table = TTY::Table.new(columns, rows)
|
43
|
+
puts table.render(:unicode)
|
44
|
+
prompt.warn('-' * 100)
|
45
|
+
end
|
46
|
+
|
47
|
+
def select_project
|
48
|
+
choices = App.project.project_list.map(&:name)
|
49
|
+
name = prompt.select('Select a project?', choices, cycle: true)
|
50
|
+
App.project.find_project(name)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module KStarter
|
4
|
+
module Commands
|
5
|
+
# Submenu for configuration
|
6
|
+
class ConfigurationMenu < KStarter::Commands::Command
|
7
|
+
def initialize(subcommand, options)
|
8
|
+
@subcommand = (subcommand || '').to_sym
|
9
|
+
|
10
|
+
@options = options
|
11
|
+
super()
|
12
|
+
end
|
13
|
+
|
14
|
+
def execute(input: $stdin, output: $stdout)
|
15
|
+
command = nil
|
16
|
+
case @subcommand
|
17
|
+
when :menu
|
18
|
+
menu
|
19
|
+
when :open_config
|
20
|
+
editor.open(App.config.filename)
|
21
|
+
menu
|
22
|
+
when :open_project
|
23
|
+
editor.open(App.project.filename)
|
24
|
+
menu
|
25
|
+
end
|
26
|
+
command&.execute(input: input, output: output) if command
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def menu
|
32
|
+
choices = [
|
33
|
+
{ name: 'Open configuration JSON', value: :open_config },
|
34
|
+
{ name: 'Open project JSON', value: :open_project }
|
35
|
+
]
|
36
|
+
|
37
|
+
subcommand = prompt.select('Select your subcommand?', choices, per_page: 15, cycle: true)
|
38
|
+
|
39
|
+
command = KStarter::Commands::ConfigurationMenu.new(subcommand, {})
|
40
|
+
command.execute(input: @input, output: @output)
|
41
|
+
rescue KStarter::EscapePressed
|
42
|
+
nil
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module KStarter
|
4
|
+
module Commands
|
5
|
+
# Submenu for new
|
6
|
+
class BootstrapProject < KStarter::Commands::Command
|
7
|
+
def initialize(**options)
|
8
|
+
@options = options
|
9
|
+
super()
|
10
|
+
end
|
11
|
+
|
12
|
+
def execute(input: $stdin, output: $stdout)
|
13
|
+
display_exiting_projects
|
14
|
+
project = select_project
|
15
|
+
|
16
|
+
# Is the if project even relevant at the moment?
|
17
|
+
bootstrap_project(project) if project
|
18
|
+
end
|
19
|
+
|
20
|
+
def bootstrap_project(project)
|
21
|
+
puts JSON.pretty_generate(project.to_h)
|
22
|
+
|
23
|
+
starter = KStarter::Map.starter(project)
|
24
|
+
starter.execute
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module KStarter
|
4
|
+
module Commands
|
5
|
+
# Submenu for new
|
6
|
+
class EditProject < KStarter::Commands::Command
|
7
|
+
def initialize(**options)
|
8
|
+
@options = options
|
9
|
+
super()
|
10
|
+
end
|
11
|
+
|
12
|
+
def execute(input: $stdin, output: $stdout)
|
13
|
+
display_exiting_projects
|
14
|
+
project = select_project
|
15
|
+
|
16
|
+
# Is the if project even relevant at the moment?
|
17
|
+
edit_project(project) if project
|
18
|
+
end
|
19
|
+
|
20
|
+
def edit_project(project)
|
21
|
+
form_type = project.type.to_sym
|
22
|
+
form_variant = project.variant&.to_sym
|
23
|
+
|
24
|
+
questions = ask_questions(form_type, form_variant, **project.to_h)
|
25
|
+
questions.ask_questions
|
26
|
+
|
27
|
+
puts JSON.pretty_generate(questions.to_h)
|
28
|
+
App.project.save_project(questions)
|
29
|
+
rescue KStarter::EscapePressed
|
30
|
+
prompt.warn 'Exiting without saving'
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module KStarter
|
4
|
+
module Commands
|
5
|
+
# Command Name goes here
|
6
|
+
class NewProject < KStarter::Commands::Command
|
7
|
+
attr_reader :form_type
|
8
|
+
attr_reader :form_variant
|
9
|
+
|
10
|
+
def initialize(form_type:, form_variant:)
|
11
|
+
@form_type = form_type
|
12
|
+
@form_variant = form_variant
|
13
|
+
|
14
|
+
super()
|
15
|
+
end
|
16
|
+
|
17
|
+
def execute(input: $stdin, output: $stdout)
|
18
|
+
questions = ask_questions(form_type, form_variant)
|
19
|
+
questions.ask_questions
|
20
|
+
|
21
|
+
puts JSON.pretty_generate(questions.to_h)
|
22
|
+
App.project.save_project(questions)
|
23
|
+
rescue KStarter::EscapePressed
|
24
|
+
prompt.warn 'Exiting without saving'
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|