Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 5 additions & 7 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -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
10 changes: 7 additions & 3 deletions serverkit-vscode.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
37 changes: 37 additions & 0 deletions test/serverkit/resources/vscode_package_test.rb
Original file line number Diff line number Diff line change
@@ -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