Skip to content

Commit

Permalink
Added ESbuild via JS Bundling gem (#18)
Browse files Browse the repository at this point in the history
* Setup Hotwire and NPM package

* fix install generator

* Setup ESlint
  • Loading branch information
damianlegawiec authored Nov 7, 2021
1 parent e8d7187 commit 61ee3e7
Show file tree
Hide file tree
Showing 17 changed files with 1,096 additions and 48 deletions.
8 changes: 8 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ run_tests: &run_tests
name: Create test app
command: |
bundle exec rake test_app
- run:
name: Unlink NPM package
command: |
cd spec/dummy && yarn unlink @spree/dashboard
- run:
name: Run Rspec
command: |
Expand Down Expand Up @@ -71,6 +75,10 @@ run_tests_3_0: &run_tests_3_0
name: Create test app
command: |
bundle exec rake test_app
- run:
name: Unlink NPM package
command: |
cd spec/dummy && yarn unlink @spree/dashboard
- run:
name: Run Rspec
command: |
Expand Down
4 changes: 2 additions & 2 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
**/vendor/**
**/dummy/**
**/sandbox/**
*-min.js
*.min.js
jquery*.js
/cli/lib/spree_cli/templates/**
app/assets/javascripts

36 changes: 0 additions & 36 deletions .eslintrc

This file was deleted.

29 changes: 29 additions & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
module.exports = {
"env": {
"browser": true,
"es2021": true
},
"extends": "eslint:recommended",
"parserOptions": {
"ecmaVersion": 13,
"sourceType": "module"
},
"rules": {
"indent": [
"error",
2
],
"linebreak-style": [
"error",
"unix"
],
"quotes": [
"error",
"double"
],
"semi": [
"error",
"never"
]
}
}
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,9 @@ vendor/bundle
*/vendor/bundle
.ignore
TODO


node_modules
app/assets/javascripts/spree_dashboard.js
app/assets/javascripts/spree_dashboard.*.js
src
9 changes: 9 additions & 0 deletions app/javascript/spree/dashboard/controllers/application.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { Application } from "@hotwired/stimulus"

const application = Application.start()

// Configure Stimulus development experience
application.debug = false
window.Stimulus = application

export { application }
10 changes: 10 additions & 0 deletions app/javascript/spree/dashboard/controllers/hello_controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Controller } from "@hotwired/stimulus"

export default class extends Controller {
static targets = [ "name", "output" ]

greet() {
this.outputTarget.textContent =
`Hello, ${this.nameTarget.value}!`
}
}
7 changes: 7 additions & 0 deletions app/javascript/spree/dashboard/controllers/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// This file is auto-generated by ./bin/rails stimulus:manifest:update
// Run that command whenever you add a new controller

import { application } from "./application"

import HelloController from "./hello_controller"
application.register("hello", HelloController)
13 changes: 13 additions & 0 deletions app/javascript/spree/dashboard/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import "./controllers"
// import * as Turbo from "@hotwired/turbo"

class Dashboard {
constructor() {
console.log("Spree Dashboard initialized")
}
}

export {
Dashboard
// Turbo
}
1 change: 1 addition & 0 deletions app/views/spree/admin/shared/_head.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<%= stylesheet_link_tag 'spree/backend/all', media: :all %>

<%= render 'spree/admin/shared/paths' %>
<%= javascript_include_tag "spree-dashboard", defer: true %>
<%= javascript_include_tag 'spree/backend/all' %>
<%= render "spree/admin/shared/translations" %>

Expand Down
4 changes: 3 additions & 1 deletion lib/generators/spree/backend/install/install_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module Spree
module Backend
module Generators
class InstallGenerator < Rails::Generators::Base
desc 'Installs spree rails admin panel'
desc 'Installs Spree Dashboard'

def self.source_paths
[
Expand All @@ -13,8 +13,10 @@ def self.source_paths
end

def install
template 'app/javascript/spree-dashboard.js'
template 'vendor/assets/javascripts/spree/backend/all.js'
template 'vendor/assets/stylesheets/spree/backend/all.css'
run 'yarn add @spree/dashboard'
end
end
end
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Entry point for the build script in your package.json

import "@spree/dashboard"

new SpreeDashboard.Dashboard()

// window.Turbo = SpreeDashboard.Turbo
2 changes: 2 additions & 0 deletions lib/spree/backend.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
require 'flatpickr'
require 'bootstrap'
require 'glyphicons'
require 'hotwire-rails'
require 'popper_js'
require 'inline_svg'
require 'jsbundling-rails'
require 'responders'
require 'tinymce-rails'

Expand Down
38 changes: 38 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"name": "@spree/dashboard",
"version": "0.0.1-alpha1",
"description": "Spree Dashboard",
"main": "app/assets/javascripts/spree_dashboard.js",
"type": "module",
"files": [
"app/assets/javascripts/*.js",
"src/*.js"
],
"homepage": "https://spreecommerce.org/",
"repository": {
"type": "git",
"url": "git+https://github.com/spree/spree_backend.git"
},
"bugs": {
"url": "https://github.com/spree/spree_backend/issues"
},
"author": "Spark Solutions <hi@sparksolutions.co>",
"license": "MIT",
"dependencies": {
"@hotwired/stimulus": "^3.0.1",
"@hotwired/turbo": "^7.0.1"
},
"devDependencies": {
"@rollup/plugin-commonjs": "^19.0.1",
"@rollup/plugin-node-resolve": "^11.0.1",
"eslint": "^8.2.0",
"rollup": "^2.35.1",
"rollup-plugin-terser": "^7.0.2"
},
"scripts": {
"build": "rollup --config rollup.config.js",
"watch": "rollup --config rollup.config.js -w",
"lint": "eslint app/javascript",
"prepublishOnly": "rm -rf src && cp -R app/javascript/spree_dashboard src"
}
}
41 changes: 41 additions & 0 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import resolve from "@rollup/plugin-node-resolve"
import commonjs from "@rollup/plugin-commonjs"
import { terser } from "rollup-plugin-terser"

const terserOptions = {
mangle: false,
compress: false,
format: {
beautify: true,
indent_level: 2
}
}

export default [
{
input: "app/javascript/spree/dashboard/index.js",
output: {
file: "app/assets/javascripts/spree_dashboard.js",
format: "umd",
name: "SpreeDashboard"
},
plugins: [
resolve(),
commonjs(),
terser(terserOptions)
]
},

{
input: "app/javascript/spree/dashboard/index.js",
output: {
file: "app/assets/javascripts/spree_dashboard.esm.js",
format: "es"
},
plugins: [
resolve(),
commonjs(),
terser(terserOptions)
]
}
]
20 changes: 11 additions & 9 deletions spree_backend.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,17 @@ Gem::Specification.new do |s|
s.add_dependency 'spree', ">= 4.3.0"

s.add_dependency 'babel-transpiler', '~> 0.7'
s.add_dependency 'bootstrap', '~> 4.0'
s.add_dependency 'glyphicons', '~> 1.0'
s.add_dependency 'flatpickr', '~> 4.6'
s.add_dependency 'inline_svg', '~> 1.5'
s.add_dependency 'jquery-rails', '~> 4.3'
s.add_dependency 'jquery-ui-rails', '~> 6.0'
s.add_dependency 'bootstrap', '~> 4.0'
s.add_dependency 'glyphicons', '~> 1.0'
s.add_dependency 'flatpickr', '~> 4.6'
s.add_dependency 'hotwire-rails'
s.add_dependency 'inline_svg', '~> 1.5'
s.add_dependency 'jsbundling-rails'
s.add_dependency 'jquery-rails', '~> 4.3'
s.add_dependency 'jquery-ui-rails', '~> 6.0'
s.add_dependency 'responders'
s.add_dependency 'sass-rails', '>= 5'
s.add_dependency 'select2-rails', '~> 4.0'
s.add_dependency 'sprockets', '~> 4.0'
s.add_dependency 'sass-rails', '>= 5'
s.add_dependency 'select2-rails', '~> 4.0'
s.add_dependency 'sprockets', '~> 4.0'
s.add_dependency 'tinymce-rails'
end
Loading

0 comments on commit 61ee3e7

Please sign in to comment.