Skip to content

Commit a306fc7

Browse files
authored
[showcase] Add support to deploy versions in virtual directories (#658)
* Build Mercury before building the showcase * Add support to deploy versions in virtual directories * Simplify versioning process * Update README.md * Update README.md
1 parent facfbab commit a306fc7

File tree

10 files changed

+82
-17
lines changed

10 files changed

+82
-17
lines changed

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,16 @@ To see the documentation and examples of how to use Mercury, visit the [showcase
4141
```bash
4242
bun build.un.watch
4343
```
44+
45+
- To build the showcase with a specific virtual directory
46+
47+
```bash
48+
bun build.version <version>
49+
```
50+
51+
For example:
52+
53+
```bash
54+
bun build.version v1.0.0-beta
55+
```
56+

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
"version": "0.0.225",
55
"type": "module",
66
"scripts": {
7-
"build": "bun build.common && cd packages/showcase && bun run build",
7+
"build": "bun build.common && bun build.mer && cd packages/showcase && bun run build",
8+
"build.version": "bun build.common && bun build.mer && cd packages/showcase && bun run build.version",
89
"build.watch": "bun build.common && cd packages/showcase && bun build.watch",
910
"build.common": "cd packages/common && bun run build",
1011
"build.mer": "cd packages/mercury && bun build-no-svg",

packages/common/src/metadata/components/chat/metadata.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,23 +88,23 @@ const AVATAR_CUSTOM_STYLES = `
8888
.chat::part(header-coordinator) {
8989
--chat-avatar-border-color-from: #FDE047;
9090
--chat-avatar-border-color-to: #F97316;
91-
--chat-avatar-background-image: url("/assets/chat-showcase/coordinator.webp");
91+
--chat-avatar-background-image: url("./assets/chat-showcase/coordinator.webp");
9292
--chat-avatar-waiting-dot-1-color: #FDE047;
9393
--chat-avatar-waiting-dot-2-color: #FBBF24;
9494
--chat-avatar-waiting-dot-3-color: #F97316;
9595
}
9696
.chat::part(header-programming-generalist) {
9797
--chat-avatar-border-color-from: #8B5CF6;
9898
--chat-avatar-border-color-to: #3B82F6;
99-
--chat-avatar-background-image: url("/assets/chat-showcase/programming-generalist.webp");
99+
--chat-avatar-background-image: url("./assets/chat-showcase/programming-generalist.webp");
100100
--chat-avatar-waiting-dot-1-color: #8B5CF6;
101101
--chat-avatar-waiting-dot-2-color: #6366F1;
102102
--chat-avatar-waiting-dot-3-color: #3B82F6;
103103
}
104104
.chat::part(header-react-expert) {
105105
--chat-avatar-border-color-from: #EC4899;
106106
--chat-avatar-border-color-to: #DC2626;
107-
--chat-avatar-background-image: url("/assets/chat-showcase/react-expert.webp");
107+
--chat-avatar-background-image: url("./assets/chat-showcase/react-expert.webp");
108108
--chat-avatar-waiting-dot-1-color: #f87bb8;
109109
--chat-avatar-waiting-dot-2-color: #ee3961;
110110
--chat-avatar-waiting-dot-3-color: #ee2525;

packages/common/src/metadata/components/chat/models.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -262,31 +262,31 @@ export const dummySampleFiles = (
262262
extension: "mp3",
263263
mimeType: "audio/mp3",
264264
uploadState: uploadState,
265-
url: "/assets/chat-showcase/guitar-bend.mp3"
265+
url: "./assets/chat-showcase/guitar-bend.mp3"
266266
},
267267
{
268268
accessibleName: "Particles in the dark",
269269
caption: "particles",
270270
extension: "mp4",
271271
mimeType: "video/mp4",
272272
uploadState: uploadState,
273-
url: "/assets/chat-showcase/particles.mp4"
273+
url: "./assets/chat-showcase/particles.mp4"
274274
},
275275
{
276276
alternativeText: "Mercury geometric thin shapes in blue",
277277
caption: "mercury-geometric-thin-shapes-in-blue-for-ui-layout-testing",
278278
extension: "svg",
279279
mimeType: "image/svg",
280280
uploadState: uploadState,
281-
url: "/assets/chat-showcase/mercury-cover.svg"
281+
url: "./assets/chat-showcase/mercury-cover.svg"
282282
},
283283
{
284284
accessibleName: "Project proposal, version 2 (PDF)",
285285
caption: "project-proposal-v2",
286286
extension: "pdf",
287287
mimeType: "application/pdf",
288288
uploadState: uploadState,
289-
url: "/assets/chat-showcase/project-proposal-v2.pdf"
289+
url: "./assets/chat-showcase/project-proposal-v2.pdf"
290290
}
291291
];
292292
};

packages/showcase/README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,17 @@ npm run build
2121
```
2222

2323
After that, you can deploy the `dist/browser` folder if you want the application to be static.
24+
25+
## Generate a custom build for a specific version
26+
27+
```bash
28+
bun build.version <version>
29+
```
30+
31+
For example:
32+
33+
```bash
34+
bun build.version v1.0.0-beta
35+
```
36+
37+
After that, you can deploy the `dist/browser` folder if you want the application to be static.

packages/showcase/build-version.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
2+
// It generates a custom version for the showcase that works in virtual
3+
// directories.
4+
// It requires a version argument, e.g. "v1.0.0-beta".
5+
// This allow us to host multiple versions of the showcase in the same domain.
6+
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
7+
import { spawn } from "child_process";
8+
import { styleText } from "util";
9+
10+
const start = Date.now();
11+
12+
const VERSION = process.argv[2];
13+
14+
if (VERSION === undefined) {
15+
console.error(
16+
styleText("red", "error: version argument is required."),
17+
"Example:",
18+
styleText(["bold", "cyanBright"], "bun build.version v1.0.0-beta")
19+
);
20+
process.exit(1);
21+
}
22+
23+
const child = spawn(
24+
`bun compute-version && bun mercury -i=/${VERSION}/assets/icons/ -f=/${VERSION}/assets/fonts/ --outDir=.mercury/ && ng build --base-href /${VERSION}/`,
25+
{ stdio: "inherit", shell: true }
26+
);
27+
28+
child.on("close", code => {
29+
const duration = Date.now() - start;
30+
31+
if (code === 0) {
32+
console.log(styleText("green", `✓ version ${VERSION} built in ${duration}ms`));
33+
} else {
34+
console.log(
35+
styleText("red", `error building the version ${VERSION} (code: ${code})`)
36+
);
37+
}
38+
});

packages/showcase/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"start": "bun compute-version && bun build.scss && ng serve -o --port 0",
99
"start.watch": "bun compute-version && ng serve -o --port 0",
1010
"build": "bun compute-version && bun build.scss && ng build",
11+
"build.version": "node build-version.js",
1112
"build.watch": "bun run build -- --watch",
1213
"build.scss": "mercury -i=/assets/icons/ -f=/assets/fonts/ --outDir=.mercury/",
1314
"watch": "bun compute-version && ng build --watch --configuration development",

packages/showcase/src/app/app.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
&::before {
3737
content: "";
3838
display: block;
39-
-webkit-mask: no-repeat center / 100% url("/assets/icons/mercury.svg");
39+
-webkit-mask: no-repeat center / 100% url("../../public/icons/mercury.svg");
4040
inline-size: 40px;
4141
block-size: 40px;
4242
background-color: currentColor;
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export const mercuryVersion = "0.32.0";
1+
export const mercuryVersion = "0.32.0";

packages/showcase/src/services/design-system.service.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { isPlatformBrowser } from "@angular/common";
22
import { effect, inject, Injectable, PLATFORM_ID, signal } from "@angular/core";
33

4-
import { SEOService } from "./seo.service";
5-
import type { DesignSystem, MercuryVariant } from "../common/types";
64
import { bundleToHashMappings } from "../../.mercury/bundle-to-hash-mappings";
5+
import type { DesignSystem, MercuryVariant } from "../common/types";
6+
import { SEOService } from "./seo.service";
77

8-
const BASE_CSS_URL = "/assets/css/";
8+
const BASE_CSS_URL = "./assets/css/";
99
export const MERCURY_BASE_CSS_URL = `${BASE_CSS_URL}mercury/`;
1010
// export const UNANIMO_BASE_CSS_URL = `${BASE_CSS_URL}unanimo/`;
1111
export const UNANIMO_BASE_CSS_URL = `${BASE_CSS_URL}mercury/`;
@@ -64,8 +64,7 @@ export class DesignSystemService {
6464
constructor() {
6565
if (isPlatformBrowser(this.platform)) {
6666
this.designSystem.set(
67-
(localStorage.getItem(DESIGN_SYSTEM_KEY) as DesignSystem | null) ??
68-
"mercury"
67+
(localStorage.getItem(DESIGN_SYSTEM_KEY) as DesignSystem | null) ?? "mercury"
6968
);
7069
this.mercuryVariant.set(
7170
(localStorage.getItem(MERCURY_VARIANT_KEY) as MercuryVariant | null) ??
@@ -87,8 +86,7 @@ export class DesignSystemService {
8786
if (alreadyExisted) {
8887
this.disablePreviousLink(newVariantSelector, link);
8988
} else {
90-
link.onload = () =>
91-
this.disablePreviousLink(newVariantSelector, link);
89+
link.onload = () => this.disablePreviousLink(newVariantSelector, link);
9290
}
9391

9492
this.seoService.updateDescription(

0 commit comments

Comments
 (0)