lib/susanoo/cli/project.rb in susanoo-0.8.0 vs lib/susanoo/cli/project.rb in susanoo-0.10.0
- old
+ new
@@ -12,16 +12,23 @@
map 's' => :server
map 'g' => :generate
map 'r' => :run_in
map 'd' => :destroy
+ map 'b' => :build
+ # Set the project root
def self.root=(path)
@@root = path
Susanoo::Project.path = path
end
+ # Set source paths for current generator
+ def self.source_root
+ "#{@@root}/src"
+ end
+
desc 'generate GENERATOR [options]', 'Run the given generator'
def generate(generator_name = nil, *options)
generator = get_the_generator_class generator_name
# Run the generator with given options
generator.start(options, behavior: :invoke,
@@ -66,10 +73,12 @@
def build
project_root = Susanoo::Project.path
require File.join(project_root, 'config/routes')
+ router = ROUTER.instance_variable_get('@router')
+
build_dir = File.join(project_root, 'www')
# setup build directory
remove_file build_dir if File.exist? build_dir
# Create the www directory if there isn't
@@ -78,19 +87,20 @@
#
# NOTE: cordova only uses this directory
# and we can't change it as far as I know
empty_directory build_dir
- Susanoo::StaticGenerator.classes.each do |klass|
- instance = klass.new
- if instance.respond_to? :build
- instance.build(self)
+ router.routes.each do |route|
+ controller = route.dest
+ if controller.respond_to? :build
+ say_status 'build', "Controller: #{controller.__getobj__.class}"
+ controller.build(self, route.dup)
else
- puts "[Warning]: '#{instance.class.to_s}' does not have 'build' method."
+ say_status 'warning', "#{controller.__getobj__.class.to_s}' does not have 'build' method.",
+ :yellow
end
end
-
end
desc 'run PLATFORM', 'Run application on PLATFORM.'
def run_in(platform = :android)
# Build the project first
@@ -115,11 +125,11 @@
begin
klass = generator_name.downcase.camelize
generator = Susanoo::Generators.const_get(klass)
rescue NameError
- print '[Error]:'.colorize(:red)
- say "Generator `#{generator}` not found."
+ say_status 'Error', "Generator `#{generator_name}` not found.",
+ :red
exit 1
end
generator
end