superglue 2.0.0.beta.2 → 2.0.0.rc.1

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 (51) hide show
  1. checksums.yaml +4 -4
  2. data/app/views/application/_humid.html.erb +1 -0
  3. data/lib/generators/superglue/install/install_generator.rb +223 -83
  4. data/lib/generators/superglue/install/templates/bun/bun.config.deepkit.js +5 -7
  5. data/lib/generators/superglue/install/templates/bun/bun.config.js +5 -7
  6. data/lib/generators/superglue/install/templates/bun/bun.config.ts.js +5 -7
  7. data/lib/generators/superglue/install/templates/bun/bun.config.typia.js +37 -0
  8. data/lib/generators/superglue/install/templates/bun/page_to_page_mapping.js +1 -1
  9. data/lib/generators/superglue/install/templates/bun/page_to_page_mapping.ts +1 -1
  10. data/lib/generators/superglue/install/templates/humid_initializer.rb +47 -0
  11. data/lib/generators/superglue/install/templates/js/application.jsx +8 -3
  12. data/lib/generators/superglue/install/templates/js/build.mjs +14 -3
  13. data/lib/generators/superglue/install/templates/js/page_to_page_mapping.js +9 -32
  14. data/lib/generators/superglue/install/templates/rollup/page_to_page_mapping.js +1 -1
  15. data/lib/generators/superglue/install/templates/rollup/page_to_page_mapping.ts +1 -1
  16. data/lib/generators/superglue/install/templates/rollup/rollup.config.deepkit.js +1 -1
  17. data/lib/generators/superglue/install/templates/rollup/rollup.config.js +2 -2
  18. data/lib/generators/superglue/install/templates/rollup/rollup.config.ts.js +2 -2
  19. data/lib/generators/superglue/install/templates/rollup/rollup.config.typia.js +38 -0
  20. data/lib/generators/superglue/install/templates/ssr/bun.build_ssr.js +37 -0
  21. data/lib/generators/superglue/install/templates/ssr/esbuild.build_ssr.mjs +37 -0
  22. data/lib/generators/superglue/install/templates/ssr/rollup.build_ssr.config.js +42 -0
  23. data/lib/generators/superglue/install/templates/ssr/server_rendering.jsx +22 -0
  24. data/lib/generators/superglue/install/templates/ssr/server_rendering.tsx +26 -0
  25. data/lib/generators/superglue/install/templates/ssr/shim.js +8490 -0
  26. data/lib/generators/superglue/install/templates/ssr/webpack.build_ssr.js +40 -0
  27. data/lib/generators/superglue/install/templates/ts/application.tsx +9 -5
  28. data/lib/generators/superglue/install/templates/ts/build.deepkit.mjs +13 -2
  29. data/lib/generators/superglue/install/templates/ts/build.mjs +14 -3
  30. data/lib/generators/superglue/install/templates/ts/build.typia.mjs +39 -0
  31. data/lib/generators/superglue/install/templates/ts/page_to_page_mapping.ts +11 -33
  32. data/lib/generators/superglue/install/templates/ts/tsconfig.json +1 -0
  33. data/lib/generators/superglue/install/templates/webpack/page_to_page_mapping.js +1 -1
  34. data/lib/generators/superglue/install/templates/webpack/page_to_page_mapping.ts +1 -1
  35. data/lib/generators/superglue/install/templates/webpack/webpack.config.typia.js +42 -0
  36. data/lib/generators/superglue/scaffold_controller/scaffold_controller_generator.rb +0 -3
  37. data/lib/generators/superglue/view_collection/view_collection_generator.rb +5 -3
  38. data/lib/superglue/engine.rb +25 -4
  39. data/lib/superglue/rendering.rb +8 -69
  40. data/lib/superglue.rb +1 -1
  41. metadata +38 -13
  42. data/lib/generators/superglue/install/templates/erb/superglue.html.erb +0 -5
  43. data/lib/superglue/resolver.rb +0 -58
  44. /data/lib/generators/superglue/view_collection/templates/js/{edit.jsx → edit.html.jsx} +0 -0
  45. /data/lib/generators/superglue/view_collection/templates/js/{index.jsx → index.html.jsx} +0 -0
  46. /data/lib/generators/superglue/view_collection/templates/js/{new.jsx → new.html.jsx} +0 -0
  47. /data/lib/generators/superglue/view_collection/templates/js/{show.jsx → show.html.jsx} +0 -0
  48. /data/lib/generators/superglue/view_collection/templates/ts/{edit.tsx → edit.html.tsx} +0 -0
  49. /data/lib/generators/superglue/view_collection/templates/ts/{index.tsx → index.html.tsx} +0 -0
  50. /data/lib/generators/superglue/view_collection/templates/ts/{new.tsx → new.html.tsx} +0 -0
  51. /data/lib/generators/superglue/view_collection/templates/ts/{show.tsx → show.html.tsx} +0 -0
@@ -1,4 +1,7 @@
1
1
  import * as esbuild from 'esbuild'
2
+ import { watch } from 'fs'
3
+ import { default as importGlob } from 'esbuild-plugin-import-glob'
4
+ const importGlobPlugin = importGlob.default
2
5
 
3
6
  const isWatch = process.argv.includes('--watch')
4
7
 
@@ -11,16 +14,24 @@ const buildOptions = {
11
14
  format: 'esm',
12
15
  outdir: 'app/assets/builds',
13
16
  publicPath: '/assets',
14
- plugins: process.env.NODE_ENV === 'production' ? [] : [] ,
17
+ plugins: [importGlobPlugin()],
15
18
  metafile: true,
16
19
  conditions: process.env.NODE_ENV === 'production' ? ['production'] : [],
17
20
  }
18
21
 
19
22
  if (isWatch) {
20
- const ctx = await esbuild.context(buildOptions)
23
+ let ctx = await esbuild.context(buildOptions)
21
24
  await ctx.watch()
22
25
  console.log('Watching for changes...')
26
+
27
+ watch('app/views', { recursive: true }, async (event, filename) => {
28
+ if (event === 'rename' && /\.[jt]sx$/.test(filename)) {
29
+ await ctx.dispose()
30
+ ctx = await esbuild.context(buildOptions)
31
+ await ctx.watch()
32
+ }
33
+ })
23
34
  } else {
24
35
  const result = await esbuild.build(buildOptions)
25
36
  console.log(await esbuild.analyzeMetafile(result.metafile))
26
- }
37
+ }
@@ -1,35 +1,12 @@
1
- // import your page component
2
- // e.g import PostsEdit from '../views/posts/edit'
1
+ import * as pages from '../views/**/*.{tsx,jsx}'
3
2
 
4
- // Mapping between your props template to Component, you must add to this
5
- // to register any new page level component you create. If you are using the
6
- // scaffold, it will auto append the identifers for you.
7
- //
8
- // For example:
9
- //
10
- // const pageIdentifierToPageComponent = {
11
- // 'posts/new': PostNew
12
- // };
13
- //
14
- //
15
- // If you are using a build tool that supports globbing, you can automatically
16
- // populate `pageIdentiferToPageComponent`. For example, if you are using vite,
17
- // you can use the following snippet instead of manually importing.
18
- //
19
- // ```
20
- // const pageIdentifierToPageComponent = {}
21
- // const pages = import.meta.glob('../views/**/*.jsx', {eager: true})
22
- //
23
- // for (const key in pages) {
24
- // if (pages.hasOwnProperty(key)) {
25
- // const identifier = key.replace("../views/", "").split('.')[0];
26
- // pageIdentifierToPageComponent[identifier] = pages[key].default;
27
- // }
28
- // }
29
- // ```
30
- //
31
- const pageIdentifierToPageComponent = {
32
- };
3
+ const pageIdentifierToPageComponent = {}
33
4
 
34
- export { pageIdentifierToPageComponent }
5
+ for (let i = 0; i < pages.filenames.length; i++) {
6
+ const identifier = pages.filenames[i]
7
+ .replace('../views/', '')
8
+ .split('.')[0]
9
+ pageIdentifierToPageComponent[identifier] = pages.default[i].default
10
+ }
35
11
 
12
+ export { pageIdentifierToPageComponent }
@@ -1,5 +1,5 @@
1
1
  const pageIdentifierToPageComponent = {}
2
- const pages = import.meta.glob('../views/**/*.jsx', { eager: true })
2
+ const pages = import.meta.glob('../views/**/*.{tsx,jsx}', { eager: true })
3
3
 
4
4
  for (const key in pages) {
5
5
  const identifier = key.replace('../views/', '').split('.')[0]
@@ -1,5 +1,5 @@
1
1
  const pageIdentifierToPageComponent: Record<string, React.ComponentType> = {}
2
- const pages = import.meta.glob('../views/**/*.tsx', { eager: true })
2
+ const pages = import.meta.glob('../views/**/*.{tsx,jsx}', { eager: true })
3
3
 
4
4
  for (const key in pages) {
5
5
  const identifier = key.replace('../views/', '').split('.')[0]
@@ -15,7 +15,6 @@ export default {
15
15
  sourcemap: true
16
16
  },
17
17
  plugins: [
18
- importMetaGlob(),
19
18
  alias({
20
19
  entries: [
21
20
  { find: "@javascript", replacement: path.resolve("app/javascript") },
@@ -32,6 +31,7 @@ export default {
32
31
  ],
33
32
  extensions: [".ts", ".tsx", ".js", ".jsx"]
34
33
  }),
34
+ importMetaGlob(),
35
35
  ...(process.env.NODE_ENV === 'production' ? [] : [deepkitPlugin()])
36
36
  ]
37
37
  }
@@ -14,7 +14,6 @@ export default {
14
14
  sourcemap: true
15
15
  },
16
16
  plugins: [
17
- importMetaGlob(),
18
17
  alias({
19
18
  entries: [
20
19
  { find: "@javascript", replacement: path.resolve("app/javascript") },
@@ -27,6 +26,7 @@ export default {
27
26
  babelHelpers: "bundled",
28
27
  presets: [["@babel/preset-react", { runtime: "automatic" }]],
29
28
  extensions: [".js", ".jsx"]
30
- })
29
+ }),
30
+ importMetaGlob(),
31
31
  ]
32
32
  }
@@ -14,7 +14,6 @@ export default {
14
14
  sourcemap: true
15
15
  },
16
16
  plugins: [
17
- importMetaGlob(),
18
17
  alias({
19
18
  entries: [
20
19
  { find: "@javascript", replacement: path.resolve("app/javascript") },
@@ -30,6 +29,7 @@ export default {
30
29
  "@babel/preset-typescript"
31
30
  ],
32
31
  extensions: [".ts", ".tsx", ".js", ".jsx"]
33
- })
32
+ }),
33
+ importMetaGlob(),
34
34
  ]
35
35
  }
@@ -0,0 +1,38 @@
1
+ import path from "path"
2
+ import resolve from "@rollup/plugin-node-resolve"
3
+ import commonjs from "@rollup/plugin-commonjs"
4
+ import babel from "@rollup/plugin-babel"
5
+ import alias from "@rollup/plugin-alias"
6
+ import importMetaGlob from "rollup-plugin-import-meta-glob"
7
+ import ttsc from "@ttsc/unplugin"
8
+ const ttscPlugin = ttsc.rollup
9
+
10
+ export default {
11
+ input: "app/javascript/application.tsx",
12
+ output: {
13
+ file: "app/assets/builds/application.js",
14
+ format: "esm",
15
+ inlineDynamicImports: true,
16
+ sourcemap: true
17
+ },
18
+ plugins: [
19
+ alias({
20
+ entries: [
21
+ { find: "@javascript", replacement: path.resolve("app/javascript") },
22
+ { find: "@views", replacement: path.resolve("app/views") }
23
+ ]
24
+ }),
25
+ resolve({ extensions: [".ts", ".tsx", ".js", ".jsx"] }),
26
+ commonjs(),
27
+ babel({
28
+ babelHelpers: "bundled",
29
+ presets: [
30
+ ["@babel/preset-react", { runtime: "automatic" }],
31
+ "@babel/preset-typescript"
32
+ ],
33
+ extensions: [".ts", ".tsx", ".js", ".jsx"]
34
+ }),
35
+ importMetaGlob(),
36
+ ...(process.env.NODE_ENV === 'production' ? [] : [ttscPlugin()])
37
+ ]
38
+ }
@@ -0,0 +1,37 @@
1
+ import { globImportPlugin } from 'bun-plugin-glob-import'
2
+ import { watch } from 'fs'
3
+
4
+ const isWatch = process.argv.includes('--watch')
5
+
6
+ const buildOptions = {
7
+ entrypoints: ['app/javascript/server_rendering.jsx'],
8
+ outdir: 'app/assets/builds',
9
+ sourcemap: 'external',
10
+ target: 'browser',
11
+ naming: 'server_rendering.js',
12
+ define: {
13
+ 'process.env.NODE_ENV': JSON.stringify('production'),
14
+ },
15
+ plugins: [globImportPlugin()],
16
+ }
17
+
18
+ if (isWatch) {
19
+ await Bun.build(buildOptions)
20
+ console.log('Watching SSR for changes...')
21
+
22
+ watch('app/views', { recursive: true }, async (event, filename) => {
23
+ if (event === 'rename' && /\.[jt]sx$/.test(filename)) {
24
+ await Bun.build(buildOptions)
25
+ }
26
+ })
27
+ } else {
28
+ const result = await Bun.build(buildOptions)
29
+
30
+ if (!result.success) {
31
+ console.error('SSR build failed')
32
+ for (const log of result.logs) {
33
+ console.error(log)
34
+ }
35
+ process.exit(1)
36
+ }
37
+ }
@@ -0,0 +1,37 @@
1
+ import * as esbuild from 'esbuild'
2
+ import { watch } from 'fs'
3
+ import { default as importGlob } from 'esbuild-plugin-import-glob'
4
+ const importGlobPlugin = importGlob.default
5
+
6
+ const isWatch = process.argv.includes('--watch')
7
+
8
+ const buildOptions = {
9
+ entryPoints: ['app/javascript/server_rendering.jsx'],
10
+ bundle: true,
11
+ sourcemap: true,
12
+ outfile: 'app/assets/builds/server_rendering.js',
13
+ platform: 'browser',
14
+ logLevel: 'info',
15
+ loader: {
16
+ '.svg': 'dataurl',
17
+ },
18
+ plugins: [
19
+ importGlobPlugin(),
20
+ ],
21
+ }
22
+
23
+ if (isWatch) {
24
+ let ctx = await esbuild.context(buildOptions)
25
+ await ctx.watch()
26
+ console.log('Watching SSR for changes...')
27
+
28
+ watch('app/views', { recursive: true }, async (event, filename) => {
29
+ if (event === 'rename' && /\.[jt]sx$/.test(filename)) {
30
+ await ctx.dispose()
31
+ ctx = await esbuild.context(buildOptions)
32
+ await ctx.watch()
33
+ }
34
+ })
35
+ } else {
36
+ await esbuild.build(buildOptions)
37
+ }
@@ -0,0 +1,42 @@
1
+ import path from "path"
2
+ import resolve from "@rollup/plugin-node-resolve"
3
+ import commonjs from "@rollup/plugin-commonjs"
4
+ import babel from "@rollup/plugin-babel"
5
+ import alias from "@rollup/plugin-alias"
6
+ import replace from "@rollup/plugin-replace"
7
+ import importMetaGlob from "rollup-plugin-import-meta-glob"
8
+
9
+ export default {
10
+ input: "app/javascript/server_rendering.jsx",
11
+ output: {
12
+ file: "app/assets/builds/server_rendering.js",
13
+ format: "iife",
14
+ name: "SSR",
15
+ inlineDynamicImports: true,
16
+ sourcemap: true,
17
+ },
18
+ plugins: [
19
+ replace({
20
+ preventAssignment: true,
21
+ 'process.env.NODE_ENV': JSON.stringify('production')
22
+ }),
23
+ alias({
24
+ entries: [
25
+ { find: "@javascript", replacement: path.resolve("app/javascript") },
26
+ { find: "@views", replacement: path.resolve("app/views") }
27
+ ]
28
+ }),
29
+ resolve({
30
+ extensions: [".js", ".jsx", ".ts", ".tsx"],
31
+ browser: true,
32
+ exportConditions: ["browser"]
33
+ }),
34
+ commonjs(),
35
+ babel({
36
+ babelHelpers: "bundled",
37
+ presets: [["@babel/preset-react", { runtime: "automatic" }]],
38
+ extensions: [".js", ".jsx", ".ts", ".tsx"]
39
+ }),
40
+ importMetaGlob(),
41
+ ]
42
+ }
@@ -0,0 +1,22 @@
1
+ import React from "react";
2
+ import { createApp } from "@thoughtbot/superglue";
3
+ import { buildVisitAndRemote } from "./application_visit";
4
+ import { pageIdentifierToPageComponent } from "./page_to_page_mapping";
5
+ import { renderToString } from "react-dom/server";
6
+
7
+ setHumidRenderer((json, baseUrl, path) => {
8
+ const initialState = JSON.parse(json);
9
+ const { Provider, Outlet } = createApp({
10
+ baseUrl,
11
+ initialPage: initialState,
12
+ path,
13
+ buildVisitAndRemote,
14
+ mapping: pageIdentifierToPageComponent,
15
+ });
16
+
17
+ return renderToString(
18
+ <Provider>
19
+ <Outlet />
20
+ </Provider>,
21
+ );
22
+ });
@@ -0,0 +1,26 @@
1
+ import React from "react";
2
+ import { createApp } from "@thoughtbot/superglue";
3
+ import { buildVisitAndRemote } from "./application_visit";
4
+ import { pageIdentifierToPageComponent } from "./page_to_page_mapping";
5
+ import { renderToString } from "react-dom/server";
6
+
7
+ declare function setHumidRenderer(
8
+ fn: (json: string, baseUrl: string, path: string) => string,
9
+ ): void;
10
+
11
+ setHumidRenderer((json, baseUrl, path) => {
12
+ const initialState = JSON.parse(json);
13
+ const { Provider, Outlet } = createApp({
14
+ baseUrl,
15
+ initialPage: initialState,
16
+ path,
17
+ buildVisitAndRemote,
18
+ mapping: pageIdentifierToPageComponent,
19
+ });
20
+
21
+ return renderToString(
22
+ <Provider>
23
+ <Outlet />
24
+ </Provider>,
25
+ );
26
+ });