jive 0.2.2 → 0.3.3

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: ecf28e3a1d722522cb6fc2bb810c34563ba78f81209f78f8a4abc7e628c6f23e
4
- data.tar.gz: 9c8c3e0390939c7393b7cc170d538f3f1a97595d8c4b8783dac66cd000067ecd
3
+ metadata.gz: 3205ae4955fafc394318f7daccceacf3d7728b15450649e66c198ce514ecef22
4
+ data.tar.gz: 128bdd0f9d8cf584503a714e0a92b4064d3cbb94f227ed9e4f50622a212e14b4
5
5
  SHA512:
6
- metadata.gz: f1631fb5229c44e2ab09e3c38723e7db97822a3c7fa0525220b9f901b38d8ee1a6f7e19e2c9d138bab405edb7ec1d4c7c210020e18c3092fc76577b867db9f73
7
- data.tar.gz: 842ac071b5edf167f5c9c240faf4466cbee6979bdfa797fed89e60f4db852486da68ae2d8e1186e8d4229af69e671e08a0b2716a4435f0eea96dd25b47d4b62d
6
+ metadata.gz: e4e02857d8f45d0a4d678418f4e9a56b009e96256ea23dcf763f67bf2e1af568509af8162303979b7ad3f998cbba0e11ff9d9ba224df1df379d90bd4ff4ed125
7
+ data.tar.gz: ecb75b2857218cd72ab6a6693e15320bed3aa77f219437f4e616afe6fa66d9d23153e037920060e7cf9b91b4402cb7e8fc4d12a98709cb895bb53a84a05a16d0
data/lib/jive.rb CHANGED
@@ -4,8 +4,10 @@ require "fileutils"
4
4
  require "open3"
5
5
 
6
6
  require "jive/batch_runner"
7
+ require "jive/docker"
7
8
  require "jive/git"
8
9
  require "jive/popen"
10
+ require "jive/project"
9
11
  require "jive/runner"
10
12
  require "jive/shell"
11
13
  require "jive/version"
@@ -20,4 +22,8 @@ module Jive
20
22
  def self.run(tasks)
21
23
  Jive::BatchRunner.new.run(tasks)
22
24
  end
25
+
26
+ def self.shell
27
+ @shell ||= ::Jive::Shell.new
28
+ end
23
29
  end
data/lib/jive/cli.rb CHANGED
@@ -1,43 +1,82 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "pathname"
3
4
  require "thor"
5
+ require "yaml"
6
+
4
7
  require "jive"
5
- require "pathname"
6
8
 
7
9
  module Jive
8
10
  module Cli
9
11
  class App < Thor
12
+ package_name "jive"
13
+
10
14
  def self.exit_on_failure?
11
15
  true
12
16
  end
13
17
 
14
- desc "cd <org>/<project>", "cd to ~/src/github.com/<org>/<project>"
15
- def cd(slug)
16
- runner.run_safely do
17
- Git.new(runner).cd(slug)
18
- end
18
+ def self.handle_no_command_error(name)
19
+ ::Jive::Cli::App.start(["exec", name])
19
20
  end
20
21
 
21
- desc "clone <org>/<project>", "git clone to ~/src/github.com/<org>/<project>"
22
- def clone(slug)
23
- runner.run_safely do
24
- Git.new(runner).clone(slug)
22
+ desc "docker SUBCOMMAND ...ARGS", "docker commands"
23
+ subcommand "docker", (Class.new(Thor) do
24
+ desc "build", "build the Dockerfile in the current directory"
25
+ def build
26
+ Docker.new.build(Pathname.pwd)
27
+ end
28
+
29
+ desc "launch", "launch a shell into a container"
30
+ def launch
31
+ Docker.new.launch(Pathname.pwd)
32
+ end
33
+
34
+ desc "size", "print the size of each image"
35
+ def size
36
+ Docker.new.size(Pathname.pwd)
37
+ end
38
+ end)
39
+
40
+ desc "git SUBCOMMAND ...ARGS", "git commands"
41
+ subcommand "git", (Class.new(Thor) do
42
+ desc "semantic", "Print help for semantic commit messages"
43
+ def semantic
44
+ say Git.new.semantic_help
45
+ end
46
+
47
+ method_option :host, type: :string, default: "github.com"
48
+ desc "clone <org>/<project>", "git clone to ~/src/github.com/<org>/<project>"
49
+ def clone(slug)
50
+ host = options[:host]
51
+ Jive.shell.run_safely { Git.new(Jive.shell).clone(slug, host: host) }
25
52
  end
53
+ end)
54
+
55
+ desc "cd <org>/<project>", "cd to ~/src/github.com/<org>/<project>"
56
+ def cd(slug)
57
+ Jive.shell.run_safely { Git.new(Jive.shell).cd(slug) }
26
58
  end
27
59
 
28
- desc "setup", "provide instructions to integrate into shell"
29
- def setup
30
- say <<~MESSAGE
31
- Include the following in your ~/.bash_profile
60
+ desc "exec <command>", "run command from jive.yml"
61
+ def exec(command)
62
+ path = Pathname.pwd.join("jive.yml")
63
+ return shell.error("Error: jive.yml not found") unless path.exist?
32
64
 
33
- source #{::Jive.root.join("jive.sh")}
34
- MESSAGE
65
+ Jive.shell.run_safely do
66
+ Jive.shell.execute(YAML.safe_load(path.read).dig("commands", command))
67
+ end
35
68
  end
36
69
 
37
- private
70
+ desc "bootstrap", "bootstrap the current project"
71
+ def bootstrap
72
+ Project
73
+ .new(Pathname.pwd)
74
+ .bootstrap(Jive.shell)
75
+ end
38
76
 
39
- def runner
40
- @runner ||= ::Jive::Shell.new
77
+ desc "setup", "provide instructions to integrate into shell"
78
+ def setup
79
+ print "source #{::Jive.root.join("jive.sh")}"
41
80
  end
42
81
  end
43
82
  end
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jive
4
+ class Docker
5
+ attr_reader :shell
6
+
7
+ def initialize(shell = ::Jive.shell)
8
+ @shell = shell
9
+ end
10
+
11
+ def build(path)
12
+ shell.execute([
13
+ "docker",
14
+ "build",
15
+ "--network=host",
16
+ "-t", image_tag_for(path),
17
+ "."
18
+ ], env: { "DOCKER_BUILDKIT" => "1" })
19
+ end
20
+
21
+ def launch(path)
22
+ shell.execute([
23
+ "docker",
24
+ "run",
25
+ "--network=host",
26
+ '--entrypoint=""',
27
+ "-it", image_tag_for(path),
28
+ "/bin/bash -l"
29
+ ])
30
+ end
31
+
32
+ def size(path)
33
+ shell.execute([
34
+ :docker, "image", "inspect", '--format="{{.Size}}"',
35
+ image_tag_for(path)
36
+ ])
37
+ end
38
+
39
+ private
40
+
41
+ def image_tag_for(path)
42
+ "#{path.basename.to_s.downcase}:latest"
43
+ end
44
+ end
45
+ end
data/lib/jive/git.rb CHANGED
@@ -4,23 +4,21 @@ module Jive
4
4
  class Git
5
5
  attr_reader :shell
6
6
 
7
- def initialize(shell)
7
+ def initialize(shell = ::Jive.shell)
8
8
  @shell = shell
9
9
  end
10
10
 
11
- def clone(slug)
12
- dir = target_dir_for(slug)
11
+ def clone(slug, host: "github.com")
12
+ dir = target_dir_for(slug, host: host)
13
13
  unless dir.exist?
14
- shell.run_each([
15
- [:mkdir, "-p", dir.parent.to_s],
16
- [:git, "clone", "git@github.com:#{slug}.git", dir]
17
- ])
14
+ shell.execute([:mkdir, "-p", dir.parent.to_s])
15
+ shell.execute([:git, "clone", "git@#{host}:#{slug}", dir])
18
16
  end
19
- cd(slug)
17
+ cd(slug, host: host) if dir.exist?
20
18
  end
21
19
 
22
- def cd(slug)
23
- dir = target_dir_for(slug)
20
+ def cd(slug, host: "github.com")
21
+ dir = target_dir_for(slug, host: host)
24
22
  if dir.exist?
25
23
  shell.after_run([
26
24
  ["cd", dir],
@@ -31,10 +29,33 @@ module Jive
31
29
  end
32
30
  end
33
31
 
32
+ def semantic_help
33
+ <<~MESSAGE
34
+ Format: <type>(<scope>): <subject>
35
+
36
+ <scope> is optional
37
+
38
+ feat: add hat wobble
39
+ ^--^ ^------------^
40
+ | |
41
+ | +-> Summary in present tense.
42
+ |
43
+ +-------> Type: chore, docs, feat, fix, refactor, style, or test.
44
+
45
+ chore: updating grunt tasks etc; no production code change
46
+ docs: changes to the documentation
47
+ feat: new feature for the user, not a new feature for build script
48
+ fix: bug fix for the user, not a fix to a build script
49
+ refactor: refactoring production code, eg. renaming a variable
50
+ style: formatting, missing semi colons, etc; no production code change
51
+ test: adding missing tests, refactoring tests; no production code change
52
+ MESSAGE
53
+ end
54
+
34
55
  private
35
56
 
36
- def target_dir_for(slug)
37
- Pathname.new(Dir.home).join("src/github.com/#{slug}")
57
+ def target_dir_for(slug, host:)
58
+ Pathname.new(Dir.home).join("src/#{host}/#{slug}")
38
59
  end
39
60
  end
40
61
  end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jive
4
+ class Project
5
+ attr_reader :path
6
+
7
+ def initialize(path)
8
+ @path = path
9
+ end
10
+
11
+ def bootstrap(shell)
12
+ tasks = []
13
+ tasks << [:asdf, "install"]
14
+ tasks << [:bundle, "install"] if bundler?
15
+ tasks << [:yarn, "install"] if yarn?
16
+
17
+ shell.run_safely do
18
+ shell.run_each(tasks)
19
+ end
20
+ end
21
+
22
+ private
23
+
24
+ def bundler?
25
+ path.join("Gemfile").exist? ||
26
+ path.glob("*.gemspec").any?
27
+ end
28
+
29
+ def yarn?
30
+ path.join("yarn.lock").exist?
31
+ end
32
+ end
33
+ end
data/lib/jive/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Jive
4
- VERSION = "0.2.2"
4
+ VERSION = "0.3.3"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jive
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - mo khan
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-02-06 00:00:00.000000000 Z
11
+ date: 2021-02-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -110,8 +110,10 @@ files:
110
110
  - lib/jive.rb
111
111
  - lib/jive/batch_runner.rb
112
112
  - lib/jive/cli.rb
113
+ - lib/jive/docker.rb
113
114
  - lib/jive/git.rb
114
115
  - lib/jive/popen.rb
116
+ - lib/jive/project.rb
115
117
  - lib/jive/runner.rb
116
118
  - lib/jive/shell.rb
117
119
  - lib/jive/version.rb