elm_install 0.1.0 → 0.1.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
  SHA1:
3
- metadata.gz: 1f5a56400929b580f8e2aef6cfddae1d98c7fe43
4
- data.tar.gz: 6cb79fca1fe9aa577a7f02495a27b2d15e896eb1
3
+ metadata.gz: 3a03f6fdb1a42bea5c14a87c7faa22623c146fbd
4
+ data.tar.gz: b484dc5f2566e0155da8a959a2ae1bf761f1ae10
5
5
  SHA512:
6
- metadata.gz: 20a1ee8f69fc2da9b1d94bd3bdbadb1e1b07e5ef2a879465d71a6c76260d29b688003a0098177565495506886de7faf2405809d2c0ab3cb3dd74cab0b0224ebc
7
- data.tar.gz: 5a476a8769744e1dd5b86fa7c7cf66f8636bdda9fdac0bde39d92060bd4ddbac47cfc3a062cbfb26c5cf61cabd033957a9aca38547cd732ecae2ab22c70127c7
6
+ metadata.gz: d783886b984c689ea08f652fae2e909c6a441820c2fa22f0defa657643b736347c5ad5f9d93e6ead8ef8eeed46a39f4864dae03f11d55547c072c9dc19c50b14
7
+ data.tar.gz: 9a04dd69660a65a3a802ad1455c54a9c06be9612772f27b695b6b4cc43b90dfebe97467976c7915085afb8280713b4bf39405c1f0ed1b5fc5f80e2a2d65661d6
data/.gitignore CHANGED
@@ -3,3 +3,6 @@ elm-stuff
3
3
  tmp
4
4
  elm-package.json
5
5
  pkg
6
+ packaging/vendor
7
+ packaging/elm-install*
8
+ packaging/traveling-ruby*
data/.rubocop.yml CHANGED
@@ -1,2 +1,5 @@
1
+ AllCops:
2
+ Exclude:
3
+ - 'packaging/**/*'
1
4
  Style/FrozenStringLiteralComment:
2
5
  Enabled: False
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.3.3
1
+ 2.2.2
data/Gemfile.lock CHANGED
@@ -1,11 +1,12 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- elm_install (0.1.0)
5
- colorize (~> 0.8.1)
4
+ elm_install (0.1.1)
6
5
  commander (~> 4.4, >= 4.4.2)
7
6
  git (~> 1.3)
8
7
  git_clone_url (~> 2.0)
8
+ hashdiff (~> 0.3.1)
9
+ smart_colored (~> 1.1, >= 1.1.1)
9
10
  solve (~> 3.1)
10
11
 
11
12
  GEM
@@ -22,7 +23,6 @@ GEM
22
23
  virtus (~> 1.0)
23
24
  coercible (1.0.0)
24
25
  descendants_tracker (~> 0.0.1)
25
- colorize (0.8.1)
26
26
  commander (4.4.2)
27
27
  highline (~> 1.7.2)
28
28
  descendants_tracker (0.0.4)
@@ -42,6 +42,7 @@ GEM
42
42
  git (1.3.0)
43
43
  git_clone_url (2.0.0)
44
44
  uri-ssh_git (>= 2.0)
45
+ hashdiff (0.3.1)
45
46
  highline (1.7.8)
46
47
  ice_nine (0.11.2)
47
48
  launchy (2.4.3)
@@ -90,6 +91,7 @@ GEM
90
91
  virtus (~> 1.0)
91
92
  semverse (2.0.0)
92
93
  sexp_processor (4.7.0)
94
+ smart_colored (1.1.1)
93
95
  solve (3.1.0)
94
96
  molinillo (>= 0.5)
95
97
  semverse (>= 1.1, < 3.0)
data/Rakefile CHANGED
@@ -4,5 +4,5 @@ Bundler::GemHelper.install_tasks
4
4
 
5
5
  task :ci do
6
6
  sh 'rubocop'
7
- sh 'rubycritic -m --no-browser -s 90'
7
+ sh 'rubycritic -m --no-browser -s 90 lib'
8
8
  end
data/elm_install.gemspec CHANGED
@@ -15,8 +15,6 @@ Gem::Specification.new do |s|
15
15
  s.test_files =
16
16
  `git ls-files -- {test,spec,features}/*`.split("\n")
17
17
 
18
- puts `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
19
-
20
18
  s.executables =
21
19
  `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
22
20
 
@@ -24,7 +22,8 @@ Gem::Specification.new do |s|
24
22
  s.add_dependency 'git_clone_url', '~> 2.0'
25
23
  s.add_dependency 'solve', '~> 3.1'
26
24
  s.add_dependency 'commander', '~> 4.4', '>= 4.4.2'
27
- s.add_dependency 'colorize', '~> 0.8.1'
25
+ s.add_dependency 'smart_colored', '~> 1.1', '>= 1.1.1'
26
+ s.add_dependency 'hashdiff', '~> 0.3.1'
28
27
 
29
28
  s.extra_rdoc_files = ['Readme.md']
30
29
  end
data/lib/elm_install.rb CHANGED
@@ -1,7 +1,8 @@
1
+ require 'smart_colored/extend'
1
2
  require 'git_clone_url'
2
3
  require 'forwardable'
3
4
  require 'fileutils'
4
- require 'colorize'
5
+ require 'hashdiff'
5
6
  require 'solve'
6
7
  require 'json'
7
8
  require 'git'
@@ -15,22 +15,30 @@ module ElmInstall
15
15
  # Initializes a new cache with the given options.
16
16
  def initialize(options = {})
17
17
  @options = options
18
+ @ref_cache = {}
18
19
  @cache = {}
19
20
  load
20
21
  end
21
22
 
22
23
  # Saves the cache into the json file.
23
24
  def save
25
+ File.binwrite(ref_file, JSON.pretty_generate(@ref_cache))
24
26
  File.binwrite(file, JSON.pretty_generate(@cache))
25
27
  end
26
28
 
27
29
  # Loads a cache from the json file.
28
30
  def load
31
+ @ref_cache = JSON.parse(File.read(ref_file))
29
32
  @cache = JSON.parse(File.read(file))
30
33
  rescue
34
+ @ref_cache = {}
31
35
  @cache = {}
32
36
  end
33
37
 
38
+ def clear
39
+ @ref_cache = {}
40
+ end
41
+
34
42
  # Returns the directory where the cache is stored.
35
43
  def directory
36
44
  @options[:directory] || File.join(Dir.home, '.elm-install')
@@ -38,7 +46,7 @@ module ElmInstall
38
46
 
39
47
  # Returns if there is a package in the cache (with at least one version).
40
48
  def package?(package)
41
- @cache.key?(package)
49
+ @ref_cache.key?(package) && @cache.key?(package)
42
50
  end
43
51
 
44
52
  # Adds a new dependency to the cache for a given package & version
@@ -71,14 +79,38 @@ module ElmInstall
71
79
  if Dir.exist?(repo_path)
72
80
  repo = Git.open(repo_path)
73
81
  repo.reset_hard
82
+
83
+ unless @ref_cache[path]
84
+ refs = refs_for(repo_path)
85
+
86
+ if HashDiff.diff(@ref_cache[path], refs).empty?
87
+ Utils.log_with_arrow "Package: #{path.bold} is outdated fetching changes..."
88
+ repo.fetch
89
+ end
90
+
91
+ @ref_cache[path] = refs
92
+ end
93
+
74
94
  repo
75
95
  else
76
- Git.clone(path, repo_path)
96
+ Utils.log_with_arrow "Package: #{path.bold} not found in cache, cloning..."
97
+ repo = Git.clone(path, repo_path)
98
+ @ref_cache[path] = refs_for(repo_path)
99
+ repo
77
100
  end
78
101
  end
79
102
 
80
103
  private
81
104
 
105
+ def refs_for(repo_path)
106
+ refs = Git.ls_remote(repo_path)
107
+ refs.delete('head')
108
+ end
109
+
110
+ def ref_file
111
+ File.join(directory, 'ref-cache.json')
112
+ end
113
+
82
114
  # Returns the path to the json file.
83
115
  def file
84
116
  File.join(directory, 'cache.json')
@@ -20,17 +20,36 @@ module ElmInstall
20
20
  puts 'Resolving packages...'
21
21
  resolver.add_constraints dependencies
22
22
 
23
- puts 'Saving index cache...'
24
- @cache.save
25
-
26
23
  puts 'Solving dependencies...'
27
- populate_elm_stuff
28
-
29
- puts 'Packages configured successfully!'
24
+ begin
25
+ populate_elm_stuff
26
+ rescue
27
+ puts ' ▶ Could not find a solution in local cache, refreshing packages...'
28
+
29
+ @cache.clear
30
+ resolver.add_constraints dependencies
31
+
32
+ begin
33
+ populate_elm_stuff
34
+ rescue Solve::Errors::NoSolutionError => e
35
+ puts 'Could not find a solution:'
36
+ puts indent(e.to_s)
37
+ end
38
+ end
30
39
  end
31
40
 
32
41
  private
33
42
 
43
+ def indent(str)
44
+ str.split("\n").map { |s| " #{s}" }.join("\n")
45
+ end
46
+
47
+ def end_sucessfully
48
+ puts 'Saving package cache...'
49
+ @cache.save
50
+
51
+ puts 'Packages configured successfully!'
52
+ end
34
53
  # Populates the `elm-stuff` directory with the packages from
35
54
  # the solution.
36
55
  def populate_elm_stuff
@@ -39,6 +58,7 @@ module ElmInstall
39
58
  end
40
59
 
41
60
  write_exact_dependencies
61
+ end_sucessfully
42
62
  end
43
63
 
44
64
  # Resolves and copies a package and it's version to `elm-stuff/packages`
@@ -54,7 +74,7 @@ module ElmInstall
54
74
  @cache.repository(package).checkout(ref)
55
75
 
56
76
  version_str = ref == version ? ref : "#{ref}(#{version})"
57
- Utils.log_with_dot "#{package_name} - #{version_str}"
77
+ Utils.log_with_dot "#{package_name.bold} - #{version_str.bold}"
58
78
 
59
79
  return if Dir.exist?(package_path)
60
80
 
@@ -54,8 +54,6 @@ module ElmInstall
54
54
  def add_package(package)
55
55
  return if @cache.package?(package)
56
56
 
57
- Utils.log_with_dot "Package: #{package} not found in cache, cloning..."
58
-
59
57
  @cache
60
58
  .repository(package)
61
59
  .tags
@@ -23,6 +23,10 @@ module ElmInstall
23
23
  puts ' ● '.green + message
24
24
  end
25
25
 
26
+ def log_with_arrow(message)
27
+ puts " ▶ #{message}"
28
+ end
29
+
26
30
  def package_version_path(package, version)
27
31
  package_name = GitCloneUrl.parse(package).path
28
32
  [package_name, File.join('elm-stuff', 'packages', package_name, version)]
@@ -1,3 +1,3 @@
1
1
  module ElmInstall
2
- VERSION = '0.1.0'.freeze
2
+ VERSION = '0.1.1'.freeze
3
3
  end
@@ -0,0 +1 @@
1
+ elm-install
data/packaging/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ ruby '2.2.2'
4
+
5
+ gem 'elm_install'
@@ -0,0 +1,34 @@
1
+ GEM
2
+ remote: https://rubygems.org/
3
+ specs:
4
+ colorize (0.8.1)
5
+ commander (4.4.2)
6
+ highline (~> 1.7.2)
7
+ elm_install (0.1.0)
8
+ colorize (~> 0.8.1)
9
+ commander (~> 4.4, >= 4.4.2)
10
+ git (~> 1.3)
11
+ git_clone_url (~> 2.0)
12
+ solve (~> 3.1)
13
+ git (1.3.0)
14
+ git_clone_url (2.0.0)
15
+ uri-ssh_git (>= 2.0)
16
+ highline (1.7.8)
17
+ molinillo (0.5.4)
18
+ semverse (2.0.0)
19
+ solve (3.1.0)
20
+ molinillo (>= 0.5)
21
+ semverse (>= 1.1, < 3.0)
22
+ uri-ssh_git (2.0.0)
23
+
24
+ PLATFORMS
25
+ ruby
26
+
27
+ DEPENDENCIES
28
+ elm_install
29
+
30
+ RUBY VERSION
31
+ ruby 2.2.2p95
32
+
33
+ BUNDLED WITH
34
+ 1.13.6
@@ -0,0 +1,93 @@
1
+ # For Bundler.with_clean_env
2
+ require 'bundler/setup'
3
+ require_relative '../lib/elm_install'
4
+
5
+ PACKAGE_NAME = 'elm-install'.freeze
6
+ VERSION = ElmInstall::VERSION
7
+ TRAVELING_RUBY_VERSION = '20150715-2.2.2'.freeze
8
+
9
+ desc 'Package your app'
10
+ task package: ['package:linux:x86', 'package:linux:x86_64', 'package:osx']
11
+
12
+ namespace :package do
13
+ namespace :linux do
14
+ desc 'Package your app for Linux x86'
15
+ task x86: [
16
+ :bundle_install,
17
+ "traveling-ruby-#{TRAVELING_RUBY_VERSION}-linux-x86.tar.gz"
18
+ ] do
19
+ create_package('linux-x86')
20
+ end
21
+
22
+ desc 'Package your app for Linux x86_64'
23
+ task x86_64: [
24
+ :bundle_install,
25
+ "traveling-ruby-#{TRAVELING_RUBY_VERSION}-linux-x86_64.tar.gz"
26
+ ] do
27
+ create_package('linux-x86_64')
28
+ end
29
+ end
30
+
31
+ desc 'Package your app for OS X'
32
+ task osx: [
33
+ :bundle_install,
34
+ "traveling-ruby-#{TRAVELING_RUBY_VERSION}-osx.tar.gz"
35
+ ] do
36
+ create_package('osx')
37
+ end
38
+
39
+ desc 'Install gems to local directory'
40
+ task :bundle_install do
41
+ sh 'rm -rf tmp'
42
+ sh 'mkdir tmp'
43
+ sh 'cp Gemfile Gemfile.lock tmp/'
44
+ Bundler.with_clean_env do
45
+ sh 'cd tmp && env BUNDLE_IGNORE_CONFIG=1 bundle install --path ../vendor --without development'
46
+ end
47
+ sh 'rm -rf tmp'
48
+ sh 'rm -f vendor/*/*/cache/*'
49
+ end
50
+ end
51
+
52
+ file "traveling-ruby-#{TRAVELING_RUBY_VERSION}-linux-x86.tar.gz" do
53
+ download_runtime('linux-x86')
54
+ end
55
+
56
+ file "traveling-ruby-#{TRAVELING_RUBY_VERSION}-linux-x86_64.tar.gz" do
57
+ download_runtime('linux-x86_64')
58
+ end
59
+
60
+ file "traveling-ruby-#{TRAVELING_RUBY_VERSION}-osx.tar.gz" do
61
+ download_runtime('osx')
62
+ end
63
+
64
+ def create_package(target)
65
+ package_dir = "#{PACKAGE_NAME}-#{VERSION}-#{target}"
66
+ sh "rm -rf #{package_dir}"
67
+ sh "mkdir #{package_dir}"
68
+ sh "mkdir -p #{package_dir}/lib/app"
69
+ sh "mkdir #{package_dir}/lib/ruby"
70
+ sh "tar -xzf traveling-ruby-#{TRAVELING_RUBY_VERSION}-#{target}.tar.gz -C #{package_dir}/lib/ruby"
71
+ sh "cp wrapper.sh #{package_dir}/elm-install"
72
+ sh "chmod +x #{package_dir}/elm-install"
73
+ sh "cp -pR vendor #{package_dir}/lib/"
74
+ sh "cp Gemfile Gemfile.lock #{package_dir}/lib/vendor/"
75
+ sh "mkdir #{package_dir}/lib/vendor/.bundle"
76
+ sh "cp bundler-config #{package_dir}/lib/vendor/.bundle/config"
77
+
78
+ sh 'rm -rf lib/vendor/ruby/*/gems/*/test'
79
+ sh 'rm -rf lib/vendor/ruby/*/gems/*/tests'
80
+ sh 'rm -rf lib/vendor/ruby/*/gems/*/spec'
81
+ sh 'rm -rf lib/vendor/ruby/*/gems/*/features'
82
+ sh 'rm -rf lib/vendor/ruby/*/gems/*/benchmark'
83
+
84
+ unless ENV['DIR_ONLY']
85
+ sh "tar -czf #{package_dir}.tar.gz #{package_dir}"
86
+ sh "rm -rf #{package_dir}"
87
+ end
88
+ end
89
+
90
+ def download_runtime(target)
91
+ sh 'curl -L -O --fail ' \
92
+ "https://d6r77u77i8pq3.cloudfront.net/releases/traveling-ruby-#{TRAVELING_RUBY_VERSION}-#{target}.tar.gz"
93
+ end
@@ -0,0 +1,3 @@
1
+ BUNDLE_PATH: .
2
+ BUNDLE_WITHOUT: development
3
+ BUNDLE_DISABLE_SHARED_GEMS: '1'
@@ -0,0 +1,12 @@
1
+ #!/bin/bash
2
+ set -e
3
+
4
+ # Figure out where this script is located.
5
+ SELFDIR="`dirname \"$0\"`"
6
+ SELFDIR="`cd \"$SELFDIR\" && pwd`"
7
+
8
+ export BUNDLE_GEMFILE="$SELFDIR/lib/vendor/Gemfile"
9
+ unset BUNDLE_IGNORE_CONFIG
10
+
11
+ # Run the actual binary using the bundled Ruby.
12
+ exec "$SELFDIR/lib/ruby/bin/ruby" -rbundler/setup "$SELFDIR/lib/vendor/ruby/2.2.0/bin/elm-install" "$@"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: elm_install
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gusztáv Szikszai
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-12-23 00:00:00.000000000 Z
11
+ date: 2016-12-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: git
@@ -73,19 +73,39 @@ dependencies:
73
73
  - !ruby/object:Gem::Version
74
74
  version: 4.4.2
75
75
  - !ruby/object:Gem::Dependency
76
- name: colorize
76
+ name: smart_colored
77
77
  requirement: !ruby/object:Gem::Requirement
78
78
  requirements:
79
79
  - - "~>"
80
80
  - !ruby/object:Gem::Version
81
- version: 0.8.1
81
+ version: '1.1'
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: 1.1.1
85
+ type: :runtime
86
+ prerelease: false
87
+ version_requirements: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - "~>"
90
+ - !ruby/object:Gem::Version
91
+ version: '1.1'
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: 1.1.1
95
+ - !ruby/object:Gem::Dependency
96
+ name: hashdiff
97
+ requirement: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - "~>"
100
+ - !ruby/object:Gem::Version
101
+ version: 0.3.1
82
102
  type: :runtime
83
103
  prerelease: false
84
104
  version_requirements: !ruby/object:Gem::Requirement
85
105
  requirements:
86
106
  - - "~>"
87
107
  - !ruby/object:Gem::Version
88
- version: 0.8.1
108
+ version: 0.3.1
89
109
  description:
90
110
  email: gusztav.szikszai@digitalnatives.hu
91
111
  executables:
@@ -111,6 +131,12 @@ files:
111
131
  - lib/elm_install/resolver.rb
112
132
  - lib/elm_install/utils.rb
113
133
  - lib/elm_install/version.rb
134
+ - packaging/.ruby-gemset
135
+ - packaging/Gemfile
136
+ - packaging/Gemfile.lock
137
+ - packaging/Rakefile
138
+ - packaging/bundler-config
139
+ - packaging/wrapper.sh
114
140
  homepage: https://github.com/gdotdesign/elm-github-install
115
141
  licenses: []
116
142
  metadata: {}
@@ -130,7 +156,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
130
156
  version: '0'
131
157
  requirements: []
132
158
  rubyforge_project:
133
- rubygems_version: 2.5.2
159
+ rubygems_version: 2.4.8
134
160
  signing_key:
135
161
  specification_version: 4
136
162
  summary: Install Elm packages from git repositories.