superglue 2.0.0.rc.1 → 2.0.0.rc.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. checksums.yaml +4 -4
  2. data/lib/generators/superglue/install/install_generator.rb +62 -4
  3. data/lib/generators/superglue/install/templates/bun/bun.config.deepkit.js +1 -0
  4. data/lib/generators/superglue/install/templates/bun/bun.config.js +1 -0
  5. data/lib/generators/superglue/install/templates/bun/bun.config.ts.js +1 -0
  6. data/lib/generators/superglue/install/templates/bun/bun.config.typia.js +1 -0
  7. data/lib/generators/superglue/install/templates/js/application.jsx +0 -1
  8. data/lib/generators/superglue/install/templates/js/build.mjs +1 -0
  9. data/lib/generators/superglue/install/templates/js/inputs.jsx +1 -1
  10. data/lib/generators/superglue/install/templates/js/jsconfig.json +1 -0
  11. data/lib/generators/superglue/install/templates/js/layout.jsx +0 -1
  12. data/lib/generators/superglue/install/templates/ssr/bun.build_ssr.js +1 -0
  13. data/lib/generators/superglue/install/templates/ssr/esbuild.build_ssr.mjs +1 -0
  14. data/lib/generators/superglue/install/templates/ssr/server_rendering.jsx +0 -1
  15. data/lib/generators/superglue/install/templates/ssr/server_rendering.tsx +0 -1
  16. data/lib/generators/superglue/install/templates/ssr/webpack.build_ssr.js +2 -1
  17. data/lib/generators/superglue/install/templates/ts/application.tsx +0 -1
  18. data/lib/generators/superglue/install/templates/ts/build.deepkit.mjs +1 -0
  19. data/lib/generators/superglue/install/templates/ts/build.mjs +1 -0
  20. data/lib/generators/superglue/install/templates/ts/build.typia.mjs +1 -0
  21. data/lib/generators/superglue/install/templates/ts/inputs.tsx +1 -1
  22. data/lib/generators/superglue/install/templates/ts/layout.tsx +1 -1
  23. data/lib/generators/superglue/install/templates/ts/tsconfig.json +1 -1
  24. data/lib/generators/superglue/install/templates/webpack/webpack.config.deepkit.js +2 -1
  25. data/lib/generators/superglue/install/templates/webpack/webpack.config.js +2 -1
  26. data/lib/generators/superglue/install/templates/webpack/webpack.config.ts.js +2 -1
  27. data/lib/generators/superglue/install/templates/webpack/webpack.config.typia.js +2 -1
  28. data/lib/generators/superglue/view_collection/templates/js/edit.html.jsx +0 -1
  29. data/lib/generators/superglue/view_collection/templates/js/index.html.jsx +0 -1
  30. data/lib/generators/superglue/view_collection/templates/js/new.html.jsx +0 -1
  31. data/lib/generators/superglue/view_collection/templates/js/show.html.jsx +0 -1
  32. data/lib/generators/superglue/view_collection/templates/ts/edit.html.tsx +0 -1
  33. data/lib/generators/superglue/view_collection/templates/ts/index.html.tsx +0 -1
  34. data/lib/generators/superglue/view_collection/templates/ts/new.html.tsx +0 -1
  35. data/lib/generators/superglue/view_collection/templates/ts/show.html.tsx +0 -1
  36. data/lib/generators/superglue/view_collection/view_collection_generator.rb +12 -5
  37. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f28636caebe6605b85b79f28e86a49a7d96b8ebacf7e7542778ad3d20460e792
4
- data.tar.gz: dc2a5f29d1ac8d61eb22bb77975f89873d0280202ea6be004ffaecac09c99ce1
3
+ metadata.gz: d17162adf65950ea5d4ee63e82835d8893c7f532607206b8a9e5bce609547297
4
+ data.tar.gz: e18b77ee95528a871782d9cc5a296601fa3763f03ef162354b5b2b165a7455b6
5
5
  SHA512:
6
- metadata.gz: 47eec6c67660566a23e99a91132d06529e0b51d9c01335b20c6a59454879c78cde32ba3d8fbb2741311ce6e72ec2a6309eef16ed0aae07f8ced16e2c10801d34
7
- data.tar.gz: 81e83bbcf1f82f07b256e5312a2f0dbd647fb89231c4386f3459ca65b128c65b7248f299c8674cffa50cb8b31248f64e75af9deaf1fb37b266add3ddfeb83cc9
6
+ metadata.gz: 1a23f6f9263af4619a667d9eb6fc6722c04547821676499417eb4533353a038efe76d80cebde261f0d085e4bb160709b4198672f89fc32ad83e507ea7cd0b80e
7
+ data.tar.gz: 86a94adb38233d8f67aad33f79dd6be31c12fdc0249e2431c2af9bef852831c3f022fc3f5f356e054275749c200d8a58736b6861441035d6048b9a16af7180a2
@@ -10,8 +10,7 @@ module Superglue
10
10
  class_option :typescript,
11
11
  type: :boolean,
12
12
  required: false,
13
- default: false,
14
- desc: "Use typescript"
13
+ desc: "Use TypeScript. Skips interactive prompt."
15
14
 
16
15
  class_option :bundler,
17
16
  type: :string,
@@ -31,8 +30,8 @@ module Superglue
31
30
  def create_files
32
31
  remove_file "#{app_js_path}/application.js"
33
32
 
34
- @use_typescript = options["typescript"]
35
33
  @bundler = ask_bundler
34
+ @use_typescript = ask_typescript
36
35
  @validator = @use_typescript ? ask_validator : "none"
37
36
  @use_svgr = ask_svgr
38
37
 
@@ -127,6 +126,16 @@ module Superglue
127
126
  ask("Which bundler are you using?", limited_to: BUNDLERS, default: detected)
128
127
  end
129
128
 
129
+ def ask_typescript
130
+ unless options["typescript"].nil?
131
+ say "TypeScript: #{options["typescript"] ? "enabled" : "disabled"}", :green
132
+ return options["typescript"]
133
+ end
134
+
135
+ say ""
136
+ yes?("Would you like to use TypeScript? [y/N]")
137
+ end
138
+
130
139
  def ask_validator
131
140
  if options["validator"]
132
141
  validator = options["validator"]
@@ -234,7 +243,7 @@ module Superglue
234
243
 
235
244
  def install_packages
236
245
  say "Installing Superglue and friends"
237
- run "yarn add react react-dom @thoughtbot/superglue@^2.0.0-beta.11"
246
+ run "yarn add react react-dom @thoughtbot/superglue@^2.0.0-rc.2"
238
247
 
239
248
  if @use_typescript
240
249
  run "yarn add -D @types/react-dom @types/react @types/node @thoughtbot/candy_wrapper@0.0.4 typescript"
@@ -374,6 +383,11 @@ module Superglue
374
383
  run %(npm pkg set scripts.build:ssr="rollup -c rollup.config.ssr.js")
375
384
  end
376
385
 
386
+ if @validator != "none"
387
+ say "Adding #{@validator} plugin to SSR build"
388
+ add_validator_to_ssr_build
389
+ end
390
+
377
391
  if @use_typescript
378
392
  say "Copying server_rendering.tsx"
379
393
  copy_file "#{__dir__}/templates/ssr/server_rendering.tsx", "#{app_js_path}/server_rendering.tsx"
@@ -415,6 +429,50 @@ module Superglue
415
429
  end
416
430
  end
417
431
 
432
+ def add_validator_to_ssr_build
433
+ plugin_call = (@validator == "deepkit") ? "deepkitPlugin()" : "ttscPlugin()"
434
+ dev_only_plugin = "...(process.env.NODE_ENV === 'production' ? [] : [#{plugin_call}])"
435
+ plugin_import = ssr_validator_import
436
+
437
+ case @bundler
438
+ when "esbuild"
439
+ inject_into_file "build_ssr.mjs", plugin_import, after: "const importGlobPlugin = importGlob.default\n"
440
+ inject_into_file "build_ssr.mjs", " #{dev_only_plugin},\n", after: " importGlobPlugin(),\n"
441
+ when "bun"
442
+ inject_into_file "build_ssr.js", plugin_import, after: "import { globImportPlugin } from 'bun-plugin-glob-import'\n"
443
+ gsub_file "build_ssr.js",
444
+ "plugins: [globImportPlugin()],",
445
+ "plugins: [\n globImportPlugin(),\n #{dev_only_plugin}\n ],"
446
+ when "webpack"
447
+ inject_into_file "webpack.config.ssr.js", plugin_import, after: "const webpack = require(\"webpack\")\n"
448
+ gsub_file "webpack.config.ssr.js", " })\n ]\n}", " }),\n #{dev_only_plugin}\n ]\n}"
449
+ when "rollup"
450
+ inject_into_file "rollup.config.ssr.js", plugin_import, after: "import importMetaGlob from \"rollup-plugin-import-meta-glob\"\n"
451
+ inject_into_file "rollup.config.ssr.js", " #{dev_only_plugin}\n", after: " importMetaGlob(),\n"
452
+ end
453
+ end
454
+
455
+ def ssr_validator_import
456
+ case [@validator, @bundler]
457
+ when ["deepkit", "esbuild"]
458
+ "import { esbuild as deepkitPlugin } from '@thoughtbot/superglue/deepkit'\n"
459
+ when ["deepkit", "bun"]
460
+ "import { bun as deepkitPlugin } from '@thoughtbot/superglue/deepkit'\n"
461
+ when ["deepkit", "webpack"]
462
+ "const { webpack: deepkitPlugin } = require(\"@thoughtbot/superglue/deepkit\")\n"
463
+ when ["deepkit", "rollup"]
464
+ "import { rollup as deepkitPlugin } from \"@thoughtbot/superglue/deepkit\"\n"
465
+ when ["typia", "esbuild"]
466
+ "import ttsc from '@ttsc/unplugin'\nconst ttscPlugin = ttsc.esbuild\n"
467
+ when ["typia", "bun"]
468
+ "import ttsc from '@ttsc/unplugin'\nconst ttscPlugin = ttsc.bun\n"
469
+ when ["typia", "webpack"]
470
+ "const ttscPlugin = require(\"@ttsc/unplugin\").default.webpack\n"
471
+ when ["typia", "rollup"]
472
+ "import ttsc from \"@ttsc/unplugin\"\nconst ttscPlugin = ttsc.rollup\n"
473
+ end
474
+ end
475
+
418
476
  def configure_svgr
419
477
  say "Configuring SVGR"
420
478
 
@@ -8,6 +8,7 @@ const config = {
8
8
  entrypoints: ['app/javascript/application.tsx'],
9
9
  outdir: 'app/assets/builds',
10
10
  sourcemap: 'external',
11
+ jsx: { runtime: 'automatic' },
11
12
  plugins: [
12
13
  globImportPlugin(),
13
14
  ...(process.env.NODE_ENV === 'production' ? [] : [deepkitPlugin()])
@@ -7,6 +7,7 @@ const config = {
7
7
  entrypoints: ['app/javascript/application.jsx'],
8
8
  outdir: 'app/assets/builds',
9
9
  sourcemap: 'external',
10
+ jsx: { runtime: 'automatic' },
10
11
  plugins: [globImportPlugin()],
11
12
  }
12
13
 
@@ -7,6 +7,7 @@ const config = {
7
7
  entrypoints: ['app/javascript/application.tsx'],
8
8
  outdir: 'app/assets/builds',
9
9
  sourcemap: 'external',
10
+ jsx: { runtime: 'automatic' },
10
11
  plugins: [globImportPlugin()],
11
12
  }
12
13
 
@@ -9,6 +9,7 @@ const config = {
9
9
  entrypoints: ['app/javascript/application.tsx'],
10
10
  outdir: 'app/assets/builds',
11
11
  sourcemap: 'external',
12
+ jsx: { runtime: 'automatic' },
12
13
  plugins: [
13
14
  globImportPlugin(),
14
15
  ...(process.env.NODE_ENV === 'production' ? [] : [ttscPlugin()])
@@ -1,4 +1,3 @@
1
- import React from "react"
2
1
  import { createRoot, hydrateRoot } from "react-dom/client"
3
2
  import { createApp } from "@thoughtbot/superglue"
4
3
  import { buildVisitAndRemote } from "./application_visit"
@@ -10,6 +10,7 @@ const buildOptions = {
10
10
  'app/javascript/application.jsx',
11
11
  ],
12
12
  bundle: true,
13
+ jsx: 'automatic',
13
14
  sourcemap: true,
14
15
  format: 'esm',
15
16
  outdir: 'app/assets/builds',
@@ -7,7 +7,7 @@
7
7
  * There is no style and structured with bare necessities. You should modify
8
8
  * these components to fit your design needs.
9
9
  */
10
- import React, { createContext, useContext, useMemo } from 'react'
10
+ import { createContext, useContext, useMemo } from 'react'
11
11
  export const ValidationContext = createContext({})
12
12
  export const useErrorMessage = (errorKey) => {
13
13
  const errors = useContext(ValidationContext)
@@ -1,5 +1,6 @@
1
1
  {
2
2
  "compilerOptions": {
3
+ "jsx": "react-jsx",
3
4
  "baseUrl": ".", // Usually the root of your project
4
5
  "paths": {
5
6
  "@javascript/*": ["app/javascript/*"],
@@ -1,4 +1,3 @@
1
- import React from 'react'
2
1
  import { useAppFlash } from '@javascript/flash'
3
2
 
4
3
  export const Layout = ({children}) => {
@@ -7,6 +7,7 @@ const buildOptions = {
7
7
  entrypoints: ['app/javascript/server_rendering.jsx'],
8
8
  outdir: 'app/assets/builds',
9
9
  sourcemap: 'external',
10
+ jsx: { runtime: 'automatic' },
10
11
  target: 'browser',
11
12
  naming: 'server_rendering.js',
12
13
  define: {
@@ -8,6 +8,7 @@ const isWatch = process.argv.includes('--watch')
8
8
  const buildOptions = {
9
9
  entryPoints: ['app/javascript/server_rendering.jsx'],
10
10
  bundle: true,
11
+ jsx: 'automatic',
11
12
  sourcemap: true,
12
13
  outfile: 'app/assets/builds/server_rendering.js',
13
14
  platform: 'browser',
@@ -1,4 +1,3 @@
1
- import React from "react";
2
1
  import { createApp } from "@thoughtbot/superglue";
3
2
  import { buildVisitAndRemote } from "./application_visit";
4
3
  import { pageIdentifierToPageComponent } from "./page_to_page_mapping";
@@ -1,4 +1,3 @@
1
- import React from "react";
2
1
  import { createApp } from "@thoughtbot/superglue";
3
2
  import { buildVisitAndRemote } from "./application_visit";
4
3
  import { pageIdentifierToPageComponent } from "./page_to_page_mapping";
@@ -15,7 +15,8 @@ module.exports = {
15
15
  exclude: /node_modules/,
16
16
  loader: "esbuild-loader",
17
17
  options: {
18
- target: "es2020"
18
+ target: "es2020",
19
+ jsx: "automatic"
19
20
  }
20
21
  }
21
22
  ]
@@ -1,4 +1,3 @@
1
- import React from "react";
2
1
  import { createRoot, hydrateRoot } from "react-dom/client";
3
2
  import { createApp, SaveResponse } from "@thoughtbot/superglue";
4
3
  import { buildVisitAndRemote } from "./application_visit";
@@ -11,6 +11,7 @@ const buildOptions = {
11
11
  'app/javascript/application.tsx',
12
12
  ],
13
13
  bundle: true,
14
+ jsx: 'automatic',
14
15
  sourcemap: true,
15
16
  format: 'esm',
16
17
  outdir: 'app/assets/builds',
@@ -10,6 +10,7 @@ const buildOptions = {
10
10
  'app/javascript/application.tsx',
11
11
  ],
12
12
  bundle: true,
13
+ jsx: 'automatic',
13
14
  sourcemap: true,
14
15
  format: 'esm',
15
16
  outdir: 'app/assets/builds',
@@ -12,6 +12,7 @@ const buildOptions = {
12
12
  'app/javascript/application.tsx',
13
13
  ],
14
14
  bundle: true,
15
+ jsx: 'automatic',
15
16
  sourcemap: true,
16
17
  format: 'esm',
17
18
  outdir: 'app/assets/builds',
@@ -7,7 +7,7 @@
7
7
  * There is no style and structured with bare necessities. You should modify
8
8
  * these components to fit your design needs.
9
9
  */
10
- import React, { createContext, ReactNode, useContext, useMemo } from "react";
10
+ import { createContext, ReactNode, useContext, useMemo } from "react";
11
11
 
12
12
  export type {
13
13
  CheckboxField as RailsCheckboxFieldProps,
@@ -1,4 +1,4 @@
1
- import React, {ReactNode} from 'react'
1
+ import type { ReactNode } from 'react'
2
2
  import { useAppFlash } from '@javascript/flash'
3
3
 
4
4
  export const Layout = ({children}: {children: ReactNode}) => {
@@ -7,7 +7,7 @@
7
7
  "strictPropertyInitialization": false,
8
8
  "noUnusedLocals": true,
9
9
  "noUnusedParameters": true,
10
- "jsx": "preserve",
10
+ "jsx": "react-jsx",
11
11
  "allowJs": false,
12
12
  "target": "ES2021",
13
13
  "allowSyntheticDefaultImports": true,
@@ -15,7 +15,8 @@ module.exports = {
15
15
  exclude: /node_modules/,
16
16
  loader: "esbuild-loader",
17
17
  options: {
18
- target: "es2020"
18
+ target: "es2020",
19
+ jsx: "automatic"
19
20
  }
20
21
  }
21
22
  ]
@@ -14,7 +14,8 @@ module.exports = {
14
14
  exclude: /node_modules/,
15
15
  loader: "esbuild-loader",
16
16
  options: {
17
- target: "es2020"
17
+ target: "es2020",
18
+ jsx: "automatic"
18
19
  }
19
20
  }
20
21
  ]
@@ -14,7 +14,8 @@ module.exports = {
14
14
  exclude: /node_modules/,
15
15
  loader: "esbuild-loader",
16
16
  options: {
17
- target: "es2020"
17
+ target: "es2020",
18
+ jsx: "automatic"
18
19
  }
19
20
  }
20
21
  ]
@@ -15,7 +15,8 @@ module.exports = {
15
15
  exclude: /node_modules/,
16
16
  loader: "esbuild-loader",
17
17
  options: {
18
- target: "es2020"
18
+ target: "es2020",
19
+ jsx: "automatic"
19
20
  }
20
21
  }
21
22
  ]
@@ -1,4 +1,3 @@
1
- import React from 'react'
2
1
  import {
3
2
  Form,
4
3
  Layout,
@@ -1,4 +1,3 @@
1
- import React from 'react'
2
1
  import { Form, Layout } from '@javascript/components'
3
2
  import { useContent } from '@thoughtbot/superglue'
4
3
 
@@ -1,4 +1,3 @@
1
- import React from 'react'
2
1
  import {
3
2
  Form,
4
3
  Layout,
@@ -1,4 +1,3 @@
1
- import React from 'react'
2
1
  import { Layout } from '@javascript/components'
3
2
  import { useContent } from '@thoughtbot/superglue'
4
3
 
@@ -1,4 +1,3 @@
1
- import React from 'react'
2
1
  import {
3
2
  Form,
4
3
  FormProps,
@@ -1,4 +1,3 @@
1
- import React from 'react'
2
1
  import { Form, FormProps, Layout } from '@javascript/components'
3
2
  import { useContent } from '@thoughtbot/superglue'
4
3
 
@@ -1,4 +1,3 @@
1
- import React from 'react'
2
1
  import {
3
2
  Form,
4
3
  FormProps,
@@ -1,4 +1,3 @@
1
- import React from 'react'
2
1
  import { Layout } from '@javascript/components'
3
2
  import { useContent } from '@thoughtbot/superglue'
4
3
 
@@ -13,8 +13,7 @@ module Superglue
13
13
  class_option :typescript,
14
14
  type: :boolean,
15
15
  required: false,
16
- default: false,
17
- desc: "Use typescript"
16
+ desc: "Use TypeScript. Defaults to true when tsconfig.json exists."
18
17
 
19
18
  def create_root_folder
20
19
  path = File.join("app/views", controller_file_path)
@@ -34,7 +33,7 @@ module Superglue
34
33
  def copy_js_files
35
34
  available_views.each do |view|
36
35
  @action_name = view
37
- if options["typescript"]
36
+ if use_typescript?
38
37
  filename = filename_with_tsx_extensions(view)
39
38
  template "ts/" + filename, File.join("app/views", controller_file_path, filename)
40
39
  else
@@ -46,7 +45,7 @@ module Superglue
46
45
 
47
46
  def append_mapping
48
47
  available_views.each do |action|
49
- app_js = if options["typescript"]
48
+ app_js = if use_typescript?
50
49
  "#{app_js_path}/page_to_page_mapping.ts"
51
50
  else
52
51
  "#{app_js_path}/page_to_page_mapping.js"
@@ -54,7 +53,7 @@ module Superglue
54
53
 
55
54
  component_name = [plural_table_name, action].map(&:camelcase).join
56
55
 
57
- js_ext = options["typescript"] ? "html.tsx" : "html.jsx"
56
+ js_ext = use_typescript? ? "html.tsx" : "html.jsx"
58
57
 
59
58
  if match_file(app_js, /pageIdentifierToPageComponent = {$/)
60
59
  prepend_to_file app_js do
@@ -72,6 +71,14 @@ module Superglue
72
71
 
73
72
  protected
74
73
 
74
+ def use_typescript?
75
+ if options["typescript"].nil?
76
+ File.exist?(File.join(destination_root, "tsconfig.json"))
77
+ else
78
+ options["typescript"]
79
+ end
80
+ end
81
+
75
82
  def js_component(attribute)
76
83
  case attribute.type
77
84
  when :string
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: superglue
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0.rc.1
4
+ version: 2.0.0.rc.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Johny Ho