isomorfeus-installer 1.0.0.delta1

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.
Files changed (42) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +0 -0
  3. data/bin/isomorfeus +137 -0
  4. data/isomorfeus-installer.gemspec +19 -0
  5. data/lib/isomorfeus/installer.rb +234 -0
  6. data/lib/isomorfeus/installer/asset_bundlers/opal_webpack_loader.rb +103 -0
  7. data/lib/isomorfeus/installer/databases/arangodb.rb +11 -0
  8. data/lib/isomorfeus/installer/databases/mysql.rb +11 -0
  9. data/lib/isomorfeus/installer/databases/neo4j.rb +11 -0
  10. data/lib/isomorfeus/installer/databases/none.rb +11 -0
  11. data/lib/isomorfeus/installer/databases/postgresql.rb +11 -0
  12. data/lib/isomorfeus/installer/frameworks/cuba.rb +26 -0
  13. data/lib/isomorfeus/installer/frameworks/rails.rb +78 -0
  14. data/lib/isomorfeus/installer/frameworks/roda.rb +26 -0
  15. data/lib/isomorfeus/installer/frameworks/sinatra.rb +26 -0
  16. data/lib/isomorfeus/installer/spectre.rb +0 -0
  17. data/lib/isomorfeus/installer/templates/Gemfile.erb +15 -0
  18. data/lib/isomorfeus/installer/templates/Procfile.erb +2 -0
  19. data/lib/isomorfeus/installer/templates/application.js.erb +29 -0
  20. data/lib/isomorfeus/installer/templates/cuba/config_ru.erb +48 -0
  21. data/lib/isomorfeus/installer/templates/isomorfeus_loader.rb.erb +8 -0
  22. data/lib/isomorfeus/installer/templates/my_app.rb.erb +17 -0
  23. data/lib/isomorfeus/installer/templates/my_component.rb.erb +12 -0
  24. data/lib/isomorfeus/installer/templates/owl/development.js.erb +145 -0
  25. data/lib/isomorfeus/installer/templates/owl/production.js.erb +93 -0
  26. data/lib/isomorfeus/installer/templates/owl/test.js.erb +0 -0
  27. data/lib/isomorfeus/installer/templates/package.json.erb +21 -0
  28. data/lib/isomorfeus/installer/templates/rails/application.html.erb.head +6 -0
  29. data/lib/isomorfeus/installer/templates/rails/application.html.erb.tail +6 -0
  30. data/lib/isomorfeus/installer/templates/rails/application_controller.rb +5 -0
  31. data/lib/isomorfeus/installer/templates/rails/application_helper.rb.erb +3 -0
  32. data/lib/isomorfeus/installer/templates/rails/assets.rb.erb +1 -0
  33. data/lib/isomorfeus/installer/templates/rails/basic-react.rb +453 -0
  34. data/lib/isomorfeus/installer/templates/rails/index.html +1 -0
  35. data/lib/isomorfeus/installer/templates/rails/routes.rb +5 -0
  36. data/lib/isomorfeus/installer/templates/roda/config_ru.erb +39 -0
  37. data/lib/isomorfeus/installer/templates/sinatra/config_ru.erb +38 -0
  38. data/lib/isomorfeus/installer/transport.rb +0 -0
  39. data/lib/isomorfeus/installer/transport_store.rb +0 -0
  40. data/lib/isomorfeus/installer/transports/actioncable.rb +11 -0
  41. data/readme.md +69 -0
  42. metadata +97 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: '087e024f4b6d1069db99cc60efe18ead0cd13d51aba1b1106feec8b1e10d64d8'
4
+ data.tar.gz: 89705b30c3d7c48147d8ca90e72e7966d02f2d9a2e343e01ffb59706beb7b2cc
5
+ SHA512:
6
+ metadata.gz: b2d60cf511dcd98ff2a3cb88301f0f2b0eeb926a54e2bf75d004d6629868dedb8cf80976adeb4db2e857fc029057ccb205a9ce12d76798cc581901d6fea8af26
7
+ data.tar.gz: 2d157a5b142433859517feb5c3e962216cbaa3336965049617f02d943fdf7419d7cbdde4d912945e41e0085497a82e95f9e2281e6d23a096d70bfb0053043d8c
data/Gemfile ADDED
File without changes
data/bin/isomorfeus ADDED
@@ -0,0 +1,137 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'optparse'
4
+ require 'erb'
5
+ require 'active_support/core_ext/string'
6
+
7
+ require_relative '../lib/isomorfeus/installer'
8
+
9
+ Isomorfeus::Installer.module_directories.each do |mod_dir|
10
+ mod_path = File.realpath(File.join(Isomorfeus::Installer.base_path, mod_dir))
11
+ modules = Dir.glob('*.rb', base: mod_path)
12
+ modules.each do |mod|
13
+ require_relative File.join(mod_path, mod)
14
+ end
15
+ end
16
+
17
+ options = {}
18
+ sorted_frameworks = Isomorfeus::Installer.frameworks.keys.sort
19
+ sorted_asset_bundlers = Isomorfeus::Installer.asset_bundlers.keys
20
+ sorted_databases = Isomorfeus::Installer.databases.keys.sort
21
+ sorted_transports = Isomorfeus::Installer.transports.keys
22
+
23
+ OptionParser.new do |opts|
24
+ opts.banner = 'Usage: isomorfeus options...'
25
+ opts.separator ''
26
+ opts.separator 'Required:'
27
+ opts.on('-nNAME', '--new=NAME', String, "Create new project with NAME and install isomorfeus.") do |v|
28
+ options[:new] = v
29
+ end
30
+ # opts.on('-e', '--existing', "Install Isomorfeus into existing project.") do |v|
31
+ # options[:existing] = v
32
+ # end
33
+ opts.separator ''
34
+ opts.separator 'Also required in any case is:'
35
+ opts.on('-fNAME', '--framework=FRAMEWORK', String, :REQUIRED, "Select base Framework, one of: #{sorted_frameworks.join(', ')}.") do |v|
36
+ if sorted_frameworks.include?(v)
37
+ options[:framework] = v
38
+ Isomorfeus::Installer.framework = Isomorfeus::Installer.frameworks[v]&.fetch(:installer)
39
+ else
40
+ puts "Framework #{v} not available!"
41
+ exit 1
42
+ end
43
+ end
44
+ opts.separator ''
45
+ opts.separator 'Other options:'
46
+ opts.on('-aBUNDLER', '--asset-bundler=BUNDLER', String, "Select asset bundler, one of: #{sorted_asset_bundlers.join(', ')}. (optional)") do |v|
47
+ if sorted_asset_bundlers.include?(v)
48
+ options[:asset_bundler] = v
49
+ Isomorfeus::Installer.asset_bundler = Isomorfeus::Installer.asset_bundlers[v]&.fetch(:installer)
50
+ else
51
+ puts "Asset bundler #{v} not available!"
52
+ exit 1
53
+ end
54
+ end
55
+ # opts.on('-dDATABASE', '--database=DATABASE', String, "Select database, one of: #{sorted_databases.join(', ')}. (optional, default: none)") do |v|
56
+ # if sorted_frameworks.include?(v)
57
+ # options[:database] = v
58
+ # else
59
+ # puts "Database #{v} not available!"
60
+ # exit 1
61
+ # end
62
+ # end
63
+ # opts.on('-tTRANSPORT', '--transport=TRANSPORT', String, "Select transport, one of: #{sorted_transports.join(', ')}. (optional, default: actioncable)") do |v|
64
+ # if sorted_frameworks.include?(v)
65
+ # options[:database] = v
66
+ # else
67
+ # puts "Database #{v} not available!"
68
+ # exit 1
69
+ # end
70
+ # end
71
+
72
+ opts.separator ''
73
+ opts.on("-h", "--help", "Prints this help") do
74
+ puts opts
75
+ exit
76
+ end
77
+ end.parse!
78
+
79
+ Isomorfeus::Installer.options = options
80
+ Isomorfeus::Installer.structure= Isomorfeus::Installer.frameworks[options[:framework]][:structure]
81
+
82
+ if options[:new] && options[:existing]
83
+ puts "Either choose a new installation (-n), or installation into a existing project (-e), both won't work!"
84
+ end
85
+ if !options[:new] && !options[:existing]
86
+ puts "Don't know what to do! Either choose a new installation (-n), or installation into a existing project (-e)."
87
+ end
88
+
89
+ if options[:new]
90
+ begin
91
+ if Isomorfeus::Installer.framework.respond_to?(:create_project)
92
+ Isomorfeus::Installer.framework.create_project(options[:new])
93
+ else
94
+ Dir.mkdir(options[:new])
95
+ end
96
+ Dir.chdir(options[:new])
97
+ rescue
98
+ puts "Directory #{options[:new]} could not be created!"
99
+ exit 1
100
+ end
101
+ end
102
+
103
+ root = Dir.open('.')
104
+
105
+ begin
106
+ Isomorfeus::Installer.create_directories
107
+ Isomorfeus::Installer.framework.install(root)
108
+ Isomorfeus::Installer.asset_bundler&.install(root)
109
+
110
+ camelized_dir = if options[:new]
111
+ options[:new].camelize
112
+ else
113
+ File.split(File.realpath(Dir.new('.'))).last.camelize
114
+ end
115
+
116
+ app_name = camelized_dir + 'App'
117
+ component_name = camelized_dir + 'Component'
118
+
119
+ Isomorfeus::Installer.create_loader(app_name)
120
+ Isomorfeus::Installer.create_toplevel(app_name, component_name)
121
+ Isomorfeus::Installer.create_component(component_name)
122
+
123
+ Isomorfeus::Installer.create_entrypoint
124
+ Isomorfeus::Installer.create_package_json
125
+ Isomorfeus::Installer.create_gemfile(Isomorfeus::Installer.frameworks[options[:framework]][:gems],
126
+ Isomorfeus::Installer.asset_bundlers[options[:asset_bundler]]&.fetch(:gems))
127
+ Isomorfeus::Installer.create_procfile
128
+
129
+ puts 'Installation finished, make your dreams come true :)'
130
+ puts
131
+ puts 'But first execute in the project directory:'
132
+ puts 'bundle install'
133
+ puts 'yarn install (or npm install)'
134
+ rescue Exception => e
135
+ puts e.backtrace.join("\n")
136
+ puts "Installation failed: #{e.message}"
137
+ end
@@ -0,0 +1,19 @@
1
+ require '../version.rb'
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = 'isomorfeus-installer'
5
+ s.version = Isomorfeus::VERSION
6
+ s.author = 'Jan Biedermann'
7
+ s.email = 'jan@kursator.de'
8
+ s.homepage = 'http://isomorfeus.com'
9
+ s.summary = 'Create new isomorfeus-framework applications with ease.'
10
+ s.description = 'Create new isomorfeus-framework applications with ease.'
11
+
12
+ s.bindir = 'bin'
13
+ s.executables << 'isomorfeus'
14
+ s.files = `git ls-files`.split("\n")
15
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
16
+ s.require_paths = ['lib']
17
+
18
+ s.add_runtime_dependency 'activesupport', '~> 5.0'
19
+ end
@@ -0,0 +1,234 @@
1
+ module Isomorfeus
2
+ module Installer
3
+
4
+ # driver support
5
+
6
+ def self.add_asset_bundler(name, props)
7
+ asset_bundlers[name] = props
8
+ end
9
+
10
+ def self.add_database(name, props)
11
+ databases[name] = props
12
+ end
13
+
14
+ def self.add_framework(name, props)
15
+ frameworks[name] = props
16
+ end
17
+
18
+ def self.add_transport(name, props)
19
+ transports[name] = props
20
+ end
21
+
22
+ def self.asset_bundler
23
+ @asset_bundler
24
+ end
25
+
26
+ def self.asset_bundler=(asset_b)
27
+ @asset_bundler = asset_b
28
+ end
29
+
30
+ def self.asset_bundlers
31
+ @asset_bundlers ||= {}
32
+ end
33
+
34
+ def self.databases
35
+ @databases ||= {}
36
+ end
37
+
38
+ def self.frameworks
39
+ @frameworks ||= {}
40
+ end
41
+
42
+ def self.framework
43
+ @framework
44
+ end
45
+
46
+ def self.framework=(frame_w)
47
+ @framework = frame_w
48
+ end
49
+
50
+ def self.transports
51
+ @transports ||= {}
52
+ end
53
+
54
+ def self.structure=(struct)
55
+ @structure = struct
56
+ end
57
+
58
+ def self.structure
59
+ @structure
60
+ end
61
+
62
+ # installer options and config
63
+
64
+ def self.options
65
+ @options
66
+ end
67
+
68
+ def self.options=(opts)
69
+ @options = opts
70
+ end
71
+
72
+ def self.module_directories
73
+ %w[asset_bundlers databases frameworks transports]
74
+ end
75
+
76
+ # installer paths
77
+ #
78
+ def self.base_path
79
+ @base_path ||= File.realpath(File.join(File.dirname(File.realpath(__FILE__)), 'installer'))
80
+ end
81
+
82
+ def self.templates_path
83
+ @templates_path ||= File.realpath(File.join(File.dirname(File.realpath(__FILE__)), 'installer', 'templates'))
84
+ end
85
+
86
+ # app paths
87
+
88
+ def self.asset_output_path
89
+ File.join('public', 'assets')
90
+ end
91
+
92
+ def self.entrypoint
93
+ 'application.js'
94
+ end
95
+
96
+ def self.entrypoint_path
97
+ if structure == :app_iso
98
+ File.join('app', 'assets', 'javascripts', entrypoint)
99
+ else
100
+ File.join('assets', 'javascripts', entrypoint)
101
+ end
102
+ end
103
+
104
+ def self.isomorfeus_path
105
+ if structure == :app_iso
106
+ File.join('app', 'isomorfeus')
107
+ else
108
+ 'isomorfeus'
109
+ end
110
+ end
111
+
112
+ def self.stylesheets_path
113
+ if structure == :app_iso
114
+ File.join('app', 'assets', 'stylesheets')
115
+ else
116
+ File.join('assets', 'stylesheets')
117
+ end
118
+ end
119
+
120
+ # install helpers
121
+
122
+ def self.create_directories
123
+ if structure == :app_iso
124
+ Dir.mkdir('config') unless Dir.exist?('config')
125
+ Dir.mkdir('app') unless Dir.exist?('app')
126
+ Dir.chdir('app')
127
+ end
128
+ Dir.mkdir('isomorfeus') unless Dir.exist?('isomorfeus')
129
+ Dir.chdir('isomorfeus')
130
+ Dir.mkdir('components') unless Dir.exist?('components')
131
+ if use_database?
132
+ Dir.mkdir('models') unless Dir.exist?('models')
133
+ end
134
+
135
+ Dir.chdir('..') if structure == :app_iso
136
+ Dir.chdir('..')
137
+
138
+ Dir.mkdir('public') unless Dir.exist?('public')
139
+ Dir.mkdir('public/assets') unless Dir.exist?('public/assets')
140
+ Dir.mkdir('assets') unless Dir.exist?('assets')
141
+ Dir.mkdir('assets/javascripts') unless Dir.exist?('assets/javascripts')
142
+ Dir.mkdir('assets/stylesheets') unless Dir.exist?('assets/stylesheets')
143
+ end
144
+
145
+ def self.create_file_from_template(template_path, target_file_path, data_hash)
146
+ template = ERB.new(File.read(File.join(templates_path, template_path), mode: 'r'))
147
+ result = template.result_with_hash(data_hash)
148
+ ext = File.exist?(target_file_path) ? '_new' : ''
149
+ File.write(target_file_path + ext, result, mode: 'w')
150
+ end
151
+
152
+ def self.create_entrypoint
153
+ data_hash = {}
154
+ create_file_from_template(entrypoint + '.erb', entrypoint_path, data_hash)
155
+ end
156
+
157
+ def self.create_gemfile(framework_gems, asset_bundler_gems)
158
+ asset_bundler_gems_result = ''
159
+ asset_bundler_gems.each { |gem| asset_bundler_gems_result << "gem '#{gem[:name]}', '#{gem[:version]}'\n" } if asset_bundler_gems
160
+ if framework_gems == :has_gemfile
161
+ framework_gems_result = File.read('Gemfile')
162
+ File.delete('Gemfile')
163
+ data_hash = { asset_bundler_gems: asset_bundler_gems_result,
164
+ framework_gems: framework_gems_result,
165
+ skip_header: true }
166
+ else
167
+ framework_gems_result = ''
168
+ framework_gems.each { |gem| framework_gems_result << "gem '#{gem[:name]}', '#{gem[:version]}'\n" }
169
+ data_hash = { asset_bundler_gems: asset_bundler_gems_result,
170
+ framework_gems: framework_gems_result }
171
+ end
172
+ create_file_from_template('Gemfile.erb', 'Gemfile', data_hash)
173
+ end
174
+
175
+ def self.create_loader(app_name)
176
+ data_hash = { app_name: app_name }
177
+ iso_entry = File.join(isomorfeus_path, 'isomorfeus_loader.rb')
178
+ create_file_from_template('isomorfeus_loader.rb.erb', iso_entry, data_hash)
179
+ end
180
+
181
+ def self.create_package_json
182
+ npms = ''
183
+ if options.has_key?(:asset_bundler) && asset_bundlers[options[:asset_bundler]].has_key?(:npms)
184
+ asset_bundlers[options[:asset_bundler]][:npms].each do |npm|
185
+ npms << "\"#{npm[:name]}\": \"#{npm[:version]}\",\n"
186
+ end
187
+ end
188
+ data_hash = { application_name: options[:new],
189
+ scripts: asset_bundler.respond_to?(:package_scripts) ? asset_bundler.package_scripts : '',
190
+ npm_packages: npms }
191
+ create_file_from_template('package.json.erb', 'package.json', data_hash)
192
+ end
193
+
194
+ def self.create_procfile
195
+ data_hash = { framework_start_command: framework.start_command,
196
+ asset_bundler_start_command: asset_bundler.start_command }
197
+ create_file_from_template('Procfile.erb', 'Procfile', data_hash)
198
+ end
199
+
200
+ def self.create_component(component_name)
201
+ data_hash = { component_name: component_name }
202
+ create_file_from_template('my_component.rb.erb',File.join(isomorfeus_path, 'components', component_name.underscore + '.rb'), data_hash)
203
+ end
204
+
205
+ def self.create_toplevel(app_name, component_name)
206
+ data_hash = { app_name: app_name, component_name: component_name }
207
+ create_file_from_template('my_app.rb.erb',File.join(isomorfeus_path, 'components', app_name.underscore + '.rb'), data_hash)
208
+ end
209
+
210
+ def self.create_requires
211
+ "require 'bundler/setup'\nBundler.require(:default)\n"
212
+ end
213
+
214
+ # def self.require_record?
215
+ # @require_record
216
+ # end
217
+ #
218
+ # def self.require_operation?
219
+ # @require_operation
220
+ # end
221
+ #
222
+ # def self.require_policy?
223
+ # @require_policy
224
+ # end
225
+ #
226
+ # def self.require_spectre?
227
+ # @require_spectre
228
+ # end
229
+
230
+ def self.use_database?
231
+ options.has_key?(:database) && options[:database] != 'none'
232
+ end
233
+ end
234
+ end
@@ -0,0 +1,103 @@
1
+ module Isomorfeus
2
+ module Installer
3
+ module AssetBundlers
4
+ module OpalWebpackLoader
5
+ TARGETS = %w[development.js production.js]
6
+
7
+ def self.start_command
8
+ 'yarn run start'
9
+ end
10
+
11
+ def self.script_tag(path)
12
+ "owl_script_tag('#{path}')"
13
+ end
14
+
15
+ def self.package_scripts
16
+ <<~SCRIPTS
17
+ "scripts": {
18
+ "start": "bundle exec opal-webpack-compile-server start webpack-dev-server --config #{development_js_path}",
19
+ "build": "bundle exec opal-webpack-compile-server start webpack --config=#{production_js_path}"
20
+ },
21
+ SCRIPTS
22
+ end
23
+
24
+ def self.development_js_path
25
+ if Isomorfeus::Installer.structure == :app_iso
26
+ File.join('config', 'webpack', 'development.js')
27
+ else
28
+ 'development.js'
29
+ end
30
+ end
31
+
32
+ def self.production_js_path
33
+ if Isomorfeus::Installer.structure == :app_iso
34
+ File.join('config', 'webpack', 'production.js')
35
+ else
36
+ 'production.js'
37
+ end
38
+ end
39
+
40
+ def self.asset_bundler_config
41
+ <<~CONFIG
42
+ # OpalWebpackLoader.manifest_path = File.join( 'public', 'assets', 'manifest.json')
43
+ if ENV['PROJECT_ENV'] && ENV['PROJECT_ENV'] != 'development'
44
+ OpalWebpackLoader.client_asset_path = '' # the full path is in the manifest already, like: /packs/website_packs-97fd9c2b7e7bdb112fc1.js
45
+ OpalWebpackLoader.use_manifest = true
46
+ else
47
+ OpalWebpackLoader.client_asset_path = 'http://localhost:3035/assets/'
48
+ OpalWebpackLoader.use_manifest = false
49
+ end
50
+ CONFIG
51
+ end
52
+
53
+ def self.asset_bundler_includes(rails_style = false)
54
+ if rails_style
55
+ "include OpalWebpackLoader::RailsViewHelper"
56
+ else
57
+ "include OpalWebpackLoader::ViewHelper"
58
+ end
59
+ end
60
+
61
+ def self.install(root)
62
+ if Isomorfeus::Installer.structure == :iso
63
+ entrypoint_path = Isomorfeus::Installer.entrypoint_path
64
+ asset_output_path = Isomorfeus::Installer.asset_output_path
65
+ isomorfeus_path = Isomorfeus::Installer.isomorfeus_path
66
+ stylesheets_path = Isomorfeus::Installer.stylesheets_path
67
+ else
68
+ entrypoint_path = File.join('..', '..', Isomorfeus::Installer.entrypoint_path)
69
+ asset_output_path = File.join('..', '..', Isomorfeus::Installer.asset_output_path)
70
+ isomorfeus_path = File.join('..', '..', Isomorfeus::Installer.isomorfeus_path)
71
+ stylesheets_path = File.join('..', '..', Isomorfeus::Installer.stylesheets_path)
72
+ end
73
+
74
+ data_hash = { isomorfeus_path: isomorfeus_path,
75
+ asset_output_path: asset_output_path,
76
+ stylesheets_path: stylesheets_path,
77
+ entrypoint_path: entrypoint_path}
78
+
79
+ if Isomorfeus::Installer.structure == :app_iso
80
+ Dir.mkdir('config') unless Dir.exist?('config')
81
+ Dir.mkdir(File.join('config','webpack')) unless Dir.exist?(File.join('config', 'webpack'))
82
+ TARGETS.each do |target|
83
+ Isomorfeus::Installer.create_file_from_template(File.join('owl', target + '.erb'),
84
+ File.join('config', 'webpack', target), data_hash)
85
+ end
86
+ else
87
+ TARGETS.each do |target_path|
88
+ Isomorfeus::Installer.create_file_from_template(File.join('owl', target_path + '.erb'),
89
+ target_path, data_hash)
90
+ end
91
+ end
92
+ end
93
+ end
94
+ end
95
+ end
96
+ end
97
+
98
+ Isomorfeus::Installer.add_asset_bundler('owl', {
99
+ gems: [ { name: 'opal-webpack-loader', version: '~> 0.5.0' } ],
100
+ npms: [ { name: 'opal-webpack-loader', version: '^0.5.0' } ],
101
+ installer: Isomorfeus::Installer::AssetBundlers::OpalWebpackLoader,
102
+ structure: :iso
103
+ })