ddenv 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ec082036626c59440016bd290efe318994ed5d11affb29c29c74a40fb7bf6f57
4
- data.tar.gz: 4af215b869b270245f24b97ac688301e6f8b53fac521c4c1c11c15c750279e99
3
+ metadata.gz: be59b284b001642fbf169fb71a0c6887b2a54c4747ef52c0cc695b6b6621f7eb
4
+ data.tar.gz: b140aa2607964e48d50555420db3d038cc1e9306ce46147e5657e97c4f2c06bd
5
5
  SHA512:
6
- metadata.gz: 9eb69dfcc93bc53d2757483eff2f14469666b220487e4356353c37687d1b22c7ff7d58a3c5a308d4565e891d08721fafca7eabc45e9a70958a7af4aecc26792c
7
- data.tar.gz: '08f42ffb6c4ab4acf25ef12253dbbe5e8c2c8d2b9031562e55f7993e94023143055dddb319e45b2880c646f5c53815352b1cdbb3a98aac455397bc8f049f5ac7'
6
+ metadata.gz: e59e6c7ef5f3e64ccd0962475e0137912009188b2cff521d39dc4bfacfb8645542ae432299aeefda5af817dfdb4b8999cc75186af8ef66ea79b8c15d947ac4f6
7
+ data.tar.gz: cdcffc2846efe163d628f6ac677533e12cd8501783d72fb8ee6f5f09cb2bd37d166ca7b37628a4b2d6321762b5f902533668ca137134458506135305710d2f36
data/.rubocop.yml CHANGED
@@ -15,5 +15,8 @@ Style/Documentation:
15
15
  Metrics:
16
16
  Enabled: false
17
17
 
18
+ Layout/LineLength:
19
+ Enabled: false
20
+
18
21
  Naming/MemoizedInstanceVariableName:
19
22
  EnforcedStyleForLeadingUnderscores: required
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.1.2] - 2024-04-29
4
+
5
+ - Fix unknown `Pathname` constant
6
+ - Add `bundle`, `node` and `npm` goals
7
+
3
8
  ## [0.1.1] - 2024-04-29
4
9
 
5
10
  - Add functioning `ddenv.yaml` with support for `homebrew` and `ruby` goals.
data/README.md CHANGED
@@ -24,20 +24,29 @@ Next, create a `ddenv.yaml` file which contains the list of dependencies to mana
24
24
  up:
25
25
  - homebrew: overmind
26
26
  - ruby: 3.3.0
27
+ - bundle
28
+ - node: 20.12.2
29
+ - npm
27
30
  ```
28
31
 
29
32
  Lastly, run `ddenv up`.
30
33
 
31
34
  ```
32
35
  % ddenv up
33
- [✔] Installing Homebrew package overmind ... done (previously achieved)
34
- [✔] Installing Homebrew package ruby-install... done (previously achieved)
35
- [✔] Installing Ruby v3.3.0 ... done (previously achieved)
36
- [✔] Initializing Shadowenv ... done (previously achieved)
37
- [✔] Creating .shadowenv.d ... done (previously achieved)
38
- [✔] Adding .shadowenv.d to .gitignore ... done (previously achieved)
39
- [✔] Trusting .shadowenv.d ... done (previously achieved)
40
- [✔] Adding Ruby to shadowenv ... done (previously achieved)
36
+ [✔] Installing Homebrew package overmind done (previously achieved)
37
+ [✔] Installing Homebrew package ruby-install done (previously achieved)
38
+ [✔] Installing Ruby v3.3.0 done (previously achieved)
39
+ [✔] Initializing Shadowenv done (previously achieved)
40
+ [✔] Creating .shadowenv.d done (previously achieved)
41
+ [✔] Adding .shadowenv.d to .gitignore done (previously achieved)
42
+ [✔] Trusting .shadowenv.d done (previously achieved)
43
+ [✔] Adding Ruby to shadowenv done (previously achieved)
44
+ [✔] Installing Ruby gem bundler done (previously achieved)
45
+ [✔] Installing bundle done (previously achieved)
46
+ [✔] Installing Homebrew package node-build done (previously achieved)
47
+ [✔] Installing Node v20.12.2 done (previously achieved)
48
+ [✔] Adding Node to shadowenv done (previously achieved)
49
+ [✔] Installing npm packages done (previously achieved)
41
50
  %
42
51
  ```
43
52
 
@@ -46,4 +55,8 @@ Now your local developer environment is ready to be used.
46
55
  ## Goals
47
56
 
48
57
  - <code>homebrew: <var>PACKAGENAME</var></code> installs the Homebrew package with the given name.
49
- - <code>ruby: <var>VERSION</var></code> installs the given version of Ruby.
58
+ - <code>ruby</code> installs Ruby (with the version specified in the `.ruby-version`
59
+ file).
60
+ - <code>bundle</code> runs `bundle install`.
61
+ - <code>node: <var>VERSION</var></code> installs the give Node.js version.
62
+ - <code>npm</code> installs packages from package.json using npm.
data/TODO.md ADDED
@@ -0,0 +1,6 @@
1
+ # To do
2
+
3
+ - Add support for bash/zsh
4
+ - Add support for installing PostgreSQL (and set env variables)
5
+ - Add support for installing Redis (and set env variables)
6
+ - Add support for installing Python (and maintain venv)
data/ddenv.yaml CHANGED
@@ -1,3 +1,6 @@
1
1
  up:
2
2
  - homebrew: overmind
3
- - ruby: 3.3.0
3
+ - ruby
4
+ - bundle
5
+ - node: 20.12.2
6
+ - npm
data/lib/ddenv/cli.rb CHANGED
@@ -2,26 +2,30 @@
2
2
 
3
3
  module Ddenv
4
4
  class CLI
5
- def initialize(args)
6
- @args = args
5
+ ROOT_CMD = Cri::Command.new_basic_root.modify do
6
+ name "ddenv"
7
+ usage "ddenv [options] [command] [options]"
8
+ summary "manage developer environment"
9
+ description "Manages your local developer environment."
7
10
  end
8
11
 
9
- def call
10
- if @args.size != 1
11
- warn "usage: ddenv [command]"
12
- exit 64 # EX_USAGE
13
- end
12
+ ROOT_CMD.define_command("up") do
13
+ name "up"
14
+ usage "up [options]"
15
+ summary "bring up developer environment"
16
+ description "Brings up the local developer environment to be in line what is described in the ddenv.yaml configuration file."
14
17
 
15
- command_name = @args.first
16
- case command_name
17
- when "help"
18
- Ddenv::Commands::Help.new.call
19
- when "up"
18
+ run do |_opts, _args, _cmd|
20
19
  Ddenv::Commands::Up.new.call
21
- else
22
- warn "ddenv: unknown command: #{command_name}"
23
- exit 64 # EX_USAGE
24
20
  end
25
21
  end
22
+
23
+ def initialize(args)
24
+ @args = args
25
+ end
26
+
27
+ def call
28
+ ROOT_CMD.run(@args)
29
+ end
26
30
  end
27
31
  end
@@ -11,7 +11,7 @@ module Ddenv
11
11
  max_message_size = all_goals.map { _1.message.size }.max
12
12
 
13
13
  all_goals.each do |goal|
14
- spinner = TTY::Spinner.new("[:spinner] :message... :title")
14
+ spinner = TTY::Spinner.new("[:spinner] :message :title")
15
15
  spinner.update(message: format("%-#{max_message_size}s", goal.message))
16
16
  spinner.update(title: "checking")
17
17
  spinner.auto_spin
data/lib/ddenv/config.rb CHANGED
@@ -19,15 +19,22 @@ module Ddenv
19
19
  when Hash
20
20
  [element.keys.first, element.values.first]
21
21
  when String
22
- # TODO: for later
23
- # (when a goal has no extra details)
22
+ [element, nil]
24
23
  end
25
24
 
26
25
  case key
27
26
  when "homebrew"
28
27
  Goals::HomebrewPackageInstalled.new(value)
29
28
  when "ruby"
30
- Goals::RubyInstalled.new(value)
29
+ Goals::RubyInstalled.new
30
+ when "node"
31
+ Goals::NodeInstalled.new(value)
32
+ when "bundle"
33
+ Goals::BundleInstalled.new
34
+ when "npm"
35
+ Goals::NpmPackesInstalled.new
36
+ else
37
+ raise "unknown key: #{key}"
31
38
  end
32
39
  end
33
40
  end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Ddenv
4
+ module Goals
5
+ class BundleInstalled < Goal
6
+ def message
7
+ "Installing bundle"
8
+ end
9
+
10
+ def achieved?
11
+ cmd = TTY::Command.new(printer: :null)
12
+ cmd.run("shadowenv", "exec", "--", "bundle", "check")
13
+ true
14
+ rescue StandardError
15
+ false
16
+ end
17
+
18
+ def achieve
19
+ # TODO: use :pretty when passing --verbose
20
+ cmd = TTY::Command.new(printer: :null)
21
+ cmd.run("shadowenv", "exec", "--", "bundle", "install")
22
+ end
23
+
24
+ def pre_goals
25
+ [
26
+ GemInstalled.new("bundler")
27
+ ]
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Ddenv
4
+ module Goals
5
+ class GemInstalled < Goal
6
+ def initialize(gem_name)
7
+ super()
8
+ @gem_name = gem_name
9
+ end
10
+
11
+ def message
12
+ "Installing Ruby gem #{@gem_name}"
13
+ end
14
+
15
+ def achieved?
16
+ cmd = TTY::Command.new(printer: :null)
17
+ stdout, _stderr = cmd.run("shadowenv", "exec", "--", "gem", "list", "-i", "^#{@gem_name}$")
18
+ stdout.chomp == "true"
19
+ end
20
+
21
+ def achieve
22
+ # TODO: use :pretty when passing --verbose
23
+ cmd = TTY::Command.new(printer: :null)
24
+ cmd.run("shadowenv", "exec", "--", "gem", "install", @gem_name)
25
+ end
26
+
27
+ def props
28
+ [@gem_name]
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Ddenv
4
+ module Goals
5
+ module NodeBuildInstalled
6
+ def self.new
7
+ Ddenv::Goals::HomebrewPackageInstalled.new("node-build")
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Ddenv
4
+ module Goals
5
+ class NodeInstalled < Goal
6
+ attr_reader :node_version
7
+
8
+ def initialize(node_version)
9
+ super()
10
+
11
+ @node_version = node_version.to_s
12
+ end
13
+
14
+ def message
15
+ "Installing Node v#{node_version}"
16
+ end
17
+
18
+ def achieved?
19
+ node_pathname.directory?
20
+ end
21
+
22
+ def achieve
23
+ # TODO: use :pretty when passing --verbose
24
+ cmd = TTY::Command.new(printer: :null)
25
+ cmd.run("node-build", node_version, node_pathname.to_s)
26
+ end
27
+
28
+ def pre_goals
29
+ [
30
+ NodeBuildInstalled.new
31
+ ]
32
+ end
33
+
34
+ def post_goals
35
+ [
36
+ NodeShadowenvCreated.new(node_version, node_pathname.to_s)
37
+ ]
38
+ end
39
+
40
+ private
41
+
42
+ def node_pathname
43
+ @_node_pathname ||= Pathname.new(Dir.home) / ".node-versions" / node_version
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Ddenv
4
+ module Goals
5
+ class NodeShadowenvCreated < Goal
6
+ PATH = ".shadowenv.d/20_node.lisp"
7
+
8
+ def initialize(node_version, node_path)
9
+ super()
10
+
11
+ @node_version = node_version
12
+ @node_path = node_path
13
+ end
14
+
15
+ def message
16
+ "Adding Node to shadowenv"
17
+ end
18
+
19
+ def achieved?
20
+ File.file?(PATH) && File.read(PATH) == shadowenv_contents
21
+ end
22
+
23
+ def achieve
24
+ File.write(PATH, shadowenv_contents)
25
+
26
+ # TODO: use :pretty when passing --verbose
27
+ cmd = TTY::Command.new(printer: :null)
28
+ cmd.run("shadowenv", "trust")
29
+ end
30
+
31
+ def pre_goals
32
+ [
33
+ Ddenv::Goals::ShadowenvDirCreated.new
34
+ ]
35
+ end
36
+
37
+ def props
38
+ [@node_version, @node_path]
39
+ end
40
+
41
+ private
42
+
43
+ def shadowenv_contents
44
+ <<~CONTENTS
45
+ (provide "node" "#{@node_version}")
46
+
47
+ (env/prepend-to-pathlist "PATH" "#{@node_path}/bin")
48
+ CONTENTS
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Ddenv
4
+ module Goals
5
+ class NpmPackesInstalled < Goal
6
+ def message
7
+ "Installing npm packages"
8
+ end
9
+
10
+ def achieved?
11
+ # TODO: use :pretty when passing --verbose
12
+ cmd = TTY::Command.new(printer: :null)
13
+ cmd.run("shadowenv", "exec", "--", "npx", "check-dependencies")
14
+ true
15
+ rescue StandardError
16
+ false
17
+ end
18
+
19
+ def achieve
20
+ # TODO: use :pretty when passing --verbose
21
+ cmd = TTY::Command.new(printer: :null)
22
+ cmd.run("shadowenv", "exec", "--", "npm", "install")
23
+ end
24
+ end
25
+ end
26
+ end
@@ -3,24 +3,19 @@
3
3
  module Ddenv
4
4
  module Goals
5
5
  class RubyInstalled < Goal
6
- def initialize(ruby_version)
7
- super()
8
- @ruby_version = ruby_version
9
- end
10
-
11
6
  def message
12
- "Installing Ruby v#{@ruby_version}"
7
+ "Installing Ruby v#{ruby_version}"
13
8
  end
14
9
 
15
10
  def achieved?
16
- pathname = Pathname.new(Dir.home) / ".rubies" / "ruby-#{@ruby_version}"
11
+ pathname = Pathname.new(Dir.home) / ".rubies" / "ruby-#{ruby_version}"
17
12
  pathname.directory?
18
13
  end
19
14
 
20
15
  def achieve
21
16
  # TODO: use :pretty when passing --verbose
22
17
  cmd = TTY::Command.new(printer: :null)
23
- cmd.run("ruby-install", "--cleanup", @ruby_version)
18
+ cmd.run("ruby-install", "--cleanup", ruby_version)
24
19
  end
25
20
 
26
21
  def pre_goals
@@ -31,18 +26,18 @@ module Ddenv
31
26
 
32
27
  def post_goals
33
28
  [
34
- RubyShadowenvCreated.new(ruby_pathname.to_s, @ruby_version)
29
+ RubyShadowenvCreated.new(ruby_version, ruby_pathname.to_s)
35
30
  ]
36
31
  end
37
32
 
38
- def props
39
- [@ruby_version]
40
- end
41
-
42
33
  private
43
34
 
35
+ def ruby_version
36
+ @_ruby_version ||= File.read(".ruby-version").chomp
37
+ end
38
+
44
39
  def ruby_pathname
45
- @_ruby_pathname ||= Pathname.new(Dir.home) / ".rubies" / "ruby-#{@ruby_version}"
40
+ @_ruby_pathname ||= Pathname.new(Dir.home) / ".rubies" / "ruby-#{ruby_version}"
46
41
  end
47
42
  end
48
43
  end
@@ -7,6 +7,7 @@ module Ddenv
7
7
 
8
8
  def initialize(ruby_version, ruby_path)
9
9
  super()
10
+
10
11
  @ruby_version = ruby_version
11
12
  @ruby_path = ruby_path
12
13
  end
@@ -33,6 +34,10 @@ module Ddenv
33
34
  ]
34
35
  end
35
36
 
37
+ def props
38
+ [@ruby_version, @ruby_path]
39
+ end
40
+
36
41
  private
37
42
 
38
43
  def shadowenv_contents
data/lib/ddenv/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Ddenv
4
- VERSION = "0.1.1"
4
+ VERSION = "0.1.2"
5
5
  end
data/lib/ddenv.rb CHANGED
@@ -1,8 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "json"
4
+ require "pathname"
4
5
  require "yaml"
5
6
 
7
+ require "cri"
6
8
  require "tty-command"
7
9
  require "tty-spinner"
8
10
 
@@ -14,13 +16,18 @@ require_relative "ddenv/homebrew"
14
16
  require_relative "ddenv/subclass_responsibility_error"
15
17
  require_relative "ddenv/version"
16
18
 
17
- require_relative "ddenv/commands/help"
18
19
  require_relative "ddenv/commands/up"
19
20
 
20
21
  require_relative "ddenv/goals/homebrew_package_installed"
21
22
  require_relative "ddenv/goals/ruby_install_installed"
22
23
  require_relative "ddenv/goals/ruby_installed"
23
24
  require_relative "ddenv/goals/ruby_shadowenv_created"
25
+ require_relative "ddenv/goals/bundle_installed"
26
+ require_relative "ddenv/goals/gem_installed"
27
+ require_relative "ddenv/goals/node_build_installed"
28
+ require_relative "ddenv/goals/node_installed"
29
+ require_relative "ddenv/goals/npm_packages_installed"
30
+ require_relative "ddenv/goals/node_shadowenv_created"
24
31
  require_relative "ddenv/goals/shadowenv_initialized"
25
32
  require_relative "ddenv/goals/shadowenv_dir_created"
26
33
  require_relative "ddenv/goals/shadowenv_dir_git_ignored"