falsework 0.1.2 → 0.2.2

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.
data/README.rdoc CHANGED
@@ -40,18 +40,24 @@ list:: Do nothing except listing all available
40
40
  new NAME:: Create a new project. It creates a directory
41
41
  <i>NAME</i> and populates it with files.
42
42
 
43
+ The following commands works only from the root project directory:
44
+
43
45
  exe NAME:: Add a new executable to an existing
44
- project. You may use this command only in
45
- the root project directory.
46
+ project.
47
+
48
+ test NAME:: Add a new minitest.
46
49
 
47
- test NAME:: Add a new minitest to an existing
48
- project. You may use this command only in
49
- the root project directory.
50
+ upgrade:: 'Inject' or upgrade some vital files from the
51
+ default 'naive' template into the
52
+ project. (<b>Warning:</b> this works only
53
+ from version 0.2.2 and (hopefully) above.)
50
54
 
51
55
  The options are as follows:
52
56
 
53
57
  -t:: A template name.
54
58
 
59
+ -b:: A batch mode. (No questions asked.)
60
+
55
61
  --config-dirs:: List all possible locations for the
56
62
  configuration file. The first found wins.
57
63
 
data/Rakefile CHANGED
@@ -17,7 +17,7 @@ require_relative 'test/rake_erb_templates'
17
17
  ERB_DYN_SKELETON = erb_skeletons(NAME, 'naive')
18
18
  ERB_DYN_SKELETON.each {|k, v|
19
19
  file k => [v] do |t|
20
- erb_make(NAME, t.name, t.prerequisites[0])
20
+ erb_make(NAME, 'naive', t.name, t.prerequisites[0])
21
21
  end
22
22
  }
23
23
 
@@ -68,3 +68,5 @@ end
68
68
  Rake::TestTask.new do |i|
69
69
  i.test_files = FileList['test/test_*.rb']
70
70
  end
71
+
72
+ task test: [:naive]
data/bin/falsework CHANGED
@@ -6,16 +6,17 @@ require_relative '../lib/falsework/mould'
6
6
  include Falsework
7
7
 
8
8
  $conf = Hash.new
9
- u = Utils.new($conf)
9
+ u = Trestle.new($conf)
10
10
 
11
11
  $conf[:banner] = <<EOF
12
12
  Usage: #{File.basename($0)} [options] command ...
13
- Available commands: list, new NAME, exe NAME or test NAME.
13
+ Available commands: list, new NAME, exe NAME, test NAME or upgrade.
14
14
  EOF
15
15
  $conf[:user] = nil
16
16
  $conf[:gecos] = nil
17
17
  $conf[:email] = nil
18
18
  $conf[:template] = nil
19
+ $conf[:batch] = false
19
20
 
20
21
  # --[ main ]------------------------------------------------------------
21
22
 
@@ -25,14 +26,15 @@ u.config_parse(['foobar']) {|src|
25
26
  o.on('--gecos STR', 'A gecos-like string') {|i| $conf[:gecos] = i}
26
27
  o.on('--email STR') {|i| $conf[:email] = i}
27
28
  o.on('-t NAME', 'A template name') {|i| $conf[:template] = i}
29
+ o.on('-b', 'Run in a batch mode, don\'t ask any questions') { $conf[:batch] = true}
28
30
  u.cl_parse(src, o) # run cl parser
29
31
  }
30
32
 
31
- Utils.errx(1, $conf[:banner]) if (ARGV.size < 2 && ARGV[0] != 'list')
33
+ Trestle.errx(1, $conf[:banner]) if (ARGV.size < 2 && ARGV[0] !~ /list|upgrade/)
32
34
 
33
35
  # print our env
34
36
  if $conf[:verbose] >= 2
35
- puts 'Libs dir: '+Utils.gem_libdir
37
+ puts 'Libs dir: '+Trestle.gem_libdir
36
38
  pp $conf
37
39
  end
38
40
 
@@ -40,18 +42,23 @@ case ARGV[0]
40
42
  when 'list'
41
43
  Mould.templates.each_key {|i| puts(i)}
42
44
  when /exe|test/
43
- m = Mould.new('foo', $conf[:user], $conf[:email], $conf[:gecos])
45
+ m = Mould.new(File.basename(Dir.pwd), $conf[:user], $conf[:email], $conf[:gecos])
44
46
  ARGV[1..-1].each {|i|
45
47
  u.veputs(1, "Generating #{i} as... __NNL__")
46
48
  u.veputs(1, m.create($conf[:template], ARGV[0], i) + '... __NNL__')
47
49
  u.veputs(1, 'OK')
48
50
  }
51
+ when 'upgrade'
52
+ m = Mould.new(File.basename(Dir.pwd), $conf[:user], $conf[:email], $conf[:gecos])
53
+ m.verbose = true if $conf[:verbose] > 0
54
+ m.batch = $conf[:batch]
55
+ m.upgrade($conf[:template]) rescue Trestle.errx(1, $!.to_s)
49
56
  when 'new'
50
57
  if File.dirname(ARGV[1]) != '.'
51
- Dir.chdir(File.dirname(ARGV[1])) rescue Utils.errx(1, "cannot chdir to '#{File.dirname(ARGV[1])}'")
58
+ Dir.chdir(File.dirname(ARGV[1])) rescue Trestle.errx(1, "cannot chdir to '#{File.dirname(ARGV[1])}'")
52
59
  ARGV[1] = File.basename ARGV[1]
53
60
  end
54
- Utils.errx(1, 'project name cannot start with a digit') if ARGV[1].strip[0] =~ /\d/
61
+ Trestle.errx(1, 'project name cannot start with a digit') if ARGV[1].strip[0] =~ /\d/
55
62
 
56
63
  m = Mould.new(ARGV[1], $conf[:user], $conf[:email], $conf[:gecos])
57
64
  m.verbose = true if $conf[:verbose] > 0
@@ -65,5 +72,5 @@ when 'new'
65
72
  g.commit("Initial import from #{Falsework::Meta::NAME} #{Falsework::Meta::VERSION}.")
66
73
  u.veputs(1, 'OK')
67
74
  else
68
- Utils.errx(1, "unknown command: " + ARGV[0])
75
+ Trestle.errx(1, "unknown command: " + ARGV[0])
69
76
  end
data/doc/README.rdoc CHANGED
@@ -40,18 +40,24 @@ list:: Do nothing except listing all available
40
40
  new NAME:: Create a new project. It creates a directory
41
41
  <i>NAME</i> and populates it with files.
42
42
 
43
+ The following commands works only from the root project directory:
44
+
43
45
  exe NAME:: Add a new executable to an existing
44
- project. You may use this command only in
45
- the root project directory.
46
+ project.
47
+
48
+ test NAME:: Add a new minitest.
46
49
 
47
- test NAME:: Add a new minitest to an existing
48
- project. You may use this command only in
49
- the root project directory.
50
+ upgrade:: 'Inject' or upgrade some vital files from the
51
+ default 'naive' template into the
52
+ project. (<b>Warning:</b> this works only
53
+ from version 0.2.2 and (hopefully) above.)
50
54
 
51
55
  The options are as follows:
52
56
 
53
57
  -t:: A template name.
54
58
 
59
+ -b:: A batch mode. (No questions asked.)
60
+
55
61
  --config-dirs:: List all possible locations for the
56
62
  configuration file. The first found wins.
57
63
 
data/doc/TODO.rdoc CHANGED
@@ -1,10 +1,9 @@
1
1
  + create a git repository automatically for a new project
2
2
  + generate a gem file list from git ls-tree
3
3
  + check for every generated file in naive test template generation
4
- - an ability to upgrade project to a newest template
5
- - more templates (a light one?)
4
+ + an ability to upgrade project from a newest template
5
+ - more templates (a lighter one?)
6
6
  - write a small tutorial 'how to write a template'
7
7
  - release to rubygems.org (it must run test, pull to github, tag, create
8
8
  gem & upload it)
9
- + generate utils.rb.erb from the current falsework utils.rb
10
9
  + the config in home dir
@@ -1,6 +1,6 @@
1
1
  module Falsework
2
2
  module Meta
3
3
  NAME = 'falsework'
4
- VERSION = '0.1.2'
4
+ VERSION = '0.2.2'
5
5
  end
6
6
  end
@@ -2,20 +2,21 @@ require 'git'
2
2
  require 'erb'
3
3
  require 'digest/md5'
4
4
 
5
- require_relative 'utils'
5
+ require_relative 'trestle'
6
6
 
7
7
  module Falsework
8
8
  class Mould
9
9
  GITCONFIG = '~/.gitconfig'
10
- TEMPLATE_DIRS = [Utils.gem_libdir + '/templates',
10
+ TEMPLATE_DIRS = [Trestle.gem_libdir + '/templates',
11
11
  File.expand_path('~/.' + Meta::NAME + '/templates')]
12
12
  TEMPLATE_DEFAULT = 'naive'
13
13
  IGNORE_FILES = ['.gitignore']
14
14
 
15
- attr_accessor :verbose
15
+ attr_accessor :verbose, :batch
16
16
 
17
17
  def initialize(project, user = nil, email = nil, gecos = nil)
18
18
  @verbose = false
19
+ @batch = false
19
20
 
20
21
  gc = Git.global_config rescue gc = {}
21
22
  @project = project
@@ -26,7 +27,7 @@ module Falsework
26
27
  [['github.user', @user],
27
28
  ['user.email', @email],
28
29
  ['user.name', @gecos]].each {|i|
29
- Utils.errx(1, "missing #{i.first} in #{GITCONFIG}") if i.last.to_s == ''
30
+ Trestle.errx(1, "missing #{i.first} in #{GITCONFIG}") if i.last.to_s == ''
30
31
  }
31
32
  end
32
33
 
@@ -51,11 +52,11 @@ module Falsework
51
52
  # Return false if nothing was extracted.
52
53
  def project_seed(template, filter)
53
54
  sl = ->(is_dir, *args) {
54
- is_dir ? Mould.erb_dirname(*args) : Mould.erb_filename(*args)
55
+ is_dir ? Mould.erb_fname(*args) : Mould.erb_fname(*args).sub(/\.erb$/, '')
55
56
  }
56
57
 
57
58
  # check for existing project
58
- Utils.errx(1, "directory '#{@project}' is not empty") if Dir.glob(@project + '/*').size > 0
59
+ Trestle.errx(1, "directory '#{@project}' is not empty") if Dir.glob(@project + '/*').size > 0
59
60
 
60
61
  Dir.mkdir(@project) unless File.directory?(@project)
61
62
  prjdir = File.expand_path(@project)
@@ -65,7 +66,7 @@ module Falsework
65
66
  Dir.chdir @project
66
67
 
67
68
  r = false
68
- start = Mould.templates[template || TEMPLATE_DEFAULT] || Utils.errx(1, "no such template: #{template}")
69
+ start = Mould.templates[template || TEMPLATE_DEFAULT] || Trestle.errx(1, "no such template: #{template}")
69
70
  puts "Template: #{start}" if @verbose
70
71
  symlinks = []
71
72
  Mould.traverse(start) {|i|
@@ -80,13 +81,13 @@ module Falsework
80
81
  sl.call(is_dir, file, binding)]
81
82
  elsif File.directory?(i)
82
83
  puts("D: #{file}") if @verbose
83
- file = Mould.erb_dirname(file, binding)
84
+ file = Mould.erb_fname(file, binding)
84
85
  # FileUtils.mkdir_p(prjdir + '/' + file)
85
86
  Dir.mkdir(prjdir + '/' + file)
86
87
  Dir.chdir(prjdir + '/' + file)
87
88
  else
88
89
  puts("N: #{file}") if @verbose
89
- to = File.basename(Mould.erb_filename(file, binding), '.erb')
90
+ to = File.basename(Mould.erb_fname(file, binding), '.erb')
90
91
  Mould.extract(start + '/' + file, binding, to)
91
92
  # make files in bin/ executable
92
93
  File.chmod(0744, to) if file =~ /bin\//
@@ -97,8 +98,10 @@ module Falsework
97
98
  # create saved symlinks
98
99
  Dir.chdir prjdir
99
100
  symlinks.each {|i|
100
- src = i[0].sub(/#{File.extname(i[0])}$/, '')
101
- dest = i[1].sub(/#{File.extname(i[1])}$/, '')
101
+ # src = i[0].sub(/#{File.extname(i[0])}$/, '')
102
+ # dest = i[1].sub(/#{File.extname(i[1])}$/, '')
103
+ src = i[0]
104
+ dest = i[1]
102
105
  puts "L: #{dest} => #{src}" if @verbose
103
106
  File.symlink(src, dest)
104
107
  }
@@ -113,15 +116,15 @@ module Falsework
113
116
  #
114
117
  # Return a name of a created file.
115
118
  def create(template, mode, what)
116
- start = Mould.templates[template || TEMPLATE_DEFAULT] || Utils.errx(1, "no such template: #{template}")
119
+ start = Mould.templates[template || TEMPLATE_DEFAULT] || Trestle.errx(1, "no such template: #{template}")
117
120
 
118
121
  t = case mode
119
122
  when 'exe'
120
123
  to = ["bin/#{what}", true]
121
- start + '/' + 'bin/.@project..erb'
124
+ start + '/' + 'bin/%%@project%%.erb'
122
125
  when 'test'
123
126
  to = ["#{mode}/test_#{what}.rb", false]
124
- start + '/' + 'test/test_.@project..rb.erb'
127
+ start + '/' + 'test/test_%%@project%%.rb.erb'
125
128
  else
126
129
  fail "invalid mode #{mode}"
127
130
  end
@@ -135,11 +138,13 @@ module Falsework
135
138
  #
136
139
  # [start] The directory to start with.
137
140
  def self.traverse(start, &block)
138
- l = Dir.glob(start + '/{*}', File::FNM_DOTMATCH)
141
+ l = Dir.glob(start + '/*', File::FNM_DOTMATCH).delete_if {
142
+ |i| i.match /\/?\.\.?$/
143
+ }
139
144
  # stop if directory is empty (contains only . and ..)
140
- return if l.size <= 2
145
+ return if l.size == 0
141
146
 
142
- l.sort[2..-1].each {|i|
147
+ l.sort.each {|i|
143
148
  yield i
144
149
  # recursion!
145
150
  self.traverse(i) {|j| block.call j} if File.directory?(i)
@@ -157,7 +162,7 @@ module Falsework
157
162
  # pp t.result
158
163
  md5_system = Digest::MD5.hexdigest(t.result(bin))
159
164
  rescue Exception
160
- Utils.errx(1, "cannot read the template file: #{$!}")
165
+ Trestle.errx(1, "cannot read the template file: #{$!}")
161
166
  end
162
167
 
163
168
  skeleton = to || File.basename(path, '.erb')
@@ -166,34 +171,138 @@ module Falsework
166
171
  begin
167
172
  File.open(skeleton, 'w+') { |fp| fp.puts t.result(bin) }
168
173
  rescue
169
- Utils.errx(1, "cannot write the skeleton: #{$!}")
174
+ Trestle.errx(1, "cannot write the skeleton: #{$!}")
170
175
  end
171
176
  elsif
172
177
  # warn a careless user
173
178
  if md5_system != Digest::MD5.file(skeleton).hexdigest
174
- Utils.errx(1, "#{skeleton} already exists")
179
+ Trestle.errx(1, "#{skeleton} already exists")
175
180
  end
176
181
  end
177
182
  end
178
183
 
179
- # Evaluate _t_ as a special directory name.
180
- #
181
- # [bin] A binding for eval.
182
- def self.erb_dirname(t, bin)
183
- if t =~ /^(.+\/)?\.(.+)\.$/
184
- return ERB.new("#{$1}<%= #{$2} %>").result(bin)
185
- end
184
+ def self.erb_fname(t, bin)
185
+ re = /%%([^.]+)?%%/
186
+ return ERB.new(t.gsub(re, '<%= \1 %>')).result(bin) if t =~ re
186
187
  return t
187
188
  end
189
+
188
190
 
189
- # Evaluate _t_ as a special file name.
191
+ # Search for all files in the _template_ for the line
190
192
  #
191
- # [bin] A binding for eval.
192
- def self.erb_filename(t, bin)
193
- if t =~ /^(.+)?\.(.+)\.(\..+)?.erb$/
194
- return ERB.new("#{$1}<%= #{$2} %>#{$3}").result(bin)
193
+ # /^..? :erb:/
194
+ #
195
+ # in first n lines. If the line is found, the file is considered a
196
+ # candidate for an upgrade. Return a hash {target:template}
197
+ def upgradable_files(template)
198
+ line_max = 4
199
+ r = {}
200
+ Falsework::Mould.traverse(template) {|i|
201
+ next if File.directory?(i)
202
+ next if File.symlink?(i) # hm...
203
+
204
+ File.open(i) {|fp|
205
+ n = 0
206
+ while n < line_max && line = fp.gets
207
+ if line =~ /^..? :erb:/
208
+ t = i.sub(/#{template}\//, '')
209
+ r[Mould.erb_fname(t, binding).sub(/\.erb$/, '')] = i
210
+ break
211
+ end
212
+ n += 1
213
+ end
214
+ }
215
+ }
216
+
217
+ r
218
+ end
219
+
220
+ # We can upgrade only those files, which were explicitly marked by
221
+ # ':erb' sign a the top the file. They are collected by
222
+ # upgradable_files() method.
223
+ #
224
+ # The upgrade can happened only if one following conditions is met:
225
+ #
226
+ # 1. there is no such files (all or some of them) in the project at
227
+ # all;
228
+ #
229
+ # 2. the files are from the previous version of falsework.
230
+ #
231
+ # The situation may combine: you may have some missing and some old
232
+ # files. But if there is at least 1 file from a newer version of
233
+ # falsework then no upgrade is possible--it's considered a user
234
+ # decision to intentionally have some files from the old versions of
235
+ # falsework.
236
+ #
237
+ # Neithe we do check for a content of upgradable files nor try to
238
+ # merge old with new. (Why?)
239
+ def upgrade(template)
240
+ # 0. search for 'new' files in the template
241
+ t = Mould.templates[template || TEMPLATE_DEFAULT] || Trestle.errx(1, "no such template: #{template}")
242
+ uf = upgradable_files(t)
243
+ fail "template #{template} cannot offer to you files for an upgrade" if uf.size == 0
244
+ # pp uf
245
+
246
+ # 1. analyse 'old' files
247
+ u = {}
248
+ uf.each {|k, v|
249
+ if ! File.readable?(k)
250
+ u[k] = v
251
+ else
252
+ # check for its version
253
+ File.open(k) {|fp|
254
+ is_versioned = false
255
+ while line = fp.gets
256
+ if line =~ /^# Don't remove this: falsework\/(#{Gem::Version::VERSION_PATTERN})\/(\w+)\/.+/
257
+ is_versioned = true
258
+ if $3 != (template || TEMPLATE_DEFAULT)
259
+ fail "file #{k} is from #{$3} template"
260
+ end
261
+ if Gem::Version.new(Meta::VERSION) >= Gem::Version.new($1)
262
+ # puts "#{k}: #{$1}"
263
+ u[k] = v
264
+ break
265
+ else
266
+ fail "file #{k} is from a newer version of #{Meta::NAME}: " + $1
267
+ end
268
+ end
269
+ end
270
+
271
+ Trestle.warnx("#{k}: unversioned") if ! is_versioned
272
+ }
273
+ end
274
+ }
275
+ fail "template #{template || TEMPLATE_DEFAULT} cannot find files for an upgrade" if u.size == 0
276
+
277
+ # 2. ask user for a commitment
278
+ if ! @batch
279
+ puts "Here is a list of files in project #{@project} we can try to upgrade/add:\n\n"
280
+ u.each {|k,v| puts "\t#{k}"}
281
+ printf %{
282
+ Does this look fine? Type y/n and press enter. If you choose 'y', those files
283
+ will be replaced with newer versions. Your old files will be preserved with
284
+ an '.old' extension. So? }
285
+ if STDIN.gets =~ /^y/i
286
+ puts ""
287
+ else
288
+ puts "\nNo? See you later."
289
+ exit 0
290
+ end
195
291
  end
196
- return t
292
+
293
+ # 3. rename & write new
294
+ count = 1
295
+ total = u.size
296
+ tsl = total.to_s.size*2+1
297
+ u.each {|k, v|
298
+ printf("%#{tsl}s) mv %s %s\n",
299
+ "#{count}/#{total}", k, "#{k}.old") if @verbose
300
+ File.rename(k, "#{k}.old") rescue Trestle.warnx('renaming failed')
301
+ printf("%#{tsl}s Extracting %s ...\n", "", File.basename(v)) if @verbose
302
+ FileUtils.mkdir_p(File.dirname(k))
303
+ Mould.extract(v, binding, k)
304
+ count += 1
305
+ }
197
306
  end
198
307
 
199
308
  end # Mould
@@ -1,6 +1,6 @@
1
1
  =Name
2
2
 
3
- <%= @project %>--an util to put function in yo function so yo can return
3
+ <%= @project %>--an util to put a function in yo function so yo can return
4
4
  while yo return.
5
5
 
6
6
 
@@ -1,12 +1,12 @@
1
1
  #!/usr/bin/env ruby
2
2
  # -*-ruby-*-
3
3
 
4
- require_relative '../lib/<%= @project %>/utils.rb'
4
+ require_relative '../lib/<%= @project %>/trestle.rb'
5
5
 
6
6
  include <%= @project.capitalize %>
7
7
 
8
8
  $conf = Hash.new
9
- u = Utils.new($conf)
9
+ u = Trestle.new($conf)
10
10
 
11
11
  $conf[:banner] = "Usage: #{File.basename($0)} [options] hren'"
12
12
  $conf[:foobar] = ''
@@ -24,7 +24,7 @@ u.config_parse(['foobar']) {|src|
24
24
 
25
25
  # print our env
26
26
  if $conf[:verbose] >= 2
27
- puts 'Libs dir: '+Utils.gem_libdir
27
+ puts 'Libs dir: ' + Trestle.gem_libdir
28
28
  pp $conf
29
29
  end
30
30
 
@@ -1,6 +1,6 @@
1
1
  =Name
2
2
 
3
- <%= @project %>--an util to put function in yo function so yo can return
3
+ <%= @project %>--an util to put a function in yo function so yo can return
4
4
  while yo return.
5
5
 
6
6
 
@@ -3,13 +3,26 @@ require 'yaml'
3
3
  require 'shellwords.rb'
4
4
  require 'optparse'
5
5
  require 'pp'
6
+ require 'open4'
6
7
 
7
8
  require_relative 'meta'
8
9
 
9
10
  # :include: ../../README.rdoc
10
11
  module <%= @project.capitalize %>
11
12
 
12
- class Utils
13
+ class Trestle
14
+
15
+ # Execute _cmd_ and return a list [exit_status, stderr,
16
+ # stdout]. Very handy.
17
+ def self.cmd_run(cmd)
18
+ so = sr = ''
19
+ status = Open4::popen4(cmd) { |pid, stdin, stdout, stderr|
20
+ so = stdout.read
21
+ sr = stderr.read
22
+ }
23
+ [status.exitstatus, sr, so]
24
+ end
25
+
13
26
  # Return a directory with program libraries.
14
27
  def self.gem_libdir
15
28
  t = ["#{File.dirname(File.expand_path($0))}/../lib/#{<%= @project.capitalize %>::Meta::NAME}",
@@ -114,7 +127,7 @@ module <%= @project.capitalize %>
114
127
  # puts "\n2 run"
115
128
  r = config_flat_load(rvars)
116
129
  rescue
117
- Utils.errx(1, "cannot load config: #{$!}")
130
+ Trestle.errx(1, "cannot load config: #{$!}")
118
131
  end
119
132
  veputs(1, "Loaded config: #{r}")
120
133
  cb.call(block_given?, ARGV)
@@ -193,11 +206,11 @@ module <%= @project.capitalize %>
193
206
  o.parse!(src)
194
207
  @cl_parsing_times += 1
195
208
  rescue
196
- Utils.errx(1, $!.to_s)
209
+ Trestle.errx(1, $!.to_s)
197
210
  end
198
211
  end
199
212
 
200
- end # Utils
213
+ end # trestle
201
214
  end
202
215
 
203
- # Don't remove this: 2010-12-22T19:42:32+02:00 falsework 0.1.2
216
+ # Don't remove this: falsework/0.2.2/naive/2010-12-26T04:50:00+02:00
@@ -1,48 +1,4 @@
1
- # :erb:
2
- # Various staff for minitest.
1
+ # This is supposed to be your helper for all your test. Feel free to
2
+ # add staff here.
3
3
 
4
- require 'fileutils'
5
- require 'open4'
6
-
7
- include FileUtils
8
-
9
- require_relative '../lib/<%= @project %>/utils'
10
- include <%= @project.capitalize %>
11
-
12
- # don't run tests automatically if they were invoked as 'gem check -t ...'
13
- if $0 =~ /gem/
14
- require 'minitest/unit'
15
- else
16
- require 'minitest/autorun'
17
- end
18
-
19
- def cmd_run(cmd)
20
- so = sr = ''
21
- status = Open4::popen4(cmd) { |pid, stdin, stdout, stderr|
22
- so = stdout.read
23
- sr = stderr.read
24
- }
25
- [status.exitstatus, sr, so]
26
- end
27
-
28
- # Return the right directory for (probably executable) _c_.
29
- def cmd(c)
30
- case File.basename(Dir.pwd)
31
- when Meta::NAME.downcase
32
- # test probably is executed from the Rakefile
33
- Dir.chdir('test')
34
- when 'test'
35
- # we are in the test directory, there is nothing special to do
36
- else
37
- # tests were invoked by 'gem check -t <%= @project %>'
38
- begin
39
- Dir.chdir(Utils.gem_libdir + '/../../test')
40
- rescue
41
- raise "running tests from '#{Dir.pwd}' isn't supported: #{$!}"
42
- end
43
- end
44
-
45
- '../bin/' + c
46
- end
47
-
48
- # Don't remove this: 2010-12-22T19:42:32+02:00 falsework 0.1.2
4
+ require_relative 'helper_trestle'
@@ -0,0 +1,37 @@
1
+ # :erb:
2
+ # Various staff for minitest. Include this file into your 'helper.rb'.
3
+
4
+ require 'fileutils'
5
+ include FileUtils
6
+
7
+ require_relative '../lib/<%= @project %>/trestle'
8
+ include <%= @project.capitalize %>
9
+
10
+ # don't run tests automatically if they were invoked as 'gem check -t ...'
11
+ if $0 =~ /gem/
12
+ require 'minitest/unit'
13
+ else
14
+ require 'minitest/autorun'
15
+ end
16
+
17
+ # Return the right directory for (probably executable) _c_.
18
+ def cmd(c)
19
+ case File.basename(Dir.pwd)
20
+ when Meta::NAME.downcase
21
+ # test probably is executed from the Rakefile
22
+ Dir.chdir('test')
23
+ when 'test'
24
+ # we are in the test directory, there is nothing special to do
25
+ else
26
+ # tests were invoked by 'gem check -t <%= @project %>'
27
+ begin
28
+ Dir.chdir(Trestle.gem_libdir + '/../../test')
29
+ rescue
30
+ raise "running tests from '#{Dir.pwd}' isn't supported: #{$!}"
31
+ end
32
+ end
33
+
34
+ '../bin/' + c
35
+ end
36
+
37
+ # Don't remove this: falsework/0.2.2/naive/2010-12-26T04:50:00+02:00
@@ -2,10 +2,23 @@
2
2
  # -*-ruby-*-
3
3
  # :erb:
4
4
 
5
+ # This is a helper for your Rakefile. Read the comments for each
6
+ # function.
7
+
5
8
  require 'git'
6
9
  require 'pp'
7
10
 
8
- # Return a list of files in a git repository _repdir_
11
+ # Return a list of files in a git repository _repdir_.
12
+ #
13
+ # Add this to your gem spec:
14
+ #
15
+ # spec = Gem::Specification.new {|i|
16
+ # i.files = git_ls('.')
17
+ # }
18
+ #
19
+ # What it does is just collecting the list of the files from the git
20
+ # repository. The idea is to use that list for the gem spec. No more
21
+ # missing or redundant files in gems!
9
22
  def git_ls(repdir, ignore_some = true)
10
23
  ignore = ['/?\.gitignore$']
11
24
 
@@ -20,4 +33,4 @@ end
20
33
 
21
34
  pp git_ls('.') if __FILE__ == $0
22
35
 
23
- # Don't remove this: 2010-12-22T19:42:32+02:00 falsework 0.1.2
36
+ # Don't remove this: falsework/0.2.2/naive/2010-12-26T04:50:00+02:00
@@ -3,13 +3,26 @@ require 'yaml'
3
3
  require 'shellwords.rb'
4
4
  require 'optparse'
5
5
  require 'pp'
6
+ require 'open4'
6
7
 
7
8
  require_relative 'meta'
8
9
 
9
10
  # :include: ../../README.rdoc
10
11
  module Falsework
11
12
 
12
- class Utils
13
+ class Trestle
14
+
15
+ # Execute _cmd_ and return a list [exit_status, stderr,
16
+ # stdout]. Very handy.
17
+ def self.cmd_run(cmd)
18
+ so = sr = ''
19
+ status = Open4::popen4(cmd) { |pid, stdin, stdout, stderr|
20
+ so = stdout.read
21
+ sr = stderr.read
22
+ }
23
+ [status.exitstatus, sr, so]
24
+ end
25
+
13
26
  # Return a directory with program libraries.
14
27
  def self.gem_libdir
15
28
  t = ["#{File.dirname(File.expand_path($0))}/../lib/#{Falsework::Meta::NAME}",
@@ -114,7 +127,7 @@ module Falsework
114
127
  # puts "\n2 run"
115
128
  r = config_flat_load(rvars)
116
129
  rescue
117
- Utils.errx(1, "cannot load config: #{$!}")
130
+ Trestle.errx(1, "cannot load config: #{$!}")
118
131
  end
119
132
  veputs(1, "Loaded config: #{r}")
120
133
  cb.call(block_given?, ARGV)
@@ -193,9 +206,9 @@ module Falsework
193
206
  o.parse!(src)
194
207
  @cl_parsing_times += 1
195
208
  rescue
196
- Utils.errx(1, $!.to_s)
209
+ Trestle.errx(1, $!.to_s)
197
210
  end
198
211
  end
199
212
 
200
- end # Utils
213
+ end # trestle
201
214
  end
data/test/helper.rb CHANGED
@@ -1,46 +1 @@
1
- # :erb:
2
- # Various staff for minitest.
3
-
4
- require 'fileutils'
5
- require 'open4'
6
-
7
- include FileUtils
8
-
9
- require_relative '../lib/falsework/utils'
10
- include Falsework
11
-
12
- # don't run tests automatically if they were invoked as 'gem check -t ...'
13
- if $0 =~ /gem/
14
- require 'minitest/unit'
15
- else
16
- require 'minitest/autorun'
17
- end
18
-
19
- def cmd_run(cmd)
20
- so = sr = ''
21
- status = Open4::popen4(cmd) { |pid, stdin, stdout, stderr|
22
- so = stdout.read
23
- sr = stderr.read
24
- }
25
- [status.exitstatus, sr, so]
26
- end
27
-
28
- # Return the right directory for (probably executable) _c_.
29
- def cmd(c)
30
- case File.basename(Dir.pwd)
31
- when Meta::NAME.downcase
32
- # test probably is executed from the Rakefile
33
- Dir.chdir('test')
34
- when 'test'
35
- # we are in the test directory, there is nothing special to do
36
- else
37
- # tests were invoked by 'gem check -t falsework'
38
- begin
39
- Dir.chdir(Utils.gem_libdir + '/../../test')
40
- rescue
41
- raise "running tests from '#{Dir.pwd}' isn't supported: #{$!}"
42
- end
43
- end
44
-
45
- '../bin/' + c
46
- end
1
+ require_relative 'helper_trestle'
@@ -0,0 +1,35 @@
1
+ # :erb:
2
+ # Various staff for minitest. Include this file into your 'helper.rb'.
3
+
4
+ require 'fileutils'
5
+ include FileUtils
6
+
7
+ require_relative '../lib/falsework/trestle'
8
+ include Falsework
9
+
10
+ # don't run tests automatically if they were invoked as 'gem check -t ...'
11
+ if $0 =~ /gem/
12
+ require 'minitest/unit'
13
+ else
14
+ require 'minitest/autorun'
15
+ end
16
+
17
+ # Return the right directory for (probably executable) _c_.
18
+ def cmd(c)
19
+ case File.basename(Dir.pwd)
20
+ when Meta::NAME.downcase
21
+ # test probably is executed from the Rakefile
22
+ Dir.chdir('test')
23
+ when 'test'
24
+ # we are in the test directory, there is nothing special to do
25
+ else
26
+ # tests were invoked by 'gem check -t falsework'
27
+ begin
28
+ Dir.chdir(Trestle.gem_libdir + '/../../test')
29
+ rescue
30
+ raise "running tests from '#{Dir.pwd}' isn't supported: #{$!}"
31
+ end
32
+ end
33
+
34
+ '../bin/' + c
35
+ end
@@ -13,8 +13,8 @@ def erb_skeletons(local_prj, template)
13
13
  line_max = 4
14
14
  target = File.absolute_path("lib/#{local_prj}/templates/#{template}")
15
15
  r = {}
16
- skiplist = ['/.git[^i]?', template, '/html', '/pkg', '/test/templates',
17
- 'find_erb_templates.rb']
16
+ skiplist = ['/.git[^i]?', "lib/#{local_prj}/templates", '/html', '/pkg',
17
+ '/test/templates', 'rake_erb_templates.rb']
18
18
 
19
19
  Falsework::Mould.traverse('.') {|i|
20
20
  next if File.directory?(i)
@@ -31,7 +31,7 @@ def erb_skeletons(local_prj, template)
31
31
  # puts line
32
32
  if line =~ /^..? :erb:/
33
33
  t = i.sub(/^.+?\//, '')
34
- r[target + '/' + t.sub(/#{local_prj}/, '.@project.') + '.erb'] = t
34
+ r[target + '/' + t.sub(/#{local_prj}/, '%%@project%%') + '.erb'] = t
35
35
  break
36
36
  end
37
37
  n += 1
@@ -42,14 +42,14 @@ def erb_skeletons(local_prj, template)
42
42
  r
43
43
  end
44
44
 
45
- def erb_make(local_prj, target, template)
46
- raw = File.read(template)
45
+ def erb_make(local_prj, template, target, tmplt)
46
+ raw = File.read(tmplt)
47
47
  raw.gsub!(/#{local_prj}/, '<%= @project %>')
48
48
  raw.gsub!(/#{local_prj.capitalize}/, '<%= @project.capitalize %>')
49
49
 
50
50
  mark = <<-EOF
51
51
 
52
- # Don't remove this: <%= DateTime.now %> <%= #{local_prj.capitalize}::Meta::NAME %> <%= #{local_prj.capitalize}::Meta::VERSION %>
52
+ # Don't remove this: <%= #{local_prj.capitalize}::Meta::NAME %>/<%= #{local_prj.capitalize}::Meta::VERSION %>/#{template}/<%= DateTime.now %>
53
53
  EOF
54
54
  File.open(target, 'w+') {
55
55
  |fp| fp.puts raw + ERB.new(mark).result(binding)
data/test/rake_git.rb CHANGED
@@ -2,10 +2,23 @@
2
2
  # -*-ruby-*-
3
3
  # :erb:
4
4
 
5
+ # This is a helper for your Rakefile. Read the comments for each
6
+ # function.
7
+
5
8
  require 'git'
6
9
  require 'pp'
7
10
 
8
- # Return a list of files in a git repository _repdir_
11
+ # Return a list of files in a git repository _repdir_.
12
+ #
13
+ # Add this to your gem spec:
14
+ #
15
+ # spec = Gem::Specification.new {|i|
16
+ # i.files = git_ls('.')
17
+ # }
18
+ #
19
+ # What it does is just collecting the list of the files from the git
20
+ # repository. The idea is to use that list for the gem spec. No more
21
+ # missing or redundant files in gems!
9
22
  def git_ls(repdir, ignore_some = true)
10
23
  ignore = ['/?\.gitignore$']
11
24
 
data/test/test_exe.rb CHANGED
@@ -8,14 +8,20 @@ class TestFalsework < MiniTest::Unit::TestCase
8
8
  end
9
9
 
10
10
  def test_project_list
11
- r = cmd_run "#{CMD} list"
11
+ r = Trestle.cmd_run "#{CMD} list"
12
12
  assert_equal(0, r[0])
13
13
  assert_match(/naive\n/, r[2])
14
14
  end
15
15
 
16
+ # very silly analogue of "sed -i'' -E 's/foo/bar/g' file"
17
+ def sed(file, re, repl)
18
+ o = File.read(file).gsub(re, repl)
19
+ File.open(file, 'w+') {|fp| fp.printf(o) }
20
+ end
21
+
16
22
  def test_project_new
17
23
  rm_rf 'templates/foo'
18
- r = cmd_run "#{CMD} new templates/foo -v"
24
+ r = Trestle.cmd_run "#{CMD} new templates/foo -v"
19
25
  # pp r
20
26
  assert_equal(0, r[0], r)
21
27
 
@@ -39,9 +45,10 @@ class TestFalsework < MiniTest::Unit::TestCase
39
45
  "templates/foo/lib",
40
46
  "templates/foo/lib/foo",
41
47
  "templates/foo/lib/foo/meta.rb",
42
- "templates/foo/lib/foo/utils.rb",
48
+ "templates/foo/lib/foo/trestle.rb",
43
49
  "templates/foo/test",
44
50
  "templates/foo/test/helper.rb",
51
+ "templates/foo/test/helper_trestle.rb",
45
52
  "templates/foo/test/rake_git.rb",
46
53
  "templates/foo/test/test_foo.rb"]
47
54
 
@@ -54,19 +61,34 @@ class TestFalsework < MiniTest::Unit::TestCase
54
61
  origdir = pwd
55
62
  cd 'templates/foo'
56
63
 
57
- r = cmd_run "../../#{CMD} exe qqq"
64
+ r = Trestle.cmd_run "../../#{CMD} exe qqq"
58
65
  assert_equal(0, r[0])
59
66
  assert_equal(true, File.executable?('bin/qqq'))
60
67
 
61
- r = cmd_run "../../#{CMD} test qqq"
68
+ r = Trestle.cmd_run "../../#{CMD} test qqq"
62
69
  assert_equal(0, r[0])
63
70
  assert_equal(true, File.exist?('test/test_qqq.rb'))
71
+
72
+ # upgrade
73
+ r = Trestle.cmd_run "../../#{CMD} upgrade -b"
74
+ assert_equal(0, r[0])
75
+ rm ['test/helper_trestle.rb', 'test/rake_git.rb']
76
+ r = Trestle.cmd_run "../../#{CMD} upgrade -b"
77
+ assert_equal(0, r[0])
78
+ sed 'test/helper_trestle.rb',
79
+ /^(# Don't.+falsework\/)\d+\.\d+\.\d+(\/.+)$/, '\1999.999.999\2'
80
+ r = Trestle.cmd_run "../../#{CMD} upgrade -b"
81
+ assert_equal(1, r[0])
82
+ assert_match(/file .+ is from .+ falsework: 999.999.999/, r[1])
83
+ mv('test', 'ttt')
84
+ r = Trestle.cmd_run "../../#{CMD} upgrade -b"
85
+ assert_equal(0, r[0])
64
86
 
65
87
  cd origdir
66
88
  end
67
89
 
68
90
  def test_project_invalid_name
69
- r = cmd_run "#{CMD} new 123"
91
+ r = Trestle.cmd_run "#{CMD} new 123"
70
92
  assert_equal(1, r[0])
71
93
  assert_match(/project name cannot start with a digit/, r[1])
72
94
  end
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 1
8
7
  - 2
9
- version: 0.1.2
8
+ - 2
9
+ version: 0.2.2
10
10
  platform: ruby
11
11
  authors:
12
12
  - Alexander Gromnitsky
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-12-22 00:00:00 +02:00
17
+ date: 2010-12-26 00:00:00 +02:00
18
18
  default_executable: falsework
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -72,21 +72,23 @@ files:
72
72
  - lib/falsework/templates/naive/.gitignore.erb
73
73
  - lib/falsework/templates/naive/README.rdoc.erb
74
74
  - lib/falsework/templates/naive/Rakefile.erb
75
- - lib/falsework/templates/naive/bin/.@project..erb
75
+ - lib/falsework/templates/naive/bin/%%@project%%.erb
76
76
  - lib/falsework/templates/naive/doc/LICENSE.erb
77
77
  - lib/falsework/templates/naive/doc/NEWS.rdoc.erb
78
78
  - lib/falsework/templates/naive/doc/README.rdoc.erb
79
- - lib/falsework/templates/naive/etc/.@project..yaml.erb
80
- - lib/falsework/templates/naive/lib/.@project./meta.rb.erb
81
- - lib/falsework/templates/naive/test/test_.@project..rb.erb
82
- - lib/falsework/utils.rb
79
+ - lib/falsework/templates/naive/etc/%%@project%%.yaml.erb
80
+ - lib/falsework/templates/naive/lib/%%@project%%/meta.rb.erb
81
+ - lib/falsework/templates/naive/test/helper.rb.erb
82
+ - lib/falsework/templates/naive/test/test_%%@project%%.rb.erb
83
+ - lib/falsework/trestle.rb
83
84
  - test/helper.rb
85
+ - test/helper_trestle.rb
84
86
  - test/rake_erb_templates.rb
85
87
  - test/rake_git.rb
86
88
  - test/templates/.keep_me
87
89
  - test/test_exe.rb
88
- - lib/falsework/templates/naive/lib/.@project./utils.rb.erb
89
- - lib/falsework/templates/naive/test/helper.rb.erb
90
+ - lib/falsework/templates/naive/lib/%%@project%%/trestle.rb.erb
91
+ - lib/falsework/templates/naive/test/helper_trestle.rb.erb
90
92
  - lib/falsework/templates/naive/test/rake_git.rb.erb
91
93
  has_rdoc: true
92
94
  homepage: http://github.com/gromnitsky/falsework