spree_extension 1.0.2 → 2.0.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: 0b9ca26be3caa2eeb5e4cca4ab3636961cf6a75b12d00ca4fe0de0d6ebc28613
4
- data.tar.gz: ef6e6d1fd78d5cb75073c8f74fa01e1ce6d495dbbb790bf0e67c80a59db4cae6
3
+ metadata.gz: 9bef5f7e05cc526f9d92c913907758c4b2103ada2ec9371057aa07ac7b22d3df
4
+ data.tar.gz: 8d3b4021d2bf8d9a4523b3e35c334fc918613a23b8e1228056ff7e534711157e
5
5
  SHA512:
6
- metadata.gz: 4fb05a17393aa6d2248bb662cb1803964c5b748d5f78c45f260e2c0ea839013693ca247da47a57a90fe8b73d686fdbebcdd93c9db20c0884a2a8571370aba862
7
- data.tar.gz: 5a1ff4024e17c3d7f50df28f147aa3d12fd79863ee6ddc4a1f96353e24498ac406ab26944ba216a6eb84871166d0f38f376fe10fbf43d9c892d26e0180591864
6
+ metadata.gz: fac446b3fa9c4e0cfec8728f005360ba43faa48c077e07b7f4494ac987158224e72d31cf08f21caf5b370c15d077e19f564fa2e19fa601cd470c93972ed6e27e
7
+ data.tar.gz: 1fcac2564531a2d227a3229dfac120bd1ee4f9facde719c6460aa7e08e717063d3694eb4d6bdcaaface5d8d78fa39843b8ef5e8732934bf7e44dbbbb59f95cca
data/README.md CHANGED
@@ -4,6 +4,15 @@
4
4
 
5
5
  CLI tool for generating and managing Spree Commerce extensions.
6
6
 
7
+ ## Compatibility
8
+
9
+ | spree_extension | Spree |
10
+ |---|---|
11
+ | 2.x | 6.0+ |
12
+ | 1.x | 5.x |
13
+
14
+ To scaffold an extension for Spree 5, install the 1.x version: `gem install spree_extension -v '~> 1.0'`.
15
+
7
16
  ## Installation
8
17
 
9
18
  ```bash
@@ -18,7 +27,13 @@ gem install spree_extension
18
27
  spree-extension create my_extension
19
28
  ```
20
29
 
21
- This creates a `spree_my_extension` directory with a complete extension scaffold including engine setup, tests, CI configuration, and more.
30
+ This creates a `spree_my_extension` directory with a complete extension scaffold: a Rails engine depending on `spree_core` and `spree_api`, directories for models, Store and Admin API controllers and serializers, services and event subscribers, an initializer for permission scopes and workflow hooks, a test setup based on [spree_dev_tools](https://github.com/spree/spree_dev_tools), and CI configuration.
31
+
32
+ An extension is backend code only. Admin screens for your extension are built as a [dashboard plugin](https://spreecommerce.org/docs/developer/dashboard/plugins/overview), scaffolded with:
33
+
34
+ ```bash
35
+ npx @spree/cli plugin new my-extension
36
+ ```
22
37
 
23
38
  ### Check version
24
39
 
@@ -37,7 +52,7 @@ bundle exec rspec
37
52
 
38
53
  ## Documentation
39
54
 
40
- For more information on developing Spree extensions, see the [Spree Developer Documentation](https://docs.spreecommerce.org/developer).
55
+ For a walkthrough of building an extension, see [Creating a Spree extension](https://spreecommerce.org/docs/developer/contributing/creating-an-extension).
41
56
 
42
57
  ## License
43
58
 
@@ -19,18 +19,15 @@ module SpreeExtension
19
19
  directory 'bin', "#{file_name}/bin"
20
20
  directory 'spec', "#{file_name}/spec"
21
21
 
22
- empty_directory "#{file_name}/app/models/#{file_name}"
23
- empty_directory "#{file_name}/app/views/spree"
24
- empty_directory "#{file_name}/app/controllers/spree/admin"
25
- empty_directory "#{file_name}/app/controllers/#{file_name}"
26
- empty_directory "#{file_name}/app/services/#{file_name}"
27
- empty_directory "#{file_name}/app/serializers/spree/api/v3"
22
+ empty_directory "#{file_name}/app/models/spree"
23
+ empty_directory "#{file_name}/app/controllers/spree/api/v3/store"
24
+ empty_directory "#{file_name}/app/controllers/spree/api/v3/admin"
28
25
  empty_directory "#{file_name}/app/serializers/spree/api/v3/admin"
29
- empty_directory "#{file_name}/vendor/javascript"
30
- empty_directory "#{file_name}/vendor/stylesheets"
26
+ empty_directory "#{file_name}/app/services/#{file_name}"
27
+ empty_directory "#{file_name}/app/subscribers/#{file_name}"
28
+ empty_directory "#{file_name}/db/migrate"
31
29
 
32
30
  chmod "#{file_name}/bin/rails", 0o755
33
- chmod "#{file_name}/bin/importmap", 0o755
34
31
 
35
32
  template 'extension.gemspec', "#{file_name}/#{file_name}.gemspec"
36
33
  template 'Gemfile', "#{file_name}/Gemfile"
@@ -41,7 +38,6 @@ module SpreeExtension
41
38
  template 'config/routes.rb', "#{file_name}/config/routes.rb"
42
39
  template 'config/locales/en.yml', "#{file_name}/config/locales/en.yml"
43
40
  template 'config/initializers/spree.rb', "#{file_name}/config/initializers/spree.rb"
44
- template 'config/importmap.rb', "#{file_name}/config/importmap.rb"
45
41
 
46
42
  template 'rspec', "#{file_name}/.rspec"
47
43
  template '.github/workflows/tests.yml', "#{file_name}/.github/workflows/tests.yml"
@@ -57,7 +53,9 @@ module SpreeExtension
57
53
  Congrats, Your Spree #{human_name} extension has been generated 🚀
58
54
 
59
55
  Next steps:
60
- * Read Spree Developer Documentation at: https://docs.spreecommerce.org/developer
56
+ * cd #{file_name} && bundle install && bundle exec rake test_app
57
+ * Read the extension guide: https://spreecommerce.org/docs/developer/contributing/creating-an-extension
58
+ * Admin screens are built as a dashboard plugin: npx @spree/cli plugin new #{file_name.delete_prefix('spree_').tr('_', '-')}
61
59
 
62
60
  #{'*' * 80}
63
61
  }
@@ -1,25 +1,27 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- gem 'rails-controller-testing'
4
-
5
3
  spree_opts = if ENV['SPREE_PATH']
6
- { 'path': ENV['SPREE_PATH'] }
4
+ { 'path': ENV['SPREE_PATH'] }
7
5
  else
8
- { 'github': 'spree/spree', 'branch': 'main', 'glob': 'spree/**/*.gemspec' }
6
+ { 'github': 'spree/spree', 'branch': 'main', 'glob': 'spree/**/*.gemspec' }
9
7
  end
8
+ # spree provides the spree:install generator used by `rake test_app`
10
9
  gem 'spree', spree_opts
11
- gem 'spree_admin', spree_opts
10
+ gem 'spree_core', spree_opts
11
+ gem 'spree_api', spree_opts
12
+
13
+ gem 'spree_dev_tools', '>= 1.0.0.beta2'
12
14
 
13
- gem 'spree_dev_tools', '>= 0.6.0.rc1'
15
+ # json 3.0 made JSON.parse options keyword-only, which Active Support 8.1 does
16
+ # not support yet. Remove the pin once Rails ships a compatible release.
17
+ gem 'json', '< 3'
14
18
 
15
19
  if ENV['DB'] == 'mysql'
16
20
  gem 'mysql2'
17
21
  elsif ENV['DB'] == 'postgres'
18
22
  gem 'pg'
19
23
  else
20
- gem 'sqlite3'
24
+ gem 'sqlite3', '>= 2.0'
21
25
  end
22
26
 
23
- gem 'propshaft'
24
-
25
27
  gemspec
@@ -2,26 +2,41 @@
2
2
 
3
3
  This is a <%= human_name %> extension for [Spree Commerce](https://spreecommerce.org), an open source e-commerce platform built with Ruby on Rails.
4
4
 
5
+ Requires Spree 6.0 or later.
6
+
5
7
  ## Installation
6
8
 
7
9
  1. Add this extension to your Gemfile with this line:
8
10
 
9
- ```ruby
11
+ ```bash
10
12
  bundle add <%= file_name %>
11
13
  ```
12
14
 
13
- 2. Run the install generator
15
+ 2. Run the install generator to copy and run the extension's migrations
14
16
 
15
- ```ruby
16
- bundle exec rails g <%= file_name %>:install
17
+ ```bash
18
+ bin/rails g <%= file_name %>:install
17
19
  ```
18
20
 
19
21
  3. Restart your server
20
22
 
21
- If your server was running, restart it so that it can find the assets properly.
22
-
23
23
  ## Developing
24
24
 
25
+ An extension is backend code only: models, migrations, Store and Admin API endpoints, permissions, workflow hooks and event subscribers.
26
+
27
+ | Part of the feature | Where it lives |
28
+ |---|---|
29
+ | Models, migrations, business logic | `app/models`, `app/services`, `db/migrate` |
30
+ | API endpoints | `app/controllers/spree/api/v3/{store,admin}`, `app/serializers/spree/api/v3`, `config/routes.rb` |
31
+ | Decorators (last resort) | `app/models/spree/*_decorator.rb` |
32
+ | Event subscribers | `app/subscribers/<%= file_name %>` |
33
+ | Permission scopes, workflow hooks, subscriber registration, registries | `config/initializers/spree.rb` |
34
+ | Decorator loading, `additional_permitted_attributes` | `lib/<%= file_name %>/engine.rb` |
35
+ | Admin screens | A [dashboard plugin](https://spreecommerce.org/docs/developer/dashboard/plugins/overview) — scaffold one with `npx @spree/cli plugin new <%= file_name.delete_prefix('spree_').tr('_', '-') %>` |
36
+ | Storefront pages | Your storefront application, through `@spree/sdk` |
37
+
38
+ See [Creating a Spree extension](https://spreecommerce.org/docs/developer/contributing/creating-an-extension) for a walkthrough.
39
+
25
40
  1. Create a dummy app
26
41
 
27
42
  ```bash
@@ -29,6 +44,8 @@ This is a <%= human_name %> extension for [Spree Commerce](https://spreecommerce
29
44
  bundle exec rake test_app
30
45
  ```
31
46
 
47
+ Run this again whenever you add a migration.
48
+
32
49
  2. Add your new code
33
50
  3. Run tests
34
51
 
@@ -36,6 +53,12 @@ This is a <%= human_name %> extension for [Spree Commerce](https://spreecommerce
36
53
  bundle exec rspec
37
54
  ```
38
55
 
56
+ To develop against a local checkout of Spree, point `SPREE_PATH` at the `spree` directory of the monorepo:
57
+
58
+ ```bash
59
+ SPREE_PATH=../spree/spree bundle update
60
+ ```
61
+
39
62
  When testing your applications integration with this extension you may use it's factories.
40
63
  Simply add this require statement to your spec_helper:
41
64
 
@@ -17,7 +17,5 @@ end
17
17
  desc 'Generates a dummy app for testing'
18
18
  task :test_app do
19
19
  ENV['LIB_NAME'] = '<%=file_name%>'
20
- Rake::Task['extension:test_app'].execute(
21
- install_admin: true
22
- )
20
+ Rake::Task['extension:test_app'].execute
23
21
  end
@@ -1,23 +1,27 @@
1
- # Uncomment lines below to add your own custom business logic
2
- # such as promotions, shipping methods, etc.
3
- Rails.application.config.after_initialize do
4
- # Spree.shipping_methods << Spree::ShippingMethods::SuperExpensiveNotVeryFastShipping
5
- # Spree.payment_methods << Spree::PaymentMethods::VerySafeAndReliablePaymentMethod
6
-
7
- # Spree.calculators.tax_rates << Spree::TaxRates::FinanceTeamForcedMeToCodeThis
8
-
9
- # Spree.stock_splitters << Spree::Stock::Splitters::SecretLogicSplitter
1
+ # Register your extension with Spree here. This file is loaded by the host
2
+ # application at boot, like any other initializer.
3
+ #
4
+ # Permission scopes: adds read_<name> and write_<name> permissions for staff
5
+ # roles and secret API keys. Use `scoped_resource :<name>` in your Admin API
6
+ # controllers to require them.
7
+ # Spree.permissions.register_scope(:my_resources, group: :catalog, resources: -> {
8
+ # [Spree::MyResource]
9
+ # })
10
+ #
11
+ # Workflow hooks: run your code at a named point inside a Spree workflow.
12
+ # Hook names are validated at boot, so a typo fails at startup.
13
+ # Spree.hooks.register('products.activate.validate', '<%= class_name %>::MyValidator')
10
14
 
11
- # Spree.adjusters << Spree::Adjustable::Adjuster::TaxTheRich
12
-
13
- # Custom promotions
14
- # Spree.calculators.promotion_actions_create_adjustments << Spree::Calculators::PromotionActions::CreateAdjustments::AddDiscountForFriends
15
- # Spree.calculators.promotion_actions_create_item_adjustments << Spree::Calculators::PromotionActions::CreateItemAdjustments::FinanceTeamForcedMeToCodeThis
16
- # Spree.promotions.rules << Spree::Promotions::Rules::OnlyForVIPCustomers
17
- # Spree.promotions.actions << Spree::Promotions::Actions::GiftWithPurchase
18
-
19
- # Spree.taxon_rules << Spree::TaxonRules::ProductsWithColor
15
+ Rails.application.config.after_initialize do
16
+ # Event subscribers (app/subscribers) — `bin/rails g spree:subscriber` adds
17
+ # registrations here.
18
+ # Spree.subscribers << <%= class_name %>::MySubscriber
20
19
 
21
- # Spree.exports << Spree::Exports::Payments
22
- # Spree.reports << Spree::Reports::MassivelyOvercomplexReportForCfo
20
+ # Registries: custom payment methods, calculators, promotion rules, etc.
21
+ # Spree.payment_methods << Spree::PaymentMethods::VerySafeAndReliablePaymentMethod
22
+ # Spree.calculators.shipping_methods << Spree::Calculator::Shipping::SuperExpensiveNotVeryFastShipping
23
+ # Spree.promotions.rules << Spree::Promotion::Rules::OnlyForVIPCustomers
24
+ # Spree.promotions.actions << Spree::Promotion::Actions::GiftWithPurchase
25
+ # Spree.stock_splitters << Spree::Stock::Splitter::SecretLogicSplitter
26
+ # Rails.application.config.spree.collection_rules << MyExtension::CollectionRules::ProductsWithColor
23
27
  end
@@ -1,7 +1,5 @@
1
- # Sample localization file for English. Add more files in this directory for other locales.
2
- # See https://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points.
3
-
1
+ ---
4
2
  en:
5
3
  spree:
6
4
  <%= file_name.gsub('spree_', '') %>:
7
- hello: "Hello <%= class_name %>"
5
+ hello: Hello <%= class_name %>
@@ -1,3 +1,15 @@
1
1
  Spree::Core::Engine.add_routes do
2
- # Add your extension routes here
2
+ # Add your extension routes here, e.g.:
3
+ #
4
+ # namespace :api, defaults: { format: 'json' } do
5
+ # namespace :v3 do
6
+ # namespace :store do
7
+ # resources :my_resources, only: [:index, :show]
8
+ # end
9
+ #
10
+ # namespace :admin do
11
+ # resources :my_resources
12
+ # end
13
+ # end
14
+ # end
3
15
  end
@@ -16,13 +16,13 @@ Gem::Specification.new do |s|
16
16
  s.homepage = 'https://github.com/<%= file_name %>'
17
17
  s.license = 'MIT'
18
18
 
19
- s.files = Dir["{app,config,db,lib,vendor}/**/*", "LICENSE.md", "Rakefile", "README.md"].reject { |f| f.match(/^spec/) && !f.match(/^spec\/fixtures/) }
19
+ s.files = Dir["{app,config,db,lib}/**/*", "LICENSE.md", "Rakefile", "README.md"].reject { |f| f.match(/^spec/) && !f.match(/^spec\/fixtures/) }
20
20
  s.require_path = 'lib'
21
21
  s.requirements << 'none'
22
22
 
23
- spree_version = '>= 5.4.0.beta'
24
- s.add_dependency 'spree', spree_version
25
- s.add_dependency 'spree_admin', spree_version
23
+ spree_version = '>= 6.0.0.beta'
24
+ s.add_dependency 'spree_core', spree_version
25
+ s.add_dependency 'spree_api', spree_version
26
26
 
27
27
  s.add_development_dependency 'spree_dev_tools'
28
28
  end
@@ -4,6 +4,7 @@ module <%= class_name %>
4
4
  isolate_namespace Spree
5
5
  engine_name '<%= file_name %>'
6
6
 
7
+ # use rspec for tests
7
8
  config.generators do |g|
8
9
  g.test_framework :rspec
9
10
  end
@@ -12,19 +13,21 @@ module <%= class_name %>
12
13
  <%= class_name %>::Config = <%= class_name %>::Configuration.new
13
14
  end
14
15
 
15
- initializer '<%= file_name %>.assets' do |app|
16
- if app.config.respond_to?(:assets)
17
- app.config.assets.paths << root.join('app/javascript')
18
- app.config.assets.precompile += %w[<%= file_name %>_manifest]
16
+ # Runs on boot and before every code reload in development.
17
+ config.to_prepare do
18
+ # Decorators are not loaded automatically. Prefer workflow hooks, events
19
+ # and additional_permitted_attributes, and use decorators as a last resort.
20
+ Dir.glob(<%= class_name %>::Engine.root.join('app/**/*_decorator*.rb')) do |decorator|
21
+ Rails.configuration.cache_classes ? require(decorator) : load(decorator)
19
22
  end
20
- end
21
23
 
22
- initializer '<%= file_name %>.importmap', before: 'importmap' do |app|
23
- if app.config.respond_to?(:importmap)
24
- app.config.importmap.paths << root.join('config/importmap.rb')
25
- # https://github.com/rails/importmap-rails?tab=readme-ov-file#sweeping-the-cache-in-development-and-test
26
- app.config.importmap.cache_sweepers << root.join('app/javascript')
27
- end
24
+ # Make your own columns writable through the existing Store and Admin API
25
+ # endpoints. Always append with +=, so attributes added by other
26
+ # extensions are kept.
27
+ # Spree::Product.additional_permitted_attributes += [:my_column]
28
28
  end
29
+
30
+ # Event subscribers, permission scopes, hooks and registry entries are
31
+ # registered in config/initializers/spree.rb.
29
32
  end
30
33
  end
@@ -1,7 +1,8 @@
1
- require 'spree'
2
- require '<%=file_name%>/engine'
3
- require '<%=file_name%>/version'
4
- require '<%=file_name%>/configuration'
1
+ require 'spree_core'
2
+ require 'spree_api'
3
+ require '<%= file_name %>/engine'
4
+ require '<%= file_name %>/version'
5
+ require '<%= file_name %>/configuration'
5
6
 
6
7
  module <%= class_name %>
7
8
  mattr_accessor :queue
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spree_extension
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Spark Solutions Sp. z o.o.
@@ -50,15 +50,9 @@ files:
50
50
  - lib/spree_extension/templates/extension/README.md
51
51
  - lib/spree_extension/templates/extension/Rakefile
52
52
  - lib/spree_extension/templates/extension/app/.gitkeep
53
- - lib/spree_extension/templates/extension/app/assets/config/%file_name%_manifest.js.tt
54
- - lib/spree_extension/templates/extension/app/assets/images/.keep
55
- - lib/spree_extension/templates/extension/app/javascript/%file_name%/application.js.tt
56
- - lib/spree_extension/templates/extension/app/javascript/%file_name%/controllers/%file_name%_controller.js.tt
57
53
  - lib/spree_extension/templates/extension/app/jobs/%file_name%/base_job.rb.tt
58
- - lib/spree_extension/templates/extension/bin/importmap
59
54
  - lib/spree_extension/templates/extension/bin/rails.tt
60
55
  - lib/spree_extension/templates/extension/config/i18n-tasks.yml
61
- - lib/spree_extension/templates/extension/config/importmap.rb.tt
62
56
  - lib/spree_extension/templates/extension/config/initializers/spree.rb.tt
63
57
  - lib/spree_extension/templates/extension/config/locales/en.yml.tt
64
58
  - lib/spree_extension/templates/extension/config/routes.rb
@@ -96,7 +90,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
96
90
  - !ruby/object:Gem::Version
97
91
  version: '0'
98
92
  requirements: []
99
- rubygems_version: 4.0.2
93
+ rubygems_version: 4.0.3
100
94
  specification_version: 4
101
95
  summary: Spree Extension Generator
102
96
  test_files: []
@@ -1,5 +0,0 @@
1
- //= link_tree ../images
2
- //= link <%= file_name %>/application.js
3
- //= link_tree ../../javascript/<%= file_name %>/controllers .js
4
- //= link_tree ../../../vendor/javascript .js
5
- //= link_tree ../../../vendor/stylesheets .css
@@ -1,16 +0,0 @@
1
- import '@hotwired/turbo-rails'
2
- import { Application } from '@hotwired/stimulus'
3
-
4
- let application
5
-
6
- if (typeof window.Stimulus === "undefined") {
7
- application = Application.start()
8
- application.debug = false
9
- window.Stimulus = application
10
- } else {
11
- application = window.Stimulus
12
- }
13
-
14
- import <%= class_name %>Controller from '<%= file_name %>/controllers/<%= file_name %>_controller'
15
-
16
- application.register('<%= file_name %>', <%= class_name %>Controller)
@@ -1,7 +0,0 @@
1
- import { Controller } from '@hotwired/stimulus'
2
-
3
- export default class extends Controller {
4
- connect() {
5
- console.log('Hello, <%= class_name %>!')
6
- }
7
- }
@@ -1,9 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
4
- require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
5
-
6
- require 'rails'
7
-
8
- require 'importmap-rails'
9
- require 'importmap/commands'
@@ -1,6 +0,0 @@
1
- pin 'application-<%= file_name.tr("_","-") %>', to: '<%= file_name %>/application.js', preload: false
2
-
3
- pin_all_from <%= class_name %>::Engine.root.join('app/javascript/<%= file_name %>/controllers'),
4
- under: '<%= file_name %>/controllers',
5
- to: '<%= file_name %>/controllers',
6
- preload: 'application-<%= file_name.tr("_","-") %>'