@protobase/cli 0.49.1 → 0.50.0
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/bin/protobase.mjs +3 -2
- package/dist/build/config-bundle.js +1 -1
- package/dist/build/deploy-bundle.js +3 -4
- package/dist/build/plugin-build.js +16 -8
- package/dist/build/plugin-fields.js +5 -2
- package/dist/build/ui-check.js +5 -0
- package/dist/build/view-check.js +1 -1
- package/dist/cli/package.js +1 -1
- package/dist/config/build-project.js +13 -6
- package/dist/config/project-files.js +4 -1
- package/dist/config/read-config.js +5 -1
- package/dist/config/source-config.js +1 -1
- package/dist/db/read-only-db.js +1 -1
- package/dist/dev/api-process.js +1 -1
- package/dist/dev/app-server.js +43 -35
- package/dist/dev/create-db.js +2 -2
- package/dist/dev/dev-jobs.js +5 -3
- package/dist/dev/entry.js +3 -3
- package/dist/dev/project.js +3 -2
- package/dist/dev/server-package.js +9 -21
- package/dist/doctor/run.js +1 -1
- package/dist/hand-over.d.ts +15 -0
- package/dist/hand-over.js +32 -0
- package/dist/main.js +22 -5
- package/dist/migration/load-project.js +1 -1
- package/dist/project/bundled-imports.js +41 -0
- package/dist/project/import-project-file.js +28 -8
- package/dist/project/load-bundle-project.js +1 -1
- package/dist/project/load-data-config.js +4 -3
- package/dist/project/project-types.js +66 -0
- package/dist/project-auth.d.ts +2 -0
- package/dist/project-auth.js +2 -0
- package/dist/run/preload.d.ts +1 -0
- package/dist/run/preload.js +20 -0
- package/dist/run/run-script.js +36 -0
- package/dist/serve/app.js +1 -1
- package/dist/serve/create-admin.js +1 -1
- package/dist/serve/host-modules.js +3 -3
- package/dist/serve/lifecycle.js +4 -3
- package/dist/supabase/load-phase.js +6 -5
- package/dist/users/load-auth.d.ts +10 -0
- package/dist/users/load-auth.js +1 -1
- package/dist/version/project-packages.js +39 -0
- package/dist/version/project-version.js +33 -12
- package/dist/worker/start-worker.js +3 -2
- package/package.json +10 -8
- package/skills/protobase/SKILL.md +1 -1
- package/skills/protobase/references/features/build-and-run.md +3 -0
- package/skills/protobase/references/features/events-webhooks-and-jobs.md +1 -0
- package/skills/protobase/references/features/files-and-images.md +1 -0
- package/skills/protobase/references/features/releases.md +2 -1
- package/skills/protobase/references/features/sign-in-and-accounts.md +1 -0
- package/skills/protobase/references/features/start-a-project.md +1 -1
- package/skills/protobase/references/getting-started.md +18 -5
- package/skills/protobase/references/guides/api-functions.md +1 -1
- package/skills/protobase/references/guides/billing-page.md +4 -4
- package/skills/protobase/references/guides/create-page.md +2 -2
- package/skills/protobase/references/guides/deploy.md +24 -8
- package/skills/protobase/references/guides/field-type.md +1 -1
- package/skills/protobase/references/guides/first-plugin.md +1 -1
- package/skills/protobase/references/guides/plugin-build.md +1 -1
- package/skills/protobase/references/guides/remote-resources.md +1 -1
- package/skills/protobase/references/guides/table-to-admin.md +8 -8
- package/skills/protobase/references/reference/ai.md +1 -1
- package/skills/protobase/references/reference/api.md +4 -4
- package/skills/protobase/references/reference/architecture.md +11 -6
- package/skills/protobase/references/reference/assistant.md +1 -1
- package/skills/protobase/references/reference/auth.md +24 -6
- package/skills/protobase/references/reference/blocks.md +1 -1
- package/skills/protobase/references/reference/bottom-bar.md +2 -2
- package/skills/protobase/references/reference/cli.md +51 -22
- package/skills/protobase/references/reference/client.md +3 -1
- package/skills/protobase/references/reference/config/api.md +2 -2
- package/skills/protobase/references/reference/config/app.md +2 -2
- package/skills/protobase/references/reference/config/sign-in.md +3 -4
- package/skills/protobase/references/reference/config.md +13 -10
- package/skills/protobase/references/reference/custom-components.md +3 -2
- package/skills/protobase/references/reference/email.md +5 -5
- package/skills/protobase/references/reference/events.md +1 -1
- package/skills/protobase/references/reference/files.md +6 -3
- package/skills/protobase/references/reference/jobs.md +20 -10
- package/skills/protobase/references/reference/layouts.md +2 -2
- package/skills/protobase/references/reference/mcp.md +9 -8
- package/skills/protobase/references/reference/notifications.md +10 -8
- package/skills/protobase/references/reference/plugins.md +3 -3
- package/skills/protobase/references/reference/ui-config.md +1 -1
- package/skills/protobase/references/reference/user-menu.md +3 -3
- package/skills/protobase/references/reference/versioning.md +21 -4
- package/skills/protobase/references/reference/webhooks.md +5 -5
package/bin/protobase.mjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import {
|
|
2
|
+
import { fileURLToPath } from 'node:url'
|
|
3
|
+
import { runHandingOver } from '../dist/hand-over.js'
|
|
3
4
|
|
|
4
|
-
await run
|
|
5
|
+
await runHandingOver(fileURLToPath(new URL('..', import.meta.url)), async () => (await import('../dist/index.js')).run, process.argv)
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { findPackageDir, packageName } from "./packages/package-dir.js";
|
|
2
|
+
import { hostModuleIds } from "../serve/host-module-ids.js";
|
|
2
3
|
import { loadSourceConfig } from "../config/source-config.js";
|
|
3
4
|
import { layoutCheck } from "./layout-check.js";
|
|
4
5
|
import { extensionImports } from "../project/extensions.js";
|
|
5
6
|
import { viteBundle } from "./vite-bundle.js";
|
|
6
|
-
import { hostModuleIds } from "../serve/host-module-ids.js";
|
|
7
7
|
import { collectComponents } from "./component-names.js";
|
|
8
8
|
import { bundleEntryCode } from "./entry-code.js";
|
|
9
9
|
import { hostPackages } from "./packages/host-packages.js";
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { bundleProtobaseVersion } from "../version/project-version.js";
|
|
2
2
|
import { buildIcons } from "./app-icons.js";
|
|
3
3
|
import { bundleLayout, bundleMigrations, bundleNodeModules, manifestFile } from "../bundle/manifest.js";
|
|
4
|
+
import { protobaseFolder } from "../project/protobase-folder.js";
|
|
4
5
|
import { buildBundlePlugins } from "./bundle-plugins.js";
|
|
5
6
|
import { copyMigrations } from "./bundle-migrations.js";
|
|
6
7
|
import { buildConfigBundle } from "./config-bundle.js";
|
|
@@ -9,7 +10,6 @@ import { buildTheme } from "./theme.js";
|
|
|
9
10
|
import { shellForBuild, shellManifestFile } from "./shell.js";
|
|
10
11
|
import { checkUi } from "./ui-check.js";
|
|
11
12
|
import { checkViews } from "./view-check.js";
|
|
12
|
-
import { protobaseFolder } from "../project/protobase-folder.js";
|
|
13
13
|
import { pinnedNative } from "../mobile/pinned-packages.js";
|
|
14
14
|
import { existsSync } from "node:fs";
|
|
15
15
|
import path from "node:path";
|
|
@@ -46,8 +46,7 @@ const copyShell = async (publicDir, sourceMaps) => {
|
|
|
46
46
|
return shell;
|
|
47
47
|
};
|
|
48
48
|
const buildDeployBundle = async ({ projectDir, outDir, bun, extensions = [], sourceMaps = false, onWarning }) => {
|
|
49
|
-
const protobase =
|
|
50
|
-
if (protobase === void 0) throw new Error(`${projectDir} has no @protobase packages installed; install the project's dependencies first`);
|
|
49
|
+
const protobase = bundleProtobaseVersion(projectDir);
|
|
51
50
|
await removeOwnFolder(outDir, bundleNodeModules, "nodeModules");
|
|
52
51
|
await removeOwnFolder(outDir, bundleMigrations, "migrations");
|
|
53
52
|
const components = /* @__PURE__ */ new Set();
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { findPackageDirSync, readPackageJson } from "./packages/package-dir.js";
|
|
2
|
+
import { projectPackages } from "../version/project-packages.js";
|
|
2
3
|
import { uiPackageDir } from "../project/admin-app.js";
|
|
3
4
|
import { extensionImports } from "../project/extensions.js";
|
|
5
|
+
import { bundledImports } from "../project/bundled-imports.js";
|
|
4
6
|
import { sharedModules } from "../project/shared-modules.js";
|
|
5
7
|
import { pluginFieldTypes } from "./plugin-fields.js";
|
|
6
8
|
import { layerPluginUtilities } from "./plugin-styles.js";
|
|
@@ -18,14 +20,17 @@ const pluginEntryFile = "protobase.ui.tsx";
|
|
|
18
20
|
/** What `build-plugin` writes beside the plugin's files, which the app reads first. */
|
|
19
21
|
const pluginManifestFile = "plugin.json";
|
|
20
22
|
const tailwindDir = path.dirname(createRequire(path.join(uiPackageDir, "package.json")).resolve("tailwindcss/package.json"));
|
|
23
|
+
const targetUiDir = (pluginDir, projectDir, bundled) => {
|
|
24
|
+
if (bundled) return uiPackageDir;
|
|
25
|
+
return findPackageDirSync("@protobase/ui", pluginDir) ?? (projectDir === void 0 ? void 0 : findPackageDirSync("@protobase/ui", projectDir)) ?? uiPackageDir;
|
|
26
|
+
};
|
|
21
27
|
/**
|
|
22
|
-
* What the plugin is built for, from
|
|
23
|
-
*
|
|
24
|
-
*
|
|
28
|
+
* What the plugin is built for, from its @protobase/ui (see `targetUiDir`): its plugin API, and Protobase from its
|
|
29
|
+
* version on, unless the plugin's package.json names other versions in `engines.protobase`. Also that version's theme,
|
|
30
|
+
* which the plugin's stylesheet draws with, and its folder.
|
|
25
31
|
*/
|
|
26
|
-
const pluginTarget = async (pluginDir, own, projectDir) => {
|
|
27
|
-
const uiDir =
|
|
28
|
-
if (!uiDir) throw new Error(`@protobase/ui is not installed for ${pluginDir}; add it to the plugin's dependencies, as the version it is built for`);
|
|
32
|
+
const pluginTarget = async (pluginDir, own, projectDir, bundled) => {
|
|
33
|
+
const uiDir = targetUiDir(pluginDir, projectDir, bundled);
|
|
29
34
|
const ui = await readPackageJson(uiDir);
|
|
30
35
|
const api = ui.protobase?.pluginApi;
|
|
31
36
|
const theme = ui.exports?.["./theme.css"];
|
|
@@ -96,7 +101,8 @@ const buildPlugin = async ({ pluginDir, outDir, name, projectDir, ignore = [], s
|
|
|
96
101
|
const own = existsSync(path.join(pluginDir, "package.json")) ? await readPackageJson(pluginDir) : {};
|
|
97
102
|
const pluginName = (name ?? own.name ?? path.basename(pluginDir)).trim();
|
|
98
103
|
if (pluginName === "") throw new Error("The plugin needs a name: give its package.json a name, or pass --name");
|
|
99
|
-
const
|
|
104
|
+
const bundled = projectDir !== void 0 && projectPackages(projectDir).mode === "bundled";
|
|
105
|
+
const target = await pluginTarget(pluginDir, own, projectDir, bundled);
|
|
100
106
|
const styles = path.join(pluginDir, "protobase-plugin.css");
|
|
101
107
|
const nodeEnv = process.env.NODE_ENV;
|
|
102
108
|
process.env.NODE_ENV = "production";
|
|
@@ -109,6 +115,7 @@ const buildPlugin = async ({ pluginDir, outDir, name, projectDir, ignore = [], s
|
|
|
109
115
|
logLevel: "warn",
|
|
110
116
|
plugins: [
|
|
111
117
|
pluginImports(),
|
|
118
|
+
...bundled ? [bundledImports([projectDir, pluginDir])] : [],
|
|
112
119
|
...projectDir === void 0 ? [] : [extensionImports(projectDir, [{ dir: pluginDir }])],
|
|
113
120
|
pluginStyles(styles, styleCode(pluginDir, target.theme, [outDir, ...ignore])),
|
|
114
121
|
react(),
|
|
@@ -147,7 +154,8 @@ const buildPlugin = async ({ pluginDir, outDir, name, projectDir, ignore = [], s
|
|
|
147
154
|
pluginDir,
|
|
148
155
|
entry,
|
|
149
156
|
uiDir: target.uiDir,
|
|
150
|
-
projectDir
|
|
157
|
+
projectDir,
|
|
158
|
+
bundled
|
|
151
159
|
});
|
|
152
160
|
const manifest = {
|
|
153
161
|
name: pluginName,
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { extensionImports } from "../project/extensions.js";
|
|
2
|
+
import { bundledImports } from "../project/bundled-imports.js";
|
|
2
3
|
import { sharedModules } from "../project/shared-modules.js";
|
|
3
4
|
import { viteBundle } from "./vite-bundle.js";
|
|
4
5
|
import { createRequire } from "node:module";
|
|
@@ -31,9 +32,10 @@ const isStorageTypes = (value) => Array.isArray(value) && value.every((item) =>
|
|
|
31
32
|
/**
|
|
32
33
|
* The field types a plugin registers (`definePlugin({ fields })`), each with the storage types it shows (`of`), which
|
|
33
34
|
* the server checks the views against at startup. The plugin's module is loaded once in Node, everything bundled into
|
|
34
|
-
* a scratch file, as `protobase build` loads a project's UI to check its names; nothing is rendered.
|
|
35
|
+
* a scratch file, as `protobase build` loads a project's UI to check its names; nothing is rendered. A plugin of a
|
|
36
|
+
* bundled project imports the CLI's @protobase packages, as its build does.
|
|
35
37
|
*/
|
|
36
|
-
const pluginFieldTypes = async ({ pluginDir, entry, uiDir, projectDir }) => {
|
|
38
|
+
const pluginFieldTypes = async ({ pluginDir, entry, uiDir, projectDir, bundled = false }) => {
|
|
37
39
|
const file = path.join(pluginDir, "protobase-plugin-fields.js");
|
|
38
40
|
const scratch = await mkdtemp(path.join(tmpdir(), "protobase-plugin-fields-"));
|
|
39
41
|
const outFile = path.join(scratch, "fields.mjs");
|
|
@@ -41,6 +43,7 @@ const pluginFieldTypes = async ({ pluginDir, entry, uiDir, projectDir }) => {
|
|
|
41
43
|
const plugins = [
|
|
42
44
|
fieldsEntry(file, fieldsCode(entry)),
|
|
43
45
|
sharedFromUi(uiDir),
|
|
46
|
+
...bundled && projectDir !== void 0 ? [bundledImports([projectDir, pluginDir])] : [],
|
|
44
47
|
...projectDir === void 0 ? [] : [extensionImports(projectDir, [{ dir: pluginDir }])]
|
|
45
48
|
];
|
|
46
49
|
await viteBundle({
|
package/dist/build/ui-check.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import { projectPackages } from "../version/project-packages.js";
|
|
1
2
|
import { extensionImports } from "../project/extensions.js";
|
|
2
3
|
import { projectUiFile, projectUiId, projectUiPlugin } from "../project/project-ui.js";
|
|
4
|
+
import { bundledImports } from "../project/bundled-imports.js";
|
|
3
5
|
import { viteBundle } from "./vite-bundle.js";
|
|
4
6
|
import { existsSync } from "node:fs";
|
|
5
7
|
import path from "node:path";
|
|
@@ -24,9 +26,12 @@ const registeredComponents = async (projectDir, extensions) => {
|
|
|
24
26
|
const scratch = await mkdtemp(path.join(tmpdir(), "protobase-ui-check-"));
|
|
25
27
|
const outFile = path.join(scratch, "ui-check.mjs");
|
|
26
28
|
try {
|
|
29
|
+
const bundled = projectPackages(projectDir).mode === "bundled";
|
|
30
|
+
const projectDirs = [projectDir, ...extensions.map((extension) => extension.dir)];
|
|
27
31
|
const plugins = [
|
|
28
32
|
checkEntry(checkFile(projectDir)),
|
|
29
33
|
projectUiPlugin(projectDir, extensions),
|
|
34
|
+
...bundled ? [bundledImports(projectDirs)] : [],
|
|
30
35
|
extensionImports(projectDir, extensions)
|
|
31
36
|
];
|
|
32
37
|
await viteBundle({
|
package/dist/build/view-check.js
CHANGED
|
@@ -11,7 +11,7 @@ import { checkViewQueries } from "@protobase/server";
|
|
|
11
11
|
const checkViews = async (projectDir) => {
|
|
12
12
|
const configDir = path.join(projectDir, "config");
|
|
13
13
|
if (!existsSync(path.join(configDir, "index.ts"))) return;
|
|
14
|
-
const { models, views } = await loadDataConfig(configDir);
|
|
14
|
+
const { models, views } = await loadDataConfig(configDir, projectDir);
|
|
15
15
|
checkViewQueries(models, views);
|
|
16
16
|
};
|
|
17
17
|
//#endregion
|
package/dist/cli/package.js
CHANGED
|
@@ -2,8 +2,13 @@ import { projectFiles, projectFunctions, projectJobs, projectNotifications, proj
|
|
|
2
2
|
import { buildAppAuth, buildAuthenticator } from "@protobase/server/internal";
|
|
3
3
|
//#region src/config/build-project.ts
|
|
4
4
|
/**
|
|
5
|
+
* The app's own mailer, the default export of its auth/mailer.ts: what sign-in and the jobs (`context.mail`) both send
|
|
6
|
+
* with; `undefined` without one, when both send through `PROTOBASE_SMTP_URL`.
|
|
7
|
+
*/
|
|
8
|
+
const projectMailer = async (config) => (await config.authFiles?.module("auth/mailer.ts")?.())?.default;
|
|
9
|
+
/**
|
|
5
10
|
* The app's sign-in, built from `auth` with the app's URL, secrets, signing key rotation and name, the hooks of its
|
|
6
|
-
* auth/hooks.ts and the
|
|
11
|
+
* auth/hooks.ts and the app's mailer when it has them; none without `auth`.
|
|
7
12
|
*/
|
|
8
13
|
const projectAuth = async (config, { db, pool }) => {
|
|
9
14
|
if (!config.auth) return void 0;
|
|
@@ -11,7 +16,7 @@ const projectAuth = async (config, { db, pool }) => {
|
|
|
11
16
|
const { url, secret, previousSecrets, signingKeyDays, signingKeyGraceDays, name } = config;
|
|
12
17
|
if (!url) throw new Error("Sign-in needs the app's public URL: set PROTOBASE_URL, such as https://admin.example.com, or url in protobase.config.ts");
|
|
13
18
|
if (!secret) throw new Error("Sign-in needs the app's secret: set PROTOBASE_SECRET to the output of `openssl rand -base64 32`, or secret in protobase.config.ts");
|
|
14
|
-
const [hooks, mailer] = await Promise.all(["auth/hooks.ts"
|
|
19
|
+
const [hooks, mailer] = await Promise.all([config.authFiles?.module("auth/hooks.ts")?.(), projectMailer(config)]);
|
|
15
20
|
return buildAppAuth({
|
|
16
21
|
...config.auth || {},
|
|
17
22
|
baseURL: url,
|
|
@@ -24,7 +29,7 @@ const projectAuth = async (config, { db, pool }) => {
|
|
|
24
29
|
pool,
|
|
25
30
|
db,
|
|
26
31
|
...hooks && { hooks },
|
|
27
|
-
...mailer && { mailer
|
|
32
|
+
...mailer && { mailer }
|
|
28
33
|
});
|
|
29
34
|
};
|
|
30
35
|
/**
|
|
@@ -38,14 +43,15 @@ const projectAuthenticate = async (config, auth) => {
|
|
|
38
43
|
};
|
|
39
44
|
/** The app, built from its merged config over its database: every reference loaded, auth and the authenticator made. */
|
|
40
45
|
const buildProject = async (config, database) => {
|
|
41
|
-
const [resources, functions, files, options, auth, webhooks, notifications] = await Promise.all([
|
|
46
|
+
const [resources, functions, files, options, auth, webhooks, notifications, mailer] = await Promise.all([
|
|
42
47
|
projectResources(config),
|
|
43
48
|
projectFunctions(config),
|
|
44
49
|
projectFiles(config),
|
|
45
50
|
projectOptions(config),
|
|
46
51
|
projectAuth(config, database),
|
|
47
52
|
projectWebhooks(config),
|
|
48
|
-
projectNotifications(config)
|
|
53
|
+
projectNotifications(config),
|
|
54
|
+
projectMailer(config)
|
|
49
55
|
]);
|
|
50
56
|
const jobs = projectJobs(config);
|
|
51
57
|
const identity = config.themeColor || config.backgroundColor ? {
|
|
@@ -63,6 +69,7 @@ const buildProject = async (config, database) => {
|
|
|
63
69
|
...config.history && { history: config.history },
|
|
64
70
|
...webhooks && { webhooks },
|
|
65
71
|
...notifications && { notifications },
|
|
72
|
+
...mailer && { mailer },
|
|
66
73
|
...config.mobile && { mobile: config.mobile },
|
|
67
74
|
...config.secret && { secret: config.secret },
|
|
68
75
|
...identity && { app: identity },
|
|
@@ -70,4 +77,4 @@ const buildProject = async (config, database) => {
|
|
|
70
77
|
};
|
|
71
78
|
};
|
|
72
79
|
//#endregion
|
|
73
|
-
export { buildProject, projectAuth, projectAuthenticate };
|
|
80
|
+
export { buildProject, projectAuth, projectAuthenticate, projectMailer };
|
|
@@ -41,7 +41,10 @@ const sourceFiles = (projectDir, importModules) => {
|
|
|
41
41
|
} },
|
|
42
42
|
functions: Object.fromEntries(functionFiles(projectDir).map(({ name, file }) => [name, one(file)])),
|
|
43
43
|
module: (file) => existsSync(path.join(projectDir, file)) ? one(path.join(projectDir, file)) : void 0,
|
|
44
|
-
package: (name) => import(
|
|
44
|
+
package: (name) => import(
|
|
45
|
+
/* @vite-ignore */
|
|
46
|
+
pathToFileURL(createRequire(path.join(projectDir, "package.json")).resolve(name)).href
|
|
47
|
+
)
|
|
45
48
|
};
|
|
46
49
|
};
|
|
47
50
|
//#endregion
|
|
@@ -22,9 +22,13 @@ const typescriptInput = async (file, importModules) => {
|
|
|
22
22
|
if (module.default === void 0) throw new Error(`${file} has no default export: export default defineConfig({ ... })`);
|
|
23
23
|
return module.default;
|
|
24
24
|
};
|
|
25
|
+
const jsonInput = async (file) => {
|
|
26
|
+
const { $schema: _, ...config } = JSON.parse(await readFile(file, "utf8"));
|
|
27
|
+
return config;
|
|
28
|
+
};
|
|
25
29
|
/** The config of a config file: a JSON object, or a TypeScript module's default export, called with `configEnv`. */
|
|
26
30
|
const readConfigFile = async (file, configEnv, importModules) => {
|
|
27
|
-
const input = file.endsWith(".json") ?
|
|
31
|
+
const input = file.endsWith(".json") ? await jsonInput(file) : await typescriptInput(file, importModules);
|
|
28
32
|
return calledConfig(input, configEnv, path.basename(file));
|
|
29
33
|
};
|
|
30
34
|
//#endregion
|
|
@@ -10,7 +10,7 @@ import path from "node:path";
|
|
|
10
10
|
* extensions' configs, with the code each folder's conventions find. Only the config files run here; that code loads
|
|
11
11
|
* when a command asks for it.
|
|
12
12
|
*/
|
|
13
|
-
const loadSourceConfig = async (dir, { command, extensions = [], importModules = importProjectFiles }) => {
|
|
13
|
+
const loadSourceConfig = async (dir, { command, extensions = [], importModules = (files) => importProjectFiles(files, dir) }) => {
|
|
14
14
|
const configEnv = {
|
|
15
15
|
command,
|
|
16
16
|
env: process.env,
|
package/dist/db/read-only-db.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Kysely, PostgresDialect } from "kysely";
|
|
2
1
|
import pg from "pg";
|
|
2
|
+
import { Kysely, PostgresDialect } from "kysely";
|
|
3
3
|
//#region src/db/read-only-db.ts
|
|
4
4
|
/** Kysely over one read-only session, for what the query package reads of the database, as the server reads it. */
|
|
5
5
|
const readOnlyDb = (url) => new Kysely({ dialect: new PostgresDialect({ pool: new pg.Pool({
|
package/dist/dev/api-process.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { errorMessage } from "../error-message.js";
|
|
2
|
+
import { serverPackage } from "./server-package.js";
|
|
2
3
|
import { moduleFile } from "../module-file.js";
|
|
3
4
|
import { createApiVite } from "./api-vite.js";
|
|
4
5
|
import { devHost } from "./loopback.js";
|
|
5
6
|
import { isProjectFile } from "./project-files.js";
|
|
6
|
-
import { serverPackage } from "./server-package.js";
|
|
7
7
|
import { startupLogger } from "./startup-logger.js";
|
|
8
8
|
import { createAdaptorServer } from "@hono/node-server";
|
|
9
9
|
//#region src/dev/api-process.ts
|
package/dist/dev/app-server.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
import { projectPackages } from "../version/project-packages.js";
|
|
1
2
|
import { uiPackageDir } from "../project/admin-app.js";
|
|
2
3
|
import { layoutCheck } from "../build/layout-check.js";
|
|
3
4
|
import { extensionImports, extensionStyles } from "../project/extensions.js";
|
|
4
5
|
import { devHost } from "./loopback.js";
|
|
5
6
|
import { frameHeaders } from "../serve/static-site.js";
|
|
6
7
|
import { projectUiPlugin } from "../project/project-ui.js";
|
|
8
|
+
import { bundledImports, bundledPackageDirs } from "../project/bundled-imports.js";
|
|
7
9
|
import { sharedModulesPlugin } from "../project/shared-modules.js";
|
|
8
10
|
import { faviconLink } from "../project/favicon-link.js";
|
|
9
11
|
import { themeLink } from "../project/theme-link.js";
|
|
@@ -30,41 +32,47 @@ const appDependencies = [
|
|
|
30
32
|
];
|
|
31
33
|
/**
|
|
32
34
|
* The Vite server of `protobase dev` that serves the admin app from `appDir`, with the project's UI, theme and icons,
|
|
33
|
-
* on `port`; `plugins` come first, such as the one that hands the API's requests to its process.
|
|
35
|
+
* on `port`; `plugins` come first, such as the one that hands the API's requests to its process. A bundled project's
|
|
36
|
+
* page code gets the admin app's own @protobase packages and React.
|
|
34
37
|
*/
|
|
35
|
-
const createAppServer = (options, plugins) =>
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
38
|
+
const createAppServer = (options, plugins) => {
|
|
39
|
+
const projectDirs = [options.projectDir, ...options.extensions.map((extension) => extension.dir)];
|
|
40
|
+
const bundled = projectPackages(options.projectDir).mode === "bundled";
|
|
41
|
+
return createServer({
|
|
42
|
+
root: options.appDir,
|
|
43
|
+
configFile: false,
|
|
44
|
+
...options.cacheDir && { cacheDir: options.cacheDir },
|
|
45
|
+
optimizeDeps: {
|
|
46
|
+
include: appDependencies,
|
|
47
|
+
exclude: ["@protobase/ui"]
|
|
48
|
+
},
|
|
49
|
+
server: {
|
|
50
|
+
headers: frameHeaders,
|
|
51
|
+
host: devHost,
|
|
52
|
+
port: options.port,
|
|
53
|
+
strictPort: true,
|
|
54
|
+
...options.allowedHosts.length > 0 && { allowedHosts: options.allowedHosts },
|
|
55
|
+
fs: { allow: [
|
|
56
|
+
searchForWorkspaceRoot(options.projectDir),
|
|
57
|
+
uiPackageDir,
|
|
58
|
+
...projectDirs,
|
|
59
|
+
...bundled ? bundledPackageDirs() : []
|
|
60
|
+
] }
|
|
61
|
+
},
|
|
62
|
+
plugins: [
|
|
63
|
+
...plugins,
|
|
64
|
+
sharedModulesPlugin(),
|
|
65
|
+
themeLink(options.projectDir),
|
|
66
|
+
faviconLink(options.projectDir),
|
|
67
|
+
projectUiPlugin(options.projectDir, options.extensions),
|
|
68
|
+
...bundled ? [bundledImports(projectDirs)] : [],
|
|
69
|
+
extensionImports(options.projectDir, options.extensions),
|
|
70
|
+
extensionStyles(options.extensions),
|
|
71
|
+
layoutCheck(),
|
|
72
|
+
react(),
|
|
73
|
+
tailwindcss()
|
|
74
|
+
]
|
|
75
|
+
});
|
|
76
|
+
};
|
|
69
77
|
//#endregion
|
|
70
78
|
export { createAppServer };
|
package/dist/dev/create-db.js
CHANGED
|
@@ -2,10 +2,10 @@ import { openAppDatabase } from "../project/pg-db.js";
|
|
|
2
2
|
import { createRequire } from "node:module";
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
//#region src/dev/create-db.ts
|
|
5
|
-
const sharedDb = (
|
|
5
|
+
const sharedDb = (packagesDir, url) => {
|
|
6
6
|
const store = globalThis;
|
|
7
7
|
if (store.__protobaseDb) return store.__protobaseDb;
|
|
8
|
-
const load = createRequire(path.join(
|
|
8
|
+
const load = createRequire(path.join(packagesDir, "package.json"));
|
|
9
9
|
store.__protobaseDb = openAppDatabase(load("pg"), url);
|
|
10
10
|
return store.__protobaseDb;
|
|
11
11
|
};
|
package/dist/dev/dev-jobs.js
CHANGED
|
@@ -2,16 +2,18 @@ import { checkJobsSchema, startJobs } from "@protobase/server";
|
|
|
2
2
|
//#region src/dev/dev-jobs.ts
|
|
3
3
|
const store = globalThis;
|
|
4
4
|
/**
|
|
5
|
-
* Runs the project's jobs in the dev server: started on the first load, once the jobs schema checks out,
|
|
6
|
-
* reloaded definitions on every load after it, so an edited job runs its new
|
|
5
|
+
* Runs the project's jobs in the dev server: started on the first load, once the jobs schema checks out, with the app's
|
|
6
|
+
* own mailer when it has one, and given the reloaded definitions on every load after it, so an edited job runs its new
|
|
7
|
+
* code from the next job on. A mailer added or changed later is the jobs' from the next start.
|
|
7
8
|
*/
|
|
8
|
-
const devJobs = async (db, definitions) => {
|
|
9
|
+
const devJobs = async (db, definitions, mailer) => {
|
|
9
10
|
if (store.__protobaseJobs) return store.__protobaseJobs.update(definitions);
|
|
10
11
|
if (definitions.length === 0) return;
|
|
11
12
|
await checkJobsSchema(db);
|
|
12
13
|
store.__protobaseJobs = await startJobs({
|
|
13
14
|
db,
|
|
14
15
|
jobs: definitions,
|
|
16
|
+
...mailer && { mailer },
|
|
15
17
|
onError: (error) => console.error(error)
|
|
16
18
|
});
|
|
17
19
|
};
|
package/dist/dev/entry.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
+
import { buildProject } from "../config/build-project.js";
|
|
1
2
|
import { projectIcons } from "../build/app-icons.js";
|
|
2
3
|
import { projectErrorReporter } from "../project/error-reporter.js";
|
|
3
4
|
import { projectAdmin } from "../project/project-admin.js";
|
|
4
|
-
import { buildProject } from "../config/build-project.js";
|
|
5
5
|
import { devJobs } from "./dev-jobs.js";
|
|
6
6
|
import { devDatabase, loadDevConfig } from "./project.js";
|
|
7
7
|
import { withDevServiceWorker } from "./service-worker-route.js";
|
|
8
8
|
import { setMissing, supabaseEnv } from "./supabase-env.js";
|
|
9
|
+
import { apiKeySettings, assistantSettings, authSchemaDrift, authStoreTables, checkAi, checkAuthSchema, checkChanges, checkComments, checkComputed, checkNotificationsSchema, checkQueryRunner, checkResourcesOutsideAuthStore, checkWebhooksSchema, configExports, hasUsers } from "@protobase/server";
|
|
9
10
|
import { upgradeWebSocket } from "@hono/node-server";
|
|
10
11
|
import { Hono } from "hono";
|
|
11
|
-
import { apiKeySettings, assistantSettings, authSchemaDrift, authStoreTables, checkAi, checkAuthSchema, checkChanges, checkComments, checkComputed, checkNotificationsSchema, checkQueryRunner, checkResourcesOutsideAuthStore, checkWebhooksSchema, configExports, hasUsers } from "@protobase/server";
|
|
12
12
|
//#region src/dev/entry.ts
|
|
13
13
|
const projectDir = process.env.PROTOBASE_PROJECT;
|
|
14
14
|
const config = await loadDevConfig(projectDir, JSON.parse(process.env.PROTOBASE_EXTENSIONS ?? "[]"));
|
|
@@ -47,7 +47,7 @@ const ui = {
|
|
|
47
47
|
icons: projectIcons(projectDir)
|
|
48
48
|
};
|
|
49
49
|
const { admin, jobs } = projectAdmin(project, db, ui, reporter, upgradeWebSocket);
|
|
50
|
-
await devJobs(db, jobs);
|
|
50
|
+
await devJobs(db, jobs, project.mailer);
|
|
51
51
|
var entry_default = withDevServiceWorker(new Hono(), Boolean(project.notifications)).route("/", admin);
|
|
52
52
|
/** Whether the auth store has a user yet, for the banner's sign-in line; undefined without one. */
|
|
53
53
|
const anyUsers = () => project.auth ? hasUsers(project.auth) : Promise.resolve(void 0);
|
package/dist/dev/project.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { serverPackage } from "./server-package.js";
|
|
1
2
|
import { loadSourceConfig } from "../config/source-config.js";
|
|
2
3
|
import { sharedDb } from "./create-db.js";
|
|
3
4
|
import { pathToFileURL } from "node:url";
|
|
@@ -24,11 +25,11 @@ const loadDevConfig = (projectDir, extensions = []) => loadSourceConfig(projectD
|
|
|
24
25
|
extensions,
|
|
25
26
|
importModules
|
|
26
27
|
});
|
|
27
|
-
/** The app's database, shared across reloads. */
|
|
28
|
+
/** The app's database, over the `pg` the project's config gets, shared across reloads. */
|
|
28
29
|
const devDatabase = (projectDir) => {
|
|
29
30
|
const url = process.env.PROTOBASE_DATABASE_URL;
|
|
30
31
|
if (!url) throw new Error("No database: set DATABASE_URL (or pass --env)");
|
|
31
|
-
return sharedDb(projectDir, url);
|
|
32
|
+
return sharedDb(serverPackage(projectDir).root, url);
|
|
32
33
|
};
|
|
33
34
|
//#endregion
|
|
34
35
|
export { devDatabase, loadDevConfig };
|
|
@@ -1,30 +1,18 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
1
|
+
import { packageName } from "../build/packages/package-dir.js";
|
|
2
|
+
import { projectPackages } from "../version/project-packages.js";
|
|
3
|
+
import { hostModuleIds } from "../serve/host-module-ids.js";
|
|
3
4
|
import { fileURLToPath } from "node:url";
|
|
4
5
|
//#region src/dev/server-package.ts
|
|
5
6
|
const server = "@protobase/server";
|
|
6
|
-
const
|
|
7
|
-
"@protobase/layout",
|
|
8
|
-
"@protobase/query",
|
|
9
|
-
"@protobase/schema",
|
|
10
|
-
server
|
|
11
|
-
];
|
|
12
|
-
const dependencyFields = [
|
|
13
|
-
"dependencies",
|
|
14
|
-
"devDependencies",
|
|
15
|
-
"optionalDependencies",
|
|
16
|
-
"peerDependencies"
|
|
17
|
-
];
|
|
7
|
+
const supplied = [...new Set(hostModuleIds.map((id) => packageName(id)))];
|
|
18
8
|
const cliDir = fileURLToPath(new URL("../..", import.meta.url));
|
|
19
9
|
/**
|
|
20
|
-
* Where the API of `protobase dev` gets @protobase/server: from the project's node_modules when
|
|
21
|
-
*
|
|
22
|
-
*
|
|
10
|
+
* Where the API of `protobase dev` gets @protobase/server: from the project's node_modules when the project is locked,
|
|
11
|
+
* so one that is not installed fails as any missing package does; otherwise, bundled, the CLI's own, with the other
|
|
12
|
+
* packages the serve runtime supplies.
|
|
23
13
|
*/
|
|
24
14
|
const serverPackage = (projectDir, ownDir = cliDir) => {
|
|
25
|
-
|
|
26
|
-
const manifest = existsSync(file) ? JSON.parse(readFileSync(file, "utf8")) : {};
|
|
27
|
-
if (dependencyFields.some((field) => manifest[field]?.[server] !== void 0)) return {
|
|
15
|
+
if (projectPackages(projectDir).mode === "locked") return {
|
|
28
16
|
from: "project",
|
|
29
17
|
root: projectDir,
|
|
30
18
|
dedupe: [server]
|
|
@@ -32,7 +20,7 @@ const serverPackage = (projectDir, ownDir = cliDir) => {
|
|
|
32
20
|
return {
|
|
33
21
|
from: "cli",
|
|
34
22
|
root: ownDir,
|
|
35
|
-
dedupe:
|
|
23
|
+
dedupe: supplied
|
|
36
24
|
};
|
|
37
25
|
};
|
|
38
26
|
//#endregion
|
package/dist/doctor/run.js
CHANGED
|
@@ -12,7 +12,7 @@ import { tableIndexes } from "@protobase/query";
|
|
|
12
12
|
const format = (issue) => ` ${issue.severity.padEnd(7)} ${issue.resource}: ${issue.message}${issue.suggestion ? `\n fix: ${issue.suggestion}` : ""}\n`;
|
|
13
13
|
const runDoctor = async (options, out) => {
|
|
14
14
|
if (!existsSync(path.join(options.configDir, "index.ts"))) throw new Error(`No config in ${options.configDir}: write it with \`protobase scaffold\`, or pass --config <dir>`);
|
|
15
|
-
const config = await loadDataConfig(options.configDir);
|
|
15
|
+
const config = await loadDataConfig(options.configDir, options.projectDir);
|
|
16
16
|
const { models } = config;
|
|
17
17
|
if (models.length === 0) throw new Error(`No resources exported from ${options.configDir}/index.ts`);
|
|
18
18
|
const sql = connect(options.url);
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
//#region src/hand-over.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* The folder of the @protobase/cli a locked project in `projectDir` has installed, when it is another CLI than the one
|
|
4
|
+
* in `ownDir`: that one runs the project, at the version it is locked to. Undefined for a bundled project, which the
|
|
5
|
+
* CLI that is started runs, and for a locked one without its own CLI installed.
|
|
6
|
+
*/
|
|
7
|
+
export declare const projectCliDir: (projectDir: string, ownDir: string) => string | undefined;
|
|
8
|
+
type Run = (argv: string[]) => Promise<void>;
|
|
9
|
+
/**
|
|
10
|
+
* Runs the command in `argv` with the CLI the project in the current directory is locked to, the Angular CLI's and
|
|
11
|
+
* Gulp's hand-over: a CLI installed globally, in CI or in an image, runs a locked project as its own CLI would, with a
|
|
12
|
+
* line on stderr naming that CLI. Otherwise it runs `own`, the started CLI.
|
|
13
|
+
*/
|
|
14
|
+
export declare const runHandingOver: (ownDir: string, own: () => Promise<Run>, argv: string[]) => Promise<void>;
|
|
15
|
+
//#endregion
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { findPackageDirSync } from "./build/packages/package-dir.js";
|
|
2
|
+
import { listedPackages, modeOf } from "./version/project-packages.js";
|
|
3
|
+
import { realpathSync } from "node:fs";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import { pathToFileURL } from "node:url";
|
|
6
|
+
//#region src/hand-over.ts
|
|
7
|
+
/**
|
|
8
|
+
* The folder of the @protobase/cli a locked project in `projectDir` has installed, when it is another CLI than the one
|
|
9
|
+
* in `ownDir`: that one runs the project, at the version it is locked to. Undefined for a bundled project, which the
|
|
10
|
+
* CLI that is started runs, and for a locked one without its own CLI installed.
|
|
11
|
+
*/
|
|
12
|
+
const projectCliDir = (projectDir, ownDir) => {
|
|
13
|
+
if (modeOf(listedPackages(projectDir)) !== "locked") return void 0;
|
|
14
|
+
const dir = findPackageDirSync("@protobase/cli", projectDir);
|
|
15
|
+
if (!dir || realpathSync(dir) === realpathSync(ownDir)) return void 0;
|
|
16
|
+
return dir;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Runs the command in `argv` with the CLI the project in the current directory is locked to, the Angular CLI's and
|
|
20
|
+
* Gulp's hand-over: a CLI installed globally, in CI or in an image, runs a locked project as its own CLI would, with a
|
|
21
|
+
* line on stderr naming that CLI. Otherwise it runs `own`, the started CLI.
|
|
22
|
+
*/
|
|
23
|
+
const runHandingOver = async (ownDir, own, argv) => {
|
|
24
|
+
const projectDir = projectCliDir(process.cwd(), ownDir);
|
|
25
|
+
if (!projectDir) return (await own())(argv);
|
|
26
|
+
const { version } = (await import(pathToFileURL(path.join(projectDir, "package.json")).href, { with: { type: "json" } })).default;
|
|
27
|
+
process.stderr.write(`protobase: this project is locked; running its own @protobase/cli ${version}\n`);
|
|
28
|
+
const { run } = await import(pathToFileURL(path.join(projectDir, "dist/index.js")).href);
|
|
29
|
+
return run(argv);
|
|
30
|
+
};
|
|
31
|
+
//#endregion
|
|
32
|
+
export { projectCliDir, runHandingOver };
|