-
Notifications
You must be signed in to change notification settings - Fork 102
/
Rakefile
76 lines (58 loc) · 1.8 KB
/
Rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# frozen_string_literal: true
require "time"
require "rspec/core/rake_task"
require "rubocop/rake_task"
RuboCop::RakeTask.new
RSpec::Core::RakeTask.new(:spec)
task default: :spec
desc "Run rackup (with rerun)"
task :rackup do
sh "rerun --pattern '{Gemfile.lock,lib/**/*.rb,lib/*.rb}' -- rackup config.ru"
end
def recursive_delete(hash, to_remove)
hash.delete(to_remove)
hash.each_value do |value|
recursive_delete(value, to_remove) if value.is_a? Hash
end
end
def build_swagger_doc(path)
require_relative "lib/mihari"
require_relative "lib/mihari/web/application"
require "rack/test"
app = Mihari::Web::App.new
session = Rack::Test::Session.new(app)
res = session.request("/api/swagger_doc")
json = JSON.parse(res.body.to_s)
# remove host because it can be varied
keys_to_remove = %w[host]
keys_to_remove.each do |key|
recursive_delete json, key
end
File.write(path, json.to_yaml)
end
namespace :build do
desc "Build Swagger doc"
task :swagger, [:path] do |_t, args|
args.with_defaults(path: "./frontend/swagger.yaml")
started_at = Time.now
build_swagger_doc args.path
elapsed = (Time.now - started_at).floor(2)
puts "Swagger doc is built in #{elapsed}s"
end
desc "Build frontend assets"
task :frontend do
# Build frontend assets
sh "cd frontend && npm install && npm run docs && npm run build-only"
# Copy built assets into ./lib/web/public/
sh "rm -rf ./lib/mihari/web/public/"
sh "mkdir -p ./lib/mihari/web/public/"
sh "cp -r frontend/dist/* ./lib/mihari/web/public"
end
end
desc "Build including Swagger doc and frontend assets"
task :build do
Rake::Task["build:swagger"].invoke
Rake::Task["build:frontend"].invoke
end
# require it later enables doing pre-build step (= build the frontend app)
require "bundler/gem_tasks"