@griddo/cx 11.7.10 → 11.7.12-rc.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/README.md +27 -226
- package/build/adapters/gatsby/actions/clean.js +10 -0
- package/build/adapters/gatsby/actions/clean.js.map +1 -0
- package/build/adapters/gatsby/actions/close.js +14 -0
- package/build/adapters/gatsby/actions/close.js.map +1 -0
- package/build/adapters/gatsby/actions/data.js +18 -0
- package/build/adapters/gatsby/actions/data.js.map +1 -0
- package/build/adapters/gatsby/actions/healthCheck.js +10 -0
- package/build/adapters/gatsby/actions/healthCheck.js.map +1 -0
- package/build/adapters/gatsby/actions/init.js +22 -0
- package/build/adapters/gatsby/actions/init.js.map +1 -0
- package/build/adapters/gatsby/actions/logs.js +9 -0
- package/build/adapters/gatsby/actions/logs.js.map +1 -0
- package/build/adapters/gatsby/actions/meta.js +13 -0
- package/build/adapters/gatsby/actions/meta.js.map +1 -0
- package/build/adapters/gatsby/actions/prepare.js +9 -0
- package/build/adapters/gatsby/actions/prepare.js.map +1 -0
- package/build/adapters/gatsby/actions/relocation.js +15 -0
- package/build/adapters/gatsby/actions/relocation.js.map +1 -0
- package/build/adapters/gatsby/actions/restore.js +26 -0
- package/build/adapters/gatsby/actions/restore.js.map +1 -0
- package/build/adapters/gatsby/actions/ssg.js +9 -0
- package/build/adapters/gatsby/actions/ssg.js.map +1 -0
- package/build/adapters/gatsby/actions/sync.js +51 -0
- package/build/adapters/gatsby/actions/sync.js.map +1 -0
- package/build/adapters/gatsby/index.js +78 -0
- package/build/adapters/gatsby/index.js.map +1 -0
- package/build/adapters/gatsby/shared/artifacts.js +20 -0
- package/build/adapters/gatsby/shared/artifacts.js.map +1 -0
- package/build/adapters/gatsby/shared/context.js +31 -0
- package/build/adapters/gatsby/shared/context.js.map +1 -0
- package/build/adapters/gatsby/shared/diff-assets.js +101 -0
- package/build/adapters/gatsby/shared/diff-assets.js.map +1 -0
- package/build/adapters/gatsby/shared/extract-assets.js +58 -0
- package/build/adapters/gatsby/shared/extract-assets.js.map +1 -0
- package/build/adapters/gatsby/shared/gatsby-build.js +55 -0
- package/build/adapters/gatsby/shared/gatsby-build.js.map +1 -0
- package/build/adapters/gatsby/shared/sync-render.js +210 -0
- package/build/adapters/gatsby/shared/sync-render.js.map +1 -0
- package/build/adapters/gatsby/shared/types.js +3 -0
- package/build/adapters/gatsby/shared/types.js.map +1 -0
- package/build/commands/end-render.js +87 -0
- package/build/commands/end-render.js.map +1 -0
- package/build/commands/prepare-assets-directory.js +30 -0
- package/build/commands/prepare-assets-directory.js.map +1 -0
- package/build/commands/prepare-domains-render.js +133 -0
- package/build/commands/prepare-domains-render.js.map +1 -0
- package/build/commands/reset-render.js +21 -0
- package/build/commands/reset-render.js.map +1 -0
- package/build/commands/start-render.js +44 -0
- package/build/commands/start-render.js.map +1 -0
- package/build/commands/upload-search-content.js +180 -0
- package/build/commands/upload-search-content.js.map +1 -0
- package/build/constants/endpoints.js +43 -0
- package/build/constants/endpoints.js.map +1 -0
- package/build/constants/envs.js +68 -0
- package/build/constants/envs.js.map +1 -0
- package/build/constants/errors.js +81 -0
- package/build/constants/errors.js.map +1 -0
- package/build/services/auth.js +40 -0
- package/build/services/auth.js.map +1 -0
- package/build/services/db-class.js +49 -0
- package/build/services/db-class.js.map +1 -0
- package/build/services/db.js +34 -0
- package/build/services/db.js.map +1 -0
- package/build/services/navigation.js +96 -0
- package/build/services/navigation.js.map +1 -0
- package/build/services/reference-fields.js +131 -0
- package/build/services/reference-fields.js.map +1 -0
- package/build/services/robots.js +60 -0
- package/build/services/robots.js.map +1 -0
- package/build/services/sites.js +110 -0
- package/build/services/sites.js.map +1 -0
- package/build/services/store.js +257 -0
- package/build/services/store.js.map +1 -0
- package/build/types/api.js +3 -0
- package/build/types/api.js.map +1 -0
- package/build/types/global.js +3 -0
- package/build/types/global.js.map +1 -0
- package/build/types/navigation.js +3 -0
- package/build/types/navigation.js.map +1 -0
- package/build/types/pages.js +3 -0
- package/build/types/pages.js.map +1 -0
- package/build/types/render.js +10 -0
- package/build/types/render.js.map +1 -0
- package/build/types/sites.js +3 -0
- package/build/types/sites.js.map +1 -0
- package/build/types/templates.js +3 -0
- package/build/types/templates.js.map +1 -0
- package/build/utils/api.js +165 -0
- package/build/utils/api.js.map +1 -0
- package/build/utils/artifacts.js +38 -0
- package/build/utils/artifacts.js.map +1 -0
- package/build/utils/brush.js +30 -0
- package/build/utils/brush.js.map +1 -0
- package/build/utils/cache.js +106 -0
- package/build/utils/cache.js.map +1 -0
- package/build/utils/check-environment-health.js +69 -0
- package/build/utils/check-environment-health.js.map +1 -0
- package/build/utils/core-utils.js +270 -0
- package/build/utils/core-utils.js.map +1 -0
- package/build/utils/domains.js +37 -0
- package/build/utils/domains.js.map +1 -0
- package/build/utils/errors.js +30 -0
- package/build/utils/errors.js.map +1 -0
- package/build/utils/folders.js +341 -0
- package/build/utils/folders.js.map +1 -0
- package/build/utils/images.js +45 -0
- package/build/utils/images.js.map +1 -0
- package/build/utils/instance.js +66 -0
- package/build/utils/instance.js.map +1 -0
- package/build/utils/loggin.js +119 -0
- package/build/utils/loggin.js.map +1 -0
- package/build/utils/npm-deps/find-up-simple.js +75 -0
- package/build/utils/npm-deps/find-up-simple.js.map +1 -0
- package/build/utils/npm-deps/pkg-dir.js +20 -0
- package/build/utils/npm-deps/pkg-dir.js.map +1 -0
- package/build/utils/npm-deps/xml-parser.js +49 -0
- package/build/utils/npm-deps/xml-parser.js.map +1 -0
- package/build/utils/pages.js +359 -0
- package/build/utils/pages.js.map +1 -0
- package/build/utils/render.js +168 -0
- package/build/utils/render.js.map +1 -0
- package/build/utils/sitemaps.js +110 -0
- package/build/utils/sitemaps.js.map +1 -0
- package/build/utils/sites.js +105 -0
- package/build/utils/sites.js.map +1 -0
- package/build/utils/store.js +193 -0
- package/build/utils/store.js.map +1 -0
- package/exporter/adapters/gatsby/actions/clean.ts +14 -0
- package/exporter/adapters/gatsby/actions/close.ts +20 -0
- package/exporter/adapters/gatsby/actions/data.ts +25 -0
- package/exporter/adapters/gatsby/actions/healthCheck.ts +10 -0
- package/exporter/adapters/gatsby/actions/init.ts +26 -0
- package/exporter/adapters/gatsby/actions/logs.ts +10 -0
- package/exporter/adapters/gatsby/actions/meta.ts +16 -0
- package/exporter/adapters/gatsby/actions/prepare.ts +9 -0
- package/exporter/adapters/gatsby/actions/relocation.ts +15 -0
- package/exporter/adapters/gatsby/actions/restore.ts +36 -0
- package/exporter/adapters/gatsby/actions/ssg.ts +12 -0
- package/exporter/adapters/gatsby/actions/sync.ts +71 -0
- package/exporter/adapters/gatsby/index.ts +73 -153
- package/exporter/adapters/gatsby/shared/artifacts.ts +16 -0
- package/exporter/adapters/gatsby/shared/context.ts +50 -0
- package/exporter/adapters/gatsby/shared/diff-assets.ts +113 -0
- package/exporter/adapters/gatsby/shared/extract-assets.ts +61 -0
- package/exporter/adapters/gatsby/shared/gatsby-build.ts +58 -0
- package/exporter/adapters/gatsby/shared/sync-render.ts +276 -0
- package/exporter/adapters/gatsby/shared/types.ts +35 -0
- package/exporter/build-esbuild.noop +42 -0
- package/exporter/build.sh +4 -38
- package/exporter/commands/end-render.ts +72 -70
- package/exporter/commands/prepare-assets-directory.ts +30 -0
- package/exporter/commands/prepare-domains-render.ts +143 -31
- package/exporter/commands/reset-render.ts +10 -3
- package/exporter/commands/start-render.ts +22 -45
- package/exporter/commands/upload-search-content.ts +194 -21
- package/exporter/constants/endpoints.ts +2 -1
- package/exporter/constants/envs.ts +57 -55
- package/exporter/{errors/errors-data.ts → constants/errors.ts} +24 -14
- package/exporter/services/auth.ts +7 -6
- package/exporter/services/db-class.ts +54 -0
- package/exporter/services/db.ts +32 -0
- package/exporter/services/navigation.ts +4 -10
- package/exporter/services/reference-fields.ts +9 -24
- package/exporter/services/robots.ts +9 -16
- package/exporter/services/sites.ts +36 -24
- package/exporter/services/store.ts +107 -96
- package/exporter/types/api.ts +27 -28
- package/exporter/types/global.ts +8 -11
- package/exporter/types/navigation.ts +1 -1
- package/exporter/types/pages.ts +2 -3
- package/exporter/types/render.ts +59 -0
- package/exporter/types/sites.ts +1 -2
- package/exporter/utils/api.ts +55 -75
- package/exporter/utils/artifacts.ts +38 -0
- package/exporter/utils/brush.ts +34 -0
- package/exporter/utils/cache.ts +37 -62
- package/exporter/utils/check-environment-health.ts +80 -0
- package/exporter/utils/core-utils.ts +133 -272
- package/exporter/utils/domains.ts +10 -7
- package/exporter/{errors/index.ts → utils/errors.ts} +10 -9
- package/exporter/utils/folders.ts +163 -98
- package/exporter/utils/images.ts +1 -6
- package/exporter/utils/instance.ts +9 -13
- package/exporter/utils/loggin.ts +44 -91
- package/exporter/utils/npm-deps/find-up-simple.ts +100 -0
- package/exporter/utils/npm-deps/pkg-dir.ts +17 -0
- package/exporter/utils/npm-deps/xml-parser.ts +57 -0
- package/exporter/utils/pages.ts +23 -88
- package/exporter/utils/render.ts +180 -48
- package/exporter/utils/sitemaps.ts +129 -0
- package/exporter/utils/sites.ts +19 -197
- package/exporter/utils/store.ts +87 -180
- package/gatsby-browser.tsx +41 -58
- package/gatsby-config.ts +10 -17
- package/gatsby-node.ts +17 -78
- package/gatsby-ssr.tsx +2 -1
- package/package.json +35 -86
- package/plugins/gatsby-plugin-svgr-loader/gatsby-node.js +55 -0
- package/plugins/gatsby-plugin-svgr-loader/package.json +8 -0
- package/react/DynamicScript/index.tsx +33 -0
- package/{exporter/react → react}/Favicon/index.tsx +1 -7
- package/{exporter/react → react}/GriddoIntegrations/index.tsx +16 -22
- package/{exporter/react → react}/GriddoIntegrations/utils.ts +21 -9
- package/{build/react/index.d.ts → react/index.tsx} +1 -0
- package/src/components/Head.tsx +13 -46
- package/src/components/template.tsx +8 -30
- package/src/gatsby-node-utils.ts +73 -2
- package/src/html.tsx +2 -11
- package/src/types.ts +5 -5
- package/tsconfig.commands.json +36 -0
- package/tsconfig.exporter.json +19 -0
- package/tsconfig.json +5 -3
- package/build/adapters/gatsby/index.d.ts +0 -4
- package/build/adapters/gatsby/utils.d.ts +0 -22
- package/build/artifacts/index.d.ts +0 -6
- package/build/commands/end-render.d.ts +0 -2
- package/build/commands/move-assets.d.ts +0 -1
- package/build/commands/prepare-domains-render.d.ts +0 -1
- package/build/commands/reset-render.d.ts +0 -2
- package/build/commands/start-render.d.ts +0 -2
- package/build/commands/upload-search-content.d.ts +0 -2
- package/build/constants/endpoints.d.ts +0 -19
- package/build/constants/envs.d.ts +0 -37
- package/build/constants/index.d.ts +0 -57
- package/build/end-render.js +0 -74
- package/build/end-render.js.map +0 -7
- package/build/errors/errors-data.d.ts +0 -22
- package/build/errors/index.d.ts +0 -15
- package/build/index.d.ts +0 -29
- package/build/index.js +0 -73
- package/build/index.js.map +0 -7
- package/build/prepare-domains-render.js +0 -73
- package/build/prepare-domains-render.js.map +0 -7
- package/build/react/Favicon/index.d.ts +0 -5
- package/build/react/Favicon/utils.d.ts +0 -9
- package/build/react/GriddoIntegrations/index.d.ts +0 -20
- package/build/react/GriddoIntegrations/utils.d.ts +0 -26
- package/build/react/index.js +0 -3
- package/build/registers/api.d.ts +0 -9
- package/build/registers/gatsby.d.ts +0 -9
- package/build/registers/index.d.ts +0 -3
- package/build/reset-render.js +0 -74
- package/build/reset-render.js.map +0 -7
- package/build/services/auth.d.ts +0 -10
- package/build/services/domains.d.ts +0 -6
- package/build/services/navigation.d.ts +0 -50
- package/build/services/reference-fields.d.ts +0 -20
- package/build/services/register.d.ts +0 -36
- package/build/services/robots.d.ts +0 -19
- package/build/services/settings.d.ts +0 -4
- package/build/services/sites.d.ts +0 -29
- package/build/services/store.d.ts +0 -6
- package/build/start-render.js +0 -100
- package/build/start-render.js.map +0 -7
- package/build/types/api.d.ts +0 -142
- package/build/types/global.d.ts +0 -84
- package/build/types/navigation.d.ts +0 -28
- package/build/types/pages.d.ts +0 -144
- package/build/types/sites.d.ts +0 -57
- package/build/types/templates.d.ts +0 -8
- package/build/upload-search-content.js +0 -74
- package/build/upload-search-content.js.map +0 -7
- package/build/utils/alerts.d.ts +0 -3
- package/build/utils/api.d.ts +0 -23
- package/build/utils/cache.d.ts +0 -35
- package/build/utils/core-utils.d.ts +0 -107
- package/build/utils/create-build-data.d.ts +0 -8
- package/build/utils/domains.d.ts +0 -13
- package/build/utils/folders.d.ts +0 -53
- package/build/utils/health-checks.d.ts +0 -7
- package/build/utils/images.d.ts +0 -16
- package/build/utils/instance.d.ts +0 -21
- package/build/utils/loggin.d.ts +0 -51
- package/build/utils/pages.d.ts +0 -34
- package/build/utils/render.d.ts +0 -13
- package/build/utils/searches.d.ts +0 -15
- package/build/utils/sites.d.ts +0 -31
- package/build/utils/store.d.ts +0 -81
- package/cx.config.d.ts +0 -5
- package/cx.config.js +0 -36
- package/exporter/adapters/gatsby/utils.ts +0 -161
- package/exporter/artifacts/README.md +0 -34
- package/exporter/artifacts/index.ts +0 -33
- package/exporter/commands/move-assets.ts +0 -11
- package/exporter/constants/index.ts +0 -129
- package/exporter/index.ts +0 -82
- package/exporter/react/index.tsx +0 -11
- package/exporter/registers/api.ts +0 -14
- package/exporter/registers/gatsby.ts +0 -14
- package/exporter/registers/index.ts +0 -4
- package/exporter/services/domains.ts +0 -16
- package/exporter/services/register.ts +0 -113
- package/exporter/services/settings.ts +0 -17
- package/exporter/utils/alerts.ts +0 -29
- package/exporter/utils/create-build-data.ts +0 -17
- package/exporter/utils/health-checks.ts +0 -64
- package/exporter/utils/searches.ts +0 -156
- package/src/README.md +0 -7
- package/start-render.js +0 -7
- /package/{exporter/react → react}/Favicon/utils.ts +0 -0
|
@@ -1,14 +1,12 @@
|
|
|
1
|
-
import
|
|
2
|
-
import path from "node:path";
|
|
1
|
+
import type { MakeDirectoryOptions } from "node:fs";
|
|
3
2
|
|
|
4
|
-
import
|
|
3
|
+
import fsp from "node:fs/promises";
|
|
4
|
+
import path from "node:path";
|
|
5
5
|
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
6
|
+
import { ArtifactError } from "../constants/errors";
|
|
7
|
+
import { walkStore } from "./core-utils";
|
|
8
|
+
import { throwError } from "./errors";
|
|
8
9
|
import { verboseLog } from "./loggin";
|
|
9
|
-
import { ArtifactError } from "../errors/errors-data";
|
|
10
|
-
|
|
11
|
-
const config = getConfig();
|
|
12
10
|
|
|
13
11
|
/**
|
|
14
12
|
* Remove an empty directory from the basePath recursively.
|
|
@@ -16,37 +14,34 @@ const config = getConfig();
|
|
|
16
14
|
*
|
|
17
15
|
* @param baseDir - The base directory.
|
|
18
16
|
*/
|
|
19
|
-
function deleteDisposableSiteDirs() {
|
|
20
|
-
|
|
21
|
-
const baseDir = path.join(__cx, "dist");
|
|
22
|
-
|
|
23
|
-
if (!fs.existsSync(baseDir)) {
|
|
17
|
+
async function deleteDisposableSiteDirs(baseDir: string) {
|
|
18
|
+
if (!(await pathExists(baseDir))) {
|
|
24
19
|
return;
|
|
25
20
|
}
|
|
26
21
|
|
|
27
|
-
const sitesDirs =
|
|
28
|
-
.
|
|
29
|
-
|
|
22
|
+
const sitesDirs = (await fsp.readdir(baseDir, { withFileTypes: true })).filter((file) =>
|
|
23
|
+
file.isDirectory(),
|
|
24
|
+
);
|
|
30
25
|
|
|
31
26
|
for (const siteDir of sitesDirs) {
|
|
32
27
|
const sitePath = path.join(baseDir, siteDir.name);
|
|
33
|
-
if (siteIsEmpty(sitePath)) {
|
|
34
|
-
|
|
28
|
+
if (await siteIsEmpty(sitePath)) {
|
|
29
|
+
await fsp.rm(sitePath, { recursive: true });
|
|
35
30
|
}
|
|
36
31
|
}
|
|
37
32
|
}
|
|
38
33
|
|
|
39
34
|
/**
|
|
40
|
-
* Creates multiple directories.
|
|
35
|
+
* Creates multiple artifact directories.
|
|
41
36
|
*
|
|
42
37
|
* @param dirs - An array of directory paths.
|
|
43
38
|
* @param options - Same option as `fs.mkdirSync()`
|
|
44
39
|
*/
|
|
45
|
-
function
|
|
40
|
+
async function createDirs(dirs: Array<string>, options?: MakeDirectoryOptions) {
|
|
46
41
|
for (const dir of dirs) {
|
|
47
42
|
try {
|
|
48
|
-
if (!
|
|
49
|
-
|
|
43
|
+
if (!(await pathExists(dir))) {
|
|
44
|
+
await fsp.mkdir(dir, { recursive: true, ...options });
|
|
50
45
|
verboseLog(`create directory: ${dir}`);
|
|
51
46
|
}
|
|
52
47
|
} catch (error) {
|
|
@@ -55,10 +50,10 @@ function createArtifacts(dirs: Array<string>, options?: MakeDirectoryOptions) {
|
|
|
55
50
|
}
|
|
56
51
|
}
|
|
57
52
|
|
|
58
|
-
function
|
|
53
|
+
async function renamePath(src: string, dst: string) {
|
|
59
54
|
try {
|
|
60
|
-
if (
|
|
61
|
-
|
|
55
|
+
if (await pathExists(src)) {
|
|
56
|
+
await fsp.rename(src, dst);
|
|
62
57
|
verboseLog(`rename ${src} to ${dst}`);
|
|
63
58
|
}
|
|
64
59
|
} catch (error) {
|
|
@@ -74,7 +69,7 @@ function renameArtifact(src: string, dst: string) {
|
|
|
74
69
|
* @param dirs - Directories to copy.
|
|
75
70
|
* @param options.withBackup - Create a previous backup before copy.
|
|
76
71
|
*/
|
|
77
|
-
function
|
|
72
|
+
async function copyDirs(
|
|
78
73
|
src: string,
|
|
79
74
|
dst: string,
|
|
80
75
|
dirs: Array<string>,
|
|
@@ -88,42 +83,40 @@ function copyArtifacts(
|
|
|
88
83
|
const dstCompose = path.join(dst, dir);
|
|
89
84
|
|
|
90
85
|
// The dir we want to copy, doesn't exist.
|
|
91
|
-
if (!
|
|
92
|
-
console.log(
|
|
93
|
-
`(Maybe first render) Source directory does not exist: ${srcCompose}`,
|
|
94
|
-
);
|
|
86
|
+
if (!(await pathExists(srcCompose))) {
|
|
87
|
+
console.log(`(Maybe first render) Source directory does not exist: ${srcCompose}`);
|
|
95
88
|
continue;
|
|
96
89
|
}
|
|
97
90
|
|
|
98
91
|
// Create the backup
|
|
99
92
|
if (withBackup) {
|
|
100
|
-
createBackup(dstCompose);
|
|
93
|
+
await createBackup(dstCompose);
|
|
101
94
|
verboseLog(`create backup: ${dstCompose}`);
|
|
102
95
|
}
|
|
103
96
|
|
|
104
97
|
// Copy directory
|
|
105
98
|
try {
|
|
106
99
|
// First clean destination
|
|
107
|
-
if (
|
|
108
|
-
|
|
100
|
+
if (await pathExists(dstCompose)) {
|
|
101
|
+
await fsp.rm(dstCompose, { recursive: true, force: true });
|
|
109
102
|
verboseLog(`clean destination: ${dstCompose}`);
|
|
110
103
|
}
|
|
111
104
|
|
|
112
105
|
// Then copy src to dst
|
|
113
|
-
|
|
106
|
+
await fsp.cp(srcCompose, dstCompose, {
|
|
114
107
|
recursive: true,
|
|
115
108
|
preserveTimestamps: true,
|
|
116
109
|
});
|
|
117
110
|
verboseLog(`copy: ${srcCompose} to ${dstCompose}`);
|
|
118
111
|
|
|
119
112
|
if (withBackup) {
|
|
120
|
-
deleteBackup(dstCompose);
|
|
113
|
+
await deleteBackup(dstCompose);
|
|
121
114
|
verboseLog(`delete backup: ${dstCompose}`);
|
|
122
115
|
}
|
|
123
116
|
} catch (error) {
|
|
124
117
|
if (withBackup) {
|
|
125
|
-
restoreBackup(dstCompose);
|
|
126
|
-
|
|
118
|
+
await restoreBackup(dstCompose);
|
|
119
|
+
verboseLog("Backup has been restored.");
|
|
127
120
|
}
|
|
128
121
|
|
|
129
122
|
throwError(ArtifactError, error);
|
|
@@ -139,7 +132,7 @@ function copyArtifacts(
|
|
|
139
132
|
* @param dirs - Directories to move.
|
|
140
133
|
* @param options - Options.
|
|
141
134
|
*/
|
|
142
|
-
function
|
|
135
|
+
async function moveDirs(
|
|
143
136
|
src: string,
|
|
144
137
|
dst: string,
|
|
145
138
|
dirs: Array<string>,
|
|
@@ -151,29 +144,29 @@ function moveArtifacts(
|
|
|
151
144
|
const srcCompose = path.join(src, dir);
|
|
152
145
|
const dstCompose = path.join(dst, dir);
|
|
153
146
|
|
|
154
|
-
if (!
|
|
147
|
+
if (!(await pathExists(srcCompose))) {
|
|
155
148
|
continue;
|
|
156
149
|
}
|
|
157
150
|
|
|
158
151
|
if (withBackup) {
|
|
159
|
-
createBackup(dstCompose);
|
|
152
|
+
await createBackup(dstCompose);
|
|
160
153
|
}
|
|
161
154
|
|
|
162
155
|
try {
|
|
163
156
|
// Clean destination
|
|
164
|
-
if (override &&
|
|
165
|
-
|
|
157
|
+
if (override && (await pathExists(dstCompose))) {
|
|
158
|
+
await fsp.rm(dstCompose, { recursive: true, force: true });
|
|
166
159
|
}
|
|
167
160
|
|
|
168
|
-
|
|
161
|
+
await fsp.rename(srcCompose, dstCompose);
|
|
169
162
|
verboseLog(`moved: ${srcCompose} to ${dstCompose}`);
|
|
170
163
|
|
|
171
164
|
if (withBackup) {
|
|
172
|
-
deleteBackup(dstCompose);
|
|
165
|
+
await deleteBackup(dstCompose);
|
|
173
166
|
}
|
|
174
167
|
} catch (error) {
|
|
175
168
|
if (withBackup) {
|
|
176
|
-
restoreBackup(dstCompose);
|
|
169
|
+
await restoreBackup(dstCompose);
|
|
177
170
|
console.log("Backup has been restored.");
|
|
178
171
|
}
|
|
179
172
|
|
|
@@ -185,30 +178,23 @@ function moveArtifacts(
|
|
|
185
178
|
/**
|
|
186
179
|
* Removes multiple artifact directories.
|
|
187
180
|
*
|
|
188
|
-
* @param
|
|
181
|
+
* @param dirs - An array of directory paths.
|
|
189
182
|
*/
|
|
190
|
-
function
|
|
191
|
-
for (const dir of
|
|
192
|
-
if (!dir) {
|
|
193
|
-
continue;
|
|
194
|
-
}
|
|
195
|
-
|
|
183
|
+
async function removeDirs(dirs: Array<string>) {
|
|
184
|
+
for (const dir of dirs) {
|
|
196
185
|
try {
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
fs.rmSync(dir, { recursive: true, force: true });
|
|
200
|
-
verboseLog(`artifact (${kind}) removed: ${dir}`);
|
|
201
|
-
}
|
|
186
|
+
await fsp.rm(dir, { recursive: true, force: true });
|
|
187
|
+
verboseLog(`artifact removed: ${dir}`);
|
|
202
188
|
} catch (error) {
|
|
203
189
|
throwError(ArtifactError, error);
|
|
204
190
|
}
|
|
205
191
|
}
|
|
206
192
|
}
|
|
207
193
|
|
|
208
|
-
function restoreBackup(src: string, suffix = "-BACKUP") {
|
|
194
|
+
async function restoreBackup(src: string, suffix = "-BACKUP") {
|
|
209
195
|
const dst = src + suffix;
|
|
210
196
|
try {
|
|
211
|
-
|
|
197
|
+
await fsp.rename(dst, src);
|
|
212
198
|
console.log(`Backup ${dst} has been restored`);
|
|
213
199
|
} catch (error) {
|
|
214
200
|
console.log(error);
|
|
@@ -216,37 +202,37 @@ function restoreBackup(src: string, suffix = "-BACKUP") {
|
|
|
216
202
|
}
|
|
217
203
|
}
|
|
218
204
|
|
|
219
|
-
function deleteBackup(src: string, suffix = "-BACKUP") {
|
|
205
|
+
async function deleteBackup(src: string, suffix = "-BACKUP") {
|
|
220
206
|
const dst = src + suffix;
|
|
221
207
|
|
|
222
|
-
if (!
|
|
208
|
+
if (!(await pathExists(dst))) {
|
|
223
209
|
return;
|
|
224
210
|
}
|
|
225
211
|
|
|
226
212
|
try {
|
|
227
|
-
|
|
228
|
-
|
|
213
|
+
await fsp.rm(dst, { recursive: true, force: true });
|
|
214
|
+
verboseLog(`Backup ${dst} has been deleted`);
|
|
229
215
|
} catch (error) {
|
|
230
216
|
console.log(error);
|
|
231
217
|
throw new Error(`Error while delete ${dst} backup`);
|
|
232
218
|
}
|
|
233
219
|
}
|
|
234
220
|
|
|
235
|
-
function createBackup(src: string, suffix = "-BACKUP") {
|
|
221
|
+
async function createBackup(src: string, suffix = "-BACKUP") {
|
|
236
222
|
const dst = src + suffix;
|
|
237
223
|
|
|
238
|
-
if (!
|
|
224
|
+
if (!(await pathExists(src))) {
|
|
239
225
|
return;
|
|
240
226
|
}
|
|
241
227
|
|
|
242
|
-
if (
|
|
228
|
+
if (await pathExists(dst)) {
|
|
243
229
|
console.log(`Destination ${dst} already exists`);
|
|
244
230
|
return;
|
|
245
231
|
}
|
|
246
232
|
|
|
247
233
|
try {
|
|
248
|
-
|
|
249
|
-
|
|
234
|
+
await fsp.rename(src, dst);
|
|
235
|
+
verboseLog(`Backup of ${src} has been created in ${dst}`);
|
|
250
236
|
} catch (error) {
|
|
251
237
|
console.log(`Error while coping ${src} to ${dst} backup`);
|
|
252
238
|
throwError(ArtifactError, error);
|
|
@@ -254,25 +240,23 @@ function createBackup(src: string, suffix = "-BACKUP") {
|
|
|
254
240
|
}
|
|
255
241
|
|
|
256
242
|
/**
|
|
257
|
-
* Elimina todas las páginas del store (de todos los sites) cuyo nombre empiece
|
|
258
|
-
* Estas páginas son "virtuales" y no tienen ids desde API por
|
|
259
|
-
*
|
|
243
|
+
* Elimina todas las páginas del store (de todos los sites) cuyo nombre empiece
|
|
244
|
+
* con un guión "-". Estas páginas son "virtuales" y no tienen ids desde API por
|
|
245
|
+
* lo que mantenerlas en el store es un problema cuando se hacen modificaciones
|
|
246
|
+
* en la página "madre". La solución por ahora es borrarlas del store y
|
|
247
|
+
* rehacerlas en todos los renders.
|
|
260
248
|
*/
|
|
261
|
-
async function
|
|
262
|
-
const { __cx } = config.paths();
|
|
263
|
-
const storePath = path.join(__cx, "store");
|
|
264
|
-
|
|
249
|
+
async function removeVirtualPages(dirPath: string) {
|
|
265
250
|
try {
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
for (const filePath of allJsonPageFilesPath) {
|
|
251
|
+
// Procesamos archivos uno por uno para evitar cargar todos en memoria
|
|
252
|
+
for await (const filePath of walkStore(dirPath)) {
|
|
269
253
|
if (path.basename(filePath).startsWith("-")) {
|
|
270
|
-
|
|
254
|
+
await fsp.unlink(filePath);
|
|
271
255
|
}
|
|
272
256
|
}
|
|
273
257
|
} catch (error) {
|
|
274
258
|
console.info(
|
|
275
|
-
|
|
259
|
+
`${dirPath} folder does not exist. Skipping multipage or static list template cleaning.`,
|
|
276
260
|
error,
|
|
277
261
|
);
|
|
278
262
|
}
|
|
@@ -281,15 +265,13 @@ async function removeVirtualPagesFromStore() {
|
|
|
281
265
|
/**
|
|
282
266
|
* Return true if the site folder is empty or only has xml files. (Recursively)
|
|
283
267
|
*/
|
|
284
|
-
function siteIsEmpty(sitePath: string) {
|
|
285
|
-
const siteFiles =
|
|
286
|
-
.
|
|
268
|
+
async function siteIsEmpty(sitePath: string) {
|
|
269
|
+
const siteFiles = (
|
|
270
|
+
await fsp.readdir(sitePath, {
|
|
287
271
|
withFileTypes: true,
|
|
288
272
|
recursive: true,
|
|
289
273
|
})
|
|
290
|
-
|
|
291
|
-
(file) => file.isFile() && !path.basename(file.name).startsWith("."),
|
|
292
|
-
);
|
|
274
|
+
).filter((file) => file.isFile() && !path.basename(file.name).startsWith("."));
|
|
293
275
|
|
|
294
276
|
const xmlFiles = siteFiles.filter((file) => file.name.endsWith(".xml"));
|
|
295
277
|
|
|
@@ -298,23 +280,106 @@ function siteIsEmpty(sitePath: string) {
|
|
|
298
280
|
}
|
|
299
281
|
}
|
|
300
282
|
|
|
301
|
-
|
|
302
|
-
|
|
283
|
+
/**
|
|
284
|
+
* Delete empty directories from the given directory in a recursive way.
|
|
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
|
+
}
|
|
303
294
|
|
|
304
|
-
|
|
305
|
-
|
|
295
|
+
let filesInDirectory: string[];
|
|
296
|
+
try {
|
|
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
|
+
}
|
|
306
340
|
}
|
|
341
|
+
}
|
|
307
342
|
|
|
308
|
-
|
|
343
|
+
async function pathExists(dir: string) {
|
|
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
|
+
}
|
|
309
372
|
}
|
|
310
373
|
|
|
311
374
|
export {
|
|
312
|
-
|
|
313
|
-
|
|
375
|
+
copyDirs,
|
|
376
|
+
createDirs,
|
|
314
377
|
deleteDisposableSiteDirs,
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
378
|
+
deleteEmptyDirectories,
|
|
379
|
+
findFilesBySuffix,
|
|
380
|
+
moveDirs,
|
|
381
|
+
pathExists,
|
|
382
|
+
removeDirs,
|
|
383
|
+
removeVirtualPages,
|
|
384
|
+
renamePath,
|
|
320
385
|
};
|
package/exporter/utils/images.ts
CHANGED
|
@@ -13,12 +13,7 @@ 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(
|
|
17
|
-
image: Fields.Image | string,
|
|
18
|
-
width: number,
|
|
19
|
-
height: number,
|
|
20
|
-
format = "jpg",
|
|
21
|
-
) {
|
|
16
|
+
function formatImage(image: Fields.Image | string, width: number, height: number, format = "jpg") {
|
|
22
17
|
const url = typeof image === "string" ? image : image?.url;
|
|
23
18
|
|
|
24
19
|
if (!url) {
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import path from "node:path";
|
|
2
2
|
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
import {
|
|
7
|
-
import { NoJSConfigFileFound } from "../errors/errors-data";
|
|
3
|
+
import { NoJSConfigFileFound } from "../constants/errors";
|
|
4
|
+
import { throwError } from "./errors";
|
|
5
|
+
import { findUpSync } from "./npm-deps/find-up-simple";
|
|
6
|
+
import { pkgDirSync } from "./npm-deps/pkg-dir";
|
|
8
7
|
|
|
9
8
|
// Consts
|
|
10
9
|
const isComponentLibrary = __dirname.includes("node_modules");
|
|
@@ -17,22 +16,18 @@ const componentLibraryPathAlias = getComponentsLibAliases();
|
|
|
17
16
|
*/
|
|
18
17
|
function resolveComponentsPath(customPath = "") {
|
|
19
18
|
return isComponentLibrary
|
|
20
|
-
? path.resolve(
|
|
21
|
-
: path.resolve(
|
|
22
|
-
pkgDir.sync(__dirname) as string,
|
|
23
|
-
"../griddo-components",
|
|
24
|
-
customPath,
|
|
25
|
-
);
|
|
19
|
+
? path.resolve(pkgDirSync({ cwd: __dirname }) as string, "../../../", customPath)
|
|
20
|
+
: path.resolve(pkgDirSync({ cwd: __dirname }) as string, "../griddo-components", customPath);
|
|
26
21
|
}
|
|
27
22
|
|
|
28
23
|
/**
|
|
29
24
|
* Return the instance or monorepo components {t|j}sconfig.json file.
|
|
30
25
|
*/
|
|
31
26
|
function getComponentsJSConfig() {
|
|
32
|
-
const jsConfigPath =
|
|
27
|
+
const jsConfigPath = findUpSync("jsconfig.json", {
|
|
33
28
|
cwd: resolveComponentsPath(),
|
|
34
29
|
});
|
|
35
|
-
const tsConfigPath =
|
|
30
|
+
const tsConfigPath = findUpSync("tsconfig.json", {
|
|
36
31
|
cwd: resolveComponentsPath(),
|
|
37
32
|
});
|
|
38
33
|
|
|
@@ -57,6 +52,7 @@ function getComponentsLibAliases() {
|
|
|
57
52
|
const absolutePath = resolveComponentsPath(relativePathToDir);
|
|
58
53
|
|
|
59
54
|
return {
|
|
55
|
+
// biome-ignore lint/performance/noAccumulatingSpread: to be fixed
|
|
60
56
|
...currentAlias,
|
|
61
57
|
[aliasKey]: absolutePath,
|
|
62
58
|
};
|