lib/ninjs/project.rb in ninjs-0.14.1 vs lib/ninjs/project.rb in ninjs-0.16.0
- old
+ new
@@ -1,39 +1,47 @@
module Ninjs
class Project
attr_reader :root,
:config,
:modules
-
-
- def initialize(name = nil)
- if name.nil?
- raise ArgumentError, "Ninjs::Project.new(name): name is required without a configuration file" unless File.exists? 'ninjs.conf'
- end
+
+ def initialize(options = nil)
+ settings = {
+ name: nil,
+ root: Dir.getwd
+ }
- @root = File.expand_path Dir.getwd
+ settings.merge!(options) unless options.nil?
+
+ @name = settings[:name]
+ @root = File.expand_path(settings[:root])
+
+ if @name.nil?
+ raise ArgumentError, "Ninjs::Project.new({ name: 'Name' }): name is required without a configuration file" unless File.exists? "#{@root}/ninjs.conf"
+ end
+
@modules = Array.new
@config = Ninjs::Configuration.new @root
- @config.setting :name, name unless name.nil?
+ @config.name = @name unless @name.nil?
end
-
+
def root=(path)
@root = File.expand_path path
@config.root = @root
@config.asset_root = @root
end
-
+
def create
puts Ninjs::Notification.notice "Creating the #{@config.name} project in #{@root}"
create_project_scaffold
@config.write
create_ninjs_lib_file
create_utility_lib_file
create_ninjs_application_file
import_test_files
end
-
+
def create_project_scaffold
Dir.mkdir "#{@root}" unless File.exists? "#{@root}"
Ninjs::Manifest.directories.each do |folder|
puts Ninjs::Notification.added "#{folder} created" unless File.exists? "#{@root}/#{folder}"
Dir.mkdir "#{@root}/#{folder}" unless File.exists? "#{@root}/#{folder}"
@@ -43,33 +51,33 @@
def create_ninjs_lib_file
operation = File.exists?("#{@root}/lib/nin.js") ? 'updated' : 'created'
ninjs_lib_secretary = Sprockets::Secretary.new(
:root => "#{Ninjs::BASE_DIR}",
:load_path => ["repository"],
- :source_files => ["repository/ninjs/core/nin.js"]
+ source_files: ["repository/ninjs/core/nin.js"]
)
ninjs_lib_secretary.concatenation.save_to "#{@root}/lib/nin.js"
puts Ninjs::Notification.added "lib/nin.js #{operation}"
end
def create_utility_lib_file
utility_lib_secretary = Sprockets::Secretary.new(
- :root => "#{Ninjs::BASE_DIR}",
- :load_path => ["repository"],
- :source_files => ["repository/ninjs/utilities/all.js"]
+ root: "#{Ninjs::BASE_DIR}",
+ load_path: ["repository"],
+ source_files: ["repository/ninjs/utilities/all.js"]
)
utility_lib_secretary.concatenation.save_to "#{@root}/lib/utilities.js"
puts Ninjs::Notification.added "lib/utilities.js created"
end
def create_ninjs_application_file
File.open("#{@root}/application/#{@config.name.downcase}.js", "w+") do |file|
- file << "//-- Ninjs #{Time.now.to_s} --//\n"
+ file << "//-- This file was automatically generated by Ninjs @ #{Time.now.to_s} DO NOT EDIT THIS FILE --//\n"
file << File.open("#{@root}/lib/nin.js", 'r').readlines.join('')
file << "\nvar #{@config.name} = new NinjsApplication();"
end
end
@@ -102,21 +110,21 @@
def get_modules
@modules = Array.new
if @config.src_dir.is_a? Array
@config.src_dir.each do |directory|
- add_scripts_to_models File.expand_path "#{directory}"
+ add_scripts_to_models File.expand_path(directory, @root)
end
else
- add_scripts_to_models File.expand_path "#{@config.src_dir}"
+ add_scripts_to_models File.expand_path(@config.src_dir, @root)
end
end
def add_scripts_to_models(directory)
Dir["#{directory}/*.js"].each do |file|
module_filename = file.gsub(directory, '')
- @modules << "#{directory}#{module_filename}" unless module_filename.match(/^_/)
+ @modules << "#{directory}#{module_filename}" unless module_filename.match(/^\/_/)
end
end
def compile_modules
@modules.each do |module_file|
@@ -129,11 +137,11 @@
begin
ninjs_lib_secretary = Sprockets::Secretary.new(
:root => "#{Ninjs::BASE_DIR}",
:asset_root => @config.asset_root,
:load_path => ["repository"],
- :source_files => ["#{module_file}"]
+ source_files: ["#{module_file}"]
)
module_file = ninjs_lib_secretary.concatenation
message = File.exists?("#{@root}/#{@config.dest_dir}/#{module_name}.js") ? "\e[32m>>>\e[0m #{@config.dest_dir}/#{module_name}.js updated" : "\e[32m>>>\e[0m #{@config.dest_dir}/#{module_name}.js created"
module_file.save_to "#{@root}/#{@config.dest_dir}/#{module_name}.js"
@@ -183,11 +191,11 @@
begin
ninjs_lib_secretary = Sprockets::Secretary.new(
:root => "#{Ninjs::BASE_DIR}",
:asset_root => @config.asset_root,
:load_path => ["repository"],
- :source_files => ["#{file}"]
+ source_files: ["#{file}"]
)
application_file = ninjs_lib_secretary.concatenation
ninjs_lib_secretary.install_assets
application_file.save_to "#{file}"
@@ -209,9 +217,7 @@
module_file << JSMin.minify(uncompressed)
end
end
end
- end
- # class Project
-end
-#module Ninjs
+ end # class Project
+end # module Ninjs
\ No newline at end of file