lib/makit/mp/project_mp.rb in makit-0.0.0 vs lib/makit/mp/project_mp.rb in makit-0.0.1
- old
+ new
@@ -5,59 +5,77 @@
module Makit
module V1
class Project
def to_yaml
data = JSON.parse(self.to_pretty_json)
- data.to_yaml.sub(/^---\n/, '')
+ 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)
-
+ project = Makit::V1::Project.new
+ project.set_default_values
+ project
+ end
+
+ def open(filename)
+ other = Makit::V1::Project::create_from_file(filename)
+ self.name = other.name
+ self.git_remote_url = other.git_remote_url
+ self.dotnet_projects = other.dotnet_projects
+ end
+
+ def self.create_from_file(filename)
+ extension = File.extname(filename)
+ case extension
+ when ".yml"
+ yaml = File.read(filename)
+ create_from_yaml(yaml)
+ when ".json"
+ json = File.read(filename)
+ create_from_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
+ raise "unsupported file extension: #{extension}"
end
- project.set_default_values
+ end
+
+ def self.create_from_yaml(yaml)
+ json = JSON.pretty_generate(YAML.load(yaml))
+ project = Makit::V1::Project.decode_json(json)
project
end
+ def self.create_from_json(json)
+ project = Makit::V1::Project.decode_json(json)
+ 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
+ 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
+ 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
+ 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)
@@ -70,91 +88,62 @@
else
raise "unsupported file extension: #{extension}"
end
end
- def with_dotnet_project(template,name,output)
- if !self.dotnet_projects.any? { |project| project.output== output }
+ 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
+ project.template = template
+ project.name = name
+ project.output = output
+ self.dotnet_projects << project
end
end
+ def setup
+ setup_dotnet_projects
+ 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)
+ 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|
+ add_project = true
+ if (project.os == "windows" && !Makit::Environment.is_windows?)
+ add_project = false
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
+ if (add_project)
+ Makit::DotNet.new_project(project.template, project.name, project.output)
+ # add any nuget packages to the project
+ project_filename = "#{project.output}/#{project.name}.csproj"
+ project.packages.each { |package|
+ Makit::DotNet::add_package(project_filename, package)
+ }
end
+ end
+ Makit::DotNet.new_solution(self.name)
+ Makit::DotNet.sln_add_projects(self.name)
else
- puts " no dotnet projects found".colorize(:yellow)
+ 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
+ "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
+ "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
\ No newline at end of file