-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRakefile
More file actions
70 lines (52 loc) · 1.81 KB
/
Rakefile
File metadata and controls
70 lines (52 loc) · 1.81 KB
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
require "bundler/setup"
APP_RAKEFILE = File.expand_path("test/dummy/Rakefile", __dir__)
load "rails/tasks/engine.rake"
load "rails/tasks/statistics.rake"
require "bundler/gem_tasks"
require 'ndr_dev_support/tasks'
# This class is responsible for building the JavaScript for the design system.
class JsBuilder
extend Rake::FileUtilsExt
def self.build(watch: false)
require 'fileutils'
sh 'npm install'
# Remove all old builds
FileUtils.rm_rf(Dir.glob('public/design_system/static/design_system-*'))
output_dir = "public/design_system/static/design_system-#{DesignSystem::VERSION}"
mkdir_p(output_dir)
command = 'npx esbuild app/javascript/design_system/index.js --bundle ' \
"--outfile=#{output_dir}/design_system.js --format=esm"
command += " --watch" if watch
if watch
puts "Watching for changes... Press Ctrl+C to stop"
trap('INT') do
puts "\nStopping watch mode"
exit
end
end
sh command
end
end
namespace :js do
desc 'Build the JavaScript for the design system'
task :build do
JsBuilder.build(watch: false)
end
desc 'Watch for changes and rebuild the JavaScript for the design system'
task :watch do
JsBuilder.build(watch: true)
end
end
desc 'Deploy the gem to RubyGems.org'
task :deploy_to_rubygems do
# Raise an error if the static files are not built
unless Dir.exist?("public/design_system/static/design_system-#{DesignSystem::VERSION}")
raise "Static files not built. Please run `rake js:build` before deploying."
end
sh 'gem build'
filename = "design_system-#{DesignSystem::VERSION}.gem"
raise "Gem file #{filename} not found. Please ensure the gem was built successfully." unless File.exist?(filename)
sh "gem push #{filename}"
# remove the built gem file after pushing
rm filename
end