Skip to content

Commit

Permalink
Remove our npm package and all related code
Browse files Browse the repository at this point in the history
We now serve the admin js via importmaps.
Look at this diff. Nothing else to add.
  • Loading branch information
tvdeyen committed Jun 29, 2023
1 parent c774564 commit a8d3152
Show file tree
Hide file tree
Showing 19 changed files with 27 additions and 222 deletions.
5 changes: 0 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,10 @@ pkg
tmp
log
.sass-cache
spec/dummy/app/assets/builds/*.js*
spec/dummy/app/javascript/
spec/dummy/config/alchemy/config.yml
spec/dummy/db/*.sqlite3*
spec/dummy/package.json
spec/dummy/postcss.config.js
spec/dummy/public/assets/
spec/dummy/public/packs/
spec/dummy/public/packs-test/
spec/dummy/uploads/
.rvmrc
/coverage/
Expand Down
1 change: 0 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ group :development, :test do
# in our case the culprit is `handlebars-assets`. The changes between 2.7.0 and 2.8.0 are
# minimal, but breaking.
gem "execjs", "= 2.8.1"
gem "jsbundling-rails", "~> 1.1"
gem "rubocop", require: false
gem "standard", "~> 1.25", require: false

Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ $ bin/start

### Bump version

Bump the version number in both `lib/alchemy/version.rb` and `./package.json`. Make sure both are exactly the same and follow [SemVer format](https://semver.org/#semantic-versioning-specification-semver).
Bump the version number in `lib/alchemy/version.rb`.

### Update the changelog

Expand All @@ -357,11 +357,11 @@ $ git commit -am "Bump version to vX.Y.Z"

### Release a new version

This task will publish both the ruby gem and the npm package.
This task will publish the ruby gem.
It also tags the latest commit.

```bash
$ bundle exec rake alchemy:release
$ bundle exec rake release
```

## ❓Getting Help
Expand Down
19 changes: 0 additions & 19 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,12 @@ namespace :alchemy do
task :prepare do
system(
<<~BASH
yarn install && \
yarn link && \
cd spec/dummy && \
export RAILS_ENV=test && \
bin/rake db:create && \
bin/rake db:environment:set && \
bin/rake db:migrate:reset && \
bin/rails javascript:install:esbuild && \
bin/rails g alchemy:install --skip --skip-demo-files --auto-accept --skip-db-create && \
yarn link @alchemy_cms/admin && \
bin/rails javascript:build && \
cd -
BASH
) || fail
Expand Down Expand Up @@ -81,18 +76,4 @@ namespace :alchemy do
File.delete(backup)
end
end

desc "Release a new Ruby gem and npm package in one command"
task :release do
require "json"
require_relative "lib/alchemy/version"
package = File.read("package.json")
unless JSON.parse(package)["version"] == Alchemy.version
abort "Ruby gem and npm package versions are out of sync! Please fix."
end
# Release the Ruby gem with bundler
Rake::Task["release"].invoke
# Publish npm package via CLI
system "npm publish"
end
end
9 changes: 0 additions & 9 deletions bin/setup
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,14 @@ def system!(*args)
end

FileUtils.chdir GEM_ROOT do
puts "\n== Linking Admin JS package =="
system! "yarn link"
puts "== Installing dependencies =="
system! "yarn install"
system! "gem install bundler --conservative"
system("bundle check") || system!("bundle install")
end

FileUtils.chdir APP_ROOT do
puts "\n== Installing Alchemy into dummy app =="
system!("bin/rails javascript:install:esbuild")
system!("bin/rails g alchemy:install --skip --skip-demo-files --auto-accept")

puts "\n== Link Alchemy admin package =="
system! "yarn link @alchemy_cms/admin"
system! "yarn install"

puts "\n== Removing old logs and tempfiles =="
system! "bin/rails log:clear tmp:clear"
end
Expand Down
2 changes: 1 addition & 1 deletion bin/start
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ end

FileUtils.chdir APP_ROOT do
puts "\n== Starting dummy app =="
system! "bin/dev"
system! "bin/rails server"
end
46 changes: 0 additions & 46 deletions config/brakeman.ignore
Original file line number Diff line number Diff line change
Expand Up @@ -80,29 +80,6 @@
],
"note": ""
},
{
"warning_type": "Command Injection",
"warning_code": 14,
"fingerprint": "6addfcb9d23d2d6f699f2f3542169744ff749dc4d0a97f8ac783ab92593e1d84",
"check_name": "Execute",
"message": "Possible command injection",
"file": "lib/alchemy/upgrader.rb",
"line": 33,
"link": "https://brakemanscanner.org/docs/warning_types/command_injection/",
"code": "`yarn add @alchemy_cms/admin@~#{Alchemy.version}`",
"render_path": null,
"location": {
"type": "method",
"class": "Alchemy::Upgrader",
"method": "update_npm_package"
},
"user_input": "Alchemy.version",
"confidence": "Medium",
"cwe_id": [
77
],
"note": "The alchemy version is safe"
},
{
"warning_type": "Cross-Site Scripting",
"warning_code": 4,
Expand Down Expand Up @@ -227,29 +204,6 @@
],
"note": ""
},
{
"warning_type": "Command Injection",
"warning_code": 14,
"fingerprint": "98ca8e77026312eaa7eec15ce26bfe45aa8dd0fcd38e4cff104cb9dffbde1733",
"check_name": "Execute",
"message": "Possible command injection",
"file": "lib/alchemy/upgrader.rb",
"line": 31,
"link": "https://brakemanscanner.org/docs/warning_types/command_injection/",
"code": "`bin/importmap pin @alchemy_cms/admin@~#{Alchemy.version}`",
"render_path": null,
"location": {
"type": "method",
"class": "Alchemy::Upgrader",
"method": "update_npm_package"
},
"user_input": "Alchemy.version",
"confidence": "Medium",
"cwe_id": [
77
],
"note": ""
},
{
"warning_type": "File Access",
"warning_code": 16,
Expand Down
11 changes: 0 additions & 11 deletions lib/alchemy/upgrader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,6 @@ def copy_new_config_file
todo "Check the default configuration file (./config/alchemy/config.yml.defaults) for new configuration options and insert them into your config file.", "Configuration has changed"
end
end

def update_npm_package
desc "Update npm package."
if File.exist? Rails.root.join("config/importmap.rb")
`bin/importmap pin @alchemy_cms/admin@~#{Alchemy.version}`
elsif File.exist? Rails.root.join("package.json")
`yarn add @alchemy_cms/admin@~#{Alchemy.version}`
else
log("Could not update alchemy admin package! Make sure you have a JS bundler installed", :warning)
end
end
end
end
end
36 changes: 13 additions & 23 deletions lib/alchemy/upgrader/seven_point_zero.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,20 @@ class Upgrader::SevenPointZero < Upgrader
include Thor::Actions

class << self
def update_admin_entrypoint
if File.exist? "app/javascript/packs/alchemy/admin.js"
FileUtils.mv "app/javascript/packs/alchemy/admin.js", "app/javascript/alchemy_admin.js"
else
log "Skipping. No alchemy/admin entrypoint found. Maybe already migrated from Webpacker?", :info
end
if Dir.exist?("app/javascript/packs/alchemy") && Dir.empty?("app/javascript/packs/alchemy")
FileUtils.rm_r "app/javascript/packs/alchemy"
end
if File.exist? "config/importmap.rb"
# We want the bundled package if using importmaps
task.gsub_file "app/javascript/alchemy_admin.js", 'import "@alchemy_cms/admin"', 'import "@alchemy_cms/dist/admin"'
end
if task.ask("Do you want to remove webpacker now? (y/N)", default: "N") == "y"
def remove_admin_entrypoint
FileUtils.rm_rf "app/javascript/packs/alchemy/admin.js"
FileUtils.rm_rf "app/javascript/packs/alchemy_admin.js"
FileUtils.rm_rf "app/javascript/packs/alchemy"
FileUtils.rm_rf "app/javascript/packs/alchemy"
task.run "yarn remove @alchemy_cms/admin"
if task.ask("Do you want to remove webpacker as well? (y/N)", default: "N") == "y"
task.run "bundle remove webpacker"
task.run "yarn remove @rails/webpacker webpack webpack-cli webpack-dev-server"
FileUtils.rm_r "app/javascript/packs"
FileUtils.rm_r "config/webpack"
FileUtils.rm "config/webpacker.yml"
FileUtils.rm "bin/webpack"
FileUtils.rm "bin/webpack-dev-server"
end
if task.ask("Do you want to add jsbundling-rails now? (Y/n)", default: "Y") == "Y"
task.run "bundle add jsbundling-rails"
task.run "bin/rails javascript:install:esbuild"
FileUtils.rm_rf "app/javascript/packs"
FileUtils.rm_rf "config/webpack"
FileUtils.rm_f "config/webpacker.yml"
FileUtils.rm_f "bin/webpack"
FileUtils.rm_f "bin/webpack-dev-server"
end
end

Expand Down
24 changes: 0 additions & 24 deletions lib/generators/alchemy/install/install_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,30 +99,6 @@ def install_gutentag_migrations
rake "gutentag:install:migrations"
end

def add_npm_package
if File.exist? app_root.join("package.json")
run "yarn add @alchemy_cms/admin@~#{Alchemy.version}"
elsif File.exist? app_root.join("config/importmap.rb")
run "bin/importmap pin @alchemy_cms/admin@~#{Alchemy.version}"
else
log("Could not add alchemy admin package! Make sure you have a JS bundler installed", :warning)
end
end

def copy_alchemy_entry_point
if Dir.exist? app_root.join("app/javascript")
if File.exist? app_root.join("config/importmap.rb")
# We want the bundled package if using importmaps
create_file app_root.join("app/javascript/alchemy_admin.js"), 'import "@alchemy_cms/dist/admin"'
else
# We want the normal package if using a bundler locally
create_file app_root.join("app/javascript/alchemy_admin.js"), 'import "@alchemy_cms/admin"'
end
else
log("Could not add alchemy admin entry point! Make sure you have a JS bundler installed", :warning)
end
end

def set_primary_language
header
install_tasks.set_primary_language(
Expand Down
18 changes: 6 additions & 12 deletions lib/tasks/alchemy/upgrade.rake
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ namespace :alchemy do
desc "Alchemy Upgrader: Prepares the database and updates Alchemys configuration file."
task prepare: [
"alchemy:upgrade:database",
"alchemy:upgrade:config",
"alchemy:upgrade:package"
"alchemy:upgrade:config"
]

desc "Alchemy Upgrader: Prepares the database."
Expand All @@ -31,11 +30,6 @@ namespace :alchemy do
Alchemy::Upgrader.copy_new_config_file
end

desc "Alchemy Upgrader: Install new Node package."
task package: [:environment] do
Alchemy::Upgrader.update_npm_package
end

desc "Upgrade Alchemy to v7.0"
task "7.0" => [
"alchemy:upgrade:prepare",
Expand All @@ -46,13 +40,13 @@ namespace :alchemy do

namespace "7.0" do
task "run" => [
"alchemy:upgrade:7.0:update_admin_entrypoint"
"alchemy:upgrade:7.0:remove_admin_entrypoint"
]

desc "Update alchemy admin entrypoint"
task update_admin_entrypoint: [:environment] do
puts "adding npm_package..."
Alchemy::Upgrader::SevenPointZero.update_admin_entrypoint
desc "Remove alchemy admin entrypoint"
task remove_admin_entrypoint: [:environment] do
puts "removing npm_package..."
Alchemy::Upgrader::SevenPointZero.remove_admin_entrypoint
end
end
end
Expand Down
29 changes: 4 additions & 25 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,41 +1,20 @@
{
"name": "@alchemy_cms/admin",
"version": "7.0.0-b",
"description": "AlchemyCMS",
"browser": "package/dist/admin.js",
"files": [
"package/**/*"
],
"directories": {
"lib": "package"
},
"scripts": {
"test": "jest",
"build": "esbuild package/admin.js --bundle --sourcemap --minify --outdir=package/dist --public-path=assets"
},
"repository": {
"type": "git",
"url": "git+https://github.com/AlchemyCMS/alchemy_cms.git"
"test": "jest"
},
"keywords": [],
"author": "Thomas von Deyen",
"license": "BSD-3-Clause",
"bugs": {
"url": "https://github.com/AlchemyCMS/alchemy_cms/issues"
},
"homepage": "https://github.com/AlchemyCMS/alchemy_cms#readme",
"dependencies": {
"flatpickr": "^4.6.9",
"lodash-es": "^4.17.21",
"sortablejs": "^1.10.2"
},
"devDependencies": {
"@babel/core": "^7.9.6",
"@babel/preset-env": "^7.9.6",
"babel-jest": "^29.0.1",
"esbuild": "^0.18.4",
"flatpickr": "^4.6.9",
"jest": "^25.2.7",
"lodash-es": "^4.17.21",
"prettier": "^2.0.2",
"sortablejs": "^1.10.2",
"xhr-mock": "^2.5.1"
},
"jest": {
Expand Down
16 changes: 0 additions & 16 deletions package/dist/admin.js

This file was deleted.

7 changes: 0 additions & 7 deletions package/dist/admin.js.map

This file was deleted.

2 changes: 0 additions & 2 deletions spec/dummy/Procfile.dev

This file was deleted.

Empty file removed spec/dummy/app/assets/builds/.keep
Empty file.
1 change: 0 additions & 1 deletion spec/dummy/app/assets/config/manifest.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@
//
//= link application.css
//= link application.js
//= link_tree ../builds
//= link_tree ../images
8 changes: 0 additions & 8 deletions spec/dummy/bin/dev

This file was deleted.

9 changes: 0 additions & 9 deletions spec/dummy/bin/setup
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,6 @@ def system!(*args)
system(*args) || abort("\n== Command #{args} failed ==")
end

FileUtils.chdir GEM_ROOT do
puts "\n== Linking Admin JS package =="
system! "yarn link"
end

FileUtils.chdir APP_ROOT do
# This script is a way to set up or update your development environment automatically.
# This script is idempotent, so that you can run it at any time and get an expectable outcome.
Expand All @@ -25,10 +20,6 @@ FileUtils.chdir APP_ROOT do
system! "gem install bundler --conservative"
system("bundle check") || system!("bundle install")

puts "\n== Installing Node dependencies =="
system! "yarn link @alchemy_cms/admin"
system! "yarn install"

puts "\n== Preparing database =="
system! "bin/rails db:prepare"

Expand Down

0 comments on commit a8d3152

Please sign in to comment.