genius-builder 0.1.0 → 0.1.1
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 +4 -4
- data/bin/genius +149 -0
- data/lib/genius.rh +10 -1
- metadata +2 -2
- data/bin/genius +0 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f3b88f0b419d9b88da858d6ace39842c451d11c26c49e6f20e654b4f8d64e602
|
4
|
+
data.tar.gz: a5f4b88ac27ff2f2b3bf46eab490e89736366a30f9bc65671426762e5af0a4cc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 40b9ab31c924e9928580ea4360f58b17004a3962065ee53fc421379e963c4d4cbefde63ca6b51603c4605798d3df7a75f0116f86989a491c54358d2cffd9594a
|
7
|
+
data.tar.gz: 9f38a77fad22d58dee046d5299aaa58424fef0789823b085f03fa14deba1c1452923965b200e7576c3a17fe3a98b21237c899734b4dfec2aecff7bad16118d52
|
data/bin/genius
ADDED
@@ -0,0 +1,149 @@
|
|
1
|
+
#!/usr/bin/env rash
|
2
|
+
require "rash"
|
3
|
+
|
4
|
+
module Genius
|
5
|
+
@@build_tools = {}
|
6
|
+
@@build_groups = {}
|
7
|
+
|
8
|
+
def self.build_tools
|
9
|
+
@@build_tools.dup
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.build_groups
|
13
|
+
@@build_groups.dup
|
14
|
+
end
|
15
|
+
|
16
|
+
# Build tool methods
|
17
|
+
def self.register_build_tool(name, *files, &command)
|
18
|
+
@@build_tools[name.to_s] = BuildTool.new(name, *files, &command)
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.define_build_tool_files(name, *files)
|
22
|
+
@@build_tools[name.to_s].files = files.flatten.map(&:to_s)
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.add_build_tool_file(name, file)
|
26
|
+
@@build_tools[name.to_s].files << file.to_s
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.define_build_tool_command(name, &command)
|
30
|
+
@@build_tools[name.to_s].commands = [command]
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.add_build_tool_command(name, &command)
|
34
|
+
@@build_tools[name.to_s].commands << command
|
35
|
+
end
|
36
|
+
|
37
|
+
# Build group methods
|
38
|
+
def self.register_group(name, *extensions, &command)
|
39
|
+
@@build_groups[name.to_s] = BuildGroup.new(name, *extensions, &command)
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.define_group_extensions(name, *exts)
|
43
|
+
@@build_groups[name.to_s].extensions = exts.flatten.map {|e| e.to_s.delete_prefiox(".")}
|
44
|
+
end
|
45
|
+
|
46
|
+
def self.add_group_extension(name, ext)
|
47
|
+
# requires 2.5
|
48
|
+
@@build_groups[name.to_s].extensions << ext.to_s.delete_prefix(".")
|
49
|
+
end
|
50
|
+
|
51
|
+
def self.define_group_command(name, &command)
|
52
|
+
@@build_groups[name.to_s].commands = [command]
|
53
|
+
end
|
54
|
+
|
55
|
+
def self.add_group_command(name, &command)
|
56
|
+
@@build_groups[name.to_s].commands << command
|
57
|
+
end
|
58
|
+
|
59
|
+
|
60
|
+
private
|
61
|
+
|
62
|
+
class BuildTool
|
63
|
+
attr_accessor :name, :files, :commands
|
64
|
+
def initialize(name, *files, &command)
|
65
|
+
@name = name
|
66
|
+
@files = files.flatten.map(&:to_s)
|
67
|
+
@commands = [command]
|
68
|
+
end
|
69
|
+
|
70
|
+
def build(files)
|
71
|
+
@commands.each do |command|
|
72
|
+
command.call(files)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
class BuildGroup
|
78
|
+
attr_accessor :name, :extensions, :commands
|
79
|
+
def initialize(name, *extensions, &command)
|
80
|
+
@name = name
|
81
|
+
@extensions = extensions.flatten.map(&:to_s)
|
82
|
+
@commands = [command]
|
83
|
+
end
|
84
|
+
|
85
|
+
def build(files)
|
86
|
+
@commands.each do |command|
|
87
|
+
command.call(files)
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
$GENIUS_HOME = File.expand_path("~/.genius")
|
94
|
+
|
95
|
+
# Sanity check for if genius's dependencies exist.
|
96
|
+
if !Dir.exist?($GENIUS_HOME)
|
97
|
+
with_stdout_as_stderr do
|
98
|
+
puts ".genius - No such directory"
|
99
|
+
puts "\nTo use genius builder, put config files in the ~/.genius directory."
|
100
|
+
puts "Documentation for creating a genius config file can be found at <insert URL here>"
|
101
|
+
end
|
102
|
+
exit 1
|
103
|
+
end
|
104
|
+
|
105
|
+
# Load all config files in .genius, assuming all non-directory files are config files.
|
106
|
+
Dir[$GENIUS_HOME + "/*"].each do |config|
|
107
|
+
next if File.directory?(config)
|
108
|
+
exit unless load config
|
109
|
+
end
|
110
|
+
|
111
|
+
# Sort files by extension. Only files that have a name and extension are considered.
|
112
|
+
# i.e. Files that have no extension or are only extensions (including extensionless
|
113
|
+
# dotfiles) will not be considered. The final extension is used if multiple are
|
114
|
+
# present.
|
115
|
+
file_set = Hash.new {|h,k| h[k] = []}
|
116
|
+
Dir["**/*"].each do |file|
|
117
|
+
split_name = file.split(".")
|
118
|
+
if split_name.size > 1
|
119
|
+
file_set[split_name[-1]] << file
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
# Check for build tool patterns, terminating after build completion if one is matched
|
124
|
+
Genius.build_tools.each do |name, tool|
|
125
|
+
if tool.files.any? {|f| File.exist?(f) && !File.directory?(f)}
|
126
|
+
puts "Matched build tool pattern: #{tool.name}"
|
127
|
+
tool.build(file_set) # Does not contain all files, so may not be useful.
|
128
|
+
exit
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
# Get counts of files matching each build group.
|
133
|
+
group_counts = Genius.build_groups.map do |name, group|
|
134
|
+
file_count = group.extensions.inject(0) {|acc, ext| acc += file_set[ext].size}
|
135
|
+
[group, file_count]
|
136
|
+
end
|
137
|
+
|
138
|
+
# check if all patterns match
|
139
|
+
if group_counts.all? {|k,v| v.zero?}
|
140
|
+
with_stdout_as_stderr do
|
141
|
+
puts "No matching build patterns for the current directory"
|
142
|
+
exit 1
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
# Build based on commands specified by most populous build group,
|
147
|
+
# passing only the files with extensions specified by that group.
|
148
|
+
group = group_counts.max_by{|k,v| v}[0]
|
149
|
+
Genius.build_groups[group.name].build(file_set.filter{|k,v| group.extensions.include?(k)})
|
data/lib/genius.rh
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
#!/usr/bin/env rash
|
2
|
+
require "rash"
|
2
3
|
|
3
4
|
module Genius
|
4
5
|
@@build_tools = {}
|
@@ -120,7 +121,7 @@ Dir["**/*"].each do |file|
|
|
120
121
|
end
|
121
122
|
|
122
123
|
# Check for build tool patterns, terminating after build completion if one is matched
|
123
|
-
Genius.build_tools.each do |tool|
|
124
|
+
Genius.build_tools.each do |name, tool|
|
124
125
|
if tool.files.any? {|f| File.exist?(f) && !File.directory?(f)}
|
125
126
|
puts "Matched build tool pattern: #{tool.name}"
|
126
127
|
tool.build(file_set) # Does not contain all files, so may not be useful.
|
@@ -134,6 +135,14 @@ group_counts = Genius.build_groups.map do |name, group|
|
|
134
135
|
[group, file_count]
|
135
136
|
end
|
136
137
|
|
138
|
+
# check if all patterns match
|
139
|
+
if group_counts.all? {|k,v| v.zero?}
|
140
|
+
with_stdout_as_stderr do
|
141
|
+
puts "No matching build patterns for the current directory"
|
142
|
+
exit 1
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
137
146
|
# Build based on commands specified by most populous build group,
|
138
147
|
# passing only the files with extensions specified by that group.
|
139
148
|
group = group_counts.max_by{|k,v| v}[0]
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: genius-builder
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kellen Watt
|
@@ -52,7 +52,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
52
52
|
- !ruby/object:Gem::Version
|
53
53
|
version: '0'
|
54
54
|
requirements: []
|
55
|
-
rubygems_version: 3.
|
55
|
+
rubygems_version: 3.1.4
|
56
56
|
signing_key:
|
57
57
|
specification_version: 4
|
58
58
|
summary: An intelligent compiler selection tool
|
data/bin/genius
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
../lib/genius.rh
|