cocoaseeds 0.3.0 → 0.4.0

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: 4d9fd573a0fb96497fe521d33f9dd057c01857a8
4
- data.tar.gz: bfad6abeaabb6b2145d8f7d55328016e9e69adad
3
+ metadata.gz: cb1ce5d4cf02f05991f1115ea60a9c41465c1689
4
+ data.tar.gz: f1987ccb684d7e1e46c39f3c8647cf4ea51be0aa
5
5
  SHA512:
6
- metadata.gz: 595b220ac03001e852bf1d29cd04a1559984433f6a6036b62b3bb7f9d252e527de7337e45dbd09aeefce4a4f1085aaeabc93dc59f573b03688f96dcf35abc516
7
- data.tar.gz: eb8a3f2e982a4b947d4748961384bbce18f1d54abc6068ceded326a0696a849488424a8589c357bf823d7684326682809ad93a2dfe796e8726b1d08e45c7710d
6
+ metadata.gz: 6ec636215395f95bb79487983bb722eee49112eaa8573d84999ea80d764c86eddb1afd02ee64fcf51200e3f31f35d68e045f83071f7adb1e8752b757cdaab6a4
7
+ data.tar.gz: b6135203d4f2535d496d376868f327287686209d9d05debee598c03f90877c516ba5f0adfb544c280660a61c84e8375094ab66a339d3a6a8019b9cb1fd4831d6
data/README.md CHANGED
@@ -33,7 +33,7 @@ How to Use CocoaSeeds
33
33
 
34
34
  ### 1. Write a Seedfile
35
35
 
36
- A *Seedfile* is a ruby script that manifests the dependencies of your project. You can manage third party libraries by simply specifying them in the Seedfile. Currently, CocoaSeeds supports only GitHub repositories. However, we are planning to support other version control systems.
36
+ A *Seedfile* is a ruby script that manifests the dependencies of your project. You can manage third party libraries by simply specifying them in the Seedfile. Currently, CocoaSeeds supports only GitHub and BitBucket repositories. However, we are planning to support other version control systems.
37
37
 
38
38
  Let's make an empty file named **Seedfile** in the directory where your Xcode project file is located. Here is a sample Seedfile:
39
39
 
@@ -43,7 +43,7 @@ Let's make an empty file named **Seedfile** in the directory where your Xcode pr
43
43
  github "Alamofire/Alamofire", "1.2.1", :files => "Source/*.{swift,h}"
44
44
  github "devxoul/JLToast", "1.2.5", :files => "JLToast/*.{swift,h}"
45
45
  github "devxoul/SwipeBack", "1.0.4"
46
- github "Masonry/SnapKit", "0.10.0", :files => "Source/*.{swift,h}"
46
+ github "SnapKit/SnapKit", :commit => "62e7645", :files => "Source/*.{swift,h}"
47
47
 
48
48
  target :MyAppTest do
49
49
  github "Quick/Quick", "v0.3.1", :files => "Quick/**.{swift,h}"
@@ -58,14 +58,14 @@ Each line in a Seedfile consists of three parts: source, tag, and files. Let's l
58
58
  ```ruby
59
59
  github "devxoul/JLToast", "1.2.5", :files => "JLToast/*.{swift,h}"
60
60
  ~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
61
- (Source) (Tag) (Files)
61
+ (Source) (Version) (Files)
62
62
  ```
63
63
 
64
- | Parts | Example | Required | Default |
65
- |--------|-----------------------------------|:--------:|:---------------------:|
66
- | Source | `github "devxoul/SwipeBack"` | Required | - |
67
- | Tag | `1.0.4` | Required | - |
68
- | Files | `:files => "JLToast/*.{swift,h}"` | Optional | `*/**.{h,m,mm,swift}` |
64
+ | Parts | Example | Required | Default |
65
+ |---------|-----------------------------------|:--------:|:---------------------:|
66
+ | Source | `github "devxoul/SwipeBack"` | Required | - |
67
+ | Version | Tag: `"1.0.4"`<br>Branch: `"swift-2.0"`<br>Commit: `:commit => "SHA1"` | Required | - |
68
+ | Files | `:files => "JLToast/*.{swift,h}"` | Optional | `*/**.{h,m,mm,swift}` |
69
69
 
70
70
  > **Tip:** You can pass an array to `:files` for multiple file patterns:
71
71
  >
@@ -161,6 +161,10 @@ module Seeds
161
161
  seed = Seeds::Seed.new
162
162
  seed.name = lock.split(' (')[0]
163
163
  seed.version = lock.split('(')[1].split(')')[0]
164
+ if seed.version.start_with? '$'
165
+ seed.commit = seed.version[1..-1]
166
+ seed.version = nil
167
+ end
164
168
  self.locks[seed.name] = seed
165
169
  end
166
170
  end
@@ -224,8 +228,17 @@ module Seeds
224
228
  seed = Seeds::Seed::GitHub.new
225
229
  seed.url = "https://github.com/#{repo}"
226
230
  seed.name = repo.split('/')[1]
227
- seed.version = tag
228
- seed.files = options[:files] || '**/*.{h,m,mm,swift}'
231
+ if tag.is_a?(String)
232
+ if options[:commit]
233
+ raise Seeds::Exception.new\
234
+ "#{repo}: Version and commit are both specified."
235
+ end
236
+ seed.version = tag
237
+ seed.files = options[:files] || '**/*.{h,m,mm,swift}'
238
+ elsif tag.is_a?(Hash)
239
+ seed.commit = tag[:commit][0..6]
240
+ seed.files = tag[:files] || '**/*.{h,m,mm,swift}'
241
+ end
229
242
  if seed.files.kind_of?(String)
230
243
  seed.files = [seed.files]
231
244
  end
@@ -256,8 +269,17 @@ module Seeds
256
269
  seed = Seeds::Seed::BitBucket.new
257
270
  seed.url = "https://bitbucket.org/#{repo}"
258
271
  seed.name = repo.split('/')[1]
259
- seed.version = tag
260
- seed.files = options[:files] || '**/*.{h,m,mm,swift}'
272
+ if tag.is_a?(String)
273
+ if options[:commit]
274
+ raise Seeds::Exception.new\
275
+ "#{repo}: Version and commit are both specified."
276
+ end
277
+ seed.version = tag
278
+ seed.files = options[:files] || '**/*.{h,m,mm,swift}'
279
+ elsif tag.is_a?(Hash)
280
+ seed.commit = tag[:commit][0..6]
281
+ seed.files = tag[:files] || '**/*.{h,m,mm,swift}'
282
+ end
261
283
  if seed.files.kind_of?(String)
262
284
  seed.files = [seed.files]
263
285
  end
@@ -289,53 +311,107 @@ module Seeds
289
311
  #
290
312
  def install_seeds
291
313
  self.seeds.sort.each do |name, seed|
292
- dirname = File.join(self.root_path, "Seeds", name)
314
+ dirname = File.join(self.root_path, "Seeds", seed.name)
315
+ self.install_seed(seed, dirname)
316
+
317
+ next if not seed.files
318
+
319
+ # add seed files to `source_files`
320
+ self.source_files[name] = []
321
+ seed.files.each do |file|
322
+ paths = Dir.glob(File.join(dirname, file))
323
+ paths.each do |path|
324
+ path = self.path_with_prefix(seed.name, path)
325
+ self.source_files[name].push(path)
326
+ end
327
+ end
328
+ end
329
+ end
293
330
 
294
- if lock = self.locks[name]
295
- old_version = lock.version
331
+
332
+ # Installs new seed or updates existing seed in {#dirname}.
333
+ #
334
+ # @!visibility private
335
+ #
336
+ def install_seed(seed, dirname)
337
+ # if remote url has changed, remove directory and clone again
338
+ remote_url = `
339
+ cd #{dirname} 2>&1 &&
340
+ git remote show origin -n | grep Fetch | awk '{ print $3 }' 2>&1
341
+ `.strip
342
+ if remote_url != seed.url
343
+ FileUtils.rm_rf(dirname)
344
+ end
345
+
346
+ # clone and return if not exists
347
+ if not File.exist?(dirname)
348
+ say "Installing #{seed.name} (#{seed.version or seed.commit})".green
349
+
350
+ command = "git clone #{seed.url}"
351
+ command += " -b #{seed.version}" if seed.version
352
+ command += " #{dirname} 2>&1"
353
+ output = `#{command}`
354
+
355
+ not_found = output.include?("not found")
356
+ if not_found and output.include?("repository")
357
+ raise Seeds::Exception.new\
358
+ "#{seed.name}: Couldn't find the repository."
359
+ elsif not_found and output.include?("upstream")
360
+ raise Seeds::Exception.new\
361
+ "#{seed.name}: Couldn't find the tag `#{seed.version}`."
296
362
  end
297
363
 
298
- if File.exist?(dirname)
299
- tag = `cd #{dirname} && git describe --tags --abbrev=0 2>&1`
300
- tag.strip!
301
- if tag == seed.version and (not old_version or tag == old_version)
302
- say "Using #{name} (#{seed.version})"
303
- `cd #{dirname} 2>&1 &&\
304
- git reset HEAD --hard 2>&1 &&\
305
- git checkout . 2>&1 &&\
306
- git clean -fd 2>&1`
307
- else
308
- say "Installing #{name} #{seed.version} (was #{old_version})".green
309
- `cd #{dirname} 2>&1 &&\
310
- git reset HEAD --hard 2>&1 &&\
311
- git checkout . 2>&1 &&\
312
- git clean -fd 2>&1 &&\
313
- git fetch origin #{seed.version} --tags 2>&1 &&\
314
- git checkout #{seed.version} 2>&1`
315
- end
316
- else
317
- say "Installing #{name} (#{seed.version})".green
318
- output = `git clone #{seed.url} -b #{seed.version} #{dirname} 2>&1`
319
- if output.include?("not found")
320
- if output.include?("repository")
321
- say "[!] #{name}: Couldn't find the repository.".red
322
- elsif output.include?("upstream")
323
- say "[!] #{name}: Couldn't find the tag `#{seed.version}`.".red
324
- end
364
+ if seed.commit and not seed.version # checkout to commit
365
+ output = `cd #{dirname} 2>&1 && git checkout #{seed.commit} 2>&1`
366
+ if output.include?("did not match any")
367
+ raise Seeds::Exception.new\
368
+ "#{seed.name}: Couldn't find the commit `#{seed.commit}`."
325
369
  end
326
370
  end
327
371
 
328
- if seed.files
329
- self.source_files[name] = []
330
- seed.files.each do |file|
331
- paths = Dir.glob(File.join(dirname, file))
332
- paths.each do |path|
333
- path = self.path_with_prefix(seed.name, path)
334
- self.source_files[name].push(path)
335
- end
336
- end
372
+ return
373
+ end
374
+
375
+ # discard local changes
376
+ `cd #{dirname} 2>&1 &&\
377
+ git reset HEAD --hard 2>&1 &&\
378
+ git checkout . 2>&1 &&\
379
+ git clean -fd 2>&1`
380
+
381
+ if lock = self.locks[seed.name]
382
+ lock_version = lock.version
383
+ lock_commit = lock.commit
384
+ end
385
+
386
+ if seed.version == lock_version and seed.commit == lock_commit
387
+ say "Using #{seed.name} (#{lock_version or lock_commit})"
388
+ return
389
+ end
390
+
391
+ if seed.version
392
+ say "Installing #{seed.name} #{seed.version}"\
393
+ " (was #{lock_version or lock_commit})".green
394
+ output = `cd #{dirname} 2>&1 &&\
395
+ git fetch origin #{seed.version} --tags 2>&1 &&\
396
+ git checkout #{seed.version} 2>&1`
397
+ if output.include?("Couldn't find")
398
+ raise Seeds::Exception.new\
399
+ "#{seed.name}: Couldn't find the tag or branch `#{seed.version}`."
400
+ end
401
+
402
+ elsif seed.commit
403
+ say "Installing #{seed.name} #{seed.commit}"\
404
+ " (was #{lock_version or lock_commit})".green
405
+ output = `cd #{dirname} 2>&1 &&
406
+ git checkout master 2>&1 &&
407
+ git pull 2>&1 &&
408
+ git checkout #{seed.commit} 2>&1`
409
+ if output.include?("did not match any")
410
+ raise Seeds::Exception.new\
411
+ "#{seed.name}: Couldn't find the commit `#{seed.commit}`.".red
337
412
  end
338
413
  end
414
+
339
415
  end
340
416
 
341
417
  # Append seed name as a prefix to file name and returns the path.
@@ -463,7 +539,7 @@ module Seeds
463
539
  def build_lockfile
464
540
  tree = { "SEEDS" => [] }
465
541
  self.seeds.each do |name, seed|
466
- tree["SEEDS"] << "#{name} (#{seed.version})"
542
+ tree["SEEDS"] << "#{name} (#{seed.version or '$' + seed.commit})"
467
543
  end
468
544
  File.write(self.lockfile_path, YAML.dump(tree))
469
545
  end
@@ -9,6 +9,10 @@ module Seeds
9
9
  #
10
10
  attr_accessor :version
11
11
 
12
+ # @return [String] the commit hash of the seed
13
+ #
14
+ attr_accessor :commit
15
+
12
16
  # @return [String] the url of the seed
13
17
  #
14
18
  attr_accessor :url
@@ -1,3 +1,3 @@
1
1
  module Seeds
2
- VERSION = "0.3.0"
2
+ VERSION = "0.4.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cocoaseeds
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Suyeol Jeon
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-10-14 00:00:00.000000000 Z
11
+ date: 2015-10-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: xcodeproj