bridgetown-core 1.2.0 → 1.3.0.beta2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/bridgetown-core.gemspec +21 -22
  3. data/lib/bridgetown-core/collection.rb +1 -1
  4. data/lib/bridgetown-core/commands/build.rb +3 -0
  5. data/lib/bridgetown-core/commands/console.rb +0 -1
  6. data/lib/bridgetown-core/commands/esbuild/esbuild.config.js +12 -2
  7. data/lib/bridgetown-core/commands/esbuild/esbuild.defaults.js.erb +64 -18
  8. data/lib/bridgetown-core/commands/esbuild/jsconfig.json +10 -0
  9. data/lib/bridgetown-core/commands/esbuild/setup.rb +1 -0
  10. data/lib/bridgetown-core/commands/esbuild/update.rb +3 -0
  11. data/lib/bridgetown-core/commands/new.rb +2 -0
  12. data/lib/bridgetown-core/configuration/configuration_dsl.rb +1 -1
  13. data/lib/bridgetown-core/configuration.rb +13 -12
  14. data/lib/bridgetown-core/configurations/is-land.rb +15 -0
  15. data/lib/bridgetown-core/configurations/lit/lit-components-entry.js +1 -1
  16. data/lib/bridgetown-core/configurations/lit.rb +9 -54
  17. data/lib/bridgetown-core/configurations/purgecss.rb +1 -1
  18. data/lib/bridgetown-core/configurations/ruby2js/ruby2js.rb +10 -0
  19. data/lib/bridgetown-core/configurations/ruby2js.rb +12 -40
  20. data/lib/bridgetown-core/configurations/turbo.rb +17 -7
  21. data/lib/bridgetown-core/errors.rb +10 -1
  22. data/lib/bridgetown-core/filters/localization_filters.rb +11 -0
  23. data/lib/bridgetown-core/helpers.rb +34 -0
  24. data/lib/bridgetown-core/plugin_manager.rb +0 -24
  25. data/lib/bridgetown-core/rack/boot.rb +13 -1
  26. data/lib/bridgetown-core/rack/routes.rb +40 -6
  27. data/lib/bridgetown-core/readers/layout_reader.rb +2 -2
  28. data/lib/bridgetown-core/tags/dsd.rb +15 -0
  29. data/lib/bridgetown-core/tags/l.rb +14 -0
  30. data/lib/bridgetown-core/utils/aux.rb +2 -0
  31. data/lib/bridgetown-core/utils/loaders_manager.rb +7 -0
  32. data/lib/bridgetown-core/utils.rb +52 -5
  33. data/lib/bridgetown-core/version.rb +2 -2
  34. data/lib/bridgetown-core/watcher.rb +15 -8
  35. data/lib/bridgetown-core.rb +12 -0
  36. data/lib/roda/plugins/bridgetown_server.rb +140 -0
  37. data/lib/site_template/Gemfile.erb +6 -3
  38. data/lib/site_template/frontend/javascript/index.js.erb +10 -1
  39. data/lib/site_template/package.json.erb +6 -6
  40. data/lib/site_template/server/roda_app.rb +4 -2
  41. data/lib/site_template/src/_posts/0000-00-00-welcome-to-bridgetown.md.erb +1 -1
  42. metadata +16 -27
  43. data/lib/bridgetown-core/commands/serve/servlet.rb +0 -68
  44. data/lib/bridgetown-core/commands/serve.rb +0 -253
  45. data/lib/bridgetown-core/rack/roda.rb +0 -157
  46. data/lib/roda/plugins/bridgetown_boot.rb +0 -25
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 599f0ff57d4bac2146e5cacb12ccb8f2e7e02026815447c2db9cbf914ed9d3a2
4
- data.tar.gz: be29cede2daa248b4db41bb6a7eaeebb7d3533b54a5cf891922b0762a6ca47e0
3
+ metadata.gz: 58cbef52cc9ace0226b8a2ba380589287678d686684bf4d81e5889a6d3ed25bc
4
+ data.tar.gz: 14a1a0f631574b0df1e9844660eeff2a6e5e50ad53b998991a3b9a636654a05f
5
5
  SHA512:
6
- metadata.gz: 739ed852e60fabf0b6b2d352c8ce8993d4751a1f6cfec67c0bb7ed4cc5f0af41bb82fb8dc3eb34f5806a421bcec38e9050cd0fbcb50249a0482f5804e19a1d27
7
- data.tar.gz: 97eea9cb28095624a8d47821f754df39790d8db46e62d79774371113c875fd914a796f3e445ad982e6f8de8e94d5babf7b8be1736c4bc93f3a9fe0a0f6862433
6
+ metadata.gz: 520791c7e08bdc24e4af37ac399bc0a2d73d939b8ea229188b162f90063b05e394e254dabfa7d529db2d41018bc2bf0fee62b5591a14961a2f88fd40d47a1ddc
7
+ data.tar.gz: d623c999cb2ceadcacbed1b1dfbdfd365dd3b705e5583037cb23398d0519301d0052e20b9005b3ab0ce75d0b8c6143abc46f352fbeec7313eef1c8864da6ec57
@@ -31,26 +31,25 @@ Gem::Specification.new do |s|
31
31
 
32
32
  s.required_ruby_version = ">= 2.7.0"
33
33
 
34
- s.add_runtime_dependency("activemodel", [">= 6.0", "< 8.0"])
35
- s.add_runtime_dependency("activesupport", [">= 6.0", "< 8.0"])
36
- s.add_runtime_dependency("addressable", "~> 2.4")
37
- s.add_runtime_dependency("amazing_print", "~> 1.2")
38
- s.add_runtime_dependency("colorator", "~> 1.0")
39
- s.add_runtime_dependency("erubi", "~> 1.9")
40
- s.add_runtime_dependency("faraday", "~> 1.0")
41
- s.add_runtime_dependency("faraday_middleware", "~> 1.0")
42
- s.add_runtime_dependency("hash_with_dot_access", "~> 1.2")
43
- s.add_runtime_dependency("i18n", "~> 1.0")
44
- s.add_runtime_dependency("kramdown", "~> 2.1")
45
- s.add_runtime_dependency("kramdown-parser-gfm", "~> 1.0")
46
- s.add_runtime_dependency("liquid", "~> 5.0")
47
- s.add_runtime_dependency("listen", "~> 3.0")
48
- s.add_runtime_dependency("rake", ">= 13.0")
49
- s.add_runtime_dependency("roda", "~> 3.46")
50
- s.add_runtime_dependency("rouge", "~> 3.0")
51
- s.add_runtime_dependency("serbea", "~> 1.0")
52
- s.add_runtime_dependency("thor", "~> 1.1")
53
- s.add_runtime_dependency("tilt", "~> 2.0")
54
- s.add_runtime_dependency("webrick", "~> 1.7")
55
- s.add_runtime_dependency("zeitwerk", "~> 2.5")
34
+ s.add_runtime_dependency("activemodel", [">= 6.0", "< 8.0"])
35
+ s.add_runtime_dependency("activesupport", [">= 6.0", "< 8.0"])
36
+ s.add_runtime_dependency("addressable", "~> 2.4")
37
+ s.add_runtime_dependency("amazing_print", "~> 1.2")
38
+ s.add_runtime_dependency("colorator", "~> 1.0")
39
+ s.add_runtime_dependency("erubi", "~> 1.9")
40
+ s.add_runtime_dependency("faraday", "~> 2.0")
41
+ s.add_runtime_dependency("faraday-follow_redirects", "~> 0.3")
42
+ s.add_runtime_dependency("hash_with_dot_access", "~> 1.2")
43
+ s.add_runtime_dependency("i18n", "~> 1.0")
44
+ s.add_runtime_dependency("kramdown", "~> 2.1")
45
+ s.add_runtime_dependency("kramdown-parser-gfm", "~> 1.0")
46
+ s.add_runtime_dependency("liquid", "~> 5.0")
47
+ s.add_runtime_dependency("listen", "~> 3.0")
48
+ s.add_runtime_dependency("rake", ">= 13.0")
49
+ s.add_runtime_dependency("roda", "~> 3.46")
50
+ s.add_runtime_dependency("rouge", "~> 3.0")
51
+ s.add_runtime_dependency("serbea", "~> 1.0")
52
+ s.add_runtime_dependency("thor", "~> 1.1")
53
+ s.add_runtime_dependency("tilt", "~> 2.0")
54
+ s.add_runtime_dependency("zeitwerk", "~> 2.5")
56
55
  end
@@ -282,7 +282,7 @@ module Bridgetown
282
282
  if model_is_multi_locale?(model, model_relative_path)
283
283
  # If the model specifies a locales key, use that to determine the
284
284
  # the locale of each resource, otherwise fall back to `site.config.available_locales`
285
- locales = model.locales || site.config.available_locales
285
+ locales = model.attributes[:locales] || site.config.available_locales
286
286
 
287
287
  locales.each do |locale|
288
288
  model.locale = locale.to_sym
@@ -48,6 +48,9 @@ module Bridgetown
48
48
 
49
49
  if !Bridgetown.env.production? &&
50
50
  !config_options[:skip_frontend] && config_options["using_puma"]
51
+ if Bridgetown::Utils.frontend_bundler_type(config_options[:root_dir]) == :esbuild
52
+ Bridgetown::Utils.update_esbuild_autogenerated_config config_options
53
+ end
51
54
  require "rake"
52
55
  Rake.with_application do |rake|
53
56
  rake.load_rakefile
@@ -16,7 +16,6 @@ module Bridgetown
16
16
  I18n.reload! # make sure any locale files get read again
17
17
  Bridgetown::Hooks.trigger :site, :pre_reload, site
18
18
  Bridgetown::Hooks.clear_reloadable_hooks
19
- site.plugin_manager.reload_plugin_files
20
19
  site.loaders_manager.reload_loaders
21
20
  Bridgetown::Hooks.trigger :site, :post_reload, site
22
21
 
@@ -24,13 +24,23 @@ const outputFolder = "output"
24
24
  // You can also support custom base_path deployments via changing `publicPath`.
25
25
  //
26
26
  // ```
27
- // const esbuildOptions = { publicPath: "/my_subfolder/_bridgetown/static" }
27
+ // const esbuildOptions = {
28
+ // publicPath: "/my_subfolder/_bridgetown/static",
29
+ // ...
30
+ // }
28
31
  // ```
29
32
 
30
33
  /**
31
34
  * @typedef { import("esbuild").BuildOptions } BuildOptions
32
35
  * @type {BuildOptions}
33
36
  */
34
- const esbuildOptions = {}
37
+ const esbuildOptions = {
38
+ plugins: [
39
+ // add new plugins here...
40
+ ],
41
+ globOptions: {
42
+ excludeFilter: /\.(dsd|lit)\.(css|js)$/
43
+ }
44
+ }
35
45
 
36
46
  build(outputFolder, esbuildOptions)
@@ -8,6 +8,14 @@
8
8
  //
9
9
  // Shipped with Bridgetown v<%= Bridgetown::VERSION %>
10
10
 
11
+ // DO NOT MANUALLY EDIT THIS CONFIGURATION:
12
+ const autogeneratedBridgetownConfig = {
13
+ "source": "src",
14
+ "destination": "output",
15
+ "componentsDir": "_components",
16
+ "islandsDir": "_islands"
17
+ }
18
+
11
19
  const path = require("path")
12
20
  const fsLib = require("fs")
13
21
  const fs = fsLib.promises
@@ -41,7 +49,7 @@ if (moduleAvailable("sass")) {
41
49
  // Glob plugin derived from:
42
50
  // https://github.com/thomaschaaf/esbuild-plugin-import-glob
43
51
  // https://github.com/xiaohui-zhangxh/jsbundling-rails/commit/b15025dcc20f664b2b0eb238915991afdbc7cb58
44
- const importGlobPlugin = () => ({
52
+ const importGlobPlugin = (options, bridgetownConfig) => ({
45
53
  name: "import-glob",
46
54
  setup: (build) => {
47
55
  build.onResolve({ filter: /\*/ }, async (args) => {
@@ -49,7 +57,9 @@ const importGlobPlugin = () => ({
49
57
  return; // Ignore unresolvable paths
50
58
  }
51
59
 
52
- const adjustedPath = args.path.replace(/^bridgetownComponents\//, "../../src/_components/")
60
+ const adjustedPath = args.path
61
+ .replace(/^\$components\/\*\*/, `../../${bridgetownConfig.source}/${bridgetownConfig.componentsDir}/**`)
62
+ .replace(/^bridgetownComponents\//, `../../${bridgetownConfig.source}/${bridgetownConfig.componentsDir}/`) // legacy
53
63
 
54
64
  return {
55
65
  path: adjustedPath,
@@ -64,7 +74,11 @@ const importGlobPlugin = () => ({
64
74
  build.onLoad({ filter: /.*/, namespace: "import-glob" }, async (args) => {
65
75
  const files = glob.sync(args.pluginData.path, {
66
76
  cwd: args.pluginData.resolveDir,
67
- }).sort()
77
+ })
78
+ .filter(module => options.excludeFilter ? !options.excludeFilter.test(module) : true)
79
+ .sort()
80
+ .map(module => module.replace(`../../${bridgetownConfig.source}/${bridgetownConfig.componentsDir}/`, "$components/"))
81
+ .map(module => module.match(/^[a-zA-Z0-9]/) ? `./${module}` : module)
68
82
 
69
83
  const importerCode = `
70
84
  ${files
@@ -72,7 +86,7 @@ const importGlobPlugin = () => ({
72
86
  .join(';')}
73
87
  const modules = {${files
74
88
  .map((module, index) => `
75
- "${module.replace("../../src/_components/", "")}": module${index},`)
89
+ "${module.replace("$components/", "")}": module${index},`)
76
90
  .join("")}
77
91
  };
78
92
  export default modules;
@@ -187,7 +201,7 @@ const sassPlugin = (options) => ({
187
201
  })
188
202
 
189
203
  // Set up defaults and generate frontend bundling manifest file
190
- const bridgetownPreset = (outputFolder) => ({
204
+ const bridgetownPreset = (bridgetownConfig) => ({
191
205
  name: "bridgetownPreset",
192
206
  async setup(build) {
193
207
  // Ensure any imports anywhere starting with `/` are left verbatim
@@ -210,8 +224,10 @@ const bridgetownPreset = (outputFolder) => ({
210
224
  const manifest = {}
211
225
  const entrypoints = []
212
226
 
213
- // We don't need `frontend/` cluttering up everything
214
- const stripPrefix = (str) => str.replace(/^frontend\//, "")
227
+ // Clean up entrypoint naming
228
+ const stripPrefix = (str) => str
229
+ .replace(/^frontend\//, "")
230
+ .replace(RegExp(String.raw`^${bridgetownConfig.source}\/${bridgetownConfig.islandsDir}\/`), "islands/")
215
231
 
216
232
  // For calculating the file size of bundle output
217
233
  const fileSize = (path) => {
@@ -220,11 +236,12 @@ const bridgetownPreset = (outputFolder) => ({
220
236
  return (size / Math.pow(1024, i)).toFixed(2) * 1 + ['B', 'KB', 'MB', 'GB', 'TB'][i]
221
237
  }
222
238
 
239
+ const pathShortener = new RegExp(String.raw`^${bridgetownConfig.destination}\/_bridgetown\/static\/`, "g")
240
+
223
241
  // Let's loop through all the various outputs
224
242
  for (const key in result.metafile.outputs) {
225
243
  const value = result.metafile.outputs[key]
226
244
  const inputs = Object.keys(value.inputs)
227
- const pathShortener = new RegExp(`^${outputFolder}\\/_bridgetown\\/static\\/`, "g")
228
245
  const outputPath = key.replace(pathShortener, "")
229
246
 
230
247
  if (value.entryPoint) {
@@ -256,23 +273,43 @@ const bridgetownPreset = (outputFolder) => ({
256
273
  }
257
274
  })
258
275
 
276
+ const bridgetownConfigured = (bridgetownConfig, outputFolder) => {
277
+ bridgetownConfig = {...autogeneratedBridgetownConfig, ...bridgetownConfig}
278
+ if (outputFolder) bridgetownConfig.destination = outputFolder
279
+
280
+ return bridgetownConfig
281
+ }
282
+
259
283
  // Load the PostCSS config from postcss.config.js or whatever else is a supported location/format
260
284
  const postcssrc = require("postcss-load-config")
261
285
 
262
- module.exports = async (outputFolder, esbuildOptions) => {
286
+ module.exports = async (esbuildOptions) => {
287
+ let outputFolder;
288
+ if (typeof esbuildOptions === "string") { // legacy syntax where first argument is output folder
289
+ esbuildOptions = arguments[1]
290
+ outputFolder = arguments[0]
291
+ }
292
+ const bridgetownConfig = bridgetownConfigured(esbuildOptions.bridgetownConfig, outputFolder)
293
+
263
294
  esbuildOptions.plugins = esbuildOptions.plugins || []
264
295
  // Add the PostCSS & glob plugins to the top of the plugin stack
265
296
  const postCssConfig = await postcssrc()
266
297
  esbuildOptions.plugins.unshift(importPostCssPlugin(postCssConfig, esbuildOptions.postCssPluginConfig || {}))
267
298
  if (esbuildOptions.postCssPluginConfig) delete esbuildOptions.postCssPluginConfig
268
- esbuildOptions.plugins.unshift(importGlobPlugin())
299
+ // Add the Glob plugin
300
+ esbuildOptions.plugins.unshift(importGlobPlugin(esbuildOptions.globOptions || {}, bridgetownConfig))
301
+ if (esbuildOptions.globOptions) delete esbuildOptions.globOptions
269
302
  // Add the Sass plugin
270
303
  esbuildOptions.plugins.push(sassPlugin(esbuildOptions.sassOptions || {}))
304
+ if (esbuildOptions.sassOptions) delete esbuildOptions.sassOptions
271
305
  // Add the Bridgetown preset
272
- esbuildOptions.plugins.push(bridgetownPreset(outputFolder))
306
+ esbuildOptions.plugins.push(bridgetownPreset(bridgetownConfig))
307
+ if (esbuildOptions.bridgetownConfig) delete esbuildOptions.bridgetownConfig
273
308
 
274
- // esbuild, take it away!
275
- require("esbuild").build({
309
+ const esbuild = require("esbuild")
310
+ const islands = glob.sync(`./${bridgetownConfig.source}/${bridgetownConfig.islandsDir}/*.{js,js.rb}`).map(item => `./${item}`)
311
+
312
+ esbuild.context({
276
313
  bundle: true,
277
314
  loader: {
278
315
  ".jpg": "file",
@@ -285,16 +322,25 @@ module.exports = async (outputFolder, esbuildOptions) => {
285
322
  ".eot": "file",
286
323
  },
287
324
  resolveExtensions: [".tsx", ".ts", ".jsx", ".js", ".css", ".scss", ".sass", ".json", ".js.rb"],
288
- nodePaths: ["frontend/javascript", "frontend/styles"],
289
- watch: process.argv.includes("--watch"),
290
325
  minify: process.argv.includes("--minify"),
291
326
  sourcemap: true,
292
- target: "es2016",
293
- entryPoints: ["./frontend/javascript/index.js"],
327
+ target: "es2020",
328
+ entryPoints: ["./frontend/javascript/index.js", ...islands],
294
329
  entryNames: "[dir]/[name].[hash]",
295
- outdir: path.join(process.cwd(), `${outputFolder}/_bridgetown/static`),
330
+ outdir: path.join(process.cwd(), `${bridgetownConfig.destination}/_bridgetown/static`),
296
331
  publicPath: "/_bridgetown/static",
297
332
  metafile: true,
298
333
  ...esbuildOptions,
334
+ }).then(context => {
335
+ if (process.argv.includes("--watch")) {
336
+ // Enable watch mode
337
+ context.watch()
338
+ } else {
339
+ // Build once and exit if not in watch mode
340
+ context.rebuild().then(result => {
341
+ context.dispose()
342
+ })
343
+ }
344
+ process.on('SIGINT', () => process.exit())
299
345
  }).catch(() => process.exit(1))
300
346
  }
@@ -0,0 +1,10 @@
1
+ {
2
+ "compilerOptions": {
3
+ "baseUrl": ".",
4
+ "paths": {
5
+ "$styles/*": ["./frontend/styles/*"],
6
+ "$javascript/*": ["./frontend/javascript/*"],
7
+ "$components/*": ["./src/_components/*"]
8
+ }
9
+ },
10
+ }
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  template "esbuild.defaults.js.erb", "config/esbuild.defaults.js"
4
+ copy_file "jsconfig.json"
4
5
  copy_file "esbuild.config.js", force: true
@@ -1,4 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  template "esbuild.defaults.js.erb", "config/esbuild.defaults.js", force: true
4
+ copy_file "jsconfig.json"
4
5
  say "🎉 esbuild configuration updated successfully!"
6
+ say "You may need to add `$styles/` to the front of your main CSS imports."
7
+ say "See https://www.bridgetownrb.com/docs/frontend-assets#esbuild-setup for details."
@@ -80,6 +80,8 @@ module Bridgetown
80
80
  after_install new_site_path, args.join(" "), options
81
81
  rescue ArgumentError => e
82
82
  say_status :alert, e.message, :red
83
+ ensure
84
+ self.class.created_site_dir = nil # reset afterwards, otherwise hanging tmp dirs in test
83
85
  end
84
86
 
85
87
  protected
@@ -49,7 +49,7 @@ module Bridgetown
49
49
  priority: Bridgetown::Hooks::DEFAULT_PRIORITY,
50
50
  &block
51
51
  )
52
- Bridgetown::Hooks.register_one(owner, event, priority: priority, &block)
52
+ Bridgetown::Hooks.register_one(owner, event, priority: priority, reloadable: false, &block)
53
53
  end
54
54
 
55
55
  def source_manifest(**kwargs)
@@ -33,8 +33,8 @@ module Bridgetown
33
33
  "collections_dir" => "",
34
34
  "cache_dir" => ".bridgetown-cache",
35
35
  "layouts_dir" => "_layouts",
36
- "data_dir" => "_data",
37
36
  "components_dir" => "_components",
37
+ "islands_dir" => "_islands",
38
38
  "partials_dir" => "_partials",
39
39
  "collections" => {},
40
40
  "taxonomies" => {
@@ -44,7 +44,6 @@ module Bridgetown
44
44
  "eager_load_paths" => [],
45
45
  "autoloader_collapsed_paths" => [],
46
46
  "additional_watch_paths" => [],
47
- "plugins_use_zeitwerk" => true,
48
47
 
49
48
  # Handling Reading
50
49
  "include" => [".htaccess", "_redirects", ".well-known"],
@@ -335,30 +334,32 @@ module Bridgetown
335
334
  self[:source] = File.expand_path(self[:source], self[:root_dir])
336
335
  self[:destination] = File.expand_path(self[:destination], self[:root_dir])
337
336
 
338
- if self[:plugins_use_zeitwerk]
339
- autoload_paths.unshift({
340
- path: self[:plugins_dir],
341
- eager: true,
342
- })
343
- end
337
+ autoload_paths.unshift({
338
+ path: self[:plugins_dir],
339
+ eager: true,
340
+ })
341
+ autoload_paths.unshift({
342
+ path: File.expand_path(self[:islands_dir], self[:source]),
343
+ eager: true,
344
+ })
344
345
  end
345
346
 
346
347
  autoload_paths.map! do |load_path|
347
348
  if load_path.is_a?(Hash)
348
- expanded = File.expand_path(load_path[:path], root_dir)
349
+ expanded = File.expand_path(load_path[:path], self[:root_dir])
349
350
  self[:eager_load_paths] << expanded if load_path[:eager]
350
351
  next expanded
351
352
  end
352
353
 
353
- File.expand_path(load_path, root_dir)
354
+ File.expand_path(load_path, self[:root_dir])
354
355
  end
355
356
 
356
357
  autoloader_collapsed_paths.map! do |collapsed_path|
357
- File.expand_path(collapsed_path, root_dir)
358
+ File.expand_path(collapsed_path, self[:root_dir])
358
359
  end
359
360
 
360
361
  additional_watch_paths.map! do |collapsed_path|
361
- File.expand_path(collapsed_path, root_dir)
362
+ File.expand_path(collapsed_path, self[:root_dir])
362
363
  end
363
364
 
364
365
  self
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ say_status "is-land", "Installing <is-land>..."
4
+
5
+ run "yarn add @11ty/is-land"
6
+
7
+ javascript_import do
8
+ <<~JS
9
+ import "@11ty/is-land/is-land.js"
10
+ import "@11ty/is-land/is-land-autoinit.js"
11
+ JS
12
+ end
13
+
14
+ say_status "is-land", "<is-land> is now configured!"
15
+ say 'For further reading, check out "https://www.bridgetownrb.com/docs/islands"', :blue
@@ -1 +1 @@
1
- import components from "bridgetownComponents/**/*.{lit.js,lit.js.rb}"
1
+ import components from "$components/**/*.{lit.js,lit.js.rb}"
@@ -11,9 +11,9 @@ end
11
11
 
12
12
  say_status :lit, "Installing Lit + SSR Plugin..."
13
13
 
14
- add_gem "bridgetown-lit-renderer"
14
+ add_gem "bridgetown-lit-renderer", version: "2.1.0.beta1"
15
15
 
16
- run "yarn add lit esbuild-plugin-lit-css bridgetown-lit-renderer"
16
+ run "yarn add lit esbuild-plugin-lit-css bridgetown-lit-renderer@2.1.0-beta1"
17
17
 
18
18
  copy_file in_templates_dir("lit-ssr.config.js"), "config/lit-ssr.config.js"
19
19
  copy_file in_templates_dir("lit-components-entry.js"), "config/lit-components-entry.js"
@@ -27,45 +27,13 @@ insert_into_file "esbuild.config.js",
27
27
  JS
28
28
  end
29
29
 
30
- found_match = false
31
- gsub_file "esbuild.config.js", %r{const esbuildOptions = {}\n} do |_match|
32
- found_match = true
33
-
34
- <<~JS
35
- const esbuildOptions = {
36
- plugins: [...plugins],
37
- // Uncomment the following to opt into `.global.css` & `.lit.css` nomenclature.
38
- // Read https://www.bridgetownrb.com/docs/components/lit#sidecar-css-files for documentation.
39
- /*
40
- postCssPluginConfig: {
41
- filter: /(?:index|\\.global)\\.css$/,
42
- },
43
- */
44
- }
30
+ insert_into_file "esbuild.config.js",
31
+ after: " plugins: [" do
32
+ <<-JS
33
+ plugins: [...plugins],
45
34
  JS
46
35
  end
47
36
 
48
- unless found_match
49
- insert_into_file "esbuild.config.js",
50
- after: 'const { plugins } = require("./config/esbuild-plugins.js")' do
51
- <<~JS
52
-
53
- // TODO: You will manually need to move any plugins below you wish to share with
54
- // Lit SSR into the `config/esbuild-plugins.js` file.
55
- // Then add `...plugins` as an item in your plugins array.
56
- //
57
- // You might also want to include the following in your esbuild config to opt into
58
- // `.global.css` & `.lit.css` nomenclature.
59
- // Read https://www.bridgetownrb.com/docs/components/lit#sidecar-css-files for documentation.
60
- /*
61
- postCssPluginConfig: {
62
- filter: /(?:index|\\.global)\\.css$/,
63
- },
64
- */
65
- JS
66
- end
67
- end
68
-
69
37
  copy_file in_templates_dir("happy-days.lit.js"), "src/_components/happy-days.lit.js"
70
38
 
71
39
  javascript_import do
@@ -74,24 +42,11 @@ javascript_import do
74
42
  JS
75
43
  end
76
44
 
77
- insert_into_file "frontend/javascript/index.js",
78
- before: 'import components from "bridgetownComponents/**/*.{js,jsx,js.rb,css}"' do
79
- <<~JS
80
- // To opt into `.global.css` & `.lit.css` nomenclature, change the `css` extension below to `global.css`.
81
- // Read https://www.bridgetownrb.com/docs/components/lit#sidecar-css-files for documentation.
82
- JS
83
- end
84
-
85
45
  add_initializer :"bridgetown-lit-renderer"
86
46
 
87
- if found_match
88
- say_status :lit, "Lit is now configured!"
89
- say_status :lit,
90
- "The `config/esbuild-plugins.js` file will let you add full-stack plugins in future."
91
- else
92
- say_status :lit, "Lit is just about configured!"
93
- say_status :lit, "You will need to edit `esbuild.config.js` to finish setting up the plugin."
94
- end
47
+ say_status :lit, "Lit is now configured!"
48
+ say_status :lit,
49
+ "The `config/esbuild-plugins.js` file will let you add full-stack plugins in future."
95
50
 
96
51
  say "Check out the example `happy-days.lit.js` file in `src/_components`", :blue
97
52
  say 'For further reading, check out "https://www.bridgetownrb.com/docs/components/lit"', :blue
@@ -31,7 +31,7 @@ create_builder "purgecss.rb" do
31
31
  manifest = JSON.parse(File.read(manifest_file))
32
32
 
33
33
  if Bridgetown::Utils.frontend_bundler_type == :esbuild
34
- css_file = manifest["styles/index.css"].split("/").last
34
+ css_file = (manifest["styles/index.css"] || manifest["styles/index.scss"]).split("/").last
35
35
  css_path = ["output", "_bridgetown", "static", css_file].join("/")
36
36
  else
37
37
  css_file = manifest["main.css"].split("/").last
@@ -0,0 +1,10 @@
1
+ # See docs on Ruby2JS options here: https://www.ruby2js.com/docs/options
2
+
3
+ preset
4
+
5
+ filter :camelCase
6
+ filter :lit
7
+
8
+ eslevel 2022
9
+
10
+ autoexports :default
@@ -11,57 +11,29 @@ end
11
11
 
12
12
  say_status :ruby2js, "Installing Ruby2JS..."
13
13
 
14
+ add_gem "ruby2js"
14
15
  run "yarn add -D @ruby2js/esbuild-plugin"
15
16
 
16
- found_match = false
17
- gsub_file "esbuild.config.js", %r{const esbuildOptions = {}\n} do |_match|
18
- found_match = true
19
-
17
+ insert_into_file "esbuild.config.js",
18
+ after: 'const build = require("./config/esbuild.defaults.js")' do
20
19
  <<~JS
21
- const ruby2js = require("@ruby2js/esbuild-plugin")
22
20
 
23
- const esbuildOptions = {
24
- plugins: [
25
- // See docs on Ruby2JS options here: https://www.ruby2js.com/docs/options
26
- ruby2js({
27
- eslevel: 2022,
28
- autoexports: "default",
29
- filters: ["camelCase", "functions", "lit", "esm", "return"]
30
- })
31
- ]
32
- }
21
+ const ruby2js = require("@ruby2js/esbuild-plugin")
33
22
  JS
34
23
  end
35
24
 
36
- unless found_match
37
- insert_into_file "esbuild.config.js",
38
- after: 'const build = require("./config/esbuild.defaults.js")' do
39
- <<~JS
40
-
41
- const ruby2js = require("@ruby2js/esbuild-plugin")
42
-
43
- // TODO: Uncomment and move the following into your plugins array:
44
- //
45
- // ruby2js({
46
- // eslevel: 2022,
47
- // autoexports: "default",
48
- // filters: ["camelCase", "functions", "lit", "esm", "return"]
49
- // })
50
- //
51
- // See docs on Ruby2JS options here: https://www.ruby2js.com/docs/options
52
-
53
- JS
54
- end
25
+ insert_into_file "esbuild.config.js",
26
+ after: " plugins: [" do
27
+ <<-JS
28
+ ruby2js(),
29
+ JS
55
30
  end
56
31
 
32
+ copy_file in_templates_dir("ruby2js.rb"), "config/ruby2js.rb"
57
33
  copy_file in_templates_dir("hello_world.js.rb"), "src/_components/hello_world.js.rb"
58
34
 
59
- if found_match
60
- say_status :ruby2js, "Ruby2JS is now configured!"
61
- else
62
- say_status :ruby2js, "Ruby2JS is just about configured!"
63
- say_status :ruby2js, "You will need to edit `esbuild.config.js` to finish setting up the plugin."
64
- end
35
+ say_status :ruby2js, "Ruby2JS is now configured!"
65
36
 
66
37
  say "Check out the example `hello_world.js.rb` file in `src/_components`", :blue
38
+ say "Ruby2JS configuration options are saved in `config/ruby2js.rb`", :blue
67
39
  say 'For further reading, check out "https://www.ruby2js.com"', :blue
@@ -3,6 +3,7 @@
3
3
  say_status :turbo, "Installing Turbo..."
4
4
 
5
5
  run("yarn add @hotwired/turbo")
6
+ run("yarn add turbo-shadow")
6
7
 
7
8
  say_status :turbo, 'Adding Turbo to "frontend/javascript/index.js"...', :magenta
8
9
 
@@ -10,11 +11,17 @@ javascript_import do
10
11
  <<~JS
11
12
  import * as Turbo from "@hotwired/turbo"
12
13
 
13
- // Uncomment the line below to add transition animations when Turbo navigates.
14
- // We recommend adding <meta name="turbo-cache-control" content="no-preview" />
15
- // to your HTML head if you turn on transitions. Use data-turbo-transition="false"
16
- // on your <main> element for pages where you don't want any transition animation.
17
- //
14
+ /**
15
+ * Adds support for declarative shadow DOM. Requires your HTML <head> to include:
16
+ * `<meta name="turbo-cache-control" content="no-cache" />`
17
+ */
18
+ import * as TurboShadow from "turbo-shadow"
19
+
20
+ /**
21
+ * Uncomment the line below to add transition animations when Turbo navigates.
22
+ * Use data-turbo-transition="false" on your <main> element for pages where
23
+ * you don't want any transition animation.
24
+ */
18
25
  // import "./turbo_transitions.js"
19
26
  JS
20
27
  end
@@ -22,5 +29,8 @@ end
22
29
  copy_file in_templates_dir("turbo_transitions.js"), "frontend/javascript/turbo_transitions.js"
23
30
 
24
31
  say_status :turbo, "Turbo successfully added!", :magenta
25
- say_status :turbo, "Take a look in your index.js file for optional animation setup.", :blue
26
- say_status :turbo, 'For further reading, check out "https://turbo.hotwired.dev/"', :blue
32
+ say_status :turbo, "For declarative shadow DOM support, you will need to update", :blue
33
+ say_status :turbo, "your HTML <head> to add the following code:", :blue
34
+ say %(<meta name="turbo-cache-control" content="no-cache" />)
35
+ say_status :turbo, "Check out your index.js file for optional animation setup.", :blue
36
+ say_status :turbo, 'For further reading, visit "https://turbo.hotwired.dev/"', :blue