@protobase/cli 0.96.7 → 0.96.9

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.
@@ -1,4 +1,4 @@
1
1
  //#region package.json
2
- var version = "0.96.7";
2
+ var version = "0.96.9";
3
3
  //#endregion
4
4
  export { version };
@@ -0,0 +1,9 @@
1
+ import { pathToFileURL } from "node:url";
2
+ //#region src/dev/dev-module-url.ts
3
+ const devModuleUrl = (file) => {
4
+ const posix = file.replaceAll("\\", "/");
5
+ if (posix.split("/").includes("node_modules")) return pathToFileURL(file).href;
6
+ return posix.startsWith("/") ? `/@fs${posix}` : `/@fs/${posix}`;
7
+ };
8
+ //#endregion
9
+ export { devModuleUrl };
@@ -1,14 +1,11 @@
1
1
  import { serverPackage } from "./server-package.js";
2
2
  import { loadSourceConfig } from "../config/source-config.js";
3
3
  import { sharedDb } from "./create-db.js";
4
- import { pathToFileURL } from "node:url";
4
+ import { devModuleUrl } from "./dev-module-url.js";
5
5
  //#region src/dev/project.ts
6
- const load = (file) => file.split("/").includes("node_modules") ? import(
6
+ const load = (file) => import(
7
7
  /* @vite-ignore */
8
- pathToFileURL(file).href
9
- ) : import(
10
- /* @vite-ignore */
11
- `/@fs${file}`
8
+ devModuleUrl(file)
12
9
  );
13
10
  const importModules = async (files) => {
14
11
  const modules = [];
@@ -0,0 +1,63 @@
1
+ import { densityScales } from "./android-app-icon.js";
2
+ //#region src/mobile/android-splash-image.ts
3
+ const res = "app/src/main/res";
4
+ const side = 288;
5
+ const shown = 192;
6
+ /** The splash image's drawable, which the launch theme names. */
7
+ const androidSplashImageName = "protobase_splash_image";
8
+ /**
9
+ * The splash for the splash screen plugin to show while the app reloads into a live update, as Android 12 and the
10
+ * core-splashscreen library draw the launch: the image at 288dp, masked to its middle 192dp circle by a ring in the
11
+ * background's colour, on that background.
12
+ */
13
+ const androidSplashImageDrawable = `<?xml version="1.0" encoding="utf-8"?>
14
+ <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
15
+ <item android:gravity="fill">
16
+ <color android:color="@color/protobase_splash_background" />
17
+ </item>
18
+ <item
19
+ android:width="${side}dp"
20
+ android:height="${side}dp"
21
+ android:drawable="@drawable/${androidSplashImageName}"
22
+ android:gravity="center" />
23
+ <item
24
+ android:width="408dp"
25
+ android:height="408dp"
26
+ android:gravity="center">
27
+ <shape android:shape="oval">
28
+ <solid android:color="@android:color/transparent" />
29
+ <stroke
30
+ android:width="108dp"
31
+ android:color="@color/protobase_splash_background" />
32
+ </shape>
33
+ </item>
34
+ </layer-list>
35
+ `;
36
+ /**
37
+ * The app's own Android splash image at each density, 288dp, its dark one under `night` beside it when there is one,
38
+ * and the drawable the splash screen plugin shows.
39
+ */
40
+ const androidSplashImage = async (sharp, light, dark) => {
41
+ const files = [{
42
+ file: `${res}/drawable/protobase_splash.xml`,
43
+ content: androidSplashImageDrawable
44
+ }];
45
+ for (const [density, scale] of Object.entries(densityScales)) {
46
+ const px = side * scale;
47
+ files.push({
48
+ file: `${res}/drawable-${density}/${androidSplashImageName}.png`,
49
+ content: await sharp(light).resize(px, px).png().toBuffer()
50
+ });
51
+ if (dark) files.push({
52
+ file: `${res}/drawable-night-${density}/${androidSplashImageName}.png`,
53
+ content: await sharp(dark).resize(px, px).png().toBuffer()
54
+ });
55
+ }
56
+ return files;
57
+ };
58
+ /** The side of the splash image, in pixels, it is drawn from: 288dp at Android's largest density. */
59
+ const splashSourceSize = side * densityScales.xxxhdpi;
60
+ /** The share of the splash image's side Android shows, in its middle. */
61
+ const shownShare = shown / side;
62
+ //#endregion
63
+ export { androidSplashImage, androidSplashImageDrawable, androidSplashImageName, shownShare, splashSourceSize };
@@ -1,4 +1,5 @@
1
- import { copySplashFile, removeTemplateSplash } from "./native-splash.js";
1
+ import { androidSplashImageName } from "./android-splash-image.js";
2
+ import { copySplashFile, removeTemplateSplash, writeSplashFiles } from "./native-splash.js";
2
3
  import path from "node:path";
3
4
  import { mkdir, readFile, writeFile } from "node:fs/promises";
4
5
  //#region src/mobile/android-splash.ts
@@ -28,10 +29,17 @@ const launchTheme = ` <style name="AppTheme.NoActionBarLaunch" parent="Theme.
28
29
  <item name="windowSplashScreenAnimatedIcon">@mipmap/ic_launcher</item>
29
30
  <item name="windowSplashScreenIconBackgroundColor">@color/ic_launcher_background</item>
30
31
  </style>`;
31
- /** The template's styles.xml with Protobase's launch theme; it fails on any other, which may set its own splash. */
32
- const withLaunchTheme = (styles) => {
32
+ const imageLaunchTheme = ` <style name="AppTheme.NoActionBarLaunch" parent="Theme.SplashScreen">
33
+ <item name="windowSplashScreenBackground">@color/protobase_splash_background</item>
34
+ <item name="windowSplashScreenAnimatedIcon">@drawable/${androidSplashImageName}</item>
35
+ </style>`;
36
+ /**
37
+ * The template's styles.xml with Protobase's launch theme, showing the app's own splash image with `ownImage`; it fails
38
+ * on any other, which may set its own splash.
39
+ */
40
+ const withLaunchTheme = (styles, ownImage = false) => {
33
41
  if (!styles.includes(templateLaunchTheme)) throw new Error("The generated android project's styles.xml is not Capacitor's template: its launch theme is not the one Protobase replaces");
34
- return styles.replace(templateLaunchTheme, launchTheme);
42
+ return styles.replace(templateLaunchTheme, ownImage ? imageLaunchTheme : launchTheme);
35
43
  };
36
44
  /** The `protobase_splash_background` colour resource, in values for light mode and values-night for dark. */
37
45
  const splashBackgroundResource = (color) => `<?xml version="1.0" encoding="utf-8"?>
@@ -39,10 +47,13 @@ const splashBackgroundResource = (color) => `<?xml version="1.0" encoding="utf-8
39
47
  <color name="protobase_splash_background">${color}</color>
40
48
  </resources>
41
49
  `;
42
- /** Gives the Android project in the workspace Protobase's splash screen on the app's background in place of Capacitor's. */
43
- const withAndroidSplash = async (ws, { light, dark }) => {
50
+ /**
51
+ * Gives the Android project in the workspace Protobase's splash screen on its background, `colors`, in place of
52
+ * Capacitor's: the launcher icon, or the app's own splash image, its `image` files, with them.
53
+ */
54
+ const withAndroidSplash = async (ws, { light, dark }, image) => {
44
55
  const styles = path.join(ws, "android", stylesPath);
45
- await writeFile(styles, withLaunchTheme(await readFile(styles, "utf8")));
56
+ await writeFile(styles, withLaunchTheme(await readFile(styles, "utf8"), image !== void 0));
46
57
  for (const [values, color] of [["values", light], ["values-night", dark]]) {
47
58
  const dir = path.join(ws, "android", res, values);
48
59
  await mkdir(dir, { recursive: true });
@@ -50,6 +61,7 @@ const withAndroidSplash = async (ws, { light, dark }) => {
50
61
  }
51
62
  for (const image of templateSplashImages) await removeTemplateSplash(ws, "android", image);
52
63
  for (const file of androidSplashFiles) await copySplashFile(ws, "android", file);
64
+ if (image) await writeSplashFiles(ws, "android", image);
53
65
  };
54
66
  //#endregion
55
67
  export { androidSplashFiles, androidSplashLayout, splashBackgroundResource, templateSplashImages, withAndroidSplash, withLaunchTheme };
@@ -16,13 +16,14 @@ const androidManifest = (ws) => path.join(ws, "android", "app", "src", "main", "
16
16
  /**
17
17
  * Generates the platform's native project in the workspace from its capacitor.config.json and app files, replacing
18
18
  * the last one: it is never edited by hand. Its home-screen icon is the app's own in `icon`, or Protobase's without
19
- * one, and its splash screen that icon on the app's background in `splash`, light and dark, in place of Capacitor's logo. An Android app with push gets the
19
+ * one, and its splash screen the app's own splash image in `splashImage`, or without one that icon, on the background
20
+ * in `splash`, light and dark, in place of Capacitor's logo. An Android app with push gets the
20
21
  * project's google-services.json from `googleServicesFrom`, an iOS app with push its entitlement in `apnsEnvironment` and
21
22
  * the token forwarding, and an iOS app calling the API over plain http may reach local addresses. Android apps opt out
22
23
  * of backup and device transfer, and iOS apps start as a fresh install after a restore or a move, so nothing carries
23
24
  * over to another phone.
24
25
  */
25
- const generatePlatform = async (ws, platform, { cleartext, splash, icon, googleServicesFrom, apnsEnvironment }, cap) => {
26
+ const generatePlatform = async (ws, platform, { cleartext, splash, splashImage, icon, googleServicesFrom, apnsEnvironment }, cap) => {
26
27
  await rm(path.join(ws, platform), {
27
28
  recursive: true,
28
29
  force: true
@@ -31,7 +32,7 @@ const generatePlatform = async (ws, platform, { cleartext, splash, icon, googleS
31
32
  if (icon) await withAppIcon(ws, platform, icon.icon);
32
33
  else await withProtobaseIcon(ws, platform);
33
34
  if (platform === "android") {
34
- await withAndroidSplash(ws, splash);
35
+ await withAndroidSplash(ws, splash, splashImage);
35
36
  if (googleServicesFrom !== void 0) await copyGoogleServices(googleServicesFrom, ws);
36
37
  await writeFile(androidManifest(ws), withoutBackup(await readFile(androidManifest(ws), "utf8")));
37
38
  const rules = path.join(ws, "android", ...dataExtractionRulesPath);
@@ -39,8 +40,8 @@ const generatePlatform = async (ws, platform, { cleartext, splash, icon, googleS
39
40
  await writeFile(rules, dataExtractionRules);
40
41
  return;
41
42
  }
42
- await withIosSplash(ws, splash);
43
- if (icon) await writeNativeFiles(ws, "ios", icon.splash, iosSplashImages.map(([file]) => file));
43
+ await withIosSplash(ws, splash, splashImage);
44
+ if (icon && !splashImage) await writeNativeFiles(ws, "ios", icon.splash, iosSplashImages.map(([file]) => file));
44
45
  await writeFile(appDelegate(ws), withFreshInstall(await readFile(appDelegate(ws), "utf8")));
45
46
  if (apnsEnvironment !== void 0) await setUpIosPush(ws, apnsEnvironment);
46
47
  if (!cleartext) return;
@@ -4,22 +4,28 @@ import path from "node:path";
4
4
  /** The size every icon is drawn from: the App Store icon's, the largest one. */
5
5
  const sourceSize = 1024;
6
6
  /**
7
- * Reads the app's icon `file`, `mobile.icon` from the project's folder `projectDir`: a square PNG of at least
8
- * `sourceSize` pixels, or a square SVG, drawn at that size. Any other file stops the build, naming the setting and
9
- * the rule, since the platforms would take a wrong one quietly.
7
+ * Reads the image `file` the setting names from the project's folder `projectDir`: a square PNG of at least `size`
8
+ * pixels, or a square SVG, drawn at that size. Any other file stops the build, naming the setting and the rule, since
9
+ * the platforms would take a wrong one quietly.
10
10
  */
11
- const readIconSource = async (sharp, projectDir, file) => {
11
+ const readSquareImage = async (sharp, projectDir, file, { setting, noun, size }) => {
12
12
  const at = path.resolve(projectDir, file);
13
- if (!existsSync(at)) throw new Error(`mobile.icon names ${file}, which does not exist: ${at}`);
13
+ if (!existsSync(at)) throw new Error(`${setting} names ${file}, which does not exist: ${at}`);
14
14
  const { format, width = 0, height = 0 } = await sharp(at).metadata();
15
- if (format !== "png" && format !== "svg") throw new Error(`mobile.icon names ${file}, which is no PNG or SVG: the icon must be a PNG or an SVG`);
16
- if (width === 0 || width !== height) throw new Error(`mobile.icon names ${file}, which is ${width}x${height} pixels: the icon must be square`);
17
- if (format === "png" && width < 1024) throw new Error(`mobile.icon names ${file}, which is ${width}x${height} pixels: a PNG icon must be at least ${sourceSize}x${sourceSize}`);
18
- const image = await (format === "svg" ? sharp(at, { density: 72 * sourceSize / width }) : sharp(at)).resize(sourceSize, sourceSize).ensureAlpha().png().toBuffer();
15
+ if (format !== "png" && format !== "svg") throw new Error(`${setting} names ${file}, which is no PNG or SVG: the ${noun} must be a PNG or an SVG`);
16
+ if (width === 0 || width !== height) throw new Error(`${setting} names ${file}, which is ${width}x${height} pixels: the ${noun} must be square`);
17
+ if (format === "png" && width < size) throw new Error(`${setting} names ${file}, which is ${width}x${height} pixels: a PNG ${noun} must be at least ${size}x${size}`);
18
+ const image = await (format === "svg" ? sharp(at, { density: 72 * size / width }) : sharp(at)).resize(size, size).ensureAlpha().png().toBuffer();
19
19
  return {
20
20
  image,
21
21
  opaque: (await sharp(image).stats()).isOpaque
22
22
  };
23
23
  };
24
+ /** Reads the app's icon `file`, `mobile.icon`: a square PNG of at least `sourceSize` pixels, or a square SVG. */
25
+ const readIconSource = (sharp, projectDir, file) => readSquareImage(sharp, projectDir, file, {
26
+ setting: "mobile.icon",
27
+ noun: "icon",
28
+ size: sourceSize
29
+ });
24
30
  //#endregion
25
- export { readIconSource, sourceSize };
31
+ export { readIconSource, readSquareImage, sourceSize };
@@ -0,0 +1,61 @@
1
+ import { shownShare } from "./android-splash-image.js";
2
+ //#region src/mobile/ios-splash-image.ts
3
+ const imageSet = "App/App/Assets.xcassets/Splash.imageset";
4
+ const scales = [
5
+ 1,
6
+ 2,
7
+ 3
8
+ ];
9
+ const name = (scale, dark) => `splash${dark ? "-dark" : ""}${scale === 1 ? "" : `@${scale}x`}.png`;
10
+ const entry = (scale, dark) => ({
11
+ ...dark && { appearances: [{
12
+ appearance: "luminosity",
13
+ value: "dark"
14
+ }] },
15
+ filename: name(scale, dark),
16
+ idiom: "universal",
17
+ scale: `${scale}x`
18
+ });
19
+ /** The `Splash` image set's Contents.json, with the dark appearance when the app has a dark image. */
20
+ const splashImageContents = (dark) => `${JSON.stringify({
21
+ images: [...scales.map((scale) => entry(scale, false)), ...dark ? scales.map((scale) => entry(scale, true)) : []],
22
+ info: {
23
+ author: "xcode",
24
+ version: 1
25
+ }
26
+ }, null, 2)}\n`;
27
+ const circleMask = (size) => Buffer.from(`<svg xmlns="http://www.w3.org/2000/svg" width="${size}" height="${size}"><circle cx="${size / 2}" cy="${size / 2}" r="${size / 2}" fill="#fff"/></svg>`);
28
+ const shownCircle = async (sharp, image, size) => {
29
+ const { width = 0 } = await sharp(image).metadata();
30
+ const kept = Math.round(width * shownShare);
31
+ const left = Math.floor((width - kept) / 2);
32
+ return sharp(image).extract({
33
+ left,
34
+ top: left,
35
+ width: kept,
36
+ height: kept
37
+ }).resize(size, size).ensureAlpha().composite([{
38
+ input: circleMask(size),
39
+ blend: "dest-in"
40
+ }]).png().toBuffer();
41
+ };
42
+ /**
43
+ * The app's own iOS splash image, the `Splash` image set: the middle circle of the image Android shows, at 1x, 2x and
44
+ * 3x of `iosSplashImagePoints`, and the dark image's beside it when there is one, so both platforms show the same.
45
+ */
46
+ const iosSplashImage = async (sharp, light, dark) => {
47
+ const drawn = (image, isDark) => Promise.all(scales.map(async (scale) => ({
48
+ file: `${imageSet}/${name(scale, isDark)}`,
49
+ content: await shownCircle(sharp, image, 192 * scale)
50
+ })));
51
+ return [
52
+ {
53
+ file: `${imageSet}/Contents.json`,
54
+ content: splashImageContents(dark !== void 0)
55
+ },
56
+ ...await drawn(light, false),
57
+ ...dark ? await drawn(dark, true) : []
58
+ ];
59
+ };
60
+ //#endregion
61
+ export { iosSplashImage, splashImageContents };
@@ -1,6 +1,6 @@
1
- import { copySplashFile, removeTemplateSplash } from "./native-splash.js";
1
+ import { copySplashFile, removeTemplateSplash, writeSplashFiles } from "./native-splash.js";
2
2
  import path from "node:path";
3
- import { mkdir, writeFile } from "node:fs/promises";
3
+ import { mkdir, readFile, writeFile } from "node:fs/promises";
4
4
  //#region src/mobile/ios-splash.ts
5
5
  const assets = "App/App/Assets.xcassets";
6
6
  /**
@@ -39,8 +39,21 @@ const splashBackgroundContents = ({ light, dark }) => `${JSON.stringify({
39
39
  version: 1
40
40
  }
41
41
  }, null, 2)}\n`;
42
- /** Gives the iOS project in the workspace Protobase's launch screen on the app's background in place of Capacitor's. */
43
- const withIosSplash = async (ws, colors) => {
42
+ const iconSize = ["constant=\"128\"", "width=\"128\" height=\"128\""];
43
+ /** Protobase's launch storyboard with the `Splash` image drawn at `points`; it fails on any other storyboard. */
44
+ const withSplashImageSize = (storyboard, points) => {
45
+ let sized = storyboard;
46
+ for (const size of iconSize) {
47
+ if (sized.split(size).length !== 3) throw new Error("@protobase/mobile's LaunchScreen.storyboard does not draw the Splash image at 128 points, the size Protobase replaces");
48
+ sized = sized.replaceAll(size, size.replaceAll("128", String(points)));
49
+ }
50
+ return sized;
51
+ };
52
+ /**
53
+ * Gives the iOS project in the workspace Protobase's launch screen on its background, `colors`, in place of
54
+ * Capacitor's: the app's icon, or the app's own splash image, its `image` files, with them.
55
+ */
56
+ const withIosSplash = async (ws, colors, image) => {
44
57
  for (const file of iosSplashFiles) {
45
58
  await removeTemplateSplash(ws, "ios", file);
46
59
  await copySplashFile(ws, "ios", file);
@@ -48,6 +61,10 @@ const withIosSplash = async (ws, colors) => {
48
61
  const set = path.join(ws, "ios", splashBackgroundSet);
49
62
  await mkdir(set, { recursive: true });
50
63
  await writeFile(path.join(set, "Contents.json"), splashBackgroundContents(colors));
64
+ if (!image) return;
65
+ await writeSplashFiles(ws, "ios", image);
66
+ const storyboard = path.join(ws, "ios", iosSplashFiles[0]);
67
+ await writeFile(storyboard, withSplashImageSize(await readFile(storyboard, "utf8"), 192));
51
68
  };
52
69
  //#endregion
53
- export { iosSplashFiles, splashBackgroundContents, splashBackgroundSet, withIosSplash };
70
+ export { iosSplashFiles, splashBackgroundContents, splashBackgroundSet, withIosSplash, withSplashImageSize };
@@ -1,6 +1,7 @@
1
1
  import { appIdProblem, isAppId } from "./app-id.js";
2
2
  import { packageNameProblem } from "./package-name.js";
3
3
  import { pinnedProblem } from "./pinned-packages.js";
4
+ import { checkSplashConfig } from "./splash-config.js";
4
5
  import { updaterPublicKey } from "./public-key.js";
5
6
  //#region src/mobile/mobile-config.ts
6
7
  const noMobileSection = "This project has no mobile section: add `mobile: { appId: 'com.example.app' }` to the default export of protobase.config.ts";
@@ -10,13 +11,14 @@ const isRecord = (value) => typeof value === "object" && value !== null && !Arra
10
11
  const checkMobileConfig = (value) => {
11
12
  if (value === void 0) throw new Error(noMobileSection);
12
13
  if (!isRecord(value)) throw new Error("mobile in protobase.config.ts must be an object such as { appId: 'com.example.app' }");
13
- const { appId, plugins, publicKey, icon } = value;
14
+ const { appId, plugins, publicKey, icon, splash } = value;
14
15
  if (!isAppId(appId)) throw new Error(appIdProblem(appId));
15
16
  if (publicKey !== void 0) updaterPublicKey(publicKey);
16
17
  if (icon !== void 0 && (typeof icon !== "string" || icon === "")) throw new Error("mobile.icon must be the path of the app's icon from the project's folder, such as 'icon.png'");
17
18
  const key = {
18
19
  ...publicKey !== void 0 && { publicKey },
19
- ...icon !== void 0 && { icon }
20
+ ...icon !== void 0 && { icon },
21
+ ...splash !== void 0 && { splash: checkSplashConfig(splash) }
20
22
  };
21
23
  if (plugins === void 0) return {
22
24
  appId,
@@ -1,6 +1,6 @@
1
1
  import { existsSync } from "node:fs";
2
2
  import path from "node:path";
3
- import { cp, rm } from "node:fs/promises";
3
+ import { cp, mkdir, rm, writeFile } from "node:fs/promises";
4
4
  //#region src/mobile/native-splash.ts
5
5
  /** Where @protobase/mobile, installed in the workspace `ws`, has the platform's splash files, by their native project paths. */
6
6
  const protobaseSplashDir = (ws, platform) => path.join(ws, "node_modules", "@protobase", "mobile", "splash", platform);
@@ -19,5 +19,13 @@ const removeTemplateSplash = async (ws, platform, file) => {
19
19
  if (!existsSync(at)) throw new Error(`The generated ${platform} project has no ${file}, the splash screen Protobase's replaces`);
20
20
  await rm(at, { recursive: true });
21
21
  };
22
+ /** Writes the app's own splash `files` into the platform's native project in the workspace, over Protobase's. */
23
+ const writeSplashFiles = async (ws, platform, files) => {
24
+ for (const { file, content } of files) {
25
+ const to = path.join(ws, platform, file);
26
+ await mkdir(path.dirname(to), { recursive: true });
27
+ await writeFile(to, content);
28
+ }
29
+ };
22
30
  //#endregion
23
- export { copySplashFile, protobaseSplashDir, removeTemplateSplash };
31
+ export { copySplashFile, protobaseSplashDir, removeTemplateSplash, writeSplashFiles };
@@ -19,6 +19,8 @@ import { liveUpdateSettings } from "./live-update-settings.js";
19
19
  import { loadMobileProject } from "./load-project.js";
20
20
  import { signForDevelopment } from "./development-signing.js";
21
21
  import { checkIosPlugins, checkProtobasePlugin, guardIosLiveUpdate, guardLiveUpdate } from "./protobase-plugin.js";
22
+ import { splashBackgrounds } from "./splash-backgrounds.js";
23
+ import { splashImage } from "./splash-image.js";
22
24
  import { mobileSpec, prepareWorkspace, workspaceDir, workspacePackageJson } from "./workspace.js";
23
25
  import path from "node:path";
24
26
  import { nativeFingerprint } from "@protobase/server/mobile-release";
@@ -28,10 +30,11 @@ const prepare = async ({ projectDir, platform, api, extensions, live, release },
28
30
  if (live !== void 0 && api !== void 0) throw new Error("--live opens protobase dev, which serves the API itself: leave out --api");
29
31
  const project = await loadMobileProject(projectDir, extensions);
30
32
  const mobile = checkMobileConfig(project.mobile);
31
- const splash = await splashColors(projectDir);
33
+ const theme = await splashColors(projectDir);
34
+ const splash = splashBackgrounds(mobile.splash, theme);
32
35
  const ownIcon = mobile.icon === void 0 ? void 0 : {
33
36
  file: mobile.icon,
34
- background: iconBackground(project.backgroundColor, splash)
37
+ background: iconBackground(project.backgroundColor, theme)
35
38
  };
36
39
  const url = live === void 0 ? apiUrl(api, project.auth?.issuer, platform) : new URL(`http://localhost:${live}`);
37
40
  if (release) checkReleaseUrl(url);
@@ -62,6 +65,12 @@ const prepare = async ({ projectDir, platform, api, extensions, live, release },
62
65
  platform,
63
66
  ...ownIcon
64
67
  });
68
+ const ownSplash = await splashImage({
69
+ ws,
70
+ projectDir,
71
+ splash: mobile.splash,
72
+ platform
73
+ });
65
74
  const { builtInOrder } = live === void 0 ? await buildWebPart({
66
75
  projectDir,
67
76
  ws,
@@ -102,6 +111,7 @@ const prepare = async ({ projectDir, platform, api, extensions, live, release },
102
111
  await generatePlatform(ws, platform, {
103
112
  ...allowances,
104
113
  splash,
114
+ ...ownSplash && { splashImage: ownSplash },
105
115
  ...icon && { icon },
106
116
  ...push && platform === "android" && { googleServicesFrom: projectDir },
107
117
  ...apnsEnvironment && { apnsEnvironment }
@@ -0,0 +1,21 @@
1
+ import { cssColor, opaqueHex } from "./splash-colors.js";
2
+ //#region src/mobile/splash-backgrounds.ts
3
+ const nativeColor = (text, setting) => {
4
+ const color = opaqueHex(cssColor(text));
5
+ if (!color) throw new Error(`${setting} is ${text}: the splash screen needs an opaque sRGB colour, such as #0d9488, rgb() or hsl()`);
6
+ return color;
7
+ };
8
+ /**
9
+ * The splash screen's background in light and dark mode: `mobile.splash.background` and `mobile.splash.dark.background`,
10
+ * a dark one left out taking the light one, and without either the theme's, `theme`.
11
+ */
12
+ const splashBackgrounds = (splash, theme) => {
13
+ const light = splash?.background === void 0 ? void 0 : nativeColor(splash.background, "mobile.splash.background");
14
+ const dark = splash?.dark?.background === void 0 ? void 0 : nativeColor(splash.dark.background, "mobile.splash.dark.background");
15
+ return {
16
+ light: light ?? theme.light,
17
+ dark: dark ?? light ?? theme.dark
18
+ };
19
+ };
20
+ //#endregion
21
+ export { splashBackgrounds };
@@ -0,0 +1,31 @@
1
+ //#region src/mobile/splash-config.ts
2
+ const isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
3
+ const shape = "such as { image: 'splash.png', background: '#0d9488', dark: { background: '#042f2e' } }";
4
+ const checkLook = (value, setting) => {
5
+ const { image, background } = value;
6
+ if (image !== void 0 && (typeof image !== "string" || image === "")) throw new Error(`${setting}.image must be the path of the splash image from the project's folder, such as 'splash.png'`);
7
+ if (background !== void 0 && (typeof background !== "string" || background === "")) throw new Error(`${setting}.background must be a colour, such as '#0d9488'`);
8
+ return {
9
+ ...image !== void 0 && { image },
10
+ ...background !== void 0 && { background }
11
+ };
12
+ };
13
+ /**
14
+ * The `mobile.splash` section, checked for its shape; its colours and image are checked when they are drawn. A dark
15
+ * image needs a light one, since the light launch shows the icon in a layout of its own.
16
+ */
17
+ const checkSplashConfig = (value) => {
18
+ if (!isRecord(value)) throw new Error(`mobile.splash must be an object, ${shape}`);
19
+ const { dark } = value;
20
+ if (dark !== void 0 && !isRecord(dark)) throw new Error(`mobile.splash.dark must be an object, ${shape}`);
21
+ const light = checkLook(value, "mobile.splash");
22
+ if (dark === void 0) return light;
23
+ const darkLook = checkLook(dark, "mobile.splash.dark");
24
+ if (darkLook.image !== void 0 && light.image === void 0) throw new Error("mobile.splash.dark.image needs mobile.splash.image: set the light image too");
25
+ return {
26
+ ...light,
27
+ dark: darkLook
28
+ };
29
+ };
30
+ //#endregion
31
+ export { checkSplashConfig };
@@ -0,0 +1,23 @@
1
+ import { androidSplashImage, splashSourceSize } from "./android-splash-image.js";
2
+ import { loadSharp } from "./icon-sharp.js";
3
+ import { readSquareImage } from "./icon-source.js";
4
+ import { iosSplashImage } from "./ios-splash-image.js";
5
+ //#region src/mobile/splash-image.ts
6
+ /**
7
+ * The files of the app's own splash image for the platform, `mobile.splash.image` and its dark one, drawn with the
8
+ * sharp installed in the workspace `ws`; none without an image, when the splash shows the app's icon.
9
+ */
10
+ const splashImage = async ({ ws, projectDir, splash, platform }) => {
11
+ if (splash?.image === void 0) return;
12
+ const sharp = loadSharp(ws);
13
+ const read = (file, setting) => readSquareImage(sharp, projectDir, file, {
14
+ setting,
15
+ noun: "splash image",
16
+ size: splashSourceSize
17
+ });
18
+ const light = await read(splash.image, "mobile.splash.image");
19
+ const dark = splash.dark?.image === void 0 ? void 0 : await read(splash.dark.image, "mobile.splash.dark.image");
20
+ return (platform === "android" ? androidSplashImage : iosSplashImage)(sharp, light.image, dark?.image);
21
+ };
22
+ //#endregion
23
+ export { splashImage };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@protobase/cli",
3
- "version": "0.96.7",
3
+ "version": "0.96.9",
4
4
  "description": "The protobase command: scaffold, doctor, dev, build and serve a Protobase project.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -43,13 +43,13 @@
43
43
  "dependencies": {
44
44
  "@better-auth/core": "^1.7.12",
45
45
  "@hono/node-server": "^2.1.3",
46
- "@protobase/config": "0.96.7",
47
- "@protobase/layout": "0.96.7",
48
- "@protobase/query": "0.96.7",
49
- "@protobase/schema": "0.96.7",
50
- "@protobase/server": "0.96.7",
51
- "@protobase/ui": "0.96.7",
52
- "@protobase/workflows": "0.96.7",
46
+ "@protobase/config": "0.96.9",
47
+ "@protobase/layout": "0.96.9",
48
+ "@protobase/query": "0.96.9",
49
+ "@protobase/schema": "0.96.9",
50
+ "@protobase/server": "0.96.9",
51
+ "@protobase/ui": "0.96.9",
52
+ "@protobase/workflows": "0.96.9",
53
53
  "@react-email/render": "^2.1.0",
54
54
  "@scalar/hono-api-reference": "^0.12.10",
55
55
  "@sentry/vite-plugin": "^11.10.0",
@@ -26,7 +26,7 @@ Develop, build and run an app, on servers, in containers and on phones.
26
26
  - [Container images](../guides/deploy.md#images): A runtime image for each release, for amd64 and arm64.
27
27
  - [Self-hosted image](../guides/deploy.md#a-self-hosted-image): One image with the app inside that serves, migrates and creates the first admin.
28
28
  - [Protobase Cloud deploys](../guides/deploy.md#protobase-cloud): A push to the app's GitHub branch builds it, migrates and checks its database in one transaction, and switches to the new version once it answers its health check.
29
- - [Mobile apps](../guides/mobile-app.md) (beta): Runs an app on iOS and Android, also on your own iPhone, with sign-in, and builds signed store releases from a section in its config. Your app shows its own home-screen icon on iOS and Android, generated from one image you name in your config.
29
+ - [Mobile apps](../guides/mobile-app.md) (beta): Runs an app on iOS and Android, also on your own iPhone, with sign-in, and builds signed store releases from a section in its config. Your app shows its own home-screen icon on iOS and Android, generated from one image you name in your config. It can open on a splash screen of its own, an image on a colour, in light and dark mode.
30
30
  - [Files from the phone](../guides/mobile-app.md#files-from-the-phone) (beta): In the iOS and Android app, Import and file fields open the phone's file picker, offering Excel, CSV and JSON files from the device and its cloud drives.
31
31
  - [Mobile releases](../reference/cli.md#mobile-releases) (in development): The server offers the mobile app a newer copy of its files, signed, and any host that serves bundles can offer the same from the bundle's files without running its config.
32
32
  - [Live updates](../reference/cli.md#the-live-updater) (in development): The Android and iOS app update themselves in the background to the server's release, downloading only the files that changed, switch to it when they come back after 5 minutes or more away, on the same page, and go back to the files they were built with when a release fails to start.
@@ -4,7 +4,7 @@
4
4
 
5
5
  Start a new app, or an admin over an existing Postgres database, and keep the config in step with it.
6
6
 
7
- - [Project starter](../getting-started.md#start-an-app): `npm create protobase` (also `bun create` and `pnpm create`) starts a new app from the scratch, ERP, property portal or real estate preset, with its own Postgres in Docker for development, and prints the next steps. Each preset has an `AGENTS.md` with rules for coding agents.
7
+ - [Project starter](../getting-started.md#start-an-app): `npm create protobase` (also `bun create` and `pnpm create`) starts a new app from the scratch, automations (workflows on), ERP, property portal or real estate preset, with its own Postgres in Docker for development, and prints the next steps. Each preset has an `AGENTS.md` with rules for coding agents.
8
8
  - [Start on an existing database](../getting-started.md#on-an-existing-database): `npm create protobase <database-url>` makes a project on a Postgres database you already have and asks which of its tables become resources, only reading the database.
9
9
  - [Example apps](../getting-started.md#run-the-erp-example): Seeded example apps on Postgres: an ERP, real estate property management and a public property portal.
10
10
  - [One config](../reference/config.md): The whole app is one object of data in `protobase.config.ts`, typed with `defineConfig`, with a sensible default for every key.
@@ -10,7 +10,7 @@ An app's own React code, its components, field types and actions, is a [plugin](
10
10
 
11
11
  ## Start an app
12
12
 
13
- `npm create protobase my-app` asks which preset to start from, scratch (the default), the ERP, the property portal or real estate, writes the project into `my-app`, with the `@protobase` packages in `devDependencies` at the caret range of the latest release, so it is [bundled](reference/versioning.md#bundled-and-locked-projects): dev, the build and its scripts run the CLI's own copies, and a newer CLI in that range updates it with no change to its files. It prints the next steps. Without a folder it asks for one too. `--preset <name>` picks the preset without asking; without a terminal it takes scratch. `bun create protobase` and `pnpm create protobase` do the same, and take `--preset` without the `--` that npm needs. It needs Node 22.12 or later. Each preset has an `AGENTS.md` with the rules for a coding agent that changes the app, such as a new migration file for every schema change.
13
+ `npm create protobase my-app` asks which preset to start from, scratch (the default), automations (scratch with [workflows](reference/workflows.md) on), the ERP, the property portal or real estate, writes the project into `my-app`, with the `@protobase` packages in `devDependencies` at the caret range of the latest release, so it is [bundled](reference/versioning.md#bundled-and-locked-projects): dev, the build and its scripts run the CLI's own copies, and a newer CLI in that range updates it with no change to its files. It prints the next steps. Without a folder it asks for one too. `--preset <name>` picks the preset without asking; without a terminal it takes scratch. `bun create protobase` and `pnpm create protobase` do the same, and take `--preset` without the `--` that npm needs. It needs Node 22.12 or later. Each preset has an `AGENTS.md` with the rules for a coding agent that changes the app, such as a new migration file for every schema change.
14
14
 
15
15
  ```sh
16
16
  npm create protobase my-app
@@ -37,7 +37,7 @@ export default defineConfig({
37
37
 
38
38
  The app is installed under the name it shows in its upper left, on iOS and Android alike: `protobase mobile` reads it from the server the app calls (its web manifest), so a `PROTOBASE_APP_NAME` the server runs with names the app on the phone too. When that server cannot be reached, `run` and `open` warn and take the project's own name, the config's `name` or `PROTOBASE_APP_NAME` in its environment, and `build` stops.
39
39
 
40
- On the home screen the app shows [its own icon](#the-icon), or Protobase's without one, on iOS and Android alike. While it starts, its splash screen shows that icon in the middle of the app's background: the `--background` [token](../reference/theme.md) of its `protobase.theme.css`, or the default without one, light or dark as the phone is. `protobase mobile` takes it as a colour such as `#f4f3ee`, `rgb()`, `hsl()` or `white`, and stops on one a phone's splash screen cannot show, such as `oklch()` or `var()`.
40
+ On the home screen the app shows [its own icon](#the-icon), or Protobase's without one, on iOS and Android alike. While it starts, its [splash screen](#the-splash-screen) shows that icon in the middle of the app's background, unless you set one of its own: the `--background` [token](../reference/theme.md) of its `protobase.theme.css`, or the default without one, light or dark as the phone is. `protobase mobile` takes it as a colour such as `#f4f3ee`, `rgb()`, `hsl()` or `white`, and stops on one a phone's splash screen cannot show, such as `oklch()` or `var()`.
41
41
 
42
42
  With a mobile section, the API answers the app's origins, `capacitor://localhost` on iOS and `https://localhost` on Android, through [CORS](../reference/api.md#cors). Apps without one get no new dependency, and `protobase build` and `protobase dev` work as before.
43
43
 
@@ -66,6 +66,24 @@ mobile: { appId: 'com.example.shop', icon: 'icon.png' },
66
66
 
67
67
  Changing the icon takes a new store release: a [live update](#7-live-updates) does not change it.
68
68
 
69
+ ### The splash screen
70
+
71
+ Set a splash image and background colour in the mobile section, with dark-mode values if you like, and the app opens on that image in the middle of that colour, on iOS and Android alike. Without them it opens on its icon over its theme background.
72
+
73
+ ```ts
74
+ mobile: {
75
+ appId: 'com.example.shop',
76
+ splash: { image: 'splash.png', background: '#0d9488', dark: { image: 'splash-dark.png', background: '#042f2e' } },
77
+ },
78
+ ```
79
+
80
+ - `image` is a path from the project's folder to a square PNG of at least 1152 × 1152 pixels, or a square SVG. Android shows it at 288 dp and only its middle circle, two thirds of its side across, so keep everything you want seen within that circle; iOS shows the same circle. `protobase mobile` stops on a missing file, any other format, an image that is not square or a smaller PNG, naming the setting.
81
+ - `background` is an opaque colour such as `#0d9488`, `rgb()` or `hsl()`; `protobase mobile` stops on any other, naming the setting.
82
+ - `dark` holds the image and background for dark mode. One left out there takes the light one, so a single image and colour serve both. A dark image needs a light one.
83
+ - Each is optional: an image without a background sits on the theme background, and a background without an image shows the icon on it.
84
+
85
+ The splash image is a centred image, not full-screen artwork, as that is all Android's splash screen shows. Changing it takes a new store release: a [live update](#7-live-updates) does not change it.
86
+
69
87
  ## 3. Run it
70
88
 
71
89
  ```sh
@@ -98,7 +98,7 @@ export default defineConfig({ backgroundColor: '#ffffff' })
98
98
 
99
99
  ## mobile
100
100
 
101
- - **Type:** `{ appId: string; plugins?: Record<string, string>; publicKey?: string; icon?: string }`
101
+ - **Type:** `{ appId: string; plugins?: Record<string, string>; publicKey?: string; icon?: string; splash?: { image?: string; background?: string; dark?: { image?: string; background?: string } } }`
102
102
 
103
103
  The app's iOS and Android build: with it, `protobase mobile` builds the app with Capacitor, and the API also allows the app's Capacitor origins (`capacitor://localhost`, `https://localhost`) for [CORS](api.md#cors). See [A mobile app](../../guides/mobile-app.md).
104
104
 
@@ -106,6 +106,7 @@ The app's iOS and Android build: with it, `protobase mobile` builds the app with
106
106
  - `plugins`: extra native Capacitor plugins, by npm name and version range. A range fetched over plain `http:` or `git:` is refused.
107
107
  - `publicKey`: the public key, PEM, of the RSA key the server signs the app's [releases](../cli.md#the-live-updater) with, from [`protobase mobile keys`](../cli.md#mobile): with it the Android and iOS app update themselves. Anything but an RSA public key of at least 2048 bits stops the build.
108
108
  - `icon`: the app's [home-screen icon](../../guides/mobile-app.md#the-icon), a path from the project's folder to a square PNG of at least 1024 × 1024 pixels or a square SVG, from which `protobase mobile` makes every iOS and Android icon. Without it the app shows Protobase's icon.
109
+ - `splash`: the app's own [splash screen](../../guides/mobile-app.md#the-splash-screen), an `image` centred on a `background` colour, with `dark` values for dark mode, each optional. Without it the app opens on its icon over its theme background.
109
110
 
110
111
  ```ts
111
112
  export default defineConfig({