Open History to see the last commit
1#!/usr/bin/env node
2
3import * as NodeRuntime from "@effect/platform-node/NodeRuntime";
4import * as NodeServices from "@effect/platform-node/NodeServices";
5import { Effect, FileSystem, Option, Path } from "effect";
6import { Argument, Command } from "effect/unstable/cli";
7import { resolveWebIconOverrides, type WebAssetBrand } from "./lib/brand-assets.ts";
8
9const WEB_ASSET_BRANDS = [
10 "development",
11 "production",
12] as const satisfies ReadonlyArray<WebAssetBrand>;
13
14export const applyWebBrandAssets = Effect.fn("applyWebBrandAssets")(function* (
15 brand: WebAssetBrand,
16 targetDirectory: string,
17) {
18 const fs = yield* FileSystem.FileSystem;
19 const path = yield* Path.Path;
20 const repoRoot = yield* path.fromFileUrl(new URL("..", import.meta.url));
21
22 yield* Effect.forEach(
23 resolveWebIconOverrides(brand, targetDirectory),
24 (override) =>
25 fs.copyFile(
26 path.join(repoRoot, override.sourceRelativePath),
27 path.join(repoRoot, override.targetRelativePath),
28 ),
29 { concurrency: "unbounded" },
30 );
31});
32
33export const applyWebBrandAssetsCommand = Command.make(
34 "apply-web-brand-assets",
35 {
36 brand: Argument.choice("brand", WEB_ASSET_BRANDS).pipe(
37 Argument.withDescription("Asset brand to copy into the hosted web output directory."),
38 ),
39 targetDirectory: Argument.string("target-directory").pipe(
40 Argument.withDescription("Output directory that contains the hosted web build assets."),
41 Argument.optional,
42 ),
43 },
44 ({ brand, targetDirectory }) =>
45 applyWebBrandAssets(
46 brand,
47 Option.getOrElse(targetDirectory, () => "apps/web/dist"),
48 ),
49).pipe(Command.withDescription("Copy web brand assets into a built hosted web app."));
50
51if (import.meta.main) {
52 Command.run(applyWebBrandAssetsCommand, { version: "0.0.0" }).pipe(
53 Effect.provide(NodeServices.layer),
54 NodeRuntime.runMain,
55 );
56}