jive 0.2.0 → 0.3.1

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: 1e99fd45b1d45c356ac45300a941833cf34dbcfc3995f935234c9c08f06dba74
4
- data.tar.gz: a68176da0fe8547d201ddbc573fb6d49e0773ca983fa312e4b6dc313c9a4157b
3
+ metadata.gz: 5961fce0c728aa39eab542b868af002e6c42dd96f9d998ed74ac27b73400c1d8
4
+ data.tar.gz: 6098d75167c508beba3eea6067caa5ada3d161d08bc328cfef0bf7d48400c8d0
5
5
  SHA512:
6
- metadata.gz: c41233baa8f43d3a9277435661eb9ccb13e874d5a5ed338f4de60cd095942c6b8ad3f13f74be5a34819d5efea3b8fd090c68369a6f39bacb8f2f10edf313e1c6
7
- data.tar.gz: cafe522151627f9e4649391e620cb4419970454a04cd62d2b31d329699c7d3cb0bb73dfb2b1faaa9b8ffbec43ee89750b06dc10b75723bf343609bbf1751a2be
6
+ metadata.gz: 5ce9925f98dead85a9e9e2b05fd21983afca43ff2b238d429f8ba1d04151faa2010aa1d22297ad9c9a7c1325f702048ac8895ce166f0d7caadf1f21bb8003e70
7
+ data.tar.gz: 20afe1c128dd85aa8476995aff3c0a794fd57ebbdfd06e4ef5b40a0fc01cf5577d29e1ab2b699123281ca082d59d74f5d61effa4d2b8060bfdff1f612fc08e52
data/jive.gemspec CHANGED
@@ -15,21 +15,19 @@ Gem::Specification.new do |spec|
15
15
  spec.required_ruby_version = Gem::Requirement.new(">= 2.5.0")
16
16
 
17
17
  spec.metadata["homepage_uri"] = spec.homepage
18
-
19
- # Specify which files should be added to the gem when it is released.
20
- # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
21
- spec.files = Dir.chdir(File.expand_path(__dir__)) do
22
- `git ls-files -z`.split("\x0").reject do |f|
23
- f.match(%r{^(test|spec|features)/})
24
- end
25
- end
18
+ spec.files = Dir["lib/**/*.rb"] + Dir["exe/*"] + [
19
+ "LICENSE.txt",
20
+ "README.md",
21
+ "jive.gemspec",
22
+ "jive.sh"
23
+ ]
26
24
  spec.bindir = "exe"
27
25
  spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
28
26
  spec.require_paths = ["lib"]
29
27
  spec.post_install_message = <<~MESSAGE
30
- Include the following in your ~/.bash_profile
28
+ Run the following command for setup instructions:
31
29
 
32
- source #{__dir__}/jive.sh
30
+ $ jive setup
33
31
  MESSAGE
34
32
 
35
33
  spec.add_dependency "thor", "~> 1.1"
data/jive.sh CHANGED
@@ -43,7 +43,7 @@ __jive_open_pipe() {
43
43
  local tmpfile
44
44
  tmpfile="$(\mktemp -u)"
45
45
 
46
- exec 9>"${tmpfile}" # Open the tempfile for writing on FD 9.
46
+ exec 42>"${tmpfile}" # Open the tempfile for writing on FD 42.
47
47
  exec 8<"${tmpfile}" # Open the tempfile for reading on FD 8.
48
48
  \rm -f "${tmpfile}" # Unlink the tempfile. (we've already opened it).
49
49
  }
@@ -76,7 +76,7 @@ __jive_flush_tasks() {
76
76
 
77
77
  __jive_close_pipe() {
78
78
  exec 8<&- # close FD 8.
79
- exec 9<&- # close FD 9.
79
+ exec 42<&- # close FD 42.
80
80
  }
81
81
 
82
82
  jive() {
data/lib/jive.rb CHANGED
@@ -4,14 +4,26 @@ require "fileutils"
4
4
  require "open3"
5
5
 
6
6
  require "jive/batch_runner"
7
+ require "jive/docker"
8
+ require "jive/git"
7
9
  require "jive/popen"
10
+ require "jive/project"
8
11
  require "jive/runner"
12
+ require "jive/shell"
9
13
  require "jive/version"
10
14
 
11
15
  module Jive
12
16
  class Error < StandardError; end
13
17
 
18
+ def self.root
19
+ @root ||= Pathname.new(__FILE__).parent.parent
20
+ end
21
+
14
22
  def self.run(tasks)
15
23
  Jive::BatchRunner.new.run(tasks)
16
24
  end
25
+
26
+ def self.shell
27
+ @shell ||= ::Jive::Shell.new
28
+ end
17
29
  end
data/lib/jive/cli.rb CHANGED
@@ -1,59 +1,99 @@
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 "clone <org>/<project>", "git clone to ~/src/github.com/<org>/<project>"
15
- def clone(slug)
16
- target_dir = Pathname.new(Dir.home).join("src/github.com/#{slug}")
17
- run_each([
18
- [:mkdir, "-p", target_dir.parent.to_s],
19
- [:git, "clone", "git@github.com:#{slug}.git", target_dir]
20
- ])
21
- after_run([
22
- ["cd", target_dir],
23
- ["setenv", "JIVE_LAST_RUN=#{Time.now.to_i}"]
24
- ])
18
+ def self.handle_no_command_error(name)
19
+ ::Jive::Cli::App.start(["exec", name])
25
20
  end
26
21
 
27
- private
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 <<~MESSAGE
45
+ Format: <type>(<scope>): <subject>
46
+
47
+ <scope> is optional
28
48
 
29
- COMMAND_MAP = {
30
- cd: "/usr/bin/cd",
31
- echo: "/usr/bin/echo",
32
- git: "/usr/bin/git",
33
- mkdir: "/usr/bin/mkdir"
34
- }.freeze
49
+ feat: add hat wobble
50
+ ^--^ ^------------^
51
+ | |
52
+ | +-> Summary in present tense.
53
+ |
54
+ +-------> Type: chore, docs, feat, fix, refactor, style, or test.
35
55
 
36
- def run_each(tasks)
37
- tasks.each do |task|
38
- break unless execute(task)
56
+ chore: updating grunt tasks etc; no production code change
57
+ docs: changes to the documentation
58
+ feat: new feature for the user, not a new feature for build script
59
+ fix: bug fix for the user, not a fix to a build script
60
+ refactor: refactoring production code, eg. renaming a variable
61
+ style: formatting, missing semi colons, etc; no production code change
62
+ test: adding missing tests, refactoring tests; no production code change
63
+ MESSAGE
39
64
  end
65
+ end)
66
+
67
+ desc "cd <org>/<project>", "cd to ~/src/github.com/<org>/<project>"
68
+ def cd(slug)
69
+ Jive.shell.run_safely { Git.new(Jive.shell).cd(slug) }
70
+ end
71
+
72
+ desc "clone <org>/<project>", "git clone to ~/src/github.com/<org>/<project>"
73
+ def clone(slug)
74
+ Jive.shell.run_safely { Git.new(Jive.shell).clone(slug) }
40
75
  end
41
76
 
42
- def execute(command, env: {})
43
- system(env, expand(command))
77
+ desc "exec <command>", "run command from jive.yml"
78
+ def exec(command)
79
+ path = Pathname.pwd.join("jive.yml")
80
+ return shell.error("Error: jive.yml not found") unless path.exist?
81
+
82
+ Jive.shell.run_safely do
83
+ Jive.shell.execute(YAML.safe_load(path.read).dig("commands", command))
84
+ end
44
85
  end
45
86
 
46
- def after_run(tasks)
47
- finalizer_fd = 9
48
- pipe = IO.new(finalizer_fd)
49
- pipe.puts(tasks.map { |x| x.join(":") }.join("\n"))
87
+ desc "bootstrap", "bootstrap the current project"
88
+ def bootstrap
89
+ Project
90
+ .new(Pathname.pwd)
91
+ .bootstrap(Jive.shell)
50
92
  end
51
93
 
52
- def expand(command)
53
- Array(command)
54
- .flatten
55
- .map { |x| COMMAND_MAP.fetch(x, x).to_s }
56
- .join(" ")
94
+ desc "setup", "provide instructions to integrate into shell"
95
+ def setup
96
+ print "source #{::Jive.root.join("jive.sh")}"
57
97
  end
58
98
  end
59
99
  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 ADDED
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jive
4
+ class Git
5
+ attr_reader :shell
6
+
7
+ def initialize(shell)
8
+ @shell = shell
9
+ end
10
+
11
+ def clone(slug)
12
+ dir = target_dir_for(slug)
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
+ ])
18
+ end
19
+ cd(slug)
20
+ end
21
+
22
+ def cd(slug)
23
+ dir = target_dir_for(slug)
24
+ if dir.exist?
25
+ shell.after_run([
26
+ ["cd", dir],
27
+ ["setenv", "JIVE_LAST_RUN=#{Time.now.to_i}"]
28
+ ])
29
+ else
30
+ clone(slug)
31
+ end
32
+ end
33
+
34
+ private
35
+
36
+ def target_dir_for(slug)
37
+ Pathname.new(Dir.home).join("src/github.com/#{slug}")
38
+ end
39
+ end
40
+ 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/shell.rb ADDED
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jive
4
+ class Shell
5
+ COMMAND_MAP = {
6
+ cd: "/usr/bin/cd",
7
+ echo: "/usr/bin/echo",
8
+ git: "/usr/bin/git",
9
+ mkdir: "/usr/bin/mkdir"
10
+ }.freeze
11
+
12
+ def run_each(tasks)
13
+ tasks.each do |task|
14
+ break unless execute(task)
15
+ end
16
+ end
17
+
18
+ def execute(command, env: {})
19
+ system(env, expand(command))
20
+ end
21
+
22
+ def after_run(tasks)
23
+ finalizer_fd = 42
24
+ pipe = IO.new(finalizer_fd)
25
+ pipe.puts(tasks.map { |x| x.join(":") }.join("\n"))
26
+ rescue Errno::EBADF => e
27
+ puts e
28
+ exit 1
29
+ end
30
+
31
+ def expand(command)
32
+ Array(command)
33
+ .flatten
34
+ .map { |x| COMMAND_MAP.fetch(x, x).to_s }
35
+ .join(" ")
36
+ end
37
+
38
+ def run_safely
39
+ yield
40
+ rescue StandardError => e
41
+ puts e
42
+ after_run([%w[noop noop]])
43
+ end
44
+ end
45
+ 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.0"
4
+ VERSION = "0.3.1"
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.0
4
+ version: 0.3.1
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-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -102,28 +102,20 @@ executables:
102
102
  extensions: []
103
103
  extra_rdoc_files: []
104
104
  files:
105
- - ".github/workflows/ci.yml"
106
- - ".gitignore"
107
- - ".rubocop.yml"
108
- - Gemfile
109
- - Gemfile.lock
110
105
  - LICENSE.txt
111
106
  - README.md
112
- - Rakefile
113
- - bin/console
114
- - bin/run
115
- - bin/setup
116
- - bin/shipit
117
- - bin/style
118
- - bin/test
119
107
  - exe/jive
120
108
  - jive.gemspec
121
109
  - jive.sh
122
110
  - lib/jive.rb
123
111
  - lib/jive/batch_runner.rb
124
112
  - lib/jive/cli.rb
113
+ - lib/jive/docker.rb
114
+ - lib/jive/git.rb
125
115
  - lib/jive/popen.rb
116
+ - lib/jive/project.rb
126
117
  - lib/jive/runner.rb
118
+ - lib/jive/shell.rb
127
119
  - lib/jive/version.rb
128
120
  homepage: https://rubygems.org/gems/jive
129
121
  licenses:
@@ -131,9 +123,9 @@ licenses:
131
123
  metadata:
132
124
  homepage_uri: https://rubygems.org/gems/jive
133
125
  post_install_message: |
134
- Include the following in your ~/.bash_profile
126
+ Run the following command for setup instructions:
135
127
 
136
- source /home/mokha/src/github.com/xlgmokha/jive/jive.sh
128
+ $ jive setup
137
129
  rdoc_options: []
138
130
  require_paths:
139
131
  - lib
@@ -1,28 +0,0 @@
1
- name: ci
2
- on:
3
- push:
4
- branches: [main]
5
- pull_request:
6
- branches: [main]
7
- jobs:
8
- test:
9
- runs-on: ubuntu-latest
10
- strategy:
11
- matrix:
12
- ruby-version: ['2.5', '2.6', '2.7', '3.0']
13
- steps:
14
- - uses: actions/checkout@v2
15
- - uses: ruby/setup-ruby@v1
16
- with:
17
- ruby-version: ${{ matrix.ruby-version }}
18
- bundler-cache: true
19
- - run: ./bin/test
20
- style:
21
- runs-on: ubuntu-latest
22
- steps:
23
- - uses: actions/checkout@v2
24
- - uses: ruby/setup-ruby@v1
25
- with:
26
- ruby-version: '3'
27
- bundler-cache: true
28
- - run: ./bin/style
data/.gitignore DELETED
@@ -1,7 +0,0 @@
1
- /.bundle/
2
- /.yardoc
3
- /_yardoc/
4
- /coverage/
5
- /doc/
6
- /pkg/
7
- /tmp/
data/.rubocop.yml DELETED
@@ -1,37 +0,0 @@
1
- require:
2
- - rubocop-minitest
3
- - rubocop-rake
4
-
5
- AllCops:
6
- NewCops: enable
7
- TargetRubyVersion: 2.5
8
-
9
- Layout/LineLength:
10
- Max: 120
11
-
12
- Layout/EndOfLine:
13
- EnforcedStyle: lf
14
-
15
- Layout/FirstArrayElementIndentation:
16
- EnforcedStyle: consistent
17
-
18
- Metrics/AbcSize:
19
- Exclude:
20
- - lib/jive/batch_runner.rb
21
- - lib/jive/popen.rb
22
-
23
- Metrics/MethodLength:
24
- Exclude:
25
- - lib/jive/batch_runner.rb
26
- - lib/jive/popen.rb
27
-
28
- Style/Documentation:
29
- Enabled: false
30
-
31
- Style/StringLiterals:
32
- Enabled: true
33
- EnforcedStyle: double_quotes
34
-
35
- Style/StringLiteralsInInterpolation:
36
- Enabled: true
37
- EnforcedStyle: double_quotes
data/Gemfile DELETED
@@ -1,6 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- source "https://rubygems.org"
4
-
5
- # Specify your gem's dependencies in jive.gemspec
6
- gemspec
data/Gemfile.lock DELETED
@@ -1,50 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- jive (0.2.0)
5
- thor (~> 1.1)
6
-
7
- GEM
8
- remote: https://rubygems.org/
9
- specs:
10
- ast (2.4.2)
11
- minitest (5.14.3)
12
- parallel (1.20.1)
13
- parser (3.0.0.0)
14
- ast (~> 2.4.1)
15
- rainbow (3.0.0)
16
- rake (13.0.3)
17
- regexp_parser (2.0.3)
18
- rexml (3.2.4)
19
- rubocop (1.9.1)
20
- parallel (~> 1.10)
21
- parser (>= 3.0.0.0)
22
- rainbow (>= 2.2.2, < 4.0)
23
- regexp_parser (>= 1.8, < 3.0)
24
- rexml
25
- rubocop-ast (>= 1.2.0, < 2.0)
26
- ruby-progressbar (~> 1.7)
27
- unicode-display_width (>= 1.4.0, < 3.0)
28
- rubocop-ast (1.4.1)
29
- parser (>= 2.7.1.5)
30
- rubocop-minitest (0.10.3)
31
- rubocop (>= 0.87, < 2.0)
32
- rubocop-rake (0.5.1)
33
- rubocop
34
- ruby-progressbar (1.11.0)
35
- thor (1.1.0)
36
- unicode-display_width (2.0.0)
37
-
38
- PLATFORMS
39
- ruby
40
-
41
- DEPENDENCIES
42
- jive!
43
- minitest (~> 5.0)
44
- rake (~> 13.0)
45
- rubocop (~> 1.7)
46
- rubocop-minitest (~> 0.1)
47
- rubocop-rake (~> 0.5)
48
-
49
- BUNDLED WITH
50
- 2.2.8
data/Rakefile DELETED
@@ -1,14 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "bundler/gem_tasks"
4
- require "rake/testtask"
5
- require "rubocop/rake_task"
6
-
7
- Rake::TestTask.new(:test) do |task|
8
- task.libs << "lib"
9
- task.libs << "test"
10
- task.test_files = FileList["test/**/*_test.rb"]
11
- end
12
- RuboCop::RakeTask.new
13
-
14
- task default: %i[test rubocop]
data/bin/console DELETED
@@ -1,8 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # frozen_string_literal: true
3
-
4
- require "bundler/setup"
5
- require "jive"
6
-
7
- require "irb"
8
- IRB.start(__FILE__)
data/bin/run DELETED
@@ -1,7 +0,0 @@
1
- #!/bin/sh
2
-
3
- set -e
4
-
5
- cd "$(dirname "$0")/.."
6
-
7
- bundle exec ./exe/jive "$@"
data/bin/setup DELETED
@@ -1,6 +0,0 @@
1
- #!/bin/sh
2
- set -e
3
-
4
- cd "$(dirname "$0")/.."
5
-
6
- bundle install
data/bin/shipit DELETED
@@ -1,7 +0,0 @@
1
- #!/bin/sh
2
-
3
- set -e
4
-
5
- cd "$(dirname "$0")/.."
6
-
7
- bundle exec rake release
data/bin/style DELETED
@@ -1,6 +0,0 @@
1
- #!/bin/sh
2
- set -e
3
-
4
- cd "$(dirname "$0")/.."
5
-
6
- bundle exec rubocop "$@"
data/bin/test DELETED
@@ -1,12 +0,0 @@
1
- #!/bin/sh
2
- set -e
3
-
4
- cd "$(dirname "$0")/.."
5
-
6
- export RUBYOPT="-Ilib:test"
7
-
8
- if [ $# -gt 0 ]; then
9
- bundle exec ruby "$@"
10
- else
11
- bundle exec ruby test/**/*_test.rb
12
- fi