@griddo/cx 11.7.7-rc.0 → 11.7.7-rc.1
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/README.md +226 -27
- package/build/adapters/gatsby/index.d.ts +4 -0
- package/build/adapters/gatsby/utils.d.ts +22 -0
- package/build/artifacts/index.d.ts +6 -0
- package/build/commands/end-render.d.ts +2 -0
- package/build/commands/move-assets.d.ts +1 -0
- package/build/commands/prepare-domains-render.d.ts +1 -0
- package/build/commands/reset-render.d.ts +2 -0
- package/build/commands/start-render.d.ts +2 -0
- package/build/commands/upload-search-content.d.ts +2 -0
- package/build/constants/endpoints.d.ts +19 -0
- package/build/constants/envs.d.ts +37 -0
- package/build/constants/index.d.ts +57 -0
- package/build/end-render.js +74 -0
- package/build/end-render.js.map +7 -0
- package/build/errors/errors-data.d.ts +22 -0
- package/build/errors/index.d.ts +15 -0
- package/build/index.d.ts +29 -0
- package/build/index.js +73 -0
- package/build/index.js.map +7 -0
- package/build/prepare-domains-render.js +73 -0
- package/build/prepare-domains-render.js.map +7 -0
- package/build/react/Favicon/index.d.ts +5 -0
- package/build/react/Favicon/utils.d.ts +9 -0
- package/build/react/GriddoIntegrations/index.d.ts +20 -0
- package/build/react/GriddoIntegrations/utils.d.ts +26 -0
- package/{react/index.tsx → build/react/index.d.ts} +0 -1
- package/build/react/index.js +3 -0
- package/build/registers/api.d.ts +9 -0
- package/build/registers/gatsby.d.ts +9 -0
- package/build/registers/index.d.ts +3 -0
- package/build/reset-render.js +74 -0
- package/build/reset-render.js.map +7 -0
- package/build/services/auth.d.ts +10 -0
- package/build/services/domains.d.ts +6 -0
- package/build/services/navigation.d.ts +50 -0
- package/build/services/reference-fields.d.ts +20 -0
- package/build/services/register.d.ts +36 -0
- package/build/services/robots.d.ts +19 -0
- package/build/services/settings.d.ts +4 -0
- package/build/services/sites.d.ts +29 -0
- package/build/services/store.d.ts +6 -0
- package/build/start-render.js +100 -0
- package/build/start-render.js.map +7 -0
- package/build/types/api.d.ts +142 -0
- package/build/types/global.d.ts +84 -0
- package/build/types/navigation.d.ts +28 -0
- package/build/types/pages.d.ts +144 -0
- package/build/types/sites.d.ts +57 -0
- package/build/types/templates.d.ts +8 -0
- package/build/upload-search-content.js +74 -0
- package/build/upload-search-content.js.map +7 -0
- package/build/utils/alerts.d.ts +3 -0
- package/build/utils/api.d.ts +23 -0
- package/build/utils/cache.d.ts +35 -0
- package/build/utils/core-utils.d.ts +107 -0
- package/build/utils/create-build-data.d.ts +8 -0
- package/build/utils/domains.d.ts +13 -0
- package/build/utils/folders.d.ts +53 -0
- package/build/utils/health-checks.d.ts +7 -0
- package/build/utils/images.d.ts +16 -0
- package/build/utils/instance.d.ts +21 -0
- package/build/utils/loggin.d.ts +51 -0
- package/build/utils/pages.d.ts +34 -0
- package/build/utils/render.d.ts +13 -0
- package/build/utils/searches.d.ts +15 -0
- package/build/utils/sites.d.ts +31 -0
- package/build/utils/store.d.ts +81 -0
- package/cx.config.d.ts +5 -0
- package/cx.config.js +36 -0
- package/exporter/adapters/gatsby/index.ts +147 -67
- package/exporter/adapters/gatsby/utils.ts +161 -0
- package/exporter/artifacts/README.md +34 -0
- package/exporter/artifacts/index.ts +33 -0
- package/exporter/build.sh +38 -4
- package/exporter/commands/end-render.ts +69 -73
- package/exporter/commands/move-assets.ts +11 -0
- package/exporter/commands/prepare-domains-render.ts +31 -144
- package/exporter/commands/reset-render.ts +1 -10
- package/exporter/commands/start-render.ts +44 -23
- package/exporter/commands/upload-search-content.ts +20 -194
- package/exporter/constants/envs.ts +55 -57
- package/exporter/constants/index.ts +129 -0
- package/exporter/{constants/errors.ts → errors/errors-data.ts} +14 -24
- package/exporter/{utils/errors.ts → errors/index.ts} +9 -10
- package/exporter/index.ts +82 -0
- package/{react → exporter/react}/Favicon/index.tsx +7 -1
- package/{react → exporter/react}/GriddoIntegrations/index.tsx +14 -6
- package/{react → exporter/react}/GriddoIntegrations/utils.ts +9 -4
- package/exporter/react/index.tsx +11 -0
- package/exporter/registers/api.ts +14 -0
- package/exporter/registers/gatsby.ts +14 -0
- package/exporter/registers/index.ts +4 -0
- package/exporter/services/auth.ts +6 -7
- package/exporter/services/domains.ts +16 -0
- package/exporter/services/navigation.ts +10 -4
- package/exporter/services/reference-fields.ts +23 -8
- package/exporter/services/register.ts +113 -0
- package/exporter/services/robots.ts +16 -9
- package/exporter/services/settings.ts +17 -0
- package/exporter/services/sites.ts +24 -35
- package/exporter/services/store.ts +78 -120
- package/exporter/types/api.ts +27 -24
- package/exporter/types/global.ts +10 -7
- package/exporter/types/navigation.ts +1 -1
- package/exporter/types/pages.ts +3 -2
- package/exporter/types/sites.ts +2 -1
- package/exporter/utils/alerts.ts +29 -0
- package/exporter/utils/api.ts +82 -46
- package/exporter/utils/cache.ts +62 -37
- package/exporter/utils/core-utils.ts +248 -129
- package/exporter/utils/create-build-data.ts +17 -0
- package/exporter/utils/domains.ts +7 -10
- package/exporter/utils/folders.ts +95 -187
- package/exporter/utils/health-checks.ts +64 -0
- package/exporter/utils/images.ts +6 -1
- package/exporter/utils/instance.ts +12 -9
- package/exporter/utils/loggin.ts +91 -32
- package/exporter/utils/pages.ts +88 -23
- package/exporter/utils/render.ts +48 -149
- package/exporter/utils/searches.ts +156 -0
- package/exporter/utils/sites.ts +90 -81
- package/exporter/utils/store.ts +180 -87
- package/gatsby-browser.tsx +58 -41
- package/gatsby-config.ts +12 -6
- package/gatsby-node.ts +77 -15
- package/gatsby-ssr.tsx +1 -2
- package/package.json +78 -36
- package/src/README.md +7 -0
- package/src/components/Head.tsx +46 -13
- package/src/components/template.tsx +30 -8
- package/src/gatsby-node-utils.ts +2 -91
- package/src/html.tsx +11 -2
- package/src/types.ts +5 -5
- package/start-render.js +7 -0
- package/tsconfig.json +3 -5
- package/build/adapters/gatsby/actions/clean.js +0 -10
- package/build/adapters/gatsby/actions/clean.js.map +0 -1
- package/build/adapters/gatsby/actions/close.js +0 -12
- package/build/adapters/gatsby/actions/close.js.map +0 -1
- package/build/adapters/gatsby/actions/data.js +0 -18
- package/build/adapters/gatsby/actions/data.js.map +0 -1
- package/build/adapters/gatsby/actions/healthCheck.js +0 -10
- package/build/adapters/gatsby/actions/healthCheck.js.map +0 -1
- package/build/adapters/gatsby/actions/init.js +0 -9
- package/build/adapters/gatsby/actions/init.js.map +0 -1
- package/build/adapters/gatsby/actions/meta.js +0 -14
- package/build/adapters/gatsby/actions/meta.js.map +0 -1
- package/build/adapters/gatsby/actions/prepare.js +0 -9
- package/build/adapters/gatsby/actions/prepare.js.map +0 -1
- package/build/adapters/gatsby/actions/relocation.js +0 -15
- package/build/adapters/gatsby/actions/relocation.js.map +0 -1
- package/build/adapters/gatsby/actions/restore.js +0 -26
- package/build/adapters/gatsby/actions/restore.js.map +0 -1
- package/build/adapters/gatsby/actions/ssg.js +0 -9
- package/build/adapters/gatsby/actions/ssg.js.map +0 -1
- package/build/adapters/gatsby/actions/sync.js +0 -51
- package/build/adapters/gatsby/actions/sync.js.map +0 -1
- package/build/adapters/gatsby/index.js +0 -79
- package/build/adapters/gatsby/index.js.map +0 -1
- package/build/adapters/gatsby/shared/context.js +0 -31
- package/build/adapters/gatsby/shared/context.js.map +0 -1
- package/build/adapters/gatsby/shared/diff-assets.js +0 -101
- package/build/adapters/gatsby/shared/diff-assets.js.map +0 -1
- package/build/adapters/gatsby/shared/extract-assets.js +0 -58
- package/build/adapters/gatsby/shared/extract-assets.js.map +0 -1
- package/build/adapters/gatsby/shared/gatsby-build.js +0 -49
- package/build/adapters/gatsby/shared/gatsby-build.js.map +0 -1
- package/build/adapters/gatsby/shared/sync-render.js +0 -210
- package/build/adapters/gatsby/shared/sync-render.js.map +0 -1
- package/build/adapters/gatsby/shared/types.js +0 -3
- package/build/adapters/gatsby/shared/types.js.map +0 -1
- package/build/commands/end-render.js +0 -88
- package/build/commands/end-render.js.map +0 -1
- package/build/commands/prepare-assets-directory.js +0 -32
- package/build/commands/prepare-assets-directory.js.map +0 -1
- package/build/commands/prepare-domains-render.js +0 -133
- package/build/commands/prepare-domains-render.js.map +0 -1
- package/build/commands/reset-render.js +0 -22
- package/build/commands/reset-render.js.map +0 -1
- package/build/commands/start-render.js +0 -45
- package/build/commands/start-render.js.map +0 -1
- package/build/commands/upload-search-content.js +0 -180
- package/build/commands/upload-search-content.js.map +0 -1
- package/build/constants/endpoints.js +0 -42
- package/build/constants/endpoints.js.map +0 -1
- package/build/constants/envs.js +0 -68
- package/build/constants/envs.js.map +0 -1
- package/build/constants/errors.js +0 -81
- package/build/constants/errors.js.map +0 -1
- package/build/services/auth.js +0 -40
- package/build/services/auth.js.map +0 -1
- package/build/services/db-class.js +0 -49
- package/build/services/db-class.js.map +0 -1
- package/build/services/db.js +0 -34
- package/build/services/db.js.map +0 -1
- package/build/services/navigation.js +0 -96
- package/build/services/navigation.js.map +0 -1
- package/build/services/reference-fields.js +0 -131
- package/build/services/reference-fields.js.map +0 -1
- package/build/services/robots.js +0 -60
- package/build/services/robots.js.map +0 -1
- package/build/services/sites.js +0 -109
- package/build/services/sites.js.map +0 -1
- package/build/services/store.js +0 -282
- package/build/services/store.js.map +0 -1
- package/build/types/api.js +0 -3
- package/build/types/api.js.map +0 -1
- package/build/types/global.js +0 -3
- package/build/types/global.js.map +0 -1
- package/build/types/navigation.js +0 -3
- package/build/types/navigation.js.map +0 -1
- package/build/types/pages.js +0 -3
- package/build/types/pages.js.map +0 -1
- package/build/types/render.js +0 -10
- package/build/types/render.js.map +0 -1
- package/build/types/sites.js +0 -3
- package/build/types/sites.js.map +0 -1
- package/build/types/templates.js +0 -3
- package/build/types/templates.js.map +0 -1
- package/build/utils/api.js +0 -161
- package/build/utils/api.js.map +0 -1
- package/build/utils/artifacts.js +0 -34
- package/build/utils/artifacts.js.map +0 -1
- package/build/utils/brush.js +0 -30
- package/build/utils/brush.js.map +0 -1
- package/build/utils/cache.js +0 -106
- package/build/utils/cache.js.map +0 -1
- package/build/utils/check-health.js +0 -68
- package/build/utils/check-health.js.map +0 -1
- package/build/utils/core-utils.js +0 -283
- package/build/utils/core-utils.js.map +0 -1
- package/build/utils/domains.js +0 -37
- package/build/utils/domains.js.map +0 -1
- package/build/utils/errors.js +0 -30
- package/build/utils/errors.js.map +0 -1
- package/build/utils/folders.js +0 -362
- package/build/utils/folders.js.map +0 -1
- package/build/utils/images.js +0 -45
- package/build/utils/images.js.map +0 -1
- package/build/utils/instance.js +0 -66
- package/build/utils/instance.js.map +0 -1
- package/build/utils/loggin.js +0 -108
- package/build/utils/loggin.js.map +0 -1
- package/build/utils/pages.js +0 -359
- package/build/utils/pages.js.map +0 -1
- package/build/utils/render.js +0 -144
- package/build/utils/render.js.map +0 -1
- package/build/utils/sites.js +0 -240
- package/build/utils/sites.js.map +0 -1
- package/build/utils/store.js +0 -193
- package/build/utils/store.js.map +0 -1
- package/exporter/adapters/gatsby/actions/clean.ts +0 -14
- package/exporter/adapters/gatsby/actions/close.ts +0 -17
- package/exporter/adapters/gatsby/actions/data.ts +0 -25
- package/exporter/adapters/gatsby/actions/healthCheck.ts +0 -10
- package/exporter/adapters/gatsby/actions/init.ts +0 -12
- package/exporter/adapters/gatsby/actions/meta.ts +0 -18
- package/exporter/adapters/gatsby/actions/prepare.ts +0 -9
- package/exporter/adapters/gatsby/actions/relocation.ts +0 -15
- package/exporter/adapters/gatsby/actions/restore.ts +0 -36
- package/exporter/adapters/gatsby/actions/ssg.ts +0 -12
- package/exporter/adapters/gatsby/actions/sync.ts +0 -71
- package/exporter/adapters/gatsby/shared/context.ts +0 -50
- package/exporter/adapters/gatsby/shared/diff-assets.ts +0 -113
- package/exporter/adapters/gatsby/shared/extract-assets.ts +0 -61
- package/exporter/adapters/gatsby/shared/gatsby-build.ts +0 -54
- package/exporter/adapters/gatsby/shared/sync-render.ts +0 -276
- package/exporter/adapters/gatsby/shared/types.ts +0 -35
- package/exporter/build-esbuild.noop +0 -42
- package/exporter/commands/prepare-assets-directory.ts +0 -33
- package/exporter/services/db-class.ts +0 -54
- package/exporter/services/db.ts +0 -32
- package/exporter/types/render.ts +0 -59
- package/exporter/utils/artifacts.ts +0 -34
- package/exporter/utils/brush.ts +0 -34
- package/exporter/utils/check-health.ts +0 -79
- package/plugins/gatsby-plugin-svgr-loader/gatsby-node.js +0 -55
- package/plugins/gatsby-plugin-svgr-loader/package.json +0 -8
- /package/{react → exporter/react}/Favicon/utils.ts +0 -0
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
import fsp from "node:fs/promises";
|
|
1
|
+
import fs from "node:fs";
|
|
4
2
|
import path from "node:path";
|
|
5
3
|
|
|
6
|
-
import {
|
|
4
|
+
import fsx, { type MakeDirectoryOptions } from "fs-extra";
|
|
7
5
|
|
|
8
|
-
import {
|
|
9
|
-
import { walkStore } from "./core-utils";
|
|
10
|
-
import { throwError } from "./errors";
|
|
6
|
+
import { throwError } from "../errors";
|
|
7
|
+
import { getConfig, walkStore } from "./core-utils";
|
|
11
8
|
import { verboseLog } from "./loggin";
|
|
9
|
+
import { ArtifactError } from "../errors/errors-data";
|
|
10
|
+
|
|
11
|
+
const config = getConfig();
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
14
|
* Remove an empty directory from the basePath recursively.
|
|
@@ -16,34 +16,37 @@ import { verboseLog } from "./loggin";
|
|
|
16
16
|
*
|
|
17
17
|
* @param baseDir - The base directory.
|
|
18
18
|
*/
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
function deleteDisposableSiteDirs() {
|
|
20
|
+
const { __cx } = config.paths();
|
|
21
|
+
const baseDir = path.join(__cx, "dist");
|
|
22
|
+
|
|
23
|
+
if (!fs.existsSync(baseDir)) {
|
|
21
24
|
return;
|
|
22
25
|
}
|
|
23
26
|
|
|
24
|
-
const sitesDirs =
|
|
25
|
-
|
|
26
|
-
|
|
27
|
+
const sitesDirs = fs
|
|
28
|
+
.readdirSync(baseDir, { withFileTypes: true })
|
|
29
|
+
.filter((file) => file.isDirectory());
|
|
27
30
|
|
|
28
31
|
for (const siteDir of sitesDirs) {
|
|
29
32
|
const sitePath = path.join(baseDir, siteDir.name);
|
|
30
|
-
if (
|
|
31
|
-
|
|
33
|
+
if (siteIsEmpty(sitePath)) {
|
|
34
|
+
fs.rmSync(sitePath, { recursive: true });
|
|
32
35
|
}
|
|
33
36
|
}
|
|
34
37
|
}
|
|
35
38
|
|
|
36
39
|
/**
|
|
37
|
-
* Creates multiple
|
|
40
|
+
* Creates multiple directories.
|
|
38
41
|
*
|
|
39
42
|
* @param dirs - An array of directory paths.
|
|
40
43
|
* @param options - Same option as `fs.mkdirSync()`
|
|
41
44
|
*/
|
|
42
|
-
|
|
45
|
+
function createArtifacts(dirs: Array<string>, options?: MakeDirectoryOptions) {
|
|
43
46
|
for (const dir of dirs) {
|
|
44
47
|
try {
|
|
45
|
-
if (!(
|
|
46
|
-
|
|
48
|
+
if (!fs.existsSync(dir)) {
|
|
49
|
+
fs.mkdirSync(dir, { recursive: true, ...options });
|
|
47
50
|
verboseLog(`create directory: ${dir}`);
|
|
48
51
|
}
|
|
49
52
|
} catch (error) {
|
|
@@ -52,10 +55,10 @@ async function createDirs(dirs: Array<string>, options?: MakeDirectoryOptions) {
|
|
|
52
55
|
}
|
|
53
56
|
}
|
|
54
57
|
|
|
55
|
-
|
|
58
|
+
function renameArtifact(src: string, dst: string) {
|
|
56
59
|
try {
|
|
57
|
-
if (
|
|
58
|
-
|
|
60
|
+
if (fs.existsSync(src)) {
|
|
61
|
+
fs.renameSync(src, dst);
|
|
59
62
|
verboseLog(`rename ${src} to ${dst}`);
|
|
60
63
|
}
|
|
61
64
|
} catch (error) {
|
|
@@ -71,7 +74,7 @@ async function renamePath(src: string, dst: string) {
|
|
|
71
74
|
* @param dirs - Directories to copy.
|
|
72
75
|
* @param options.withBackup - Create a previous backup before copy.
|
|
73
76
|
*/
|
|
74
|
-
|
|
77
|
+
function copyArtifacts(
|
|
75
78
|
src: string,
|
|
76
79
|
dst: string,
|
|
77
80
|
dirs: Array<string>,
|
|
@@ -85,40 +88,42 @@ async function copyDirs(
|
|
|
85
88
|
const dstCompose = path.join(dst, dir);
|
|
86
89
|
|
|
87
90
|
// The dir we want to copy, doesn't exist.
|
|
88
|
-
if (!(
|
|
89
|
-
console.log(
|
|
91
|
+
if (!fsx.existsSync(srcCompose)) {
|
|
92
|
+
console.log(
|
|
93
|
+
`(Maybe first render) Source directory does not exist: ${srcCompose}`,
|
|
94
|
+
);
|
|
90
95
|
continue;
|
|
91
96
|
}
|
|
92
97
|
|
|
93
98
|
// Create the backup
|
|
94
99
|
if (withBackup) {
|
|
95
|
-
|
|
100
|
+
createBackup(dstCompose);
|
|
96
101
|
verboseLog(`create backup: ${dstCompose}`);
|
|
97
102
|
}
|
|
98
103
|
|
|
99
104
|
// Copy directory
|
|
100
105
|
try {
|
|
101
106
|
// First clean destination
|
|
102
|
-
if (
|
|
103
|
-
|
|
107
|
+
if (fsx.existsSync(dstCompose)) {
|
|
108
|
+
fs.rmSync(dstCompose, { recursive: true, force: true });
|
|
104
109
|
verboseLog(`clean destination: ${dstCompose}`);
|
|
105
110
|
}
|
|
106
111
|
|
|
107
112
|
// Then copy src to dst
|
|
108
|
-
|
|
113
|
+
fs.cpSync(srcCompose, dstCompose, {
|
|
109
114
|
recursive: true,
|
|
110
115
|
preserveTimestamps: true,
|
|
111
116
|
});
|
|
112
117
|
verboseLog(`copy: ${srcCompose} to ${dstCompose}`);
|
|
113
118
|
|
|
114
119
|
if (withBackup) {
|
|
115
|
-
|
|
120
|
+
deleteBackup(dstCompose);
|
|
116
121
|
verboseLog(`delete backup: ${dstCompose}`);
|
|
117
122
|
}
|
|
118
123
|
} catch (error) {
|
|
119
124
|
if (withBackup) {
|
|
120
|
-
|
|
121
|
-
|
|
125
|
+
restoreBackup(dstCompose);
|
|
126
|
+
console.log("Backup has been restored.");
|
|
122
127
|
}
|
|
123
128
|
|
|
124
129
|
throwError(ArtifactError, error);
|
|
@@ -134,7 +139,7 @@ async function copyDirs(
|
|
|
134
139
|
* @param dirs - Directories to move.
|
|
135
140
|
* @param options - Options.
|
|
136
141
|
*/
|
|
137
|
-
|
|
142
|
+
function moveArtifacts(
|
|
138
143
|
src: string,
|
|
139
144
|
dst: string,
|
|
140
145
|
dirs: Array<string>,
|
|
@@ -146,29 +151,29 @@ async function moveDirs(
|
|
|
146
151
|
const srcCompose = path.join(src, dir);
|
|
147
152
|
const dstCompose = path.join(dst, dir);
|
|
148
153
|
|
|
149
|
-
if (!(
|
|
154
|
+
if (!fsx.existsSync(srcCompose)) {
|
|
150
155
|
continue;
|
|
151
156
|
}
|
|
152
157
|
|
|
153
158
|
if (withBackup) {
|
|
154
|
-
|
|
159
|
+
createBackup(dstCompose);
|
|
155
160
|
}
|
|
156
161
|
|
|
157
162
|
try {
|
|
158
163
|
// Clean destination
|
|
159
|
-
if (override && (
|
|
160
|
-
|
|
164
|
+
if (override && fsx.existsSync(dstCompose)) {
|
|
165
|
+
fs.rmSync(dstCompose, { recursive: true, force: true });
|
|
161
166
|
}
|
|
162
167
|
|
|
163
|
-
|
|
168
|
+
fs.renameSync(srcCompose, dstCompose);
|
|
164
169
|
verboseLog(`moved: ${srcCompose} to ${dstCompose}`);
|
|
165
170
|
|
|
166
171
|
if (withBackup) {
|
|
167
|
-
|
|
172
|
+
deleteBackup(dstCompose);
|
|
168
173
|
}
|
|
169
174
|
} catch (error) {
|
|
170
175
|
if (withBackup) {
|
|
171
|
-
|
|
176
|
+
restoreBackup(dstCompose);
|
|
172
177
|
console.log("Backup has been restored.");
|
|
173
178
|
}
|
|
174
179
|
|
|
@@ -180,23 +185,30 @@ async function moveDirs(
|
|
|
180
185
|
/**
|
|
181
186
|
* Removes multiple artifact directories.
|
|
182
187
|
*
|
|
183
|
-
* @param
|
|
188
|
+
* @param artifacts - An array of artifact directory paths.
|
|
184
189
|
*/
|
|
185
|
-
|
|
186
|
-
for (const dir of
|
|
190
|
+
function removeArtifacts(artifacts: Array<string>) {
|
|
191
|
+
for (const dir of artifacts) {
|
|
192
|
+
if (!dir) {
|
|
193
|
+
continue;
|
|
194
|
+
}
|
|
195
|
+
|
|
187
196
|
try {
|
|
188
|
-
|
|
189
|
-
|
|
197
|
+
if (fsx.existsSync(dir)) {
|
|
198
|
+
const kind = fs.statSync(dir).isDirectory() ? "dir" : "file";
|
|
199
|
+
fs.rmSync(dir, { recursive: true, force: true });
|
|
200
|
+
verboseLog(`artifact (${kind}) removed: ${dir}`);
|
|
201
|
+
}
|
|
190
202
|
} catch (error) {
|
|
191
203
|
throwError(ArtifactError, error);
|
|
192
204
|
}
|
|
193
205
|
}
|
|
194
206
|
}
|
|
195
207
|
|
|
196
|
-
|
|
208
|
+
function restoreBackup(src: string, suffix = "-BACKUP") {
|
|
197
209
|
const dst = src + suffix;
|
|
198
210
|
try {
|
|
199
|
-
|
|
211
|
+
fs.renameSync(dst, src);
|
|
200
212
|
console.log(`Backup ${dst} has been restored`);
|
|
201
213
|
} catch (error) {
|
|
202
214
|
console.log(error);
|
|
@@ -204,37 +216,37 @@ async function restoreBackup(src: string, suffix = "-BACKUP") {
|
|
|
204
216
|
}
|
|
205
217
|
}
|
|
206
218
|
|
|
207
|
-
|
|
219
|
+
function deleteBackup(src: string, suffix = "-BACKUP") {
|
|
208
220
|
const dst = src + suffix;
|
|
209
221
|
|
|
210
|
-
if (!(
|
|
222
|
+
if (!fsx.existsSync(dst)) {
|
|
211
223
|
return;
|
|
212
224
|
}
|
|
213
225
|
|
|
214
226
|
try {
|
|
215
|
-
|
|
216
|
-
|
|
227
|
+
fs.rmSync(dst, { recursive: true, force: true });
|
|
228
|
+
console.log(`Backup ${dst} has been deleted`);
|
|
217
229
|
} catch (error) {
|
|
218
230
|
console.log(error);
|
|
219
231
|
throw new Error(`Error while delete ${dst} backup`);
|
|
220
232
|
}
|
|
221
233
|
}
|
|
222
234
|
|
|
223
|
-
|
|
235
|
+
function createBackup(src: string, suffix = "-BACKUP") {
|
|
224
236
|
const dst = src + suffix;
|
|
225
237
|
|
|
226
|
-
if (!(
|
|
238
|
+
if (!fsx.existsSync(src)) {
|
|
227
239
|
return;
|
|
228
240
|
}
|
|
229
241
|
|
|
230
|
-
if (
|
|
242
|
+
if (fsx.existsSync(dst)) {
|
|
231
243
|
console.log(`Destination ${dst} already exists`);
|
|
232
244
|
return;
|
|
233
245
|
}
|
|
234
246
|
|
|
235
247
|
try {
|
|
236
|
-
|
|
237
|
-
|
|
248
|
+
fs.renameSync(src, dst);
|
|
249
|
+
console.log(`Backup of ${src} has been created in ${dst}`);
|
|
238
250
|
} catch (error) {
|
|
239
251
|
console.log(`Error while coping ${src} to ${dst} backup`);
|
|
240
252
|
throwError(ArtifactError, error);
|
|
@@ -242,23 +254,25 @@ async function createBackup(src: string, suffix = "-BACKUP") {
|
|
|
242
254
|
}
|
|
243
255
|
|
|
244
256
|
/**
|
|
245
|
-
* Elimina todas las páginas del store (de todos los sites) cuyo nombre empiece
|
|
246
|
-
*
|
|
247
|
-
*
|
|
248
|
-
* en la página "madre". La solución por ahora es borrarlas del store y
|
|
249
|
-
* rehacerlas en todos los renders.
|
|
257
|
+
* Elimina todas las páginas del store (de todos los sites) cuyo nombre empiece con un guión "-".
|
|
258
|
+
* Estas páginas son "virtuales" y no tienen ids desde API por lo que mantenerlas en el store es un problema cuando se hacen modificaciones en la página "madre".
|
|
259
|
+
* La solución por ahora es borrarlas del store y rehacerlas en todos los renders.
|
|
250
260
|
*/
|
|
251
|
-
async function
|
|
261
|
+
async function removeVirtualPagesFromStore() {
|
|
262
|
+
const { __cx } = config.paths();
|
|
263
|
+
const storePath = path.join(__cx, "store");
|
|
264
|
+
|
|
252
265
|
try {
|
|
253
|
-
|
|
254
|
-
|
|
266
|
+
const allJsonPageFilesPath = walkStore(storePath);
|
|
267
|
+
|
|
268
|
+
for (const filePath of allJsonPageFilesPath) {
|
|
255
269
|
if (path.basename(filePath).startsWith("-")) {
|
|
256
|
-
|
|
270
|
+
fs.unlinkSync(filePath);
|
|
257
271
|
}
|
|
258
272
|
}
|
|
259
273
|
} catch (error) {
|
|
260
274
|
console.info(
|
|
261
|
-
|
|
275
|
+
"`store` folder does not exist. Skipping multipage or static list template cleaning.",
|
|
262
276
|
error,
|
|
263
277
|
);
|
|
264
278
|
}
|
|
@@ -267,13 +281,15 @@ async function removeVirtualPages(dirPath: string) {
|
|
|
267
281
|
/**
|
|
268
282
|
* Return true if the site folder is empty or only has xml files. (Recursively)
|
|
269
283
|
*/
|
|
270
|
-
|
|
271
|
-
const siteFiles =
|
|
272
|
-
|
|
284
|
+
function siteIsEmpty(sitePath: string) {
|
|
285
|
+
const siteFiles = fs
|
|
286
|
+
.readdirSync(sitePath, {
|
|
273
287
|
withFileTypes: true,
|
|
274
288
|
recursive: true,
|
|
275
289
|
})
|
|
276
|
-
|
|
290
|
+
.filter(
|
|
291
|
+
(file) => file.isFile() && !path.basename(file.name).startsWith("."),
|
|
292
|
+
);
|
|
277
293
|
|
|
278
294
|
const xmlFiles = siteFiles.filter((file) => file.name.endsWith(".xml"));
|
|
279
295
|
|
|
@@ -282,131 +298,23 @@ async function siteIsEmpty(sitePath: string) {
|
|
|
282
298
|
}
|
|
283
299
|
}
|
|
284
300
|
|
|
285
|
-
|
|
301
|
+
function prependFileSync(filePath: string, content: string) {
|
|
286
302
|
let currentContent = "";
|
|
287
303
|
|
|
288
|
-
if (
|
|
289
|
-
currentContent =
|
|
304
|
+
if (fs.existsSync(filePath)) {
|
|
305
|
+
currentContent = fs.readFileSync(filePath, "utf8");
|
|
290
306
|
}
|
|
291
307
|
|
|
292
|
-
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
/**
|
|
296
|
-
* Delete empty directories from the given directory in a recursive way.
|
|
297
|
-
*/
|
|
298
|
-
async function deleteEmptyDirectories(dirPath: string) {
|
|
299
|
-
try {
|
|
300
|
-
const stats = await fsp.stat(dirPath);
|
|
301
|
-
|
|
302
|
-
// Si no es un directorio, no hacemos nada
|
|
303
|
-
if (!stats.isDirectory()) {
|
|
304
|
-
return;
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
let filesInDirectory: string[];
|
|
308
|
-
try {
|
|
309
|
-
filesInDirectory = await fsp.readdir(dirPath);
|
|
310
|
-
} catch (err: any) {
|
|
311
|
-
// Si el directorio no existe o no se puede leer (ej. permisos), lo saltamos.
|
|
312
|
-
if (err.code === "ENOENT") {
|
|
313
|
-
console.warn(`The directory "${dirPath}" does not exist, skipping it.`);
|
|
314
|
-
return;
|
|
315
|
-
}
|
|
316
|
-
console.error(`Error al leer el directorio "${dirPath}":`, err);
|
|
317
|
-
throw err; // Re-lanza el error para que sea manejado por el llamador
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
// Recorrer los contenidos del directorio
|
|
321
|
-
for (const file of filesInDirectory) {
|
|
322
|
-
const fullPath = path.join(dirPath, file);
|
|
323
|
-
await deleteEmptyDirectories(fullPath); // Llamada recursiva síncrona
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
// Después de procesar todos los subdirectorios, verifica si el directorio actual está vacío
|
|
327
|
-
const remainingFiles = await fsp.readdir(dirPath);
|
|
328
|
-
|
|
329
|
-
if (remainingFiles.length === 0) {
|
|
330
|
-
try {
|
|
331
|
-
await fsp.rmdir(dirPath);
|
|
332
|
-
verboseLog(`Remove empty directory: ${dirPath}`);
|
|
333
|
-
} catch (err: any) {
|
|
334
|
-
// Puede que haya habido un problema de concurrencia o permisos
|
|
335
|
-
if (err.code === "ENOENT") {
|
|
336
|
-
console.warn(
|
|
337
|
-
`El directorio "${dirPath}" ya no existe. Posiblemente fue borrado por otra operación.`,
|
|
338
|
-
);
|
|
339
|
-
} else {
|
|
340
|
-
console.error(`Error al borrar el directorio "${dirPath}":`, err);
|
|
341
|
-
}
|
|
342
|
-
}
|
|
343
|
-
}
|
|
344
|
-
} catch (err: any) {
|
|
345
|
-
if (err.code === "ENOENT") {
|
|
346
|
-
// El directorio ya no existe, no es un error para nosotros en este contexto
|
|
347
|
-
console.warn(`The directory "${dirPath}" does not exist or has already been processed.`);
|
|
348
|
-
} else {
|
|
349
|
-
console.error(`General error general while processing "${dirPath}":`, err);
|
|
350
|
-
throw err;
|
|
351
|
-
}
|
|
352
|
-
}
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
async function pathExists(dir: string) {
|
|
356
|
-
try {
|
|
357
|
-
await fsp.access(dir);
|
|
358
|
-
return true;
|
|
359
|
-
} catch {
|
|
360
|
-
return false;
|
|
361
|
-
}
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
async function pkgDir(options?: { readonly cwd?: string }) {
|
|
365
|
-
const { cwd } = options || {};
|
|
366
|
-
const filePath = await findUp("package.json", { cwd });
|
|
367
|
-
return filePath && path.dirname(filePath);
|
|
368
|
-
}
|
|
369
|
-
|
|
370
|
-
function pkgDirSync(options?: { readonly cwd?: string }) {
|
|
371
|
-
const { cwd } = options || {};
|
|
372
|
-
const filePath = findUpSync("package.json", { cwd });
|
|
373
|
-
return filePath && path.dirname(filePath);
|
|
374
|
-
}
|
|
375
|
-
|
|
376
|
-
/**
|
|
377
|
-
* Busca recursivamente archivos que terminen con un sufijo específico dentro de un directorio.
|
|
378
|
-
* Esta función es un generador asíncrono, lo que la hace muy eficiente en uso de memoria.
|
|
379
|
-
*
|
|
380
|
-
* @param dir El directorio base para comenzar la búsqueda.
|
|
381
|
-
* @param suffix El sufijo con el que deben terminar los nombres de archivo (ej: 'page-data.json').
|
|
382
|
-
* @returns Un generador asíncrono que produce la ruta completa de cada archivo encontrado.
|
|
383
|
-
* @throws Si el directorio inicial `dir` no existe o no se puede leer.
|
|
384
|
-
*/
|
|
385
|
-
async function* findFilesBySuffix(dir: string, suffix: string): AsyncGenerator<string> {
|
|
386
|
-
const dirHandle = await fsp.opendir(dir);
|
|
387
|
-
for await (const item of dirHandle) {
|
|
388
|
-
const fullPath = path.join(dir, item.name);
|
|
389
|
-
if (item.isDirectory()) {
|
|
390
|
-
// yield* para encadenar otro generator.
|
|
391
|
-
yield* findFilesBySuffix(fullPath, suffix);
|
|
392
|
-
} else if (item.isFile() && item.name.endsWith(suffix)) {
|
|
393
|
-
yield fullPath;
|
|
394
|
-
}
|
|
395
|
-
}
|
|
308
|
+
fs.writeFileSync(filePath, content + currentContent, "utf8");
|
|
396
309
|
}
|
|
397
310
|
|
|
398
311
|
export {
|
|
399
|
-
|
|
400
|
-
|
|
312
|
+
copyArtifacts,
|
|
313
|
+
createArtifacts,
|
|
401
314
|
deleteDisposableSiteDirs,
|
|
402
|
-
|
|
403
|
-
findFilesBySuffix,
|
|
404
|
-
moveDirs,
|
|
405
|
-
pathExists,
|
|
406
|
-
pkgDir,
|
|
407
|
-
pkgDirSync,
|
|
315
|
+
moveArtifacts,
|
|
408
316
|
prependFileSync,
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
317
|
+
removeArtifacts,
|
|
318
|
+
removeVirtualPagesFromStore,
|
|
319
|
+
renameArtifact,
|
|
412
320
|
};
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { boxLog } from "./loggin";
|
|
2
|
+
import { envs } from "../constants";
|
|
3
|
+
|
|
4
|
+
const GRIDDO_ENVS_VARS: ReadonlyArray<string> = [];
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Check if the environment is secure to launch a render.
|
|
8
|
+
* If something fails then log an error message and exit from the process.
|
|
9
|
+
* Otherwise just return true.
|
|
10
|
+
*/
|
|
11
|
+
function checkRenderHealthOrExit() {
|
|
12
|
+
// Bypass the check using this env var, handy for local renders.
|
|
13
|
+
if (envs.GRIDDO_SKIP_BUILD_CHECKS) {
|
|
14
|
+
console.info("Build health check skipped");
|
|
15
|
+
|
|
16
|
+
return true;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// Checklist
|
|
20
|
+
const envsVars = checkEnvsVars(GRIDDO_ENVS_VARS);
|
|
21
|
+
|
|
22
|
+
// Render is safe if...
|
|
23
|
+
const renderingIsSave = envsVars;
|
|
24
|
+
|
|
25
|
+
// The environment is suitable for a build-render
|
|
26
|
+
if (renderingIsSave) {
|
|
27
|
+
console.info("Build health check passed");
|
|
28
|
+
|
|
29
|
+
return true;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// Error
|
|
33
|
+
boxLog(
|
|
34
|
+
"Error. The environment is not suitable for a build.",
|
|
35
|
+
"Not valid environment",
|
|
36
|
+
);
|
|
37
|
+
process.exit(1);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Check if a list of environments variables exist with any value.
|
|
42
|
+
*
|
|
43
|
+
* @todo Also check the value.
|
|
44
|
+
* @param envs An array of environments variables
|
|
45
|
+
* @returns exists with (1) if there are missing envs vars
|
|
46
|
+
*/
|
|
47
|
+
function checkEnvsVars(envs: ReadonlyArray<string>) {
|
|
48
|
+
const missingEnvs = envs.filter((envName) => {
|
|
49
|
+
return !process.env[envName];
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
if (missingEnvs.length) {
|
|
53
|
+
const missingEnvsMsg = missingEnvs.join("\n");
|
|
54
|
+
console.error(
|
|
55
|
+
`Env check failed. These envs vars are missing: \n\n${missingEnvsMsg}`,
|
|
56
|
+
);
|
|
57
|
+
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return true;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export { checkRenderHealthOrExit };
|
package/exporter/utils/images.ts
CHANGED
|
@@ -13,7 +13,12 @@ import type { Fields } from "@griddo/core";
|
|
|
13
13
|
* formatImage("https://images.griddo.io/tree", 300, 200, "jpg")
|
|
14
14
|
* // https://images.griddo.io/tree/w/300/h/200/f/jpg
|
|
15
15
|
*/
|
|
16
|
-
function formatImage(
|
|
16
|
+
function formatImage(
|
|
17
|
+
image: Fields.Image | string,
|
|
18
|
+
width: number,
|
|
19
|
+
height: number,
|
|
20
|
+
format = "jpg",
|
|
21
|
+
) {
|
|
17
22
|
const url = typeof image === "string" ? image : image?.url;
|
|
18
23
|
|
|
19
24
|
if (!url) {
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import path from "node:path";
|
|
2
2
|
|
|
3
|
-
import
|
|
3
|
+
import findUp from "find-up";
|
|
4
|
+
import pkgDir from "pkg-dir";
|
|
4
5
|
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import { pkgDirSync } from "./folders";
|
|
6
|
+
import { throwError } from "../errors";
|
|
7
|
+
import { NoJSConfigFileFound } from "../errors/errors-data";
|
|
8
8
|
|
|
9
9
|
// Consts
|
|
10
10
|
const isComponentLibrary = __dirname.includes("node_modules");
|
|
@@ -17,18 +17,22 @@ const componentLibraryPathAlias = getComponentsLibAliases();
|
|
|
17
17
|
*/
|
|
18
18
|
function resolveComponentsPath(customPath = "") {
|
|
19
19
|
return isComponentLibrary
|
|
20
|
-
? path.resolve(
|
|
21
|
-
: path.resolve(
|
|
20
|
+
? path.resolve(pkgDir.sync(__dirname) as string, "../../../", customPath)
|
|
21
|
+
: path.resolve(
|
|
22
|
+
pkgDir.sync(__dirname) as string,
|
|
23
|
+
"../griddo-components",
|
|
24
|
+
customPath,
|
|
25
|
+
);
|
|
22
26
|
}
|
|
23
27
|
|
|
24
28
|
/**
|
|
25
29
|
* Return the instance or monorepo components {t|j}sconfig.json file.
|
|
26
30
|
*/
|
|
27
31
|
function getComponentsJSConfig() {
|
|
28
|
-
const jsConfigPath =
|
|
32
|
+
const jsConfigPath = findUp.sync("jsconfig.json", {
|
|
29
33
|
cwd: resolveComponentsPath(),
|
|
30
34
|
});
|
|
31
|
-
const tsConfigPath =
|
|
35
|
+
const tsConfigPath = findUp.sync("tsconfig.json", {
|
|
32
36
|
cwd: resolveComponentsPath(),
|
|
33
37
|
});
|
|
34
38
|
|
|
@@ -53,7 +57,6 @@ function getComponentsLibAliases() {
|
|
|
53
57
|
const absolutePath = resolveComponentsPath(relativePathToDir);
|
|
54
58
|
|
|
55
59
|
return {
|
|
56
|
-
// biome-ignore lint/performance/noAccumulatingSpread: to be fixed
|
|
57
60
|
...currentAlias,
|
|
58
61
|
[aliasKey]: absolutePath,
|
|
59
62
|
};
|