chest 0.1.0 → 1.0.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 55c3329304474c96b37ecad89d250855fc8fb1ae
4
- data.tar.gz: 309be62c63ac9496921b00344163cef9cc8d55be
3
+ metadata.gz: 65aa90d80384f349e429206838c688bdf2cdc8d6
4
+ data.tar.gz: 2577a229f02f5be3d5e914b8a4dda8244d00b229
5
5
  SHA512:
6
- metadata.gz: 15108dda85ff3f2c52f7159892b614b56b1b5f478042d8f8d26af24e2395c3d775bb8e6720fa2400e89cc15b84231bd1e9d277ad39b917735a66f823b04334a9
7
- data.tar.gz: af790a5c5eaa2f9941ca9b95076caa83eb8fa3a77fdfa9abf0cda80bfb0d413c1b872f47fe4cde0ba6de8c481f2aad51563a01041185e49e6568cdab0bbcd0e1
6
+ metadata.gz: 6b4def3328ee5719e23dcc1b74824238d184530629ef29ee42da3587b907ff80950b48716e4cb1e621262f6f00b52d97266d0c416cb914f2dfdef6fa0909d8da
7
+ data.tar.gz: e429e352e92e7e30ec39cc0a9946ccadd7019dddbd68d0c1c567d1a95820922c234c5361ce6607cf795fedce9ac710c72d1c7c09566250168262df17c14ea92b
data/README.md CHANGED
@@ -10,6 +10,25 @@ $ gem install chest
10
10
 
11
11
  ## Usage
12
12
 
13
+ You can install Sketch plugins from Github by using `install` command:
14
+
15
+ ```console
16
+ $ chest install https://github.com/uetchy/Sketch-StickyGrid.git
17
+ $ chest install uetchy/Sketch-StickyGrid
18
+ $ chest i uetchy/Sketch-StickyGrid
19
+ ```
20
+
21
+ Also you can use `uninstall`, `update`, `list` commands like this:
22
+
23
+ ```console
24
+ $ chest uninstall Sketch-StickyGrid # delete from Plugins folder
25
+ $ chest update Sketch-StickyGrid # pull from git
26
+ $ chest update # this updates all of plugins
27
+ $ chest list # list installed plugins
28
+ ```
29
+
30
+ To see all of available commands, use `help` command:
31
+
13
32
  ```console
14
33
  $ chest help
15
34
  ```
data/lib/chest.rb CHANGED
@@ -1,6 +1,4 @@
1
- require "chest/version"
2
- require "chest/plugin"
3
- require "chest/cli"
4
-
5
- module Chest
6
- end
1
+ require 'chest/config'
2
+ require 'chest/plugin'
3
+ require 'chest/version'
4
+ require 'chest/cli'
data/lib/chest/cli.rb CHANGED
@@ -2,27 +2,40 @@ require 'thor'
2
2
  require 'fileutils'
3
3
 
4
4
  class Chest::CLI < Thor
5
- PLUGINS_FOLDER = File.expand_path '~/Library/Containers/com.bohemiancoding.sketch3/Data/Library/Application Support/com.bohemiancoding.sketch3/Plugins'
6
-
7
5
  desc 'list', 'List plugins'
8
6
  def list
9
- plugins.each do |plugin|
7
+ Chest::Plugin.all.each do |plugin|
10
8
  puts "(#{plugin.kind})\t#{plugin.name}"
11
9
  end
12
10
  end
13
11
 
14
- desc 'install URL', 'Install plugin'
15
- def install(url)
16
- name = File.basename url, '.*'
17
- path = File.join(PLUGINS_FOLDER, name)
12
+ desc 'install QUERY', 'Install plugin'
13
+ def install(query)
14
+ if query =~ /\.git$/
15
+ # just url
16
+ name = File.basename query, '.*'
17
+ url = query
18
+ elsif query =~ /([^\/]+)\/([^\/]+)/
19
+ # user/repo
20
+ name = $2
21
+ url = "https://github.com/#{$1}/#{$2}.git"
22
+ end
23
+
24
+ path = File.join(Chest::PLUGINS_FOLDER, name)
25
+ if Dir.exist? path
26
+ puts "#{name} was already installed."
27
+ exit
28
+ end
29
+
18
30
  puts "Installing '#{name}' ..."
19
31
  system "git clone '#{url}' '#{path}'"
20
32
  end
21
33
 
22
34
  desc 'uninstall NAME', 'Uninstall plugin'
23
35
  def uninstall(name)
24
- path = File.join(PLUGINS_FOLDER, name)
36
+ path = File.join(Chest::PLUGINS_FOLDER, name)
25
37
  return unless Dir.exist? path
38
+
26
39
  puts "Uninstalling '#{name}' ..."
27
40
  FileUtils.rm_r(path)
28
41
  end
@@ -30,17 +43,9 @@ class Chest::CLI < Thor
30
43
  desc 'update [NAME]', 'Update plugins'
31
44
  def update(name=nil)
32
45
  if name
33
- plugins.find{|x| name == x.name and x.update}
46
+ Chest::Plugin.all.find{|x| name == x.name and x.update}
34
47
  else
35
- plugins.map(&:update)
48
+ Chest::Plugin.all.map(&:update)
36
49
  end
37
50
  end
38
-
39
- private
40
-
41
- def plugins
42
- Dir.glob(File.join(PLUGINS_FOLDER, '*')).collect do |path|
43
- Dir.exist?(path) ? Chest::Plugin.new(path) : nil
44
- end.compact
45
- end
46
51
  end
@@ -0,0 +1,62 @@
1
+ require 'json'
2
+ require 'ostruct'
3
+ require 'fileutils'
4
+
5
+ module Chest
6
+
7
+ CONFIG_NAME = '.chestrc'
8
+ CONFIG_PATH = File.expand_path(CONFIG_NAME, '~')
9
+
10
+ class FileMissingError < StandardError; end
11
+
12
+ class Config < OpenStruct
13
+ attr_reader :file_path
14
+
15
+ def initialize(file_path=CONFIG_PATH)
16
+ super({})
17
+ @file_path = file_path
18
+ self.load!
19
+ end
20
+
21
+ def load!
22
+ begin
23
+ if File.exist? @file_path
24
+ File.open(@file_path, 'r') do |f|
25
+ self.marshal_load(symbolize_keys(JSON(f.read)))
26
+ end
27
+ end
28
+ rescue Errno::ENOENT, IOError
29
+ raise FileMissingError
30
+ end
31
+ end
32
+
33
+ def update!(attributes={})
34
+ attributes_with!(attributes)
35
+ end
36
+
37
+ def attributes_with!(attributes={})
38
+ attributes.each do |key, value|
39
+ self.send(key.to_s + "=", value) if self.respond_to?(key.to_s + "=")
40
+ end
41
+ end
42
+
43
+ def save
44
+ FileUtils.mkpath(File.dirname(@file_path))
45
+ File.open(@file_path, 'w') {|f| f.puts self.to_json }
46
+ end
47
+
48
+ def to_hash
49
+ table.to_h
50
+ end
51
+
52
+ def to_json
53
+ JSON.pretty_generate(to_hash)
54
+ end
55
+
56
+ private
57
+
58
+ def symbolize_keys(hash)
59
+ hash.inject({}){|res, (k,v)| res[k.to_sym] = v; res}
60
+ end
61
+ end
62
+ end
data/lib/chest/plugin.rb CHANGED
@@ -1,37 +1,49 @@
1
- class Chest::Plugin
2
- attr_reader :path, :name, :kind
1
+ module Chest
2
+ PLUGINS_FOLDER = File.expand_path('~/Library/Containers/com.bohemiancoding.sketch3/Data/Library/Application Support/com.bohemiancoding.sketch3/Plugins')
3
3
 
4
- def initialize(path)
5
- @path = path
6
- @name = File.basename(path)
7
- @kind = guess_kind(path)
8
- end
4
+ class Plugin
5
+ attr_reader :path, :name, :kind
9
6
 
10
- def updatable?
11
- @kind != :local
12
- end
7
+ def initialize(path)
8
+ @path = path
9
+ @name = File.basename(path)
10
+ @kind = guess_kind(path)
11
+ end
13
12
 
14
- def update
15
- case @kind
16
- when :git
17
- update_git
18
- else
19
- false
13
+ def updatable?
14
+ @kind != :local
20
15
  end
21
- end
22
16
 
23
- def update_git
24
- puts "Updating '#{@name}' ..."
25
- system "cd '#{@path}' && git pull"
26
- end
17
+ def update
18
+ case @kind
19
+ when :git
20
+ update_git
21
+ else
22
+ puts "#{@name} is kind of un-updatable plugin"
23
+ false
24
+ end
25
+ end
26
+
27
+ class << self
28
+ def all
29
+ Dir.glob(File.join(PLUGINS_FOLDER, '*')).collect do |path|
30
+ Dir.exist?(path) ? Plugin.new(path) : nil
31
+ end.compact
32
+ end
33
+ end
27
34
 
28
- private
35
+ private
36
+ def guess_kind(path)
37
+ if Dir.exist? File.join(path, '.git')
38
+ :git
39
+ else
40
+ :local
41
+ end
42
+ end
29
43
 
30
- def guess_kind(path)
31
- if Dir.exist? File.join(path, '.git')
32
- :git
33
- else
34
- :local
44
+ def update_git
45
+ puts "Updating '#{@name}' ..."
46
+ system "cd '#{@path}' && git pull"
35
47
  end
36
48
  end
37
49
  end
data/lib/chest/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Chest
2
- VERSION = "0.1.0"
2
+ VERSION = "1.0.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chest
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yasuaki Uechi
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-02-15 00:00:00.000000000 Z
11
+ date: 2015-03-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -103,6 +103,7 @@ files:
103
103
  - exe/chest
104
104
  - lib/chest.rb
105
105
  - lib/chest/cli.rb
106
+ - lib/chest/config.rb
106
107
  - lib/chest/plugin.rb
107
108
  - lib/chest/version.rb
108
109
  homepage: https://github.com/uetchy/Sketch-Chest