frails 0.1.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'open3'
4
+
3
5
  install_template_path = File.expand_path('../install/template.rb', __dir__).freeze
4
6
  bin_path = ENV['BUNDLE_BIN'] || './bin'
5
7
 
@@ -8,4 +10,33 @@ namespace :frails do
8
10
  task :install do
9
11
  exec "#{RbConfig.ruby} #{bin_path}/rails app:template LOCATION=#{install_template_path}"
10
12
  end
13
+
14
+ desc 'Compile JavaScript packs using webpack for production with digests'
15
+ task compile: :environment do
16
+ puts 'Compiling Webpack...'
17
+
18
+ ENV['RAILS_ENV'] ||= 'development'
19
+ env = {
20
+ 'RAILS_ASSET_HOST' => ActionController::Base.helpers.compute_asset_host,
21
+ 'RAILS_RELATIVE_URL_ROOT' => ActionController::Base.relative_url_root
22
+ }
23
+
24
+ stdout, sterr, status = Open3.capture3(env, "yarn webpack --env #{ENV['RAILS_ENV']}")
25
+
26
+ if sterr == '' && status.success?
27
+ puts 'Frails successfully compiled 🎉'
28
+ else
29
+ puts "Frails failed compilation\n#{sterr}\n#{stdout}"
30
+ end
31
+ end
32
+ end
33
+
34
+ # Compile packs after we've compiled all other assets during precompilation
35
+ if Rake::Task.task_defined?('assets:precompile')
36
+ Rake::Task['assets:precompile'].enhance do
37
+ Rake::Task['frails:compile'].invoke
38
+ end
39
+ else
40
+ Rake::Task.define_task('assets:precompile' => ['frails:compile'])
41
+ Rake::Task.define_task('assets:clean') # null task just so Heroku builds don't fail
11
42
  end
@@ -0,0 +1,16 @@
1
+ {
2
+ "name": "frails",
3
+ "version": "0.3.0",
4
+ "description": "A Modern [F]ront End on [Rails] and Webpack",
5
+ "main": "index.js",
6
+ "files": [
7
+ "package"
8
+ ],
9
+ "repository": "git@github.com:joelmoss/frails.git",
10
+ "author": "Joel Moss <joel@developwithstyle.com>",
11
+ "license": "MIT",
12
+ "dependencies": {
13
+ "glob": "^7.1.4",
14
+ "lodash.has": "^4.5.2"
15
+ }
16
+ }
@@ -0,0 +1,47 @@
1
+ const glob = require('glob')
2
+ const path = require('path')
3
+ const fs = require('fs')
4
+
5
+ const appPath = path.join(process.cwd(), 'app')
6
+
7
+ // Build entry points for HTML based components (components with an index.html.erb and index.css).
8
+ //
9
+ // NOTE: Adding new files will require a rebuild!
10
+ const buildComponents = () => {
11
+ const result = {}
12
+
13
+ // Find HTML partials and add its corresponding index.css as an entry point if it exists.
14
+ glob.sync(path.join(appPath, 'components/**/_index.html.erb')).forEach(paf => {
15
+ paf = paf.replace('_index.html.erb', 'index.css')
16
+
17
+ if (!fs.existsSync(paf)) return
18
+
19
+ const namespace = path.relative(path.join(appPath), path.dirname(paf))
20
+ const name = path.join(namespace, path.basename(paf, path.extname(paf)))
21
+
22
+ result[name] = paf
23
+ })
24
+
25
+ // Find components with no JSX and HTML index files, and add its corresponding index.css as an
26
+ // entry point if it exists. These will be components that render from within the Ruby class
27
+ // itself.
28
+ glob.sync(path.join(appPath, 'components/**/*_component.rb')).forEach(paf => {
29
+ css_paf = paf.replace('_component.rb', '/index.css')
30
+ html_paf = paf.replace('_component.rb', '/_index.html.erb')
31
+ jsx_paf = paf.replace('_component.rb', '/index.entry.jsx')
32
+
33
+ // Ignore if we have a JSX or HTML file, or no CSS file.
34
+ if (fs.existsSync(jsx_paf) || fs.existsSync(html_paf) || !fs.existsSync(css_paf)) return
35
+
36
+ const namespace = path.relative(path.join(appPath), path.dirname(css_paf))
37
+ const name = path.join(namespace, path.basename(css_paf, path.extname(css_paf)))
38
+
39
+ result[name] = css_paf
40
+ })
41
+
42
+ return result
43
+ }
44
+
45
+ module.exports = {
46
+ entry: { ...buildComponents() }
47
+ }
@@ -0,0 +1,25 @@
1
+ const glob = require("glob");
2
+ const path = require("path");
3
+ const has = require("lodash.has");
4
+
5
+ const appPath = path.join(process.cwd(), "app");
6
+
7
+ // Entry points for side-loaded CSS and JS, which are any .css and .js files that exist alongside
8
+ // the view template. For example, a view template at /app/views/pages/show.html.erb could have a
9
+ // css file alongside it at /app/views/pages/show.css.
10
+ const build = () => {
11
+ const result = {};
12
+
13
+ glob.sync(path.join(appPath, "views/**/*.{css,js}")).forEach(paf => {
14
+ const namespace = path.relative(appPath, path.dirname(paf));
15
+ const name = path.join(namespace, path.basename(paf, path.extname(paf)));
16
+
17
+ has(result, name) ? result[name].push(paf) : (result[name] = [paf]);
18
+ });
19
+
20
+ return result;
21
+ };
22
+
23
+ module.exports = {
24
+ entry: { ...build() }
25
+ };
@@ -0,0 +1,80 @@
1
+ # THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
2
+ # yarn lockfile v1
3
+
4
+
5
+ balanced-match@^1.0.0:
6
+ version "1.0.0"
7
+ resolved "https://registry.yarnpkg.com/balanced-match/-/balanced-match-1.0.0.tgz#89b4d199ab2bee49de164ea02b89ce462d71b767"
8
+ integrity sha1-ibTRmasr7kneFk6gK4nORi1xt2c=
9
+
10
+ brace-expansion@^1.1.7:
11
+ version "1.1.11"
12
+ resolved "https://registry.yarnpkg.com/brace-expansion/-/brace-expansion-1.1.11.tgz#3c7fcbf529d87226f3d2f52b966ff5271eb441dd"
13
+ integrity sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==
14
+ dependencies:
15
+ balanced-match "^1.0.0"
16
+ concat-map "0.0.1"
17
+
18
+ concat-map@0.0.1:
19
+ version "0.0.1"
20
+ resolved "https://registry.yarnpkg.com/concat-map/-/concat-map-0.0.1.tgz#d8a96bd77fd68df7793a73036a3ba0d5405d477b"
21
+ integrity sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=
22
+
23
+ fs.realpath@^1.0.0:
24
+ version "1.0.0"
25
+ resolved "https://registry.yarnpkg.com/fs.realpath/-/fs.realpath-1.0.0.tgz#1504ad2523158caa40db4a2787cb01411994ea4f"
26
+ integrity sha1-FQStJSMVjKpA20onh8sBQRmU6k8=
27
+
28
+ glob@^7.1.4:
29
+ version "7.1.4"
30
+ resolved "https://registry.yarnpkg.com/glob/-/glob-7.1.4.tgz#aa608a2f6c577ad357e1ae5a5c26d9a8d1969255"
31
+ integrity sha512-hkLPepehmnKk41pUGm3sYxoFs/umurYfYJCerbXEyFIWcAzvpipAgVkBqqT9RBKMGjnq6kMuyYwha6csxbiM1A==
32
+ dependencies:
33
+ fs.realpath "^1.0.0"
34
+ inflight "^1.0.4"
35
+ inherits "2"
36
+ minimatch "^3.0.4"
37
+ once "^1.3.0"
38
+ path-is-absolute "^1.0.0"
39
+
40
+ inflight@^1.0.4:
41
+ version "1.0.6"
42
+ resolved "https://registry.yarnpkg.com/inflight/-/inflight-1.0.6.tgz#49bd6331d7d02d0c09bc910a1075ba8165b56df9"
43
+ integrity sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=
44
+ dependencies:
45
+ once "^1.3.0"
46
+ wrappy "1"
47
+
48
+ inherits@2:
49
+ version "2.0.4"
50
+ resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.4.tgz#0fa2c64f932917c3433a0ded55363aae37416b7c"
51
+ integrity sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==
52
+
53
+ lodash.has@^4.5.2:
54
+ version "4.5.2"
55
+ resolved "https://registry.yarnpkg.com/lodash.has/-/lodash.has-4.5.2.tgz#d19f4dc1095058cccbe2b0cdf4ee0fe4aa37c862"
56
+ integrity sha1-0Z9NwQlQWMzL4rDN9O4P5Ko3yGI=
57
+
58
+ minimatch@^3.0.4:
59
+ version "3.0.4"
60
+ resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-3.0.4.tgz#5166e286457f03306064be5497e8dbb0c3d32083"
61
+ integrity sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==
62
+ dependencies:
63
+ brace-expansion "^1.1.7"
64
+
65
+ once@^1.3.0:
66
+ version "1.4.0"
67
+ resolved "https://registry.yarnpkg.com/once/-/once-1.4.0.tgz#583b1aa775961d4b113ac17d9c50baef9dd76bd1"
68
+ integrity sha1-WDsap3WWHUsROsF9nFC6753Xa9E=
69
+ dependencies:
70
+ wrappy "1"
71
+
72
+ path-is-absolute@^1.0.0:
73
+ version "1.0.1"
74
+ resolved "https://registry.yarnpkg.com/path-is-absolute/-/path-is-absolute-1.0.1.tgz#174b9268735534ffbc7ace6bf53a5a9e1b5c5f5f"
75
+ integrity sha1-F0uSaHNVNP+8es5r9TpanhtcX18=
76
+
77
+ wrappy@1:
78
+ version "1.0.2"
79
+ resolved "https://registry.yarnpkg.com/wrappy/-/wrappy-1.0.2.tgz#b5243d8f3ec1aa35f1364605bc0d1036e30ab69f"
80
+ integrity sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=
metadata CHANGED
@@ -1,85 +1,57 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: frails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joel Moss
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-04-04 00:00:00.000000000 Z
11
+ date: 2019-10-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: rack-proxy
14
+ name: nokogiri
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 0.6.5
19
+ version: 1.10.4
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: 0.6.5
26
+ version: 1.10.4
27
27
  - !ruby/object:Gem::Dependency
28
- name: railties
28
+ name: rack-proxy
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: '5.2'
33
+ version: 0.6.5
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: '5.2'
41
- - !ruby/object:Gem::Dependency
42
- name: bundler
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - "~>"
46
- - !ruby/object:Gem::Version
47
- version: '2.0'
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - "~>"
53
- - !ruby/object:Gem::Version
54
- version: '2.0'
55
- - !ruby/object:Gem::Dependency
56
- name: minitest
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - "~>"
60
- - !ruby/object:Gem::Version
61
- version: '5.0'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - "~>"
67
- - !ruby/object:Gem::Version
68
- version: '5.0'
40
+ version: 0.6.5
69
41
  - !ruby/object:Gem::Dependency
70
- name: rake
42
+ name: rails
71
43
  requirement: !ruby/object:Gem::Requirement
72
44
  requirements:
73
- - - "~>"
45
+ - - ">="
74
46
  - !ruby/object:Gem::Version
75
- version: '10.0'
76
- type: :development
47
+ version: '6.0'
48
+ type: :runtime
77
49
  prerelease: false
78
50
  version_requirements: !ruby/object:Gem::Requirement
79
51
  requirements:
80
- - - "~>"
52
+ - - ">="
81
53
  - !ruby/object:Gem::Version
82
- version: '10.0'
54
+ version: '6.0'
83
55
  description:
84
56
  email:
85
57
  - joel@developwithstyle.com
@@ -98,18 +70,35 @@ files:
98
70
  - Rakefile
99
71
  - bin/console
100
72
  - bin/setup
73
+ - bin/test
101
74
  - frails.gemspec
75
+ - index.js
102
76
  - lib/frails.rb
77
+ - lib/frails/component.rb
78
+ - lib/frails/component/abstract_component.rb
79
+ - lib/frails/component/component_renderer.rb
80
+ - lib/frails/component/plain_component.rb
81
+ - lib/frails/component/react_component.rb
82
+ - lib/frails/component/react_component_renderer.rb
83
+ - lib/frails/component/renderer_concerns.rb
103
84
  - lib/frails/dev_server.rb
104
85
  - lib/frails/dev_server_proxy.rb
105
86
  - lib/frails/helper.rb
106
- - lib/frails/instance.rb
87
+ - lib/frails/log_subscriber.rb
107
88
  - lib/frails/manifest.rb
89
+ - lib/frails/manifest_manager.rb
90
+ - lib/frails/monkey/action_view/abstract_renderer.rb
91
+ - lib/frails/monkey/action_view/partial_renderer.rb
92
+ - lib/frails/monkey/action_view/renderer.rb
93
+ - lib/frails/monkey/action_view/template_renderer.rb
108
94
  - lib/frails/railtie.rb
109
- - lib/frails/server_manifest.rb
110
95
  - lib/frails/version.rb
111
96
  - lib/install/template.rb
112
97
  - lib/tasks/frails.rake
98
+ - package.json
99
+ - package/components.js
100
+ - package/side_load.js
101
+ - yarn.lock
113
102
  homepage: https://github.com/joelmoss/frails
114
103
  licenses: []
115
104
  metadata:
@@ -135,5 +124,5 @@ requirements: []
135
124
  rubygems_version: 3.0.3
136
125
  signing_key:
137
126
  specification_version: 4
138
- summary: A Modern Front End on Rails and Webpack
127
+ summary: A Modern [F]ront End on [Rails] and Webpack
139
128
  test_files: []
@@ -1,11 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class Frails::Instance
4
- def dev_server
5
- @dev_server ||= Frails::DevServer.new
6
- end
7
-
8
- def manifest
9
- @manifest ||= Frails::Manifest.new
10
- end
11
- end
@@ -1,7 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class Frails::ServerManifest < Frails::Manifest
4
- def manifest_path
5
- @manifest_path ||= Rails.root.join('public', 'packs', 'server-manifest.json')
6
- end
7
- end