superglue 2.0.0.alpha.10 → 2.0.0.alpha.11
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 +10 -1
- data/lib/generators/superglue/install/templates/esbuild/plugin.js +43 -0
- data/lib/generators/superglue/install/templates/js/build.mjs +26 -0
- data/lib/generators/superglue/install/templates/ts/build.mjs +27 -0
- data/lib/generators/superglue/install/templates/ts/page_to_page_mapping.ts +3 -1
- data/lib/generators/superglue/install/templates/ts/tsconfig.json +2 -1
- data/lib/generators/superglue/view_collection/templates/ts/new.tsx +1 -1
- data/lib/superglue/rendering.rb +18 -4
- metadata +6 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: b1527733a6372de0c0ec7d25718e65f2461b5d50ab16cbb54fa7b37a46d6a485
|
|
4
|
+
data.tar.gz: b22b3698f31b77ce9b67bda5789f39f617f14abc8dbef550dec67b15355b530d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 60cd812d8228c56b0f5d86b2bc7c42d0f57d9f27d6d601efa9f50a8221049f63b560322c7790bb6a5c76bf1dd15e98038c8d498969e1f2a076965443144a939c
|
|
7
|
+
data.tar.gz: c9a3d065a75ead8c7055bd77d68ee829ea7602b83fefbdcd55c106b9161f318e106b423a498ba4d21c058ce1580215ba255fd188f48777a35eaa23699d39579f
|
|
@@ -43,7 +43,7 @@ module Superglue
|
|
|
43
43
|
run "yarn add react react-dom @reduxjs/toolkit react-redux @thoughtbot/superglue@2.0.0-alpha.8"
|
|
44
44
|
|
|
45
45
|
if use_typescript
|
|
46
|
-
run "yarn add -D @types/react-dom @types/react @types/node @thoughtbot/candy_wrapper@0.0.4"
|
|
46
|
+
run "yarn add -D @types/react-dom @types/react @types/node @deepkit/type @deepkit/core @deepkit/type-compiler @thoughtbot/candy_wrapper@0.0.4 typescript"
|
|
47
47
|
end
|
|
48
48
|
|
|
49
49
|
say "Superglue is Installed! 🎉", :green
|
|
@@ -113,6 +113,12 @@ module Superglue
|
|
|
113
113
|
|
|
114
114
|
say "Copying tsconfig.json file to #{app_js_path}"
|
|
115
115
|
copy_file "#{__dir__}/templates/ts/tsconfig.json", "tsconfig.json"
|
|
116
|
+
|
|
117
|
+
say "Copying esbuild plugin for Deepkit"
|
|
118
|
+
copy_file "#{__dir__}/templates/esbuild/plugin.js", "deepkit.mjs"
|
|
119
|
+
|
|
120
|
+
say "Adding build.mjs for TypeScript compilation"
|
|
121
|
+
copy_file "#{__dir__}/templates/ts/build.mjs", "build.mjs"
|
|
116
122
|
end
|
|
117
123
|
|
|
118
124
|
def copy_js_files
|
|
@@ -138,6 +144,9 @@ module Superglue
|
|
|
138
144
|
|
|
139
145
|
say "Copying jsconfig.json file to #{app_js_path}"
|
|
140
146
|
copy_file "#{__dir__}/templates/js/jsconfig.json", "jsconfig.json"
|
|
147
|
+
|
|
148
|
+
say "Adding build.mjs for TypeScript compilation"
|
|
149
|
+
copy_file "#{__dir__}/templates/js/build.mjs", "build.mjs"
|
|
141
150
|
end
|
|
142
151
|
|
|
143
152
|
def add_member_methods
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import * as ts from "typescript";
|
|
2
|
+
import { cwd } from "process";
|
|
3
|
+
import { declarationTransformer, transformer } from "@deepkit/type-compiler";
|
|
4
|
+
import { readFile } from "fs/promises";
|
|
5
|
+
|
|
6
|
+
export default function deepkitType(options = {}){
|
|
7
|
+
return {
|
|
8
|
+
name: "Deepkit",
|
|
9
|
+
setup(build) {
|
|
10
|
+
const transformers = options.transformers || {
|
|
11
|
+
before: [transformer],
|
|
12
|
+
after: [declarationTransformer],
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
build.onLoad({ filter: /\.tsx?$/ }, async (args) => {
|
|
16
|
+
const configFilePath = options.tsConfig || cwd() + "/tsconfig.json";
|
|
17
|
+
|
|
18
|
+
const code = await readFile(args.path, { encoding: 'utf8' });
|
|
19
|
+
const transformed = ts.transpileModule(code, {
|
|
20
|
+
compilerOptions: Object.assign(
|
|
21
|
+
{
|
|
22
|
+
target: ts.ScriptTarget.ESNext,
|
|
23
|
+
module: ts.ModuleKind.ESNext,
|
|
24
|
+
sourceMap: false,
|
|
25
|
+
skipDefaultLibCheck: true,
|
|
26
|
+
skipLibCheck: true,
|
|
27
|
+
configFilePath,
|
|
28
|
+
},
|
|
29
|
+
options || {},
|
|
30
|
+
),
|
|
31
|
+
fileName: args.path,
|
|
32
|
+
moduleName: args.namespace,
|
|
33
|
+
transformers,
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
return {
|
|
37
|
+
contents: transformed.outputText,
|
|
38
|
+
loader: args.path.endsWith('.tsx') ? 'tsx' : 'ts'
|
|
39
|
+
};
|
|
40
|
+
});
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import * as esbuild from 'esbuild'
|
|
2
|
+
|
|
3
|
+
const isWatch = process.argv.includes('--watch')
|
|
4
|
+
|
|
5
|
+
const buildOptions = {
|
|
6
|
+
entryPoints: [
|
|
7
|
+
'app/javascript/application.jsx',
|
|
8
|
+
],
|
|
9
|
+
bundle: true,
|
|
10
|
+
sourcemap: true,
|
|
11
|
+
format: 'esm',
|
|
12
|
+
outdir: 'app/assets/builds',
|
|
13
|
+
publicPath: '/assets',
|
|
14
|
+
plugins: process.env.NODE_ENV === 'production' ? [] : [] ,
|
|
15
|
+
metafile: true,
|
|
16
|
+
conditions: process.env.NODE_ENV === 'production' ? ['production'] : [],
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
if (isWatch) {
|
|
20
|
+
const ctx = await esbuild.context(buildOptions)
|
|
21
|
+
await ctx.watch()
|
|
22
|
+
console.log('Watching for changes...')
|
|
23
|
+
} else {
|
|
24
|
+
const result = await esbuild.build(buildOptions)
|
|
25
|
+
console.log(await esbuild.analyzeMetafile(result.metafile))
|
|
26
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import * as esbuild from 'esbuild'
|
|
2
|
+
import deepkitType from './deepkit.mjs'
|
|
3
|
+
|
|
4
|
+
const isWatch = process.argv.includes('--watch')
|
|
5
|
+
|
|
6
|
+
const buildOptions = {
|
|
7
|
+
entryPoints: [
|
|
8
|
+
'app/javascript/application.tsx',
|
|
9
|
+
],
|
|
10
|
+
bundle: true,
|
|
11
|
+
sourcemap: true,
|
|
12
|
+
format: 'esm',
|
|
13
|
+
outdir: 'app/assets/builds',
|
|
14
|
+
publicPath: '/assets',
|
|
15
|
+
plugins: process.env.NODE_ENV === 'production' ? [] : [deepkitType()] ,
|
|
16
|
+
metafile: true,
|
|
17
|
+
conditions: process.env.NODE_ENV === 'production' ? ['production'] : [],
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
if (isWatch) {
|
|
21
|
+
const ctx = await esbuild.context(buildOptions)
|
|
22
|
+
await ctx.watch()
|
|
23
|
+
console.log('Watching for changes...')
|
|
24
|
+
} else {
|
|
25
|
+
const result = await esbuild.build(buildOptions)
|
|
26
|
+
console.log(await esbuild.analyzeMetafile(result.metafile))
|
|
27
|
+
}
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
"strictPropertyInitialization": false,
|
|
8
8
|
"noUnusedLocals": true,
|
|
9
9
|
"noUnusedParameters": true,
|
|
10
|
-
"jsx": "
|
|
10
|
+
"jsx": "preserve",
|
|
11
11
|
"allowJs": false,
|
|
12
12
|
"target": "ES2021",
|
|
13
13
|
"allowSyntheticDefaultImports": true,
|
|
@@ -24,4 +24,5 @@
|
|
|
24
24
|
"app/javascript/**/*",
|
|
25
25
|
"app/views/**/*"
|
|
26
26
|
],
|
|
27
|
+
"reflection": true
|
|
27
28
|
}
|
|
@@ -17,7 +17,7 @@ type ContentProps = {
|
|
|
17
17
|
<%= js_plural_table_name %>Path: string
|
|
18
18
|
<%= js_singular_table_name %>Form: FormProps<{
|
|
19
19
|
<%- attributes.each do |attr| -%>
|
|
20
|
-
<%= attr.column_name.camelize(:lower)%>: <%=
|
|
20
|
+
<%= attr.column_name.camelize(:lower)%>: Rails<%= js_component(attr)%>Props
|
|
21
21
|
<%- end -%>
|
|
22
22
|
submit: RailsSubmitButtonProps
|
|
23
23
|
}>
|
data/lib/superglue/rendering.rb
CHANGED
|
@@ -25,14 +25,24 @@ module Superglue
|
|
|
25
25
|
end
|
|
26
26
|
|
|
27
27
|
@_render_options = options
|
|
28
|
-
_ensure_react_page!(options[:template], options[:prefixes])
|
|
28
|
+
_ensure_react_page!(options[:template], options[:prefixes]) if request.format.html?
|
|
29
29
|
|
|
30
|
-
|
|
31
|
-
|
|
30
|
+
target_template_exists = template_exists?(options[:template], options[:prefixes], false)
|
|
31
|
+
|
|
32
|
+
if request.format.html? && !target_template_exists
|
|
33
|
+
# this uses the default superglue html template, which is super basic so
|
|
34
|
+
# we don't' need to create a separate one for each view
|
|
32
35
|
super(options.merge(
|
|
33
36
|
template: _superglue_template,
|
|
34
37
|
prefixes: []
|
|
35
38
|
))
|
|
39
|
+
elsif request.format.json? && !target_template_exists
|
|
40
|
+
# This fixes an issue with rendering json direclty but teh template doesn't exist
|
|
41
|
+
# we still want ot see the layout rendered
|
|
42
|
+
super(options.merge(
|
|
43
|
+
inline: "",
|
|
44
|
+
layout: _layout_for_option(true)
|
|
45
|
+
))
|
|
36
46
|
else
|
|
37
47
|
super
|
|
38
48
|
end
|
|
@@ -54,7 +64,11 @@ module Superglue
|
|
|
54
64
|
end
|
|
55
65
|
|
|
56
66
|
def _jsx_defaults
|
|
57
|
-
@_use_jsx_rendering_defaults && request.format.html?
|
|
67
|
+
@_use_jsx_rendering_defaults && (request.format.html? || request.format.json?)
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def _props_defaults
|
|
71
|
+
@_use_jsx_rendering_defaults && request.format.json?
|
|
58
72
|
end
|
|
59
73
|
|
|
60
74
|
def _ensure_react_page!(template, prefixes)
|
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.alpha.
|
|
4
|
+
version: 2.0.0.alpha.11
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Johny Ho
|
|
@@ -35,14 +35,14 @@ dependencies:
|
|
|
35
35
|
requirements:
|
|
36
36
|
- - "~>"
|
|
37
37
|
- !ruby/object:Gem::Version
|
|
38
|
-
version: 1.0.0
|
|
38
|
+
version: 1.0.0
|
|
39
39
|
type: :runtime
|
|
40
40
|
prerelease: false
|
|
41
41
|
version_requirements: !ruby/object:Gem::Requirement
|
|
42
42
|
requirements:
|
|
43
43
|
- - "~>"
|
|
44
44
|
- !ruby/object:Gem::Version
|
|
45
|
-
version: 1.0.0
|
|
45
|
+
version: 1.0.0
|
|
46
46
|
- !ruby/object:Gem::Dependency
|
|
47
47
|
name: form_props
|
|
48
48
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -79,9 +79,11 @@ files:
|
|
|
79
79
|
- lib/generators/superglue/install/install_generator.rb
|
|
80
80
|
- lib/generators/superglue/install/templates/application.json.props
|
|
81
81
|
- lib/generators/superglue/install/templates/erb/superglue.html.erb
|
|
82
|
+
- lib/generators/superglue/install/templates/esbuild/plugin.js
|
|
82
83
|
- lib/generators/superglue/install/templates/initializer.rb
|
|
83
84
|
- lib/generators/superglue/install/templates/js/application.jsx
|
|
84
85
|
- lib/generators/superglue/install/templates/js/application_visit.js
|
|
86
|
+
- lib/generators/superglue/install/templates/js/build.mjs
|
|
85
87
|
- lib/generators/superglue/install/templates/js/components.js
|
|
86
88
|
- lib/generators/superglue/install/templates/js/flash.js
|
|
87
89
|
- lib/generators/superglue/install/templates/js/inputs.jsx
|
|
@@ -92,6 +94,7 @@ files:
|
|
|
92
94
|
- lib/generators/superglue/install/templates/stream.json.props
|
|
93
95
|
- lib/generators/superglue/install/templates/ts/application.tsx
|
|
94
96
|
- lib/generators/superglue/install/templates/ts/application_visit.ts
|
|
97
|
+
- lib/generators/superglue/install/templates/ts/build.mjs
|
|
95
98
|
- lib/generators/superglue/install/templates/ts/components.ts
|
|
96
99
|
- lib/generators/superglue/install/templates/ts/flash.ts
|
|
97
100
|
- lib/generators/superglue/install/templates/ts/inputs.tsx
|