file-timestamp 1.5.0 → 1.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +8 -8
  2. data/bin/timestamp +22 -6
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- YmQ0MDRiZGJmMGQ5MWI4OGYyNGVlZjI1YmE2M2E5N2ZiNzYyNzYzMA==
4
+ OGU5Y2NmMGU0NWU5ZDY0OWUxNWIyMDVkOWM1OWMyOWVjYmZhMzY4Nw==
5
5
  data.tar.gz: !binary |-
6
- NzJhYTU3YzEyNmU5NzVkZTk1N2JmNWQ5ZDU1MjJiZTI0NWNiMjlkMg==
6
+ N2MyZWY3ZDMxMGQ4ZGVlZDNlNzhmZjU2N2Q0MTIxZDU5Nzg3NzcyMw==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- ZTJhY2FkZjJjODM2ZWQ1ZDQ1OTJjZDQyNzQyN2M3ODdiZjVjOWYyMmExOTdj
10
- YzUzYWU0MDk3MWE4NDgxNjIxYTgxNzRmMTE3YTZmNWJiOTI0NzU2N2Y3MjE4
11
- MWJhMDQ5MDljNWQwYTE0MjBmNmJkZDI2N2YzMGU5NzBkNjU0NjY=
9
+ NWY0Yjc1YTJhZDJhNTg4YWQzYTZhZGRkMmMyNDRmMmE1OTJlNjlhY2RkNGQw
10
+ MDA3NWE2NzA1NzE2YTlmMTBlZmQ4ZGFjODA0NWMyNGNmN2YzMDg2YWQ0ZTU0
11
+ OTI1YThkODZhYWZlMzM5NDc1ZjMxOGIxZWY0MWVjMzYzYzg0ZDU=
12
12
  data.tar.gz: !binary |-
13
- MDkyM2Y3ZmRkZmI1YzdjMTI0M2YxMDFjZTBkYjExZTgzNDhiZDg3MmJhYzgw
14
- OWMyNTFhZmQ0YWE2ODhkOWQzZmI0NTA2MTMwMmE2MzJkYjkzMzkyMzA5ZTFi
15
- ZjBmMGIwODEwZjQ4ODllZTk1NzRmZDNiNTUxOTEzOTA2NjZkOTI=
13
+ ZGNiNjg5YzA2ZTNjM2E3MWYwOTQ4NjY2MzlmNGZmMWIwNWU1MWZkOWNjZmM2
14
+ MjE0ODNmZjg2YTNkM2VkNDBiNmViODc3OGExMjdlMmVkZTZlYzdhMzJmMmI1
15
+ OGMyOTFmODJhNTdlNmRlOTA5NmMyYmM2OTU2ZTVkZDMyZTkwMjQ=
data/bin/timestamp CHANGED
@@ -4,10 +4,17 @@
4
4
  require 'rubygems'
5
5
  require 'json'
6
6
  require 'optparse'
7
+ require 'digest/md5'
7
8
 
8
- VERSION = "1.5"
9
+ VERSION = "1.6"
10
+
11
+ def collectFileMtime dir, option
12
+ exclude_ext = option[:exclude_ext]
13
+ exclude_dir = option[:exclude_dir]
14
+ include_ext = option[:include_ext]
15
+ md5 = option[:md5]
16
+ formatter = option[:time_format]
9
17
 
10
- def collectFileMtime dir, exclude_ext, exclude_dir, include_ext
11
18
  # debugger
12
19
  map = {}
13
20
  full_dir = File.expand_path dir
@@ -17,7 +24,7 @@ def collectFileMtime dir, exclude_ext, exclude_dir, include_ext
17
24
  if File.directory? file
18
25
  unless exclude_dir.to_s.include? file
19
26
  pwd = Dir.pwd
20
- submap = collectFileMtime file, exclude_ext, exclude_dir, include_ext
27
+ submap = collectFileMtime file, option
21
28
  is_empty = false unless submap.nil? or submap.empty?
22
29
  unless submap.nil?
23
30
  map[file] = submap
@@ -28,7 +35,12 @@ def collectFileMtime dir, exclude_ext, exclude_dir, include_ext
28
35
  ext = File.extname file
29
36
  if include_ext.length == 0 or include_ext.to_s.include?(ext)
30
37
  unless exclude_ext.to_s.include? ext
31
- map[file] = (File.mtime file).strftime "%Y%m%d%H%M%S"
38
+ mtime = File.mtime file
39
+ if md5 > 0
40
+ map[file] = Digest::MD5.hexdigest(mtime.to_s)[0...md5];
41
+ else
42
+ map[file] = mtime.strftime formatter
43
+ end
32
44
  is_empty = false
33
45
  end
34
46
  end
@@ -43,7 +55,9 @@ option = {
43
55
  :template => "#output#",
44
56
  :exclude_ext => [".DS_Store", ".swp"],
45
57
  :include_ext => [],
46
- :exclude_dir => [".","..",".svn",".git"]
58
+ :exclude_dir => [".","..",".svn",".git"],
59
+ :md5 => 0,
60
+ :time_format => "%Y%m%d%H%M%S"
47
61
  }
48
62
 
49
63
  begin
@@ -59,6 +73,8 @@ timestamp [dir] 按目录树结构输出指定目录下的所有指定类型文
59
73
  opts.on("--exclude-ext x,y,z", Array, "要排除的文件扩展名") { |exclude_ext| option[:exclude_ext].concat exclude_ext }
60
74
  opts.on("--exclude-dir x,y,z", Array, "要排除的目录,默认--exclude-dir .svn,.git") { |exclude_dir| option[:exclude_dir].concat exclude_dir }
61
75
  opts.on("--seajs", "使用默认的seajs模板"){option[:template] = ";define('timestamp', function(require, exports, module) {\n module.exports =#output#\n});" }
76
+ opts.on("--md5 <length>", "MD5 checksum代替时间戳"){ |length| option[:md5] = length.to_i }
77
+ opts.on("--time_format <format>", '时间戳的格式化字符串,默认为%Y%m%d%H%M%S'){ |format| option[:time_format] = format }
62
78
  opts.on("--version", "显示版本"){option[:version] = true}
63
79
 
64
80
  end.parse!
@@ -66,7 +82,7 @@ timestamp [dir] 按目录树结构输出指定目录下的所有指定类型文
66
82
  if option[:version]
67
83
  puts VERSION
68
84
  else
69
- tree = collectFileMtime(ARGV[0] || ".", option[:exclude_ext], option[:exclude_dir], option[:include_ext])
85
+ tree = collectFileMtime(ARGV[0] || ".", option.clone)
70
86
 
71
87
  if option[:pretty]
72
88
  output = JSON.pretty_generate(tree)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: file-timestamp
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.0
4
+ version: 1.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Zhong Xingdou
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-01-02 00:00:00.000000000 Z
11
+ date: 2013-10-10 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: ! " 按目录树输出包含文件最后修改时间的JSON\n output timestamp of directory for web
14
14
  front-end developer\n"