@rocket/js 0.0.0 → 0.1.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.
- package/LICENSE +21 -0
- package/README.md +233 -2
- package/dist-types/exports/MainMenu.d.ts +2 -0
- package/dist-types/exports/MainMenu.d.ts.map +1 -0
- package/dist-types/exports/PageData.d.ts +2 -0
- package/dist-types/exports/PageData.d.ts.map +1 -0
- package/dist-types/exports/RocketCodeBlock.d.ts +2 -0
- package/dist-types/exports/RocketCodeBlock.d.ts.map +1 -0
- package/dist-types/exports/RocketIcon.d.ts +2 -0
- package/dist-types/exports/RocketIcon.d.ts.map +1 -0
- package/dist-types/exports/RocketJsDemo.d.ts +2 -0
- package/dist-types/exports/RocketJsDemo.d.ts.map +1 -0
- package/dist-types/exports/RocketRequestDemo.d.ts +2 -0
- package/dist-types/exports/RocketRequestDemo.d.ts.map +1 -0
- package/dist-types/exports/SocialPreviewPlayground.d.ts +2 -0
- package/dist-types/exports/SocialPreviewPlayground.d.ts.map +1 -0
- package/dist-types/exports/adapters/netlify.d.ts +2 -0
- package/dist-types/exports/adapters/netlify.d.ts.map +1 -0
- package/dist-types/exports/asyncMessage.d.ts +2 -0
- package/dist-types/exports/asyncMessage.d.ts.map +1 -0
- package/dist-types/exports/component-hydration.d.ts +2 -0
- package/dist-types/exports/component-hydration.d.ts.map +1 -0
- package/dist-types/exports/components/web-awesome.d.ts +3 -0
- package/dist-types/exports/components/web-awesome.d.ts.map +1 -0
- package/dist-types/exports/components.d.ts +2 -0
- package/dist-types/exports/components.d.ts.map +1 -0
- package/dist-types/exports/config.d.ts +2 -0
- package/dist-types/exports/config.d.ts.map +1 -0
- package/dist-types/exports/debounce.d.ts +2 -0
- package/dist-types/exports/debounce.d.ts.map +1 -0
- package/dist-types/exports/define/RocketCodeBlock.d.ts +2 -0
- package/dist-types/exports/define/RocketCodeBlock.d.ts.map +1 -0
- package/dist-types/exports/define/RocketIcon.d.ts +2 -0
- package/dist-types/exports/define/RocketIcon.d.ts.map +1 -0
- package/dist-types/exports/define/RocketJsDemo.d.ts +2 -0
- package/dist-types/exports/define/RocketJsDemo.d.ts.map +1 -0
- package/dist-types/exports/define/RocketRequestDemo.d.ts +2 -0
- package/dist-types/exports/define/RocketRequestDemo.d.ts.map +1 -0
- package/dist-types/exports/define/menus.d.ts +2 -0
- package/dist-types/exports/define/menus.d.ts.map +1 -0
- package/dist-types/exports/extractCode.d.ts +2 -0
- package/dist-types/exports/extractCode.d.ts.map +1 -0
- package/dist-types/exports/globalData.d.ts +2 -0
- package/dist-types/exports/globalData.d.ts.map +1 -0
- package/dist-types/exports/hydration/hydrationLoader.d.ts +2 -0
- package/dist-types/exports/hydration/hydrationLoader.d.ts.map +1 -0
- package/dist-types/exports/icons.d.ts +2 -0
- package/dist-types/exports/icons.d.ts.map +1 -0
- package/dist-types/exports/layout-helper.d.ts +2 -0
- package/dist-types/exports/layout-helper.d.ts.map +1 -0
- package/dist-types/exports/layout.d.ts +2 -0
- package/dist-types/exports/layout.d.ts.map +1 -0
- package/dist-types/exports/layouts/atlasDoc.d.ts +2 -0
- package/dist-types/exports/layouts/atlasDoc.d.ts.map +1 -0
- package/dist-types/exports/layouts/atlasHero.d.ts +2 -0
- package/dist-types/exports/layouts/atlasHero.d.ts.map +1 -0
- package/dist-types/exports/layouts/atlasNotFound.d.ts +2 -0
- package/dist-types/exports/layouts/atlasNotFound.d.ts.map +1 -0
- package/dist-types/exports/loaded-page-module.d.ts +2 -0
- package/dist-types/exports/loaded-page-module.d.ts.map +1 -0
- package/dist-types/exports/markdownHook.d.ts +2 -0
- package/dist-types/exports/markdownHook.d.ts.map +1 -0
- package/dist-types/exports/menu.d.ts +2 -0
- package/dist-types/exports/menu.d.ts.map +1 -0
- package/dist-types/exports/menus.d.ts +6 -0
- package/dist-types/exports/menus.d.ts.map +1 -0
- package/dist-types/exports/page-runtime.d.ts +2 -0
- package/dist-types/exports/page-runtime.d.ts.map +1 -0
- package/dist-types/exports/pages.d.ts +2 -0
- package/dist-types/exports/pages.d.ts.map +1 -0
- package/dist-types/exports/resolve.d.ts +2 -0
- package/dist-types/exports/resolve.d.ts.map +1 -0
- package/dist-types/exports/ssr.d.ts +2 -0
- package/dist-types/exports/ssr.d.ts.map +1 -0
- package/dist-types/exports/standalone-demo-url.d.ts +2 -0
- package/dist-types/exports/standalone-demo-url.d.ts.map +1 -0
- package/dist-types/exports/transform.d.ts +2 -0
- package/dist-types/exports/transform.d.ts.map +1 -0
- package/dist-types/exports/types/hydration.d.ts +23 -0
- package/dist-types/exports/types/hydration.d.ts.map +1 -0
- package/dist-types/exports/types/rocket.d.ts +504 -0
- package/dist-types/exports/types/rocket.d.ts.map +1 -0
- package/dist-types/exports/types.d.ts +3 -0
- package/dist-types/exports/types.d.ts.map +1 -0
- package/dist-types/exports/wds-plugin.d.ts +2 -0
- package/dist-types/exports/wds-plugin.d.ts.map +1 -0
- package/dist-types/src/PageData.d.ts +82 -0
- package/dist-types/src/PageData.d.ts.map +1 -0
- package/dist-types/src/RocketCodeBlock.d.ts +64 -0
- package/dist-types/src/RocketCodeBlock.d.ts.map +1 -0
- package/dist-types/src/RocketIcon.d.ts +35 -0
- package/dist-types/src/RocketIcon.d.ts.map +1 -0
- package/dist-types/src/RocketJsDemo.d.ts +59 -0
- package/dist-types/src/RocketJsDemo.d.ts.map +1 -0
- package/dist-types/src/RocketJsDemo.test-browser.d.ts +3 -0
- package/dist-types/src/RocketJsDemo.test-browser.d.ts.map +1 -0
- package/dist-types/src/RocketRequestDemo.d.ts +57 -0
- package/dist-types/src/RocketRequestDemo.d.ts.map +1 -0
- package/dist-types/src/RocketRequestDemo.test-browser.d.ts +3 -0
- package/dist-types/src/RocketRequestDemo.test-browser.d.ts.map +1 -0
- package/dist-types/src/SocialPreviewPlayground.d.ts +102 -0
- package/dist-types/src/SocialPreviewPlayground.d.ts.map +1 -0
- package/dist-types/src/adapters/netlify.d.ts +54 -0
- package/dist-types/src/adapters/netlify.d.ts.map +1 -0
- package/dist-types/src/asyncMessage.d.ts +14 -0
- package/dist-types/src/asyncMessage.d.ts.map +1 -0
- package/dist-types/src/cli/RocketBuild.d.ts +78 -0
- package/dist-types/src/cli/RocketBuild.d.ts.map +1 -0
- package/dist-types/src/cli/RocketCli.d.ts +17 -0
- package/dist-types/src/cli/RocketCli.d.ts.map +1 -0
- package/dist-types/src/cli/RocketInit.d.ts +22 -0
- package/dist-types/src/cli/RocketInit.d.ts.map +1 -0
- package/dist-types/src/cli/RocketStart.d.ts +45 -0
- package/dist-types/src/cli/RocketStart.d.ts.map +1 -0
- package/dist-types/src/cli/cli.d.ts +3 -0
- package/dist-types/src/cli/cli.d.ts.map +1 -0
- package/dist-types/src/component-hydration.d.ts +26 -0
- package/dist-types/src/component-hydration.d.ts.map +1 -0
- package/dist-types/src/components/FeatureList.d.ts +15 -0
- package/dist-types/src/components/FeatureList.d.ts.map +1 -0
- package/dist-types/src/components/Footer.d.ts +17 -0
- package/dist-types/src/components/Footer.d.ts.map +1 -0
- package/dist-types/src/components/Header.d.ts +6 -0
- package/dist-types/src/components/Header.d.ts.map +1 -0
- package/dist-types/src/components/RocketDrawer.d.ts +20 -0
- package/dist-types/src/components/RocketDrawer.d.ts.map +1 -0
- package/dist-types/src/components/RocketSocialLink.d.ts +30 -0
- package/dist-types/src/components/RocketSocialLink.d.ts.map +1 -0
- package/dist-types/src/components.d.ts +7 -0
- package/dist-types/src/components.d.ts.map +1 -0
- package/dist-types/src/config.d.ts +6 -0
- package/dist-types/src/config.d.ts.map +1 -0
- package/dist-types/src/debounce.d.ts +8 -0
- package/dist-types/src/debounce.d.ts.map +1 -0
- package/dist-types/src/defaultSocialPreviewTemplate.d.ts +31 -0
- package/dist-types/src/defaultSocialPreviewTemplate.d.ts.map +1 -0
- package/dist-types/src/development-page-module-loader.d.ts +15 -0
- package/dist-types/src/development-page-module-loader.d.ts.map +1 -0
- package/dist-types/src/extractCode.d.ts +5 -0
- package/dist-types/src/extractCode.d.ts.map +1 -0
- package/dist-types/src/hydration/evaluate.d.ts +20 -0
- package/dist-types/src/hydration/evaluate.d.ts.map +1 -0
- package/dist-types/src/hydration/extractStrategies.d.ts +5 -0
- package/dist-types/src/hydration/extractStrategies.d.ts.map +1 -0
- package/dist-types/src/hydration/hydrationLoader.d.ts +64 -0
- package/dist-types/src/hydration/hydrationLoader.d.ts.map +1 -0
- package/dist-types/src/icons.d.ts +182 -0
- package/dist-types/src/icons.d.ts.map +1 -0
- package/dist-types/src/layouts/atlas/atlasDocLayout.d.ts +45 -0
- package/dist-types/src/layouts/atlas/atlasDocLayout.d.ts.map +1 -0
- package/dist-types/src/layouts/atlas/atlasHeroLayout.d.ts +7 -0
- package/dist-types/src/layouts/atlas/atlasHeroLayout.d.ts.map +1 -0
- package/dist-types/src/layouts/atlas/atlasNotFoundLayout.d.ts +5 -0
- package/dist-types/src/layouts/atlas/atlasNotFoundLayout.d.ts.map +1 -0
- package/dist-types/src/layouts/layout-helper.d.ts +16 -0
- package/dist-types/src/layouts/layout-helper.d.ts.map +1 -0
- package/dist-types/src/layouts/layout.d.ts +7 -0
- package/dist-types/src/layouts/layout.d.ts.map +1 -0
- package/dist-types/src/loaded-page-module.d.ts +51 -0
- package/dist-types/src/loaded-page-module.d.ts.map +1 -0
- package/dist-types/src/main.d.ts +2 -0
- package/dist-types/src/main.d.ts.map +1 -0
- package/dist-types/src/markdownCompiler.d.ts +22 -0
- package/dist-types/src/markdownCompiler.d.ts.map +1 -0
- package/dist-types/src/markdownHook.d.ts +6 -0
- package/dist-types/src/markdownHook.d.ts.map +1 -0
- package/dist-types/src/menu.d.ts +22 -0
- package/dist-types/src/menu.d.ts.map +1 -0
- package/dist-types/src/menus/MainMenu.d.ts +23 -0
- package/dist-types/src/menus/MainMenu.d.ts.map +1 -0
- package/dist-types/src/menus/RocketMenu.d.ts +23 -0
- package/dist-types/src/menus/RocketMenu.d.ts.map +1 -0
- package/dist-types/src/menus/RocketNextPage.d.ts +18 -0
- package/dist-types/src/menus/RocketNextPage.d.ts.map +1 -0
- package/dist-types/src/menus/RocketPreviousPage.d.ts +18 -0
- package/dist-types/src/menus/RocketPreviousPage.d.ts.map +1 -0
- package/dist-types/src/menus/RocketToc.d.ts +54 -0
- package/dist-types/src/menus/RocketToc.d.ts.map +1 -0
- package/dist-types/src/menus/pageNavigation.d.ts +41 -0
- package/dist-types/src/menus/pageNavigation.d.ts.map +1 -0
- package/dist-types/src/page-pagination.d.ts +69 -0
- package/dist-types/src/page-pagination.d.ts.map +1 -0
- package/dist-types/src/page-runtime.d.ts +110 -0
- package/dist-types/src/page-runtime.d.ts.map +1 -0
- package/dist-types/src/pages.d.ts +10 -0
- package/dist-types/src/pages.d.ts.map +1 -0
- package/dist-types/src/publicAssets.d.ts +70 -0
- package/dist-types/src/publicAssets.d.ts.map +1 -0
- package/dist-types/src/requestDemoMetadata.d.ts +19 -0
- package/dist-types/src/requestDemoMetadata.d.ts.map +1 -0
- package/dist-types/src/resolve.d.ts +7 -0
- package/dist-types/src/resolve.d.ts.map +1 -0
- package/dist-types/src/siteDiscoverability.d.ts +33 -0
- package/dist-types/src/siteDiscoverability.d.ts.map +1 -0
- package/dist-types/src/siteHeadMetadata.d.ts +20 -0
- package/dist-types/src/siteHeadMetadata.d.ts.map +1 -0
- package/dist-types/src/socialPreviewImages.d.ts +186 -0
- package/dist-types/src/socialPreviewImages.d.ts.map +1 -0
- package/dist-types/src/socialPreviewTemplatePreview.d.ts +22 -0
- package/dist-types/src/socialPreviewTemplatePreview.d.ts.map +1 -0
- package/dist-types/src/ssr.d.ts +6 -0
- package/dist-types/src/ssr.d.ts.map +1 -0
- package/dist-types/src/standalone-demo-url.d.ts +60 -0
- package/dist-types/src/standalone-demo-url.d.ts.map +1 -0
- package/dist-types/src/static-page-module-loader.d.ts +15 -0
- package/dist-types/src/static-page-module-loader.d.ts.map +1 -0
- package/dist-types/src/transform.d.ts +10 -0
- package/dist-types/src/transform.d.ts.map +1 -0
- package/dist-types/src/urlLifecycle.d.ts +23 -0
- package/dist-types/src/urlLifecycle.d.ts.map +1 -0
- package/dist-types/src/wds-plugin.d.ts +15 -0
- package/dist-types/src/wds-plugin.d.ts.map +1 -0
- package/docs/assets/home-background.svg +1 -0
- package/docs/assets/prism-one-light.css +368 -0
- package/docs/assets/rocket-logo-dark-with-text-below.svg +8 -0
- package/docs/assets/rocket-logo-dark-with-text.svg +7 -0
- package/docs/assets/rocket-logo-dark.svg +7 -0
- package/docs/assets/rocket-logo-light-with-text-below.svg +14 -0
- package/docs/assets/rocket-logo-light-with-text.svg +13 -0
- package/docs/assets/rocket-logo-light.svg +12 -0
- package/docs/assets/rocket-text-no-logo.svg +3 -0
- package/exports/MainMenu.js +1 -0
- package/exports/PageData.js +1 -0
- package/exports/RocketCodeBlock.js +1 -0
- package/exports/RocketIcon.js +1 -0
- package/exports/RocketJsDemo.js +1 -0
- package/exports/RocketRequestDemo.js +1 -0
- package/exports/SocialPreviewPlayground.js +1 -0
- package/exports/adapters/netlify.js +1 -0
- package/exports/asyncMessage.js +1 -0
- package/exports/component-hydration.js +1 -0
- package/exports/components/web-awesome.js +63 -0
- package/exports/components.js +1 -0
- package/exports/config.js +1 -0
- package/exports/debounce.js +1 -0
- package/exports/define/RocketCodeBlock.js +2 -0
- package/exports/define/RocketIcon.js +3 -0
- package/exports/define/RocketJsDemo.js +5 -0
- package/exports/define/RocketRequestDemo.js +5 -0
- package/exports/define/menus.js +14 -0
- package/exports/extractCode.js +1 -0
- package/exports/globalData.js +1 -0
- package/exports/hydration/hydrationLoader.js +1 -0
- package/exports/icons.js +11 -0
- package/exports/layout-helper.js +1 -0
- package/exports/layout.js +1 -0
- package/exports/layouts/_atlas.css +3 -0
- package/exports/layouts/atlasDoc.js +5 -0
- package/exports/layouts/atlasHero.js +1 -0
- package/exports/layouts/atlasNotFound.js +4 -0
- package/exports/loaded-page-module.js +5 -0
- package/exports/markdownHook.js +4 -0
- package/exports/menu.js +4 -0
- package/exports/menus.js +5 -0
- package/exports/page-runtime.js +5 -0
- package/exports/pages.js +1 -0
- package/exports/resolve.js +1 -0
- package/exports/ssr.js +1 -0
- package/exports/standalone-demo-url.js +10 -0
- package/exports/transform.js +1 -0
- package/exports/types/hydration.ts +26 -0
- package/exports/types/rocket.ts +598 -0
- package/exports/types.ts +71 -0
- package/exports/wds-plugin.js +1 -0
- package/package.json +192 -9
- package/src/PageData.js +244 -0
- package/src/RocketCodeBlock.js +516 -0
- package/src/RocketIcon.js +291 -0
- package/src/RocketJsDemo.js +397 -0
- package/src/RocketJsDemo.test-browser.js +228 -0
- package/src/RocketRequestDemo.js +439 -0
- package/src/RocketRequestDemo.test-browser.js +301 -0
- package/src/SocialPreviewPlayground.js +573 -0
- package/src/adapters/netlify.js +814 -0
- package/src/asyncMessage.js +21 -0
- package/src/cli/RocketBuild.js +581 -0
- package/src/cli/RocketCli.js +47 -0
- package/src/cli/RocketInit.js +636 -0
- package/src/cli/RocketStart.js +145 -0
- package/src/cli/cli.js +7 -0
- package/src/component-hydration.js +86 -0
- package/src/components/FeatureList.js +114 -0
- package/src/components/Footer.js +116 -0
- package/src/components/Header.js +122 -0
- package/src/components/RocketDrawer.js +193 -0
- package/src/components/RocketSocialLink.js +128 -0
- package/src/components/assets/discord.svg +7 -0
- package/src/components/assets/github.svg +4 -0
- package/src/components/assets/gitlab.svg +1 -0
- package/src/components/assets/info.txt +1 -0
- package/src/components/assets/license.svg +3 -0
- package/src/components/assets/npm.svg +5 -0
- package/src/components/assets/slack.svg +5 -0
- package/src/components/assets/telegram.svg +4 -0
- package/src/components/assets/twitter.svg +1 -0
- package/src/components.js +34 -0
- package/src/config.js +319 -0
- package/src/debounce.js +21 -0
- package/src/defaultSocialPreviewTemplate.js +118 -0
- package/src/development-page-module-loader.js +29 -0
- package/src/extractCode.js +41 -0
- package/src/hydration/evaluate.js +54 -0
- package/src/hydration/extractStrategies.js +91 -0
- package/src/hydration/hydrationLoader.js +330 -0
- package/src/icons.js +898 -0
- package/src/layouts/atlas/atlasDoc.css +877 -0
- package/src/layouts/atlas/atlasDocLayout.js +275 -0
- package/src/layouts/atlas/atlasHero.css +774 -0
- package/src/layouts/atlas/atlasHeroLayout.js +337 -0
- package/src/layouts/atlas/atlasNotFound.css +365 -0
- package/src/layouts/atlas/atlasNotFoundLayout.js +69 -0
- package/src/layouts/layout-helper.js +92 -0
- package/src/layouts/layout.js +52 -0
- package/src/loaded-page-module.js +97 -0
- package/src/main.js +72 -0
- package/src/markdownCompiler.js +303 -0
- package/src/markdownHook.js +148 -0
- package/src/menu.js +210 -0
- package/src/menus/MainMenu.js +58 -0
- package/src/menus/RocketMenu.js +191 -0
- package/src/menus/RocketNextPage.js +25 -0
- package/src/menus/RocketPreviousPage.js +29 -0
- package/src/menus/RocketToc.js +309 -0
- package/src/menus/pageNavigation.js +285 -0
- package/src/page-pagination.js +241 -0
- package/src/page-runtime.js +481 -0
- package/src/pages.js +537 -0
- package/src/publicAssets.js +336 -0
- package/src/requestDemoMetadata.js +97 -0
- package/src/resolve.js +15 -0
- package/src/siteDiscoverability.js +184 -0
- package/src/siteHeadMetadata.js +69 -0
- package/src/socialPreviewImages.js +482 -0
- package/src/socialPreviewTemplatePreview.js +352 -0
- package/src/ssr.js +14 -0
- package/src/standalone-demo-url.js +147 -0
- package/src/static-page-module-loader.js +29 -0
- package/src/transform.js +720 -0
- package/src/urlLifecycle.js +57 -0
- package/src/wds-plugin.js +307 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/** @typedef {import('node:worker_threads').MessagePort} MessagePort */
|
|
2
|
+
/** @typedef {MessagePort & {sendAndWait: (message: any) => any; _wait: PromiseWithResolvers<any>}} AsyncPort */
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Turns a MessagePort into an AsyncPort, which can wait for responses.
|
|
6
|
+
* @param {MessagePort} port
|
|
7
|
+
* @returns {AsyncPort}
|
|
8
|
+
*/
|
|
9
|
+
export function makeAsyncPort(port) {
|
|
10
|
+
const p = /** @type {AsyncPort} */ (port);
|
|
11
|
+
p._wait = Promise.withResolvers();
|
|
12
|
+
p.on('message', message => {
|
|
13
|
+
p._wait.resolve(message);
|
|
14
|
+
p._wait = Promise.withResolvers();
|
|
15
|
+
});
|
|
16
|
+
p.sendAndWait = async message => {
|
|
17
|
+
p.postMessage(message);
|
|
18
|
+
return p._wait;
|
|
19
|
+
};
|
|
20
|
+
return p;
|
|
21
|
+
}
|
|
@@ -0,0 +1,581 @@
|
|
|
1
|
+
import { getPages } from '../pages.js';
|
|
2
|
+
import { copyFileSync, existsSync, globSync, mkdirSync, rmSync, statSync, writeFileSync } from 'fs';
|
|
3
|
+
import { register } from 'node:module';
|
|
4
|
+
import { MessageChannel } from 'node:worker_threads';
|
|
5
|
+
import { build } from 'vite';
|
|
6
|
+
import path from 'node:path';
|
|
7
|
+
import { PageRuntime } from '../page-runtime.js';
|
|
8
|
+
import { createIconAssetStore, rocketIconRuntimeOutputs } from '../icons.js';
|
|
9
|
+
import { paginatedArchivePaths } from '../page-pagination.js';
|
|
10
|
+
import { createStaticPageModuleLoader } from '../static-page-module-loader.js';
|
|
11
|
+
import { writeSiteDiscoverabilityOutputs } from '../siteDiscoverability.js';
|
|
12
|
+
import { normalizeDocumentPath, standaloneDemoPaths } from '../standalone-demo-url.js';
|
|
13
|
+
import {
|
|
14
|
+
assertPublicAssetsOutputDir,
|
|
15
|
+
copyPublicAssets,
|
|
16
|
+
discoverPublicAssets,
|
|
17
|
+
validatePublicAssetCollisions,
|
|
18
|
+
} from '../publicAssets.js';
|
|
19
|
+
import {
|
|
20
|
+
validateUrlLifecycleGeneratedOutputCollisions,
|
|
21
|
+
validateUrlLifecyclePageCollisions,
|
|
22
|
+
} from '../urlLifecycle.js';
|
|
23
|
+
import {
|
|
24
|
+
captureSocialPreviewImageWithBrowser,
|
|
25
|
+
generateStaticDefaultSocialPreviewImages,
|
|
26
|
+
publicSocialPreviewPages,
|
|
27
|
+
} from '../socialPreviewImages.js';
|
|
28
|
+
|
|
29
|
+
export class RocketBuild {
|
|
30
|
+
/**
|
|
31
|
+
* @type {((options: {
|
|
32
|
+
* html: string;
|
|
33
|
+
* width: number;
|
|
34
|
+
* height: number;
|
|
35
|
+
* pathname: string;
|
|
36
|
+
* }) => Promise<Uint8Array> | Uint8Array) | undefined}
|
|
37
|
+
*/
|
|
38
|
+
socialPreviewCapture;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* @param {import('commander').Command} program
|
|
42
|
+
* @param {import('./RocketCli.js').RocketCli} cli
|
|
43
|
+
*/
|
|
44
|
+
async setupCommand(program, cli) {
|
|
45
|
+
this.cli = cli;
|
|
46
|
+
|
|
47
|
+
program
|
|
48
|
+
.command('build')
|
|
49
|
+
.option('-o, --output-dir <path>', 'Path where to output built files')
|
|
50
|
+
.action(async ({ outputDir }) => {
|
|
51
|
+
if (outputDir) {
|
|
52
|
+
this.outputDir = outputDir;
|
|
53
|
+
}
|
|
54
|
+
await this.build();
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
async build() {
|
|
59
|
+
await this.cli?.getConfig?.();
|
|
60
|
+
if (!this.cli?.config) {
|
|
61
|
+
throw new Error('Missing Config');
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const { port1 } = new MessageChannel();
|
|
65
|
+
|
|
66
|
+
// register must be AFTER the config is read
|
|
67
|
+
register('../markdownHook.js', {
|
|
68
|
+
parentURL: import.meta.url,
|
|
69
|
+
data: { port: port1 },
|
|
70
|
+
transferList: [port1],
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
process.env.ENVIRONMENT = 'BUILD';
|
|
74
|
+
|
|
75
|
+
const pages = await getPages(
|
|
76
|
+
process.cwd(),
|
|
77
|
+
this.cli.config.includeGlobs,
|
|
78
|
+
this.cli.config.excludeRegex,
|
|
79
|
+
);
|
|
80
|
+
validateUrlLifecyclePageCollisions({
|
|
81
|
+
redirects: this.cli.config.urlLifecycle?.redirects,
|
|
82
|
+
pages,
|
|
83
|
+
});
|
|
84
|
+
const { staticPages, serverPages } = splitPages(pages);
|
|
85
|
+
if (serverPages.size && !this.cli.config.adapter) {
|
|
86
|
+
throw new Error(
|
|
87
|
+
`${serverPages.size} page(s) use config.render = 'server', but no adapter is configured`,
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
const publicAssets = discoverPublicAssets(process.cwd());
|
|
91
|
+
validatePublicAssetCollisions({
|
|
92
|
+
publicAssets,
|
|
93
|
+
pages,
|
|
94
|
+
generatedPages: staticPages,
|
|
95
|
+
config: this.cli.config,
|
|
96
|
+
emitRedirectFallbacks: !this.cli.config.adapter,
|
|
97
|
+
});
|
|
98
|
+
const outDir = this.outputDir ? path.resolve(this.outputDir) : path.resolve('dist');
|
|
99
|
+
assertPublicAssetsOutputDir({ projectRoot: process.cwd(), outDir });
|
|
100
|
+
|
|
101
|
+
try {
|
|
102
|
+
if (existsSync('tmp-dist-rocket')) {
|
|
103
|
+
rmSync('tmp-dist-rocket', { recursive: true });
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
const { defaultSocialPreviewImages } = await renderStaticPages({
|
|
107
|
+
pages,
|
|
108
|
+
staticPages,
|
|
109
|
+
urlLifecycle: this.cli.config.urlLifecycle,
|
|
110
|
+
siteHeadMetadata: this.cli.config.siteHeadMetadata,
|
|
111
|
+
siteOrigin: this.cli.config.siteOrigin,
|
|
112
|
+
iconLibraries: this.cli.config.iconLibraries,
|
|
113
|
+
defaultIconLibrary: this.cli.config.defaultIconLibrary,
|
|
114
|
+
socialPreviewCacheDirectory: path.resolve('.rocket/social-preview-images'),
|
|
115
|
+
captureSocialPreviewImage: this.socialPreviewCapture,
|
|
116
|
+
emitRedirectFallbacks: !this.cli.config.adapter,
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
const entries = existsSync('tmp-dist-rocket')
|
|
120
|
+
? globSync('**/*.html', { cwd: 'tmp-dist-rocket' }).map(p =>
|
|
121
|
+
path.resolve('tmp-dist-rocket', p),
|
|
122
|
+
)
|
|
123
|
+
: [];
|
|
124
|
+
|
|
125
|
+
if (entries.length) {
|
|
126
|
+
await build({
|
|
127
|
+
configFile: false,
|
|
128
|
+
root: 'tmp-dist-rocket',
|
|
129
|
+
build: {
|
|
130
|
+
outDir,
|
|
131
|
+
target: 'esnext',
|
|
132
|
+
emptyOutDir: true,
|
|
133
|
+
manifest: true,
|
|
134
|
+
rollupOptions: {
|
|
135
|
+
external: [/^\/assets\//, /^\/_rocket\//, '/src/components/RocketDrawer.js'],
|
|
136
|
+
input: entries,
|
|
137
|
+
},
|
|
138
|
+
},
|
|
139
|
+
});
|
|
140
|
+
} else {
|
|
141
|
+
clearExistingOutputDir(outDir);
|
|
142
|
+
mkdirSync(outDir, { recursive: true });
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
copyStaticFileOutputs(outDir);
|
|
146
|
+
writeSiteDiscoverabilityOutputs({ pages, outDir, config: this.cli.config });
|
|
147
|
+
|
|
148
|
+
if (this.cli.config.adapter) {
|
|
149
|
+
await this.cli.config.adapter.build({
|
|
150
|
+
pages,
|
|
151
|
+
staticPages,
|
|
152
|
+
serverPages,
|
|
153
|
+
outDir,
|
|
154
|
+
projectRoot: process.cwd(),
|
|
155
|
+
config: this.cli.config,
|
|
156
|
+
defaultSocialPreviewImages,
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
copyPublicAssets({ publicAssets, outDir });
|
|
161
|
+
} finally {
|
|
162
|
+
if (existsSync('tmp-dist-rocket')) {
|
|
163
|
+
rmSync('tmp-dist-rocket', { recursive: true });
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* @param {import('@rocket/js/types.js').PageRegistry} pages
|
|
171
|
+
* @returns {{ staticPages: import('@rocket/js/types.js').PageRegistry; serverPages: import('@rocket/js/types.js').PageRegistry }}
|
|
172
|
+
*/
|
|
173
|
+
export function splitPages(pages) {
|
|
174
|
+
/** @type {import('@rocket/js/types.js').PageRegistry} */
|
|
175
|
+
const staticPages = new Map();
|
|
176
|
+
/** @type {import('@rocket/js/types.js').PageRegistry} */
|
|
177
|
+
const serverPages = new Map();
|
|
178
|
+
for (const [pagePath, page] of pages) {
|
|
179
|
+
const renderMode = page.module.config.render || 'static';
|
|
180
|
+
if (renderMode === 'server') {
|
|
181
|
+
serverPages.set(pagePath, page);
|
|
182
|
+
} else if (renderMode === 'static') {
|
|
183
|
+
staticPages.set(pagePath, page);
|
|
184
|
+
} else {
|
|
185
|
+
throw new Error(
|
|
186
|
+
`Invalid render mode ${JSON.stringify(renderMode)} for page ${page.file}. ` +
|
|
187
|
+
`Expected "static" or "server".`,
|
|
188
|
+
);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
return { staticPages, serverPages };
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* @param {{
|
|
196
|
+
* pages: import('@rocket/js/types.js').PageRegistry;
|
|
197
|
+
* staticPages: import('@rocket/js/types.js').PageRegistry;
|
|
198
|
+
* pageModuleLoader?: import('../page-runtime.js').PageModuleLoader;
|
|
199
|
+
* origin?: string;
|
|
200
|
+
* urlLifecycle?: import('@rocket/js/types.js').UrlLifecycleConfig;
|
|
201
|
+
* siteHeadMetadata?: import('@rocket/js/types.js').SiteHeadMetadataConfig;
|
|
202
|
+
* siteOrigin?: string;
|
|
203
|
+
* iconLibraries?: import('@rocket/js/types.js').IconLibrariesConfig;
|
|
204
|
+
* defaultIconLibrary?: string;
|
|
205
|
+
* iconAssetStore?: import('../icons.js').IconAssetStore;
|
|
206
|
+
* socialPreviewCacheDirectory?: string;
|
|
207
|
+
* captureSocialPreviewImage?: (options: {
|
|
208
|
+
* html: string;
|
|
209
|
+
* width: number;
|
|
210
|
+
* height: number;
|
|
211
|
+
* pathname: string;
|
|
212
|
+
* }) => Promise<Uint8Array> | Uint8Array;
|
|
213
|
+
* emitRedirectFallbacks?: boolean;
|
|
214
|
+
* }} options
|
|
215
|
+
* @returns {Promise<{ defaultSocialPreviewImages: Map<string, string> }>}
|
|
216
|
+
*/
|
|
217
|
+
export async function renderStaticPages({
|
|
218
|
+
pages,
|
|
219
|
+
staticPages,
|
|
220
|
+
pageModuleLoader = createStaticPageModuleLoader(),
|
|
221
|
+
origin = 'http://localhost',
|
|
222
|
+
urlLifecycle,
|
|
223
|
+
siteHeadMetadata,
|
|
224
|
+
siteOrigin,
|
|
225
|
+
iconLibraries,
|
|
226
|
+
defaultIconLibrary,
|
|
227
|
+
iconAssetStore = createIconAssetStore(),
|
|
228
|
+
socialPreviewCacheDirectory,
|
|
229
|
+
captureSocialPreviewImage = captureSocialPreviewImageWithBrowser,
|
|
230
|
+
emitRedirectFallbacks = true,
|
|
231
|
+
}) {
|
|
232
|
+
assertStaticJavaScriptPagesHaveConcretePaths(staticPages);
|
|
233
|
+
assertNoStandaloneDemoPathCollisions(pages, staticPages);
|
|
234
|
+
assertNoPaginatedArchivePathCollisions(pages, staticPages);
|
|
235
|
+
validateUrlLifecycleGeneratedOutputCollisions({
|
|
236
|
+
redirects: urlLifecycle?.redirects,
|
|
237
|
+
pages,
|
|
238
|
+
staticPages,
|
|
239
|
+
});
|
|
240
|
+
const socialPreviewPages = publicSocialPreviewPages(pages);
|
|
241
|
+
const defaultSocialPreviewImageOutputs = await generateStaticDefaultSocialPreviewImages({
|
|
242
|
+
pages: socialPreviewPages,
|
|
243
|
+
siteHeadMetadata,
|
|
244
|
+
siteOrigin,
|
|
245
|
+
cacheDirectory: socialPreviewCacheDirectory,
|
|
246
|
+
captureSocialPreviewImage,
|
|
247
|
+
});
|
|
248
|
+
/** @type {Map<string, string>} */
|
|
249
|
+
const defaultSocialPreviewImages = new Map();
|
|
250
|
+
for (const [pagePath, output] of defaultSocialPreviewImageOutputs) {
|
|
251
|
+
defaultSocialPreviewImages.set(pagePath, output.publicUrl);
|
|
252
|
+
}
|
|
253
|
+
for (const output of defaultSocialPreviewImageOutputs.values()) {
|
|
254
|
+
writeFileOutput(output.publicPath, output.data);
|
|
255
|
+
}
|
|
256
|
+
const pageRuntime = new PageRuntime({
|
|
257
|
+
pages,
|
|
258
|
+
pageModuleLoader,
|
|
259
|
+
siteHeadMetadata,
|
|
260
|
+
siteOrigin,
|
|
261
|
+
iconLibraries,
|
|
262
|
+
defaultIconLibrary,
|
|
263
|
+
iconAssetStore,
|
|
264
|
+
defaultSocialPreviewImages,
|
|
265
|
+
});
|
|
266
|
+
for (const [pagePath, page] of staticPages) {
|
|
267
|
+
try {
|
|
268
|
+
const response = await pageRuntime.render(new Request(new URL(pagePath, origin)));
|
|
269
|
+
await writeStaticResponse(pagePath, response);
|
|
270
|
+
for (const archivePath of paginatedArchivePaths({ pages, page, pagePath })) {
|
|
271
|
+
const archiveResponse = await pageRuntime.render(new Request(new URL(archivePath, origin)));
|
|
272
|
+
await writeStaticResponse(archivePath, archiveResponse);
|
|
273
|
+
}
|
|
274
|
+
for (const demoPath of standaloneDemoPaths(pagePath, page)) {
|
|
275
|
+
const demoResponse = await pageRuntime.render(new Request(new URL(demoPath, origin)));
|
|
276
|
+
await writeStandaloneDemoResponse(demoPath, page, demoResponse);
|
|
277
|
+
}
|
|
278
|
+
} catch (error) {
|
|
279
|
+
throw new Error(`Failed to render page: ${pagePath}. ${errorMessage(error)}`, {
|
|
280
|
+
cause: error,
|
|
281
|
+
});
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
writeIconAssetOutputs(iconAssetStore);
|
|
285
|
+
if (emitRedirectFallbacks) {
|
|
286
|
+
writeRedirectFallbackFiles(urlLifecycle?.redirects);
|
|
287
|
+
}
|
|
288
|
+
return { defaultSocialPreviewImages };
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
/**
|
|
292
|
+
* @param {import('@rocket/js/types.js').PageRegistry} staticPages
|
|
293
|
+
*/
|
|
294
|
+
function assertStaticJavaScriptPagesHaveConcretePaths(staticPages) {
|
|
295
|
+
for (const [pagePath, page] of staticPages) {
|
|
296
|
+
if (!page.file.endsWith('.js') || !hasPathParameter(pagePath)) {
|
|
297
|
+
continue;
|
|
298
|
+
}
|
|
299
|
+
throw new Error(
|
|
300
|
+
`Static JavaScript Page ${pagePath} (${page.file}) cannot be rendered as one static ` +
|
|
301
|
+
`output document because its path is parameterized. Parameterized JavaScript Pages need ` +
|
|
302
|
+
`request-time rendering until Rocket has an API for enumerating static params. Use ` +
|
|
303
|
+
`render: 'server' for this Page today.`,
|
|
304
|
+
);
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
/**
|
|
309
|
+
* @param {string} pagePath
|
|
310
|
+
*/
|
|
311
|
+
function hasPathParameter(pagePath) {
|
|
312
|
+
return /(^|\/):[^/]+/.test(pagePath);
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
/**
|
|
316
|
+
* @param {import('@rocket/js/types.js').PageRegistry} pages
|
|
317
|
+
* @param {import('@rocket/js/types.js').PageRegistry} staticPages
|
|
318
|
+
*/
|
|
319
|
+
function assertNoStandaloneDemoPathCollisions(pages, staticPages) {
|
|
320
|
+
const configuredPages = configuredPageOutputPaths(pages);
|
|
321
|
+
for (const [pagePath, page] of staticPages) {
|
|
322
|
+
for (const demoPath of standaloneDemoPaths(pagePath, page)) {
|
|
323
|
+
const collision = configuredPages.get(normalizeDocumentPath(demoPath));
|
|
324
|
+
if (collision) {
|
|
325
|
+
throw new Error(
|
|
326
|
+
`Standalone Demo URL ${demoPath} for page ${page.file} collides with configured ` +
|
|
327
|
+
`Page ${collision.page.file} at ${collision.path}`,
|
|
328
|
+
);
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
/**
|
|
335
|
+
* @param {import('@rocket/js/types.js').PageRegistry} pages
|
|
336
|
+
* @param {import('@rocket/js/types.js').PageRegistry} staticPages
|
|
337
|
+
*/
|
|
338
|
+
function assertNoPaginatedArchivePathCollisions(pages, staticPages) {
|
|
339
|
+
const configuredPages = configuredPageOutputPaths(pages);
|
|
340
|
+
const standaloneDemoPages = standaloneDemoOutputPaths(staticPages);
|
|
341
|
+
const archivePages = new Map();
|
|
342
|
+
for (const [pagePath, page] of staticPages) {
|
|
343
|
+
for (const archivePath of paginatedArchivePaths({ pages, page, pagePath })) {
|
|
344
|
+
const archiveOutputPath = normalizeDocumentPath(archivePath);
|
|
345
|
+
const collision = configuredPages.get(archiveOutputPath);
|
|
346
|
+
if (collision) {
|
|
347
|
+
throw new Error(
|
|
348
|
+
`Generated archive Page ${archivePath} for page ${page.file} collides with ` +
|
|
349
|
+
`configured Page ${collision.page.file} at ${collision.path}`,
|
|
350
|
+
);
|
|
351
|
+
}
|
|
352
|
+
const archiveCollision = archivePages.get(archiveOutputPath);
|
|
353
|
+
if (archiveCollision) {
|
|
354
|
+
throw new Error(
|
|
355
|
+
`Generated archive Page ${archivePath} for page ${page.file} collides with ` +
|
|
356
|
+
`generated archive Page ${archiveCollision.path} for page ${archiveCollision.page.file}`,
|
|
357
|
+
);
|
|
358
|
+
}
|
|
359
|
+
const standaloneDemoCollision = standaloneDemoPages.get(archiveOutputPath);
|
|
360
|
+
if (standaloneDemoCollision) {
|
|
361
|
+
throw new Error(
|
|
362
|
+
`Generated archive Page ${archivePath} for page ${page.file} collides with ` +
|
|
363
|
+
`Standalone Demo URL ${standaloneDemoCollision.path} for page ${standaloneDemoCollision.page.file}`,
|
|
364
|
+
);
|
|
365
|
+
}
|
|
366
|
+
archivePages.set(archiveOutputPath, { path: archivePath, page });
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
/**
|
|
372
|
+
* @param {import('@rocket/js/types.js').PageRegistry} staticPages
|
|
373
|
+
*/
|
|
374
|
+
function standaloneDemoOutputPaths(staticPages) {
|
|
375
|
+
const paths = new Map();
|
|
376
|
+
for (const [pagePath, page] of staticPages) {
|
|
377
|
+
for (const demoPath of standaloneDemoPaths(pagePath, page)) {
|
|
378
|
+
paths.set(normalizeDocumentPath(demoPath), { path: demoPath, page });
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
return paths;
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
/**
|
|
385
|
+
* @param {import('@rocket/js/types.js').PageRegistry} pages
|
|
386
|
+
* @returns {Map<string, { path: string; page: import('../page-runtime.js').Page }>}
|
|
387
|
+
*/
|
|
388
|
+
function configuredPageOutputPaths(pages) {
|
|
389
|
+
const paths = new Map();
|
|
390
|
+
for (const [pagePath, page] of pages) {
|
|
391
|
+
paths.set(normalizeDocumentPath(pagePath), { path: pagePath, page });
|
|
392
|
+
}
|
|
393
|
+
return paths;
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
/**
|
|
397
|
+
* @param {string} outDir
|
|
398
|
+
*/
|
|
399
|
+
function copyStaticFileOutputs(outDir) {
|
|
400
|
+
if (!existsSync('tmp-dist-rocket')) {
|
|
401
|
+
return;
|
|
402
|
+
}
|
|
403
|
+
for (const file of globSync('**/*', { cwd: 'tmp-dist-rocket' })) {
|
|
404
|
+
const source = path.join('tmp-dist-rocket', file);
|
|
405
|
+
if (!statSync(source).isFile() || file.endsWith('.html')) {
|
|
406
|
+
continue;
|
|
407
|
+
}
|
|
408
|
+
const destination = path.join(outDir, file);
|
|
409
|
+
mkdirSync(path.dirname(destination), { recursive: true });
|
|
410
|
+
copyFileSync(source, destination);
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
/**
|
|
415
|
+
* @param {import('../icons.js').IconAssetStore} iconAssetStore
|
|
416
|
+
*/
|
|
417
|
+
function writeIconAssetOutputs(iconAssetStore) {
|
|
418
|
+
for (const output of iconAssetStore.outputs()) {
|
|
419
|
+
writeFileOutput(output.url, Buffer.from(output.svg, 'utf8'));
|
|
420
|
+
}
|
|
421
|
+
if (!iconAssetStore.needsRuntime) {
|
|
422
|
+
return;
|
|
423
|
+
}
|
|
424
|
+
for (const output of rocketIconRuntimeOutputs()) {
|
|
425
|
+
writeFileOutput(output.path, Buffer.from(output.data, 'utf8'));
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
/**
|
|
430
|
+
* @param {string} outDir
|
|
431
|
+
*/
|
|
432
|
+
function clearExistingOutputDir(outDir) {
|
|
433
|
+
if (!existsSync(outDir)) {
|
|
434
|
+
return;
|
|
435
|
+
}
|
|
436
|
+
const projectRoot = path.resolve(process.cwd());
|
|
437
|
+
const relativeOutDir = path.relative(projectRoot, outDir);
|
|
438
|
+
if (
|
|
439
|
+
relativeOutDir === '' ||
|
|
440
|
+
relativeOutDir.startsWith(`..${path.sep}`) ||
|
|
441
|
+
relativeOutDir === '..' ||
|
|
442
|
+
path.isAbsolute(relativeOutDir)
|
|
443
|
+
) {
|
|
444
|
+
throw new Error(
|
|
445
|
+
`Invalid build output directory ${outDir}. ` +
|
|
446
|
+
`Rocket can only clear an existing output directory inside the project root.`,
|
|
447
|
+
);
|
|
448
|
+
}
|
|
449
|
+
rmSync(outDir, { recursive: true });
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
/**
|
|
453
|
+
* @param {import('@rocket/js/types.js').RedirectConfig[] | undefined} redirects
|
|
454
|
+
*/
|
|
455
|
+
function writeRedirectFallbackFiles(redirects = []) {
|
|
456
|
+
for (const redirect of redirects) {
|
|
457
|
+
const html = redirectFallbackHtml(redirect.target);
|
|
458
|
+
if (isFileOutputPath(redirect.source)) {
|
|
459
|
+
writeFileOutput(redirect.source, Buffer.from(html, 'utf8'));
|
|
460
|
+
continue;
|
|
461
|
+
}
|
|
462
|
+
writeHtml(redirect.source, html);
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
/**
|
|
467
|
+
* @param {string} target
|
|
468
|
+
*/
|
|
469
|
+
function redirectFallbackHtml(target) {
|
|
470
|
+
const escapedTarget = escapeHtml(target);
|
|
471
|
+
const scriptTarget = JSON.stringify(target).replaceAll('<', '\\u003C');
|
|
472
|
+
return [
|
|
473
|
+
'<!doctype html>',
|
|
474
|
+
'<html lang="en">',
|
|
475
|
+
'<head>',
|
|
476
|
+
' <meta charset="utf-8">',
|
|
477
|
+
` <meta http-equiv="refresh" content="0; url=${escapedTarget}">`,
|
|
478
|
+
` <link rel="canonical" href="${escapedTarget}" vite-ignore>`,
|
|
479
|
+
' <title>Redirecting</title>',
|
|
480
|
+
'</head>',
|
|
481
|
+
'<body>',
|
|
482
|
+
` <p>Redirecting to <a href="${escapedTarget}">${escapedTarget}</a>.</p>`,
|
|
483
|
+
` <script>window.location.replace(${scriptTarget});</script>`,
|
|
484
|
+
'</body>',
|
|
485
|
+
'</html>',
|
|
486
|
+
'',
|
|
487
|
+
].join('\n');
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
/**
|
|
491
|
+
* @param {string} pagePath
|
|
492
|
+
* @param {Response} response
|
|
493
|
+
*/
|
|
494
|
+
async function writeStaticResponse(pagePath, response) {
|
|
495
|
+
const data = new Uint8Array(await response.arrayBuffer());
|
|
496
|
+
if (isFileOutputPath(pagePath)) {
|
|
497
|
+
writeFileOutput(pagePath, data);
|
|
498
|
+
return;
|
|
499
|
+
}
|
|
500
|
+
writeHtml(pagePath, Buffer.from(data).toString('utf8'));
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
/**
|
|
504
|
+
* @param {string} demoPath
|
|
505
|
+
* @param {import('@rocket/js/types.js').Page} page
|
|
506
|
+
* @param {Response} response
|
|
507
|
+
*/
|
|
508
|
+
async function writeStandaloneDemoResponse(demoPath, page, response) {
|
|
509
|
+
const body = await response.text();
|
|
510
|
+
if (!response.ok) {
|
|
511
|
+
throw new Error(
|
|
512
|
+
`Standalone Demo URL ${demoPath} for page ${page.file} returned HTTP ${response.status}. ` +
|
|
513
|
+
`Expected a 2xx response. Body starts with: ${previewResponseBody(body)}`,
|
|
514
|
+
);
|
|
515
|
+
}
|
|
516
|
+
writeHtml(demoPath, body);
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
/**
|
|
520
|
+
* @param {string} pagePath
|
|
521
|
+
* @returns {boolean}
|
|
522
|
+
*/
|
|
523
|
+
function isFileOutputPath(pagePath) {
|
|
524
|
+
return path.extname(pagePath) !== '';
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
/**
|
|
528
|
+
* @param {string} pagePath
|
|
529
|
+
* @param {Uint8Array} data
|
|
530
|
+
*/
|
|
531
|
+
function writeFileOutput(pagePath, data) {
|
|
532
|
+
if (!pagePath.startsWith('/')) {
|
|
533
|
+
pagePath = '/' + pagePath;
|
|
534
|
+
}
|
|
535
|
+
const outputPath = 'tmp-dist-rocket' + pagePath;
|
|
536
|
+
mkdirSync(path.dirname(outputPath), { recursive: true });
|
|
537
|
+
writeFileSync(outputPath, data);
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
/**
|
|
541
|
+
* @param {string} pagePath
|
|
542
|
+
* @param {string} data
|
|
543
|
+
*/
|
|
544
|
+
function writeHtml(pagePath, data) {
|
|
545
|
+
pagePath = normalizeDocumentPath(pagePath);
|
|
546
|
+
const outputPath = 'tmp-dist-rocket' + pagePath;
|
|
547
|
+
if (!existsSync(outputPath)) {
|
|
548
|
+
mkdirSync(outputPath, { recursive: true });
|
|
549
|
+
}
|
|
550
|
+
writeFileSync(outputPath + 'index.html', data);
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
/**
|
|
554
|
+
* @param {string} value
|
|
555
|
+
*/
|
|
556
|
+
function escapeHtml(value) {
|
|
557
|
+
return value
|
|
558
|
+
.replaceAll('&', '&')
|
|
559
|
+
.replaceAll('"', '"')
|
|
560
|
+
.replaceAll("'", ''')
|
|
561
|
+
.replaceAll('<', '<')
|
|
562
|
+
.replaceAll('>', '>');
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
/**
|
|
566
|
+
* @param {string} body
|
|
567
|
+
*/
|
|
568
|
+
function previewResponseBody(body) {
|
|
569
|
+
const normalized = body.replace(/\s+/g, ' ').trim();
|
|
570
|
+
if (!normalized) {
|
|
571
|
+
return '(empty body)';
|
|
572
|
+
}
|
|
573
|
+
return JSON.stringify(normalized.slice(0, 200));
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
/**
|
|
577
|
+
* @param {unknown} error
|
|
578
|
+
*/
|
|
579
|
+
function errorMessage(error) {
|
|
580
|
+
return error instanceof Error ? error.message : String(error);
|
|
581
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
import { readConfig } from '../config.js';
|
|
3
|
+
import { RocketBuild } from './RocketBuild.js';
|
|
4
|
+
import { RocketInit } from './RocketInit.js';
|
|
5
|
+
import { RocketStart } from './RocketStart.js';
|
|
6
|
+
|
|
7
|
+
export class RocketCli {
|
|
8
|
+
/** @type {string[]} */
|
|
9
|
+
argv;
|
|
10
|
+
|
|
11
|
+
/** @type {Command} */
|
|
12
|
+
program;
|
|
13
|
+
|
|
14
|
+
/** @type {string | undefined} */
|
|
15
|
+
configFilePath;
|
|
16
|
+
|
|
17
|
+
/** @type {import('@rocket/js/types.js').ResolvedRocketConfig | undefined} */
|
|
18
|
+
config;
|
|
19
|
+
|
|
20
|
+
constructor({ argv = process.argv } = {}) {
|
|
21
|
+
this.argv = argv;
|
|
22
|
+
|
|
23
|
+
this.program = new Command();
|
|
24
|
+
this.program.allowUnknownOption(true).option('-c, --config-file <path>', 'path to config file');
|
|
25
|
+
this.program.parseOptions(this.argv);
|
|
26
|
+
|
|
27
|
+
this.program.allowUnknownOption(false);
|
|
28
|
+
|
|
29
|
+
if (this.program.opts().configFile) {
|
|
30
|
+
this.configFilePath = this.program.opts().configFile;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
async getConfig() {
|
|
35
|
+
this.config ??= await readConfig(this.configFilePath);
|
|
36
|
+
return this.config;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
async start() {
|
|
40
|
+
for (const progClass of [RocketInit, RocketBuild, RocketStart]) {
|
|
41
|
+
const prog = new progClass();
|
|
42
|
+
await prog.setupCommand(this.program, this);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
await this.program.parseAsync(this.argv);
|
|
46
|
+
}
|
|
47
|
+
}
|