lib/gamefic-sdk/shell.rb in gamefic-sdk-1.6.0 vs lib/gamefic-sdk/shell.rb in gamefic-sdk-1.7.0

- old
+ new

@@ -7,11 +7,12 @@ autoload :Init, 'gamefic-sdk/shell/init' autoload :Test, 'gamefic-sdk/shell/test' map %w[--version -v] => :version map [:create, :new] => :init - + map ['scripts'] => :script + desc "--version, -v", "Print the version" def version puts "gamefic-sdk #{Gamefic::Sdk::VERSION}" puts "gamefic #{Gamefic::VERSION}" end @@ -56,41 +57,92 @@ desc 'clean [DIRECTORY_NAME]', 'Perform cleanup of DIRECTORY_NAME' def clean(directory_name = '.') Gamefic::Sdk::Build.clean(directory_name) end - desc 'import-scripts [DIRECTORY_NAME]', 'Copy external scripts to the local scripts directory' - def import_scripts(directory_name = '.') - config_yaml = File.join(directory_name, 'config.yaml') - if File.exist?(config_yaml) - config_path = PlotConfig.new config_yaml - else - config_path = PlotConfig.new - end - FileUtils.mkdir_p(File.join(directory_name, 'scripts')) - paths = config_path.script_paths + [Gamefic::Sdk::GLOBAL_SCRIPT_PATH] + desc 'import [DIRECTORY_NAME]', 'Copy external scripts to the project' + option :quiet, type: :boolean, aliases: :q, desc: 'Suppress output' + def import(directory_name = '.') + config = Gamefic::Sdk::Config.load directory_name + FileUtils.remove_entry_secure config.import_path if File.exist?(config.import_path) + FileUtils.mkdir_p config.import_path + paths = [config.script_path, Gamefic::Sdk::GLOBAL_SCRIPT_PATH] plot = Gamefic::Sdk::Debug::Plot.new Source::File.new(*paths) plot.script 'main' plot.imported_scripts.each { |s| + next unless s.absolute_path.start_with?(Gamefic::Sdk::GLOBAL_SCRIPT_PATH) src = File.absolute_path(s.absolute_path) - dst = File.absolute_path(File.join(directory_name, 'scripts', "#{s.path}.plot.rb")) + dst = File.absolute_path(File.join(directory_name, 'imports', "#{s.path}.plot.rb")) next if src == dst - puts "Importing #{s.path}" + puts "Importing #{s.path}" unless options[:quiet] FileUtils.mkdir_p(File.dirname(dst)) FileUtils.cp_r(src, dst) } end - desc 'reset-package [DIRECTORY_NAME]', 'Reset package.yaml to the default values' - def reset_config(directory_name = '.') - + desc 'default-config [DIRECTORY_NAME]', 'Create or overwrite config.yml with default values' + def default_config(directory_name = '.') + File.open(File.join(directory_name, 'config.yml'), 'w') do |file| + file << Gamefic::Sdk::Config.generate + end + puts "Default config.yml created." end desc 'webskins', 'List the available skins for the Web platform' def webskins Dir[File.join(Gamefic::Sdk::HTML_TEMPLATE_PATH, 'skins', '*')].sort.each { |d| puts File.basename(d) } + end + + desc 'script [PATH]', 'List or document the scripts in the SDK' + def script path = nil + if path.nil? + s = [] + Dir[File.join GLOBAL_SCRIPT_PATH, '**', '*.rb'].each { |f| + c = File.read(f) + c.each_line { |l| + match = l.match(/[\s]*#[\s]*@gamefic.script[ ]+([a-z0-9\/]+)/) + unless match.nil? + s.push(match[1]) + end + } + } + puts s.sort.join("\n") + else + document_script path + end + end + + private + + def document_script path + f = File.join(GLOBAL_SCRIPT_PATH, "#{path}.plot.rb") + if File.exist?(f) + c = File.read(f) + doc = '' + in_comment = false + c.each_line { |l| + if in_comment + break unless l.start_with?('#') + doc += "#{l[2..-1]}" + else + match = l.match(/[\s]*#[\s]*@gamefic.script[ ]+([a-z0-9\/]+)/) + in_comment = true unless match.nil? + end + } + if in_comment + puts '' + puts path + puts '' + puts doc unless doc == '' + puts '' unless doc == '' + else + puts "Path '#{path}' is not documented." + end + else + puts "Script path '#{path}' does not exist." + end end end end end