@live-change/cli 0.9.138 → 0.9.139
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.
- package/lib/starter.js +165 -0
- package/package.json +8 -8
- package/LICENSE.md +0 -11
package/lib/starter.js
CHANGED
|
@@ -15,9 +15,11 @@ const app = App.app()
|
|
|
15
15
|
import {
|
|
16
16
|
|
|
17
17
|
SsrServer,
|
|
18
|
+
Renderer,
|
|
18
19
|
Services,
|
|
19
20
|
|
|
20
21
|
createLoopbackDao,
|
|
22
|
+
serverDao,
|
|
21
23
|
setupApiServer,
|
|
22
24
|
setupApiSockJs,
|
|
23
25
|
setupApiWs,
|
|
@@ -184,6 +186,14 @@ export function ssrServerOptions(yargs) {
|
|
|
184
186
|
})
|
|
185
187
|
}
|
|
186
188
|
|
|
189
|
+
export function prerenderOptions(yargs) {
|
|
190
|
+
yargs.option('staticHtml', {
|
|
191
|
+
describe: 'generate static html files',
|
|
192
|
+
type: 'boolean',
|
|
193
|
+
default: false
|
|
194
|
+
})
|
|
195
|
+
}
|
|
196
|
+
|
|
187
197
|
let globalServicesConfig
|
|
188
198
|
|
|
189
199
|
export default function starter(servicesConfig = null, args = {}, extraArgs = {}) {
|
|
@@ -243,6 +253,22 @@ export default function starter(servicesConfig = null, args = {}, extraArgs = {}
|
|
|
243
253
|
await setupApp({...argv, uidBorders: '[]'})
|
|
244
254
|
await server({...argv, uidBorders: '[]'}, false)
|
|
245
255
|
})
|
|
256
|
+
.command('prerender', 'prerender pages', (yargs) => {
|
|
257
|
+
prerenderOptions(yargs)
|
|
258
|
+
ssrServerOptions(yargs)
|
|
259
|
+
apiServerOptions(yargs)
|
|
260
|
+
startOptions(yargs)
|
|
261
|
+
}, async (argv) => {
|
|
262
|
+
argv = { ...extraArgs, ...argv }
|
|
263
|
+
await setupApp({...argv, uidBorders: '[]'})
|
|
264
|
+
try {
|
|
265
|
+
await prerender(argv)
|
|
266
|
+
process.exit(0)
|
|
267
|
+
} catch(e) {
|
|
268
|
+
console.error("PRERENDER ERROR", e)
|
|
269
|
+
process.exit(1)
|
|
270
|
+
}
|
|
271
|
+
})
|
|
246
272
|
.command('server', 'start server', (yargs) => {
|
|
247
273
|
ssrServerOptions(yargs)
|
|
248
274
|
apiServerOptions(yargs)
|
|
@@ -574,4 +600,143 @@ export async function server(argv, dev) {
|
|
|
574
600
|
httpServer.listen(ssrPort, ssrHost)
|
|
575
601
|
|
|
576
602
|
console.log("LISTENING ON ",`${ssrHost}:${ssrPort} link: http://${ssrHost}:${ssrPort}/`)
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
export async function prerender(argv) {
|
|
606
|
+
if(globalServicesConfig) argv.services = globalServicesConfig
|
|
607
|
+
argv.stopped = true
|
|
608
|
+
argv.dev = false
|
|
609
|
+
|
|
610
|
+
const manifest = JSON.parse(fs.readFileSync((path.resolve(argv.ssrRoot, 'dist/client/.vite/ssr-manifest.json'))))
|
|
611
|
+
|
|
612
|
+
const fastAuth = true
|
|
613
|
+
|
|
614
|
+
let apiServer
|
|
615
|
+
if(argv.withApi) {
|
|
616
|
+
apiServer = await setupApiServer({ ...argv, fastAuth })
|
|
617
|
+
}
|
|
618
|
+
|
|
619
|
+
async function daoFactory(credentials, ip) {
|
|
620
|
+
if(apiServer) {
|
|
621
|
+
return createLoopbackDao(credentials, () => apiServer.daoFactory(credentials, ip))
|
|
622
|
+
} else {
|
|
623
|
+
const host = (argv.apiHost === '0.0.0.0' || !argv.apiHost)
|
|
624
|
+
? 'localhost' : argv.apiHost
|
|
625
|
+
return await serverDao(credentials, ip, {
|
|
626
|
+
remoteUrl: `ws://${host}:${this.settings.apiPort || 8002}/api/ws`
|
|
627
|
+
})
|
|
628
|
+
}
|
|
629
|
+
}
|
|
630
|
+
|
|
631
|
+
|
|
632
|
+
const serverEntry = path.resolve(argv.ssrRoot, 'dist/server/entry-server.js')
|
|
633
|
+
const templatePath = path.resolve(argv.ssrRoot, 'dist/client/index.html')
|
|
634
|
+
const renderer = new Renderer(manifest, {
|
|
635
|
+
...argv,
|
|
636
|
+
serverEntry,
|
|
637
|
+
templatePath
|
|
638
|
+
})
|
|
639
|
+
await renderer.start()
|
|
640
|
+
|
|
641
|
+
if(argv.staticHtml) {
|
|
642
|
+
console.log("STATIC HTML RENDERER STARTED!")
|
|
643
|
+
} else {
|
|
644
|
+
console.log("RENDERER STARTED!")
|
|
645
|
+
}
|
|
646
|
+
|
|
647
|
+
const sitemapFunction = await renderer.withContext(async (context) => {
|
|
648
|
+
return await renderer.getSitemapRenderFunction(context)
|
|
649
|
+
})
|
|
650
|
+
|
|
651
|
+
const domain = argv.services?.clientConfig?.domain ?? process.env.BRAND_DOMAIN ?? 'localhost:8001'
|
|
652
|
+
const version = argv.version ?? 'unknown'
|
|
653
|
+
const now = Date.now()
|
|
654
|
+
|
|
655
|
+
const routes = []
|
|
656
|
+
|
|
657
|
+
console.log("COLLECTING ROUTES FROM SITEMAP!")
|
|
658
|
+
|
|
659
|
+
const dao = await daoFactory({ sessionKey: 'sitemap' }, '127.0.0.1')
|
|
660
|
+
|
|
661
|
+
await sitemapFunction({
|
|
662
|
+
dao,
|
|
663
|
+
clientIp: '127.0.0.1',
|
|
664
|
+
credentials: { sessionKey: 'sitemap' },
|
|
665
|
+
windowId: app.uidGenerator(),
|
|
666
|
+
headers: {
|
|
667
|
+
'Host': domain,
|
|
668
|
+
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36',
|
|
669
|
+
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7',
|
|
670
|
+
'Accept-Language': 'en-US,en;q=0.9',
|
|
671
|
+
'Accept-Encoding': 'gzip, deflate, br',
|
|
672
|
+
'Connection': 'keep-alive',
|
|
673
|
+
'Cache-Control': 'max-age=0',
|
|
674
|
+
},
|
|
675
|
+
url: `https://${domain}/sitemap.xml`,
|
|
676
|
+
version,
|
|
677
|
+
now,
|
|
678
|
+
domain,
|
|
679
|
+
}, (route) => routes.push(route))
|
|
680
|
+
|
|
681
|
+
console.log("ROUTES COLLECTED!", routes.length)
|
|
682
|
+
|
|
683
|
+
// await fs.promises.rm(path.resolve(argv.ssrRoot, 'dist/prerender'), { recursive: true })
|
|
684
|
+
await fs.promises.mkdir(path.resolve(argv.ssrRoot, 'dist/prerender'), { recursive: true })
|
|
685
|
+
|
|
686
|
+
const prerenderRoot = path.resolve(argv.ssrRoot, 'dist/prerender')
|
|
687
|
+
|
|
688
|
+
for(const route of routes) {
|
|
689
|
+
const url = new URL(route.url)
|
|
690
|
+
const relativeFilename = url.pathname.slice(1) + (url.pathname.endsWith('/') ? 'index' : '/index')
|
|
691
|
+
const baseFilename = path.resolve(prerenderRoot, relativeFilename)
|
|
692
|
+
const htmlFilename = baseFilename + '.html'
|
|
693
|
+
const jsonFilename = baseFilename + '.json'
|
|
694
|
+
|
|
695
|
+
console.log("RENDERING ROUTE", url.pathname, '->', relativeFilename)
|
|
696
|
+
|
|
697
|
+
const rendered = await renderer.renderPage({
|
|
698
|
+
url: url.pathname,
|
|
699
|
+
headers: {
|
|
700
|
+
'Host': domain,
|
|
701
|
+
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36',
|
|
702
|
+
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7',
|
|
703
|
+
'Accept-Language': 'en-US,en;q=0.9',
|
|
704
|
+
'Accept-Encoding': 'gzip, deflate, br',
|
|
705
|
+
'Connection': 'keep-alive',
|
|
706
|
+
'Cache-Control': 'max-age=0',
|
|
707
|
+
},
|
|
708
|
+
dao,
|
|
709
|
+
clientIp: '127.0.0.1',
|
|
710
|
+
credentials: { sessionKey: 'sitemap' },
|
|
711
|
+
windowId: app.uidGenerator(),
|
|
712
|
+
version,
|
|
713
|
+
now,
|
|
714
|
+
domain,
|
|
715
|
+
})
|
|
716
|
+
|
|
717
|
+
console.log("RENDERED:", Object.keys(rendered).join(', '))
|
|
718
|
+
const { html, ...metadata } = rendered
|
|
719
|
+
//console.log("HTML", html)
|
|
720
|
+
//console.log("METADATA", metadata)
|
|
721
|
+
|
|
722
|
+
await fs.promises.mkdir(path.dirname(htmlFilename), { recursive: true })
|
|
723
|
+
|
|
724
|
+
await fs.promises.writeFile(htmlFilename, html)
|
|
725
|
+
await fs.promises.writeFile(jsonFilename, JSON.stringify(metadata, null, 2))
|
|
726
|
+
|
|
727
|
+
console.log("RENDERED ROUTE", url.pathname, '->', relativeFilename)
|
|
728
|
+
}
|
|
729
|
+
|
|
730
|
+
if(argv.staticHtml) {
|
|
731
|
+
const clientAssetsDirectory = path.resolve(argv.ssrRoot, 'dist/client/assets')
|
|
732
|
+
const prerenderAssetsDirectory = path.resolve(prerenderRoot, 'assets')
|
|
733
|
+
console.log("COPYING CLIENT ASSETS FROM", clientAssetsDirectory, "TO", prerenderAssetsDirectory)
|
|
734
|
+
await fs.promises.cp(clientAssetsDirectory, prerenderAssetsDirectory, { recursive: true })
|
|
735
|
+
console.log("CLIENT ASSETS COPIED FROM", clientAssetsDirectory, "TO", prerenderAssetsDirectory)
|
|
736
|
+
|
|
737
|
+
const publicAssetsDirectory = path.resolve(argv.ssrRoot, 'public')
|
|
738
|
+
console.log("COPYING PUBLIC ASSETS FROM", publicAssetsDirectory, "TO", prerenderRoot)
|
|
739
|
+
await fs.promises.cp(publicAssetsDirectory, prerenderRoot, { recursive: true })
|
|
740
|
+
console.log("PUBLIC ASSETS COPIED FROM", publicAssetsDirectory, "TO", prerenderRoot)
|
|
741
|
+
}
|
|
577
742
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@live-change/cli",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.139",
|
|
4
4
|
"description": "Live Change Framework - command line interface",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -25,12 +25,12 @@
|
|
|
25
25
|
"type": "module",
|
|
26
26
|
"homepage": "https://github.com/live-change/live-change-stack",
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@live-change/dao": "^0.9.
|
|
29
|
-
"@live-change/dao-sockjs": "^0.9.
|
|
30
|
-
"@live-change/dao-websocket": "^0.9.
|
|
31
|
-
"@live-change/db-server": "^0.9.
|
|
32
|
-
"@live-change/framework": "^0.9.
|
|
33
|
-
"@live-change/server": "^0.9.
|
|
28
|
+
"@live-change/dao": "^0.9.139",
|
|
29
|
+
"@live-change/dao-sockjs": "^0.9.139",
|
|
30
|
+
"@live-change/dao-websocket": "^0.9.139",
|
|
31
|
+
"@live-change/db-server": "^0.9.139",
|
|
32
|
+
"@live-change/framework": "^0.9.139",
|
|
33
|
+
"@live-change/server": "^0.9.139",
|
|
34
34
|
"dotenv": "^17.2.1",
|
|
35
35
|
"express": "^4.18.2",
|
|
36
36
|
"http-proxy-middleware": "2.0.6",
|
|
@@ -40,5 +40,5 @@
|
|
|
40
40
|
"websocket": "^1.0.34",
|
|
41
41
|
"yargs": "^17.7.2"
|
|
42
42
|
},
|
|
43
|
-
"gitHead": "
|
|
43
|
+
"gitHead": "9202c36abc25e3baf5fe39806d89c3fab203f428"
|
|
44
44
|
}
|
package/LICENSE.md
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
Copyright 2019-2024 Michał Łaszczewski
|
|
2
|
-
|
|
3
|
-
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
|
4
|
-
|
|
5
|
-
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
|
6
|
-
|
|
7
|
-
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
|
8
|
-
|
|
9
|
-
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
|
10
|
-
|
|
11
|
-
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|