@lomray/vite-ssr-boost 1.0.0-beta.2 → 1.0.0-beta.20

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 (83) hide show
  1. package/README.md +207 -0
  2. package/browser/entry.d.ts +8 -7
  3. package/browser/entry.js +1 -1
  4. package/browser/entry.js.map +1 -1
  5. package/cli/build.d.ts +4 -1
  6. package/cli/build.js +1 -1
  7. package/cli/build.js.map +1 -1
  8. package/cli/run-dev.d.ts +2 -1
  9. package/cli/run-dev.js +1 -1
  10. package/cli/run-dev.js.map +1 -1
  11. package/cli/run-docker-build.d.ts +12 -0
  12. package/cli/run-docker-build.js +2 -0
  13. package/cli/run-docker-build.js.map +1 -0
  14. package/cli/run-prod.d.ts +1 -0
  15. package/cli/run-prod.js +1 -1
  16. package/cli/run-prod.js.map +1 -1
  17. package/cli.js +1 -1
  18. package/cli.js.map +1 -1
  19. package/components/with-suspense.d.ts +7 -0
  20. package/components/with-suspense.js +2 -0
  21. package/components/with-suspense.js.map +1 -0
  22. package/constants/cli-actions.d.ts +1 -0
  23. package/constants/cli-actions.js +1 -1
  24. package/constants/cli-actions.js.map +1 -1
  25. package/helpers/dev-marker.d.ts +9 -0
  26. package/helpers/dev-marker.js +2 -0
  27. package/helpers/dev-marker.js.map +1 -0
  28. package/helpers/get-server-state.d.ts +5 -0
  29. package/helpers/get-server-state.js +2 -0
  30. package/helpers/get-server-state.js.map +1 -0
  31. package/helpers/import-route.d.ts +252 -0
  32. package/helpers/import-route.js +2 -0
  33. package/helpers/import-route.js.map +1 -0
  34. package/helpers/is-route-file.d.ts +5 -0
  35. package/helpers/is-route-file.js +2 -0
  36. package/helpers/is-route-file.js.map +1 -0
  37. package/helpers/print-server-info.js +1 -1
  38. package/helpers/print-server-info.js.map +1 -1
  39. package/helpers/print-server-urls.js +1 -1
  40. package/helpers/print-server-urls.js.map +1 -1
  41. package/helpers/unlock-robots.d.ts +5 -0
  42. package/helpers/unlock-robots.js +2 -0
  43. package/helpers/unlock-robots.js.map +1 -0
  44. package/helpers/vite-aliases.d.ts +6 -0
  45. package/helpers/vite-aliases.js +2 -0
  46. package/helpers/vite-aliases.js.map +1 -0
  47. package/interfaces/fc-route.d.ts +19 -0
  48. package/interfaces/fc-route.js +2 -0
  49. package/interfaces/fc-route.js.map +1 -0
  50. package/interfaces/fc.d.ts +4 -0
  51. package/interfaces/fc.js +2 -0
  52. package/interfaces/fc.js.map +1 -0
  53. package/interfaces/route-object.d.ts +8 -0
  54. package/interfaces/route-object.js +2 -0
  55. package/interfaces/route-object.js.map +1 -0
  56. package/node/entry.d.ts +11 -9
  57. package/node/entry.js +1 -1
  58. package/node/entry.js.map +1 -1
  59. package/node/render.d.ts +5 -4
  60. package/node/render.js +1 -1
  61. package/node/render.js.map +1 -1
  62. package/node/server.js +1 -1
  63. package/node/server.js.map +1 -1
  64. package/package.json +8 -4
  65. package/plugin.d.ts +6 -4
  66. package/plugin.js +1 -1
  67. package/plugin.js.map +1 -1
  68. package/plugins/make-aliases.d.ts +11 -0
  69. package/plugins/make-aliases.js +2 -0
  70. package/plugins/make-aliases.js.map +1 -0
  71. package/plugins/normalize-route.d.ts +13 -0
  72. package/plugins/normalize-route.js +2 -0
  73. package/plugins/normalize-route.js.map +1 -0
  74. package/services/prepare-server.d.ts +5 -3
  75. package/services/prepare-server.js +1 -1
  76. package/services/prepare-server.js.map +1 -1
  77. package/services/server-config.d.ts +6 -9
  78. package/services/server-config.js +1 -1
  79. package/services/server-config.js.map +1 -1
  80. package/services/ssr-manifest.d.ts +157 -0
  81. package/services/ssr-manifest.js +2 -0
  82. package/services/ssr-manifest.js.map +1 -0
  83. package/workflow/Dockerfile +23 -0
package/README.md ADDED
@@ -0,0 +1,207 @@
1
+ <h1 align='center'>Vite SSR BOOST</h1>
2
+
3
+ - Develop ⚡charged⚡ server side applications with React streaming 💨 support.
4
+ - Unlocks Suspense for server side applications.
5
+ - Switch between SPA and SSR in 1 second.
6
+ - Charged CLI out of box.
7
+ - Very easy to migrate, very easy to use.
8
+ - All the power of [vite](https://vitejs.dev/)⚡
9
+ - All the power of [react-router](https://reactrouter.com/)🛣
10
+
11
+ <p align="center">
12
+ <img src="https://sonarcloud.io/api/project_badges/measure?project=vite-ssr-boost&metric=reliability_rating" alt="reliability">
13
+ <img src="https://sonarcloud.io/api/project_badges/measure?project=vite-ssr-boost&metric=security_rating" alt="Security Rating">
14
+ <img src="https://sonarcloud.io/api/project_badges/measure?project=vite-ssr-boost&metric=sqale_rating" alt="Maintainability Rating">
15
+ <img src="https://sonarcloud.io/api/project_badges/measure?project=vite-ssr-boost&metric=vulnerabilities" alt="Vulnerabilities">
16
+ <img src="https://sonarcloud.io/api/project_badges/measure?project=vite-ssr-boost&metric=bugs" alt="Bugs">
17
+ <img src="https://sonarcloud.io/api/project_badges/measure?project=vite-ssr-boost&metric=ncloc" alt="Lines of Code">
18
+ <img src="https://img.shields.io/bundlephobia/minzip/@lomray/vite-ssr-boost" alt="size">
19
+ <img src="https://img.shields.io/npm/l/@lomray/vite-ssr-boost" alt="size">
20
+ <img src="https://img.shields.io/npm/v/@lomray/vite-ssr-boost?label=semantic%20release&logo=semantic-release" alt="semantic version">
21
+ </p>
22
+
23
+ ## Table of contents
24
+ - [Getting started](#getting-started)
25
+ - [How to use](#how-to-use)
26
+ - [Plugin options](#plugin-options)
27
+ - [CLI](#cli)
28
+ - [Example](#demo)
29
+ - [Bugs and feature requests](#bugs-and-feature-requests)
30
+ - [License](#license)
31
+
32
+ ## Getting started
33
+
34
+ The package is distributed using [npm](https://www.npmjs.com/), the node package manager.
35
+
36
+ ```
37
+ npm i --save @lomray/vite-ssr-boost
38
+ ```
39
+
40
+ ## How to use
41
+
42
+ 1. Add plugin to vite config:
43
+ ```typescript
44
+ /**
45
+ * vite.config.ts
46
+ */
47
+
48
+ import { defineConfig } from 'vite'
49
+ import react from '@vitejs/plugin-react'
50
+ /**
51
+ * Import plugin
52
+ */
53
+ import SsrBoost from '@lomray/vite-ssr-boost/plugin';
54
+
55
+ // https://vitejs.dev/config/
56
+ export default defineConfig({
57
+ /**
58
+ * Change root not necessary, but more understandable
59
+ */
60
+ root: 'src',
61
+ publicDir: '../public',
62
+ build: {
63
+ outDir: '../build',
64
+ },
65
+ /**
66
+ * Put here
67
+ */
68
+ plugins: [SsrBoost(), react()],
69
+ });
70
+
71
+ ```
72
+ 2. Create `client` entrypoint:
73
+
74
+ ```typescript jsx
75
+ /**
76
+ * src/client.tsx
77
+ */
78
+ import entryClient from '@lomray/vite-ssr-boost/browser/entry';
79
+ import App from './App.tsx'
80
+ import routes from './routes';
81
+
82
+ void entryClient(App, routes, {
83
+ /**
84
+ * Client configuration (optional)
85
+ */
86
+ init: () => {}
87
+ });
88
+ ```
89
+
90
+ 3. Create `server` entrypoint:
91
+
92
+ ```typescript jsx
93
+ /**
94
+ * src/server.ts
95
+ */
96
+ import entryServer from '@lomray/vite-ssr-boost/node/entry';
97
+ import App from './App';
98
+ import routes from './routes';
99
+
100
+ export default entryServer(App, routes, {
101
+ /**
102
+ * Server configuration (optional)
103
+ */
104
+ init: () => ({
105
+ /**
106
+ * (optional). Called once after express server creation.
107
+ * E.g. use for configure express middlewares
108
+ */
109
+ onServerCreated: () => {},
110
+ /**
111
+ * (optional). Called on each incoming request.
112
+ * E.g. configure request state, create state manager etc.
113
+ */
114
+ onRequest: async () => {},
115
+ /**
116
+ * (optional). Called when react router and it's context was created.
117
+ * E.g. here you can switch stream depends on req.headers, for search crawlers you can disable stream.
118
+ */
119
+ onRouterReady: () => {},
120
+ /**
121
+ * (optional). Called when application shell is ready to send on client.
122
+ * E.g. here you can modify header or footer.
123
+ */
124
+ onShellReady: () => {},
125
+ /**
126
+ * (optional). Called when application shell or suspense resolved and sent to the client.
127
+ * E.g. here you can add some payload like custom state (any manager state) to response.
128
+ */
129
+ onResponse: () => {},
130
+ /**
131
+ * (optional). Called when application shell or all html (depends on stream option) is ready to send on client.
132
+ * E.g. here you can send any context or state to client.
133
+ */
134
+ getState: () => {},
135
+ }),
136
+ }, App);
137
+ ```
138
+
139
+ 4. Replace `package.json` scripts:
140
+
141
+ ```json
142
+ {
143
+ ...
144
+ "scripts": {
145
+ "develop": "ssr-boost dev",
146
+ "build": "ssr-boost build",
147
+ "start:ssr": "ssr-boost start",
148
+ "start:spa": "ssr-boost start --only-client",
149
+ "preview": "ssr-boost preview"
150
+ },
151
+ ...
152
+ }
153
+ ```
154
+
155
+ 5. Let's do the magic:
156
+
157
+ ```shell
158
+ npm run develop
159
+ ```
160
+
161
+ ## Plugin options
162
+ ```typescript
163
+ import SsrBoost from '@lomray/vite-ssr-boost/plugin';
164
+ import type { FCRoute } from '@lomray/vite-ssr-boost/interfaces/fc-route';
165
+
166
+ /**
167
+ * Configuration
168
+ */
169
+ SsrBoost({
170
+ /**
171
+ * With this option you can export route components like FCRoute or FCCRoute
172
+ * @example
173
+ * const Page: FCRoute = () => <div>Hi</div>;
174
+ *
175
+ * Page.ErrorBoudary = () => <div>Error</div>;
176
+ *
177
+ * export default Page;
178
+ *
179
+ * Routes:
180
+ * const routes = [{ path: '/', lazyNR: () => import('./pages/home') }]
181
+ */
182
+ hasLazyRoutePlugin: true, // default: true
183
+
184
+ /**
185
+ * Add tsconfig aliases to vite config aliases
186
+ */
187
+ tsconfigAliases: true, // default: true
188
+ })
189
+ ```
190
+
191
+ ## CLI
192
+ Explore all commands and options:
193
+ ```shell
194
+ ssr-boost -h
195
+ ```
196
+
197
+ ## Demo
198
+ Explore [demo app](https://github.com/Lomray-Software/vite-template) to more understand.
199
+
200
+ ## Bugs and feature requests
201
+
202
+ Bug or a feature request, [please open a new issue](https://github.com/Lomray-Software/vite-ssr-boost/issues/new).
203
+
204
+ ## License
205
+ Made with 💚
206
+
207
+ Published under [Apache License](./LICENSE).
@@ -1,20 +1,21 @@
1
1
  /// <reference types="react-dom" />
2
+ import { Router as RemixRouter } from '@remix-run/router/dist/router';
2
3
  import { FC, PropsWithChildren } from 'react';
3
4
  import ReactDOM from 'react-dom/client';
4
- import { RouteObject } from 'react-router-dom';
5
- interface IEntryClientOptions {
6
- routes: RouteObject[];
7
- }
5
+ import { TRouteObject } from "../interfaces/route-object.js";
8
6
  interface IAppClientProps<T = undefined> {
9
7
  client: T;
10
8
  }
11
9
  interface IInitPropsParams {
12
10
  isSSRMode: boolean;
11
+ router: RemixRouter;
13
12
  }
14
13
  type TApp<T> = FC<PropsWithChildren<IAppClientProps<T>>>;
15
- type TAppGetProps<T> = (params: IInitPropsParams) => Promise<T>;
14
+ interface IEntryClientOptions<T> {
15
+ init?: (params: IInitPropsParams) => Promise<T>;
16
+ }
16
17
  /**
17
18
  * Render client side application
18
19
  */
19
- declare function entry<TAppProps>({ routes }: IEntryClientOptions, App: TApp<TAppProps>, initProps?: TAppGetProps<TAppProps>): Promise<ReactDOM.Root | void>;
20
- export { entry as default, IEntryClientOptions, IAppClientProps, IInitPropsParams, TApp, TAppGetProps };
20
+ declare function entry<TAppProps>(App: TApp<TAppProps>, routes: TRouteObject[], { init }?: IEntryClientOptions<TAppProps>): Promise<ReactDOM.Root | void>;
21
+ export { entry as default, IAppClientProps, IInitPropsParams, TApp, IEntryClientOptions };
package/browser/entry.js CHANGED
@@ -1,2 +1,2 @@
1
- import t from"react";import e from"react-dom/client";import{matchRoutes as o,createBrowserRouter as r,RouterProvider as a}from"react-router-dom";import{IS_SSR_MODE as n}from"../constants/common.js";async function c({routes:c},l,m){const i=o(c,window.location)?.filter((t=>t.route.lazy));i&&i?.length>0&&await Promise.all(i.map((async t=>{const e=await(t.route.lazy?.());Object.assign(t.route,{...e,lazy:void 0})})));const s=await(m?.({isSSRMode:n})),u=r(c),d=document.getElementById("root"),f=()=>t.createElement(l,{client:s},t.createElement(a,{router:u}));return n?e.hydrateRoot(d,t.createElement(f,null)):e.createRoot(d).render(t.createElement(f,null))}export{c as default};
1
+ import t from"react";import e from"react-dom/client";import{matchRoutes as o,createBrowserRouter as r,RouterProvider as a}from"react-router-dom";import{IS_SSR_MODE as n}from"../constants/common.js";async function c(c,l,{init:m}={}){const i=o(l,window.location)?.filter((t=>t.route.lazy));i&&i?.length>0&&await Promise.all(i.map((async t=>{const e=await(t.route.lazy?.());Object.assign(t.route,{...e,lazy:void 0})})));const s=r(l),u=document.getElementById("root"),d=await(m?.({isSSRMode:n,router:s})),f=()=>t.createElement(c,{client:d},t.createElement(a,{router:s}));return n?e.hydrateRoot(u,t.createElement(f,null)):e.createRoot(u).render(t.createElement(f,null))}export{c as default};
2
2
  //# sourceMappingURL=entry.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"entry.js","sources":["../../src/browser/entry.tsx"],"sourcesContent":["import type { FC, PropsWithChildren } from 'react';\nimport React from 'react';\nimport ReactDOM from 'react-dom/client';\nimport type { RouteObject } from 'react-router-dom';\nimport { createBrowserRouter, matchRoutes, RouterProvider } from 'react-router-dom';\nimport { IS_SSR_MODE } from '@constants/common';\n\nexport interface IEntryClientOptions {\n routes: RouteObject[];\n}\n\nexport interface IAppClientProps<T = undefined> {\n client: T;\n}\n\nexport interface IInitPropsParams {\n isSSRMode: boolean;\n}\n\nexport type TApp<T> = FC<PropsWithChildren<IAppClientProps<T>>>;\n\nexport type TAppGetProps<T> = (params: IInitPropsParams) => Promise<T>;\n\n/**\n * Render client side application\n */\nasync function entry<TAppProps>(\n { routes }: IEntryClientOptions,\n App: TApp<TAppProps>,\n initProps?: TAppGetProps<TAppProps>,\n): Promise<ReactDOM.Root | void> {\n const lazyMatches = matchRoutes(routes, window.location)?.filter((m) => m.route.lazy);\n\n // Load the lazy matches and update the routes before creating router,\n // so we can hydrate the SSR-rendered content synchronously\n if (lazyMatches && lazyMatches?.length > 0) {\n await Promise.all(\n lazyMatches.map(async (m) => {\n const routeModule = await m.route.lazy?.();\n\n Object.assign(m.route, {\n ...routeModule,\n lazy: undefined,\n });\n }),\n );\n }\n\n const appProps = (await initProps?.({ isSSRMode: IS_SSR_MODE })) as TAppProps;\n const router = createBrowserRouter(routes);\n const root = document.getElementById('root') as HTMLElement;\n\n const AppComponent: FC = () => (\n <App client={appProps}>\n <RouterProvider router={router} />\n </App>\n );\n\n if (!IS_SSR_MODE) {\n return ReactDOM.createRoot(root).render(<AppComponent />);\n }\n\n return ReactDOM.hydrateRoot(root, <AppComponent />);\n}\n\nexport default entry;\n"],"names":["async","entry","routes","App","initProps","lazyMatches","matchRoutes","window","location","filter","m","route","lazy","length","Promise","all","map","routeModule","Object","assign","undefined","appProps","isSSRMode","IS_SSR_MODE","router","createBrowserRouter","root","document","getElementById","AppComponent","React","createElement","client","RouterProvider","ReactDOM","hydrateRoot","createRoot","render"],"mappings":"sMA0BAA,eAAeC,GACbC,OAAEA,GACFC,EACAC,GAEA,MAAMC,EAAcC,EAAYJ,EAAQK,OAAOC,WAAWC,QAAQC,GAAMA,EAAEC,MAAMC,OAI5EP,GAAeA,GAAaQ,OAAS,SACjCC,QAAQC,IACZV,EAAYW,KAAIhB,MAAOU,IACrB,MAAMO,QAAoBP,EAAEC,MAAMC,UAElCM,OAAOC,OAAOT,EAAEC,MAAO,IAClBM,EACHL,UAAMQ,GACN,KAKR,MAAMC,QAAkBjB,IAAY,CAAEkB,UAAWC,KAC3CC,EAASC,EAAoBvB,GAC7BwB,EAAOC,SAASC,eAAe,QAE/BC,EAAmB,IACvBC,EAAAC,cAAC5B,EAAG,CAAC6B,OAAQX,GACXS,EAACC,cAAAE,GAAeT,OAAQA,KAI5B,OAAKD,EAIEW,EAASC,YAAYT,EAAMI,EAACC,cAAAF,EAAe,OAHzCK,EAASE,WAAWV,GAAMW,OAAOP,EAAAC,cAACF,EAAY,MAIzD"}
1
+ {"version":3,"file":"entry.js","sources":["../../src/browser/entry.tsx"],"sourcesContent":["import type { Router as RemixRouter } from '@remix-run/router/dist/router';\nimport type { FC, PropsWithChildren } from 'react';\nimport React from 'react';\nimport ReactDOM from 'react-dom/client';\nimport type { RouteObject } from 'react-router-dom';\nimport { createBrowserRouter, matchRoutes, RouterProvider } from 'react-router-dom';\nimport { IS_SSR_MODE } from '@constants/common';\nimport type { TRouteObject } from '@interfaces/route-object';\n\nexport interface IAppClientProps<T = undefined> {\n client: T;\n}\n\nexport interface IInitPropsParams {\n isSSRMode: boolean;\n router: RemixRouter;\n}\n\nexport type TApp<T> = FC<PropsWithChildren<IAppClientProps<T>>>;\n\nexport interface IEntryClientOptions<T> {\n init?: (params: IInitPropsParams) => Promise<T>;\n}\n\n/**\n * Render client side application\n */\nasync function entry<TAppProps>(\n App: TApp<TAppProps>,\n routes: TRouteObject[],\n { init }: IEntryClientOptions<TAppProps> = {},\n): Promise<ReactDOM.Root | void> {\n const lazyMatches = matchRoutes(routes as RouteObject[], window.location)?.filter(\n (m) => m.route.lazy,\n );\n\n // Load the lazy matches and update the routes before creating router,\n // so we can hydrate the SSR-rendered content synchronously\n if (lazyMatches && lazyMatches?.length > 0) {\n await Promise.all(\n lazyMatches.map(async (m) => {\n const routeModule = await m.route.lazy?.();\n\n Object.assign(m.route, {\n ...routeModule,\n lazy: undefined,\n });\n }),\n );\n }\n\n const router = createBrowserRouter(routes as RouteObject[]);\n const root = document.getElementById('root') as HTMLElement;\n const appProps = (await init?.({ isSSRMode: IS_SSR_MODE, router })) as TAppProps;\n\n const AppComponent: FC = () => (\n <App client={appProps}>\n <RouterProvider router={router} />\n </App>\n );\n\n if (!IS_SSR_MODE) {\n return ReactDOM.createRoot(root).render(<AppComponent />);\n }\n\n return ReactDOM.hydrateRoot(root, <AppComponent />);\n}\n\nexport default entry;\n"],"names":["async","entry","App","routes","init","lazyMatches","matchRoutes","window","location","filter","m","route","lazy","length","Promise","all","map","routeModule","Object","assign","undefined","router","createBrowserRouter","root","document","getElementById","appProps","isSSRMode","IS_SSR_MODE","AppComponent","React","createElement","client","RouterProvider","ReactDOM","hydrateRoot","createRoot","render"],"mappings":"sMA2BAA,eAAeC,EACbC,EACAC,GACAC,KAAEA,GAAyC,CAAA,GAE3C,MAAMC,EAAcC,EAAYH,EAAyBI,OAAOC,WAAWC,QACxEC,GAAMA,EAAEC,MAAMC,OAKbP,GAAeA,GAAaQ,OAAS,SACjCC,QAAQC,IACZV,EAAYW,KAAIhB,MAAOU,IACrB,MAAMO,QAAoBP,EAAEC,MAAMC,UAElCM,OAAOC,OAAOT,EAAEC,MAAO,IAClBM,EACHL,UAAMQ,GACN,KAKR,MAAMC,EAASC,EAAoBnB,GAC7BoB,EAAOC,SAASC,eAAe,QAC/BC,QAAkBtB,IAAO,CAAEuB,UAAWC,EAAaP,YAEnDQ,EAAmB,IACvBC,EAAAC,cAAC7B,EAAG,CAAC8B,OAAQN,GACXI,EAACC,cAAAE,GAAeZ,OAAQA,KAI5B,OAAKO,EAIEM,EAASC,YAAYZ,EAAMO,EAACC,cAAAF,EAAe,OAHzCK,EAASE,WAAWb,GAAMc,OAAOP,EAAAC,cAACF,EAAY,MAIzD"}
package/cli/build.d.ts CHANGED
@@ -1,11 +1,14 @@
1
1
  interface IBuildParams {
2
2
  isOnlyClient?: boolean;
3
3
  isWatch?: boolean;
4
+ isUnlockRobots?: boolean;
4
5
  clientOptions?: string;
5
6
  serverOptions?: string;
7
+ mode?: string;
8
+ onFinish?: () => void;
6
9
  }
7
10
  /**
8
11
  * Build production application
9
12
  */
10
- declare function build({ isOnlyClient, isWatch, clientOptions, serverOptions, }: IBuildParams): Promise<void | [unknown, unknown]>;
13
+ declare function build({ onFinish, isOnlyClient, isWatch, isUnlockRobots, clientOptions, serverOptions, mode, }: IBuildParams): Promise<void>;
11
14
  export { build as default };
package/cli/build.js CHANGED
@@ -1,2 +1,2 @@
1
- import e from"node:child_process";import{performance as o}from"node:perf_hooks";import i from"chalk";import{resolveConfig as r}from"vite";import t from"../constants/cli-name.js";import n from"../helpers/plugin-config.js";const s=e=>new Promise(((o,i)=>{e.on("exit",(e=>{o(e)})),e.on("close",(e=>{o(e)})),e.on("error",(e=>{i(e)}))}));async function l({isOnlyClient:l=!1,isWatch:a=!1,clientOptions:c="",serverOptions:p=""}){const m=o.now(),u=await r({},"build"),d=n(u),{outDir:f}=u.build,h=["client"],S=new AbortController,v=s(e.spawn(`vite build ${c} --emptyOutDir --outDir ${f}/client`,{signal:S.signal,stdio:"inherit",shell:!0,env:{...process.env,SSR_BOOST_IS_SSR:l?"0":"1"}}));let w;if(a||await v,l||(w=s(e.spawn(`vite build ${p} --emptyOutDir --outDir ${f}/server --ssr ${d.serverFile}`,{signal:S.signal,stdio:"inherit",shell:!0,env:{...process.env,SSR_BOOST_IS_SSR:l?"0":"1"}})),a||await w,h.push("server")),a){process.on("exit",(()=>{S.abort()}));const e=Promise.all([v,w]);return e.controller=S,e}const $=i.dim(`${i.yellowBright(h.join(","))} built in ${i.reset(i.bold(Math.ceil(o.now()-m)))} ms`);console.info(`\n ${i.green(`${i.bold(t.toUpperCase())}`)} ${$}\n`)}export{l as default};
1
+ import o from"node:child_process";import e from"node:fs";import t from"node:path";import{performance as s}from"node:perf_hooks";import r from"chalk";import{resolveConfig as i}from"vite";import n from"./vite-reset-cache.js";import l from"../constants/cli-name.js";import{createDevMarker as p}from"../helpers/dev-marker.js";import a from"../helpers/plugin-config.js";import c from"../helpers/unlock-robots.js";import d from"../services/ssr-manifest.js";const m=o=>{const e=new Promise(((e,t)=>{o.on("exit",(o=>{e(o)})),o.on("close",(o=>{e(o)})),o.on("error",(o=>{t(o)}))}));return o.stdout?.pipe(process.stdout),o.stderr?.pipe(process.stderr),e.command=o,e};async function u({onFinish:u,isOnlyClient:v=!1,isWatch:f=!1,isUnlockRobots:O=!1,clientOptions:S="",serverOptions:b="",mode:h=""}){const _=s.now(),$=await i({},"build",h,"production"===h?"production":"development"),g=a($),{outDir:w}=$.build,R=["client"],B=new AbortController,C=h?`--mode ${h}`:"",D=process.env.NODE_ENV||"development",j="production"===D,y=t.resolve($.root,w);await n(),e.existsSync(y)&&e.rmSync(y,{recursive:!0});const A=m(o.spawn(`vite build ${S} --emptyOutDir --outDir ${w}/client ${C}`,{signal:B.signal,stdio:[process.stdin,"pipe",process.stderr],shell:!0,env:{...process.env,FORCE_COLOR:"2",SSR_BOOST_IS_SSR:v?"0":"1",SSR_BOOST_ACTION:global.viteBoostAction}}));let E;if(f||await A,v||(E=m(o.spawn(`vite build ${b} --emptyOutDir --outDir ${w}/server --ssr ${g.serverFile} ${C}`,{signal:B.signal,stdio:[process.stdin,"pipe",process.stderr],shell:!0,env:{...process.env,FORCE_COLOR:"2",SSR_BOOST_IS_SSR:v?"0":"1",SSR_BOOST_ACTION:global.viteBoostAction}})),f||(await E,await d.get($.root,{alias:$.resolve.alias,buildDir:w}).buildRoutesManifest(g.preloadAssets)),R.push("server")),f){process.on("exit",(()=>{B.abort()}));let o=v?1:2;const e=t=>{Buffer.from(t).toString().includes("built in")&&(o-=1,o||(A.command.stdout.removeListener("data",e),E?.command.stdout.removeListener("data",e),p(j,$),u?.()))};return A.command.stdout.on("data",e),void E?.command.stdout.on("data",e)}O&&c($.root,w),p(j,$),u?.();const N=r.dim(`${r.yellowBright(R.join(","))} built in ${r.reset(r.bold(Math.ceil(s.now()-_)))} ms`);console.info(`\n ${r.green(`${r.bold(l.toUpperCase())}`)} ${N} ${j?"":r.redBright(`NODE_ENV=${D}`)}\n`)}export{u as default};
2
2
  //# sourceMappingURL=build.js.map
package/cli/build.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"build.js","sources":["../../src/cli/build.ts"],"sourcesContent":["import childProcess from 'node:child_process';\nimport { performance } from 'node:perf_hooks';\nimport chalk from 'chalk';\nimport { resolveConfig } from 'vite';\nimport cliName from '@constants/cli-name';\nimport getPluginConfig from '@helpers/plugin-config';\n\ninterface IBuildParams {\n isOnlyClient?: boolean;\n isWatch?: boolean;\n clientOptions?: string;\n serverOptions?: string;\n}\n\n/**\n * Promisify spawn process\n */\nconst promisify = (command: childProcess.ChildProcess) =>\n new Promise((resolve, reject) => {\n command.on('exit', (code) => {\n resolve(code);\n });\n\n command.on('close', (code) => {\n resolve(code);\n });\n\n command.on('error', (message) => {\n reject(message);\n });\n });\n\n/**\n * Build production application\n */\nasync function build({\n isOnlyClient = false,\n isWatch = false,\n clientOptions = '',\n serverOptions = '',\n}: IBuildParams): Promise<void | [unknown, unknown]> {\n const perfStart = performance.now();\n const config = await resolveConfig({}, 'build');\n const pluginConfig = getPluginConfig(config);\n const { outDir } = config.build;\n const types = ['client'];\n const controller = new AbortController();\n\n // build client\n const clientProcess = promisify(\n childProcess.spawn(`vite build ${clientOptions} --emptyOutDir --outDir ${outDir}/client`, {\n signal: controller.signal,\n stdio: 'inherit',\n shell: true,\n env: {\n ...process.env,\n SSR_BOOST_IS_SSR: isOnlyClient ? '0' : '1',\n },\n }),\n );\n\n if (!isWatch) {\n await clientProcess;\n }\n\n let serverProcess;\n\n if (!isOnlyClient) {\n // build server\n serverProcess = promisify(\n childProcess.spawn(\n `vite build ${serverOptions} --emptyOutDir --outDir ${outDir}/server --ssr ${pluginConfig.serverFile}`,\n {\n signal: controller.signal,\n stdio: 'inherit',\n shell: true,\n env: {\n ...process.env,\n SSR_BOOST_IS_SSR: isOnlyClient ? '0' : '1',\n },\n },\n ),\n );\n\n if (!isWatch) {\n await serverProcess;\n }\n\n types.push('server');\n }\n\n if (isWatch) {\n process.on('exit', () => {\n controller.abort();\n });\n\n const buildPromise = Promise.all([clientProcess, serverProcess]);\n\n buildPromise['controller'] = controller;\n\n return buildPromise;\n }\n\n const buildDurationString = chalk.dim(\n `${chalk.yellowBright(types.join(','))} built in ${chalk.reset(\n chalk.bold(Math.ceil(performance.now() - perfStart)),\n )} ms`,\n );\n\n console.info(\n `\\n ${chalk.green(`${chalk.bold(cliName.toUpperCase())}`)} ${buildDurationString}\\n`,\n );\n}\n\nexport default build;\n"],"names":["promisify","command","Promise","resolve","reject","on","code","message","async","build","isOnlyClient","isWatch","clientOptions","serverOptions","perfStart","performance","now","config","resolveConfig","pluginConfig","getPluginConfig","outDir","types","controller","AbortController","clientProcess","childProcess","spawn","signal","stdio","shell","env","process","SSR_BOOST_IS_SSR","serverProcess","serverFile","push","abort","buildPromise","all","buildDurationString","chalk","dim","yellowBright","join","reset","bold","Math","ceil","console","info","green","cliName","toUpperCase"],"mappings":"6NAiBA,MAAMA,EAAaC,GACjB,IAAIC,SAAQ,CAACC,EAASC,KACpBH,EAAQI,GAAG,QAASC,IAClBH,EAAQG,EAAK,IAGfL,EAAQI,GAAG,SAAUC,IACnBH,EAAQG,EAAK,IAGfL,EAAQI,GAAG,SAAUE,IACnBH,EAAOG,EAAQ,GACf,IAMNC,eAAeC,GAAMC,aACnBA,GAAe,EAAKC,QACpBA,GAAU,EAAKC,cACfA,EAAgB,GAAEC,cAClBA,EAAgB,KAEhB,MAAMC,EAAYC,EAAYC,MACxBC,QAAeC,EAAc,CAAE,EAAE,SACjCC,EAAeC,EAAgBH,IAC/BI,OAAEA,GAAWJ,EAAOR,MACpBa,EAAQ,CAAC,UACTC,EAAa,IAAIC,gBAGjBC,EAAgBzB,EACpB0B,EAAaC,MAAM,cAAcf,4BAAwCS,WAAiB,CACxFO,OAAQL,EAAWK,OACnBC,MAAO,UACPC,OAAO,EACPC,IAAK,IACAC,QAAQD,IACXE,iBAAkBvB,EAAe,IAAM,QAS7C,IAAIwB,EA0BJ,GA9BKvB,SACGc,EAKHf,IAEHwB,EAAgBlC,EACd0B,EAAaC,MACX,cAAcd,4BAAwCQ,kBAAuBF,EAAagB,aAC1F,CACEP,OAAQL,EAAWK,OACnBC,MAAO,UACPC,OAAO,EACPC,IAAK,IACAC,QAAQD,IACXE,iBAAkBvB,EAAe,IAAM,QAM1CC,SACGuB,EAGRZ,EAAMc,KAAK,WAGTzB,EAAS,CACXqB,QAAQ3B,GAAG,QAAQ,KACjBkB,EAAWc,OAAO,IAGpB,MAAMC,EAAepC,QAAQqC,IAAI,CAACd,EAAeS,IAIjD,OAFAI,EAAyB,WAAIf,EAEtBe,CACR,CAED,MAAME,EAAsBC,EAAMC,IAChC,GAAGD,EAAME,aAAarB,EAAMsB,KAAK,kBAAkBH,EAAMI,MACvDJ,EAAMK,KAAKC,KAAKC,KAAKjC,EAAYC,MAAQF,WAI7CmC,QAAQC,KACN,OAAOT,EAAMU,MAAM,GAAGV,EAAMK,KAAKM,EAAQC,sBAAsBb,MAEnE"}
1
+ {"version":3,"file":"build.js","sources":["../../src/cli/build.ts"],"sourcesContent":["import childProcess from 'node:child_process';\nimport fs from 'node:fs';\nimport path from 'node:path';\nimport { performance } from 'node:perf_hooks';\nimport chalk from 'chalk';\nimport { resolveConfig } from 'vite';\nimport viteResetCache from '@cli/vite-reset-cache';\nimport cliName from '@constants/cli-name';\nimport { createDevMarker } from '@helpers/dev-marker';\nimport getPluginConfig from '@helpers/plugin-config';\nimport unlockRobots from '@helpers/unlock-robots';\nimport SsrManifest from '@services/ssr-manifest';\n\ninterface IBuildParams {\n isOnlyClient?: boolean;\n isWatch?: boolean;\n isUnlockRobots?: boolean;\n clientOptions?: string;\n serverOptions?: string;\n mode?: string;\n onFinish?: () => void;\n}\n\n/**\n * Promisify spawn process\n */\nconst promisify = (command: childProcess.ChildProcess) => {\n const promise = new Promise((resolve, reject) => {\n command.on('exit', (code) => {\n resolve(code);\n });\n\n command.on('close', (code) => {\n resolve(code);\n });\n\n command.on('error', (message) => {\n reject(message);\n });\n });\n\n command.stdout?.pipe(process.stdout);\n command.stderr?.pipe(process.stderr);\n\n promise['command'] = command;\n\n return promise;\n};\n\n/**\n * Build production application\n */\nasync function build({\n onFinish,\n isOnlyClient = false,\n isWatch = false,\n isUnlockRobots = false,\n clientOptions = '',\n serverOptions = '',\n mode = '',\n}: IBuildParams): Promise<void> {\n const perfStart = performance.now();\n const config = await resolveConfig(\n {},\n 'build',\n mode,\n mode === 'production' ? 'production' : 'development',\n );\n const pluginConfig = getPluginConfig(config);\n const { outDir } = config.build;\n const types = ['client'];\n const controller = new AbortController();\n const modeOpt = mode ? `--mode ${mode}` : '';\n const nodeEnv = process.env.NODE_ENV || 'development';\n const isProd = nodeEnv === 'production';\n const buildDir = path.resolve(config.root, outDir);\n\n // this is required step - build with different env may cause problems\n await viteResetCache();\n\n // clear build folder\n if (fs.existsSync(buildDir)) {\n fs.rmSync(buildDir, { recursive: true });\n }\n\n /**\n * Build client\n */\n const clientProcess = promisify(\n childProcess.spawn(\n `vite build ${clientOptions} --emptyOutDir --outDir ${outDir}/client ${modeOpt}`,\n {\n signal: controller.signal,\n stdio: [process.stdin, 'pipe', process.stderr],\n shell: true,\n env: {\n ...process.env,\n FORCE_COLOR: '2',\n SSR_BOOST_IS_SSR: isOnlyClient ? '0' : '1',\n SSR_BOOST_ACTION: global.viteBoostAction,\n },\n },\n ),\n );\n\n if (!isWatch) {\n await clientProcess;\n }\n\n let serverProcess: Promise<unknown> | undefined;\n\n /**\n * Build server\n */\n if (!isOnlyClient) {\n serverProcess = promisify(\n childProcess.spawn(\n `vite build ${serverOptions} --emptyOutDir --outDir ${outDir}/server --ssr ${pluginConfig.serverFile} ${modeOpt}`,\n {\n signal: controller.signal,\n stdio: [process.stdin, 'pipe', process.stderr],\n shell: true,\n env: {\n ...process.env,\n FORCE_COLOR: '2',\n SSR_BOOST_IS_SSR: isOnlyClient ? '0' : '1',\n SSR_BOOST_ACTION: global.viteBoostAction,\n },\n },\n ),\n );\n\n if (!isWatch) {\n await serverProcess;\n await SsrManifest.get(config.root, {\n alias: config.resolve.alias,\n buildDir: outDir,\n }).buildRoutesManifest(pluginConfig.preloadAssets);\n }\n\n types.push('server');\n }\n\n /**\n * Preview mode\n */\n if (isWatch) {\n process.on('exit', () => {\n controller.abort();\n });\n\n let buildCount = isOnlyClient ? 1 : 2;\n const listener = (buff: Uint8Array): void => {\n const msg = Buffer.from(buff).toString();\n\n if (msg.includes('built in')) {\n buildCount -= 1;\n\n if (!buildCount) {\n clientProcess['command'].stdout.removeListener('data', listener);\n serverProcess?.['command'].stdout.removeListener('data', listener);\n createDevMarker(isProd, config);\n onFinish?.();\n }\n }\n };\n\n /**\n * Listen output for call onFinish\n */\n clientProcess['command'].stdout.on('data', listener);\n serverProcess?.['command'].stdout.on('data', listener);\n\n return;\n }\n\n if (isUnlockRobots) {\n unlockRobots(config.root, outDir);\n }\n\n createDevMarker(isProd, config);\n onFinish?.();\n\n const buildDurationString = chalk.dim(\n `${chalk.yellowBright(types.join(','))} built in ${chalk.reset(\n chalk.bold(Math.ceil(performance.now() - perfStart)),\n )} ms`,\n );\n\n console.info(\n `\\n ${chalk.green(`${chalk.bold(cliName.toUpperCase())}`)} ${buildDurationString} ${\n isProd ? '' : chalk.redBright(`NODE_ENV=${nodeEnv}`)\n }\\n`,\n );\n}\n\nexport default build;\n"],"names":["promisify","command","promise","Promise","resolve","reject","on","code","message","stdout","pipe","process","stderr","async","build","onFinish","isOnlyClient","isWatch","isUnlockRobots","clientOptions","serverOptions","mode","perfStart","performance","now","config","resolveConfig","pluginConfig","getPluginConfig","outDir","types","controller","AbortController","modeOpt","nodeEnv","env","NODE_ENV","isProd","buildDir","path","root","viteResetCache","fs","existsSync","rmSync","recursive","clientProcess","childProcess","spawn","signal","stdio","stdin","shell","FORCE_COLOR","SSR_BOOST_IS_SSR","SSR_BOOST_ACTION","global","viteBoostAction","serverProcess","serverFile","SsrManifest","get","alias","buildRoutesManifest","preloadAssets","push","abort","buildCount","listener","buff","Buffer","from","toString","includes","removeListener","createDevMarker","unlockRobots","buildDurationString","chalk","dim","yellowBright","join","reset","bold","Math","ceil","console","info","green","cliName","toUpperCase","redBright"],"mappings":"mcA0BA,MAAMA,EAAaC,IACjB,MAAMC,EAAU,IAAIC,SAAQ,CAACC,EAASC,KACpCJ,EAAQK,GAAG,QAASC,IAClBH,EAAQG,EAAK,IAGfN,EAAQK,GAAG,SAAUC,IACnBH,EAAQG,EAAK,IAGfN,EAAQK,GAAG,SAAUE,IACnBH,EAAOG,EAAQ,GACf,IAQJ,OALAP,EAAQQ,QAAQC,KAAKC,QAAQF,QAC7BR,EAAQW,QAAQF,KAAKC,QAAQC,QAE7BV,EAAiB,QAAID,EAEdC,CAAO,EAMhBW,eAAeC,GAAMC,SACnBA,EAAQC,aACRA,GAAe,EAAKC,QACpBA,GAAU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XN,QAAQL,GAAG,QAAQ,KACjByB,EAAWmC,OAAO,IAGpB,IAAIC,EAAanD,EAAe,EAAI,EACpC,MAAMoD,EAAYC,IACJC,OAAOC,KAAKF,GAAMG,WAEtBC,SAAS,cACfN,GAAc,EAETA,IACHrB,EAAuB,QAAErC,OAAOiE,eAAe,OAAQN,GACvDV,GAAyB,QAAEjD,OAAOiE,eAAe,OAAQN,GACzDO,EAAgBtC,EAAQZ,GACxBV,OAEH,EASH,OAHA+B,EAAuB,QAAErC,OAAOH,GAAG,OAAQ8D,QAC3CV,GAAyB,QAAEjD,OAAOH,GAAG,OAAQ8D,EAG9C,CAEGlD,GACF0D,EAAanD,EAAOe,KAAMX,GAG5B8C,EAAgBtC,EAAQZ,GACxBV,MAEA,MAAM8D,EAAsBC,EAAMC,IAChC,GAAGD,EAAME,aAAalD,EAAMmD,KAAK,kBAAkBH,EAAMI,MACvDJ,EAAMK,KAAKC,KAAKC,KAAK9D,EAAYC,MAAQF,WAI7CgE,QAAQC,KACN,OAAOT,EAAMU,MAAM,GAAGV,EAAMK,KAAKM,EAAQC,sBAAsBb,KAC7DxC,EAAS,GAAKyC,EAAMa,UAAU,YAAYzD,SAGhD"}
package/cli/run-dev.d.ts CHANGED
@@ -5,6 +5,7 @@ interface IRunDevParams {
5
5
  version: string;
6
6
  isHost?: boolean;
7
7
  isPrintInfo?: boolean;
8
+ mode?: string;
8
9
  }
9
10
  interface IRunDevOut {
10
11
  server: Server;
@@ -13,5 +14,5 @@ interface IRunDevOut {
13
14
  /**
14
15
  * Run development server
15
16
  */
16
- declare function runDev({ version, isHost, isPrintInfo }: IRunDevParams): Promise<IRunDevOut>;
17
+ declare function runDev({ version, isHost, isPrintInfo, mode }: IRunDevParams): Promise<IRunDevOut>;
17
18
  export { runDev as default };
package/cli/run-dev.js CHANGED
@@ -1,2 +1,2 @@
1
- import{performance as o}from"node:perf_hooks";import r from"../node/server.js";import i from"../services/server-config.js";async function s({version:s,isHost:e,isPrintInfo:n}){global.viteBoostStartTime=o.now();const t=i.init({isHost:e}),{run:f}=await r(t);return{server:f({version:s,isPrintInfo:n}),config:t}}export{s as default};
1
+ import{performance as o}from"node:perf_hooks";import r from"../node/server.js";import e from"../services/server-config.js";async function i({version:i,isHost:s,isPrintInfo:n,mode:t}){global.viteBoostStartTime=o.now();const f=e.init({isHost:s,mode:t}),{run:m}=await r(f);return{server:m({version:i,isPrintInfo:n}),config:f}}export{i as default};
2
2
  //# sourceMappingURL=run-dev.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"run-dev.js","sources":["../../src/cli/run-dev.ts"],"sourcesContent":["import type { Server } from 'node:net';\nimport { performance } from 'node:perf_hooks';\nimport createServer from '@node/server';\nimport ServerConfig from '@services/server-config';\n\ninterface IRunDevParams {\n version: string;\n isHost?: boolean;\n isPrintInfo?: boolean;\n}\n\ninterface IRunDevOut {\n server: Server;\n config: ServerConfig;\n}\n\n/**\n * Run development server\n */\nasync function runDev({ version, isHost, isPrintInfo }: IRunDevParams): Promise<IRunDevOut> {\n global.viteBoostStartTime = performance.now();\n\n const config = ServerConfig.init({ isHost });\n const { run } = await createServer(config);\n\n return {\n server: run({ version, isPrintInfo }),\n config,\n };\n}\n\nexport default runDev;\n"],"names":["async","runDev","version","isHost","isPrintInfo","global","viteBoostStartTime","performance","now","config","ServerConfig","init","run","createServer","server"],"mappings":"2HAmBAA,eAAeC,GAAOC,QAAEA,EAAOC,OAAEA,EAAMC,YAAEA,IACvCC,OAAOC,mBAAqBC,EAAYC,MAExC,MAAMC,EAASC,EAAaC,KAAK,CAAER,YAC7BS,IAAEA,SAAcC,EAAaJ,GAEnC,MAAO,CACLK,OAAQF,EAAI,CAAEV,UAASE,gBACvBK,SAEJ"}
1
+ {"version":3,"file":"run-dev.js","sources":["../../src/cli/run-dev.ts"],"sourcesContent":["import type { Server } from 'node:net';\nimport { performance } from 'node:perf_hooks';\nimport createServer from '@node/server';\nimport ServerConfig from '@services/server-config';\n\ninterface IRunDevParams {\n version: string;\n isHost?: boolean;\n isPrintInfo?: boolean;\n mode?: string;\n}\n\ninterface IRunDevOut {\n server: Server;\n config: ServerConfig;\n}\n\n/**\n * Run development server\n */\nasync function runDev({ version, isHost, isPrintInfo, mode }: IRunDevParams): Promise<IRunDevOut> {\n global.viteBoostStartTime = performance.now();\n\n const config = ServerConfig.init({ isHost, mode });\n const { run } = await createServer(config);\n\n return {\n server: run({ version, isPrintInfo }),\n config,\n };\n}\n\nexport default runDev;\n"],"names":["async","runDev","version","isHost","isPrintInfo","mode","global","viteBoostStartTime","performance","now","config","ServerConfig","init","run","createServer","server"],"mappings":"2HAoBAA,eAAeC,GAAOC,QAAEA,EAAOC,OAAEA,EAAMC,YAAEA,EAAWC,KAAEA,IACpDC,OAAOC,mBAAqBC,EAAYC,MAExC,MAAMC,EAASC,EAAaC,KAAK,CAAET,SAAQE,UACrCQ,IAAEA,SAAcC,EAAaJ,GAEnC,MAAO,CACLK,OAAQF,EAAI,CAAEX,UAASE,gBACvBM,SAEJ"}
@@ -0,0 +1,12 @@
1
+ interface IRunDockerBuildParams {
2
+ imageName: string;
3
+ dockerOptions?: string;
4
+ dockerFile?: string;
5
+ isOnlyClient?: boolean;
6
+ mode?: string;
7
+ }
8
+ /**
9
+ * Build docker image
10
+ */
11
+ declare function runDockerBuild({ imageName, dockerFile, isOnlyClient, dockerOptions, mode, }: IRunDockerBuildParams): Promise<void>;
12
+ export { runDockerBuild as default };
@@ -0,0 +1,2 @@
1
+ import o from"node:child_process";import e from"node:path";import{cwd as r}from"node:process";import{resolveConfig as i}from"vite";import t from"../helpers/plugin-config.js";async function n({imageName:n,dockerFile:d,isOnlyClient:l=!1,dockerOptions:p="",mode:s=""}){const c="production"===s?"production":"development",a=await i({},"build",s),m=t(a),{root:u,build:{outDir:f}}=a,$=r(),g=`.${e.resolve(u,f).replace($,"")}`,b=l?"spa":"ssr",h=d||`${m.pluginPath}/workflow/Dockerfile`;o.execSync(`docker build -f ${h} --build-arg BUILD_PATH=${g} --build-arg RUN_TYPE=${b} --build-arg ENV_MODE=${c}${p} -t ${n} ${$}`,{stdio:"inherit",env:{...process.env}})}export{n as default};
2
+ //# sourceMappingURL=run-docker-build.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"run-docker-build.js","sources":["../../src/cli/run-docker-build.ts"],"sourcesContent":["import childProcess from 'node:child_process';\nimport path from 'node:path';\nimport { cwd } from 'node:process';\nimport { resolveConfig } from 'vite';\nimport getPluginConfig from '@helpers/plugin-config';\n\ninterface IRunDockerBuildParams {\n imageName: string;\n dockerOptions?: string;\n dockerFile?: string;\n isOnlyClient?: boolean;\n mode?: string;\n}\n\n/**\n * Build docker image\n */\nasync function runDockerBuild({\n imageName,\n dockerFile,\n isOnlyClient = false,\n dockerOptions = '',\n mode = '',\n}: IRunDockerBuildParams): Promise<void> {\n const nodeEnv = mode === 'production' ? 'production' : 'development';\n const config = await resolveConfig({}, 'build', mode);\n const pluginConfig = getPluginConfig(config);\n const {\n root,\n build: { outDir },\n } = config;\n const projectRoot = cwd();\n const buildDir = `.${path.resolve(root, outDir).replace(projectRoot, '')}`; // relative path\n const runType = isOnlyClient ? 'spa' : 'ssr';\n const docFile = dockerFile || `${pluginConfig.pluginPath}/workflow/Dockerfile`;\n\n childProcess.execSync(\n `docker build -f ${docFile}` +\n ` --build-arg BUILD_PATH=${buildDir}` +\n ` --build-arg RUN_TYPE=${runType} --build-arg ENV_MODE=${nodeEnv}` +\n `${dockerOptions} -t ${imageName} ${projectRoot}`,\n {\n stdio: 'inherit',\n env: {\n ...process.env,\n },\n },\n );\n}\n\nexport default runDockerBuild;\n"],"names":["async","runDockerBuild","imageName","dockerFile","isOnlyClient","dockerOptions","mode","nodeEnv","config","resolveConfig","pluginConfig","getPluginConfig","root","build","outDir","projectRoot","cwd","buildDir","path","resolve","replace","runType","docFile","pluginPath","childProcess","execSync","stdio","env","process"],"mappings":"8KAiBAA,eAAeC,GAAeC,UAC5BA,EAASC,WACTA,EAAUC,aACVA,GAAe,EAAKC,cACpBA,EAAgB,GAAEC,KAClBA,EAAO,KAEP,MAAMC,EAAmB,eAATD,EAAwB,aAAe,cACjDE,QAAeC,EAAc,CAAE,EAAE,QAASH,GAC1CI,EAAeC,EAAgBH,IAC/BI,KACJA,EACAC,OAAOC,OAAEA,IACPN,EACEO,EAAcC,IACdC,EAAW,IAAIC,EAAKC,QAAQP,EAAME,GAAQM,QAAQL,EAAa,MAC/DM,EAAUjB,EAAe,MAAQ,MACjCkB,EAAUnB,GAAc,GAAGO,EAAaa,iCAE9CC,EAAaC,SACX,mBAAmBH,4BACUL,0BACFI,0BAAgCd,IACtDF,QAAoBH,KAAaa,IACtC,CACEW,MAAO,UACPC,IAAK,IACAC,QAAQD,MAInB"}
package/cli/run-prod.d.ts CHANGED
@@ -7,6 +7,7 @@ interface IRunProdParams {
7
7
  isHost?: boolean;
8
8
  isPrintInfo?: boolean;
9
9
  onlyClient?: boolean;
10
+ mode?: string;
10
11
  }
11
12
  interface IRunProdOut {
12
13
  server: Server;
package/cli/run-prod.js CHANGED
@@ -1,2 +1,2 @@
1
- import{performance as o}from"node:perf_hooks";import r from"../node/server.js";import i from"../services/server-config.js";async function n({version:n,isHost:s,isPrintInfo:t,port:e,onlyClient:f=!1}){global.viteBoostStartTime=o.now();const a=i.init({isHost:s,isProd:!0,isOnlyClient:f},{port:e}),{run:l}=await r(a);return{server:l({version:n,isPrintInfo:t}),config:a}}export{n as default};
1
+ import{performance as o}from"node:perf_hooks";import r from"../node/server.js";import i from"../services/server-config.js";async function t({version:t,isHost:s,isPrintInfo:e,port:n,onlyClient:f=!1}){global.viteBoostStartTime||(global.viteBoostStartTime=o.now());const a=i.init({isHost:s,isProd:!0,isOnlyClient:f},{port:n}),{run:l}=await r(a);return{server:l({version:t,isPrintInfo:e}),config:a}}export{t as default};
2
2
  //# sourceMappingURL=run-prod.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"run-prod.js","sources":["../../src/cli/run-prod.ts"],"sourcesContent":["import type { Server } from 'node:net';\nimport { performance } from 'node:perf_hooks';\nimport createServer from '@node/server';\nimport ServerConfig from '@services/server-config';\n\ninterface IRunProdParams {\n version: string;\n port?: number;\n isHost?: boolean;\n isPrintInfo?: boolean;\n onlyClient?: boolean; // SPA mode\n}\n\ninterface IRunProdOut {\n server: Server;\n config: ServerConfig;\n}\n\n/**\n * Run production server\n */\nasync function runProd({\n version,\n isHost,\n isPrintInfo,\n port,\n onlyClient = false,\n}: IRunProdParams): Promise<IRunProdOut> {\n global.viteBoostStartTime = performance.now();\n\n const config = ServerConfig.init({ isHost, isProd: true, isOnlyClient: onlyClient }, { port });\n const { run } = await createServer(config);\n\n return {\n server: run({ version, isPrintInfo }),\n config,\n };\n}\n\nexport default runProd;\n"],"names":["async","runProd","version","isHost","isPrintInfo","port","onlyClient","global","viteBoostStartTime","performance","now","config","ServerConfig","init","isProd","isOnlyClient","run","createServer","server"],"mappings":"2HAqBAA,eAAeC,GAAQC,QACrBA,EAAOC,OACPA,EAAMC,YACNA,EAAWC,KACXA,EAAIC,WACJA,GAAa,IAEbC,OAAOC,mBAAqBC,EAAYC,MAExC,MAAMC,EAASC,EAAaC,KAAK,CAAEV,SAAQW,QAAQ,EAAMC,aAAcT,GAAc,CAAED,UACjFW,IAAEA,SAAcC,EAAaN,GAEnC,MAAO,CACLO,OAAQF,EAAI,CAAEd,UAASE,gBACvBO,SAEJ"}
1
+ {"version":3,"file":"run-prod.js","sources":["../../src/cli/run-prod.ts"],"sourcesContent":["import type { Server } from 'node:net';\nimport { performance } from 'node:perf_hooks';\nimport createServer from '@node/server';\nimport ServerConfig from '@services/server-config';\n\ninterface IRunProdParams {\n version: string;\n port?: number;\n isHost?: boolean;\n isPrintInfo?: boolean;\n onlyClient?: boolean; // SPA mode\n mode?: string;\n}\n\ninterface IRunProdOut {\n server: Server;\n config: ServerConfig;\n}\n\n/**\n * Run production server\n */\nasync function runProd({\n version,\n isHost,\n isPrintInfo,\n port,\n onlyClient = false,\n}: IRunProdParams): Promise<IRunProdOut> {\n if (!global.viteBoostStartTime) {\n global.viteBoostStartTime = performance.now();\n }\n\n const config = ServerConfig.init({ isHost, isProd: true, isOnlyClient: onlyClient }, { port });\n const { run } = await createServer(config);\n\n return {\n server: run({ version, isPrintInfo }),\n config,\n };\n}\n\nexport default runProd;\n"],"names":["async","runProd","version","isHost","isPrintInfo","port","onlyClient","global","viteBoostStartTime","performance","now","config","ServerConfig","init","isProd","isOnlyClient","run","createServer","server"],"mappings":"2HAsBAA,eAAeC,GAAQC,QACrBA,EAAOC,OACPA,EAAMC,YACNA,EAAWC,KACXA,EAAIC,WACJA,GAAa,IAERC,OAAOC,qBACVD,OAAOC,mBAAqBC,EAAYC,OAG1C,MAAMC,EAASC,EAAaC,KAAK,CAAEV,SAAQW,QAAQ,EAAMC,aAAcT,GAAc,CAAED,UACjFW,IAAEA,SAAcC,EAAaN,GAEnC,MAAO,CACLO,OAAQF,EAAI,CAAEd,UAASE,gBACvBO,SAEJ"}
package/cli.js CHANGED
@@ -1,3 +1,3 @@
1
1
  #!/usr/bin/env node
2
- import{readFileSync as o}from"fs";import t from"chalk";import{Command as n,Option as e}from"commander";import i from"./cli/build.js";import s from"./cli/keyboard-input.js";import r from"./cli/run-dev.js";import c from"./cli/run-prod.js";import a from"./cli/vite-reset-cache.js";import p from"./constants/cli-actions.js";import d from"./constants/cli-context.js";import l from"./constants/cli-name.js";const{description:m,version:f}=JSON.parse(o(new URL("./package.json",import.meta.url),"utf8")),v=()=>{process.stdin.isTTY&&(process.stdin.setRawMode(!0),process.stdin.on("data",s).setEncoding("utf8").resume())},u=new n;u.name(l).description(m).version(f).hook("preAction",((o,t)=>{global.viteBoostAction=t.name()}));const O=new e("--host","Ability to access the local instance on other devices under the same network.").default(!1),w=new e("--only-client","Build/run only client side part.").default(!1),y=new e("--port [port]","Server port.").default(3e3);u.command(p.dev).description("Run development server.").addOption(O).addOption(new e("--reset-cache","Clear vite cache before run.").default(!1)).action((async({host:o,resetCache:t})=>{t&&await a();const n=async t=>{const{server:n,config:e}=await r({version:f,isHost:o,isPrintInfo:t});d.server=n,d.config=e};return d.reboot=n,v(),n()})),u.command(p.build).description("Create production build.").addOption(w).addOption(new e("--client-options [client-options]",'Pass vite build options for client. Example: --client-options="--ssrManifest"').env("VITE_BUILD_CLIENT_OPTIONS").default("")).addOption(new e("--server-options [server-options]","Pass vite build options for server.").env("VITE_BUILD_SERVER_OPTIONS").default("")).action((async({onlyClient:o,clientOptions:t,serverOptions:n})=>{await i({isOnlyClient:o,clientOptions:t,serverOptions:n})})),u.command(p.start).description("Run production server.").addOption(O).addOption(y).addOption(w).action((({host:o,port:t,onlyClient:n})=>{const e=async e=>{const{server:i,config:s}=await c({version:f,isHost:o,isPrintInfo:e,port:t,onlyClient:n});d.server=i,d.config=s};return d.reboot=e,v(),e()})),u.command(p.preview).description("Build and preview production.").addOption(w).addOption(O).addOption(y).action((async({host:o,port:n,onlyClient:e})=>{const s=async i=>{const{server:s,config:r}=await c({version:f,isHost:o,isPrintInfo:i,port:n,onlyClient:e});s.on("listening",(()=>{setTimeout((()=>{r.getLogger().info(t.yellow("\n Running preview mode... \n"))}),0)})),d.server=s,d.config=r};d.reboot=s,v();const r=i({isWatch:!0,isOnlyClient:e,clientOptions:"-w",serverOptions:"-w"});await Promise.all([s(),r])})),u.parse();
2
+ import{readFileSync as o}from"fs";import e from"chalk";import{Command as n,Option as t}from"commander";import i from"./cli/build.js";import r from"./cli/keyboard-input.js";import s from"./cli/run-dev.js";import d from"./cli/run-docker-build.js";import a from"./cli/run-prod.js";import c from"./cli/vite-reset-cache.js";import l from"./constants/cli-actions.js";import p from"./constants/cli-context.js";import m from"./constants/cli-name.js";const{description:f,version:u}=JSON.parse(o(new URL("./package.json",import.meta.url),"utf8")),v=()=>{process.stdin.isTTY&&(process.stdin.setRawMode(!0),process.stdin.on("data",r).setEncoding("utf8").resume())},O=new n;O.name(m).description(f).version(u).hook("preAction",((o,e)=>{global.viteBoostAction=e.name()}));const w=new t("--host","Ability to access the local instance on other devices under the same network.").default(!1),k=new t("--only-client","Build/run only client side part.").default(!1),g=new t("--port [port]","Server port.").default(3e3),b=new t("--mode [mode]","Env mode.").env("VITE_ENV_MODE").default("production");O.command(l.dev).description("Run development server.").addOption(w).addOption(new t("--reset-cache","Clear vite cache before run.").default(!1)).addOption(new t("--mode [mode]","Env mode.").env("VITE_ENV_MODE").default("development")).action((async({host:o,resetCache:e,mode:n})=>{e&&await c();const t=async e=>{const{server:t,config:i}=await s({version:u,isHost:o,isPrintInfo:e,mode:n});p.server=t,p.config=i};return p.reboot=t,v(),t()})),O.command(l.build).description("Create production build.").addOption(k).addOption(b).addOption(new t("--client-options [client-options]",'Pass vite build options for client. Example: --client-options="--ssrManifest"').env("VITE_BUILD_CLIENT_OPTIONS").default("")).addOption(new t("--server-options [server-options]","Pass vite build options for server.").env("VITE_BUILD_SERVER_OPTIONS").default("")).addOption(new t("--unlock-robots","Change general directive Disallow to Allow in robots.txt").default(!1)).action((async({onlyClient:o,clientOptions:e,serverOptions:n,mode:t,unlockRobots:r})=>{await i({isOnlyClient:o,isUnlockRobots:r,clientOptions:e,serverOptions:n,mode:t})})),O.command(l.start).description("Run production server.").addOption(w).addOption(g).addOption(k).action((({host:o,port:e,onlyClient:n})=>{const t=async t=>{const{server:i,config:r}=await a({version:u,isHost:o,isPrintInfo:t,port:e,onlyClient:n});p.server=i,p.config=r};return p.reboot=t,v(),t()})),O.command(l.preview).description("Build and preview production.").addOption(k).addOption(w).addOption(g).addOption(b).action((async({host:o,port:n,onlyClient:t,mode:r})=>{global.viteBoostStartTime=performance.now();const s=async i=>{const{server:r,config:s}=await a({version:u,isHost:o,isPrintInfo:i,port:n,onlyClient:t});r.on("listening",(()=>{setTimeout((()=>{s.getLogger().info(e.yellow("\n Running preview mode... \n"))}),0)})),p.server=r,p.config=s};p.reboot=s,v();await i({mode:r,isWatch:!0,isOnlyClient:t,clientOptions:"-w",serverOptions:"-w",onFinish:()=>{s()}})})),O.command(l.buildDocker).description("Create docker image with production build.").requiredOption("--image-name <image-name>","Docker image name.").addOption(new t("--docker-options [docker-options]","Extra docker options which pass to docker build command.")).addOption(new t("--docker-file [docker-file]","Name of the Dockerfile (Default is PLUGIN_PATH/workflow/Dockerfile).")).addOption(k).addOption(b).action((async({imageName:o,dockerOptions:e,dockerFile:n,onlyClient:t,mode:i})=>{await d({imageName:o,dockerOptions:e,dockerFile:n,isOnlyClient:t,mode:i})})),O.parse();
3
3
  //# sourceMappingURL=cli.js.map
package/cli.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"cli.js","sources":["../src/cli.ts"],"sourcesContent":["#!/usr/bin/env node\n\nimport { readFileSync } from 'fs';\nimport chalk from 'chalk';\nimport { Command, Option } from 'commander';\nimport runBuild from '@cli/build';\nimport onKeyPress from '@cli/keyboard-input';\nimport runDev from '@cli/run-dev';\nimport runProd from '@cli/run-prod';\nimport viteResetCache from '@cli/vite-reset-cache';\nimport CliActions from '@constants/cli-actions';\nimport cliContext from '@constants/cli-context';\nimport cliName from '@constants/cli-name';\n\n/**\n * Parse package meta\n */\nconst { description, version } = JSON.parse(\n readFileSync(new URL('./package.json', import.meta.url), 'utf8'),\n) as { name: string; description: string; version: string };\n\n/**\n * Enable shortcuts\n * listen keyboard command\n */\nconst enableShortcuts = (): void => {\n if (process.stdin.isTTY) {\n process.stdin.setRawMode(true);\n process.stdin.on('data', onKeyPress).setEncoding('utf8').resume();\n }\n};\n\nconst program = new Command();\n\nprogram\n .name(cliName)\n .description(description)\n .version(version)\n .hook('preAction', (_, actionCommand) => {\n // pass cli action to plugin config\n global.viteBoostAction = actionCommand.name();\n });\n\n/**\n * Common options\n */\nconst hostOption = new Option(\n '--host',\n 'Ability to access the local instance on other devices under the same network.',\n).default(false);\nconst onlyClientOption = new Option('--only-client', 'Build/run only client side part.').default(\n false,\n);\nconst portOption = new Option('--port [port]', 'Server port.').default(3000);\n\n/**\n * Cli commands\n */\n\nprogram\n .command(CliActions.dev)\n .description('Run development server.')\n .addOption(hostOption)\n .addOption(new Option('--reset-cache', 'Clear vite cache before run.').default(false))\n .action(async ({ host, resetCache }) => {\n if (resetCache) {\n await viteResetCache();\n }\n\n const command = async (isPrintInfo?: boolean): Promise<void> => {\n const { server, config } = await runDev({ version, isHost: host, isPrintInfo });\n\n cliContext.server = server;\n cliContext.config = config;\n };\n\n cliContext.reboot = command;\n\n enableShortcuts();\n\n return command();\n });\n\nprogram\n .command(CliActions.build)\n .description('Create production build.')\n .addOption(onlyClientOption)\n .addOption(\n new Option(\n '--client-options [client-options]',\n 'Pass vite build options for client. Example: --client-options=\"--ssrManifest\"',\n )\n .env('VITE_BUILD_CLIENT_OPTIONS')\n .default(''),\n )\n .addOption(\n new Option('--server-options [server-options]', 'Pass vite build options for server.')\n .env('VITE_BUILD_SERVER_OPTIONS')\n .default(''),\n )\n .action(async ({ onlyClient, clientOptions, serverOptions }) => {\n await runBuild({ isOnlyClient: onlyClient, clientOptions, serverOptions });\n });\n\nprogram\n .command(CliActions.start)\n .description('Run production server.')\n .addOption(hostOption)\n .addOption(portOption)\n .addOption(onlyClientOption)\n .action(({ host, port, onlyClient }) => {\n const command = async (isPrintInfo?: boolean): Promise<void> => {\n const { server, config } = await runProd({\n version,\n isHost: host,\n isPrintInfo,\n port,\n onlyClient,\n });\n\n cliContext.server = server;\n cliContext.config = config;\n };\n\n cliContext.reboot = command;\n\n enableShortcuts();\n\n return command();\n });\n\nprogram\n .command(CliActions.preview)\n .description('Build and preview production.')\n .addOption(onlyClientOption)\n .addOption(hostOption)\n .addOption(portOption)\n .action(async ({ host, port, onlyClient }) => {\n const command = async (isPrintInfo?: boolean): Promise<void> => {\n const { server, config } = await runProd({\n version,\n isHost: host,\n isPrintInfo,\n port,\n onlyClient,\n });\n\n server.on('listening', () => {\n setTimeout(() => {\n config.getLogger().info(chalk.yellow('\\n Running preview mode... \\n'));\n }, 0);\n });\n\n cliContext.server = server;\n cliContext.config = config;\n };\n\n cliContext.reboot = command;\n\n enableShortcuts();\n\n const buildOptions = '-w';\n const build = runBuild({\n isWatch: true,\n isOnlyClient: onlyClient,\n clientOptions: buildOptions,\n serverOptions: buildOptions,\n });\n\n await Promise.all([command(), build]);\n });\n\nprogram.parse();\n"],"names":["description","version","JSON","parse","readFileSync","URL","url","enableShortcuts","process","stdin","isTTY","setRawMode","on","onKeyPress","setEncoding","resume","program","Command","name","cliName","hook","_","actionCommand","global","viteBoostAction","hostOption","Option","default","onlyClientOption","portOption","command","CliActions","dev","addOption","action","async","host","resetCache","viteResetCache","isPrintInfo","server","config","runDev","isHost","cliContext","reboot","build","env","onlyClient","clientOptions","serverOptions","runBuild","isOnlyClient","start","port","runProd","preview","setTimeout","getLogger","info","chalk","yellow","isWatch","Promise","all"],"mappings":";iZAiBA,MAAMA,YAAEA,EAAWC,QAAEA,GAAYC,KAAKC,MACpCC,EAAa,IAAIC,IAAI,6BAA8BC,KAAM,SAOrDC,EAAkB,KAClBC,QAAQC,MAAMC,QAChBF,QAAQC,MAAME,YAAW,GACzBH,QAAQC,MAAMG,GAAG,OAAQC,GAAYC,YAAY,QAAQC,SAC1D,EAGGC,EAAU,IAAIC,EAEpBD,EACGE,KAAKC,GACLnB,YAAYA,GACZC,QAAQA,GACRmB,KAAK,aAAa,CAACC,EAAGC,KAErBC,OAAOC,gBAAkBF,EAAcJ,MAAM,IAMjD,MAAMO,EAAa,IAAIC,EACrB,SACA,iFACAC,SAAQ,GACJC,EAAmB,IAAIF,EAAO,gBAAiB,oCAAoCC,SACvF,GAEIE,EAAa,IAAIH,EAAO,gBAAiB,gBAAgBC,QAAQ,KAMvEX,EACGc,QAAQC,EAAWC,KACnBhC,YAAY,2BACZiC,UAAUR,GACVQ,UAAU,IAAIP,EAAO,gBAAiB,gCAAgCC,SAAQ,IAC9EO,QAAOC,OAASC,OAAMC,iBACjBA,SACIC,IAGR,MAAMR,EAAUK,MAAOI,IACrB,MAAMC,OAAEA,EAAMC,OAAEA,SAAiBC,EAAO,CAAEzC,UAAS0C,OAAQP,EAAM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C,cALmB,aAQfa,QAAQC,IAAI,CAAClC,IAAWgB,GAAO,IAGzC9B,EAAQb"}
1
+ {"version":3,"file":"cli.js","sources":["../src/cli.ts"],"sourcesContent":["#!/usr/bin/env node\n\nimport { readFileSync } from 'fs';\nimport chalk from 'chalk';\nimport { Command, Option } from 'commander';\nimport runBuild from '@cli/build';\nimport onKeyPress from '@cli/keyboard-input';\nimport runDev from '@cli/run-dev';\nimport runDockerBuild from '@cli/run-docker-build';\nimport runProd from '@cli/run-prod';\nimport viteResetCache from '@cli/vite-reset-cache';\nimport CliActions from '@constants/cli-actions';\nimport cliContext from '@constants/cli-context';\nimport cliName from '@constants/cli-name';\n\n/**\n * Parse package meta\n */\nconst { description, version } = JSON.parse(\n readFileSync(new URL('./package.json', import.meta.url), 'utf8'),\n) as { name: string; description: string; version: string };\n\n/**\n * Enable shortcuts\n * listen keyboard command\n */\nconst enableShortcuts = (): void => {\n if (process.stdin.isTTY) {\n process.stdin.setRawMode(true);\n process.stdin.on('data', onKeyPress).setEncoding('utf8').resume();\n }\n};\n\nconst program = new Command();\n\nprogram\n .name(cliName)\n .description(description)\n .version(version)\n .hook('preAction', (_, actionCommand) => {\n // pass cli action to plugin config\n global.viteBoostAction = actionCommand.name();\n });\n\n/**\n * Common options\n */\nconst hostOption = new Option(\n '--host',\n 'Ability to access the local instance on other devices under the same network.',\n).default(false);\nconst onlyClientOption = new Option('--only-client', 'Build/run only client side part.').default(\n false,\n);\nconst portOption = new Option('--port [port]', 'Server port.').default(3000);\nconst envModeOption = new Option('--mode [mode]', 'Env mode.')\n .env('VITE_ENV_MODE')\n .default('production');\n\n/**\n * Cli commands\n */\n\nprogram\n .command(CliActions.dev)\n .description('Run development server.')\n .addOption(hostOption)\n .addOption(new Option('--reset-cache', 'Clear vite cache before run.').default(false))\n .addOption(new Option('--mode [mode]', 'Env mode.').env('VITE_ENV_MODE').default('development'))\n .action(async ({ host, resetCache, mode }) => {\n if (resetCache) {\n await viteResetCache();\n }\n\n const command = async (isPrintInfo?: boolean): Promise<void> => {\n const { server, config } = await runDev({ version, isHost: host, isPrintInfo, mode });\n\n cliContext.server = server;\n cliContext.config = config;\n };\n\n cliContext.reboot = command;\n\n enableShortcuts();\n\n return command();\n });\n\nprogram\n .command(CliActions.build)\n .description('Create production build.')\n .addOption(onlyClientOption)\n .addOption(envModeOption)\n .addOption(\n new Option(\n '--client-options [client-options]',\n 'Pass vite build options for client. Example: --client-options=\"--ssrManifest\"',\n )\n .env('VITE_BUILD_CLIENT_OPTIONS')\n .default(''),\n )\n .addOption(\n new Option('--server-options [server-options]', 'Pass vite build options for server.')\n .env('VITE_BUILD_SERVER_OPTIONS')\n .default(''),\n )\n .addOption(\n new Option(\n '--unlock-robots',\n 'Change general directive Disallow to Allow in robots.txt',\n ).default(false),\n )\n .action(async ({ onlyClient, clientOptions, serverOptions, mode, unlockRobots }) => {\n await runBuild({\n isOnlyClient: onlyClient,\n isUnlockRobots: unlockRobots,\n clientOptions,\n serverOptions,\n mode,\n });\n });\n\nprogram\n .command(CliActions.start)\n .description('Run production server.')\n .addOption(hostOption)\n .addOption(portOption)\n .addOption(onlyClientOption)\n .action(({ host, port, onlyClient }) => {\n const command = async (isPrintInfo?: boolean): Promise<void> => {\n const { server, config } = await runProd({\n version,\n isHost: host,\n isPrintInfo,\n port,\n onlyClient,\n });\n\n cliContext.server = server;\n cliContext.config = config;\n };\n\n cliContext.reboot = command;\n\n enableShortcuts();\n\n return command();\n });\n\nprogram\n .command(CliActions.preview)\n .description('Build and preview production.')\n .addOption(onlyClientOption)\n .addOption(hostOption)\n .addOption(portOption)\n .addOption(envModeOption)\n .action(async ({ host, port, onlyClient, mode }) => {\n global.viteBoostStartTime = performance.now();\n\n const command = async (isPrintInfo?: boolean): Promise<void> => {\n const { server, config } = await runProd({\n version,\n isHost: host,\n isPrintInfo,\n port,\n onlyClient,\n });\n\n server.on('listening', () => {\n setTimeout(() => {\n config.getLogger().info(chalk.yellow('\\n Running preview mode... \\n'));\n }, 0);\n });\n\n cliContext.server = server;\n cliContext.config = config;\n };\n\n cliContext.reboot = command;\n\n enableShortcuts();\n\n const buildOptions = '-w';\n\n await runBuild({\n mode,\n isWatch: true,\n isOnlyClient: onlyClient,\n clientOptions: buildOptions,\n serverOptions: buildOptions,\n onFinish: () => {\n void command();\n },\n });\n });\n\nprogram\n .command(CliActions.buildDocker)\n .description('Create docker image with production build.')\n .requiredOption('--image-name <image-name>', 'Docker image name.')\n .addOption(\n new Option(\n '--docker-options [docker-options]',\n 'Extra docker options which pass to docker build command.',\n ),\n )\n .addOption(\n new Option(\n '--docker-file [docker-file]',\n 'Name of the Dockerfile (Default is PLUGIN_PATH/workflow/Dockerfile).',\n ),\n )\n .addOption(onlyClientOption)\n .addOption(envModeOption)\n .action(async ({ imageName, dockerOptions, dockerFile, onlyClient, mode }) => {\n await runDockerBuild({\n imageName,\n dockerOptions,\n dockerFile,\n isOnlyClient: onlyClient,\n mode,\n });\n });\n\nprogram.parse();\n"],"names":["description","version","JSON","parse","readFileSync","URL","url","enableShortcuts","process","stdin","isTTY","setRawMode","on","onKeyPress","setEncoding","resume","program","Command","name","cliName","hook","_","actionCommand","global","viteBoostAction","hostOption","Option","default","onlyClientOption","portOption","envModeOption","env","command","CliActions","dev","addOption","action","async","host","resetCache","mode","viteResetCache","isPrintInfo","server","config","runDev","isHost","cliContext","reboot","build","onlyClient","clientOptions","serverOptions","unlockRobots","runBuild","isOnlyClient","isUnlockRobots","start","port","runProd","preview","viteBoostStartTime","performance","now","setTimeout","getLogger","info","chalk","yellow","isWatch","onFinish","buildDocker","requiredOption","imageName","dockerOptions","dockerFile","runDockerBuild"],"mappings":";0bAkBA,MAAMA,YAAEA,EAAWC,QAAEA,GAAYC,KAAKC,MACpCC,EAAa,IAAIC,IAAI,6BAA8BC,KAAM,SAOrDC,EAAkB,KAClBC,QAAQC,MAAMC,QAChBF,QAAQC,MAAME,YAAW,GACzBH,QAAQC,MAAMG,GAAG,OAAQC,GAAYC,YAAY,QAAQ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2
+ import { FCAny, FCC } from "../interfaces/fc.js";
3
+ /**
4
+ * Wrap component in suspense
5
+ */
6
+ declare const withSuspense: <T extends Record<string, any>>(Component: FCAny<T>, Suspense: FCC<Record<string, any>>) => FC<T>;
7
+ export { withSuspense as default };
@@ -0,0 +1,2 @@
1
+ import t from"hoist-non-react-statics";import e from"react";const r=(r,o)=>{const n=t=>e.createElement(o,null,e.createElement(r,{...t}));return t(n,r),n};export{r as default};
2
+ //# sourceMappingURL=with-suspense.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"with-suspense.js","sources":["../../src/components/with-suspense.tsx"],"sourcesContent":["import hoistNonReactStatics from 'hoist-non-react-statics';\nimport type { FC } from 'react';\nimport React from 'react';\nimport type { FCAny, FCC } from '@interfaces/fc';\n\n/**\n * Wrap component in suspense\n */\nconst withSuspense = <T extends Record<string, any>>(\n Component: FCAny<T>,\n Suspense: FCC<Record<string, any>>,\n): FC<T> => {\n const Element: FC<T> = (props) => (\n <Suspense>\n <Component {...props} />\n </Suspense>\n );\n\n hoistNonReactStatics(Element, Component);\n\n return Element;\n};\n\nexport default withSuspense;\n"],"names":["withSuspense","Component","Suspense","Element","props","React","createElement","hoistNonReactStatics"],"mappings":"4DAQA,MAAMA,EAAe,CACnBC,EACAC,KAEA,MAAMC,EAAkBC,GACtBC,EAAAC,cAACJ,EAAQ,KACPG,EAAAC,cAACL,EAAc,IAAAG,KAMnB,OAFAG,EAAqBJ,EAASF,GAEvBE,CAAO"}
@@ -1,6 +1,7 @@
1
1
  declare enum CliActions {
2
2
  dev = "dev",
3
3
  build = "build",
4
+ buildDocker = "build-docker",
4
5
  start = "start",
5
6
  preview = "preview"
6
7
  }
@@ -1,2 +1,2 @@
1
- var e;!function(e){e.dev="dev",e.build="build",e.start="start",e.preview="preview"}(e||(e={}));var r=e;export{r as default};
1
+ var e;!function(e){e.dev="dev",e.build="build",e.buildDocker="build-docker",e.start="start",e.preview="preview"}(e||(e={}));var r=e;export{r as default};
2
2
  //# sourceMappingURL=cli-actions.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"cli-actions.js","sources":["../../src/constants/cli-actions.ts"],"sourcesContent":["enum CliActions {\n dev = 'dev',\n build = 'build',\n start = 'start',\n preview = 'preview',\n}\n\nexport default CliActions;\n"],"names":["CliActions","CliActions$1"],"mappings":"AAAA,IAAKA,GAAL,SAAKA,GACHA,EAAA,IAAA,MACAA,EAAA,MAAA,QACAA,EAAA,MAAA,QACAA,EAAA,QAAA,SACD,CALD,CAAKA,IAAAA,EAKJ,CAAA,IAED,IAAAC,EAAeD"}
1
+ {"version":3,"file":"cli-actions.js","sources":["../../src/constants/cli-actions.ts"],"sourcesContent":["enum CliActions {\n dev = 'dev',\n build = 'build',\n buildDocker = 'build-docker',\n start = 'start',\n preview = 'preview',\n}\n\nexport default CliActions;\n"],"names":["CliActions","CliActions$1"],"mappings":"AAAA,IAAKA,GAAL,SAAKA,GACHA,EAAA,IAAA,MACAA,EAAA,MAAA,QACAA,EAAA,YAAA,eACAA,EAAA,MAAA,QACAA,EAAA,QAAA,SACD,CAND,CAAKA,IAAAA,EAMJ,CAAA,IAED,IAAAC,EAAeD"}
@@ -0,0 +1,9 @@
1
+ import { ResolvedConfig } from 'vite';
2
+ declare const markerFileName = "server/.dev";
3
+ /**
4
+ * Create dev marker
5
+ *
6
+ * @see printServerInfo
7
+ */
8
+ declare const createDevMarker: (isProd: boolean, { root, build: buildConf }: ResolvedConfig) => void;
9
+ export { createDevMarker, markerFileName };
@@ -0,0 +1,2 @@
1
+ import r from"node:fs";import e from"node:path";const o="server/.dev",t=(t,{root:i,build:s})=>{const n=e.resolve(i,s.outDir),c=`${n}/${o}`;t?r.existsSync(c)&&r.rmSync(c):(r.existsSync(n)||r.mkdirSync(n,{recursive:!0}),r.writeFileSync(c,""))};export{t as createDevMarker,o as markerFileName};
2
+ //# sourceMappingURL=dev-marker.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dev-marker.js","sources":["../../src/helpers/dev-marker.ts"],"sourcesContent":["import fs from 'node:fs';\nimport path from 'node:path';\nimport type { ResolvedConfig } from 'vite';\n\nconst markerFileName = 'server/.dev';\n\n/**\n * Create dev marker\n *\n * @see printServerInfo\n */\nconst createDevMarker = (isProd: boolean, { root, build: buildConf }: ResolvedConfig): void => {\n const devMarkerPath = path.resolve(root, buildConf.outDir);\n const devMarker = `${devMarkerPath}/${markerFileName}`;\n\n if (!isProd) {\n if (!fs.existsSync(devMarkerPath)) {\n fs.mkdirSync(devMarkerPath, { recursive: true });\n }\n\n fs.writeFileSync(devMarker, '');\n } else if (fs.existsSync(devMarker)) {\n fs.rmSync(devMarker);\n }\n};\n\nexport { createDevMarker, markerFileName };\n"],"names":["markerFileName","createDevMarker","isProd","root","build","buildConf","devMarkerPath","path","resolve","outDir","devMarker","fs","existsSync","rmSync","mkdirSync","recursive","writeFileSync"],"mappings":"gDAIM,MAAAA,EAAiB,cAOjBC,EAAkB,CAACC,GAAmBC,OAAMC,MAAOC,MACvD,MAAMC,EAAgBC,EAAKC,QAAQL,EAAME,EAAUI,QAC7CC,EAAY,GAAGJ,KAAiBN,IAEjCE,EAMMS,EAAGC,WAAWF,IACvBC,EAAGE,OAAOH,IANLC,EAAGC,WAAWN,IACjBK,EAAGG,UAAUR,EAAe,CAAES,WAAW,IAG3CJ,EAAGK,cAAcN,EAAW,IAG7B"}
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Get server state on the client side
3
+ */
4
+ declare const getServerState: (name: string, shouldRemove?: boolean) => Record<string, any>;
5
+ export { getServerState as default };
@@ -0,0 +1,2 @@
1
+ const e=(e,t=!0)=>{const n=window[e];return t&&n&&delete window[e],n??{}};export{e as default};
2
+ //# sourceMappingURL=get-server-state.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-server-state.js","sources":["../../src/helpers/get-server-state.ts"],"sourcesContent":["/**\n * Get server state on the client side\n */\nconst getServerState = (name: string, shouldRemove = true): Record<string, any> => {\n const data = window[name] as Record<string, any>;\n\n if (shouldRemove && data) {\n delete window[name];\n }\n\n return data ?? {};\n};\n\nexport default getServerState;\n"],"names":["getServerState","name","shouldRemove","data","window"],"mappings":"AAGM,MAAAA,EAAiB,CAACC,EAAcC,GAAe,KACnD,MAAMC,EAAOC,OAAOH,GAMpB,OAJIC,GAAgBC,UACXC,OAAOH,GAGTE,GAAQ,CAAA,CAAE"}