spud 0.2.2 → 0.2.3

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cce5f6a59f2b4bcc19711fa385dedb9a57aa1783e4cf0d56f3bafbf03c964aeb
4
- data.tar.gz: 7e00b4f4ecd4c475cbd4e4264e44f6ed28d45aedb69f728edf27f36c093fb34b
3
+ metadata.gz: c426d3d847aaa06b411cb1eba2e84ddf7ea45ff43d9d02781075637cac24f395
4
+ data.tar.gz: 2e37705b14ca816367dd038eb51d402e20d4fac00e144f263fcc8a930654023e
5
5
  SHA512:
6
- metadata.gz: fd3523e631ab8f99f8a54768a4a97c0a24b726e71938c8e7fd779e738de6d8d2648d53bbadb3654f0b7e7ddf9e2c3568ce14038e1bb1b7f093044f17c4c86002
7
- data.tar.gz: 37b04a554bc571547c66f88d36937e0340d6290ec9c797317bf8c1bdbe1e37241882425133f721306a83daceff8f6274d692a3a788c9b2dff08b202814b8dfcc
6
+ metadata.gz: 44a4bd5790ca2613a7af968fc04c7460264a83743ca68ce77513eaafa41098b4fedea9d8a95163100eef2ddb48f2f91182ba7d38df0cdf4a04ae05d8f146b641
7
+ data.tar.gz: 17f6f57907780792ee7606520a53a2b373b722ab88bf981eb8193663975e716583f3597835035c228e79c9b8d7c6ea43ea88ab3d63be615b1c6530949c1da7cc
@@ -0,0 +1,38 @@
1
+ module Spud
2
+ module BuildTools
3
+ module Spud
4
+ class Dependency
5
+ def initialize(source, target)
6
+ @sources = [source].flatten
7
+ @targets = [target].flatten
8
+ end
9
+
10
+ # @return [Boolean]
11
+ def need_to_update?
12
+ !up_to_date?
13
+ end
14
+
15
+ # @return [Boolean]
16
+ def up_to_date?
17
+ source_filenames = Dir[*@sources]
18
+ return true if source_filenames.empty?
19
+
20
+ newest_source = source_filenames
21
+ .map(&File.method(:stat))
22
+ .map(&:mtime)
23
+ .max
24
+
25
+ target_filenames = Dir[*@targets]
26
+ return false if target_filenames.empty?
27
+
28
+ oldest_target = target_filenames
29
+ .map(&File.method(:stat))
30
+ .map(&:mtime)
31
+ .min
32
+
33
+ newest_source < oldest_target
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -9,8 +9,8 @@ module Spud
9
9
  require("./#{name}")
10
10
  end
11
11
 
12
- def task(name, *, &block)
13
- BuildTools::Spud::Task.add_task(name, &block)
12
+ def task(name, dependencies = {}, &block)
13
+ BuildTools::Spud::Task.add_task(name, dependencies, &block)
14
14
  end
15
15
 
16
16
  def method_missing(name, *args, &block)
@@ -1,6 +1,8 @@
1
+ require 'stringio'
1
2
  require 'spud/error'
2
3
  require 'spud/task_args'
3
4
  require 'spud/build_tools/task'
5
+ require 'spud/build_tools/spud/dependency'
4
6
  require 'spud/build_tools/spud/task'
5
7
  require 'spud/build_tools/spud/dsl/file'
6
8
  require 'spud/build_tools/spud/dsl/task'
@@ -27,10 +29,13 @@ module Spud
27
29
  # @param task [String]
28
30
  # @param block [Proc]
29
31
  # @return [void]
30
- def self.add_task(task, &block)
31
- raise "task '#{task}' somehow created without filename" unless @filename
32
-
33
- new(name: qualified_name(@filename, task.to_s), filename: @filename, &block)
32
+ def self.add_task(task, dependencies, &block)
33
+ new(
34
+ name: qualified_name(@filename, task.to_s),
35
+ filename: @filename,
36
+ dependencies: dependencies,
37
+ &block
38
+ )
34
39
  end
35
40
 
36
41
  # @param filename [String]
@@ -49,10 +54,14 @@ module Spud
49
54
 
50
55
  # @param filename [String]
51
56
  # @param task [String]
57
+ # @return [BuildTools::Spud::Task]
52
58
  def self.task_for(filename, task)
53
59
  Runtime.tasks[qualified_name(filename, task.to_s)]
54
60
  end
55
61
 
62
+ # @param filename [String]
63
+ # @param task [String]
64
+ # @return [String]
56
65
  def self.qualified_name(filename, task)
57
66
  raise "task '#{task}' somehow created without filename" unless filename
58
67
 
@@ -71,8 +80,13 @@ module Spud
71
80
  (dirname.split('/') + basename_array).join('.')
72
81
  end
73
82
 
74
- def initialize(name:, filename:, &block)
75
- super
83
+ # @param name [String]
84
+ # @param filename [String]
85
+ # @param dependencies [Hash]
86
+ # @param block [Proc]
87
+ def initialize(name:, filename:, dependencies:, &block)
88
+ super(name: name, filename: filename)
89
+ @dependencies = dependencies.map { |to, from| Dependency.new(to, from) }
76
90
  @block = block
77
91
  end
78
92
 
@@ -80,7 +94,12 @@ module Spud
80
94
  # @param named [Hash]
81
95
  # @return [Object]
82
96
  def invoke(positional, named)
83
- check_required!(positional)
97
+ if up_to_date?
98
+ puts "'#{name}' up to date"
99
+ return
100
+ end
101
+
102
+ check_required_args!(positional)
84
103
 
85
104
  return task_dsl.instance_exec(*positional, &@block) unless args.any_named?
86
105
 
@@ -94,11 +113,37 @@ module Spud
94
113
  @args ||= ::Spud::TaskArgs.from_block(filename, &@block)
95
114
  end
96
115
 
116
+ # @return [String]
117
+ def details
118
+ filename, line_cursor = @block.source_location
119
+ line_cursor -= 1
120
+
121
+ lines = File.read(filename).split("\n")
122
+ builder = StringIO.new
123
+
124
+ while lines[line_cursor - 1] && lines[line_cursor - 1].start_with?('#')
125
+ line_cursor -= 1
126
+ end
127
+
128
+ while lines[line_cursor].start_with?('#')
129
+ builder.puts lines[line_cursor]
130
+ line_cursor += 1
131
+ end
132
+
133
+ until lines[line_cursor].start_with?('end')
134
+ builder.puts lines[line_cursor]
135
+ line_cursor += 1
136
+ end
137
+
138
+ builder.puts lines[line_cursor]
139
+ builder.string
140
+ end
141
+
97
142
  private
98
143
 
99
144
  # @param positional [Array<String>]
100
145
  # @return [void]
101
- def check_required!(positional)
146
+ def check_required_args!(positional)
102
147
  required_positional = args.required_positional
103
148
  missing_positional = required_positional.length - positional.length
104
149
  if missing_positional > 0
@@ -107,6 +152,13 @@ module Spud
107
152
  end
108
153
  end
109
154
 
155
+ # @return [Boolean]
156
+ def up_to_date?
157
+ return false if @dependencies.empty?
158
+
159
+ @dependencies.all?(&:up_to_date?)
160
+ end
161
+
110
162
  # @return [Spud::DSL::Task]
111
163
  def task_dsl
112
164
  @task_dsl ||= DSL::Task.new(filename)
@@ -31,6 +31,11 @@ module Spud
31
31
  def args
32
32
  @args ||= TaskArgs.new([])
33
33
  end
34
+
35
+ # @return [String]
36
+ def details
37
+ name
38
+ end
34
39
  end
35
40
  end
36
41
  end
@@ -50,6 +50,7 @@ module Spud
50
50
  case flag
51
51
  when '-h', '--help' then options.help = true
52
52
  when '-f', '--files' then options.files = true
53
+ when '-i', '--inspect' then options.inspect = true
53
54
  when '-w', '--watch' then options.watches << take!
54
55
  when '--debug' then options.debug = true
55
56
  else raise Error, "invalid option: '#{flag}'"
@@ -13,9 +13,10 @@ module Spud
13
13
  help.puts ' spud [options] <task> [args]'
14
14
  help.puts
15
15
  help.puts 'options:'
16
- help.puts ' -h, --help show this help dialog'
17
- help.puts ' -f, --files list parsed files'
18
- help.puts ' --debug run in debug mode'
16
+ help.puts ' -h, --help show this help dialog'
17
+ help.puts ' -f, --files list parsed files'
18
+ help.puts ' -i, --inspect show details about a task'
19
+ help.puts ' --debug run in debug mode'
19
20
 
20
21
  puts help.string
21
22
  end
@@ -1,6 +1,6 @@
1
1
  module Spud
2
2
  class Options
3
- BOOLEANS = %i[help files debug]
3
+ BOOLEANS = %i[help files inspect debug]
4
4
 
5
5
  BOOLEANS.each do |name|
6
6
  attr_accessor name
@@ -32,6 +32,11 @@ module Spud
32
32
  return
33
33
  end
34
34
 
35
+ if options.inspect?
36
+ puts get_task(args.task).details
37
+ return
38
+ end
39
+
35
40
  invoke(args.task, args.positional, args.named)
36
41
  rescue Error => error
37
42
  puts error.message
@@ -45,9 +50,14 @@ module Spud
45
50
  # @param positional [Array]
46
51
  # @param named [Hash]
47
52
  def invoke(task_name, positional = [], named = {})
53
+ get_task(task_name).invoke(positional, named)
54
+ end
55
+
56
+ def get_task(task_name)
48
57
  task = tasks[task_name.to_s]
49
58
  raise Error, "no task found for '#{task_name}'" unless task
50
- task.invoke(positional, named)
59
+
60
+ task
51
61
  end
52
62
 
53
63
  # @return [Hash{String->Spud::Task}]
@@ -1,3 +1,3 @@
1
1
  module Spud
2
- VERSION = '0.2.2'
2
+ VERSION = '0.2.3'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spud
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Booth
@@ -65,6 +65,7 @@ files:
65
65
  - lib/spud/build_tools/make/task.rb
66
66
  - lib/spud/build_tools/package.json/task.rb
67
67
  - lib/spud/build_tools/spud/block_param_info.rb
68
+ - lib/spud/build_tools/spud/dependency.rb
68
69
  - lib/spud/build_tools/spud/dsl/file.rb
69
70
  - lib/spud/build_tools/spud/dsl/task.rb
70
71
  - lib/spud/build_tools/spud/shell/command.rb