cyborg 0.1.1 → 0.2.0
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/cyborg +5 -1
- data/lib/cyborg.rb +1 -0
- data/lib/cyborg/command.rb +1 -1
- data/lib/cyborg/command/npm.rb +0 -6
- data/lib/cyborg/command/scaffold.rb +90 -85
- data/lib/cyborg/plugin.rb +23 -18
- data/lib/cyborg/plugin/assets/javascripts.rb +1 -1
- data/lib/cyborg/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: de1ffb656fd08f1bc6ce7993f13df4f0d40a8055
|
4
|
+
data.tar.gz: 14313e29b7ae7968042e0027a8498d9953cd2d39
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8d55c4eacd4a0e75d6462776143c8e221a9e570b76d2fb05af9a54658fd17019b47e805f6020f4f681835f38767ead191606a66afc3c6d513576cc04f8de6db1
|
7
|
+
data.tar.gz: 844bce677e103e3e487ba0c6adeadb5815ac675f066fc4ac71f6ae55908d408a8b9ce52cac666ff6005afc68d17c7b32540bdcd38edee38358d9ba593e75bf3a
|
data/bin/cyborg
CHANGED
@@ -28,7 +28,11 @@ OptionParser.new do |opts|
|
|
28
28
|
if %w(n new).include? options[:command]
|
29
29
|
options[:name] = next_arg
|
30
30
|
|
31
|
-
opts.on("-
|
31
|
+
opts.on("-e", "--engine ENGINE_NAME", String, "Name the engine (defaults to gem name)") do |engine|
|
32
|
+
options[:engine] = engine
|
33
|
+
end
|
34
|
+
|
35
|
+
opts.on("-f", "--force", "overwrite existing files") do |val|
|
32
36
|
options[:force] = true
|
33
37
|
end
|
34
38
|
end
|
data/lib/cyborg.rb
CHANGED
data/lib/cyborg/command.rb
CHANGED
data/lib/cyborg/command/npm.rb
CHANGED
@@ -21,17 +21,11 @@ module Cyborg
|
|
21
21
|
|
22
22
|
if File.exist?(package_path)
|
23
23
|
update_package_json
|
24
|
-
install
|
25
24
|
else
|
26
25
|
write_package_json(DEPENDENCIES)
|
27
|
-
install
|
28
26
|
end
|
29
27
|
end
|
30
28
|
|
31
|
-
def install
|
32
|
-
system "npm install"
|
33
|
-
end
|
34
|
-
|
35
29
|
def package_path
|
36
30
|
File.join(Dir.pwd, 'package.json')
|
37
31
|
end
|
@@ -2,14 +2,16 @@ require 'fileutils'
|
|
2
2
|
|
3
3
|
module Cyborg
|
4
4
|
class Scaffold
|
5
|
-
attr_reader :
|
5
|
+
attr_reader :gem, :engine, :namespace, :plugin_module, :spec, :path, :gemspec_path
|
6
6
|
|
7
|
-
def initialize(
|
7
|
+
def initialize(options)
|
8
8
|
@cwd = Dir.pwd
|
9
|
-
@
|
10
|
-
@
|
9
|
+
@gem = underscorize(options[:name])
|
10
|
+
@engine = underscorize(options[:engine] || options[:name])
|
11
|
+
@namespace = @engine
|
12
|
+
@plugin_module = modulize @engine
|
11
13
|
|
12
|
-
puts "Creating new plugin #{
|
14
|
+
puts "Creating new plugin #{@namespace}".bold
|
13
15
|
engine_site_scaffold
|
14
16
|
|
15
17
|
@gemspec_path = create_gem
|
@@ -33,9 +35,9 @@ module Cyborg
|
|
33
35
|
begin
|
34
36
|
require 'bundler'
|
35
37
|
require 'bundler/cli'
|
36
|
-
Bundler::CLI.start(['gem',
|
38
|
+
Bundler::CLI.start(['gem', gem])
|
37
39
|
|
38
|
-
Dir.glob(File.join(
|
40
|
+
Dir.glob(File.join(gem, "/*.gemspec")).first
|
39
41
|
|
40
42
|
rescue LoadError
|
41
43
|
raise "To use this feature you'll need to install the bundler gem with `gem install bundler`."
|
@@ -51,11 +53,7 @@ module Cyborg
|
|
51
53
|
# First remove scaffold spec.files (which rely on git) to avoid errors
|
52
54
|
# when loading the spec
|
53
55
|
def fix_gemspec_files
|
54
|
-
|
55
|
-
|
56
|
-
File.open(gemspec_path, 'w') do |io|
|
57
|
-
io.write gs.gsub(/^.+spec\.files.+$/,'')
|
58
|
-
end
|
56
|
+
write_file(gemspec_path, File.read(gemspec_path).gsub(/^.+spec\.files.+$/,''))
|
59
57
|
end
|
60
58
|
|
61
59
|
def bootstrap_gem
|
@@ -64,61 +62,55 @@ module Cyborg
|
|
64
62
|
FileUtils.rm_rf(File.join(path, 'bin'))
|
65
63
|
|
66
64
|
# Simplify gempsec and set up to add assets properly
|
67
|
-
|
68
|
-
io.write gemspec
|
69
|
-
end
|
65
|
+
write_file(gemspec_path, gemspec)
|
70
66
|
|
71
|
-
|
67
|
+
write_file("#{gem}/lib/#{gem}.rb", %Q{require 'cyborg'
|
68
|
+
require '#{gem}/version'
|
72
69
|
|
73
|
-
|
74
|
-
io.write %Q{require 'megatron'
|
75
|
-
require '#{name}/version'
|
76
|
-
|
77
|
-
module #{@module_name}
|
70
|
+
module #{modulize(gem)}
|
78
71
|
class Plugin < Cyborg::Plugin
|
79
72
|
end
|
80
73
|
end
|
81
74
|
|
82
|
-
Cyborg.register(#{
|
83
|
-
|
84
|
-
})}
|
85
|
-
|
86
|
-
|
75
|
+
Cyborg.register(#{modulize(gem)}::Plugin, {
|
76
|
+
#{cyborg_plugin_config}
|
77
|
+
})})
|
78
|
+
end
|
79
|
+
|
80
|
+
def cyborg_plugin_config
|
81
|
+
plugin_config = "gem: '#{gem}'"
|
82
|
+
plugin_config += ",\n engine: '#{engine}'" if engine
|
83
|
+
plugin_config
|
87
84
|
end
|
88
85
|
|
89
86
|
# Add engine's app assets and utilities
|
90
87
|
def engine_app_scaffold
|
91
88
|
|
92
89
|
# Add asset dirs
|
93
|
-
%w(images javascripts stylesheets svgs).
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
end
|
90
|
+
files = %w(images javascripts stylesheets svgs).map { |path|
|
91
|
+
"#{gem}/app/assets/#{path}/#{namespace}/.keep"
|
92
|
+
}
|
93
|
+
|
94
|
+
write_file(files, '')
|
99
95
|
|
100
96
|
# Add helper and layout dirs
|
101
|
-
%w(helpers views/layouts).each
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
97
|
+
files = %w(helpers views/layouts).each { |path|
|
98
|
+
"#{gem}/app/#{path}/#{namespace}"
|
99
|
+
}
|
100
|
+
|
101
|
+
write_file(files, '')
|
106
102
|
|
107
103
|
# Add an application helper
|
108
|
-
|
109
|
-
io.write %Q{module #{@module_name}
|
104
|
+
write_file("#{gem}/app/helpers/#{namespace}/application_helper.rb", %Q{module #{plugin_module}
|
110
105
|
module ApplicationHelper
|
111
106
|
end
|
112
|
-
end}
|
113
|
-
action_log "create", "#{name}/app/helpers/#{name}/application_helper.rb"
|
114
|
-
end
|
107
|
+
end})
|
115
108
|
|
116
109
|
# Add an a base layout
|
117
|
-
|
118
|
-
io.write %Q{<!DOCTYPE html>
|
110
|
+
write_file("#{gem}/app/views/layouts/#{namespace}/application.html.erb", %Q{<!DOCTYPE html>
|
119
111
|
<html>
|
120
112
|
<head>
|
121
|
-
<title>#{
|
113
|
+
<title>#{plugin_module}</title>
|
122
114
|
<%= csrf_meta_tags %>
|
123
115
|
<%= asset_tags %>
|
124
116
|
<%= yield :stylesheets %>
|
@@ -131,12 +123,11 @@ end}
|
|
131
123
|
<div class='page'><%=yield %></div>
|
132
124
|
</div>
|
133
125
|
</body>
|
134
|
-
</html>}
|
135
|
-
end
|
136
|
-
action_log "create", "#{name}/app/views/layouts/#{name}/application.html.erb"
|
126
|
+
</html>})
|
137
127
|
|
138
|
-
|
139
|
-
|
128
|
+
|
129
|
+
# Update .gitignore
|
130
|
+
write_file("#{gem}/.gitignore", %Q{.DS_Store
|
140
131
|
log/*.log
|
141
132
|
pkg/
|
142
133
|
node_modules
|
@@ -144,15 +135,13 @@ site/log/*.log
|
|
144
135
|
site/tmp/
|
145
136
|
/public/
|
146
137
|
_svg.js
|
147
|
-
.sass-cache}
|
148
|
-
end
|
149
|
-
action_log "update", "#{name}/.gitignore"
|
138
|
+
.sass-cache}, 'a')
|
150
139
|
end
|
151
140
|
|
152
141
|
def engine_site_scaffold
|
153
|
-
FileUtils.mkdir_p(".#{
|
154
|
-
Dir.chdir ".#{
|
155
|
-
response = Open3.capture3("rails plugin new #{
|
142
|
+
FileUtils.mkdir_p(".#{gem}-tmp")
|
143
|
+
Dir.chdir ".#{gem}-tmp" do
|
144
|
+
response = Open3.capture3("rails plugin new #{gem} --mountable --dummy-path=site --skip-test-unit")
|
156
145
|
if !response[1].empty?
|
157
146
|
puts response[1]
|
158
147
|
abort "FAILED: Please be sure you have the rails gem installed with `gem install rails`"
|
@@ -164,7 +153,7 @@ _svg.js
|
|
164
153
|
site_path = File.join(path, 'site')
|
165
154
|
FileUtils.mkdir_p(site_path)
|
166
155
|
|
167
|
-
Dir.chdir ".#{
|
156
|
+
Dir.chdir ".#{gem}-tmp/#{gem}" do
|
168
157
|
%w(app config bin config.ru Rakefile public log).each do |item|
|
169
158
|
target = File.join(site_path, item)
|
170
159
|
|
@@ -174,7 +163,7 @@ _svg.js
|
|
174
163
|
|
175
164
|
end
|
176
165
|
|
177
|
-
FileUtils.rm_rf(".#{
|
166
|
+
FileUtils.rm_rf(".#{gem}-tmp")
|
178
167
|
%w(app/mailers app/models config/database.yml).each do |item|
|
179
168
|
FileUtils.rm_rf(File.join(site_path, item))
|
180
169
|
end
|
@@ -183,8 +172,7 @@ _svg.js
|
|
183
172
|
def prepare_engine_site
|
184
173
|
site_path = File.join(path, 'site')
|
185
174
|
|
186
|
-
File.
|
187
|
-
io.write %Q{Rails.application.configure do
|
175
|
+
write_file(File.join(site_path, 'config/environments/development.rb'), %Q{Rails.application.configure do
|
188
176
|
config.cache_classes = false
|
189
177
|
|
190
178
|
# Do not eager load code on boot.
|
@@ -197,11 +185,9 @@ _svg.js
|
|
197
185
|
# Print deprecation notices to the Rails logger.
|
198
186
|
config.active_support.deprecation = :log
|
199
187
|
end
|
200
|
-
|
201
|
-
end
|
188
|
+
})
|
202
189
|
|
203
|
-
File.
|
204
|
-
io.write %Q{require File.expand_path('../boot', __FILE__)
|
190
|
+
write_file(File.join(site_path, 'config/application.rb'), %Q{require File.expand_path('../boot', __FILE__)
|
205
191
|
|
206
192
|
require "rails"
|
207
193
|
# Pick the frameworks you want:
|
@@ -213,40 +199,31 @@ require 'bundler'
|
|
213
199
|
# you've limited to :test, :development, or :production.
|
214
200
|
Bundler.require(*Rails.groups)
|
215
201
|
|
216
|
-
require '#{
|
202
|
+
require '#{gem}'
|
217
203
|
require 'sprockets/railtie'
|
218
204
|
|
219
205
|
module Site
|
220
206
|
class Application < Cyborg::Application
|
221
207
|
end
|
222
|
-
end}
|
223
|
-
end
|
208
|
+
end})
|
224
209
|
|
225
|
-
File.
|
226
|
-
io.write %Q{Rails.application.routes.draw do
|
210
|
+
write_file(File.join(site_path, 'config/routes.rb'), %Q{Rails.application.routes.draw do
|
227
211
|
resources :docs, param: :page, path: ''
|
228
|
-
end}
|
229
|
-
end
|
212
|
+
end})
|
230
213
|
|
231
|
-
File.
|
232
|
-
io.write %Q{class DocsController < ApplicationController
|
214
|
+
write_file(File.join(site_path, 'app/controllers/docs_controller.rb'), %Q{class DocsController < ApplicationController
|
233
215
|
def show
|
234
216
|
render action: "#\{params[:page]\}"
|
235
217
|
end
|
236
|
-
end}
|
237
|
-
end
|
218
|
+
end})
|
238
219
|
|
239
|
-
File.
|
240
|
-
|
241
|
-
|
242
|
-
FileUtils.mkdir_p File.join(site_path, 'app/views/docs')
|
243
|
-
File.open File.join(site_path, 'app/views/docs/index.html.erb'), 'w' do |io|
|
244
|
-
io.write %Q{<h1>#{@module_name} Documentaiton</h1>}
|
245
|
-
end
|
220
|
+
write_file(File.join(site_path, 'app/views/layouts/application.html.erb'), "<%= layout do %>\n<% end %>")
|
221
|
+
|
222
|
+
write_file(File.join(site_path, 'app/views/docs/index.html.erb'), "<h1>#{plugin_module} Documentation</h1>")
|
246
223
|
end
|
247
224
|
|
248
225
|
def update_git
|
249
|
-
Dir.chdir
|
226
|
+
Dir.chdir gem do
|
250
227
|
system "git reset"
|
251
228
|
system "git add -A"
|
252
229
|
end
|
@@ -261,7 +238,7 @@ require "#{spec.name}/version"
|
|
261
238
|
# Describe your gem and declare its dependencies:
|
262
239
|
Gem::Specification.new do |spec|
|
263
240
|
spec.name = "#{spec.name}"
|
264
|
-
spec.version = #{
|
241
|
+
spec.version = #{modulize(gem)}::VERSION
|
265
242
|
spec.authors = #{spec.authors}
|
266
243
|
spec.email = #{spec.email}
|
267
244
|
spec.summary = "Summary of your gem."
|
@@ -272,7 +249,7 @@ Gem::Specification.new do |spec|
|
|
272
249
|
spec.require_paths = ["lib"]
|
273
250
|
|
274
251
|
spec.add_dependency "rails", "~> 4.2.6"
|
275
|
-
spec.add_runtime_dependency "
|
252
|
+
spec.add_runtime_dependency "cyborg"
|
276
253
|
|
277
254
|
spec.add_development_dependency "bundler", "~> 1.12"
|
278
255
|
spec.add_development_dependency "rake", "~> 10.0"
|
@@ -280,8 +257,36 @@ end
|
|
280
257
|
}
|
281
258
|
end
|
282
259
|
|
260
|
+
def write_file(paths, content, mode='w')
|
261
|
+
paths = [paths].flatten
|
262
|
+
paths.each do |path|
|
263
|
+
if File.exist?(path)
|
264
|
+
type = 'update'
|
265
|
+
else
|
266
|
+
FileUtils.mkdir_p(File.dirname(path))
|
267
|
+
type ='create'
|
268
|
+
end
|
269
|
+
|
270
|
+
File.open path, mode do |io|
|
271
|
+
io.write(content)
|
272
|
+
end
|
273
|
+
|
274
|
+
action_log(type, path)
|
275
|
+
end
|
276
|
+
end
|
277
|
+
|
283
278
|
def action_log(action, path)
|
284
279
|
puts action.rjust(12).colorize(:green).bold + " #{path}"
|
285
280
|
end
|
281
|
+
|
282
|
+
def modulize(input)
|
283
|
+
input.split('_').collect(&:capitalize).join
|
284
|
+
end
|
285
|
+
|
286
|
+
def underscorize(input)
|
287
|
+
input.gsub(/[A-Z]/) do |char|
|
288
|
+
'_'+char
|
289
|
+
end.sub(/^_/,'').downcase
|
290
|
+
end
|
286
291
|
end
|
287
292
|
end
|
data/lib/cyborg/plugin.rb
CHANGED
@@ -1,45 +1,50 @@
|
|
1
1
|
module Cyborg
|
2
2
|
class Plugin
|
3
|
-
attr_reader :
|
3
|
+
attr_reader :name, :gem, :engine,
|
4
4
|
:stylesheets, :javascripts, :svgs, :destination
|
5
5
|
|
6
6
|
def initialize(options)
|
7
|
-
@name = options.delete(:
|
8
|
-
@
|
9
|
-
@gem = Gem.loaded_specs[@name]
|
7
|
+
@name = options.delete(:engine).downcase
|
8
|
+
@gem = Gem.loaded_specs[options.delete(:gem)]
|
10
9
|
@maps = false
|
11
10
|
config(options)
|
12
11
|
expand_asset_paths
|
13
12
|
|
14
13
|
# Store the gem path for access later when overriding root
|
15
14
|
parent_module.instance_variable_set(:@gem_path, root)
|
15
|
+
parent_module.instance_variable_set(:@cyborg_plugin_name, name)
|
16
16
|
add_assets
|
17
|
+
end
|
17
18
|
|
18
|
-
|
19
|
+
def engine_name
|
20
|
+
@engine.name.sub(/::Engine/,'')
|
19
21
|
end
|
20
22
|
|
21
23
|
def create_engine
|
22
24
|
# Create a new Rails::Engine
|
23
|
-
|
25
|
+
@engine = parent_module.const_set('Engine', Class.new(Rails::Engine) do
|
24
26
|
|
25
|
-
def
|
26
|
-
parent = Object.const_get(self.class.
|
27
|
-
|
28
|
-
Pathname.new path
|
27
|
+
def cyborg_plugin_path
|
28
|
+
parent = Object.const_get(self.class.name.sub(/::Engine/,''))
|
29
|
+
Pathname.new parent.instance_variable_get("@gem_path")
|
29
30
|
end
|
30
31
|
|
31
32
|
def config
|
32
|
-
@config ||= Rails::Engine::Configuration.new(
|
33
|
+
@config ||= Rails::Engine::Configuration.new(cyborg_plugin_path)
|
33
34
|
end
|
34
35
|
|
35
|
-
|
36
|
+
engine_name Cyborg.plugin.name
|
37
|
+
|
38
|
+
initializer "#{name}.static_assets" do |app|
|
36
39
|
app.middleware.insert_before(::ActionDispatch::Static, ::ActionDispatch::Static, "#{root}/public")
|
37
40
|
end
|
38
41
|
end)
|
39
42
|
end
|
40
43
|
|
41
44
|
def parent_module
|
42
|
-
|
45
|
+
mods = self.class.to_s.split('::')
|
46
|
+
mods.pop
|
47
|
+
Object.const_get(mods.join('::'))
|
43
48
|
end
|
44
49
|
|
45
50
|
def add_assets
|
@@ -89,15 +94,15 @@ module Cyborg
|
|
89
94
|
|
90
95
|
def config(options)
|
91
96
|
options = {
|
92
|
-
production_asset_root: "/assets/#{
|
93
|
-
asset_root: "/assets/#{
|
97
|
+
production_asset_root: "/assets/#{name}",
|
98
|
+
asset_root: "/assets/#{name}",
|
94
99
|
destination: "public/",
|
95
100
|
root: @gem.full_gem_path,
|
96
101
|
version: @gem.version.to_s,
|
97
102
|
paths: {
|
98
|
-
stylesheets: "app/assets/stylesheets/#{
|
99
|
-
javascripts: "app/assets/javascripts/#{
|
100
|
-
svgs: "app/assets/svgs/#{
|
103
|
+
stylesheets: "app/assets/stylesheets/#{name}",
|
104
|
+
javascripts: "app/assets/javascripts/#{name}",
|
105
|
+
svgs: "app/assets/svgs/#{name}",
|
101
106
|
}
|
102
107
|
}.merge(options)
|
103
108
|
|
@@ -13,7 +13,7 @@ module Cyborg
|
|
13
13
|
if Open3.capture3("npm ls browserify-incremental")[1].empty?
|
14
14
|
find_files.each do |file|
|
15
15
|
dest = destination(file).sub(/\.js$/,'')
|
16
|
-
cmd = "browserifyinc --cachefile #{Cyborg.rails_path("tmp/cache/assets/.browserify-cache.json")} #{file} -t babelify --standalone #{plugin.
|
16
|
+
cmd = "browserifyinc --cachefile #{Cyborg.rails_path("tmp/cache/assets/.browserify-cache.json")} #{file} -t babelify --standalone #{plugin.name} -o #{dest}.js -d"
|
17
17
|
cmd += " -p [ minifyify --map #{url(file).sub(/\.js$/,'')}.map.json --output #{dest}.map.json ]" if plugin.maps? || Cyborg.production?
|
18
18
|
system cmd
|
19
19
|
compress(destination(file))
|
data/lib/cyborg/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cyborg
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brandon Mathis
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-07-
|
11
|
+
date: 2016-07-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sass
|