Class: Makit::V1::Project
- Inherits:
-
Object
- Object
- Makit::V1::Project
- Defined in:
- lib/makit/mp/project_mp.rb
Class Method Summary collapse
-
.create ⇒ Object
def to_yaml data = JSON.parse(self.to_pretty_json) data.to_yaml.sub(/^—n/, “”) end.
Instance Method Summary collapse
- #build ⇒ Object
- #build_dotnet_projects ⇒ Object
- #get_capitalized_name(name) ⇒ Object
- #get_name(name) ⇒ Object
- #make ⇒ Object
- #make_dotnet_projects ⇒ Object
- #open(filename) ⇒ Object
- #save_as(filename) ⇒ Object
-
#set_default_values ⇒ Object
def self.create_from_json(json) project = Makit::V1::Project.decode_json(json) project end.
- #setup ⇒ Object
- #setup_dotnet_projects ⇒ Object
- #test ⇒ Object
- #test_dotnet_projects ⇒ Object
- #with_dotnet_project(template, name, output) ⇒ Object
Class Method Details
.create ⇒ Object
def to_yaml
data = JSON.parse(self.to_pretty_json)
data.to_yaml.sub(/^---\n/, "")
end
14 15 16 17 18 |
# File 'lib/makit/mp/project_mp.rb', line 14 def self.create project = Makit::V1::Project.new project.set_default_values project end |
Instance Method Details
#build ⇒ Object
117 118 119 |
# File 'lib/makit/mp/project_mp.rb', line 117 def build build_dotnet_projects end |
#build_dotnet_projects ⇒ Object
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 |
# File 'lib/makit/mp/project_mp.rb', line 165 def build_dotnet_projects dotnet_projects.each do |project| next if project.os == "windows" && !Makit::Environment.is_windows? project.commands.each do |command| Makit::Directory.(project.output) # newest_file = Makit::Directory::get_newest_file_or_now(project.output) command_request = Makit::Commands::Request.from_string(command) Makit::Commands::Runner.default.execute(command_request) end project.build_args.each do |build_arg| project_path = File.join(project.output, "#{project.name}.csproj") Makit::DotNet.build(project_path, build_arg.configuration, build_arg.output) end project.publish_args.each do |publish_arg| project_path = File.join(project.output, "#{project.name}.csproj") Makit::DotNet.publish(project_path, publish_arg.configuration, publish_arg.output) end end end |
#get_capitalized_name(name) ⇒ Object
76 77 78 |
# File 'lib/makit/mp/project_mp.rb', line 76 def get_capitalized_name(name) name.split(".").map(&:capitalize).join(".") end |
#get_name(name) ⇒ Object
68 69 70 71 72 73 74 |
# File 'lib/makit/mp/project_mp.rb', line 68 def get_name(name) if !git_remote_url.nil? && !git_remote_url.empty? is_dotnet = git_remote_url.include?("nuget") get_capitalized_name(name) if is_dotnet end name.downcase end |
#make ⇒ Object
107 108 109 110 111 112 113 114 115 |
# File 'lib/makit/mp/project_mp.rb', line 107 def make setup_dotnet_projects make_dotnet_projects # verify the artifacts exist artifacts.each do |artifact| raise "artifact does not exist: #{artifact}" unless File.exist?(artifact) end end |
#make_dotnet_projects ⇒ Object
152 153 154 155 156 157 158 159 160 161 162 163 |
# File 'lib/makit/mp/project_mp.rb', line 152 def make_dotnet_projects dotnet_projects.each do |project| next if project.os == "windows" && !Makit::Environment.is_windows? project.commands.each do |command| Makit::Directory.(project.output) # newest_file = Makit::Directory::get_newest_file_or_now(project.output) command_request = Makit::Commands::Request.from_string(command) Makit::Commands::Runner.default.execute(command_request) end end end |
#open(filename) ⇒ Object
20 21 22 23 24 25 26 27 |
# File 'lib/makit/mp/project_mp.rb', line 20 def open(filename) other = Makit::Serializer.open(filename, Makit::V1::Project) # 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 self.artifacts = other.artifacts end |
#save_as(filename) ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/makit/mp/project_mp.rb', line 80 def save_as(filename) Makit::Serializer.save_as(filename, self) # 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 |
#set_default_values ⇒ Object
def self.create_from_json(json)
project = Makit::V1::Project.decode_json(json)
project
end
54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/makit/mp/project_mp.rb', line 54 def set_default_values # self.language = "csharp" # self.primary_artifact_type = "nuget" self.git_remote_url = `git remote get-url origin`.strip if git_remote_url.nil? || git_remote_url.empty? if name.nil? || name.empty? if !git_remote_url.nil? && !git_remote_url.empty? self.name = get_name(File.basename(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 |
#setup ⇒ Object
103 104 105 |
# File 'lib/makit/mp/project_mp.rb', line 103 def setup setup_dotnet_projects end |
#setup_dotnet_projects ⇒ Object
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
# File 'lib/makit/mp/project_mp.rb', line 125 def setup_dotnet_projects if dotnet_projects.any? if !File.exist?("#{name}.sln") puts " Creating solution file: #{"#{name}.sln".colorize(:green)}" "dotnet new sln -n #{name}".run unless File.exist?("#{name}.sln") else # puts " Solution file already exists: " + "#{self.name}.sln".colorize(:yellow) end dotnet_projects.each do |project| add_project = true add_project = false if project.os == "windows" && !Makit::Environment.is_windows? next unless 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 do |package| Makit::DotNet.add_package(project_filename, package) end end # Makit::DotNet.new_solution(self.name) Makit::DotNet.sln_add_projects(name) else # puts " no dotnet projects found".colorize(:yellow) end end |
#test ⇒ Object
121 122 123 |
# File 'lib/makit/mp/project_mp.rb', line 121 def test test_dotnet_projects end |
#test_dotnet_projects ⇒ Object
186 187 188 189 190 191 192 193 194 195 196 |
# File 'lib/makit/mp/project_mp.rb', line 186 def test_dotnet_projects dotnet_projects.each do |project| next if project.os == "windows" && !Makit::Environment.is_windows? project.test_args.each do |test_args| project_path = File.join(project.output, "#{project.name}.csproj") Makit::DotNet.test(project_path, test_args.configuration, test_args.output) end # "dotnet test #{project.output} --configuration Release".run end end |
#with_dotnet_project(template, name, output) ⇒ Object
93 94 95 96 97 98 99 100 101 |
# File 'lib/makit/mp/project_mp.rb', line 93 def with_dotnet_project(template, name, output) return if dotnet_projects.any? { |project| project.output == output } project = Makit::V1::DotNetProject.new project.template = template project.name = name project.output = output dotnet_projects << project end |