@plitzi/sdk-shared 0.38.23 → 0.39.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/CHANGELOG.md +162 -1
- package/dist/actions/functions.d.ts +22 -1
- package/dist/actions/functions.mjs +3 -3
- package/dist/actions/index.d.ts +1 -1
- package/dist/actions/index.mjs +7 -7
- package/dist/auth/failureChannel.mjs +1 -0
- package/dist/auth/index.d.ts +1 -1
- package/dist/auth/index.mjs +2 -2
- package/dist/auth/visitorRoles.d.ts +8 -0
- package/dist/auth/visitorRoles.mjs +5 -2
- package/dist/authoring/declare.d.ts +34 -1
- package/dist/authoring/elementCallbacks.d.ts +13 -0
- package/dist/authoring/elementCallbacks.mjs +11 -5
- package/dist/authoring/index.mjs +3 -3
- package/dist/authoring/paramSpec.d.ts +1 -0
- package/dist/dataSource/getBindingsDetails.d.ts +1 -1
- package/dist/dataSource/getBindingsDetails.mjs +1 -1
- package/dist/dataSource/globalSources.d.ts +1 -1
- package/dist/dataSource/index.d.ts +1 -2
- package/dist/dataSource/index.mjs +1 -1
- package/dist/dataSource/utility/arrayMap.mjs +1 -1
- package/dist/dataSource/utility/capitalize.mjs +1 -1
- package/dist/dataSource/utility/styleSelector.mjs +5 -3
- package/dist/dataSource/utility/styleVariant.mjs +17 -13
- package/dist/dataSource/variables/index.d.ts +2 -0
- package/dist/dataSource/variables/index.mjs +1 -0
- package/dist/dataSource/{resolveVariables.d.ts → variables/resolveVariables.d.ts} +1 -1
- package/dist/dataSource/{resolveVariables.mjs → variables/resolveVariables.mjs} +1 -1
- package/dist/devTools/chrome.d.ts +6 -0
- package/dist/devTools/chrome.mjs +2 -2
- package/dist/devTools/index.mjs +5 -5
- package/dist/devTools/sight/index.d.ts +1 -0
- package/dist/devTools/sight/index.mjs +1 -0
- package/dist/devTools/sight/sight.d.ts +28 -0
- package/dist/devTools/sight/sight.mjs +127 -0
- package/dist/devTools/utils/PlitziConsole.d.ts +14 -0
- package/dist/devTools/utils/PlitziConsole.mjs +20 -3
- package/dist/flags/flagsCookie.mjs +4 -4
- package/dist/flags/resolveFlags.d.ts +1 -1
- package/dist/helpers/index.mjs +19 -19
- package/dist/helpers/ruleEvaluator.d.ts +2 -0
- package/dist/helpers/ruleEvaluator.mjs +2 -2
- package/dist/helpers/scroll.d.ts +10 -0
- package/dist/helpers/scroll.mjs +2 -2
- package/dist/helpers/twigWrapper/Evaluator/Evaluator.mjs +90 -88
- package/dist/helpers/twigWrapper/Evaluator/helpers.d.ts +6 -0
- package/dist/helpers/twigWrapper/Evaluator/helpers.mjs +11 -2
- package/dist/helpers/twigWrapper/filters/arrays.d.ts +2 -0
- package/dist/helpers/twigWrapper/filters/arrays.mjs +66 -0
- package/dist/helpers/twigWrapper/filters/catalog/index.d.ts +17 -0
- package/dist/helpers/twigWrapper/filters/catalog/index.mjs +351 -0
- package/dist/helpers/twigWrapper/filters/dateParts.d.ts +25 -0
- package/dist/helpers/twigWrapper/filters/dateParts.mjs +56 -0
- package/dist/helpers/twigWrapper/filters/dates.d.ts +2 -0
- package/dist/helpers/twigWrapper/filters/dates.mjs +97 -0
- package/dist/helpers/twigWrapper/filters/filters.d.ts +3 -13
- package/dist/helpers/twigWrapper/filters/filters.mjs +25 -483
- package/dist/helpers/twigWrapper/filters/hashing.d.ts +3 -0
- package/dist/helpers/twigWrapper/filters/hashing.mjs +101 -0
- package/dist/helpers/twigWrapper/filters/index.mjs +4 -1
- package/dist/helpers/twigWrapper/filters/misc.d.ts +5 -0
- package/dist/helpers/twigWrapper/filters/misc.mjs +52 -0
- package/dist/helpers/twigWrapper/filters/numbers.d.ts +2 -0
- package/dist/helpers/twigWrapper/filters/numbers.mjs +36 -0
- package/dist/helpers/twigWrapper/filters/objects.d.ts +3 -0
- package/dist/helpers/twigWrapper/filters/objects.mjs +61 -0
- package/dist/helpers/twigWrapper/filters/raw.d.ts +8 -0
- package/dist/helpers/twigWrapper/filters/raw.mjs +7 -0
- package/dist/helpers/twigWrapper/filters/strings.d.ts +7 -0
- package/dist/helpers/twigWrapper/filters/strings.mjs +79 -0
- package/dist/helpers/twigWrapper/filters/types.d.ts +5 -0
- package/dist/helpers/twigWrapper/filters/types.mjs +4 -0
- package/dist/helpers/twigWrapper/filters/values.d.ts +12 -0
- package/dist/helpers/twigWrapper/filters/values.mjs +17 -0
- package/dist/helpers/twigWrapper/inspectTemplate.d.ts +5 -0
- package/dist/helpers/twigWrapper/inspectTemplate.mjs +39 -20
- package/dist/helpers/utils.d.ts +4 -0
- package/dist/helpers/utils.mjs +3 -5
- package/dist/navigation/index.d.ts +2 -0
- package/dist/navigation/index.mjs +2 -1
- package/dist/navigation/sitemap.d.ts +16 -0
- package/dist/navigation/sitemap.mjs +25 -0
- package/dist/network/entitlements.d.ts +101 -0
- package/dist/network/entitlements.mjs +4 -0
- package/dist/network/graphql/builder/Mutations/Space/SpaceRunE2eTestsMutation.d.ts +31 -0
- package/dist/network/graphql/builder/Mutations/Space/SpaceRunE2eTestsMutation.mjs +13 -0
- package/dist/network/graphql/builder/Mutations/Space/SpaceSetTestsMutation.d.ts +5 -0
- package/dist/network/graphql/builder/Mutations/Space/SpaceSetTestsMutation.mjs +11 -0
- package/dist/network/graphql/builder/Mutations/Space/SpaceUpdateSettingsMutation.d.ts +1 -1
- package/dist/network/graphql/builder/Mutations/Space/SpaceUpdateSettingsMutation.mjs +1 -1
- package/dist/network/graphql/builder/Mutations/index.d.ts +5 -0
- package/dist/network/graphql/builder/Mutations/index.mjs +150 -146
- package/dist/network/graphql/builder/Queries/Space/SpaceTestsQuery.d.ts +40 -0
- package/dist/network/graphql/builder/Queries/Space/SpaceTestsQuery.mjs +24 -0
- package/dist/network/graphql/builder/Queries/index.d.ts +3 -0
- package/dist/network/graphql/builder/Queries/index.mjs +44 -42
- package/dist/network/graphql/sdk/Queries/InitQuery.d.ts +3 -1
- package/dist/network/graphql/sdk/Queries/InitQuery.mjs +1 -1
- package/dist/network/index.d.ts +1 -0
- package/dist/network/index.mjs +9 -8
- package/dist/network/spaceEvents.d.ts +20 -1
- package/dist/network/spaceEvents.mjs +12 -0
- package/dist/project/index.mjs +8 -5
- package/dist/project/layout/check.d.ts +22 -0
- package/dist/project/layout/check.mjs +60 -0
- package/dist/project/{layout.d.ts → layout/codes.d.ts} +3 -66
- package/dist/project/layout/codes.mjs +108 -0
- package/dist/project/layout/contents.d.ts +10 -0
- package/dist/project/layout/contents.mjs +31 -0
- package/dist/project/layout/files.d.ts +31 -0
- package/dist/project/layout/files.mjs +49 -0
- package/dist/project/layout/folders.d.ts +4 -0
- package/dist/project/layout/folders.mjs +69 -0
- package/dist/project/layout/index.d.ts +16 -0
- package/dist/project/layout/index.mjs +5 -0
- package/dist/project/layout/plugins.d.ts +46 -0
- package/dist/project/layout/plugins.mjs +99 -0
- package/dist/project/layout/vendor.d.ts +15 -0
- package/dist/project/layout/vendor.mjs +34 -0
- package/dist/project/pages/index.d.ts +8 -0
- package/dist/project/pages/index.mjs +14 -0
- package/dist/project/paths/index.d.ts +52 -4
- package/dist/project/paths/index.mjs +2 -2
- package/dist/project/root.d.ts +6 -0
- package/dist/project/root.mjs +11 -10
- package/dist/realtime/client.mjs +104 -91
- package/dist/realtime/presence.d.ts +2 -2
- package/dist/realtime/presence.mjs +27 -21
- package/dist/runs/index.d.ts +73 -0
- package/dist/runs/index.mjs +6 -0
- package/dist/runs/report.d.ts +56 -0
- package/dist/runs/report.mjs +17 -0
- package/dist/schema/index.d.ts +6 -0
- package/dist/schema/index.mjs +18 -12
- package/dist/schema/motion.d.ts +25 -0
- package/dist/schema/motion.mjs +47 -19
- package/dist/schema/pageAccess.d.ts +6 -0
- package/dist/schema/pageAccess.mjs +8 -3
- package/dist/schema/pageHead.d.ts +64 -0
- package/dist/schema/pageHead.mjs +68 -0
- package/dist/schema/providerAnswer.d.ts +17 -0
- package/dist/schema/providerAnswer.mjs +4 -0
- package/dist/schema/providerWhen.d.ts +36 -0
- package/dist/schema/providerWhen.mjs +58 -0
- package/dist/schema/schemaSettings.d.ts +14 -0
- package/dist/schema/schemaSettings.mjs +4 -0
- package/dist/schema/serverElements.d.ts +20 -1
- package/dist/schema/serverElements.mjs +41 -28
- package/dist/schema/serverInput.d.ts +34 -0
- package/dist/schema/serverInput.mjs +60 -0
- package/dist/schema/serverQuery.d.ts +47 -0
- package/dist/schema/serverQuery.mjs +70 -0
- package/dist/server/index.mjs +5 -5
- package/dist/server/rsc/refreshRsc.d.ts +6 -2
- package/dist/server/rsc/refreshRsc.mjs +75 -59
- package/dist/server/rsc/useRscSync.mjs +22 -18
- package/dist/source/export.d.ts +1 -1
- package/dist/state/runtimeStatePersist.mjs +25 -17
- package/dist/store/renderSettings.d.ts +2 -0
- package/dist/store/renderSettings.mjs +13 -5
- package/dist/store/storeHooks.d.ts +45 -45
- package/dist/style/index.mjs +16 -16
- package/dist/style/styleConstants.d.ts +12 -2
- package/dist/style/styleConstants.mjs +20 -0
- package/dist/style/styleStates.d.ts +5 -0
- package/dist/style/styleStates.mjs +21 -5
- package/dist/types/ActionTypes.d.ts +26 -3
- package/dist/types/AuthTypes.d.ts +19 -1
- package/dist/types/CommonTypes.d.ts +3 -2
- package/dist/types/ElementTypes.d.ts +1 -1
- package/dist/types/InteractionTypes.d.ts +10 -1
- package/dist/types/JobTypes.d.ts +2 -1
- package/dist/types/OAuthTypes.d.ts +246 -0
- package/dist/types/OAuthTypes.mjs +0 -0
- package/dist/types/PluginTypes.d.ts +2 -0
- package/dist/types/PreviewTypes.d.ts +71 -0
- package/dist/types/PreviewTypes.mjs +0 -0
- package/dist/types/RealtimeTypes.d.ts +11 -0
- package/dist/types/SchemaTypes.d.ts +56 -0
- package/dist/types/ServerAdapterTypes.d.ts +345 -0
- package/dist/types/ServerAdapterTypes.mjs +0 -0
- package/dist/types/ServerConfigTypes.d.ts +527 -0
- package/dist/types/ServerConfigTypes.mjs +0 -0
- package/dist/types/ServerLogTypes.d.ts +119 -0
- package/dist/types/ServerLogTypes.mjs +0 -0
- package/dist/types/ServerTypes.d.ts +30 -1215
- package/dist/types/StoreTypes.d.ts +39 -1
- package/dist/types/TestTypes.d.ts +249 -0
- package/dist/types/TestTypes.mjs +0 -0
- package/dist/types/index.d.ts +6 -0
- package/eslint.config.mjs +3 -1
- package/package.json +2 -2
- package/setupTests.ts +4 -3
- package/dist/project/layout.mjs +0 -394
|
@@ -105,6 +105,18 @@ var u = l.custom((t) => e(t) && typeof t.id == "string", { message: "expected an
|
|
|
105
105
|
l.boolean()
|
|
106
106
|
])
|
|
107
107
|
}),
|
|
108
|
+
SPACE_UPDATE_TESTS: l.object({ tests: l.custom(e) }),
|
|
109
|
+
SPACE_TESTS_PLAYING: l.object({
|
|
110
|
+
run: l.string(),
|
|
111
|
+
test: l.string(),
|
|
112
|
+
at: l.number().int().nonnegative(),
|
|
113
|
+
of: l.number().int().positive(),
|
|
114
|
+
played: l.number().int().nonnegative(),
|
|
115
|
+
steps: l.number().int().nonnegative(),
|
|
116
|
+
ok: l.boolean(),
|
|
117
|
+
ended: l.boolean().optional(),
|
|
118
|
+
frame: l.string().optional()
|
|
119
|
+
}),
|
|
108
120
|
STYLE_ADD_SELECTOR: l.object({
|
|
109
121
|
displayMode: b,
|
|
110
122
|
selector: l.string(),
|
package/dist/project/index.mjs
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
1
|
+
import { PROJECT_LAYOUT_CODES as e } from "./layout/codes.mjs";
|
|
2
|
+
import { ACTIVE_RUN_FILE as t, AUTHOR_FILE as n, BUILD_DIR as r, CLI_DIR as i, DATA_DIR as a, DEV_SERVER_FILE as o, FUNCTIONS_DIR as s, JOBS_FILE as c, KV_FILE as l, LATER_ANSWER_FILE as u, LATER_ASK_FILE as d, LEGACY_CLI_DIR as f, PLUGINS_DIR as p, PLUGIN_DECLARATION_FILE as m, PLUGIN_ENTRIES as h, PLUGIN_FUNCTIONS_DIR as g, PLUGIN_MANIFEST_FILE as _, PREVIEW_FILE_ENV as v, PREVIEW_SLUG as y, PROJECT_DATA_PREFIX as b, PROJECT_STATE as x, PROJECT_TMP as S, PUBLIC_DIR as C, RUNS_DIR as w, RUNTIME_BUNDLE as T, RUNTIME_DIR as E, RUNTIME_ENTRY as D, SERVER_RECORD_ENV as O, SOURCE_DIR as k, SPACE_DIR as A, SPACE_ENTRY as j, STATE_DIR_ENV as M, VENDOR_PLUGINS_DIR as N, previewCopyId as P } from "./paths/index.mjs";
|
|
3
|
+
import { readVendorPlugin as F } from "./layout/vendor.mjs";
|
|
4
|
+
import { checkPluginFolder as I, elementEntry as L, pluginEntry as R, pluginTypeOf as z } from "./layout/plugins.mjs";
|
|
5
|
+
import { ProjectLayoutError as B, assertProjectLayout as V, checkProjectLayout as H, layoutFindingText as U } from "./layout/check.mjs";
|
|
6
|
+
import { localNetworkName as W, networkAddresses as G } from "./network.mjs";
|
|
7
|
+
import { ProjectRootError as K, checkProjectRoot as q, projectMark as J, projectModule as Y, projectRoot as X } from "./root.mjs";
|
|
8
|
+
export { t as ACTIVE_RUN_FILE, n as AUTHOR_FILE, r as BUILD_DIR, i as CLI_DIR, a as DATA_DIR, o as DEV_SERVER_FILE, s as FUNCTIONS_DIR, c as JOBS_FILE, l as KV_FILE, u as LATER_ANSWER_FILE, d as LATER_ASK_FILE, f as LEGACY_CLI_DIR, p as PLUGINS_DIR, m as PLUGIN_DECLARATION_FILE, h as PLUGIN_ENTRIES, g as PLUGIN_FUNCTIONS_DIR, _ as PLUGIN_MANIFEST_FILE, v as PREVIEW_FILE_ENV, y as PREVIEW_SLUG, b as PROJECT_DATA_PREFIX, e as PROJECT_LAYOUT_CODES, x as PROJECT_STATE, S as PROJECT_TMP, C as PUBLIC_DIR, B as ProjectLayoutError, K as ProjectRootError, w as RUNS_DIR, T as RUNTIME_BUNDLE, E as RUNTIME_DIR, D as RUNTIME_ENTRY, O as SERVER_RECORD_ENV, k as SOURCE_DIR, A as SPACE_DIR, j as SPACE_ENTRY, M as STATE_DIR_ENV, N as VENDOR_PLUGINS_DIR, V as assertProjectLayout, I as checkPluginFolder, H as checkProjectLayout, q as checkProjectRoot, L as elementEntry, U as layoutFindingText, W as localNetworkName, G as networkAddresses, R as pluginEntry, z as pluginTypeOf, P as previewCopyId, J as projectMark, Y as projectModule, X as projectRoot, F as readVendorPlugin };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { LayoutFinding, ProjectLayoutOptions } from './codes';
|
|
2
|
+
/**
|
|
3
|
+
* Everything out of place in the project at `root`, errors first: what its server, its authoring and `plitzi doctor`
|
|
4
|
+
* say of its layout. `PROJECT_LAYOUT_CODES` says what each code means.
|
|
5
|
+
*/
|
|
6
|
+
export declare const checkProjectLayout: (root: string, options?: ProjectLayoutOptions) => LayoutFinding[];
|
|
7
|
+
/** One finding as the terminal says it: what is wrong, then what to do. */
|
|
8
|
+
export declare const layoutFindingText: (layoutFinding: LayoutFinding) => string;
|
|
9
|
+
/**
|
|
10
|
+
* The errors of a project's layout, every one at once: what its server and its authoring refuse to start with.
|
|
11
|
+
* `findings` holds them as data, for a tool that says them its own way.
|
|
12
|
+
*/
|
|
13
|
+
export declare class ProjectLayoutError extends Error {
|
|
14
|
+
#private;
|
|
15
|
+
get findings(): readonly LayoutFinding[];
|
|
16
|
+
constructor(findings: readonly LayoutFinding[]);
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* The project's layout, refused with every error at once (`ProjectLayoutError`) — what its server and its authoring
|
|
20
|
+
* check before anything else — and its warnings answered, for the caller to say.
|
|
21
|
+
*/
|
|
22
|
+
export declare const assertProjectLayout: (root: string, options?: ProjectLayoutOptions) => LayoutFinding[];
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { isRecord as e } from "../../helpers/isRecord.mjs";
|
|
2
|
+
import { exists as t } from "./files.mjs";
|
|
3
|
+
import { FUNCTIONS_DIR as n, RUNTIME_DIR as r } from "../paths/index.mjs";
|
|
4
|
+
import { functionsFindings as i, pluginFindings as a, sourceEntryFindings as o } from "./plugins.mjs";
|
|
5
|
+
import { dataFindings as s, envFindings as c, publicFindings as l } from "./contents.mjs";
|
|
6
|
+
import { nearMissFindings as u, spaceFindings as d } from "./folders.mjs";
|
|
7
|
+
import f from "node:path";
|
|
8
|
+
import { readFileSync as p } from "node:fs";
|
|
9
|
+
//#region src/project/layout/check.ts
|
|
10
|
+
var m = (t) => {
|
|
11
|
+
try {
|
|
12
|
+
let n = JSON.parse(p(f.join(t, "package.json"), "utf-8"));
|
|
13
|
+
return e(n) && [n.dependencies, n.devDependencies].some((t) => e(t) && "@plitzi/sdk-server" in t);
|
|
14
|
+
} catch {
|
|
15
|
+
return !1;
|
|
16
|
+
}
|
|
17
|
+
}, h = (e, n) => ({
|
|
18
|
+
mode: n.mode ?? (m(e) ? "server" : "client"),
|
|
19
|
+
space: n.space ?? (t(e, "src/space", "folder") || t(e, ".plitzi/author.ts", "file") ? "local" : "cloud")
|
|
20
|
+
}), g = (e, t = {}) => {
|
|
21
|
+
let f = h(e, t), p = u(e, f), m = [
|
|
22
|
+
...a(e),
|
|
23
|
+
...i(e, {
|
|
24
|
+
folder: n,
|
|
25
|
+
code: "functions-entry-missing",
|
|
26
|
+
lost: "none of the project’s functions runs",
|
|
27
|
+
write: `Write the domain's file at the top of ${n}/ (rooms.ts) exporting defineFunctions({ tasks: [ … ] }) by default — a domain a file, nothing to list.`
|
|
28
|
+
}),
|
|
29
|
+
...o(e, {
|
|
30
|
+
folder: r,
|
|
31
|
+
accepted: ["index.ts"],
|
|
32
|
+
code: "runtime-entry-missing",
|
|
33
|
+
lost: "the space’s runtime does not run",
|
|
34
|
+
write: `Write ${r}/index.ts exporting defineRuntime(…) by default — npx plitzi runtime add writes one.`
|
|
35
|
+
}),
|
|
36
|
+
...f.space === "local" ? d(e, p) : [],
|
|
37
|
+
...p,
|
|
38
|
+
...c(e),
|
|
39
|
+
...f.mode === "server" ? s(e) : [],
|
|
40
|
+
...l(e, f.mode)
|
|
41
|
+
];
|
|
42
|
+
return [...m.filter((e) => e.level === "error"), ...m.filter((e) => e.level === "warning")];
|
|
43
|
+
}, _ = (e) => `${e.message}\n → ${e.fix}`, v = class extends Error {
|
|
44
|
+
#e;
|
|
45
|
+
get findings() {
|
|
46
|
+
return this.#e;
|
|
47
|
+
}
|
|
48
|
+
constructor(e) {
|
|
49
|
+
let t = e.length === 1 ? "one error" : `${String(e.length)} errors`, n = e.map((e, t) => `${String(t + 1)}. ${e.message}\n → ${e.fix}`).join("\n\n"), r = e.filter((e) => e.autofix).length, i = r === e.length ? "these fixes" : `${String(r)} of these fixes`, a = r > 0 ? `npx plitzi doctor --fix makes ${i} itself.` : "npx plitzi doctor says these with the rest of the project.";
|
|
50
|
+
super(`The project is not laid out as Plitzi reads it — ${t}:\n\n${n}\n\n${a}`), this.name = "ProjectLayoutError", this.#e = e;
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
Object.defineProperty(v, "name", { value: "ProjectLayoutError" });
|
|
54
|
+
var y = (e, t = {}) => {
|
|
55
|
+
let n = g(e, t), r = n.filter((e) => e.level === "error");
|
|
56
|
+
if (r.length > 0) throw new v(r);
|
|
57
|
+
return n;
|
|
58
|
+
};
|
|
59
|
+
//#endregion
|
|
60
|
+
export { v as ProjectLayoutError, y as assertProjectLayout, g as checkProjectLayout, _ as layoutFindingText };
|
|
@@ -1,13 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The project's layout held to what reads it: every folder the server builds, runs or serves from where the CLI puts
|
|
3
|
-
* it, each with the file it starts at. One check, said the same by the three that read the project — its server at
|
|
4
|
-
* boot (`serveProject`), its authoring (`projectAuthoring`: `npm run author` and the CLI's checks) and `plitzi doctor`,
|
|
5
|
-
* which makes the fixes that have one reading (`autofix`). Pure file system: what a file holds is never imported.
|
|
6
|
-
*
|
|
7
|
-
* An `error` is what keeps a part of the project from running — a plugin the server cannot build, code in a folder
|
|
8
|
-
* nothing reads, settings Node never loads — and stops the server and the authoring; a `warning` works, and should not
|
|
9
|
-
* stay.
|
|
10
|
-
*/
|
|
11
1
|
export type LayoutLevel = 'error' | 'warning';
|
|
12
2
|
/** Every finding of the layout check, by its code: how much it matters, and what it means in a line. */
|
|
13
3
|
export declare const PROJECT_LAYOUT_CODES: {
|
|
@@ -37,11 +27,11 @@ export declare const PROJECT_LAYOUT_CODES: {
|
|
|
37
27
|
};
|
|
38
28
|
readonly 'plugin-functions-entry-missing': {
|
|
39
29
|
readonly level: "error";
|
|
40
|
-
readonly means: "a plugin’s functions/ with code and no
|
|
30
|
+
readonly means: "a plugin’s functions/ with code and no file at its top, which its server half is built from";
|
|
41
31
|
};
|
|
42
32
|
readonly 'functions-entry-missing': {
|
|
43
33
|
readonly level: "error";
|
|
44
|
-
readonly means: "src/functions/ with code and no
|
|
34
|
+
readonly means: "src/functions/ with code and no file at its top, which the project’s functions are built from";
|
|
45
35
|
};
|
|
46
36
|
readonly 'runtime-entry-missing': {
|
|
47
37
|
readonly level: "error";
|
|
@@ -141,57 +131,4 @@ export interface ProjectLayoutOptions {
|
|
|
141
131
|
/** Where its space is: written in it (`src/space/`), or kept on Plitzi — told by its files when left out. */
|
|
142
132
|
space?: 'local' | 'cloud';
|
|
143
133
|
}
|
|
144
|
-
|
|
145
|
-
export declare const pluginTypeOf: (folder: string) => string;
|
|
146
|
-
/**
|
|
147
|
-
* The file an element's folder is built from, wherever the folder is — its `index.ts`, or `index.tsx` — or nothing
|
|
148
|
-
* when it has neither, or both: what `plitzi plugin pack` builds a folder from, as the server does.
|
|
149
|
-
*/
|
|
150
|
-
export declare const elementEntry: (dir: string) => string | undefined;
|
|
151
|
-
/**
|
|
152
|
-
* The file a folder of `src/plugins/` is built from (`elementEntry`) — or nothing when it is no plugin the server can
|
|
153
|
-
* build: a name that is no element type, no entry, or both. What the server registers, and what `checkPluginFolder`
|
|
154
|
-
* says why of.
|
|
155
|
-
*/
|
|
156
|
-
export declare const pluginEntry: (root: string, folder: string) => string | undefined;
|
|
157
|
-
/**
|
|
158
|
-
* One folder of `src/plugins/` as the server reads it: a name that is a type, the entry it is built from, its server
|
|
159
|
-
* half's entry, and its declaration. What the server says of a folder added while it runs, and what
|
|
160
|
-
* `checkProjectLayout` says of each.
|
|
161
|
-
*/
|
|
162
|
-
export declare const checkPluginFolder: (root: string, folder: string) => LayoutFinding[];
|
|
163
|
-
/** What a built plugin runs, by absolute path: its script, its style and its server half, as its manifest names them. */
|
|
164
|
-
export interface VendorPlugin {
|
|
165
|
-
script: string;
|
|
166
|
-
style?: string;
|
|
167
|
-
version: string;
|
|
168
|
-
functions?: string;
|
|
169
|
-
}
|
|
170
|
-
/**
|
|
171
|
-
* A plugin of `vendor/plugins/` — one a project made from a space runs as it was built, beside the manifest `plitzi
|
|
172
|
-
* pack plugin` wrote when it was published — or what keeps it from running.
|
|
173
|
-
*/
|
|
174
|
-
export declare const readVendorPlugin: (root: string, type: string) => VendorPlugin | {
|
|
175
|
-
problem: LayoutFinding;
|
|
176
|
-
};
|
|
177
|
-
/**
|
|
178
|
-
* Everything out of place in the project at `root`, errors first: what its server, its authoring and `plitzi doctor`
|
|
179
|
-
* say of its layout. `PROJECT_LAYOUT_CODES` says what each code means.
|
|
180
|
-
*/
|
|
181
|
-
export declare const checkProjectLayout: (root: string, options?: ProjectLayoutOptions) => LayoutFinding[];
|
|
182
|
-
/** One finding as the terminal says it: what is wrong, then what to do. */
|
|
183
|
-
export declare const layoutFindingText: (layoutFinding: LayoutFinding) => string;
|
|
184
|
-
/**
|
|
185
|
-
* The errors of a project's layout, every one at once: what its server and its authoring refuse to start with.
|
|
186
|
-
* `findings` holds them as data, for a tool that says them its own way.
|
|
187
|
-
*/
|
|
188
|
-
export declare class ProjectLayoutError extends Error {
|
|
189
|
-
#private;
|
|
190
|
-
get findings(): readonly LayoutFinding[];
|
|
191
|
-
constructor(findings: readonly LayoutFinding[]);
|
|
192
|
-
}
|
|
193
|
-
/**
|
|
194
|
-
* The project's layout, refused with every error at once (`ProjectLayoutError`) — what its server and its authoring
|
|
195
|
-
* check before anything else — and its warnings answered, for the caller to say.
|
|
196
|
-
*/
|
|
197
|
-
export declare const assertProjectLayout: (root: string, options?: ProjectLayoutOptions) => LayoutFinding[];
|
|
134
|
+
export declare const finding: (code: LayoutCode, file: string, message: string, fix: string, autofix?: LayoutAutofix) => LayoutFinding;
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
//#region src/project/layout/codes.ts
|
|
2
|
+
var e = {
|
|
3
|
+
"plugin-entry-missing": {
|
|
4
|
+
level: "error",
|
|
5
|
+
means: "a folder of src/plugins/ with no index.ts (or index.tsx), which the server builds the plugin from"
|
|
6
|
+
},
|
|
7
|
+
"plugin-entry-ambiguous": {
|
|
8
|
+
level: "error",
|
|
9
|
+
means: "a folder of src/plugins/ with both index.ts and index.tsx: a plugin starts at one"
|
|
10
|
+
},
|
|
11
|
+
"entry-not-typescript": {
|
|
12
|
+
level: "error",
|
|
13
|
+
means: "an entry the server builds or runs written as JavaScript (index.js, .jsx, .mjs, .cjs): the project is TypeScript"
|
|
14
|
+
},
|
|
15
|
+
"plugin-name-invalid": {
|
|
16
|
+
level: "error",
|
|
17
|
+
means: "a folder of src/plugins/ whose name cannot be an element type: a letter, then letters and digits"
|
|
18
|
+
},
|
|
19
|
+
"plugin-type-taken": {
|
|
20
|
+
level: "error",
|
|
21
|
+
means: "two folders of src/plugins/ that are the same element type (StoryEditor and storyEditor)"
|
|
22
|
+
},
|
|
23
|
+
"plugin-shadowed": {
|
|
24
|
+
level: "error",
|
|
25
|
+
means: "a plugin both in src/plugins/ and, as it was built, in vendor/plugins/: the built one runs"
|
|
26
|
+
},
|
|
27
|
+
"plugin-functions-entry-missing": {
|
|
28
|
+
level: "error",
|
|
29
|
+
means: "a plugin’s functions/ with code and no file at its top, which its server half is built from"
|
|
30
|
+
},
|
|
31
|
+
"functions-entry-missing": {
|
|
32
|
+
level: "error",
|
|
33
|
+
means: "src/functions/ with code and no file at its top, which the project’s functions are built from"
|
|
34
|
+
},
|
|
35
|
+
"runtime-entry-missing": {
|
|
36
|
+
level: "error",
|
|
37
|
+
means: "src/runtime/ with code and no index.ts, which the space’s runtime starts at"
|
|
38
|
+
},
|
|
39
|
+
"space-entry-missing": {
|
|
40
|
+
level: "error",
|
|
41
|
+
means: "a space written in the project with no src/space/index.ts, which the server and npm run author import"
|
|
42
|
+
},
|
|
43
|
+
"space-default-export": {
|
|
44
|
+
level: "error",
|
|
45
|
+
means: "src/space/index.ts exporting the space by default, where it is imported by name: `space`"
|
|
46
|
+
},
|
|
47
|
+
"vendor-manifest-missing": {
|
|
48
|
+
level: "error",
|
|
49
|
+
means: "a built plugin (vendor/plugins/<type>/) with no plugin-manifest.json"
|
|
50
|
+
},
|
|
51
|
+
"vendor-manifest-invalid": {
|
|
52
|
+
level: "error",
|
|
53
|
+
means: "a built plugin’s plugin-manifest.json that is not a manifest"
|
|
54
|
+
},
|
|
55
|
+
"vendor-script-missing": {
|
|
56
|
+
level: "error",
|
|
57
|
+
means: "a built plugin’s manifest naming no script to run, or one that is not there"
|
|
58
|
+
},
|
|
59
|
+
"env-in-src": {
|
|
60
|
+
level: "error",
|
|
61
|
+
means: ".env inside src/: Node reads the project’s settings from the .env at its root"
|
|
62
|
+
},
|
|
63
|
+
"folder-misplaced": {
|
|
64
|
+
level: "error",
|
|
65
|
+
means: "code in a folder named like one the server reads (src/plugin/, plugins/ at the root): nothing reads it"
|
|
66
|
+
},
|
|
67
|
+
"folder-near-miss": {
|
|
68
|
+
level: "warning",
|
|
69
|
+
means: "a folder named like one the server reads (src/Data/, src/runtimes/), which nothing reads"
|
|
70
|
+
},
|
|
71
|
+
"plugin-declaration-missing": {
|
|
72
|
+
level: "warning",
|
|
73
|
+
means: "a plugin folder with no declaration.ts: the space’s use of the plugin is held to nothing"
|
|
74
|
+
},
|
|
75
|
+
"plugin-file-loose": {
|
|
76
|
+
level: "warning",
|
|
77
|
+
means: "a file directly in src/plugins/, where every plugin is a folder"
|
|
78
|
+
},
|
|
79
|
+
"data-not-json": {
|
|
80
|
+
level: "warning",
|
|
81
|
+
means: "a file of src/data/ that is not JSON, which no provider and no ctx.data reads"
|
|
82
|
+
},
|
|
83
|
+
"env-missing": {
|
|
84
|
+
level: "warning",
|
|
85
|
+
means: "no .env at the project’s root: none of its settings is set"
|
|
86
|
+
},
|
|
87
|
+
"env-example-missing": {
|
|
88
|
+
level: "warning",
|
|
89
|
+
means: "no .env.example: a clone does not know what .env must hold"
|
|
90
|
+
},
|
|
91
|
+
"public-data": {
|
|
92
|
+
level: "warning",
|
|
93
|
+
means: "JSON in public/data/ of a project with a server: served to anyone who asks"
|
|
94
|
+
},
|
|
95
|
+
"public-secret-file": {
|
|
96
|
+
level: "warning",
|
|
97
|
+
means: "a file in public/ named like a secret (.env, a key, a dump): served to anyone who asks"
|
|
98
|
+
}
|
|
99
|
+
}, t = (t, n, r, i, a) => ({
|
|
100
|
+
level: e[t].level,
|
|
101
|
+
code: t,
|
|
102
|
+
file: n,
|
|
103
|
+
message: r,
|
|
104
|
+
fix: i,
|
|
105
|
+
...a ? { autofix: a } : {}
|
|
106
|
+
});
|
|
107
|
+
//#endregion
|
|
108
|
+
export { e as PROJECT_LAYOUT_CODES, t as finding };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { LayoutFinding } from './codes';
|
|
2
|
+
/** Settings where Node reads them: `.env` at the root, `.env.example` beside it — and none inside `src/`. */
|
|
3
|
+
export declare const envFindings: (root: string) => LayoutFinding[];
|
|
4
|
+
/** Anything in `src/data/` but JSON: a provider's `/data/<file>` and `ctx.data` read JSON alone. */
|
|
5
|
+
export declare const dataFindings: (root: string) => LayoutFinding[];
|
|
6
|
+
/**
|
|
7
|
+
* What `public/` serves that had better be kept: files named like a secret, in any project — and, in one with a
|
|
8
|
+
* server, which has a folder of data it never serves, the JSON of `public/data/`.
|
|
9
|
+
*/
|
|
10
|
+
export declare const publicFindings: (root: string, mode: "server" | "client") => LayoutFinding[];
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { finding as e } from "./codes.mjs";
|
|
2
|
+
import { NOT_SOURCE as t, entriesOf as n, filesUnder as r } from "./files.mjs";
|
|
3
|
+
import { DATA_DIR as i, PUBLIC_DIR as a, RUNS_DIR as o } from "../paths/index.mjs";
|
|
4
|
+
import s from "node:path";
|
|
5
|
+
import { readFileSync as c } from "node:fs";
|
|
6
|
+
//#region src/project/layout/contents.ts
|
|
7
|
+
var l = (e) => e.split("\n").map((e) => e.replace(/^(\s*(?:export\s+)?[A-Za-z_][A-Za-z0-9_]*\s*=).*$/, "$1")).join("\n"), u = (t) => {
|
|
8
|
+
let i = n(t).files, a = i.includes(".env"), u = i.includes(".env.example"), d = r(t, "src", /* @__PURE__ */ new Set(["node_modules"])).filter((e) => s.posix.basename(e) === ".env"), f = !a && d.length === 1, p = d.map((t) => e("env-in-src", t, `${t} is never read: Node reads the project's settings from the .env at its root, as its scripts start it (--env-file-if-exists=.env).`, f ? `Move it to the root: mv ${t} .env` : `Copy what it sets into the root's .env, then delete ${t}.`, f ? {
|
|
9
|
+
action: "move",
|
|
10
|
+
from: t,
|
|
11
|
+
to: ".env"
|
|
12
|
+
} : void 0)), m = `${s.resolve(t).split(s.sep).join("/")}/`.includes(`/${o}/`), h = a || m || p.length > 0 ? [] : [e("env-missing", ".env", ".env is missing at the project’s root: none of its settings is set — the keys and secrets its code reads from process.env.", u ? "Copy .env.example and fill it in: cp .env.example .env" : "Write .env with the settings the project reads (process.env.*), and .env.example naming them.", u ? {
|
|
13
|
+
action: "copy",
|
|
14
|
+
from: ".env.example",
|
|
15
|
+
to: ".env"
|
|
16
|
+
} : void 0)], g = u ? [] : [e("env-example-missing", ".env.example", ".env.example is missing: committed where .env never is, it names the settings .env holds, with no secret in them — so a clone knows what to fill in.", a ? "Write it from .env with every value left empty, and commit it." : "Write it — each setting the project reads, as KEY= with no value — and commit it.", a ? {
|
|
17
|
+
action: "write",
|
|
18
|
+
file: ".env.example",
|
|
19
|
+
contents: l(c(s.join(t, ".env"), "utf-8"))
|
|
20
|
+
} : void 0)];
|
|
21
|
+
return [
|
|
22
|
+
...p,
|
|
23
|
+
...h,
|
|
24
|
+
...g
|
|
25
|
+
];
|
|
26
|
+
}, d = (n) => r(n, i).filter((e) => !t.has(s.posix.basename(e)) && !e.endsWith(".json")).map((t) => e("data-not-json", t, `${t} is not JSON: a provider's /data/<file> and ctx.data read JSON files only, and plitzi space push leaves it behind.`, `Keep it as JSON (${t.replace(/\.[^./]*$/, "")}.json), or move it out of ${i}/.`)), f = /^\.env(?:\..*)?$|\.(?:pem|key|p12|pfx|jks|keystore|sqlite3?|db|sql|dump)$|secret|credential|password|passwd|private[-_.]?key|id_rsa|id_ed25519|service[-_]?account/i, p = (t, n) => {
|
|
27
|
+
let o = r(t, a, /* @__PURE__ */ new Set(["node_modules"])), c = o.filter((e) => f.test(s.posix.basename(e))).map((t) => e("public-secret-file", t, `${t} is served to anyone who asks, as it is — everything in ${a}/ is on the internet once the project is deployed — and its name says it holds a secret, a key or a database.`, `Take it out of ${a}/: settings go in the root's .env${n === "server" ? `, data only the server reads in ${i}/` : ""}.`)), l = `${a}/data`, u = n === "server" ? o.filter((e) => e.startsWith(`${l}/`) && e.endsWith(".json")) : [], d = u.slice(0, 3).map((e) => s.posix.basename(e)), p = u.length > 0 ? [e("public-data", `${l}/`, `${l}/ holds ${String(u.length)} JSON file${u.length === 1 ? "" : "s"} (${d.join(", ")}${u.length > d.length ? ", …" : ""}), served to anyone who asks: every visitor can read all of ${u.length === 1 ? "it" : "them"}, not only what a page shows.`, `Data only the server should read goes in ${i}/ — a provider reads it on the server (runtime: 'server', query: '/data/<file>'), a function with ctx.data('<file>'), and neither serves the file. What every visitor may read can stay.`)] : [];
|
|
28
|
+
return [...c, ...p];
|
|
29
|
+
};
|
|
30
|
+
//#endregion
|
|
31
|
+
export { d as dataFindings, u as envFindings, p as publicFindings };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/** What a folder holds besides its code — never a reason for it to need an entry. */
|
|
2
|
+
export declare const NOT_SOURCE: ReadonlySet<string>;
|
|
3
|
+
export declare const JAVASCRIPT_ENTRY: RegExp;
|
|
4
|
+
/** An element type: what a folder of `src/plugins/` is registered as, and a space renders it by. */
|
|
5
|
+
export declare const TYPE_NAME: RegExp;
|
|
6
|
+
interface Entries {
|
|
7
|
+
files: string[];
|
|
8
|
+
folders: string[];
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* A folder's files and folders, by the names they have — never by a lookup, which a macOS or Windows disk answers
|
|
12
|
+
* ignoring case: `Index.ts` is found as `index.ts` there, and not on the Linux the project is deployed to.
|
|
13
|
+
*/
|
|
14
|
+
export declare const entriesOf: (dir: string) => Entries;
|
|
15
|
+
/** Whether `relative` is there under `root`, every part of it named exactly so. */
|
|
16
|
+
export declare const exists: (root: string, relative: string, kind: "file" | "folder") => boolean;
|
|
17
|
+
/** Every file under a folder, relative to the root — none of a folder named in `skipping`. */
|
|
18
|
+
export declare const filesUnder: (root: string, folder: string, skipping?: ReadonlySet<string>) => string[];
|
|
19
|
+
export declare const holdsSource: ({ files, folders }: Entries) => boolean;
|
|
20
|
+
export declare const sameIgnoringCase: (a: string, b: string) => boolean;
|
|
21
|
+
export declare const capitalized: (text: string) => string;
|
|
22
|
+
/**
|
|
23
|
+
* Whether `name` is `wanted` mistyped: the same but for case, one `s` more or less, or — for a name long enough that one
|
|
24
|
+
* letter does not make another word — one edit away. `wanted` itself is not.
|
|
25
|
+
*/
|
|
26
|
+
export declare const nearName: (name: string, wanted: string) => boolean;
|
|
27
|
+
/** On a disk that ignores case — macOS's, Windows' — two names that differ only in case are one file. */
|
|
28
|
+
export declare const CASE_NOTE = "macOS and Windows disks ignore case, so it is found there \u2014 and not on Linux, where the project is deployed.";
|
|
29
|
+
/** A rename git makes on a disk that ignores case too: through a name of its own, when only case changes. */
|
|
30
|
+
export declare const gitMove: (from: string, to: string) => string;
|
|
31
|
+
export {};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import e from "node:path";
|
|
2
|
+
import { readdirSync as t, statSync as n } from "node:fs";
|
|
3
|
+
//#region src/project/layout/files.ts
|
|
4
|
+
var r = /* @__PURE__ */ new Set([
|
|
5
|
+
".gitkeep",
|
|
6
|
+
"README.md",
|
|
7
|
+
".DS_Store"
|
|
8
|
+
]), i = /^index\.(?:js|jsx|mjs|cjs)$/, a = /^[A-Za-z][A-Za-z0-9]*$/, o = (r) => {
|
|
9
|
+
let i = {
|
|
10
|
+
files: [],
|
|
11
|
+
folders: []
|
|
12
|
+
};
|
|
13
|
+
try {
|
|
14
|
+
for (let a of t(r, { withFileTypes: !0 })) {
|
|
15
|
+
let t = a.isSymbolicLink() ? n(e.join(r, a.name), { throwIfNoEntry: !1 }) : void 0;
|
|
16
|
+
a.isFile() || t?.isFile() ? i.files.push(a.name) : (a.isDirectory() || t?.isDirectory()) && i.folders.push(a.name);
|
|
17
|
+
}
|
|
18
|
+
} catch {
|
|
19
|
+
return i;
|
|
20
|
+
}
|
|
21
|
+
return {
|
|
22
|
+
files: i.files.sort(),
|
|
23
|
+
folders: i.folders.sort()
|
|
24
|
+
};
|
|
25
|
+
}, s = (t, n, r) => {
|
|
26
|
+
let i = n.split("/").filter((e) => e !== "" && e !== "."), a = t;
|
|
27
|
+
for (let [t, n] of i.entries()) {
|
|
28
|
+
let { files: s, folders: c } = o(a);
|
|
29
|
+
if (!(t === i.length - 1 && r === "file" ? s : c).includes(n)) return !1;
|
|
30
|
+
a = e.join(a, n);
|
|
31
|
+
}
|
|
32
|
+
return !0;
|
|
33
|
+
}, c = (t, n, r = /* @__PURE__ */ new Set()) => {
|
|
34
|
+
let { files: i, folders: a } = o(e.join(t, n));
|
|
35
|
+
return [...i.map((e) => `${n}/${e}`), ...a.filter((e) => !r.has(e)).flatMap((e) => c(t, `${n}/${e}`, r))];
|
|
36
|
+
}, l = ({ files: e, folders: t }) => t.length > 0 || e.some((e) => !r.has(e)), u = (e, t) => e.toLowerCase() === t.toLowerCase(), d = (e) => `${e.charAt(0).toUpperCase()}${e.slice(1)}`, f = (e, t) => {
|
|
37
|
+
let n = Array.from({ length: e.length + 1 }, (e, n) => Array.from({ length: t.length + 1 }, (e, t) => Math.max(n, t) * Number(n === 0 || t === 0)));
|
|
38
|
+
for (let r = 1; r <= e.length; r++) for (let i = 1; i <= t.length; i++) {
|
|
39
|
+
let a = e[r - 1] === t[i - 1] ? 0 : 1;
|
|
40
|
+
n[r][i] = Math.min(n[r - 1][i] + 1, n[r][i - 1] + 1, n[r - 1][i - 1] + a), r > 1 && i > 1 && e[r - 1] === t[i - 2] && e[r - 2] === t[i - 1] && (n[r][i] = Math.min(n[r][i], n[r - 2][i - 2] + 1));
|
|
41
|
+
}
|
|
42
|
+
return n[e.length][t.length];
|
|
43
|
+
}, p = (e, t) => {
|
|
44
|
+
if (e === t) return !1;
|
|
45
|
+
let n = e.toLowerCase(), r = t.toLowerCase();
|
|
46
|
+
return n === r || n === `${r}s` || `${n}s` === r || r.length >= 5 && f(n, r) <= 1;
|
|
47
|
+
}, m = "macOS and Windows disks ignore case, so it is found there — and not on Linux, where the project is deployed.", h = (e, t) => u(e, t) ? `git mv ${e} ${e}-tmp && git mv ${e}-tmp ${t}` : `git mv ${e} ${t}`;
|
|
48
|
+
//#endregion
|
|
49
|
+
export { m as CASE_NOTE, i as JAVASCRIPT_ENTRY, r as NOT_SOURCE, a as TYPE_NAME, d as capitalized, o as entriesOf, s as exists, c as filesUnder, h as gitMove, l as holdsSource, p as nearName, u as sameIgnoringCase };
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { LayoutFinding, ProjectLayoutOptions } from './codes';
|
|
2
|
+
export declare const nearMissFindings: (root: string, options: Required<ProjectLayoutOptions>) => LayoutFinding[];
|
|
3
|
+
/** The space's entry, in a project whose space is its own: there, and exporting the space by the name it is imported by. */
|
|
4
|
+
export declare const spaceFindings: (root: string, misplaced: readonly LayoutFinding[]) => LayoutFinding[];
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { finding as e } from "./codes.mjs";
|
|
2
|
+
import { CASE_NOTE as t, capitalized as n, entriesOf as r, exists as i, gitMove as a, nearName as o, sameIgnoringCase as s } from "./files.mjs";
|
|
3
|
+
import { AUTHOR_FILE as c, DATA_DIR as l, FUNCTIONS_DIR as u, PLUGINS_DIR as d, PLUGIN_DECLARATION_FILE as f, PLUGIN_ENTRIES as p, PUBLIC_DIR as m, RUNTIME_DIR as h, SPACE_DIR as g, SPACE_ENTRY as _ } from "../paths/index.mjs";
|
|
4
|
+
import { entryFindings as v } from "./plugins.mjs";
|
|
5
|
+
import y from "node:path";
|
|
6
|
+
import { readFileSync as b } from "node:fs";
|
|
7
|
+
//#region src/project/layout/folders.ts
|
|
8
|
+
var x = (e, t) => t.map((t) => e.find((e) => s(e, t))).find((e) => e !== void 0), S = (e) => (t) => {
|
|
9
|
+
for (let n of r(y.join(e, t)).folders) {
|
|
10
|
+
let i = x(r(y.join(e, t, n)).files, [...p, f]);
|
|
11
|
+
if (i) return `${t}/${n}/${i}`;
|
|
12
|
+
}
|
|
13
|
+
}, C = (e) => (t) => {
|
|
14
|
+
let n = x(r(y.join(e, t)).files, ["index.ts"]);
|
|
15
|
+
return n ? `${t}/${n}` : void 0;
|
|
16
|
+
}, w = (e, { mode: t, space: n }) => [
|
|
17
|
+
{
|
|
18
|
+
at: d,
|
|
19
|
+
reads: `the server builds plugins from ${d}/ only`,
|
|
20
|
+
holds: S(e)
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
at: u,
|
|
24
|
+
reads: `the project's functions are built from ${u}/ only`,
|
|
25
|
+
holds: C(e)
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
at: h,
|
|
29
|
+
reads: `the space's runtime is run from ${h}/ only`,
|
|
30
|
+
holds: C(e)
|
|
31
|
+
},
|
|
32
|
+
...n === "local" ? [{
|
|
33
|
+
at: g,
|
|
34
|
+
reads: `the server's entry point and ${c} import the space from ${_}`,
|
|
35
|
+
holds: C(e)
|
|
36
|
+
}] : [],
|
|
37
|
+
...t === "server" ? [{
|
|
38
|
+
at: l,
|
|
39
|
+
reads: `the server reads the project's data from ${l}/ only (/data/<file>, ctx.data)`
|
|
40
|
+
}] : [],
|
|
41
|
+
{
|
|
42
|
+
at: m,
|
|
43
|
+
reads: `the server serves ${m}/ only, at the site's root`
|
|
44
|
+
}
|
|
45
|
+
], T = (e, t) => {
|
|
46
|
+
let n = y.posix.dirname(t), i = y.posix.basename(t), a = n === "." ? "src" : ".", s = r(y.join(e, n)).folders.filter((e) => o(e, i)).map((e) => y.posix.join(n, e)), c = r(y.join(e, a)).folders.filter((e) => e === i || o(e, i)).map((e) => y.posix.join(a, e));
|
|
47
|
+
return [...s, ...c];
|
|
48
|
+
}, E = (r, o) => w(r, o).flatMap(({ at: o, reads: c, holds: l }) => T(r, o).map((u) => {
|
|
49
|
+
let d = l?.(u), f = s(u, o), p = `did you mean ${o}/? ${n(c)}.${f ? ` ${t}` : ""}`, m = `Move it: ${a(u, o)}`;
|
|
50
|
+
f ? m = `Rename it: ${a(u, o)}` : i(r, o, "folder") && (m = `Move what it holds into ${o}/, and delete it.`);
|
|
51
|
+
let h = {
|
|
52
|
+
action: "move",
|
|
53
|
+
from: `${u}/`,
|
|
54
|
+
to: `${o}/`
|
|
55
|
+
};
|
|
56
|
+
return d ? e("folder-misplaced", `${u}/`, `${u}/ holds ${d}, and nothing reads it there — ${p}`, m, h) : e("folder-near-miss", `${u}/`, `${u}/ is read by nothing — ${p}`, m, h);
|
|
57
|
+
})), D = (t, n) => {
|
|
58
|
+
if (!i(t, "src/space/index.ts", "file")) return n.some((e) => e.code === "folder-misplaced" && e.autofix?.action === "move" && e.autofix.to === "src/space/") ? [] : v(t, {
|
|
59
|
+
folder: g,
|
|
60
|
+
accepted: ["index.ts"],
|
|
61
|
+
code: "space-entry-missing",
|
|
62
|
+
lost: `the server's entry point and ${c}, which import the space from ${_}, do not start`,
|
|
63
|
+
write: `Write ${_} exporting the space — export const space = { name, permanentUrl, pages } — or bring back the one git has: git checkout -- ${_}`
|
|
64
|
+
});
|
|
65
|
+
let r = b(y.join(t, _), "utf-8"), a = /^\s*export\s+default\b/m.test(r), o = /\bexport\s+(?:const|let|var|function)\s+space\b/.test(r) || /\bexport\s*\{[^}]*\bspace\b[^}]*\}/.test(r);
|
|
66
|
+
return a && !o ? [e("space-default-export", _, `${_} exports the space by default, and it is imported by name — import { space } from './space/index.ts' — so the server's entry point and ${c} find no space.`, "Export it as `export const space = …` instead of `export default …`.")] : [];
|
|
67
|
+
};
|
|
68
|
+
//#endregion
|
|
69
|
+
export { E as nearMissFindings, D as spaceFindings };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The project's layout held to what reads it: every folder the server builds, runs or serves from where the CLI puts
|
|
3
|
+
* it, each with the file it starts at. One check, said the same by the three that read the project — its server at
|
|
4
|
+
* boot (`serveProject`), its authoring (`projectAuthoring`: `npm run author` and the CLI's checks) and `plitzi doctor`,
|
|
5
|
+
* which makes the fixes that have one reading (`autofix`). Pure file system: what a file holds is never imported.
|
|
6
|
+
*
|
|
7
|
+
* An `error` is what keeps a part of the project from running — a plugin the server cannot build, code in a folder
|
|
8
|
+
* nothing reads, settings Node never loads — and stops the server and the authoring; a `warning` works, and should not
|
|
9
|
+
* stay.
|
|
10
|
+
*/
|
|
11
|
+
export { PROJECT_LAYOUT_CODES } from './codes';
|
|
12
|
+
export type { LayoutAutofix, LayoutCode, LayoutFinding, LayoutLevel, ProjectLayoutOptions } from './codes';
|
|
13
|
+
export { checkPluginFolder, elementEntry, pluginEntry, pluginTypeOf } from './plugins';
|
|
14
|
+
export { readVendorPlugin } from './vendor';
|
|
15
|
+
export type { VendorPlugin } from './vendor';
|
|
16
|
+
export { ProjectLayoutError, assertProjectLayout, checkProjectLayout, layoutFindingText } from './check';
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { PROJECT_LAYOUT_CODES as e } from "./codes.mjs";
|
|
2
|
+
import { readVendorPlugin as t } from "./vendor.mjs";
|
|
3
|
+
import { checkPluginFolder as n, elementEntry as r, pluginEntry as i, pluginTypeOf as a } from "./plugins.mjs";
|
|
4
|
+
import { ProjectLayoutError as o, assertProjectLayout as s, checkProjectLayout as c, layoutFindingText as l } from "./check.mjs";
|
|
5
|
+
export { e as PROJECT_LAYOUT_CODES, o as ProjectLayoutError, s as assertProjectLayout, n as checkPluginFolder, c as checkProjectLayout, r as elementEntry, l as layoutFindingText, i as pluginEntry, a as pluginTypeOf, t as readVendorPlugin };
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { LayoutCode, LayoutFinding } from './codes';
|
|
2
|
+
/** `src/plugins/StatCard` is the plugin `statCard`: what the server registers a folder as. */
|
|
3
|
+
export declare const pluginTypeOf: (folder: string) => string;
|
|
4
|
+
/**
|
|
5
|
+
* The file an element's folder is built from, wherever the folder is — its `index.ts`, or `index.tsx` — or nothing
|
|
6
|
+
* when it has neither, or both: what `plitzi plugin pack` builds a folder from, as the server does.
|
|
7
|
+
*/
|
|
8
|
+
export declare const elementEntry: (dir: string) => string | undefined;
|
|
9
|
+
/**
|
|
10
|
+
* The file a folder of `src/plugins/` is built from (`elementEntry`) — or nothing when it is no plugin the server can
|
|
11
|
+
* build: a name that is no element type, no entry, or both. What the server registers, and what `checkPluginFolder`
|
|
12
|
+
* says why of.
|
|
13
|
+
*/
|
|
14
|
+
export declare const pluginEntry: (root: string, folder: string) => string | undefined;
|
|
15
|
+
interface EntryRule {
|
|
16
|
+
/** The folder, relative to the root, with no `/` at its end. */
|
|
17
|
+
folder: string;
|
|
18
|
+
accepted: readonly string[];
|
|
19
|
+
code: Extract<LayoutCode, 'plugin-entry-missing' | 'plugin-functions-entry-missing' | 'functions-entry-missing' | 'runtime-entry-missing' | 'space-entry-missing'>;
|
|
20
|
+
/** What goes wrong without it, after "so": `the server cannot build the plugin card`. */
|
|
21
|
+
lost: string;
|
|
22
|
+
/** What to write, when nothing near it is there to rename. */
|
|
23
|
+
write: string;
|
|
24
|
+
}
|
|
25
|
+
/** The entry of a folder the server builds or runs: there, and only one — or JavaScript, a near name, a level too deep. */
|
|
26
|
+
export declare const entryFindings: (root: string, rule: EntryRule) => LayoutFinding[];
|
|
27
|
+
/**
|
|
28
|
+
* A folder of functions — the project's `src/functions/`, a plugin's `functions/` — is built from every file at its top,
|
|
29
|
+
* each a definition (`isFunctionsDefinitionFile`): one holding code with none there builds nothing. A folder in it is
|
|
30
|
+
* helpers, so code in one alone is one folder too deep.
|
|
31
|
+
*/
|
|
32
|
+
export declare const functionsFindings: (root: string, rule: Omit<EntryRule, "accepted">) => LayoutFinding[];
|
|
33
|
+
/** A folder built from only when it holds code: one with a README or a `.gitkeep` alone is a placeholder. */
|
|
34
|
+
export declare const sourceEntryFindings: (root: string, rule: EntryRule) => LayoutFinding[];
|
|
35
|
+
/**
|
|
36
|
+
* One folder of `src/plugins/` as the server reads it: a name that is a type, the entry it is built from, its server
|
|
37
|
+
* half's entry, and its declaration. What the server says of a folder added while it runs, and what
|
|
38
|
+
* `checkProjectLayout` says of each.
|
|
39
|
+
*/
|
|
40
|
+
export declare const checkPluginFolder: (root: string, folder: string) => LayoutFinding[];
|
|
41
|
+
/**
|
|
42
|
+
* `src/plugins/` and `vendor/plugins/` as the server registers them: each plugin folder (`checkPluginFolder`), a type
|
|
43
|
+
* two folders make, one both a folder and built, every built one's manifest — and a file where a folder belongs.
|
|
44
|
+
*/
|
|
45
|
+
export declare const pluginFindings: (root: string) => LayoutFinding[];
|
|
46
|
+
export {};
|