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