lib/lhj/command/yapi.rb in lhj-tools-0.1.64 vs lib/lhj/command/yapi.rb in lhj-tools-0.1.65
- old
+ new
@@ -104,11 +104,14 @@
end
def save_to_file
@model_names = []
file_name = gen_model_name('')
- h_file = File.join('.', "#{file_name}.h")
- m_file = File.join('.', "#{file_name}.m")
+ time = Time.now
+ folder_name = time.strftime('%Y%m%d%H%M%S')
+ FileUtils.mkdir_p(File.expand_path(folder_name, '.')) unless File.exist?(File.expand_path(folder_name, '.'))
+ h_file = File.join('.', folder_name, "#{file_name}.h")
+ m_file = File.join('.', folder_name, "#{file_name}.m")
File.write(h_file, @h_file_array.join("\n")) if @h_file_array.count.positive?
File.write(m_file, @m_file_array.join("\n")) if @m_file_array.count.positive?
puts "\n\n生成文件成功!所在路径:\n#{File.expand_path(h_file)} \n#{File.expand_path(m_file)}".green
end