file-timestamp 1.4.0 → 1.5.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.
Files changed (3) hide show
  1. checksums.yaml +8 -8
  2. data/bin/timestamp +18 -13
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ZjUwOTc0NDJkZTBhZTUwZGFhZmJlYTdjNjVmMGEwZjY0NjRhNjgxYw==
4
+ YmQ0MDRiZGJmMGQ5MWI4OGYyNGVlZjI1YmE2M2E5N2ZiNzYyNzYzMA==
5
5
  data.tar.gz: !binary |-
6
- ZWQ1NDM2ZmMyNzljZjM3ZGMwMGYwNjgwZDYyOWZkYWE2ZDkxMDE2MQ==
6
+ NzJhYTU3YzEyNmU5NzVkZTk1N2JmNWQ5ZDU1MjJiZTI0NWNiMjlkMg==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- Zjc0M2M0Nzc3YzNlNGViZjk5ZGZkYzBiYWMzMDA3Mjk3MWQ1OGUyNzQ3NTNj
10
- MDk2MzJmMDc4N2JjZWNlZWQ0MTU0MTNlMjlkMDZjYWZkNTk5OTIwMjYzY2Q3
11
- MGM3ODdjMDY5ZmI4NGUxMjIwNWJkN2RmNTFkMjdiMGM3OWVhYTY=
9
+ ZTJhY2FkZjJjODM2ZWQ1ZDQ1OTJjZDQyNzQyN2M3ODdiZjVjOWYyMmExOTdj
10
+ YzUzYWU0MDk3MWE4NDgxNjIxYTgxNzRmMTE3YTZmNWJiOTI0NzU2N2Y3MjE4
11
+ MWJhMDQ5MDljNWQwYTE0MjBmNmJkZDI2N2YzMGU5NzBkNjU0NjY=
12
12
  data.tar.gz: !binary |-
13
- MDI5ZWJmMTgwMDc0YTk3ZWQ2MGE3ZGRkMzdjZmMxNjI4YjNjZGRhNTU1ZWJj
14
- YjRiNTcxMTVhODc4YTQyNzQ5M2Q1ODBhZTFlNTBkNjcyNTBlMWViYzA5NTU5
15
- OGVkZDY2MTgzNGJiNDAzZTI1NWVkNjFlZTE1NjZhNGNmOGY1ZDM=
13
+ MDkyM2Y3ZmRkZmI1YzdjMTI0M2YxMDFjZTBkYjExZTgzNDhiZDg3MmJhYzgw
14
+ OWMyNTFhZmQ0YWE2ODhkOWQzZmI0NTA2MTMwMmE2MzJkYjkzMzkyMzA5ZTFi
15
+ ZjBmMGIwODEwZjQ4ODllZTk1NzRmZDNiNTUxOTEzOTA2NjZkOTI=
data/bin/timestamp CHANGED
@@ -5,9 +5,9 @@ require 'rubygems'
5
5
  require 'json'
6
6
  require 'optparse'
7
7
 
8
- VERSION = "1.4"
8
+ VERSION = "1.5"
9
9
 
10
- def collectFileMtime dir, file_ext, exclude_dir
10
+ def collectFileMtime dir, exclude_ext, exclude_dir, include_ext
11
11
  # debugger
12
12
  map = {}
13
13
  full_dir = File.expand_path dir
@@ -15,9 +15,9 @@ def collectFileMtime dir, file_ext, exclude_dir
15
15
  is_empty = true
16
16
  Dir.foreach "." do |file|
17
17
  if File.directory? file
18
- unless exclude_dir.include? file
18
+ unless exclude_dir.to_s.include? file
19
19
  pwd = Dir.pwd
20
- submap = collectFileMtime file, file_ext, exclude_dir
20
+ submap = collectFileMtime file, exclude_ext, exclude_dir, include_ext
21
21
  is_empty = false unless submap.nil? or submap.empty?
22
22
  unless submap.nil?
23
23
  map[file] = submap
@@ -25,9 +25,12 @@ def collectFileMtime dir, file_ext, exclude_dir
25
25
  Dir.chdir pwd
26
26
  end
27
27
  else
28
- if file_ext.include? File.extname file
29
- map[file] = (File.mtime file).strftime "%Y%m%d%H%M%S"
30
- is_empty = false
28
+ ext = File.extname file
29
+ if include_ext.length == 0 or include_ext.to_s.include?(ext)
30
+ unless exclude_ext.to_s.include? ext
31
+ map[file] = (File.mtime file).strftime "%Y%m%d%H%M%S"
32
+ is_empty = false
33
+ end
31
34
  end
32
35
  end
33
36
  end
@@ -38,7 +41,8 @@ end
38
41
  option = {
39
42
  :pretty => false,
40
43
  :template => "#output#",
41
- :include_ext => [".js",".css"],
44
+ :exclude_ext => [".DS_Store", ".swp"],
45
+ :include_ext => [],
42
46
  :exclude_dir => [".","..",".svn",".git"]
43
47
  }
44
48
 
@@ -49,10 +53,11 @@ file-timestamp #{VERSION}
49
53
  Usage:
50
54
  timestamp [dir] 按目录树结构输出指定目录下的所有指定类型文件的时间戳JSON,默认输出当前目录
51
55
  EOF
52
- opts.on('--format', "格式化输出") { option[:format] = true }
56
+ opts.on('--pretty', "格式化输出") { option[:pretty] = true }
53
57
  opts.on('--template <template>', '指定模板文本,内容占位符为#output#,如--template ";var json=#output#;"') { |template| option[:template] = template}
54
- opts.on("--include x,y,z", Array, "要输出时间戳的文件扩展名,默认--include .js,.css") { |include_ext| option[:include_ext] = include_ext }
55
- opts.on("--exclude x,y,z", Array, "要排除的目录,默认--exlude .svn,.git") { |exclude_dir| option[:exclude_dir].concat exclude_dir }
58
+ opts.on("--include-ext x,y,z", Array, "要包含的文件扩展名") { |include_ext| option[:include_ext].concat include_ext }
59
+ opts.on("--exclude-ext x,y,z", Array, "要排除的文件扩展名") { |exclude_ext| option[:exclude_ext].concat exclude_ext }
60
+ opts.on("--exclude-dir x,y,z", Array, "要排除的目录,默认--exclude-dir .svn,.git") { |exclude_dir| option[:exclude_dir].concat exclude_dir }
56
61
  opts.on("--seajs", "使用默认的seajs模板"){option[:template] = ";define('timestamp', function(require, exports, module) {\n module.exports =#output#\n});" }
57
62
  opts.on("--version", "显示版本"){option[:version] = true}
58
63
 
@@ -61,9 +66,9 @@ timestamp [dir] 按目录树结构输出指定目录下的所有指定类型文
61
66
  if option[:version]
62
67
  puts VERSION
63
68
  else
64
- tree = collectFileMtime(ARGV[0] || ".", option[:include_ext], option[:exclude_dir])
69
+ tree = collectFileMtime(ARGV[0] || ".", option[:exclude_ext], option[:exclude_dir], option[:include_ext])
65
70
 
66
- if option[:format]
71
+ if option[:pretty]
67
72
  output = JSON.pretty_generate(tree)
68
73
  else
69
74
  output = tree.to_json
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: file-timestamp
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.0
4
+ version: 1.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Zhong Xingdou