Skip to content

Commit

Permalink
Refactor installation process in asd.rb
Browse files Browse the repository at this point in the history
The installation process in asd.rb has been revamped to include the extraction of PHAR files, running npm install, providing execution permissions to necessary files and creating asd.phar execution scripts. Additionally, the previous test for expected output has been replaced with new tests to execute asdw and asd scripts.
  • Loading branch information
koriym committed Jun 15, 2024
1 parent 469cbcc commit 54025de
Showing 1 changed file with 36 additions and 6 deletions.
42 changes: 36 additions & 6 deletions asd.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,42 @@ class Asd < Formula
depends_on "composer" => :build
depends_on "node"


def install
bin.install "asd.phar"
mv bin/"asd.phar", bin/"asd"
end
# PHARファイルをlibexecにインストール
libexec.install "asd.phar"

# PHARファイルを解凍
system "php -r \"(new Phar('#{libexec}/asd.phar'))->extractTo('#{libexec}');\""

# npm install の実行
system "npm", "install", "--prefix", "#{libexec}/asd-sync"

# 必要なファイルに実行権限を付与し、shebangを追加
bin_asd = "#{libexec}/bin/asd"
chmod 0755, bin_asd
File.open(bin_asd, 'r+') do |file|
content = file.read
file.seek(0)
file.write("#!/usr/bin/env php\n" + content)
end

# npmプロジェクト実行スクリプトの作成
(bin/"asdw").write <<~EOS
#!/bin/bash
cd "#{libexec}/asd-sync" && npm start -- --profile "$@"
EOS
(bin/"asdw").chmod 0755

test do
assert_match "Expected output", shell_output("#{bin}/asd")
end
# asd.phar 実行スクリプトの作成
(bin/"asd").write <<~EOS
#!/bin/bash
php "#{libexec}/asd.phar" "$@"
EOS
(bin/"asd").chmod 0755
end
test do
system "#{bin}/asdw"
system "#{bin}/asd"
end
end

0 comments on commit 54025de

Please sign in to comment.