superglue 2.0.0.rc.2 → 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.
- checksums.yaml +4 -4
- data/lib/generators/superglue/install/install_generator.rb +62 -4
- data/lib/generators/superglue/install/templates/bun/bun.config.deepkit.js +1 -0
- data/lib/generators/superglue/install/templates/bun/bun.config.js +1 -0
- data/lib/generators/superglue/install/templates/bun/bun.config.ts.js +1 -0
- data/lib/generators/superglue/install/templates/bun/bun.config.typia.js +1 -0
- data/lib/generators/superglue/install/templates/js/application.jsx +0 -1
- data/lib/generators/superglue/install/templates/js/build.mjs +1 -0
- data/lib/generators/superglue/install/templates/js/inputs.jsx +1 -1
- data/lib/generators/superglue/install/templates/js/jsconfig.json +1 -0
- data/lib/generators/superglue/install/templates/js/layout.jsx +0 -1
- data/lib/generators/superglue/install/templates/ssr/bun.build_ssr.js +1 -0
- data/lib/generators/superglue/install/templates/ssr/esbuild.build_ssr.mjs +1 -0
- data/lib/generators/superglue/install/templates/ssr/server_rendering.jsx +0 -1
- data/lib/generators/superglue/install/templates/ssr/server_rendering.tsx +0 -1
- data/lib/generators/superglue/install/templates/ssr/webpack.build_ssr.js +2 -1
- data/lib/generators/superglue/install/templates/ts/application.tsx +0 -1
- data/lib/generators/superglue/install/templates/ts/build.deepkit.mjs +1 -0
- data/lib/generators/superglue/install/templates/ts/build.mjs +1 -0
- data/lib/generators/superglue/install/templates/ts/build.typia.mjs +1 -0
- data/lib/generators/superglue/install/templates/ts/inputs.tsx +1 -1
- data/lib/generators/superglue/install/templates/ts/layout.tsx +1 -1
- data/lib/generators/superglue/install/templates/ts/tsconfig.json +1 -1
- data/lib/generators/superglue/install/templates/webpack/webpack.config.deepkit.js +2 -1
- data/lib/generators/superglue/install/templates/webpack/webpack.config.js +2 -1
- data/lib/generators/superglue/install/templates/webpack/webpack.config.ts.js +2 -1
- data/lib/generators/superglue/install/templates/webpack/webpack.config.typia.js +2 -1
- data/lib/generators/superglue/view_collection/templates/js/edit.html.jsx +0 -1
- data/lib/generators/superglue/view_collection/templates/js/index.html.jsx +0 -1
- data/lib/generators/superglue/view_collection/templates/js/new.html.jsx +0 -1
- data/lib/generators/superglue/view_collection/templates/js/show.html.jsx +0 -1
- data/lib/generators/superglue/view_collection/templates/ts/edit.html.tsx +0 -1
- data/lib/generators/superglue/view_collection/templates/ts/index.html.tsx +0 -1
- data/lib/generators/superglue/view_collection/templates/ts/new.html.tsx +0 -1
- data/lib/generators/superglue/view_collection/templates/ts/show.html.tsx +0 -1
- data/lib/generators/superglue/view_collection/view_collection_generator.rb +12 -5
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: d17162adf65950ea5d4ee63e82835d8893c7f532607206b8a9e5bce609547297
|
|
4
|
+
data.tar.gz: e18b77ee95528a871782d9cc5a296601fa3763f03ef162354b5b2b165a7455b6
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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
|
-
|
|
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-rc.
|
|
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,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
|
|
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)
|
|
@@ -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
|
|
10
|
+
import { createContext, ReactNode, useContext, useMemo } from "react";
|
|
11
11
|
|
|
12
12
|
export type {
|
|
13
13
|
CheckboxField as RailsCheckboxFieldProps,
|
|
@@ -13,8 +13,7 @@ module Superglue
|
|
|
13
13
|
class_option :typescript,
|
|
14
14
|
type: :boolean,
|
|
15
15
|
required: false,
|
|
16
|
-
|
|
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
|
|
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
|
|
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 =
|
|
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
|