From 3dae74e80e8d8abc986d454eec79e330554fa188 Mon Sep 17 00:00:00 2001 From: Toshimaru Date: Fri, 9 May 2025 08:31:05 +0900 Subject: [PATCH 1/4] chore: Update `spec.files` logic --- serverkit-vscode.gemspec | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/serverkit-vscode.gemspec b/serverkit-vscode.gemspec index 1754b23..00d9139 100644 --- a/serverkit-vscode.gemspec +++ b/serverkit-vscode.gemspec @@ -20,11 +20,15 @@ Gem::Specification.new do |spec| # Specify which files should be added to the gem when it is released. # The `git ls-files -z` loads the files in the RubyGem that have been added into git. - spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do - `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) } + gemspec = File.basename(__FILE__) + spec.files = IO.popen(%w[git ls-files -z], chdir: __dir__, err: IO::NULL) do |ls| + ls.readlines("\x0", chomp: true).reject do |f| + (f == gemspec) || + f.start_with?(*%w[bin/ test/ spec/ features/ .git .github appveyor Gemfile]) + end end spec.bindir = "exe" - spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) } + spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) } spec.require_paths = ["lib"] spec.add_runtime_dependency "serverkit" From 1fc5f252391bb0e0feab876464b9f1bbc7410c0a Mon Sep 17 00:00:00 2001 From: Toshimaru Date: Fri, 9 May 2025 08:34:31 +0900 Subject: [PATCH 2/4] chore: Simplify `Rakefile` --- Rakefile | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/Rakefile b/Rakefile index d433a1e..a596216 100644 --- a/Rakefile +++ b/Rakefile @@ -1,10 +1,8 @@ +# frozen_string_literal: true + require "bundler/gem_tasks" -require "rake/testtask" +require "minitest/test_task" -Rake::TestTask.new(:test) do |t| - t.libs << "test" - t.libs << "lib" - t.test_files = FileList["test/**/*_test.rb"] -end +Minitest::TestTask.create -task :default => :test +task default: :test From 84996f350df7a43e00bfaf54a65fafff8ddba6e1 Mon Sep 17 00:00:00 2001 From: Toshimaru Date: Fri, 9 May 2025 08:43:01 +0900 Subject: [PATCH 3/4] docs: Update README with usage instructions --- README.md | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 7dd55cb..1da875e 100644 --- a/README.md +++ b/README.md @@ -5,13 +5,38 @@ [Serverkit](https://github.com/serverkit/serverkit) plug-in for [VSCode](https://code.visualstudio.com/). -## Install +## Installation ```rb # Gemfile gem "serverkit-vscode" ``` +## Usage + +### Prerequisites + +- Ensure you have [serverkit](https://github.com/serverkit/serverkit) gem installed +- Ensure you have [VSCode CLI](https://code.visualstudio.com/docs/configure/command-line) installed on your system + +### Basic Example + +Create a recipe file that uses the vscode resources: + +```yaml +# recipe.yml +resources: + # Install GitHub Copilot extension + - type: vscode_package + name: github.copilot +``` + +Then apply your recipe with Serverkit: + +```console +$ serverkit apply recipe.yml +``` + ## Resource ### vscode_package From 83769bd3dcadb2abf73d51ebe15d6e8094ed5d9d Mon Sep 17 00:00:00 2001 From: Toshimaru Date: Fri, 9 May 2025 08:59:36 +0900 Subject: [PATCH 4/4] test: Create vscode_package_test.rb --- .../resources/vscode_package_test.rb | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 test/serverkit/resources/vscode_package_test.rb diff --git a/test/serverkit/resources/vscode_package_test.rb b/test/serverkit/resources/vscode_package_test.rb new file mode 100644 index 0000000..db11631 --- /dev/null +++ b/test/serverkit/resources/vscode_package_test.rb @@ -0,0 +1,37 @@ +# frozen_string_literal: true + +require "test_helper" +require "serverkit/resources/vscode_package" + +class Serverkit::Resources::VscodePackageTest < Minitest::Test + ATTRIBUTES = {"name" => "test-package"} + ATTRIBUTES_WITH_VERSION = {"name" => "test-package", "version" => "1.2.3"} + + def setup + @resource = Serverkit::Resources::VscodePackage.new({}, ATTRIBUTES) + @resource_with_version = Serverkit::Resources::VscodePackage.new({}, ATTRIBUTES_WITH_VERSION) + end + + def test_resource_instance + assert_instance_of Serverkit::Resources::VscodePackage, @resource + assert_instance_of Serverkit::Resources::VscodePackage, @resource_with_version + end + + def test_apply + @resource.stub :run_command, ->(cmd) { cmd } do + assert_equal("code --install-extension test-package", @resource.apply) + end + @resource_with_version.stub :run_command, ->(cmd) { cmd } do + assert_equal("code --install-extension test-package@1.2.3", @resource_with_version.apply) + end + end + + def test_check + @resource.stub :check_command, ->(cmd) { cmd } do + assert_equal("code --list-extensions --show-versions | grep -E '^test-package@'", @resource.check) + end + @resource_with_version.stub :check_command, ->(cmd) { cmd } do + assert_equal("code --list-extensions --show-versions | grep -E '^test-package@1.2.3$'", @resource_with_version.check) + end + end +end