Skip to content

Commit ddc85c1

Browse files
committed
add script to update new major
1 parent 4a3052d commit ddc85c1

File tree

2 files changed

+100
-0
lines changed

2 files changed

+100
-0
lines changed

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,17 @@ brew install nx
1010
nx --version
1111
```
1212

13+
## New Major Version
14+
15+
Run the script:
16+
17+
```
18+
./create_new_major.rb 22.0.0
19+
```
20+
21+
This will create the new `nx.rb` file and rename the existing major version to `nx@<major>.rb`. You can then open a PR with this version and let CI verify it. To install the new version:
22+
23+
```shell
24+
brew update
25+
brew upgrade nx
26+
```

create_new_major.rb

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
#!/usr/bin/env ruby
2+
3+
require 'open-uri'
4+
require 'digest'
5+
require 'fileutils'
6+
7+
def calculate_sha256(url)
8+
content = URI.open(url).read
9+
Digest::SHA256.hexdigest(content)
10+
end
11+
12+
def rename_current_formula
13+
current_file = 'Formula/nx.rb'
14+
return unless File.exist?(current_file)
15+
16+
content = File.read(current_file)
17+
version_match = content.match(/url ".*nx-(\d+\.\d+\.\d+)\.tgz"/)
18+
return unless version_match
19+
20+
current_version = version_match[1]
21+
new_file = "Formula/nx@#{current_version.split('.').first}.rb"
22+
23+
# Update class name in content
24+
updated_content = content.gsub(/class Nx/, "class NxAT#{current_version.split('.').first}")
25+
26+
# Write to new file and remove old file
27+
File.write(new_file, updated_content)
28+
File.delete(current_file)
29+
30+
puts "Renamed #{current_file} to #{new_file}"
31+
end
32+
33+
def create_new_formula(version)
34+
url = "https://registry.npmjs.org/nx/-/nx-#{version}.tgz"
35+
sha256 = calculate_sha256(url)
36+
37+
template = <<~RUBY
38+
require "language/node"
39+
40+
class Nx < Formula
41+
desc "Smart, Fast and Extensible Build System"
42+
homepage "https://nx.dev"
43+
url "#{url}"
44+
sha256 "#{sha256}"
45+
license "MIT"
46+
47+
livecheck do
48+
url :stable
49+
end
50+
51+
depends_on "node@22"
52+
53+
def install
54+
system "npm", "install", *Language::Node.std_npm_install_args(libexec)
55+
bin.install_symlink Dir["\#{libexec}/bin/*"]
56+
end
57+
58+
test do
59+
# Create a temporary directory for testing
60+
testdir = testpath/"test-project"
61+
testdir.mkdir
62+
testdir.cd do
63+
system bin/"nx", "--version"
64+
end
65+
end
66+
end
67+
RUBY
68+
69+
File.write('Formula/nx.rb', template)
70+
puts "Created new Formula/nx.rb with version #{version}"
71+
end
72+
73+
if ARGV.empty?
74+
puts "Usage: #{$0} <version>"
75+
puts "Example: #{$0} 21.0.4"
76+
exit 1
77+
end
78+
79+
version = ARGV[0]
80+
unless version.match?(/^\d+\.\d+\.\d+$/)
81+
puts "Error: Version must be in format X.Y.Z"
82+
exit 1
83+
end
84+
85+
rename_current_formula
86+
create_new_formula(version)

0 commit comments

Comments
 (0)