Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

install generator: Add option to force patched babel config #2495

Merged
merged 1 commit into from
Jun 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ namespace :alchemy do
bin/rake db:create && \
bin/rake db:environment:set && \
bin/rake db:migrate:reset && \
bin/rails g alchemy:install --skip --skip-demo-files --auto-accept --skip-db-create && \
bin/rails g alchemy:install --skip --skip-demo-files --auto-accept --skip-db-create --force-babel-config && \
yarn link @alchemy_cms/admin && \
RAILS_ENV=test bin/webpack && \
cd -
Expand Down
64 changes: 64 additions & 0 deletions lib/generators/alchemy/install/files/babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
module.exports = function (api) {
var validEnv = ["development", "test", "production"]
var currentEnv = api.env()
var isDevelopmentEnv = api.env("development")
var isProductionEnv = api.env("production")
var isTestEnv = api.env("test")

if (!validEnv.includes(currentEnv)) {
throw new Error(
"Please specify a valid `NODE_ENV` or " +
'`BABEL_ENV` environment variables. Valid values are "development", ' +
'"test", and "production". Instead, received: ' +
JSON.stringify(currentEnv) +
"."
)
}

return {
presets: [
isTestEnv && [
"@babel/preset-env",
{
targets: {
node: "current"
}
}
],
(isProductionEnv || isDevelopmentEnv) && [
"@babel/preset-env",
{
forceAllTransforms: true,
useBuiltIns: "entry",
corejs: 3,
modules: false,
exclude: ["transform-typeof-symbol"]
}
]
].filter(Boolean),
plugins: [
"babel-plugin-macros",
"@babel/plugin-syntax-dynamic-import",
isTestEnv && "babel-plugin-dynamic-import-node",
"@babel/plugin-transform-destructuring",
[
"@babel/plugin-proposal-object-rest-spread",
{
useBuiltIns: true
}
],
[
"@babel/plugin-transform-runtime",
{
helpers: false
}
],
[
"@babel/plugin-transform-regenerator",
{
async: false
}
]
].filter(Boolean)
}
}
12 changes: 12 additions & 0 deletions lib/generators/alchemy/install/install_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ class InstallGenerator < ::Rails::Generators::Base
default: false,
desc: "Skip running the webpacker installer."

class_option :force_babel_config,
type: :boolean,
default: false,
desc: "Force installing a patched babel config."

class_option :skip_db_create,
type: :boolean,
default: false,
Expand Down Expand Up @@ -113,6 +118,13 @@ def run_webpacker_installer
end
end

# We need to force the babel.config.js file, because webpacker has an invalid one
def copy_babel_config
if options[:force_babel_config]
copy_file "babel.config.js", app_root.join("babel.config.js"), force: true
end
end

def add_npm_package
run "yarn add @alchemy_cms/admin@~#{Alchemy.version}"
end
Expand Down