lib/xing/cli/generators/new_project.rb in xing-framework-0.2.6 vs lib/xing/cli/generators/new_project.rb in xing-framework-0.2.7.pre.beta1
- old
+ new
@@ -1,14 +1,14 @@
require 'caliph'
require 'bundler'
-require 'architecture/dsl'
require 'securerandom'
+require 'xing/cli/templaters'
+require 'xing/cli/generators/new_project/user_input'
module Xing::CLI::Generators
class NewProject
include Caliph::CommandLineDSL
- include Architecture
attr_accessor :target_name
attr_accessor :ruby_version
attr_accessor :with_gemset
@@ -18,10 +18,13 @@
attr_writer :shell
# For the moment, this is the simplest thing that can work. Zero templating
# is done so the project will still have the default module names etc.
def generate
+
+ user_input.gather
+
command = cmd('cp', '-a', File.expand_path('../../../../../default_configuration/base_app/', __FILE__), target_name)
result = shell.run(command)
unless result.succeeded?
raise "Attempt to copy base application to #{target_name} failed!"
@@ -35,15 +38,16 @@
write_ruby_gemset
write_ruby_gemset "frontend"
write_ruby_gemset "backend"
end
- write_database_yml
- write_secrets_yml
+ database_yml_templater.template
+ secrets_yml_templater.template
+ control_files_templater.template
+ doc_files_templater.template
+ code_of_conduct_templater.template
- write_git_control_files
-
Bundler.with_clean_env do
if with_gemset
bundler = shell.run(setup_env_command &
cmd("cd", target_name) &
cmd("gem", "install", "bundler"))
@@ -67,54 +71,58 @@
cmd("rake", "xing:install:migrations")).must_succeed!
end
end
- def write_database_yml
- dbyml_path = File.join(target_name, "backend", "config", "database.yml")
- if !File.exist?(dbyml_path)
- with_templates do |arc|
- arc.copy file: "backend/config/database.yml", context: { app_name: target_name }
- arc.copy file: "backend/config/database.yml.example", context: { app_name: target_name }
- arc.copy file: "backend/config/database.yml.ci", context: { app_name: target_name }
- end
+ def database_yml_templater
+ @database_yml_templater ||= begin
+ dbyml_path = File.join(target_name, "backend", "config", "database.yml")
+ Xing::CLI::Templaters::DatabaseYmlTemplater.new(target_name, context, File.exist?(dbyml_path))
end
end
- def write_git_control_files
- with_templates do |arc|
- arc.copy file: "gitignore", as: ".gitignore"
- arc.copy file: "backend/gitignore", as:"backend/.gitignore"
- arc.copy file: "frontend/gitignore", as: "frontend/.gitignore"
- arc.copy file: "gitattributes", as: ".gitattributes"
- arc.copy file: "backend/gitattributes", as: "backend/.gitattributes"
- arc.copy file: "frontend/gitattributes", as: "frontend/.gitattributes"
- end
+ def control_files_templater
+ @control_files_templater ||= Xing::CLI::Templaters::ControlFilesTemplater.new(
+ target_name, context)
end
- def write_secrets_yml
- secyml_path = File.join(target_name, "backend", "config", "secrets.yml")
- if !File.exist?(secyml_path)
- context = {
- dev_secret_key_base: SecureRandom.hex(64),
- test_secret_key_base: SecureRandom.hex(64),
- app_name: target_name
- }
- with_templates do |arc|
- arc.copy file: "backend/config/secrets.yml", context: context
- arc.copy file: "backend/config/secrets.yml.example", context: context
- arc.copy file: "backend/config/secrets.yml.ci", context: context
- end
- end
+ def doc_files_templater
+ @doc_files_templater ||= Xing::CLI::Templaters::DocFilesTemplater.new(
+ target_name,
+ context.merge({
+ code_of_conduct_reference: (user_input.code_of_conduct ?
+ "All contributors must abide by the [Code of Conduct](CODE_OF_CONDUCT.md)" : "")
+ }))
end
- def with_templates
- architecture source: File.expand_path('../../../../../default_configuration/templates/', __FILE__) , destination: target_name do |arc|
- yield(arc)
+ def secrets_yml_templater
+ @secrets_yml_templater ||= begin
+ secyml_path = File.join(target_name, "backend", "config", "secrets.yml")
+ Xing::CLI::Templaters::SecretsYmlTemplater.new(
+ target_name,
+ context.merge({
+ dev_secret_key_base: SecureRandom.hex(64),
+ test_secret_key_base: SecureRandom.hex(64),
+ }),
+ File.exist?(secyml_path)
+ )
end
end
+ def code_of_conduct_templater
+ @code_of_conduct_templater ||= Xing::CLI::Templaters::CodeOfConductTemplater.new(
+ target_name,
+ context.merge({
+ email: user_input.coc_contact_email
+ }),
+ !user_input.code_of_conduct)
+ end
+
+ def context
+ { app_name: target_name }
+ end
+
def write_file_to(name, subdir)
File.open(File.join(*([target_name] + subdir + [name])), "w") do |rv|
yield(rv)
end
end
@@ -139,7 +147,12 @@
else
# put other rb environemnt scripts here
cmd(":")
end
end
+
+ def user_input
+ @user_input ||= UserInput.new
+ end
+
end
end