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