cm-admin 3.0.16 → 4.1.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: f3debddacbd593b7ae649770a5237ea0af2f7c3481cfdb75f93adf833345c702
4
- data.tar.gz: f2d63c47f670a66b78241fa45398edfac023c36acc89d079065734319e72bccd
3
+ metadata.gz: 19fd7ec610f3f8b02370549dfac1e314ece5c44f57466727666058c83f4f5905
4
+ data.tar.gz: fe9a9c73585456a365364b1e44305e229a242a19bf832da849117bc1fb3f47a6
5
5
  SHA512:
6
- metadata.gz: 7d04f7523d8e25ef11d45025a4e8adbb3f583c4d1c5b8e353cd30a7f0d055a79280cfe081a1120721f83377476ba074334d9ec01e822595b372e1c78f2c64217
7
- data.tar.gz: 76b3873cc8a0bea1c6ec2bd435538c9e06304310000a77d7380e2fc9bbb46232734a6d1881ccb566ca7aa135679606dea7b374777b292092f1747a2736cc8adc
6
+ metadata.gz: 8fef781ecc5b1bfc28f04fdc4bbdea3c6463cddb39aa4cddddfcb84d359af8528ce77c8f33eb98a505e95214c468883c89185f61cb7b320b614c91813f1bef10
7
+ data.tar.gz: '068f711e3e85d6019af1d40256c1bff7a11fd69016e11be5285e48598d13dd652d1ae7447cae179279063f2f7edd1f85398f4a140a83bf41bc494c4332d1318c'
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- cm-admin (3.0.16)
4
+ cm-admin (4.1.0)
5
5
  caxlsx_rails
6
6
  cocoon (~> 1.2.15)
7
7
  csv-importer (~> 0.8.2)
@@ -9,9 +9,8 @@ PATH
9
9
  local_time (~> 3.0.2)
10
10
  pagy (~> 4.11.0)
11
11
  pundit (~> 2.2.0)
12
- rails (>= 6.0)
13
- slim (~> 4.1.0)
14
- webpacker (~> 5.4.3)
12
+ rails (>= 7.0)
13
+ slim (>= 4.1.0)
15
14
 
16
15
  GEM
17
16
  remote: https://rubygems.org/
@@ -178,8 +177,6 @@ GEM
178
177
  activesupport (>= 3.0.0)
179
178
  racc (1.8.1)
180
179
  rack (3.1.8)
181
- rack-proxy (0.7.7)
182
- rack
183
180
  rack-session (2.0.0)
184
181
  rack (>= 3.0.0)
185
182
  rack-test (2.1.0)
@@ -258,7 +255,6 @@ GEM
258
255
  rubocop-ast (>= 1.31.1, < 2.0)
259
256
  ruby-progressbar (1.13.0)
260
257
  rubyzip (2.3.2)
261
- semantic_range (3.0.0)
262
258
  slim (4.1.0)
263
259
  temple (>= 0.7.6, < 0.9)
264
260
  tilt (>= 2.0.6, < 2.1)
@@ -275,11 +271,6 @@ GEM
275
271
  axiom-types (~> 0.1)
276
272
  coercible (~> 1.0)
277
273
  descendants_tracker (~> 0.0, >= 0.0.3)
278
- webpacker (5.4.4)
279
- activesupport (>= 5.2)
280
- rack-proxy (>= 0.6.1)
281
- railties (>= 5.2)
282
- semantic_range (>= 2.3.0)
283
274
  webrick (1.8.2)
284
275
  websocket-driver (0.7.6)
285
276
  websocket-extensions (>= 0.1.0)
@@ -6,12 +6,19 @@ module CmAdmin
6
6
  helper CmAdmin::ViewHelpers
7
7
 
8
8
  skip_before_action :verify_authenticity_token, only: :reset_sort_columns
9
+ before_action :set_current_user_permission
10
+
11
+
12
+ def set_current_user_permission
13
+ CmCurrent.user_permissions = Current.user.cm_role.cm_permissions if Current.user.cm_role.present?
14
+ end
9
15
 
10
16
  def cm_index(params)
11
17
  @current_action = CmAdmin::Models::Action.find_by(@model, name: 'index')
12
18
  # Based on the params the filter and pagination object to be set
13
19
  authorize @ar_object, policy_class: "CmAdmin::#{controller_name.classify}Policy".constantize if defined? "CmAdmin::#{controller_name.classify}Policy".constantize
14
20
  records = "CmAdmin::#{@model.name}Policy::IndexScope".constantize.new(Current.user, @model.name.constantize).resolve
21
+ records = records.includes(@current_action.eager_load_associations) if @current_action.eager_load_associations.present?
15
22
  records = apply_scopes(records)
16
23
  @ar_object = if %w[table card].include?(params[:view_type]) || %i[table card].include?(@current_action.view_type)
17
24
  filter_by(params, records, filter_params: @model.filter_params(params))
@@ -163,6 +170,7 @@ module CmAdmin
163
170
  @current_action = @action
164
171
  if @action.parent == 'index'
165
172
  records = apply_scopes(records)
173
+ records = records.includes(@model.eager_load_associations) if @model.eager_load_associations.present?
166
174
  @ar_object = filter_by(params, records, filter_params: @model.filter_params(params))
167
175
  else
168
176
  resource_identifier
@@ -304,6 +312,7 @@ module CmAdmin
304
312
  return @ar_object unless @current_action.child_records
305
313
 
306
314
  child_records = @ar_object.send(@current_action.child_records)
315
+ child_records = child_records.includes(@current_action.eager_load_associations) if @current_action.eager_load_associations.present?
307
316
  child_records = apply_scopes(child_records)
308
317
  @reflection = @model.ar_model.reflect_on_association(@current_action.child_records)
309
318
  @associated_model = if @reflection.klass.column_names.include?('type')
@@ -1,10 +1,5 @@
1
1
  module CmAdmin
2
2
  module ApplicationHelper
3
-
4
- def current_webpacker_instance
5
- CmAdmin.webpacker
6
- end
7
-
8
3
  # Allow if policy is not defined.
9
4
  def has_valid_policy(ar_object, action_name)
10
5
  if ar_object.instance_of?(OpenStruct) && ar_object&.parent_record.present? && ar_object&.associated_model.present?
@@ -0,0 +1,14 @@
1
+ module CmAdmin
2
+ module PermissionHelper
3
+
4
+ # Used in mode.rb while creating policies.
5
+ def has_access_to?(ar_model, action)
6
+ find_permission_by(ar_model, action).present?
7
+ end
8
+
9
+ # Checks if the current user permission has access to the specified model and action
10
+ def find_permission_by(ar_model, action)
11
+ CmCurrent.user_permissions.find { |permission| permission.ar_model_name == ar_model.name && permission.action_name == action.name }
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,3 @@
1
+ class CmCurrent < ActiveSupport::CurrentAttributes
2
+ attribute :user_permissions
3
+ end
@@ -19,4 +19,5 @@ class CmPermission < ApplicationRecord
19
19
  CmPermission.where(action_name: 'update', ar_model_name:, cm_role_id:).first&.destroy
20
20
  end
21
21
  end
22
+
22
23
  end
@@ -20,17 +20,11 @@ html
20
20
  meta[name="viewport" content="width=device-width,initial-scale=1"]
21
21
  = csrf_meta_tags
22
22
  = csp_meta_tag
23
- = stylesheet_link_tag 'cm_admin/cm_admin', media: 'all', 'data-turbolinks-track': 'reload'
24
- - if CmAdmin::VersionManager.use_webpacker?
25
- = stylesheet_pack_tag 'cm_admin/application', 'data-turbolinks-track': 'reload'
26
- = javascript_pack_tag 'cm_admin/application', 'data-turbolinks-track': 'reload'
27
- script src="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/js/select2.min.js"
28
- - elsif CmAdmin::VersionManager.use_importmap?
29
- = javascript_importmap_tags
30
- = javascript_import_module_tag "cm_admin/application"
31
- = javascript_include_tag 'cm_admin/custom', 'data-turbolinks-track': 'reload'
23
+ = stylesheet_link_tag 'cm_admin/cm_admin', media: 'all', 'data-turbo-track': 'reload'
24
+ = javascript_importmap_tags
25
+ = javascript_import_module_tag "cm_admin/application"
32
26
  script src="https://kit.fontawesome.com/9c93dde7a7.js" data-mutate-approach="sync"
33
- = stylesheet_link_tag 'cm_admin/custom', media: 'all', 'data-turbolinks-track': 'reload'
27
+ = stylesheet_link_tag 'cm_admin/custom', media: 'all', 'data-turbo-track': 'reload'
34
28
  link href="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/css/select2.min.css" rel="stylesheet" /
35
29
 
36
30
  script src="https://raw.githack.com/SortableJS/Sortable/master/Sortable.js"
@@ -6,10 +6,7 @@ html
6
6
  meta[name="viewport" content="width=device-width,initial-scale=1"]
7
7
  = csrf_meta_tags
8
8
  = csp_meta_tag
9
- = stylesheet_link_tag 'cm_admin/cm_admin', media: 'all', 'data-turbolinks-track': 'reload'
10
- - if CmAdmin::VersionManager.rails6?
11
- = stylesheet_pack_tag 'cm_admin/application', 'data-turbolinks-track': 'reload'
12
- = javascript_pack_tag 'cm_admin/application', 'data-turbolinks-track': 'reload'
9
+ = stylesheet_link_tag 'cm_admin/cm_admin', media: 'all', 'data-turbo-track': 'reload'
13
10
  body
14
11
  - flash.each do |type, msg|
15
12
  .alert class="alert-#{type}"
data/cm_admin.gemspec CHANGED
@@ -34,8 +34,7 @@ Gem::Specification.new do |spec|
34
34
  spec.add_runtime_dependency 'local_time', '~> 3.0.2'
35
35
  spec.add_runtime_dependency 'pagy', '~> 4.11.0'
36
36
  spec.add_runtime_dependency 'pundit', '~> 2.2.0'
37
- spec.add_runtime_dependency('rails', '>= 6.0')
38
- spec.add_runtime_dependency 'slim', '~> 4.1.0'
39
- spec.add_runtime_dependency 'webpacker', '~> 5.4.3'
37
+ spec.add_runtime_dependency 'rails', '>= 7.0'
38
+ spec.add_runtime_dependency 'slim', '>= 4.1.0'
40
39
  spec.add_dependency 'importmap-rails'
41
40
  end
@@ -6,56 +6,31 @@ module CmAdmin
6
6
  class Engine < Rails::Engine
7
7
  isolate_namespace CmAdmin
8
8
 
9
- config.app_middleware.use(
10
- Rack::Static,
11
- # note! this varies from the webpacker/engine documentation
12
- urls: ["/cm-admin-packs"], root: CmAdmin::Engine.root.join("public")
13
- )
14
-
15
9
  initializer 'RailsAdmin precompile hook', group: :all do |app|
16
- app.config.assets.precompile += %w(
10
+ app.config.assets.precompile += %w[
17
11
  cm_admin/cm_admin.css
18
12
  cm_admin/custom.js
19
13
  cm_admin/custom.css
20
- )
14
+ ]
21
15
  end
22
16
 
23
17
  def mount_path
24
18
  CmAdmin::Engine.routes.find_script_name({})
25
19
  end
26
20
 
27
- if VersionManager.rails6?
28
- initializer "webpacker.proxy" do |app|
29
- insert_middleware = begin
30
- CmAdmin.webpacker.config.dev_server.present?
31
- rescue
32
- nil
33
- end
34
- next unless insert_middleware
21
+ initializer 'cm_admin.importmap', before: 'importmap' do |app|
22
+ # NOTE: this will add pins from this engine to the main app
23
+ # https://github.com/rails/importmap-rails#composing-import-maps
24
+ app.config.importmap.paths << root.join('config/importmap.rb')
35
25
 
36
- app.middleware.insert_before(
37
- 0, Webpacker::DevServerProxy, # "Webpacker::DevServerProxy" if Rails version < 5
38
- ssl_verify_none: true,
39
- webpacker: CmAdmin.webpacker
40
- )
41
- end
42
- elsif VersionManager.rails7?
43
- initializer "cm_admin.importmap", before: "importmap" do |app|
44
- # NOTE: this will add pins from this engine to the main app
45
- # https://github.com/rails/importmap-rails#composing-import-maps
46
- app.config.importmap.paths << root.join("config/importmap.rb")
47
-
48
- # NOTE: something about cache; I did not look into it.
49
- # https://github.com/rails/importmap-rails#sweeping-the-cache-in-development-and-test
50
- app.config.importmap.cache_sweepers << root.join("app/assets/javascripts")
51
- end
52
-
53
- # NOTE: add engine manifest to precompile assets in production
54
- initializer "cm_admin.assets" do |app|
55
- app.config.assets.precompile += %w[cm_admin_manifest]
56
- end
26
+ # NOTE: something about cache; I did not look into it.
27
+ # https://github.com/rails/importmap-rails#sweeping-the-cache-in-development-and-test
28
+ app.config.importmap.cache_sweepers << root.join('app/assets/javascripts')
57
29
  end
58
30
 
59
-
31
+ # NOTE: add engine manifest to precompile assets in production
32
+ initializer 'cm_admin.assets' do |app|
33
+ app.config.assets.precompile += %w[cm_admin_manifest]
34
+ end
60
35
  end
61
36
  end
@@ -188,12 +188,14 @@ module CmAdmin
188
188
  def define_pundit_policy(ar_model)
189
189
  if $available_actions.present?
190
190
  klass = Class.new(ApplicationPolicy) do
191
+ include CmAdmin::PermissionHelper
191
192
  $available_actions.each do |action|
192
193
  define_method "#{action.name}?".to_sym do
193
194
  return false unless Current.user.respond_to?(:cm_role_id)
194
195
  return false if Current.user.cm_role.nil?
196
+ return false if CmCurrent.user_permissions.empty?
195
197
 
196
- Current.user.cm_role.cm_permissions.where(action_name: action.name, ar_model_name: ar_model.name).present?
198
+ has_access_to?(ar_model, action)
197
199
  end
198
200
  end
199
201
  end
@@ -211,7 +213,7 @@ module CmAdmin
211
213
 
212
214
  define_method :resolve do
213
215
  # action_name = Current.request_params.dig("action")
214
- permission = Current.user.cm_role.cm_permissions.find_by(action_name: action.name, ar_model_name: ar_model.name)
216
+ permission = find_permission_by(ar_model, action)
215
217
  if permission.present? && permission.scope_name.present?
216
218
  scope.send(permission.scope_name)
217
219
  else
@@ -7,7 +7,7 @@ module CmAdmin
7
7
  attr_accessor :name, :display_name, :verb, :layout_type, :layout, :partial, :path, :page_title, :page_description,
8
8
  :child_records, :is_nested_field, :nested_table_name, :parent, :display_if, :route_type, :code_block,
9
9
  :display_type, :action_type, :redirection_url, :sort_direction, :sort_column, :icon_name, :scopes, :view_type,
10
- :kanban_attr, :model_name, :redirect_to, :execution_mode
10
+ :kanban_attr, :model_name, :redirect_to, :execution_mode, :eager_load_associations
11
11
 
12
12
  VALID_SORT_DIRECTION = Set[:asc, :desc].freeze
13
13
 
@@ -41,6 +41,7 @@ module CmAdmin
41
41
  self.route_type = nil
42
42
  self.display_type = nil
43
43
  self.view_type = :table
44
+ self.eager_load_associations = []
44
45
  self.kanban_attr = {}
45
46
  end
46
47
 
@@ -402,6 +402,17 @@ module CmAdmin
402
402
  @default_sort_column = default_column[:column]
403
403
  @default_sort_direction = default_column[:default_direction] if default_column[:default_direction].present?
404
404
  end
405
+
406
+ # Configure Eager load associations for action
407
+ # This will help us avoid N+1 queries
408
+ #
409
+ # @example Eager load associations
410
+ # eager_load_assocations [:association_name]
411
+ # eager_load_assocations [:constant]
412
+ #
413
+ def eager_load_associations(associations=[])
414
+ @current_action.eager_load_associations = associations if @current_action
415
+ end
405
416
  end
406
417
  end
407
418
  end
@@ -1,3 +1,3 @@
1
1
  module CmAdmin
2
- VERSION = '3.0.16'
2
+ VERSION = '4.1.0'
3
3
  end
@@ -1,20 +1,16 @@
1
1
  module CmAdmin
2
2
  class VersionManager
3
3
  class << self
4
- def rails6?
5
- Rails::VERSION::MAJOR == 6
6
- end
7
-
8
4
  def rails7?
9
5
  Rails::VERSION::MAJOR == 7
10
6
  end
11
7
 
12
- def use_importmap?
13
- rails7? && File.exist?('config/importmap.rb')
8
+ def rails8?
9
+ Rails::VERSION::MAJOR == 8
14
10
  end
15
11
 
16
- def use_webpacker?
17
- rails6? && defined?(Webpacker) == 'constant'
12
+ def use_importmap?
13
+ (rails7? || rails8?) && File.exist?('config/importmap.rb')
18
14
  end
19
15
  end
20
16
  end
data/lib/cm_admin.rb CHANGED
@@ -16,13 +16,6 @@ module CmAdmin
16
16
  @@cm_admin_models ||= []
17
17
 
18
18
  class << self
19
- def webpacker
20
- @webpacker ||= ::Webpacker::Instance.new(
21
- root_path: CmAdmin::Engine.root,
22
- config_path: CmAdmin::Engine.root.join('config', 'webpacker.yml')
23
- )
24
- end
25
-
26
19
  def configure
27
20
  # instance_eval(&block)
28
21
  @config ||= Configuration.new
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cm-admin
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.16
4
+ version: 4.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael
@@ -14,7 +14,7 @@ authors:
14
14
  autorequire:
15
15
  bindir: exe
16
16
  cert_chain: []
17
- date: 2024-11-25 00:00:00.000000000 Z
17
+ date: 2024-11-26 00:00:00.000000000 Z
18
18
  dependencies:
19
19
  - !ruby/object:Gem::Dependency
20
20
  name: caxlsx_rails
@@ -106,42 +106,28 @@ dependencies:
106
106
  requirements:
107
107
  - - ">="
108
108
  - !ruby/object:Gem::Version
109
- version: '6.0'
109
+ version: '7.0'
110
110
  type: :runtime
111
111
  prerelease: false
112
112
  version_requirements: !ruby/object:Gem::Requirement
113
113
  requirements:
114
114
  - - ">="
115
115
  - !ruby/object:Gem::Version
116
- version: '6.0'
116
+ version: '7.0'
117
117
  - !ruby/object:Gem::Dependency
118
118
  name: slim
119
119
  requirement: !ruby/object:Gem::Requirement
120
120
  requirements:
121
- - - "~>"
121
+ - - ">="
122
122
  - !ruby/object:Gem::Version
123
123
  version: 4.1.0
124
124
  type: :runtime
125
125
  prerelease: false
126
126
  version_requirements: !ruby/object:Gem::Requirement
127
127
  requirements:
128
- - - "~>"
128
+ - - ">="
129
129
  - !ruby/object:Gem::Version
130
130
  version: 4.1.0
131
- - !ruby/object:Gem::Dependency
132
- name: webpacker
133
- requirement: !ruby/object:Gem::Requirement
134
- requirements:
135
- - - "~>"
136
- - !ruby/object:Gem::Version
137
- version: 5.4.3
138
- type: :runtime
139
- prerelease: false
140
- version_requirements: !ruby/object:Gem::Requirement
141
- requirements:
142
- - - "~>"
143
- - !ruby/object:Gem::Version
144
- version: 5.4.3
145
131
  - !ruby/object:Gem::Dependency
146
132
  name: importmap-rails
147
133
  requirement: !ruby/object:Gem::Requirement
@@ -358,10 +344,9 @@ files:
358
344
  - app/controllers/cm_admin/static_controller.rb
359
345
  - app/helpers/cm_admin/application_helper.rb
360
346
  - app/helpers/cm_admin/custom_helper.rb
361
- - app/javascript/packs/cm_admin/application.js
362
- - app/javascript/packs/cm_admin/scaffolds.js
363
- - app/javascript/stylesheets/cm_admin/application.scss
347
+ - app/helpers/cm_admin/permission_helper.rb
364
348
  - app/jobs/file_import_processor_job.rb
349
+ - app/models/cm_current.rb
365
350
  - app/models/cm_permission.rb
366
351
  - app/models/cm_role.rb
367
352
  - app/models/concerns/cm_admin/bulk_action_processor.rb
@@ -413,25 +398,16 @@ files:
413
398
  - bin/console
414
399
  - bin/importmap
415
400
  - bin/setup
416
- - bin/webpack
417
- - bin/webpack-dev-server
418
401
  - cm_admin.gemspec
419
- - config/.DS_Store
420
402
  - config/importmap.rb
421
403
  - config/initializers/active_record_extension.rb
422
404
  - config/routes.rb
423
- - config/webpack/development.js
424
- - config/webpack/environment.js
425
- - config/webpack/production.js
426
- - config/webpack/test.js
427
- - config/webpacker.yml
428
405
  - docs/AddingAlert.md
429
406
  - docs/CustomFilterMethod.md
430
407
  - docs/ListingSelectTwoAjax.md
431
408
  - docs/ListingSelectTwoItems.md
432
409
  - docs/RoleManagement.md
433
410
  - docs/ShowHideContent.md
434
- - lib/.DS_Store
435
411
  - lib/cm-admin.rb
436
412
  - lib/cm_admin.rb
437
413
  - lib/cm_admin/configuration.rb
@@ -498,7 +474,6 @@ files:
498
474
  - lib/generators/cm_admin/templates/graphql/objects/base/paging_type.rb
499
475
  - lib/generators/cm_admin/templates/graphql/queries/base_query.rb
500
476
  - lib/generators/cm_admin/templates/policy.rb
501
- - lib/tasks/webpack_install.rake
502
477
  - package-lock.json
503
478
  - package.json
504
479
  - postcss.config.js
@@ -1,27 +0,0 @@
1
- require("@rails/ujs").start();
2
- require("turbolinks").start();
3
- require("@rails/activestorage").start();
4
- require("stylesheets/cm_admin/application");
5
- require("jquery");
6
- require("moment");
7
- require("bootstrap");
8
- require("flatpickr");
9
- require("jgrowl");
10
- require("trix");
11
- require("./scaffolds.js");
12
- require("/app/assets/javascripts/cm_admin/shared_scaffolds.js");
13
- require("/app/assets/javascripts/cm_admin/form_validation.js");
14
- require("/app/assets/javascripts/cm_admin/quick_search.js");
15
- require("/app/assets/javascripts/cm_admin/filters.js");
16
- require("/app/assets/javascripts/cm_admin/exports.js");
17
- require("/app/assets/javascripts/cm_admin/bulk_actions.js");
18
-
19
- import jQuery from "jquery";
20
- import LocalTime from "local-time";
21
- window.$ = jQuery;
22
- window.jQuery = jQuery;
23
-
24
- LocalTime.start();
25
- require("@nathanvda/cocoon");
26
- import "@fortawesome/fontawesome-free/css/all";
27
- import "daterangepicker";
@@ -1,5 +0,0 @@
1
- import { initializeComponents } from "../../../assets/javascripts/cm_admin/shared_scaffolds";
2
-
3
- $(document).on('turbolinks:load', function () {
4
- initializeComponents();
5
- });
@@ -1,3 +0,0 @@
1
- @import "bootstrap/scss/bootstrap";
2
- @import "flatpickr/dist/flatpickr";
3
- @import "../../../../node_modules/daterangepicker/daterangepicker.css";
data/bin/webpack DELETED
@@ -1,18 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- ENV['RAILS_ENV'] ||= ENV['RACK_ENV'] || 'development'
4
- ENV['NODE_ENV'] ||= 'development'
5
-
6
- require 'pathname'
7
- ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile',
8
- Pathname.new(__FILE__).realpath)
9
-
10
- require 'bundler/setup'
11
-
12
- require 'webpacker'
13
- require 'webpacker/webpack_runner'
14
-
15
- APP_ROOT = File.expand_path('..', __dir__)
16
- Dir.chdir(APP_ROOT) do
17
- Webpacker::WebpackRunner.run(ARGV)
18
- end
@@ -1,18 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- ENV['RAILS_ENV'] ||= ENV['RACK_ENV'] || 'development'
4
- ENV['NODE_ENV'] ||= 'development'
5
-
6
- require 'pathname'
7
- ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile',
8
- Pathname.new(__FILE__).realpath)
9
-
10
- require 'bundler/setup'
11
-
12
- require 'webpacker'
13
- require 'webpacker/dev_server_runner'
14
-
15
- APP_ROOT = File.expand_path('..', __dir__)
16
- Dir.chdir(APP_ROOT) do
17
- Webpacker::DevServerRunner.run(ARGV)
18
- end
data/config/.DS_Store DELETED
Binary file
@@ -1,5 +0,0 @@
1
- process.env.NODE_ENV = process.env.NODE_ENV || 'development'
2
-
3
- const environment = require('./environment')
4
-
5
- module.exports = environment.toWebpackConfig()
@@ -1,13 +0,0 @@
1
- const { environment } = require('@rails/webpacker')
2
-
3
- const webpack = require('webpack')
4
- environment.plugins.prepend('Provide',
5
- new webpack.ProvidePlugin({
6
- $: 'jquery',
7
- jQuery: 'jquery',
8
- moment: 'moment',
9
- Popper: ['popper.js', 'default']
10
- })
11
- )
12
-
13
- module.exports = environment
@@ -1,5 +0,0 @@
1
- process.env.NODE_ENV = process.env.NODE_ENV || 'production'
2
-
3
- const environment = require('./environment')
4
-
5
- module.exports = environment.toWebpackConfig()
@@ -1,5 +0,0 @@
1
- process.env.NODE_ENV = process.env.NODE_ENV || 'development'
2
-
3
- const environment = require('./environment')
4
-
5
- module.exports = environment.toWebpackConfig()
data/config/webpacker.yml DELETED
@@ -1,92 +0,0 @@
1
- # Note: You must restart bin/webpack-dev-server for changes to take effect
2
-
3
- default: &default
4
- source_path: app/javascript
5
- source_entry_path: packs
6
- public_root_path: public
7
- public_output_path: cm-admin-packs
8
- cache_path: tmp/cache/webpacker
9
- webpack_compile_output: true
10
-
11
- # Additional paths webpack should lookup modules
12
- # ['app/assets', 'engine/foo/app/assets']
13
- additional_paths: ['app/assets']
14
-
15
- # Reload manifest.json on all requests so we reload latest compiled packs
16
- cache_manifest: false
17
-
18
- # Extract and emit a css file
19
- extract_css: false
20
-
21
- static_assets_extensions:
22
- - .jpg
23
- - .jpeg
24
- - .png
25
- - .gif
26
- - .tiff
27
- - .ico
28
- - .svg
29
- - .eot
30
- - .otf
31
- - .ttf
32
- - .woff
33
- - .woff2
34
-
35
- extensions:
36
- - .mjs
37
- - .js
38
- - .sass
39
- - .scss
40
- - .css
41
- - .module.sass
42
- - .module.scss
43
- - .module.css
44
- - .png
45
- - .svg
46
- - .gif
47
- - .jpeg
48
- - .jpg
49
-
50
- development:
51
- <<: *default
52
- compile: true
53
-
54
- # Reference: https://webpack.js.org/configuration/dev-server/
55
- dev_server:
56
- https: false
57
- host: localhost
58
- port: 3035
59
- public: localhost:3035
60
- hmr: false
61
- # Inline should be set to true if using HMR
62
- inline: true
63
- overlay: true
64
- compress: true
65
- disable_host_check: true
66
- use_local_ip: false
67
- quiet: false
68
- pretty: false
69
- headers:
70
- 'Access-Control-Allow-Origin': '*'
71
- watch_options:
72
- ignored: '**/node_modules/**'
73
-
74
-
75
- test:
76
- <<: *default
77
- compile: true
78
-
79
- # Compile test packs to a separate directory
80
- public_output_path: packs-test
81
-
82
- production:
83
- <<: *default
84
-
85
- # Production depends on precompilation of packs prior to booting for performance.
86
- compile: false
87
-
88
- # Extract and emit a css file
89
- extract_css: true
90
-
91
- # Cache manifest.json for performance
92
- cache_manifest: true
data/lib/.DS_Store DELETED
Binary file
@@ -1,65 +0,0 @@
1
- # desc "Explaining what the task does"
2
- # task :cm_admin do
3
- # # Task goes here
4
- # end
5
-
6
- def ensure_log_goes_to_stdout
7
- old_logger = Webpacker.logger
8
- Webpacker.logger = ActiveSupport::Logger.new(STDOUT)
9
- yield
10
- ensure
11
- Webpacker.logger = old_logger
12
- end
13
-
14
- namespace :cm_admin do
15
- namespace :webpacker do
16
- desc "Install deps with yarn"
17
- task :yarn_install do
18
- Dir.chdir(File.join(__dir__, "../..")) do
19
- system "yarn install --no-progress --production"
20
- end
21
- end
22
-
23
- desc "Compile JavaScript packs using webpack for production with digests"
24
- task compile: [:yarn_install, :environment] do
25
- Webpacker.with_node_env("production") do
26
- ensure_log_goes_to_stdout do
27
- if CmAdmin.webpacker.commands.compile
28
- # Successful compilation!
29
- else
30
- # Failed compilation
31
- exit!
32
- end
33
- end
34
- end
35
- end
36
- end
37
- end
38
-
39
- def yarn_install_available?
40
- rails_major = Rails::VERSION::MAJOR
41
- rails_minor = Rails::VERSION::MINOR
42
-
43
- rails_major > 5 || (rails_major == 5 && rails_minor >= 1)
44
- end
45
-
46
- def enhance_assets_precompile
47
- # yarn:install was added in Rails 5.1
48
- deps = yarn_install_available? ? [] : ["cm_admin:webpacker:yarn_install"]
49
- Rake::Task["assets:precompile"].enhance(deps) do
50
- Rake::Task["cm_admin:webpacker:compile"].invoke
51
- end
52
- end
53
-
54
- if CmAdmin::VersionManager.rails6?
55
- # Compile packs after we've compiled all other assets during precompilation
56
- skip_webpacker_precompile = %w(no false n f).include?(ENV["WEBPACKER_PRECOMPILE"])
57
-
58
- unless skip_webpacker_precompile
59
- if Rake::Task.task_defined?("assets:precompile")
60
- enhance_assets_precompile
61
- else
62
- Rake::Task.define_task("assets:precompile" =>"cm_admin:webpacker:compile")
63
- end
64
- end
65
- end