file-timestamp 1.3.0 → 1.4.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 +15 -0
  2. data/bin/timestamp +29 -19
  3. metadata +6 -9
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ ZjUwOTc0NDJkZTBhZTUwZGFhZmJlYTdjNjVmMGEwZjY0NjRhNjgxYw==
5
+ data.tar.gz: !binary |-
6
+ ZWQ1NDM2ZmMyNzljZjM3ZGMwMGYwNjgwZDYyOWZkYWE2ZDkxMDE2MQ==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ Zjc0M2M0Nzc3YzNlNGViZjk5ZGZkYzBiYWMzMDA3Mjk3MWQ1OGUyNzQ3NTNj
10
+ MDk2MzJmMDc4N2JjZWNlZWQ0MTU0MTNlMjlkMDZjYWZkNTk5OTIwMjYzY2Q3
11
+ MGM3ODdjMDY5ZmI4NGUxMjIwNWJkN2RmNTFkMjdiMGM3OWVhYTY=
12
+ data.tar.gz: !binary |-
13
+ MDI5ZWJmMTgwMDc0YTk3ZWQ2MGE3ZGRkMzdjZmMxNjI4YjNjZGRhNTU1ZWJj
14
+ YjRiNTcxMTVhODc4YTQyNzQ5M2Q1ODBhZTFlNTBkNjcyNTBlMWViYzA5NTU5
15
+ OGVkZDY2MTgzNGJiNDAzZTI1NWVkNjFlZTE1NjZhNGNmOGY1ZDM=
@@ -5,7 +5,10 @@ require 'rubygems'
5
5
  require 'json'
6
6
  require 'optparse'
7
7
 
8
+ VERSION = "1.4"
9
+
8
10
  def collectFileMtime dir, file_ext, exclude_dir
11
+ # debugger
9
12
  map = {}
10
13
  full_dir = File.expand_path dir
11
14
  Dir.chdir full_dir
@@ -13,12 +16,13 @@ def collectFileMtime dir, file_ext, exclude_dir
13
16
  Dir.foreach "." do |file|
14
17
  if File.directory? file
15
18
  unless exclude_dir.include? file
19
+ pwd = Dir.pwd
16
20
  submap = collectFileMtime file, file_ext, exclude_dir
17
21
  is_empty = false unless submap.nil? or submap.empty?
18
22
  unless submap.nil?
19
23
  map[file] = submap
20
24
  end
21
- Dir.chdir ".."
25
+ Dir.chdir pwd
22
26
  end
23
27
  else
24
28
  if file_ext.include? File.extname file
@@ -41,29 +45,35 @@ option = {
41
45
  begin
42
46
  OptionParser.new do |opts|
43
47
  opts.banner = <<-EOF
44
- Usage:
45
- #$0 [div] 按目录树结构输出指定目录下的所有指定类型文件的时间戳JSON,默认输出当前目录
46
- EOF
48
+ file-timestamp #{VERSION}
49
+ Usage:
50
+ timestamp [dir] 按目录树结构输出指定目录下的所有指定类型文件的时间戳JSON,默认输出当前目录
51
+ EOF
52
+ opts.on('--format', "格式化输出") { option[:format] = true }
53
+ 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 }
56
+ opts.on("--seajs", "使用默认的seajs模板"){option[:template] = ";define('timestamp', function(require, exports, module) {\n module.exports =#output#\n});" }
57
+ opts.on("--version", "显示版本"){option[:version] = true}
47
58
 
48
- opts.on('--pretty', "格式化输出") { option[:pretty] = true }
49
- opts.on('--template <template>', '指定模板文本,内容占位符为#output#,如--template ";var json=#output#;"') { |template| option[:template] = template}
50
- opts.on("--include x,y,z", Array, "要输出时间戳的文件扩展名,默认--include .js,.css") { |include_ext| option[:include_ext] = include_ext }
51
- opts.on("--exclude x,y,z", Array, "要排除的目录,默认--exlude .svn,.git") { |exclude_dir| option[:exclude_dir].concat exclude_dir }
52
- opts.on("--seajs", "使用默认的seajs模板"){option[:template] = ";define('timestamp', function(require, exports, module) {\n module.exports =#output#\n});" }
53
59
  end.parse!
54
60
 
55
- tree = collectFileMtime(ARGV[0] || ".", option[:include_ext], option[:exclude_dir])
56
-
57
- if option[:pretty]
58
- output = JSON.pretty_generate(tree)
61
+ if option[:version]
62
+ puts VERSION
59
63
  else
60
- output = tree.to_json
61
- end
64
+ tree = collectFileMtime(ARGV[0] || ".", option[:include_ext], option[:exclude_dir])
62
65
 
63
- if option[:template] != "#output#"
64
- puts option[:template].sub("#output#",output)
65
- else
66
- puts output
66
+ if option[:format]
67
+ output = JSON.pretty_generate(tree)
68
+ else
69
+ output = tree.to_json
70
+ end
71
+
72
+ if option[:template] != "#output#"
73
+ puts option[:template].sub("#output#",output)
74
+ else
75
+ puts output
76
+ end
67
77
  end
68
78
  rescue OptionParser::InvalidOption => e
69
79
  puts "参数非法, 查看帮助请使用: #$0 --help "
metadata CHANGED
@@ -1,8 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: file-timestamp
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
5
- prerelease:
4
+ version: 1.4.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Zhong Xingdou
@@ -11,9 +10,8 @@ bindir: bin
11
10
  cert_chain: []
12
11
  date: 2013-01-02 00:00:00.000000000 Z
13
12
  dependencies: []
14
- description: ! ' output timestamp of directory for web front-end developer
15
-
16
- '
13
+ description: ! " 按目录树输出包含文件最后修改时间的JSON\n output timestamp of directory for web
14
+ front-end developer\n"
17
15
  email: zhongxingdou@gmail.com
18
16
  executables:
19
17
  - timestamp
@@ -23,26 +21,25 @@ files:
23
21
  - bin/timestamp
24
22
  homepage:
25
23
  licenses: []
24
+ metadata: {}
26
25
  post_install_message:
27
26
  rdoc_options: []
28
27
  require_paths:
29
28
  - lib
30
29
  required_ruby_version: !ruby/object:Gem::Requirement
31
- none: false
32
30
  requirements:
33
31
  - - ! '>='
34
32
  - !ruby/object:Gem::Version
35
33
  version: '0'
36
34
  required_rubygems_version: !ruby/object:Gem::Requirement
37
- none: false
38
35
  requirements:
39
36
  - - ! '>='
40
37
  - !ruby/object:Gem::Version
41
38
  version: '0'
42
39
  requirements: []
43
40
  rubyforge_project:
44
- rubygems_version: 1.8.25
41
+ rubygems_version: 2.0.3
45
42
  signing_key:
46
- specification_version: 3
43
+ specification_version: 4
47
44
  summary: output timestamp of directory for web front-end developer
48
45
  test_files: []