file-timestamp 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/bin/timestamp +65 -0
  2. metadata +62 -0
@@ -0,0 +1,65 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: utf-8
3
+
4
+ require 'rubygems'
5
+ require 'json'
6
+ require 'optparse'
7
+
8
+ def collectFileMtime dir, file_ext, exclude_dir
9
+ map = {}
10
+ full_dir = File.expand_path dir
11
+ Dir.chdir full_dir
12
+ Dir.foreach "." do |file|
13
+ if File.directory? file
14
+ unless exclude_dir.include? file
15
+ map[file] = collectFileMtime file, file_ext, exclude_dir
16
+ Dir.chdir ".."
17
+ end
18
+ else
19
+ if file_ext.include? File.extname file
20
+ map[file] = (File.mtime file).strftime "%m%d%H%M%S"
21
+ end
22
+ end
23
+ end
24
+
25
+ return map
26
+ end
27
+
28
+ option = {
29
+ :pretty => false,
30
+ :template => "#output#",
31
+ :include_ext => [".js",".css"],
32
+ :exclude_dir => [".","..",".svn",".git"]
33
+ }
34
+
35
+ begin
36
+ OptionParser.new do |opts|
37
+ opts.banner = <<-EOF
38
+ Usage:
39
+ #$0 [div] 按目录树结构输出指定目录下的所有指定类型文件的时间戳JSON,默认输出当前目录
40
+ EOF
41
+
42
+ opts.on('--pretty', "格式化输出") { option[:pretty] = true }
43
+ opts.on('--template <template>', '指定模板文本,内容占位符为#output#,如--template ";var json=#output#;"') { |template| option[:template] = template}
44
+ opts.on("--include x,y,z", Array, "要输出时间戳的文件扩展名,默认--include .js,.css") { |include_ext| option[:include_ext].concat include_ext }
45
+ opts.on("--exclude x,y,z", Array, "要排除的目录,默认--exlude .svn,.git") { |exclude_dir| option[:exclude_dir].concat exclude_dir }
46
+ opts.on("--seajs", "使用默认的seajs模板"){option[:template] = ";define('timestamp', function(require, exports, module) {\n module.exports =#output#\n});" }
47
+ end.parse!
48
+
49
+ tree = collectFileMtime(ARGV[0] || ".", option[:include_ext], option[:exclude_dir])
50
+ if option[:pretty]
51
+ output = JSON.pretty_generate(tree)
52
+ else
53
+ output = tree.to_json
54
+ end
55
+
56
+ if option[:template] != "#output#"
57
+ puts option[:template].sub("#output#",output)
58
+ else
59
+ puts output
60
+ end
61
+ rescue OptionParser::InvalidOption => e
62
+ puts "参数非法, 查看帮助请使用: #$0 --help "
63
+ rescue Exception => e
64
+ puts e.to_s
65
+ end
metadata ADDED
@@ -0,0 +1,62 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: file-timestamp
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 1
7
+ - 0
8
+ - 0
9
+ version: 1.0.0
10
+ platform: ruby
11
+ authors:
12
+ - Zhong Xingdou
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2012-09-27 00:00:00 +08:00
18
+ default_executable:
19
+ dependencies: []
20
+
21
+ description: " output timestamp of directory for web front-end developer\n"
22
+ email: zhongxingdou@gmail.com
23
+ executables:
24
+ - timestamp
25
+ extensions: []
26
+
27
+ extra_rdoc_files: []
28
+
29
+ files:
30
+ - bin/timestamp
31
+ has_rdoc: true
32
+ homepage:
33
+ licenses: []
34
+
35
+ post_install_message:
36
+ rdoc_options: []
37
+
38
+ require_paths:
39
+ - lib
40
+ required_ruby_version: !ruby/object:Gem::Requirement
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ segments:
45
+ - 0
46
+ version: "0"
47
+ required_rubygems_version: !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ segments:
52
+ - 0
53
+ version: "0"
54
+ requirements: []
55
+
56
+ rubyforge_project:
57
+ rubygems_version: 1.3.6
58
+ signing_key:
59
+ specification_version: 3
60
+ summary: output timestamp of directory for web front-end developer
61
+ test_files: []
62
+