Skip to content

Commit ec3622c

Browse files
authored
Chore: decidim 029 (#109)
* chore: update to 0.27.9 version * fix: docker build and voca overload system * chore: add decidim-awesome * chore: move to shakapacker
1 parent a82ae6c commit ec3622c

32 files changed

+31859
-22356
lines changed

.gitignore

+7-1
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,10 @@ vendor
4040
.bash_history
4141
node_modules
4242
.npm
43-
.bash_history
43+
.bash_history
44+
/public/packs
45+
/public/packs-test
46+
/node_modules
47+
/yarn-error.log
48+
yarn-debug.log*
49+
.yarn-integrity

.node-version

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
16.20.2
1+
20.18.2

.yarn/install-state.gz

1.31 MB
Binary file not shown.

.yarnrc.yml

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
nodeLinker: node-modules

Dockerfile

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM octree/voca-decidim:0.27-bullseye
1+
FROM octree/voca-decidim:0.29-bullseye
22
ENV PM2_RUN="decidim,daily,monthly" \
33
ROOT="/home/decidim/app" \
44
NODE_ENV=development \
@@ -23,7 +23,9 @@ RUN NODE_MAJOR_VERSION=$(cut -d '.' -f1 /home/decidim/app/.node-version) \
2323
&& apt-get update -yq \
2424
&& apt-get install -yq --no-upgrade nodejs \
2525
&& export SECRET_KEY_BASE=assets \
26+
&& bundle config set deployment false \
2627
&& bundle install \
28+
&& patch-gemlock \
2729
&& apt-get update -yq \
2830
# Install native deps
2931
&& apt-get install -yq nginx \

Dockerfile.dev

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM hfroger/decidim:0.27-dev
1+
FROM hfroger/decidim:0.29-dev
22
ENV RAILS_ENV=development \
33
NODE_ENV=development \
44
ROOT=/home/decidim/app

bin/compile-assets

+83
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
#!/bin/bash
2+
3+
set -e # Exit immediately on error
4+
5+
# Default values
6+
FORCE=false
7+
QUIET=false
8+
UPGRADE=false
9+
HELP=false
10+
ROOT=$(pwd) # Default to current directory
11+
12+
# Print usage
13+
usage() {
14+
echo "Usage: $0 [-f|--force] [-q|--quiet] [--upgrade] [-h|--help]"
15+
echo ""
16+
echo "Options:"
17+
echo " -f, --force If 'public/decidim-packs' exists, move it to 'public/<oldfilename>.<date>.bak' and compile"
18+
echo " -q, --quiet Suppress all log output"
19+
echo " --upgrade Run 'bundle exec rails decidim:upgrade' before compiling assets"
20+
echo " -h, --help Display this help message"
21+
exit 0
22+
}
23+
24+
# Parse arguments
25+
while [[ "$#" -gt 0 ]]; do
26+
case $1 in
27+
-f|--force) FORCE=true ;;
28+
-q|--quiet) QUIET=true ;;
29+
--upgrade) UPGRADE=true ;;
30+
-h|--help) HELP=true ;;
31+
*) echo "Unknown parameter passed: $1"; usage ;;
32+
esac
33+
shift
34+
done
35+
36+
# Display help if needed
37+
if [ "$HELP" = true ]; then
38+
usage
39+
fi
40+
41+
# Log function, suppress output if QUIET is enabled
42+
log() {
43+
if [ "$QUIET" = false ]; then
44+
echo "$1"
45+
fi
46+
}
47+
48+
# Force option: Backup and move decidim-packs
49+
if [ "$FORCE" = true ]; then
50+
if [ -d "$ROOT/public/decidim-packs" ]; then
51+
TIMESTAMP=$(date +%Y%m%d%H%M%S)
52+
BACKUP_DIR="$ROOT/public/decidim-packs.$TIMESTAMP.bak"
53+
log "Backing up 'public/decidim-packs' to '$BACKUP_DIR'..."
54+
mv "$ROOT/public/decidim-packs" "$BACKUP_DIR"
55+
else
56+
log "'public/decidim-packs' does not exist, compiling."
57+
fi
58+
else
59+
if [ -d "$ROOT/public/decidim-packs" ]; then
60+
log "'public/decidim-packs' already exists, nothing to do."
61+
log "use '--force', '-f' options to force recompilation"
62+
exit 0
63+
fi
64+
fi
65+
66+
# Upgrade option
67+
if [ "$UPGRADE" = true ]; then
68+
log "Running 'bundle exec rails decidim:upgrade'..."
69+
bundle exec rails decidim:upgrade
70+
fi
71+
72+
# Install dependencies and precompile assets
73+
log "Installing Node.js dependencies..."
74+
NODE_ENV=development npm ci
75+
76+
log "Precompiling Rails assets..."
77+
NODE_ENV=development RAILS_ENV=production bundle exec rails assets:precompile
78+
79+
# Cleanup
80+
log "Cleaning up temporary files..."
81+
rm -rf .yarn .npm yarn.lock node_modules
82+
83+
log "Assets compilation completed successfully."

bin/patch-gemlock

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#! /bin/bash
2+
set -e
3+
4+
sed -i '/psych (.*)$/d' $ROOT/voca/Gemfile.lock
5+
sed -i '/openssl (.*)$/d' $ROOT/voca/Gemfile.lock

bin/setup

+3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ FileUtils.chdir APP_ROOT do
1717
system! 'gem install bundler --conservative'
1818
system('bundle check') || system!('bundle install')
1919

20+
# Install JavaScript dependencies
21+
system!("bin/yarn")
22+
2023
# Install JavaScript dependencies
2124
system! 'bin/yarn'
2225

bin/shakapacker

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/usr/bin/env ruby
2+
3+
ENV["RAILS_ENV"] ||= "development"
4+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", __FILE__)
5+
6+
require "bundler/setup"
7+
require "shakapacker"
8+
require "shakapacker/webpack_runner"
9+
10+
APP_ROOT = File.expand_path("..", __dir__)
11+
Dir.chdir(APP_ROOT) do
12+
Shakapacker::WebpackRunner.run(ARGV)
13+
end

bin/shakapacker-dev-server

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/usr/bin/env ruby
2+
3+
ENV["RAILS_ENV"] ||= "development"
4+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", __FILE__)
5+
6+
require "bundler/setup"
7+
require "shakapacker"
8+
require "shakapacker/dev_server_runner"
9+
10+
APP_ROOT = File.expand_path("..", __dir__)
11+
Dir.chdir(APP_ROOT) do
12+
Shakapacker::DevServerRunner.run(ARGV)
13+
end

bin/webpack-dev-server

-21
This file was deleted.

bin/yarn

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/usr/bin/env ruby
2+
3+
APP_ROOT = File.expand_path("..", __dir__)
4+
Dir.chdir(APP_ROOT) do
5+
yarn = ENV["PATH"].split(File::PATH_SEPARATOR).
6+
select { |dir| File.expand_path(dir) != __dir__ }.
7+
product(["yarn", "yarnpkg", "yarn.cmd", "yarn.ps1"]).
8+
map { |dir, file| File.expand_path(file, dir) }.
9+
find { |file| File.executable?(file) }
10+
11+
if yarn
12+
exec yarn, *ARGV
13+
else
14+
$stderr.puts "Yarn executable was not detected in the system."
15+
$stderr.puts "Download Yarn at https://yarnpkg.com/en/docs/install"
16+
exit 1
17+
end
18+
end

config/initializers/session_store.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Rails.application.config.session_store :active_record_store, :key => '_decidim_session'
1+
# Rails.application.config.session_store :active_record_store, :key => '_decidim_session'

config/initializers/sitemap.rb

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
Decidim::Sitemaps.configure do |config|
2-
config.users = { enabled: false, changefreq: "daily", priority: 0.5 }
3-
# @see defaults https://git.fpfis.tech.ec.europa.eu/future-of-europe/digit-cofe-libraries/digit-cofe-sitemap/-/blob/master/lib/decidim/sitemaps.rb?ref_type=heads
4-
end
1+
if defined?(Decidim::Sitemaps)
2+
Decidim::Sitemaps.configure do |config|
3+
config.users = { enabled: false, changefreq: "daily", priority: 0.5 }
4+
# @see defaults https://git.fpfis.tech.ec.europa.eu/future-of-europe/digit-cofe-libraries/digit-cofe-sitemap/-/blob/master/lib/decidim/sitemaps.rb?ref_type=heads
5+
end
6+
end

config/initializers/social_share_button.rb

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
# Further information on how to configure the SocialShareButton gem can be
44
# found here: https://github.com/huacnlee/social-share-button#configure
5-
#
6-
SocialShareButton.configure do |config|
7-
config.allow_sites = %w(twitter facebook whatsapp_app whatsapp_web telegram)
8-
end
5+
#
6+
# SocialShareButton.configure do |config|
7+
# config.allow_sites = %w(twitter facebook whatsapp_app whatsapp_web telegram)
8+
# end

config/webpacker.yml config/shakapacker.yml

+26-2
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,15 @@
44
default: &default
55
source_path: app/packs
66
source_entry_path: entrypoints
7-
public_output_path: decidim-packs
7+
nested_entries: true
8+
css_extract_ignore_order_warnings: false
9+
810
public_root_path: public
11+
public_output_path: decidim-packs
12+
cache_path: tmp/shakapacker
913
webpack_compile_output: true
10-
cache_path: tmp/webpacker-cache
1114
extract_css: true
15+
shakapacker_precompile: true
1216

1317
additional_paths:
1418
- node_modules
@@ -17,9 +21,24 @@ default: &default
1721
# Reload manifest.json on all requests so we reload latest compiled packs
1822
cache_manifest: false
1923

24+
# Select loader to use, available options are 'babel' (default), 'swc' or 'esbuild'
25+
webpack_loader: 'esbuild'
26+
27+
# Set to true to enable check for matching versions of shakapacker gem and NPM package - will raise an error if there is a mismatch or wildcard versioning is used
28+
ensure_consistent_versioning: true
29+
30+
# Select whether the compiler will use SHA digest ('digest' option) or most recent modified timestamp ('mtime') to determine freshness
31+
compiler_strategy: digest
32+
33+
# Select whether the compiler will always use a content hash and not just in production
34+
# Do not use contentHash except for production for performance
35+
# https://webpack.js.org/guides/build-performance/#avoid-production-specific-tooling
36+
useContentHash: false
37+
2038
development:
2139
<<: *default
2240
compile: true
41+
compiler_strategy: mtime
2342
# Compile test packs to decidim decidim-packs folder
2443

2544
# Reference: https://webpack.js.org/configuration/dev-server/
@@ -31,6 +50,8 @@ development:
3150
port: 3035
3251
# Hot Module Replacement updates modules while the application is running without a full reload
3352
hmr: false
53+
# mini-css-extract-plugin is a required dependency in both cases.
54+
inline_css: true
3455
client:
3556
# Should we show a full-screen overlay in the browser when there are compiler errors or warnings?
3657
overlay: false
@@ -61,5 +82,8 @@ production:
6182
# Production depends on precompilation of packs prior to booting for performance.
6283
compile: false
6384

85+
# Use content hash for naming assets. Cannot be overridden by for production.
86+
useContentHash: true
87+
6488
# Cache manifest.json for performance
6589
cache_manifest: true

config/webpack/base.js

-6
This file was deleted.

config/webpack/custom.js

+16-22
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,11 @@
11
/* eslint-disable */
2-
const { config } = require("@rails/webpacker");
2+
const { config } = require("shakapacker");
33
const { InjectManifest } = require("workbox-webpack-plugin");
4+
const { EsbuildPlugin } = require("esbuild-loader");
45

56
module.exports = {
67
module: {
78
rules: [
8-
{
9-
test: require.resolve("quill"),
10-
loader: "expose-loader",
11-
options: {
12-
exposes: ["Quill"]
13-
}
14-
},
159
{
1610
test: require.resolve("jquery"),
1711
loader: "expose-loader",
@@ -21,8 +15,8 @@ module.exports = {
2115
},
2216
{
2317
test: /\.(js|jsx)$/,
24-
exclude: /node_modules\/(?!tributejs)/,
25-
loader: "babel-loader"
18+
exclude: /node_modules\//,
19+
loader: "esbuild-loader"
2620
},
2721
{
2822
test: /\.(graphql|gql)$/,
@@ -43,14 +37,11 @@ module.exports = {
4337
}
4438
},
4539
{
46-
test: [
47-
/\.md$/,
48-
/\.odt$/,
49-
],
40+
test: [/\.md$/, /\.odt$/],
5041
exclude: [/\.(js|mjs|jsx|ts|tsx)$/],
51-
type: 'asset/resource',
42+
type: "asset/resource",
5243
generator: {
53-
filename: 'media/documents/[hash][ext][query]'
44+
filename: "media/documents/[hash][ext][query]"
5445
}
5546
},
5647
// Overwrite webpacker files rule to amend the filename output
@@ -74,9 +65,9 @@ module.exports = {
7465
/\.svg$/
7566
],
7667
exclude: [/\.(js|mjs|jsx|ts|tsx)$/],
77-
type: 'asset/resource',
68+
type: "asset/resource",
7869
generator: {
79-
filename: 'media/images/[name]-[hash][ext][query]'
70+
filename: "media/images/[name]-[hash][ext][query]"
8071
}
8172
}
8273
]
@@ -87,10 +78,13 @@ module.exports = {
8778
crypto: false
8879
}
8980
},
90-
// https://github.com/rails/webpacker/issues/2932
91-
// As Decidim uses multiple packs, we need to enforce a single runtime, to prevent duplication
9281
optimization: {
93-
runtimeChunk: false
82+
minimizer: [
83+
new EsbuildPlugin({
84+
target: "es2015",
85+
css: true
86+
})
87+
]
9488
},
9589
entry: config.entrypoints,
9690
plugins: [
@@ -106,4 +100,4 @@ module.exports = {
106100
swDest: "../sw.js"
107101
})
108102
]
109-
}
103+
};

config/webpack/development.js

-7
This file was deleted.

0 commit comments

Comments
 (0)