superglue 0.40.0 → 0.41.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a72d44f915a1102e37b882a5492a0bae8427c68715acf5a59a809fc70cd47aba
4
- data.tar.gz: 00cb36e39bbc5d47001c3c6ad9a588204e5ccf27deabbce41ddae66a1ba83ac5
3
+ metadata.gz: 20e7f46b274beaffe44eb96b704678e4eb2ebb43c85607a6b4170974525db452
4
+ data.tar.gz: 4e4280233e4e9ed82664aafb9fde2f176471c605142bba3af3326282431e0278
5
5
  SHA512:
6
- metadata.gz: dfa4b3fc28f855eca34ff1533050afd0abf800d7106ffdac25ee44e051e530546990138cae9b33b78526264a9235692a0f878011ea46da84baef8a4278f49280
7
- data.tar.gz: a2198132a6bf2d004745ddb1be7b49de05a21571dd55b507c0d8f09928b06771ebcefb25271b9d84ff9f88303e3f359fea9f6c197ff40db907eb3bf65e75620f
6
+ metadata.gz: ba6cd0dabf868452a22e88533df3b2d76f324078e7d7559917a1b5d5aa181cf3e060ceee6f1ea9271f8a8478fde127636639493914eb38ba6eba583026edeabd
7
+ data.tar.gz: 7ebb6ade8ba3a240013f9c55f2b6527423773d8655be5292aedab05e01af089884f8e6f7e93bbb0e45f27c785aebd20c4153e20e93796da3c88e3f0804bb775a
@@ -1,9 +1,10 @@
1
1
  require 'rails/generators/named_base'
2
2
  require 'rails/generators/resource_helpers'
3
+ require 'rails/version'
3
4
 
4
5
  module Rails
5
6
  module Generators
6
- class SuperglueGenerator < NamedBase # :nodoc:
7
+ class SuperglueGenerator < NamedBase
7
8
  include Rails::Generators::ResourceHelpers
8
9
 
9
10
  source_root File.expand_path('../templates', __FILE__)
@@ -42,13 +43,29 @@ module Rails
42
43
 
43
44
 
44
45
  protected
46
+ def view_path
47
+ if Rails.version >= "7"
48
+ "../views"
49
+ else
50
+ "../../views"
51
+ end
52
+ end
53
+
54
+ def app_js_path
55
+ if Rails.version >= "7"
56
+ "app/javascript/"
57
+ else
58
+ "app/javascript/packs"
59
+ end
60
+ end
61
+
45
62
  def append_mapping(action)
46
- app_js = 'app/javascript/packs/application.js'
63
+ app_js = "#{app_js_path}/application.js"
47
64
 
48
65
  component_name = [plural_table_name, action].map(&:camelcase).join
49
66
 
50
67
  inject_into_file app_js, after: "from '@thoughtbot/superglue'" do
51
- "\nimport #{component_name} from 'views/#{controller_file_path}/#{action}'"
68
+ "\nimport #{component_name} from '#{view_path}/#{controller_file_path}/#{action}'"
52
69
  end
53
70
 
54
71
  inject_into_file app_js, after: 'identifierToComponentMapping = {' do
@@ -1,4 +1,3 @@
1
1
  // Example:
2
2
  //
3
3
  // export const CLEAR_FORM_ERRORS = 'CLEAR_FORM_ERRORS'
4
- export const REHYDRATE = 'persist/REHYDRATE'
@@ -5,8 +5,6 @@ import thunk from 'redux-thunk';
5
5
  import { Provider } from 'react-redux';
6
6
  import { render } from 'react-dom';
7
7
  import { ApplicationBase, fragmentMiddleware } from '@thoughtbot/superglue';
8
- import { persistStore, persistReducer } from 'redux-persist';
9
- import storage from 'redux-persist/lib/storage';
10
8
  import { applicationRootReducer, applicationPagesReducer } from './reducer';
11
9
  import { buildVisitAndRemote } from './application_visit';
12
10
 
@@ -58,57 +56,20 @@ export default class Application extends ApplicationBase {
58
56
  const composeEnhancers =
59
57
  (this.hasWindow && window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__) ||
60
58
  compose;
61
- const reducer = this.wrapWithPersistReducer(
62
- reduceReducers(
59
+ const reducer = reduceReducers(
63
60
  combineReducers({
64
61
  superglue: superglueReducer,
65
62
  pages: reduceReducers(pagesReducer, applicationPagesReducer),
66
63
  }),
67
64
  applicationRootReducer
68
- )
69
65
  );
66
+
70
67
  const store = createStore(
71
68
  reducer,
72
69
  initialState,
73
70
  composeEnhancers(applyMiddleware(thunk, fragmentMiddleware))
74
71
  );
75
72
 
76
- if (this.hasWindow) {
77
- // Persist the store using Redux-Persist
78
- persistStore(store);
79
- }
80
-
81
73
  return store;
82
74
  }
83
-
84
- wrapWithPersistReducer(reducers) {
85
- // Redux Persist settings
86
- // The key is set to the stringified JS asset path to remove the need for
87
- // migrations when hydrating.
88
- if (!this.hasWindow) {
89
- return reducers;
90
- }
91
- const prefix = "superglue";
92
- const persistKey =
93
- prefix +
94
- this.props.initialPage.assets
95
- .filter((asset) => asset.endsWith(".js"))
96
- .join(",");
97
- const persistConfig = {
98
- key: persistKey,
99
- storage,
100
- };
101
-
102
- // Remove older storage items that were used by previous JS assets
103
- if (this.hasWindow) {
104
- const storedKeys = Object.keys(localStorage);
105
- storedKeys.forEach((key) => {
106
- if (key.startsWith(`persist:${prefix}`) && key !== persistKey) {
107
- localStorage.removeItem(key);
108
- }
109
- });
110
- }
111
-
112
- return persistReducer(persistConfig, reducers);
113
- }
114
75
  }
@@ -8,7 +8,8 @@ json.component_identifier local_assigns[:virtual_path_of_template]
8
8
  json.defers json.deferred!
9
9
  json.fragments json.fragments!
10
10
  json.assets [
11
- asset_pack_path('application.js'),
11
+ # Uncomment for webpacker support
12
+ # asset_pack_path('application.js'),
12
13
  asset_path('application.css')
13
14
  ]
14
15
 
@@ -20,9 +20,6 @@
20
20
  // }
21
21
  // }
22
22
 
23
- import {
24
- REHYDRATE,
25
- } from './actions'
26
23
 
27
24
  // The applicationPageReducer is for cross page reducers
28
25
  // Its common to add to this. You'll typically have to pass a pageKey to the
@@ -38,34 +35,9 @@ export const applicationPagesReducer = (state = {}, action) => {
38
35
  }
39
36
 
40
37
  // The applicationRootReducer is for app wide reducers
41
- // Its rare to be adding to this. Included out of the box ix a reducer for
42
- // Redux Persist.
43
- //
44
- // The REHYDRATE reducer is generated by Superglue and is needed to persist state
45
- // on any changes made to the initial state that gets injected into
46
- // window.SUPERGLUE_INITIAL_PAGE_STATE.
38
+ // Its rare to be adding to this.
47
39
  export const applicationRootReducer = (state = {}, action) => {
48
40
  switch(action.type) {
49
- case REHYDRATE: {
50
- if (action.payload) {
51
- const {
52
- pages: hydratedPages
53
- } = action.payload
54
- const { pages } = state
55
- const nextPages = { ...pages, ...hydratedPages }
56
-
57
- for (const key in pages) {
58
- if (pages[key] && hydratedPages[key] &&
59
- pages[key].renderedAt > hydratedPages[key].renderedAt) {
60
- nextPages[key] = { ...pages[key] }
61
- }
62
- }
63
-
64
- return { ...state, pages: nextPages }
65
- } else {
66
- return state
67
- }
68
- }
69
41
  default:
70
42
  return state
71
43
  }
data/lib/install/web.rb CHANGED
@@ -1,6 +1,4 @@
1
- require "webpacker/configuration"
2
-
3
- babel_config = Rails.root.join("babel.config.js")
1
+ require "rails/version"
4
2
 
5
3
  def add_member_methods
6
4
  inject_into_file "app/models/application_record.rb", after: "class ApplicationRecord < ActiveRecord::Base\n" do
@@ -16,35 +14,28 @@ def add_member_methods
16
14
  end
17
15
  end
18
16
 
19
- say "Copying module-resolver preset to your babel.config.js"
20
- resolver_snippet = <<~JAVASCRIPT
21
- [
22
- require('babel-plugin-module-resolver').default, {
23
- "root": ["./app"],
24
- "alias": {
25
- "views": "./app/views",
26
- "components": "./app/components",
27
- "javascript": "./app/javascript"
28
- }
29
- }
30
- ],
31
- JAVASCRIPT
32
- insert_into_file "babel.config.js", resolver_snippet, after: /plugins: \[\n/
17
+ def app_js_path
18
+ if Rails.version >= "7"
19
+ "app/javascript/"
20
+ else
21
+ "app/javascript/packs"
22
+ end
23
+ end
33
24
 
34
- say "Copying application.js file to #{Webpacker.config.source_entry_path}"
35
- copy_file "#{__dir__}/templates/web/application.js", "#{Webpacker.config.source_entry_path}/application.js"
25
+ say "Copying application.js file to #{app_js_path}"
26
+ copy_file "#{__dir__}/templates/web/application.js", "#{app_js_path}/application.js"
36
27
 
37
- say "Copying reducer.js file to #{Webpacker.config.source_entry_path}"
38
- copy_file "#{__dir__}/templates/web/reducer.js", "#{Webpacker.config.source_entry_path}/reducer.js"
28
+ say "Copying reducer.js file to #{app_js_path}"
29
+ copy_file "#{__dir__}/templates/web/reducer.js", "#{app_js_path}/reducer.js"
39
30
 
40
- say "Copying action_creators.js file to #{Webpacker.config.source_entry_path}"
41
- copy_file "#{__dir__}/templates/web/action_creators.js", "#{Webpacker.config.source_entry_path}/action_creators.js"
31
+ say "Copying action_creators.js file to #{app_js_path}"
32
+ copy_file "#{__dir__}/templates/web/action_creators.js", "#{app_js_path}/action_creators.js"
42
33
 
43
- say "Copying actions.js file to #{Webpacker.config.source_entry_path}"
44
- copy_file "#{__dir__}/templates/web/actions.js", "#{Webpacker.config.source_entry_path}/actions.js"
34
+ say "Copying actions.js file to #{app_js_path}"
35
+ copy_file "#{__dir__}/templates/web/actions.js", "#{app_js_path}/actions.js"
45
36
 
46
- say "Copying application_visit.js file to #{Webpacker.config.source_entry_path}"
47
- copy_file "#{__dir__}/templates/web/application_visit.js", "#{Webpacker.config.source_entry_path}/application_visit.js"
37
+ say "Copying application_visit.js file to #{app_js_path}"
38
+ copy_file "#{__dir__}/templates/web/application_visit.js", "#{app_js_path}/application_visit.js"
48
39
 
49
40
  say "Copying Superglue initializer"
50
41
  copy_file "#{__dir__}/templates/web/initializer.rb", "config/initializers/superglue.rb"
@@ -56,11 +47,13 @@ say "Adding required member methods to ApplicationRecord"
56
47
  add_member_methods
57
48
 
58
49
  say "Installing React, Redux, and Superglue"
59
- run "yarn add babel-plugin-module-resolver history html-react-parser react-redux redux-thunk redux redux-persist reduce-reducers immer @thoughtbot/superglue --save"
50
+ run "yarn add history html-react-parser react-redux redux-thunk redux reduce-reducers immer @thoughtbot/superglue --save"
60
51
 
61
- # For newer webpacker
62
- insert_into_file Webpacker.config.config_path, "'app/views', 'app/components'", after: /additional_paths: \[/
63
- # For older webpacker
64
- insert_into_file Webpacker.config.config_path, "'app/views', 'app/components'", after: /resolved_paths: \[/
52
+ if Rails.version < "7"
53
+ # For newer webpacker
54
+ insert_into_file Webpacker.config.config_path, "'app/views', 'app/components'", after: /additional_paths: \[/
55
+ # For older webpacker
56
+ insert_into_file Webpacker.config.config_path, "'app/views', 'app/components'", after: /resolved_paths: \[/
57
+ end
65
58
 
66
- say "Webpacker now supports superglue.js 🎉", :green
59
+ say "Superglue is Installed! 🎉", :green
@@ -1,15 +1,4 @@
1
1
  namespace :superglue do
2
- desc "Verifies if any version of Yarn is installed"
3
- task :verify_yarn do
4
- begin
5
- yarn_version = `yarn --version`
6
- raise Errno::ENOENT if yarn_version.blank?
7
- rescue Errno::ENOENT
8
- $stderr.puts "Yarn not installed. Please download and install Yarn from https://yarnpkg.com/lang/en/docs/install/"
9
- $stderr.puts "Exiting!" && exit!
10
- end
11
- end
12
-
13
2
  desc "Verifies if any version of react is in package.json"
14
3
  task :verify_react do
15
4
  package_json = JSON.parse(File.read(Rails.root.join("package.json")))
@@ -20,20 +9,9 @@ namespace :superglue do
20
9
  end
21
10
  end
22
11
 
23
- desc "Verifies webpacker has been installed"
24
- task "verify_webpacker" do
25
- begin
26
- require "webpacker/configuration"
27
- rescue LoadError
28
- $stderr.puts "Superglue's web install requires webpacker!"
29
- $stderr.puts "https://github.com/rails/webpacker#installation"
30
- $stderr.puts "Exiting!" && exit!
31
- end
32
- end
33
-
34
12
  namespace :install do
35
13
  desc "Install everything needed for superglue web"
36
- task 'web' => ["superglue:verify_webpacker", "webpacker:verify_install", "superglue:verify_react"] do
14
+ task 'web' => ["superglue:verify_react"] do
37
15
  template = File.expand_path("../install/web.rb", __dir__)
38
16
  exec "#{RbConfig.ruby} ./bin/rails app:template LOCATION=#{template}"
39
17
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: superglue
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.40.0
4
+ version: 0.41.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Johny Ho
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-04-03 00:00:00.000000000 Z
11
+ date: 2023-01-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionpack