elspy 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +3 -4
- data/lib/elspy/manager.rb +2 -0
- data/lib/elspy/recipe.rb +71 -0
- data/lib/elspy/version.rb +1 -1
- data/recipes/solargraph.rb +2 -0
- data/recipes/typescript_language_server.rb +15 -0
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 870cfc3d73c801f48a7063d8905bef573cceed7bb7eb8ae23abec8adac588b2c
|
|
4
|
+
data.tar.gz: 88b4cc487390724c6c8f360435d626f4aaa9ea1b9806b8dfde55a3fe5aaac968
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 962a18d6ec2b7ea8230604465621a0d0340231a1aceadbd12c5f912cce953f23d92d1fb2f173c951a4e4c3dca834a2c25ccb2706842a5e2a9b742cda06334a04
|
|
7
|
+
data.tar.gz: 94ca2e45fed6908f4dab68346c1c4281dc2c84780074ee14df2e0ba719661f7ddef4f23372b2b58e0e9283dfffcf4b64b5a2ce7d277eb17388f4debc84def61e
|
data/README.md
CHANGED
|
@@ -13,11 +13,8 @@ Also, why not?
|
|
|
13
13
|
|
|
14
14
|
## Installation
|
|
15
15
|
|
|
16
|
-
For now, clone the repository and add it to your path:
|
|
17
16
|
```bash
|
|
18
|
-
|
|
19
|
-
cd elspy
|
|
20
|
-
echo 'export PATH="$PATH:'$(pwd)'/bin"' >> ~/.bashrc # or ~/.zshrc
|
|
17
|
+
gem install elspy
|
|
21
18
|
```
|
|
22
19
|
|
|
23
20
|
## Usage
|
|
@@ -69,6 +66,8 @@ Bundled ones are available in the repository, check the `recipes/` directory for
|
|
|
69
66
|
|
|
70
67
|
```rb
|
|
71
68
|
Elspy.recipe 'solargraph' do
|
|
69
|
+
depends_on 'gem'
|
|
70
|
+
|
|
72
71
|
binary 'bin/solargraph'
|
|
73
72
|
|
|
74
73
|
download do |version: :latest|
|
data/lib/elspy/manager.rb
CHANGED
|
@@ -10,11 +10,13 @@ module Elspy
|
|
|
10
10
|
|
|
11
11
|
def install(recipe_name, version: :latest)
|
|
12
12
|
recipe = load_recipe recipe_name
|
|
13
|
+
recipe.check_dependencies!
|
|
13
14
|
recipe.exec_download(version:)
|
|
14
15
|
end
|
|
15
16
|
|
|
16
17
|
def update(recipe_name)
|
|
17
18
|
recipe = load_recipe recipe_name
|
|
19
|
+
recipe.check_dependencies!
|
|
18
20
|
recipe.exec_download(version: :latest)
|
|
19
21
|
end
|
|
20
22
|
|
data/lib/elspy/recipe.rb
CHANGED
|
@@ -10,6 +10,7 @@ module Elspy
|
|
|
10
10
|
|
|
11
11
|
def initialize(name, &)
|
|
12
12
|
@name = name
|
|
13
|
+
@dependencies = []
|
|
13
14
|
|
|
14
15
|
@install_dir = File.join(DOWNLOADS_DIR, name)
|
|
15
16
|
|
|
@@ -37,6 +38,36 @@ module Elspy
|
|
|
37
38
|
@run_block = block
|
|
38
39
|
end
|
|
39
40
|
|
|
41
|
+
def depends_on(*commands, any: nil, all: nil)
|
|
42
|
+
@dependencies << { type: :any, commands: Array(any) } if any
|
|
43
|
+
@dependencies << { type: :all, commands: Array(all) } if all
|
|
44
|
+
|
|
45
|
+
return unless commands.any?
|
|
46
|
+
|
|
47
|
+
@dependencies << { type: :all, commands: }
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def check_dependencies!
|
|
51
|
+
@dependencies.each do |dep|
|
|
52
|
+
case dep[:type]
|
|
53
|
+
when :all
|
|
54
|
+
missing = dep[:commands].reject { |cmd| command_exists?(cmd) }
|
|
55
|
+
unless missing.empty?
|
|
56
|
+
|
|
57
|
+
raise Error, "Missing required dependencies: #{missing.join(', ')}\n" \
|
|
58
|
+
'Please install them to continue.'
|
|
59
|
+
end
|
|
60
|
+
when :any
|
|
61
|
+
found = dep[:commands].any? { |cmd| command_exists?(cmd) }
|
|
62
|
+
unless found
|
|
63
|
+
|
|
64
|
+
raise Error, "Missing dependencies: need at least one of [#{dep[:commands].join(', ')}]\n" \
|
|
65
|
+
'Please install one of them to continue.'
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
|
|
40
71
|
def exec_download(version: :latest)
|
|
41
72
|
@version = version
|
|
42
73
|
instance_exec(version:, &@download_block)
|
|
@@ -87,6 +118,46 @@ module Elspy
|
|
|
87
118
|
save_metadata(version:)
|
|
88
119
|
end
|
|
89
120
|
|
|
121
|
+
def node_install(package, version = :latest, package_manager: nil)
|
|
122
|
+
FileUtils.mkdir_p(@install_dir)
|
|
123
|
+
|
|
124
|
+
package_manager ||= node_pm
|
|
125
|
+
package_arg = version == :latest ? package : "#{package}@#{version}"
|
|
126
|
+
|
|
127
|
+
Dir.chdir(@install_dir) do
|
|
128
|
+
case package_manager
|
|
129
|
+
when :pnpm
|
|
130
|
+
system('pnpm', 'add', package_arg, exception: true)
|
|
131
|
+
when :npm
|
|
132
|
+
system('npm', 'install', package_arg, '--no-save', '--prefix', '.', exception: true)
|
|
133
|
+
end
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
version = if version == :latest
|
|
137
|
+
package_json = File.join(@install_dir, 'node_modules', package, 'package.json')
|
|
138
|
+
if File.exist?(package_json)
|
|
139
|
+
JSON.parse(File.read(package_json))['version']
|
|
140
|
+
else
|
|
141
|
+
'unknown'
|
|
142
|
+
end
|
|
143
|
+
else
|
|
144
|
+
version.to_s
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
save_metadata(version:)
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
def node_pm
|
|
151
|
+
return :pnpm if command_exists? 'pnpm'
|
|
152
|
+
return :npm if command_exists? 'npm'
|
|
153
|
+
|
|
154
|
+
raise Error, 'npm or pnpm is not in PATH'
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
def command_exists?(cmd)
|
|
158
|
+
system("which #{cmd} > /dev/null 2>&1")
|
|
159
|
+
end
|
|
160
|
+
|
|
90
161
|
def save_metadata(version:, **extra)
|
|
91
162
|
metadata = {
|
|
92
163
|
name: @name,
|
data/lib/elspy/version.rb
CHANGED
data/recipes/solargraph.rb
CHANGED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
Elspy.recipe 'typescript_language_server' do
|
|
4
|
+
depends_on any: %w[npm pnpm]
|
|
5
|
+
|
|
6
|
+
binary 'node_modules/.bin/typescript-language-server'
|
|
7
|
+
|
|
8
|
+
download do |version: :latest|
|
|
9
|
+
node_install 'typescript-language-server', version
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
run do |args|
|
|
13
|
+
exec binary_path, '--stdio', *args
|
|
14
|
+
end
|
|
15
|
+
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: elspy
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- chocycat
|
|
@@ -28,6 +28,7 @@ files:
|
|
|
28
28
|
- lib/elspy/recipe.rb
|
|
29
29
|
- lib/elspy/version.rb
|
|
30
30
|
- recipes/solargraph.rb
|
|
31
|
+
- recipes/typescript_language_server.rb
|
|
31
32
|
homepage: https://github.com/chocycat/elspy
|
|
32
33
|
licenses:
|
|
33
34
|
- AGPL-3.0-or-later
|