-
Notifications
You must be signed in to change notification settings - Fork 351
Expand file tree
/
Copy pathRakefile
More file actions
133 lines (111 loc) · 4.31 KB
/
Copy pathRakefile
File metadata and controls
133 lines (111 loc) · 4.31 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
require 'json'
require 'net/http'
require 'json'
require 'tempfile'
namespace :lint do
desc 'Lints swift files'
task :swift do
sh 'swift package --allow-writing-to-package-directory format --lint'
end
desc 'Lints README.md'
task :markdown do
unless system('which npx > /dev/null 2>&1')
puts "Error: npx is not installed. Please run: brew install node"
exit 1
end
readme_path = 'README.md'
check_result = system('npx --yes prettier --check README.md')
unless check_result
puts ""
puts "README.md has unformatted changes."
puts "Please run `bundle exec rake format:markdown` and commit the result."
exit 1
end
end
end
namespace :format do
desc 'Formats swift files'
task :swift do
sh 'swift package --allow-writing-to-package-directory format'
end
desc 'Formats README.md'
task :markdown do
unless system('which npx > /dev/null 2>&1')
puts "Error: npx is not installed. Please run: brew install node"
exit 1
end
readme_path = 'README.md'
# Check if there would be changes by running prettier in check mode
check_result = system('npx --yes prettier --check README.md > /dev/null 2>&1')
if check_result
puts "No changes"
else
# Format the file
sh 'npx --yes prettier --write README.md'
puts "Formatted README.md"
end
end
end
namespace :update do
desc 'Updates SwiftFormat to the latest version'
task :swiftformat do
# Find the most recent nightly release of SwiftFormat in the https://github.com/calda/SwiftFormat-nightly repo.
response = Net::HTTP.get(URI('https://api.github.com/repos/calda/SwiftFormat-nightly/releases/latest'))
latest_release_info = JSON.parse(response)
latest_version_number = latest_release_info['tag_name']
# Download the artifact bundle for the latest release and compute its checksum.
temp_dir = Dir.mktmpdir
artifact_bundle_url = "https://github.com/calda/SwiftFormat-nightly/releases/download/#{latest_version_number}/swiftformat.artifactbundle.zip"
artifact_bundle_zip_path = "#{temp_dir}/swiftformat.artifactbundle.zip"
sh "curl #{artifact_bundle_url} -L --output #{artifact_bundle_zip_path}"
checksum = `swift package compute-checksum #{artifact_bundle_zip_path}`
# Update the Package.swift file to reference this version
package_manifest_path = 'Package.swift'
package_manifest_content = File.read(package_manifest_path)
updated_swift_format_reference = <<-EOS
.binaryTarget(
name: "swiftformat",
url: "https://github.com/calda/SwiftFormat-nightly/releases/download/#{latest_version_number}/SwiftFormat.artifactbundle.zip",
checksum: "#{checksum.strip}"
),
EOS
regex = /[ ]*.binaryTarget\([\S\s]*name: "swiftformat"[\S\s]*?\),\s/
updated_package_manifest = package_manifest_content.gsub(regex, updated_swift_format_reference)
File.open(package_manifest_path, "w") { |file| file.puts updated_package_manifest }
puts "Updated Package.swift to reference SwiftFormat #{latest_version_number}"
end
end
namespace :site do
desc 'Prepares index.md and syntax highlighting assets'
task :prepare do
require_relative 'site/site_content'
site_content = SiteContent.new
puts '📋 Generating index.md from README.md with frontmatter...'
site_content.write_index
puts '🤖 Generating SKILL.md from README.md with frontmatter...'
site_content.write_skill_md
puts '📄 Generating raw SKILL.md...'
site_content.write_skill_md_raw
puts '🎨 Generating syntax highlighting CSS...'
site_content.generate_syntax_css
end
desc 'Builds the static site into _site/'
task build: :prepare do
env = { 'JEKYLL_ENV' => ENV.fetch('JEKYLL_ENV', 'production') }
sh env, 'bundle exec jekyll build --source site/src'
end
desc 'Serves the site to support previewing its content during development'
task serve: :prepare do
env = { 'JEKYLL_ENV' => 'development' }
sh env, 'bundle exec jekyll serve --source site/src'
end
desc 'Enables validating the README content used to build the site during local development'
task :filter_readme do
require_relative 'site/site_content'
puts SiteContent.new.filter_readme
end
desc 'Runs integration tests for site content'
task :test do
sh 'bundle exec rspec site/site_content_spec.rb'
end
end