ruby_make_script 0.1.0 → 0.1.5

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
  SHA256:
3
- metadata.gz: 3406be1df614999fd1ca1ea31185363c98ae75e77beae44547c3ea4a6225c2a4
4
- data.tar.gz: c01a6f7f1975958eee6c8db653bf8001789575c12f3880651809cdd990ef7a75
3
+ metadata.gz: a370bfa77890704eba2e733162beac06b58ab808c12560aa80f82954ead81b9a
4
+ data.tar.gz: 2367de1ec588fa4927475288cdc9959e8aa13afb487e608d08911cd1f7d8c15f
5
5
  SHA512:
6
- metadata.gz: 97cfd2352791c73010bf3c06239a02af829530e023d7092b10297b8fa80a090bfde40ff082b33fe7de8cd31851c48ade3cf0b3964d9e80237befac9f273a2de6
7
- data.tar.gz: 387906e219c62fa99ed6d573b013b1037512623a02af0114e0b35d6585bfca532af5a856de7b7e83d4ab935429bdda65f49d348f8653c1c678adbd52fbf70c29
6
+ metadata.gz: b85472ea65c10e3642fdb99aa1b578b686e95fa3f6d85271e3a7f197efae992091f18b4b154a596fee23b8c01c737e28829dcd7c6d1329669759f695ea5cdbac
7
+ data.tar.gz: 3f6b650ac72704263761b7cded263e00378e893d0fc5838bf346646c461a80ca1bb0845ed5b5d3372e6516642aea77f079f89fa9a7789ea4428817dc741b895a
data/Gemfile CHANGED
@@ -1,6 +1,5 @@
1
1
  source "https://rubygems.org"
2
2
 
3
-
4
3
  gem 'pastel'
5
4
 
6
5
  git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
@@ -15,6 +15,10 @@
15
15
  #
16
16
  #
17
17
 
18
+ if !system('gem list | grep pastel > /dev/null')
19
+ puts "pastel not install automaticly, please 'gem install pastel'"
20
+ end
21
+
18
22
  require 'pastel'
19
23
  require 'yaml'
20
24
 
@@ -35,7 +39,7 @@ require 'ruby_make_script/target'
35
39
 
36
40
  # check a file (recursively) and run the commands of the target.
37
41
  def resolve(file, force_exec=false)
38
- if file_modified?(file) || force_exec
42
+ if force_exec || file_modified?(file)
39
43
  t = $file_target_dict[file]
40
44
  # when t == nil, its a file not used for target
41
45
  if t != nil
@@ -108,7 +112,7 @@ class Symbol
108
112
  # end
109
113
  # ```
110
114
  def then
111
- from()
115
+ PhonyTarget.new(String(self)).from() { yield }
112
116
  end
113
117
  end
114
118
 
@@ -158,23 +162,23 @@ def make
158
162
  $file_time_dict = YAML.load(File.read('./.make_script.yaml'))
159
163
  $cur_file_time_dict = $file_time_dict.clone()
160
164
  end
161
- puts Pastel.new.green.bold("ruby_make_script> ") + "start"
165
+ puts Pastel.new.bright_cyan("make> ") + "start"
166
+
162
167
  begin
163
- if ARGV.length <= 1
168
+ if ARGV.length == 0
164
169
  $targetlist[0].resolve_all
165
170
  else
166
- resolve(ARGV[1], force_exec=true)
171
+ resolve(ARGV[0], true)
167
172
  end
168
173
 
169
174
  rescue StandardError => e
170
- puts Pastel.new.red.bold("ruby_make_script failed> ") + e.message
175
+ puts Pastel.new.red.bold("make failed> ") + e.message
171
176
  if e.message != "make command failed"
172
177
  puts e.backtrace
173
178
  end
174
179
  else
175
- puts Pastel.new.green.bold("ruby_make_script> ") + "completed"
180
+ puts Pastel.new.bright_cyan("make> ") + "completed"
176
181
  end
177
182
 
178
183
  File.open('./.make_script.yaml', 'w') { |f| f.write(YAML.dump($cur_file_time_dict)) }
179
-
180
- end
184
+ end
@@ -1,15 +1,6 @@
1
-
2
-
3
1
  # since ~ "cd <path>" invalid, add a function here
4
2
  def cd(str)
5
- if block_given?
6
- orig = Dir.pwd
7
- Dir.chdir(str)
8
- yield
9
- Dir.chdir(orig)
10
- else
11
- Dir.chdir(str)
12
- end
3
+ Dir.chdir(str)
13
4
  end
14
5
 
15
6
  # these were like cd function
@@ -21,6 +12,15 @@ end
21
12
  def mkdir(*str)
22
13
  r"mkdir #{str.join(' ')}"
23
14
  end
15
+ # these were like cd function
16
+ def mv(*str)
17
+ r"mv #{str.join(' ')}"
18
+ end
19
+
20
+ # these were like cd function
21
+ def cp(*str)
22
+ r"cp #{str.join(' ')}"
23
+ end
24
24
 
25
25
  def r(*str)
26
26
  str = str.join(" ")
@@ -34,14 +34,7 @@ end
34
34
  # since ~ "cd <path>" invalid, add a function here
35
35
  def cd?(str)
36
36
  begin
37
- if block_given?
38
- orig = Dir.pwd
39
- Dir.chdir(str)
40
- yield
41
- Dir.chdir(orig)
42
- else
43
- Dir.chdir(str)
44
- end
37
+ Dir.chdir(str)
45
38
  rescue => exception
46
39
  puts Pastel.new.yellow("warning> ") + "command error: cd " + str + " (suppressed)"
47
40
  return false
@@ -59,6 +52,16 @@ def mkdir?(*str)
59
52
  r?"mkdir #{str.join(' ')}"
60
53
  end
61
54
 
55
+ # these were like cd function
56
+ def mv?(*str)
57
+ r?"mv #{str.join(' ')}"
58
+ end
59
+
60
+ # these were like cd function
61
+ def cp?(*str)
62
+ r?"cp #{str.join(' ')}"
63
+ end
64
+
62
65
  # no error
63
66
  def r?(*str)
64
67
  str = str.join(" ")
@@ -74,7 +77,65 @@ def runfile(file, *args)
74
77
  path = File.expand_path(file)
75
78
  r path, *args
76
79
  end
80
+
77
81
  def runfile?(file, *args)
78
82
  path = File.expand_path(file)
79
83
  r? path, *args
80
84
  end
85
+
86
+ class InDir
87
+ def initialize(path, err=true)
88
+ @path = path
89
+ @err = err
90
+ end
91
+
92
+ def enter
93
+ @orig = Dir.pwd
94
+ if @err
95
+ cd @path
96
+ else
97
+ cd? @path
98
+ end
99
+ end
100
+
101
+ def exit
102
+ if @err
103
+ cd @orig
104
+ else
105
+ cd? @orig
106
+ end
107
+ end
108
+ end
109
+
110
+ def dir(path)
111
+ InDir.new(path)
112
+ end
113
+
114
+ def dir?(path)
115
+ InDir.new(path, false)
116
+ end
117
+
118
+ class InEnv
119
+ def initialize(expr)
120
+ @k, @v = expr.split('=')
121
+ end
122
+
123
+ def enter
124
+ @v0 = ENV[k]
125
+ ENV[k] = @v
126
+ end
127
+
128
+ def exit
129
+ ENV[k] = @v0
130
+ end
131
+ end
132
+
133
+ def envir(expr)
134
+ InEnv.new(expr)
135
+ end
136
+
137
+ def using(*operation)
138
+ operation.each{ |o| o.enter}
139
+ yield
140
+ operation.each{ |o| o.exit}
141
+ end
@@ -1,3 +1,3 @@
1
1
  module RubyMakeScript
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.5"
3
3
  end
@@ -13,7 +13,7 @@ Gem::Specification.new do |spec|
13
13
  spec.description = %q{A ruby make DSL for ruby like GNU make. (very simple)}
14
14
  spec.homepage = "https://github.com/DnailZ/ruby_make_script"
15
15
  spec.license = "MIT"
16
-
16
+
17
17
  # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
18
  # to allow pushing to a single host or delete this section to allow pushing to any host.
19
19
  if spec.respond_to?(:metadata)
@@ -32,7 +32,6 @@ Gem::Specification.new do |spec|
32
32
  spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
33
33
  `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
34
34
  end
35
- p spec.files
36
35
  spec.bindir = "exe"
37
36
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
38
37
  spec.require_paths = ["lib"]
@@ -40,4 +39,5 @@ Gem::Specification.new do |spec|
40
39
  spec.add_development_dependency "bundler", "~> 1.17"
41
40
  spec.add_development_dependency "rake", "~> 10.0"
42
41
  spec.add_development_dependency "minitest", "~> 5.0"
42
+ spec.add_development_dependency "pastel" , "~> 0.7.4"
43
43
  end
data/test.rb ADDED
@@ -0,0 +1,7 @@
1
+ require "ruby_make_script"
2
+
3
+ make do
4
+ :setup.from do
5
+ r "echo", "Hello", "World"
6
+ end
7
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby_make_script
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - dnailz
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-06-23 00:00:00.000000000 Z
11
+ date: 2020-06-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '5.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pastel
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.7.4
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.7.4
55
69
  description: A ruby make DSL for ruby like GNU make. (very simple)
56
70
  email:
57
71
  - dnailzb@outlook.com
@@ -73,6 +87,7 @@ files:
73
87
  - lib/ruby_make_script/utils.rb
74
88
  - lib/ruby_make_script/version.rb
75
89
  - ruby_make_script.gemspec
90
+ - test.rb
76
91
  homepage: https://github.com/DnailZ/ruby_make_script
77
92
  licenses:
78
93
  - MIT