lib/lhj/command/yapi.rb in lhj-tools-0.1.80 vs lib/lhj/command/yapi.rb in lhj-tools-0.1.81

- old
+ new

@@ -97,10 +97,16 @@ puts str.blue @m_file_array ||= [] @m_file_array << str end + def puts_mock(str) + puts str.green + @req_mock_array ||= [] + @req_mock_array << str + end + def sub_folder_name return @sub_folder_name if @sub_folder_name time = Time.now @sub_folder_name ||= time.strftime('%Y%m%d%H%M%S') @@ -112,18 +118,23 @@ file_name = gen_model_name FileUtils.mkdir_p(File.expand_path(sub_folder_name, '.')) unless File.exist?(File.expand_path(sub_folder_name, '.')) h_file = File.join('.', sub_folder_name, "#{file_name}.h") m_file = File.join('.', sub_folder_name, "#{file_name}.m") service_file = File.join('.', sub_folder_name, "#{model_pre}#{name}Service.m") + req_mock_file = File.join('.', sub_folder_name, "#{model_pre}#{name}Mock.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? File.write(service_file, service_code) if service_code + File.write(req_mock_file, @req_mock_array.join("\n")) if @req_mock_array.count.positive? + puts "\n\n生成文件成功!所在路径:\n#{File.expand_path(h_file)} \n#{File.expand_path(m_file)}".green if @save && !@notify { h_file: "#{sub_folder_name}/#{file_name}.h", m_file: "#{sub_folder_name}/#{file_name}.m", - s_file: "#{sub_folder_name}/#{model_pre}#{name}Service.m" + s_file: "#{sub_folder_name}/#{model_pre}#{name}Service.m", + req_mock_file: "#{sub_folder_name}/#{model_pre}#{name}Mock.m" } end def push_to_git Actions.sh('git checkout master') @@ -514,31 +525,31 @@ def print_mock_request_data(req_models) puts "\n<===============打印Mock Data-Begin=====================>\n".green req_models.each do |model| model_name = model[:name] || '' model_properties = model[:properties] - puts "#{model_name} *mock = [[#{model_name} alloc] init];" + puts_mock "#{model_name} *mock = [[#{model_name} alloc] init];" model_properties.each do |m| - puts "/// #{m[:description]}" + puts_mock "/// #{m[:description]}" type = m[:type] case type when 'integer' - puts "mock.#{m[:key]} = 0;" + puts_mock "mock.#{m[:key]} = 0;" when 'number' - puts "mock.#{m[:key]} = 0;" + puts_mock "mock.#{m[:key]} = 0;" when 'float' - puts "mock.#{m[:key]} = 0;" + puts_mock "mock.#{m[:key]} = 0;" when 'double' - puts "mock.#{m[:key]} = 0;" + puts_mock "mock.#{m[:key]} = 0;" when 'object' - puts "mock.#{m[:key]} = @{};" + puts_mock "mock.#{m[:key]} = @{};" when 'array' - puts "mock.#{m[:key]} = @[];" + puts_mock "mock.#{m[:key]} = @[];" else - puts "mock.#{m[:key]} = @\"\";" + puts_mock "mock.#{m[:key]} = @\"\";" end end - puts "\n\n" + puts_mock "\n\n" end puts "\n<===============打印Mock Data-End=====================>\n".green end end end