Skip to content

Commit

Permalink
Replace Node with Importmap (#308)
Browse files Browse the repository at this point in the history
* Replace Node with Importmap
* less complexity
* no node dependencies
* Rails-way
  • Loading branch information
damianlegawiec authored Mar 1, 2024
1 parent 808c4ac commit 65dca50
Show file tree
Hide file tree
Showing 32 changed files with 154 additions and 1,387 deletions.
227 changes: 82 additions & 145 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,108 +1,86 @@
version: 2.1

defaults: &defaults
parameters: &default_parameters
ruby_image:
type: string
redis_image:
type: string
restore_cache_key_1:
type: string
default: 'spree-bundle-v10-ruby-3-2-{{ .Branch }}'
restore_cache_key_2:
type: string
default: spree-bundle-v10-ruby-3-2
save_cache_key:
type: string
default: "n"
run_file_path:
type: string
rails_version:
type: string
default: '~> 7.0.0'
store_artefacts:
type: boolean
default: false
environment: &environment
CIRCLE_TEST_REPORTS: /tmp/test-results
CIRCLE_ARTIFACTS: /tmp/test-artifacts
BUNDLE_JOBS: 4
BUNDLE_RETRY: 3
BUNDLE_PATH: ~/spree/vendor/bundle
RAILS_VERSION: << parameters.rails_version >>
CIRCLE_TEST_REPORTS: /tmp/test-results
CIRCLE_ARTIFACTS: /tmp/test-artifacts
BUNDLE_JOBS: 4
BUNDLE_RETRY: 3
BUNDLE_PATH: ~/spree/vendor/bundle
RAILS_VERSION: '~> 7.1.0'
working_directory: ~/spree
docker:
- image: &ruby_image << parameters.ruby_image >>
- image: &redis_image << parameters.redis_image >>
- image: &ruby_image cimg/ruby:3.3.0-browsers

run_tests: &run_tests
<<: *defaults
parallelism: 8
steps:
- checkout
- restore_cache:
keys:
- spree-storefront-bundle-{{ checksum ".ruby-version" }}-{{ .Branch }}
- spree-storefront-bundle-{{ checksum ".ruby-version" }}
- run:
name: Add keyserver
command: sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 4EB27DB2A3B88B8B
- run:
name: Install libvips
command: sudo apt-get update && sudo apt-get install libvips
- run:
name: Set bundle path
command: bundle config --local path vendor/bundle
- run:
name: Ensure Bundle Install
command: |
bundle check || bundle install
- run:
name: Create test app
command: |
bundle exec rake test_app
- run:
name: Run Rspec
command: |
TESTFILES=$(circleci tests glob "spec/**/*_spec.rb" | circleci tests split --split-by=timings)
bundle exec rspec --format documentation \
--format RspecJunitFormatter \
-o ~/rspec/rspec.xml \
-- ${TESTFILES}
- store_test_results:
path: ~/rspec
- store_artifacts:
path: tmp/capybara

jobs:
run_test: &run_test
bundle:
<<: *defaults
steps: &default_steps
steps:
- checkout
- restore_cache:
keys:
- << parameters.restore_cache_key_1 >>
- << parameters.restore_cache_key_2 >>
- spree-storefront-bundle-{{ checksum ".ruby-version" }}-{{ .Branch }}
- spree-storefront-bundle-{{ checksum ".ruby-version" }}
- run:
name: Allow executing given file
command: chmod +x << parameters.run_file_path >>
name: Add keyserver
command: sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 4EB27DB2A3B88B8B
- run:
name: Run << parameters.run_file_path >> file
command: bash << parameters.run_file_path >>
- when:
condition: << parameters.save_cache_key >>
steps:
- save_cache:
key: << parameters.save_cache_key >>
paths:
- ~/spree/vendor/bundle
- when:
condition: << parameters.store_artefacts >>
steps:
- store_artifacts:
path: /tmp/test-artifacts
destination: test-artifacts
- store_artifacts:
path: /tmp/test-results
destination: raw-test-output
- store_test_results:
path: ~/rspec

tests_postgres:
<<: *run_test
parallelism: << parameters.parallelism >>
parameters:
<<: *default_parameters
postgres_image:
type: string
parallelism:
type: integer
default: 8
environment:
<<: *environment
DB: postgres
DB_HOST: localhost
DB_USERNAME: postgres
docker:
- image: *ruby_image
- image: << parameters.postgres_image >>
environment:
POSTGRES_USER: postgres
- image: *redis_image
name: Install libvips
command: sudo apt-get update && sudo apt-get install libvips
- run:
name: Set bundle path
command: bundle config --local path vendor/bundle
- run:
name: Bundle Install
command: |
bundle check || bundle install
- save_cache:
paths:
- vendor/bundle
key: spree-storefront-bundle-{{ checksum ".ruby-version" }}-{{ .Branch }}

tests_mysql:
<<: *run_test
parallelism: << parameters.parallelism >>
parameters:
<<: *default_parameters
mysql_image:
type: string
parallelism:
type: integer
default: 8
environment:
<<: *run_tests
environment: &mysql_environment
<<: *environment
DB: mysql
DB_HOST: 127.0.0.1
Expand All @@ -111,70 +89,29 @@ jobs:
COVERAGE_DIR: /tmp/workspace/simplecov
docker:
- image: *ruby_image
- image: *redis_image
- image: << parameters.mysql_image >>
command: [--default-authentication-plugin=mysql_native_password]

send_test_coverage:
<<: *defaults
steps:
- checkout
- attach_workspace:
at: /tmp/workspace
- run:
name: Allow executing given file
command: chmod +x << parameters.run_file_path >>
- run:
name: Send test coverage
command: bash << parameters.run_file_path >>
- image: cimg/mysql:8.0

tests_postgres:
<<: *run_tests
environment: &postgres_environment
<<: *environment
DB: postgres
DB_HOST: localhost
DB_USERNAME: postgres
docker:
- image: *ruby_image
- image: cimg/postgres:16.2
environment:
POSTGRES_USER: postgres

workflows:
version: 2
main:
jobs:
- run_test:
name: bundle_ruby_3_0
restore_cache_key_1: "spree-dashboard-bundle-v10-ruby-3-0-{{ .Branch }}"
restore_cache_key_2: "spree-dashboard-bundle-v10-ruby-3-0"
ruby_image: circleci/ruby:3.0-node-browsers
redis_image: circleci/redis:6.2-alpine
run_file_path: ./bin/bundle_ruby_3_0.sh
save_cache_key: spree-dashboard-bundle-v10-ruby-3-0-{{ checksum "Gemfile.lock" }}
- run_test:
name: bundle_ruby_3_2
ruby_image: cimg/ruby:3.2.0-browsers
redis_image: circleci/redis:6.2-alpine
run_file_path: ./bin/bundle_ruby.sh
save_cache_key: spree-dashboard-bundle-v10-ruby-3-2-{{ checksum "Gemfile.lock" }}
- bundle
- tests_postgres:
name: tests_ruby_3_2_rails_7_1_postgres
rails_version: '~> 7.1.0'
ruby_image: cimg/ruby:3.2.0-browsers
redis_image: circleci/redis:6.2-alpine
postgres_image: circleci/postgres:12-alpine
store_artefacts: true
run_file_path: ./bin/tests_database_ci.sh
requires:
- bundle_ruby_3_2
- tests_postgres:
name: tests_ruby_3_0_rails_7_0_postgres
rails_version: '~> 7.0.0'
ruby_image: circleci/ruby:3.0-node-browsers
redis_image: circleci/redis:6.2-alpine
postgres_image: circleci/postgres:12-alpine
store_artefacts: true
run_file_path: ./bin/tests_database_ci.sh
requires:
- bundle_ruby_3_0
- bundle
- tests_mysql:
name: tests_ruby_3_2_rails_7_1_mysql
rails_version: '~> 7.1.0'
ruby_image: cimg/ruby:3.2.0-browsers
redis_image: circleci/redis:6.2-alpine
mysql_image: circleci/mysql:8-ram
store_artefacts: true
run_file_path: ./bin/tests_database_ci.sh
requires:
- bundle_ruby_3_2

- bundle
1 change: 1 addition & 0 deletions .ruby-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.3.0
5 changes: 3 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ end
platforms :ruby do
if ENV['DB'] == 'mysql'
gem 'mysql2'
elsif ENV['DB'] == 'postgres'
gem 'pg'
else
gem 'pg', '~> 1.1'
gem 'sqlite3'
end
end

Expand Down Expand Up @@ -56,7 +58,6 @@ group :test, :development do
end

group :development do
gem 'github_fast_changelog'
gem 'solargraph'
end

Expand Down
35 changes: 1 addition & 34 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

# Spree Admin Dashboard

This is the default Spree Admin Dashboard.
This is the default Spree Admin Dashboard.

## Developed by

Expand Down Expand Up @@ -51,39 +51,6 @@ Spree Admin Dashboard is an open source project and we love contributions in any

Please review the [Spree Contributing Guide](https://dev-docs.spreecommerce.org/contributing/index)

### Development Setup (JavaScript)

When working on the JavaScript in Spree Dashboard locally, you will need to yarn link your local development copy of `@spree/dashboard`, to the Rails app you are working in, so that your changes are picked up and represented live in the view.


From the root of `spree_backend` run:

```bash
yarn link
```

Next, from the root of the Rails app you are using to develop run:

```bash
yarn link "@spree/dashboard"
```

Once your local Spree Dashboard is linked with the Rails app you are using for development you will need two terminal tabs open,
one at the root of your Rails app, and one at the root of `spree_backend`.

In the terminal window at the root of the `spree_backend` run:

```bash
yarn watch
```

And from the Rails app you are using to run Spree and develop in run the following:

```bash
bin/dev
```
Any changes made to the JavaScript files in `spree_backend` will be processed by yarn and picked up in the Rails app you are running for development.

### Local setup

1. Fork it!
Expand Down
2 changes: 1 addition & 1 deletion app/assets/config/spree_backend_manifest.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//= link_tree ../images

//= link spree-dashboard.js
//= link sortablejs.js
//= link spree/backend/all.js
//= link spree/backend/all.css

Expand Down
3 changes: 3 additions & 0 deletions app/assets/javascripts/spree/backend.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
//= require tinymce
//= require underscore-min.js
//= require jsonapi-serializer.min
//= require popper
//= require bootstrap-sprockets
//= require flatpickr

//= require spree/backend/global/_index

Expand Down
1 change: 1 addition & 0 deletions app/assets/javascripts/spree/backend/global/_index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//= require spree/backend/global/tooltips
//= require spree/backend/global/alerts
//= require spree/backend/global/animate_css
//= require spree/backend/global/fetch_request_utility
Expand Down
21 changes: 21 additions & 0 deletions app/assets/javascripts/spree/backend/global/tooltips.es6
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const initTooltips = () => {
$('.with-tip').each(function() {
$(this).tooltip()
})

$('.with-tip').on('show.bs.tooltip', function(event) {
if (('ontouchstart' in window)) {
event.preventDefault()
}
})
}

const removeTooltips = () => {
$('.with-tip').each(function() {
$(this).tooltip('dispose')
})
}

document.addEventListener("turbo:click", removeTooltips)
document.addEventListener("turbo:load", initTooltips)
document.addEventListener('turbo:frame-render', initTooltips)
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,4 @@ export function patch (url, options) {
export function destroy (url, options) {
const request = new FetchRequest("delete", url, options)
return withProgress(request.perform())
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Controller } from "@hotwired/stimulus"
import { Sortable } from "sortablejs"
import { patch } from "../utilities/request_utility"
import { patch } from "./request_utility"


export default class extends Controller {
static values = { handle: String }
Expand Down
Loading

0 comments on commit 65dca50

Please sign in to comment.