# frozen_string_literal: true require "json" require "yaml" module Makit module V1 class Project def to_yaml data = JSON.parse(self.to_pretty_json) data.to_yaml.sub(/^---\n/, '') end def self.create project = nil if (File.exist?(".makit.project.yml")) yaml = File.read(".makit.project.yml") # convert yaml to json data = YAML.load(yaml) json = JSON.pretty_generate(data) project = Makit::V1::Project.decode_json(json) else if (File.exist?(".makit.project.json")) json = File.read("project.json") project = Makit::V1::Project.decode_json(json) else project = Makit::V1::Project.new end end project.set_default_values project end def set_default_values #self.language = "csharp" #self.primary_artifact_type = "nuget" if self.git_remote_url.nil? || self.git_remote_url.empty? self.git_remote_url = `git remote get-url origin`.strip end if self.name.nil? || self.name.empty? if(!self.git_remote_url.nil? && !self.git_remote_url.empty?) self.name =get_name(File.basename(self.git_remote_url,".git"))# get_capitalized_name(File.basename(self.git_remote_url, ".git")) else self.name =get_name(File.basename(Dir.getwd))# get_capitalized_name(File.basename(Dir.getwd)) end end self end def get_name(name) if !self.git_remote_url.nil? && !self.git_remote_url.empty? is_dotnet = self.git_remote_url.include?("nuget") if is_dotnet get_capitalized_name(name) end end name.downcase end def get_capitalized_name(name) name.split(".").map(&:capitalize).join(".") end def save_as(filename) extension = File.extname(filename) case extension when ".json" File.write(filename, self.to_pretty_json) when ".yml" File.write(filename, self.to_yaml) else raise "unsupported file extension: #{extension}" end end def with_dotnet_project(template,name,output) if !self.dotnet_projects.any? { |project| project.output== output } project = Makit::V1::DotNetProject.new project.template = template project.name = name project.output = output self.dotnet_projects << project end end def setup_dotnet_projects if self.dotnet_projects.any? if(!File.exist?("#{self.name}.sln")) puts " Creating solution file: " + "#{self.name}.sln".colorize(:green) "dotnet new sln -n #{self.name}".run unless File.exist?("#{self.name}.sln") else puts " Solution file already exists: " + "#{self.name}.sln".colorize(:yellow) end self.dotnet_projects.each do |project| if(!Dir.exist?("#{project.output}")) puts " Creating project file: " + "#{project.name}/#{project.name}.csproj".colorize(:green) "dotnet new #{project.template} -n #{project.name} -o #{project.output}".run unless Dir.exist?("#{project.output}") # add the .csproj file to the .sln puts " Adding project to solution: " + "#{project.output}/#{project.name}.csproj".colorize(:green) "dotnet sln #{self.name}.sln add #{project.output}/#{project.name}.csproj".run else puts " Project file already exists: " + "#{project.name}/#{project.name}.csproj".colorize(:yellow) end end else puts " no dotnet projects found".colorize(:yellow) end end def build_dotnet_projects self.dotnet_projects.each do |project| "dotnet build #{project.output} --configuration Release".run end end def test_dotnet_projects self.dotnet_projects.each do |project| "dotnet test #{project.output} --configuration Release".run end end end # class Project end # module V1 end # module Makit #task :setup do # if(Makit::PROJECT.git_remote_url.include?("nuget") || # Makit::PROJECT.primary_artifact_type.include?("nuget")) # if(!File.exist?("#{Makit::PROJECT.name}.sln")) # puts " Creating solution file: " + "#{Makit::PROJECT.name}.sln".colorize(:green) # "dotnet new sln -n #{Makit::PROJECT.name}".run unless File.exist?("#{Makit::PROJECT.name}.sln") # end # end # Makit::PROJECT.dotnet_projects.each do |project| # if(!Dir.exist?("#{project.output}")) # puts " Creating project file: " + "#{project.name}/#{project.name}.csproj".colorize(:green) # "dotnet new #{project.template} -n #{project.name} -o #{project.output}".run unless Dir.exist?("#{project.output}") # end # end # add all .csproj file to the .sln # Dir.glob("**/*.csproj").each do |file| # "dotnet sln #{Makit::PROJECT.name}.sln add #{file}".run # end #template = "nunit" #"dotnet new #{template} -n #{Makit::PROJECT.name}.Tests -o src/#{Makit::PROJECT.name}".run unless Dir.exist?("#{Makit::PROJECT.name}.Tests") #if(Makit::PROJECt.primary_artifact_type.include?("nuget")) # puts #end # end #"dotnet build src/Facilities.Models/Facilities.Models.csproj --configuration Release".run # "dotnet build test/Facilities.Models.Tests/Facilities.Models.Tests.csproj --configuration Release".run # "dotnet build examples/Facilities.Models.Wasm.Demo/Facilities.Models.Wasm.Demo.csproj --configuration Release".run #"dotnet test test/Facilities.Models.Tests/Facilities.Models.Tests.csproj --configuration Release".run