lake 0.1.3 → 0.1.6

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
  SHA1:
3
- metadata.gz: ef96e289c26a1c97a6ec16dafec98c834ce929ac
4
- data.tar.gz: b84deeb48b23d4fef38353e7fb0c9a03706f42c1
3
+ metadata.gz: 02079022e1dfb242f0b79d8561ce277469a77173
4
+ data.tar.gz: 520e8cd20ccd5927866032e3765871955567b238
5
5
  SHA512:
6
- metadata.gz: 3d7f779031a4bce3f872604a8a9b944559170b5f58e25ee169ac9a4e3586bb1639ec015c680b15ee35ed733e955ddffca54bc8395450f2d89d0477d941eb97a1
7
- data.tar.gz: 77373138956efbd15ba2186bc4dbd7a713b9d6bbb42db55d6d4476955d0e8cd73da20420a2b4408052010c591de5a5f2b1c44e3859f6f2b69027f2f481a2f652
6
+ metadata.gz: 17e7a806e952f0c951d3ab0d0914601c60a76dec1dee4d22f8a2e9db5e621709fef5c1d061b1335769caef37cb200bba222acac6f6fdf876ee4b75f7a7dee993
7
+ data.tar.gz: 4b8027c4137e485b69af0bd1552c93667c61038795a3f3d631ca1d98671cc6200724af5facf980017fc1bf3ab4d264a690e3fc303ce434dfaac0b4fe13f4052f
data/bin/lake CHANGED
@@ -34,6 +34,7 @@ if File.exists? File.expand_path Lake::Opts.file
34
34
  eval code
35
35
  else
36
36
  puts "[FATAL] File not found"
37
+ exit 1
37
38
  end
38
39
 
39
40
  if Lake::Opts.list then
data/bin/lake-gen ADDED
@@ -0,0 +1,76 @@
1
+ #!/usr/bin/ruby
2
+
3
+ require 'lake/utils'
4
+ require 'lake/gen'
5
+ require 'optparse'
6
+ require 'open-uri'
7
+
8
+ class Opts
9
+ class << self
10
+ attr_accessor :out,:install
11
+ end
12
+ end
13
+
14
+ OptionParser.new do |o|
15
+ o.banner = "LakeGen"
16
+ o.on("-nNAME","--name=NAME","Set file name"){
17
+ |name|
18
+ Opts.out = name
19
+ }
20
+ o.on("-l","--list","List available templates and exit"){
21
+ puts "[INFO] Available templates:"
22
+ Dir.chdir(Dir.home) do
23
+ Dir.mkdir(".lake-gen") unless File.exists? ".lake-gen"
24
+ Dir.chdir(".lake-gen") do
25
+ puts Dir.glob("**/*.erb").map{|e| File.basename(e,".erb")}.join("\n\t")
26
+ end
27
+ end
28
+ exit
29
+ }
30
+ o.on("-iURL","--install=URL","Install template and exit"){
31
+ |url|
32
+ puts "[INFO] Install mode enabled"
33
+ Opts.install = url
34
+ }
35
+ o.on("-h","--help","Print this help"){puts o; exit}
36
+ end.parse!
37
+
38
+ def p_usage
39
+ puts "Usage:\n\tlake-gen (-h|--help) # Print this help"
40
+ puts "\tlake-gen (-i|--install) <url> [(-n|--name) <name>] # Download template <url> [and install as <name>]"
41
+ puts "\tlake-gen (-l|--list) # List templates"
42
+ puts "\tlake-gen [(-n|--name) <name>] <template> <arg1> ... <argN> # Generate file [and save as <name>"
43
+ end
44
+
45
+ def try_render(inp,out,argv)
46
+ content = ""
47
+ Dir.chdir(Dir.home) do
48
+ Dir.mkdir(".lake-gen") unless File.exists? ".lake-gen"
49
+ Dir.chdir(".lake-gen") do
50
+ if File.exists? inp then
51
+ content = File.read inp
52
+ else
53
+ puts "[FATAL] Cannot find #{inp}"
54
+ exit 1
55
+ end
56
+ end
57
+ end
58
+ Lake::Gen::render_template(content,argv,out)
59
+ end
60
+
61
+ if Opts.install then
62
+ puts "[INFO] Installing #{Opts.install}"
63
+ file = Opts.install
64
+ Opts.out ||= File.basename(file)
65
+ File.open(File.join(Dir.home,".lake-gen",Opts.out),"w"){
66
+ |f|
67
+ f.write File.read(file)
68
+ }
69
+ puts "[INFO] Successfully installed #{Opts.out}"
70
+ elsif ARGV.size > 0
71
+ file = ARGV.shift
72
+ Opts.out ||= File.basename(file,".erb")
73
+ try_render file, Opts.out, ARGV
74
+ else
75
+ p_usage
76
+ end
@@ -0,0 +1,13 @@
1
+ require "erb"
2
+
3
+ module Lake
4
+ module ERB
5
+ def render(template,vars)
6
+ b = binding
7
+ out = nil
8
+ ::ERB.new(template,0,nil,"out").result b
9
+ return out
10
+ end
11
+ module_function :render
12
+ end
13
+ end
data/lib/lake/gen.rb ADDED
@@ -0,0 +1,10 @@
1
+ require 'lake/gen/erb'
2
+ require 'optparse'
3
+ module Lake::Gen
4
+ def render_template(template,vars,file)
5
+ File.open(file,"w") do |f|
6
+ f.write(::Lake::ERB.render(template,vars))
7
+ end
8
+ end
9
+ module_function :render_template
10
+ end
data/lib/lake/utils.rb ADDED
@@ -0,0 +1,7 @@
1
+ module Lake
2
+ module Utils
3
+ def lake_root
4
+ File.expand_path("../..",__FILE__)
5
+ end
6
+ end
7
+ end
data/lib/lake.rb CHANGED
@@ -1,26 +1,37 @@
1
1
  $targets = {}
2
2
 
3
3
  module Lake
4
- VERSION='0.1.0 Beta'
4
+ VERSION='0.1.6'
5
5
  Target = Struct.new(:name,:proc,:deps,:flags) do
6
6
  def build
7
- for d in deps
8
- if proc or need_build?
9
- $targets[d.to_s].build if $targets[d.to_s]
10
- else
11
- puts "[INFO] #{d} is already built"
12
- end
7
+ if need_build? then
8
+ puts "[INFO] Building #{name}"
9
+ deps.each{
10
+ |e|
11
+ $targets[e.to_s].build
12
+ }
13
+ proc.call if proc
14
+ else
15
+ puts "[INFO] #{name} is already built"
13
16
  end
14
- puts "[INFO] Building #{name}"
15
- proc.call if proc
16
17
  end
17
18
 
18
19
  def need_build?
19
20
  for dep in deps do
20
- return true if not $targets[dep.to_s] and File.exists? dep.to_s
21
- return true if $targets[dep.to_s] and $targets[dep.to_s].need_build?
21
+ #return true if not $targets[dep.to_s] and not File.exists? dep.to_s
22
+ #return true if $targets[dep.to_s] and $targets[dep.to_s].need_build?
23
+ if $targets[dep.to_s] then
24
+ return true if $targets[dep.to_s].need_build?
25
+ else
26
+ return true unless File.exists? dep.to_s
27
+ end
28
+ end
29
+ return true if flags[:unchecked]
30
+ if flags[:virtual] then
31
+ return false
32
+ else
33
+ return ! File.exists?(name.to_s)
22
34
  end
23
- (!dep)||(!File.exists? dep)||(flags[:unchecked])
24
35
  end
25
36
  end
26
37
 
@@ -57,6 +68,10 @@ module Lake
57
68
  return name
58
69
  end
59
70
 
71
+ def virtual(name)
72
+ $targets[name].flags[:virtual] = true
73
+ end
74
+
60
75
  def use(*plugin)
61
76
  plugin.each{|p|require "lake/plugins/#{p.to_s}"}
62
77
  end
metadata CHANGED
@@ -1,24 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lake
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stepan unn4m3d Melnikov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-06-05 00:00:00.000000000 Z
11
+ date: 2016-06-07 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Lake - a Make-style build system with Ruby syntax
14
14
  email: smelnikov871@gmail.com
15
15
  executables:
16
16
  - lake
17
+ - lake-gen
17
18
  extensions: []
18
19
  extra_rdoc_files: []
19
20
  files:
20
21
  - bin/lake
22
+ - bin/lake-gen
21
23
  - lib/lake.rb
24
+ - lib/lake/gen.rb
25
+ - lib/lake/gen/erb.rb
26
+ - lib/lake/utils.rb
22
27
  homepage: https://github.com/unn4m3d/lake
23
28
  licenses:
24
29
  - MIT