solidus_importer 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (100) hide show
  1. checksums.yaml +7 -0
  2. data/.circleci/config.yml +35 -0
  3. data/.gem_release.yml +5 -0
  4. data/.github/stale.yml +17 -0
  5. data/.gitignore +20 -0
  6. data/.hound.yml +8 -0
  7. data/.rspec +2 -0
  8. data/.rubocop.yml +2 -0
  9. data/Gemfile +33 -0
  10. data/LICENSE +26 -0
  11. data/README.md +170 -0
  12. data/Rakefile +6 -0
  13. data/app/assets/javascripts/spree/backend/solidus_importer.js +2 -0
  14. data/app/assets/javascripts/spree/frontend/solidus_importer.js +2 -0
  15. data/app/assets/stylesheets/spree/backend/solidus_importer.css +16 -0
  16. data/app/assets/stylesheets/spree/frontend/solidus_importer.css +4 -0
  17. data/app/controllers/spree/admin/solidus_importer/import_rows_controller.rb +24 -0
  18. data/app/controllers/spree/admin/solidus_importer/imports_controller.rb +44 -0
  19. data/app/jobs/solidus_importer/import_job.rb +30 -0
  20. data/app/models/solidus_importer/import.rb +48 -0
  21. data/app/models/solidus_importer/row.rb +26 -0
  22. data/app/views/spree/admin/solidus_importer/import_rows/show.html.erb +46 -0
  23. data/app/views/spree/admin/solidus_importer/imports/_form.html.erb +14 -0
  24. data/app/views/spree/admin/solidus_importer/imports/index.html.erb +80 -0
  25. data/app/views/spree/admin/solidus_importer/imports/new.html.erb +13 -0
  26. data/app/views/spree/admin/solidus_importer/imports/show.html.erb +87 -0
  27. data/bin/console +17 -0
  28. data/bin/rails +7 -0
  29. data/bin/rails-engine +13 -0
  30. data/bin/rails-sandbox +16 -0
  31. data/bin/rake +7 -0
  32. data/bin/sandbox +84 -0
  33. data/bin/setup +8 -0
  34. data/config/initializers/spree.rb +11 -0
  35. data/config/locales/en.yml +28 -0
  36. data/config/routes.rb +11 -0
  37. data/db/migrate/20191216101011_create_solidus_importer_imports.rb +19 -0
  38. data/db/migrate/20191216101012_create_solidus_importer_rows.rb +14 -0
  39. data/examples/importers/custom_importer.rb +20 -0
  40. data/examples/processors/notify_on_failure.rb +22 -0
  41. data/lib/generators/solidus_importer/install/install_generator.rb +22 -0
  42. data/lib/solidus_importer.rb +25 -0
  43. data/lib/solidus_importer/base_importer.rb +26 -0
  44. data/lib/solidus_importer/configuration.rb +39 -0
  45. data/lib/solidus_importer/engine.rb +23 -0
  46. data/lib/solidus_importer/exception.rb +5 -0
  47. data/lib/solidus_importer/factories.rb +4 -0
  48. data/lib/solidus_importer/process_import.rb +88 -0
  49. data/lib/solidus_importer/process_row.rb +46 -0
  50. data/lib/solidus_importer/processors/address.rb +47 -0
  51. data/lib/solidus_importer/processors/base.rb +15 -0
  52. data/lib/solidus_importer/processors/customer.rb +41 -0
  53. data/lib/solidus_importer/processors/log.rb +15 -0
  54. data/lib/solidus_importer/processors/option_types.rb +43 -0
  55. data/lib/solidus_importer/processors/option_values.rb +49 -0
  56. data/lib/solidus_importer/processors/order.rb +40 -0
  57. data/lib/solidus_importer/processors/product.rb +51 -0
  58. data/lib/solidus_importer/processors/product_images.rb +30 -0
  59. data/lib/solidus_importer/processors/taxon.rb +52 -0
  60. data/lib/solidus_importer/processors/variant.rb +51 -0
  61. data/lib/solidus_importer/processors/variant_images.rb +30 -0
  62. data/lib/solidus_importer/version.rb +5 -0
  63. data/solidus_importer.gemspec +36 -0
  64. data/spec/factories/solidus_importer_imports.rb +27 -0
  65. data/spec/factories/solidus_importer_rows.rb +82 -0
  66. data/spec/features/admin/solidus_importer/import_rows_spec.rb +30 -0
  67. data/spec/features/admin/solidus_importer/imports_spec.rb +121 -0
  68. data/spec/features/solidus_importer/import_spec.rb +138 -0
  69. data/spec/features/solidus_importer/processors_spec.rb +53 -0
  70. data/spec/fixtures/solidus_importer/apparel.csv +23 -0
  71. data/spec/fixtures/solidus_importer/customers.csv +3 -0
  72. data/spec/fixtures/solidus_importer/home-and-garden.csv +22 -0
  73. data/spec/fixtures/solidus_importer/invalid_headers.csv +3 -0
  74. data/spec/fixtures/solidus_importer/invalid_product.csv +2 -0
  75. data/spec/fixtures/solidus_importer/jewelery.csv +55 -0
  76. data/spec/fixtures/solidus_importer/orders.csv +5 -0
  77. data/spec/fixtures/solidus_importer/products.csv +8 -0
  78. data/spec/fixtures/solidus_importer/thinking-cat.jpg +0 -0
  79. data/spec/jobs/solidus_importer/import_job_spec.rb +54 -0
  80. data/spec/lib/solidus_importer/base_importer_spec.rb +23 -0
  81. data/spec/lib/solidus_importer/process_import_spec.rb +74 -0
  82. data/spec/lib/solidus_importer/process_row_spec.rb +24 -0
  83. data/spec/lib/solidus_importer/processors/address_spec.rb +18 -0
  84. data/spec/lib/solidus_importer/processors/base_spec.rb +9 -0
  85. data/spec/lib/solidus_importer/processors/customer_spec.rb +65 -0
  86. data/spec/lib/solidus_importer/processors/log_spec.rb +18 -0
  87. data/spec/lib/solidus_importer/processors/option_types_spec.rb +38 -0
  88. data/spec/lib/solidus_importer/processors/option_values_spec.rb +43 -0
  89. data/spec/lib/solidus_importer/processors/order_spec.rb +56 -0
  90. data/spec/lib/solidus_importer/processors/product_images_spec.rb +42 -0
  91. data/spec/lib/solidus_importer/processors/product_spec.rb +66 -0
  92. data/spec/lib/solidus_importer/processors/taxon_spec.rb +33 -0
  93. data/spec/lib/solidus_importer/processors/variant_images_spec.rb +44 -0
  94. data/spec/lib/solidus_importer/processors/variant_spec.rb +86 -0
  95. data/spec/lib/solidus_importer_spec.rb +14 -0
  96. data/spec/models/solidus_importer/import_spec.rb +60 -0
  97. data/spec/models/solidus_importer/row_spec.rb +18 -0
  98. data/spec/spec_helper.rb +27 -0
  99. data/spec/support/solidus_importer_helpers.rb +13 -0
  100. metadata +227 -0
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SolidusImporter
4
+ class ImportJob < ActiveJob::Base
5
+ queue_as :default
6
+
7
+ retry_on ActiveRecord::Deadlocked
8
+
9
+ def perform(source, import_type = nil)
10
+ raise ArgumentError, 'Missing import source' unless source
11
+
12
+ if source.is_a?(Integer)
13
+ perform_import_from_model(source)
14
+ elsif source.is_a?(String) && import_type.present?
15
+ perform_import_from_filename(source, import_type)
16
+ else
17
+ raise ArgumentError, "#{source} should be a filename or an Import id"
18
+ end
19
+ end
20
+
21
+ def perform_import_from_model(id)
22
+ import = ::SolidusImporter::Import.find(id)
23
+ ::SolidusImporter::ProcessImport.new(import).process
24
+ end
25
+
26
+ def perform_import_from_filename(filename, import_type)
27
+ ::SolidusImporter::ProcessImport.import_from_file(filename, import_type)
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SolidusImporter
4
+ class Import < ApplicationRecord
5
+ self.table_name = 'solidus_importer_imports'
6
+
7
+ attr_accessor :importer
8
+
9
+ has_many :rows,
10
+ class_name: 'SolidusImporter::Row',
11
+ inverse_of: :import,
12
+ dependent: :destroy
13
+
14
+ enum state: {
15
+ created: 'created',
16
+ processing: 'processing',
17
+ failed: 'failed',
18
+ completed: 'completed'
19
+ }
20
+
21
+ has_attached_file :file
22
+
23
+ do_not_validate_attachment_file_type :file
24
+ validates_attachment_presence :file
25
+ validates :import_type, presence: true, allow_blank: false
26
+ validates :state, presence: true, allow_blank: false
27
+
28
+ def created_or_failed?
29
+ %w[created failed].include? state
30
+ end
31
+
32
+ def finished?
33
+ rows.failed_or_completed.size == rows.size
34
+ end
35
+
36
+ def import_file=(path)
37
+ raise SolidusImporter::Exception, 'Existing file required' if !path || !File.exist?(path)
38
+
39
+ self.file = File.open(path, 'r')
40
+ end
41
+
42
+ class << self
43
+ def available_types
44
+ SolidusImporter::Import.select(:import_type).order(:import_type).group(:import_type).pluck(:import_type)
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SolidusImporter
4
+ class Row < ApplicationRecord
5
+ self.table_name = 'solidus_importer_rows'
6
+
7
+ belongs_to :import,
8
+ class_name: 'SolidusImporter::Import',
9
+ inverse_of: :rows
10
+
11
+ serialize :data, JSON
12
+
13
+ enum state: {
14
+ created: 'created',
15
+ processing: 'processing',
16
+ failed: 'failed',
17
+ completed: 'completed'
18
+ }
19
+
20
+ scope :created_or_failed, -> { where(state: %i[created failed]) }
21
+ scope :failed_or_completed, -> { where(state: %i[failed completed]) }
22
+
23
+ validates :data, presence: true, allow_blank: false
24
+ validates :state, presence: true, allow_blank: false
25
+ end
26
+ end
@@ -0,0 +1,46 @@
1
+ <%
2
+ admin_layout('full-width')
3
+ import_id = @import_row.import_id
4
+ admin_breadcrumb(
5
+ t('spree.solidus_importer.title'),
6
+ link_to(t('spree.solidus_importer.imports'), admin_solidus_importer_imports_path),
7
+ link_to(import_id.to_s, admin_solidus_importer_import_path(id: import_id)),
8
+ t('spree.solidus_importer.import_rows'),
9
+ @import_row.id.to_s
10
+ )
11
+ %>
12
+
13
+ <div data-hook="admin_solidus_importer_import_rows_show">
14
+ <dl>
15
+ <dt><%= t('spree.id') %></dt>
16
+ <dd><%= @import_row.id %></dd>
17
+ <dt><%= t('spree.state') %></dt>
18
+ <dd class="solidus_importer state-<%= @import_row.state %>"><%= @import_row.state %></dd>
19
+ <dt><%= t('spree.solidus_importer.created_at') %></dt>
20
+ <dd><%= @import_row.created_at %></dd>
21
+ <dt><%= t('spree.solidus_importer.updated_at') %></dt>
22
+ <dd><%= @import_row.updated_at %></dd>
23
+ <dt><%= t('spree.solidus_importer.messages') %></dt>
24
+ <dd><%= @import_row.messages.blank? ? '-' : @import_row.messages %></dd>
25
+ <% if @log_details %>
26
+ <dt><%= t('spree.solidus_importer.log_entry') %></dt>
27
+ <dd><%= @log_details %></dd>
28
+ <% end %>
29
+ <% if @target_entity %>
30
+ <dt><%= t('spree.solidus_importer.target_entity') %></dt>
31
+ <dd>
32
+ <%= link_to("#{@target_entity.class} ##{@target_entity.id}", url_for([:admin, @target_entity])) rescue '-' %>
33
+ </dd>
34
+ <% end %>
35
+ <dt><%= t('spree.solidus_importer.data') %></dt>
36
+ </dl>
37
+
38
+ <table class="table">
39
+ <% @import_row.data.each do |k, v| %>
40
+ <tr class="import_row_attribute">
41
+ <td class="key"><%= k %></td>
42
+ <td class="value"><%= v %></td>
43
+ </tr>
44
+ <% end %>
45
+ </table>
46
+ </div>
@@ -0,0 +1,14 @@
1
+ <div class="row">
2
+ <div class="col-4">
3
+ <div class="field">
4
+ <%= f.label :import_type %><br>
5
+ <%= f.select :import_type, [nil] + @import_types %>
6
+ </div>
7
+ </div>
8
+ <div class="col-3">
9
+ <div class="field">
10
+ <%= f.label :file %><br>
11
+ <%= f.file_field :file %>
12
+ </div>
13
+ </div>
14
+ </div>
@@ -0,0 +1,80 @@
1
+ <% admin_layout('full-width') %>
2
+ <% admin_breadcrumb(t('spree.solidus_importer.title'), t('spree.solidus_importer.imports')) %>
3
+
4
+ <% content_for :page_actions do %>
5
+ <li>
6
+ <%= link_to t('spree.admin.solidus_importer.new'), new_admin_solidus_importer_import_url, id: 'admin_new_order', class: 'btn btn-primary' %>
7
+ </li>
8
+ <% end if can? :create, SolidusImporter::Import %>
9
+
10
+ <% content_for :table_filter do %>
11
+ <%= search_form_for [:admin, @search], url: admin_solidus_importer_imports_path do |f| %>
12
+ <div class="row">
13
+ <div class="col-md-4">
14
+ <div class="form-group">
15
+ <%= label_tag :q_import_type_eq, t('spree.type') %>:
16
+ <%= f.select :import_type_eq, SolidusImporter::Import.available_types, { include_blank: true }, class: 'select2 js-filterable' %>
17
+ </div>
18
+ </div>
19
+ <div class="col-md-2">
20
+ <div class="form-group">
21
+ <%= label_tag :q_state_eq, t('spree.state') %>:
22
+ <%= f.select :state_eq, SolidusImporter::Import.states, { include_blank: true }, class: 'select2 js-filterable' %>
23
+ </div>
24
+ </div>
25
+ <div class="col-md-2">
26
+ <div class="input-group">
27
+ <%= f.text_field :created_at_gt, class: 'datepicker datepicker-from form-control', value: params.dig(:q, :created_at_gt), autocomplete: 'off', placeholder: t('spree.solidus_importer.updated_at_from') %> &nbsp;
28
+ </div>
29
+ </div>
30
+ <div class="col-md-2">
31
+ <div class="input-group">
32
+ <%= f.text_field :created_at_lt, class: 'datepicker datepicker-to form-control', value: params.dig(:q, :created_at_lt), autocomplete: 'off', placeholder: t('spree.solidus_importer.updated_at_to') %> &nbsp;
33
+ </div>
34
+ </div>
35
+ <div class="col-md-2 text-right">
36
+ <%= button_tag t('spree.filter_results') %>
37
+ </div>
38
+ </div>
39
+ <% end %>
40
+ <% end %>
41
+
42
+ <div data-hook="admin_solidus_importer_imports_index">
43
+ <%= paginate @imports, theme: 'solidus_admin' %>
44
+
45
+ <% if @imports.any? %>
46
+ <table class="table table-bordered table-striped">
47
+ <thead>
48
+ <tr>
49
+ <th><%= sort_link @search, :id, t('spree.id') %></th>
50
+ <th><%= sort_link @search, :import_type, t('spree.type') %></th>
51
+ <th><%= sort_link @search, :state, t('spree.state') %></th>
52
+ <th><%= t('spree.solidus_importer.import_rows') %></th>
53
+ <th><%= sort_link @search, :updated_at, t('spree.solidus_importer.updated_at') %></th>
54
+ <th class="actions"></th>
55
+ </tr>
56
+ </thead>
57
+ <tbody>
58
+ <% @imports.each do |import| %>
59
+ <% link_details = admin_solidus_importer_import_path(id: import.id) %>
60
+ <tr class='solidus_importer_import'>
61
+ <td><%= link_to import.id.to_s, link_details %></td>
62
+ <td><%= import.import_type %></td>
63
+ <td class="solidus_importer state-<%= import.state %>"><%= import.state %></td>
64
+ <th><%= import.rows.count %></th>
65
+ <td><%= l(import.updated_at) %></td>
66
+ <td><%= link_to 'Details', link_details, class: 'fa fa-eye icon_link', 'data-action': 'view' %></td>
67
+ </tr>
68
+ <% end %>
69
+ </tbody>
70
+ </table>
71
+ <% else %>
72
+ <div class="no-objects-found">
73
+ <%= render 'spree/admin/shared/no_objects_found',
74
+ resource: SolidusImporter::Import,
75
+ new_resource_url: new_object_url %>
76
+ </div>
77
+ <% end %>
78
+
79
+ <%= paginate @imports, theme: 'solidus_admin' %>
80
+ </div>
@@ -0,0 +1,13 @@
1
+ <% admin_breadcrumb t('spree.solidus_importer.title'), link_to(t('spree.solidus_importer.imports'), admin_solidus_importer_imports_path) %>
2
+
3
+ <%= form_for [:admin, @import], method: :post, html: { multipart: true } do |f| %>
4
+ <fieldset class="no-border-top">
5
+ <%= render partial: 'spree/shared/error_messages', locals: { target: @import } %>
6
+ <%= render partial: 'form', locals: { f: f } %>
7
+
8
+ <div class="form-buttons filter-actions actions" data-hook="buttons">
9
+ <%= f.submit t('spree.actions.create'), class: 'btn btn-primary' %>
10
+ </div>
11
+ </fieldset>
12
+ <% end %>
13
+
@@ -0,0 +1,87 @@
1
+ <%
2
+ admin_layout('full-width')
3
+ admin_breadcrumb(
4
+ t('spree.solidus_importer.title'),
5
+ link_to(t('spree.solidus_importer.imports'), admin_solidus_importer_imports_path),
6
+ @import.id.to_s
7
+ )
8
+ %>
9
+
10
+ <div data-hook="admin_solidus_importer_imports_show">
11
+ <dl>
12
+ <dt><%= t('spree.id') %></dt>
13
+ <dd><%= @import.id %></dd>
14
+ <dt><%= t('spree.type') %></dt>
15
+ <dd><%= @import.import_type %></dd>
16
+ <dt><%= t('spree.state') %></dt>
17
+ <dd class="solidus_importer state-<%= @import.state %>"><%= @import.state %></dd>
18
+ <dt><%= t('spree.solidus_importer.import') %></dt>
19
+ <dd><%= link_to @import.file_file_name, @import.file.url %></dd>
20
+ <dt><%= t('spree.solidus_importer.import_rows') %></dt>
21
+ <dd><%= @import.rows.count %></dd>
22
+ <dt><%= t('spree.solidus_importer.created_at') %></dt>
23
+ <dd><%= @import.created_at %></dd>
24
+ <dt><%= t('spree.solidus_importer.updated_at') %></dt>
25
+ <dd><%= @import.updated_at %></dd>
26
+ <dt><%= t('spree.solidus_importer.messages') %></dt>
27
+ <dd><%= @import.messages.blank? ? '-' : @import.messages %></dd>
28
+ </dl>
29
+
30
+ <hr/>
31
+
32
+ <%= search_form_for [:admin, @search], url: admin_solidus_importer_import_path(@import) do |f| %>
33
+ <div class="row">
34
+ <div class="col-md-3">
35
+ <div class="form-group">
36
+ <%= label_tag :q_state_eq, t('spree.state') %>:
37
+ <%= f.select :state_eq, SolidusImporter::Import.states, { include_blank: true }, class: 'select2 js-filterable' %>
38
+ </div>
39
+ </div>
40
+ <div class="col-md-3">
41
+ <div class="input-group">
42
+ <%= f.text_field :created_at_gt, class: 'datepicker datepicker-from form-control', value: params.dig(:q, :created_at_gt), autocomplete: 'off', placeholder: t('spree.solidus_importer.updated_at_from') %> &nbsp;
43
+ </div>
44
+ </div>
45
+ <div class="col-md-3">
46
+ <div class="input-group">
47
+ <%= f.text_field :created_at_lt, class: 'datepicker datepicker-to form-control', value: params.dig(:q, :created_at_lt), autocomplete: 'off', placeholder: t('spree.solidus_importer.updated_at_to') %> &nbsp;
48
+ </div>
49
+ </div>
50
+ <div class="col-md-3 text-right">
51
+ <%= button_tag t('spree.filter_results') %>
52
+ </div>
53
+ </div>
54
+ <% end %>
55
+
56
+ <%= paginate @import_rows, theme: 'solidus_admin' %>
57
+
58
+ <% if @import_rows.any? %>
59
+ <table class="table table-bordered table-striped">
60
+ <thead>
61
+ <tr>
62
+ <th><%= sort_link @search, :id, t('spree.id') %></th>
63
+ <th><%= sort_link @search, :state, t('spree.state') %></th>
64
+ <th><%= sort_link @search, :updated_at, t('spree.solidus_importer.updated_at') %></th>
65
+ <th class="actions"></th>
66
+ </tr>
67
+ </thead>
68
+ <tbody>
69
+ <% @import_rows.each do |import_row| %>
70
+ <% link_details = admin_solidus_importer_import_import_row_path(import_id: @import.id, id: import_row.id) %>
71
+ <tr class='solidus_importer_import_row'>
72
+ <td><%= link_to import_row.id.to_s, link_details %></td>
73
+ <td class="solidus_importer state-<%= import_row.state %>"><%= import_row.state %></td>
74
+ <td><%= l(import_row.updated_at) %></td>
75
+ <td><%= link_to 'Details', link_details, class: 'fa fa-eye icon_link', 'data-action': 'view' %></td>
76
+ </tr>
77
+ <% end %>
78
+ </tbody>
79
+ </table>
80
+ <% else %>
81
+ <div class="no-objects-found">
82
+ <%= render 'spree/admin/shared/no_objects_found', resource: SolidusImporter::Row %>
83
+ </div>
84
+ <% end %>
85
+
86
+ <%= paginate @import_rows, theme: 'solidus_admin' %>
87
+ </div>
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # frozen_string_literal: true
4
+
5
+ require "bundler/setup"
6
+ require "solidus_importer"
7
+
8
+ # You can add fixtures and/or initialization code here to make experimenting
9
+ # with your gem easier. You can also use a different console, if you like.
10
+ $LOAD_PATH.unshift(*Dir["#{__dir__}/../app/*"])
11
+
12
+ # (If you use this, don't forget to add pry to your Gemfile!)
13
+ # require "pry"
14
+ # Pry.start
15
+
16
+ require "irb"
17
+ IRB.start(__FILE__)
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ if %w[g generate].include? ARGV.first
4
+ exec "#{__dir__}/rails-engine", *ARGV
5
+ else
6
+ exec "#{__dir__}/rails-sandbox", *ARGV
7
+ end
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env ruby
2
+ # This command will automatically be run when you run "rails" with Rails gems
3
+ # installed from the root of your application.
4
+
5
+ ENGINE_ROOT = File.expand_path('..', __dir__)
6
+ ENGINE_PATH = File.expand_path('../lib/solidus_importer/engine', __dir__)
7
+
8
+ # Set up gems listed in the Gemfile.
9
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
10
+ require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
11
+
12
+ require 'rails/all'
13
+ require 'rails/engine/commands'
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ app_root = 'sandbox'
4
+
5
+ unless File.exist? "#{app_root}/bin/rails"
6
+ warn 'Creating the sandbox app...'
7
+ Dir.chdir "#{__dir__}/.." do
8
+ system "#{__dir__}/sandbox" or begin # rubocop:disable Style/AndOr
9
+ warn 'Automatic creation of the sandbox app failed'
10
+ exit 1
11
+ end
12
+ end
13
+ end
14
+
15
+ Dir.chdir app_root
16
+ exec 'bin/rails', *ARGV
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "rubygems"
5
+ require "bundler/setup"
6
+
7
+ load Gem.bin_path("rake", "rake")
@@ -0,0 +1,84 @@
1
+ #!/usr/bin/env bash
2
+
3
+ set -e
4
+
5
+ case "$DB" in
6
+ postgres|postgresql)
7
+ RAILSDB="postgresql"
8
+ ;;
9
+ mysql)
10
+ RAILSDB="mysql"
11
+ ;;
12
+ sqlite|'')
13
+ RAILSDB="sqlite3"
14
+ ;;
15
+ *)
16
+ echo "Invalid DB specified: $DB"
17
+ exit 1
18
+ ;;
19
+ esac
20
+
21
+ if [ ! -z $SOLIDUS_BRANCH ]
22
+ then
23
+ BRANCH=$SOLIDUS_BRANCH
24
+ else
25
+ BRANCH="master"
26
+ fi
27
+
28
+ extension_name="solidus_importer"
29
+
30
+ # Stay away from the bundler env of the containing extension.
31
+ function unbundled {
32
+ ruby -rbundler -e'b = proc {system *ARGV}; Bundler.respond_to?(:with_unbundled_env) ? Bundler.with_unbundled_env(&b) : Bundler.with_clean_env(&b)' -- $@
33
+ }
34
+
35
+ rm -rf ./sandbox
36
+ unbundled bundle exec rails new sandbox --database="$RAILSDB" \
37
+ --skip-bundle \
38
+ --skip-git \
39
+ --skip-keeps \
40
+ --skip-rc \
41
+ --skip-spring \
42
+ --skip-test \
43
+ --skip-javascript
44
+
45
+ if [ ! -d "sandbox" ]; then
46
+ echo 'sandbox rails application failed'
47
+ exit 1
48
+ fi
49
+
50
+ cd ./sandbox
51
+ cat <<RUBY >> Gemfile
52
+ gem 'solidus', github: 'solidusio/solidus', branch: '$BRANCH'
53
+ gem 'solidus_auth_devise', '>= 2.1.0'
54
+ gem 'rails-i18n'
55
+ gem 'solidus_i18n'
56
+
57
+ gem '$extension_name', path: '..'
58
+
59
+ group :test, :development do
60
+ platforms :mri do
61
+ gem 'pry-byebug'
62
+ end
63
+ end
64
+ RUBY
65
+
66
+ unbundled bundle install --gemfile Gemfile
67
+
68
+ unbundled bundle exec rake db:drop db:create
69
+
70
+ unbundled bundle exec rails generate spree:install \
71
+ --auto-accept \
72
+ --user_class=Spree::User \
73
+ --enforce_available_locales=true \
74
+ --with-authentication=false \
75
+ $@
76
+
77
+ unbundled bundle exec rails generate solidus:auth:install
78
+
79
+ echo
80
+ echo "🚀 Sandbox app successfully created for $extension_name!"
81
+ echo "🚀 Using $RAILSDB and Solidus $BRANCH"
82
+ echo "🚀 Use 'export DB=[postgres|mysql|sqlite]' to control the DB adapter"
83
+ echo "🚀 Use 'export SOLIDUS_BRANCH=<BRANCH-NAME>' to control the Solidus version"
84
+ echo "🚀 This app is intended for test purposes."