bin/bs in blade-setting-0.2.2 vs bin/bs in blade-setting-0.2.3
- old
+ new
@@ -11,11 +11,11 @@
end
def ok
prompt = TTY::Prompt.new
prompt.ok("generate complete ! check files now")
- exit(0);
+ cli
end
def fail()
prompt = TTY::Prompt.new
prompt.warn("generate failed ! check error above")
@@ -31,85 +31,104 @@
exit(0);
end
require_relative '../lib/blade/setting'
-menu_result = prompt.collect do
- key(:menu).select('select the menu you want to do') do |menu|
- menu.choice "Generate yml and setting logic files", 1
- menu.choice "Generate Model's crud scaffold", 2
- menu.choice "Add graphql base file to your project", 3
- menu.choice "Add Doorkeeper Token to project", 4
- menu.choice "Add Base File for project [response.rb,application.json.jbuilder, application.helper, base_model_concern]", 0
+def cli
+ prompt = TTY::Prompt.new
+ menu_result = prompt.collect do
+ key(:menu).select('select the menu you want to do') do |menu|
+ menu.choice "Generate yml and setting logic files", 1
+ menu.choice "Generate Model's crud scaffold", 2
+ menu.choice "Add graphql base file to your project", 3
+ menu.choice "Add Doorkeeper Token to project", 4
+ menu.choice "Add Base File for project [response.rb,application.json.jbuilder, application.helper, base_model_concern]", 0
+ menu.choice "Generate Swagger doc file by Model Module", 5
+ end
end
-end
-case menu_result[:menu]
-when 1
- result = prompt.collect do
- key(:setting_path).ask('The generated config file path', default: '/app/settings')
+ case menu_result[:menu]
+ when 1
+ result = prompt.collect do
+ key(:setting_path).ask('The generated config file path', default: '/app/settings')
- setting_choices = %w(redis sentry database influxdb scout_apm send_cloud elastic_search wechat carrierwave)
+ setting_choices = %w(redis sentry database influxdb scout_apm send_cloud elastic_search wechat carrierwave)
- prompt.say('Please select the config file you want to generate,
+ prompt.say('Please select the config file you want to generate,
(Use arrow keys, press Space to select and Enter to finish, and letter keys to filter)')
- key(:configs).multi_select('check configs',
- setting_choices, filter: true)
+ key(:configs).multi_select('check configs',
+ setting_choices, filter: true)
- key(:yml_path).ask('The generated yml path', default: '/environments')
+ key(:yml_path).ask('The generated yml path', default: '/environments')
- key(:extra_yml_path).ask('Other environment? (Input words like sit,dit,prod)', default: 'dev,sit,dit,prod') do |q|
- q.convert -> (input) {input.split(/,\s*/)}
+ key(:extra_yml_path).ask('Other environment? (Input words like sit,dit,prod)', default: 'dev,sit,dit,prod') do |q|
+ q.convert -> (input) {input.split(/,\s*/)}
+ end
end
- end
- prompt.ok('config complete')
- prompt.warn("generating files ...plz don't quit")
+ prompt.ok('config complete')
+ prompt.warn("generating files ...plz don't quit")
#生成setting logic
- Blade::BladeSetting.generate_setting_logic(result[:setting_path], result[:configs])
+ Blade::BladeSetting.generate_setting_logic(result[:setting_path], result[:configs])
- prompt.warn('generating yml files ...')
- Blade::BladeSetting.generate_setting_yml(result[:yml_path], result[:extra_yml_path], result[:configs])
+ prompt.warn('generating yml files ...')
+ Blade::BladeSetting.generate_setting_yml(result[:yml_path], result[:extra_yml_path], result[:configs])
- prompt.ok("generate complete ! check files now")
+ prompt.ok("generate complete ! check files now")
-when 2
- model_result = prompt.collect do
- key(:model_name).ask('enter the model name')
- key(:namespace).ask('enter the controller namespace', default: 'api')
- end
- ActiveRecord::Base.connection
- model = Blade::BladeSetting.get_model(model_result[:model_name].classify)
- if (model.blank?)
- prompt.error("Model doesn't exist")
- exit(0);
- end
- prompt.warn("generating files ...please don't quit")
- Blade::BladeSetting.generate_model_template(model,model_result[:model_name])
- Blade::BladeSetting.generate_crud(model,model_result[:model_name], model_result[:namespace])
- ok();
+ when 2
+ model_result = prompt.collect do
+ key(:model_name).ask('enter the model name')
+ key(:namespace).ask('enter the controller namespace', default: 'api')
+ end
+ ActiveRecord::Base.connection
+ model = Blade::BladeSetting.get_model(model_result[:model_name].classify)
+ if (model.blank?)
+ prompt.error("Model doesn't exist")
+ exit(0);
+ end
+ prompt.warn("generating files ...please don't quit")
+ Blade::BladeSetting.generate_model_template(model, model_result[:model_name])
+ Blade::BladeSetting.generate_crud(model, model_result[:model_name], model_result[:namespace])
+ ok();
-when 3
+ when 3
-when 4
- token_result = prompt.collect do
- key(:app_name).ask('Enter the app name', default: 'My app')
- key(:uri).ask('enter the redirect uri', default: 'localhost:3000')
- end
- if (!defined? Doorkeeper)
- Blade::BladeSetting.generate_gem('doorkeeper')
- prompt.error('You should install doorkeeper first')
- else
- app = Doorkeeper::Application.new(name: token_result[:app_name], redirect_uri: token_result[:uri], scopes: token_result[:uri])
- app.save!
- end
- fail()
+ when 4
+ token_result = prompt.collect do
+ key(:app_name).ask('Enter the app name', default: 'My app')
+ key(:uri).ask('enter the redirect uri', default: 'http://localhost:3000')
+ end
+ if (!defined? Doorkeeper)
+ Blade::BladeSetting.generate_gem('doorkeeper')
+ prompt.error('You should install doorkeeper first')
+ fail()
+ else
+ app = Doorkeeper::Application.new(name: token_result[:app_name], redirect_uri: token_result[:uri], scopes: token_result[:uri])
+ app.save!
+ prompt.ok("The Uid is #{app.uid}")
+ prompt.ok("The secret key is #{app.secret}")
+ end
+ ok()
-when 0
- Blade::BladeSetting.generate_base_files
- ok();
+ when 5
+ doc_result = prompt.collect do
+ key(:model).ask('Enter the module name', default: 'user')
+ end
+ doc_name_result = prompt.collect do
+ key(:name).ask('Enter the module name', default: doc_result[:model])
+ end
+ Blade::BladeSetting.generate_doc(doc_result[:model], doc_name_result[:name])
+ ok()
+ when 0
+ Blade::BladeSetting.generate_base_files
+ ok();
+ end
end
+
+cli
+