@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,50 +1,16 @@
|
|
|
1
1
|
import type { APIResponses } from "../types/api";
|
|
2
|
-
import type {
|
|
3
|
-
CXConfig,
|
|
4
|
-
LifeCyclesNames,
|
|
5
|
-
LifeCycleSteps,
|
|
6
|
-
} from "../types/global";
|
|
7
|
-
import type { APIPageObject } from "../types/pages";
|
|
8
|
-
|
|
9
|
-
import fs from "node:fs";
|
|
10
|
-
import path from "node:path";
|
|
11
|
-
|
|
12
|
-
import fsx from "fs-extra";
|
|
13
|
-
import kleur from "kleur";
|
|
14
|
-
import { bgRed, black } from "kleur/colors";
|
|
15
|
-
import pkgDir from "pkg-dir";
|
|
16
|
-
|
|
17
|
-
import { envs } from "../constants";
|
|
18
|
-
import { throwError } from "../errors";
|
|
19
|
-
import { prependFileSync } from "./folders";
|
|
20
|
-
import { boxLog, infoLog, successLog } from "./loggin";
|
|
21
|
-
import { generateBuildReport, generateSitemaps } from "./sites";
|
|
22
|
-
import { LifecycleExecutionError } from "../errors/errors-data";
|
|
23
|
-
import { RobotsService } from "../services/robots";
|
|
2
|
+
import type { LifeCycleAction, LifeCyclesNames } from "../types/global";
|
|
24
3
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
const instanceRootDir = pkgDir.sync()!; // instance root dir
|
|
4
|
+
import fsp from "node:fs/promises";
|
|
5
|
+
import path from "node:path";
|
|
28
6
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
*/
|
|
37
|
-
function getConfig(): CXConfig {
|
|
38
|
-
try {
|
|
39
|
-
const configModule = require("../../cx.config.js");
|
|
40
|
-
const config = configModule.default;
|
|
41
|
-
|
|
42
|
-
return config;
|
|
43
|
-
} catch (error) {
|
|
44
|
-
console.log(error);
|
|
45
|
-
throw new Error("Error while reading configuration file");
|
|
46
|
-
}
|
|
47
|
-
}
|
|
7
|
+
import { LifecycleExecutionError } from "../constants/errors";
|
|
8
|
+
import { readDB } from "../services/db";
|
|
9
|
+
import { brush } from "./brush";
|
|
10
|
+
import { throwError } from "./errors";
|
|
11
|
+
import { pathExists } from "./folders";
|
|
12
|
+
import { infoLog, successLog } from "./loggin";
|
|
13
|
+
import { getRenderPathsFromDB } from "./render";
|
|
48
14
|
|
|
49
15
|
/**
|
|
50
16
|
* Returns true for "true", "on", true and positive numbers.
|
|
@@ -90,53 +56,25 @@ function isTruthy(value: any): boolean {
|
|
|
90
56
|
return false;
|
|
91
57
|
}
|
|
92
58
|
|
|
93
|
-
/**
|
|
94
|
-
* Walk a directory and returns the file pathts.
|
|
95
|
-
*
|
|
96
|
-
* @param dir A directory path.
|
|
97
|
-
*/
|
|
98
|
-
function walk(dir: string) {
|
|
99
|
-
const results: Array<string> = [];
|
|
100
|
-
const list = fs.readdirSync(dir);
|
|
101
|
-
for (const file of list) {
|
|
102
|
-
results.push(path.join(dir, file));
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
return results;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
59
|
/**
|
|
109
60
|
* Walk a directory and returns the JSON file absolute paths with one level of depth.
|
|
110
|
-
* Bypass the `metadata` folder.
|
|
111
61
|
* /abs/.../sotre/<siteId>/jsonfile.json
|
|
112
62
|
* /abs/.../sotre/<siteId>/jsonfile.json
|
|
113
63
|
* /abs/.../sotre/<siteId>/jsonfile.json
|
|
114
64
|
* /abs/.../sotre/<siteId>/jsonfile.json
|
|
115
65
|
*/
|
|
116
|
-
function walkStore(
|
|
117
|
-
const
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
for (const subdir of subdirs) {
|
|
127
|
-
const subdirPath = path.join(dir, subdir);
|
|
128
|
-
|
|
129
|
-
// Listamos los archivos en cada subcarpeta y filtramos los .json
|
|
130
|
-
const files = fs
|
|
131
|
-
.readdirSync(subdirPath)
|
|
132
|
-
.filter((file) => file.endsWith(".json"));
|
|
133
|
-
|
|
134
|
-
for (const file of files) {
|
|
135
|
-
results.push(path.join(subdirPath, file));
|
|
66
|
+
async function* walkStore(storeDir: string): AsyncGenerator<string> {
|
|
67
|
+
const rootDirHandle = await fsp.opendir(storeDir);
|
|
68
|
+
for await (const siteDirent of rootDirHandle) {
|
|
69
|
+
if (siteDirent.isDirectory()) {
|
|
70
|
+
const siteDirPath = path.join(storeDir, siteDirent.name);
|
|
71
|
+
const siteDirHandle = await fsp.opendir(siteDirPath);
|
|
72
|
+
for await (const jsonFileDirent of siteDirHandle) {
|
|
73
|
+
const jsonFilePath = path.join(siteDirPath, jsonFileDirent.name);
|
|
74
|
+
yield jsonFilePath;
|
|
75
|
+
}
|
|
136
76
|
}
|
|
137
77
|
}
|
|
138
|
-
|
|
139
|
-
return results;
|
|
140
78
|
}
|
|
141
79
|
|
|
142
80
|
/**
|
|
@@ -187,70 +125,6 @@ function removeProperties(obj: Record<string, unknown>, props: Array<string>) {
|
|
|
187
125
|
}
|
|
188
126
|
}
|
|
189
127
|
|
|
190
|
-
/**
|
|
191
|
-
* Remove unused files (old) inside the `apiCache` dir
|
|
192
|
-
*
|
|
193
|
-
* @todo remove other file types: sites, socials, etc..
|
|
194
|
-
*/
|
|
195
|
-
function sanitizeAPICacheDir() {
|
|
196
|
-
const { __cx } = config.paths();
|
|
197
|
-
const dirPath = path.join(__cx, "apiCache");
|
|
198
|
-
const allCachedFiles = fs.readdirSync(dirPath);
|
|
199
|
-
|
|
200
|
-
// Object to store the the more rencent file names
|
|
201
|
-
// Record<string, string> = { "234856872634", "3268746238747238.json"};
|
|
202
|
-
const filesByIdMap: Record<string, string> = {};
|
|
203
|
-
// ^id ^path
|
|
204
|
-
|
|
205
|
-
// Page files.
|
|
206
|
-
// We only need files that describes a page object.
|
|
207
|
-
const pageFilePaths = allCachedFiles.filter((fileName) => {
|
|
208
|
-
const filePath = `${dirPath}/${fileName}`;
|
|
209
|
-
const fileObject = fsx.readJSONSync(filePath, "utf-8") as APIPageObject;
|
|
210
|
-
const { id, entity, fullUrl } = fileObject;
|
|
211
|
-
|
|
212
|
-
// Is a page file if has id, entity and fullUrl
|
|
213
|
-
return !!(id && entity && fullUrl);
|
|
214
|
-
});
|
|
215
|
-
|
|
216
|
-
// Fill the filesById object
|
|
217
|
-
for (const fileName of pageFilePaths) {
|
|
218
|
-
const filePath = `${dirPath}/${fileName}`;
|
|
219
|
-
const fileObject = fsx.readJSONSync(filePath, "utf-8") as APIPageObject;
|
|
220
|
-
const fileCreationDate = fs.statSync(filePath).mtimeMs;
|
|
221
|
-
|
|
222
|
-
const { id } = fileObject;
|
|
223
|
-
|
|
224
|
-
// Is a valid page if doesn't exists in the store object or is newer
|
|
225
|
-
// that the stored one.
|
|
226
|
-
const validPageFile =
|
|
227
|
-
!filesByIdMap[id] ||
|
|
228
|
-
fileCreationDate > fs.statSync(`${dirPath}/${filesByIdMap[id]}`).mtimeMs;
|
|
229
|
-
|
|
230
|
-
if (validPageFile) {
|
|
231
|
-
filesByIdMap[id] = fileName;
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
let counter = 0;
|
|
236
|
-
|
|
237
|
-
// Delete files using the store object filesById as reference map.
|
|
238
|
-
for (const fileName of pageFilePaths) {
|
|
239
|
-
const filePath = `${dirPath}/${fileName}`;
|
|
240
|
-
const fileObject = fsx.readJSONSync(filePath, "utf-8") as APIPageObject;
|
|
241
|
-
|
|
242
|
-
const { id } = fileObject;
|
|
243
|
-
|
|
244
|
-
// If the filename is not present in the map, remove it!
|
|
245
|
-
if (fileName !== filesByIdMap[id]) {
|
|
246
|
-
fs.unlinkSync(filePath);
|
|
247
|
-
counter++;
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
console.log(`Sanitize apiCache dir for ${counter} files`);
|
|
252
|
-
}
|
|
253
|
-
|
|
254
128
|
/**
|
|
255
129
|
* Measures the execution time of a series of sync or async functions.
|
|
256
130
|
*
|
|
@@ -258,84 +132,64 @@ function sanitizeAPICacheDir() {
|
|
|
258
132
|
* @param functions - Functions to be executed to measure their execution time.
|
|
259
133
|
* @returns A promise that resolves with the total execution time in seconds.
|
|
260
134
|
*/
|
|
261
|
-
async function
|
|
262
|
-
|
|
263
|
-
)
|
|
264
|
-
const
|
|
265
|
-
|
|
266
|
-
for (const func of functions) {
|
|
267
|
-
await func();
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
const [seconds, miliseconds] = process.hrtime(start);
|
|
271
|
-
const timeInSeconds = seconds + miliseconds / 1e9;
|
|
272
|
-
|
|
273
|
-
return +timeInSeconds.toFixed(3);
|
|
135
|
+
async function executeAndReturnExecutionTime<T>(func: () => T | Promise<T>) {
|
|
136
|
+
const start = process.hrtime.bigint();
|
|
137
|
+
await Promise.resolve(func());
|
|
138
|
+
const end = process.hrtime.bigint();
|
|
139
|
+
return Number((Number(end - start) / 1e9).toFixed(3));
|
|
274
140
|
}
|
|
275
141
|
|
|
276
142
|
/**
|
|
277
|
-
*
|
|
278
|
-
*
|
|
279
|
-
* @param title
|
|
280
|
-
* @returns
|
|
281
|
-
*/
|
|
282
|
-
function pause(title: string) {
|
|
283
|
-
const isPauseEnabled = !!envs.GRIDDO_RENDER_BREAKPOINTS_FEATURE;
|
|
284
|
-
|
|
285
|
-
if (!isPauseEnabled) {
|
|
286
|
-
return;
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
return new Promise<void>((resolve) => {
|
|
290
|
-
console.log("\n");
|
|
291
|
-
boxLog(`⌛️ ${title}`, "", 1, 0);
|
|
292
|
-
process.stdin.once("data", () => {
|
|
293
|
-
resolve();
|
|
294
|
-
});
|
|
295
|
-
});
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
/**
|
|
299
|
-
* Executes a life cycle process, which involves executing an array of
|
|
300
|
-
* functions, printing to the console, and handling errors with optional
|
|
301
|
-
* retries.
|
|
143
|
+
* Executes a life cycle process, which involves executing a callback
|
|
144
|
+
* function, printing to the console, and handling errors with optional retries.
|
|
302
145
|
*
|
|
303
146
|
* @async
|
|
304
147
|
* @param name - The name of the life cycle.
|
|
305
|
-
* @param
|
|
306
|
-
* @param options
|
|
148
|
+
* @param action - A callback function to execute.
|
|
149
|
+
* @param options - Optional configuration for the life cycle process.
|
|
150
|
+
* @param options.maxRetrys - The maximum number of retries for the life cycle.
|
|
151
|
+
* @param options.enabled - Whether the life cycle process should be executed.
|
|
307
152
|
* @returns - A promise that resolves when the life cycle process is completed.
|
|
308
153
|
*/
|
|
309
|
-
async function doLifeCycle(
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
}
|
|
154
|
+
async function doLifeCycle(
|
|
155
|
+
name: string,
|
|
156
|
+
action: LifeCycleAction,
|
|
157
|
+
options?: {
|
|
158
|
+
maxRetrys?: number;
|
|
159
|
+
spinner?: boolean;
|
|
160
|
+
skip?: undefined | false | string;
|
|
161
|
+
},
|
|
162
|
+
) {
|
|
163
|
+
const { maxRetrys = 3, skip } = options || {};
|
|
164
|
+
|
|
165
|
+
if (skip) {
|
|
166
|
+
console.log(`Skiping life-cycle. Reason: ${skip}`);
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
324
169
|
|
|
325
170
|
let trysCount = 0;
|
|
326
|
-
const maxTrysAccepted = attemptsByLifeCycleName[name] || 1;
|
|
327
171
|
|
|
328
|
-
while (trysCount <
|
|
172
|
+
while (trysCount < maxRetrys) {
|
|
329
173
|
try {
|
|
330
174
|
infoLog(`start ${name} life-cycle`);
|
|
331
|
-
|
|
175
|
+
|
|
176
|
+
// let counter = 0;
|
|
177
|
+
// process.stdout.write("\x1B[?25l");
|
|
178
|
+
// const spinnerChars = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"];
|
|
179
|
+
// const interval = setInterval(() => {
|
|
180
|
+
// const spinner = spinnerChars[counter % spinnerChars.length];
|
|
181
|
+
// process.stdout.write(`\r${spinner} ${name} life-cycle...`);
|
|
182
|
+
// counter++;
|
|
183
|
+
// }, 60);
|
|
184
|
+
|
|
185
|
+
const exeTime = await executeAndReturnExecutionTime(action);
|
|
186
|
+
// clearInterval(interval);
|
|
187
|
+
// process.stdout.write("\x1B[?25h");
|
|
332
188
|
successLog(`${name} - ${exeTime}s\n`);
|
|
333
|
-
// if no errors, print and go out
|
|
334
|
-
await pause(`${name} LifeCycle`);
|
|
335
189
|
break;
|
|
336
190
|
} catch (error) {
|
|
337
|
-
const errorString =
|
|
338
|
-
const attemptsString =
|
|
191
|
+
const errorString = brush.red(` Error in ${name} LifeCycle `);
|
|
192
|
+
const attemptsString = brush.yellow(`Attempt (${trysCount + 1})`);
|
|
339
193
|
console.log(`\n${errorString} ${attemptsString}\n`);
|
|
340
194
|
console.log(error);
|
|
341
195
|
console.log();
|
|
@@ -344,38 +198,23 @@ async function doLifeCycle(name: LifeCyclesNames, steps: LifeCycleSteps) {
|
|
|
344
198
|
}
|
|
345
199
|
}
|
|
346
200
|
|
|
347
|
-
if (trysCount ===
|
|
348
|
-
throwError(LifecycleExecutionError(
|
|
201
|
+
if (trysCount === maxRetrys) {
|
|
202
|
+
throwError(LifecycleExecutionError(maxRetrys, name));
|
|
349
203
|
}
|
|
350
204
|
}
|
|
351
205
|
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
* @async
|
|
357
|
-
* @param domain
|
|
358
|
-
*/
|
|
359
|
-
async function createDomainMetadata(domain: string) {
|
|
360
|
-
await generateBuildReport();
|
|
361
|
-
await generateSitemaps();
|
|
362
|
-
await RobotsService.writeFiles(domain);
|
|
363
|
-
}
|
|
364
|
-
|
|
365
|
-
function removeAllSiteDirsFromStore() {
|
|
366
|
-
const { __cx } = config.paths();
|
|
367
|
-
const storeDir = path.join(__cx, "store");
|
|
368
|
-
const allDirs = fs.readdirSync(storeDir);
|
|
206
|
+
async function removeAllSiteDirsFromStore() {
|
|
207
|
+
const { __root } = await getRenderPathsFromDB();
|
|
208
|
+
const storeDir = path.join(__root, "store");
|
|
209
|
+
const allDirs = await fsp.readdir(storeDir);
|
|
369
210
|
|
|
370
211
|
const allSiteDirs = allDirs.filter((dirname) => dirname !== "metadata");
|
|
371
212
|
|
|
372
|
-
const allSiteDirsFullPath = allSiteDirs.map((name) =>
|
|
373
|
-
path.join(storeDir, name),
|
|
374
|
-
);
|
|
213
|
+
const allSiteDirsFullPath = allSiteDirs.map((name) => path.join(storeDir, name));
|
|
375
214
|
|
|
376
215
|
// Remove all site directories except "metadata" directory.
|
|
377
216
|
for (const site of allSiteDirsFullPath) {
|
|
378
|
-
|
|
217
|
+
await fsp.rm(site, { recursive: true, force: true });
|
|
379
218
|
}
|
|
380
219
|
}
|
|
381
220
|
|
|
@@ -396,63 +235,85 @@ function getFormattedDateTime() {
|
|
|
396
235
|
return `${date}_${time}`;
|
|
397
236
|
}
|
|
398
237
|
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
*
|
|
402
|
-
* This information will **not** be sent to any API.
|
|
403
|
-
*/
|
|
404
|
-
function saveBuildEndLogs() {
|
|
405
|
-
const { __cx } = config.paths();
|
|
406
|
-
const { sitesToPublish, createdPages, buildProcessData } = fsx.readJSONSync(
|
|
407
|
-
path.join(__cx, "render-metadata.json"),
|
|
408
|
-
);
|
|
238
|
+
async function saveDetailRenderLog(domain: string) {
|
|
239
|
+
const data = await readDB();
|
|
409
240
|
|
|
410
241
|
const dateString = getFormattedDateTime();
|
|
411
|
-
const
|
|
242
|
+
const debugDir = path.join(data.paths.exportsDir, domain, "logs");
|
|
412
243
|
|
|
413
|
-
if (!
|
|
414
|
-
|
|
244
|
+
if (!(await pathExists(debugDir))) {
|
|
245
|
+
await fsp.mkdir(debugDir);
|
|
415
246
|
}
|
|
416
247
|
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
248
|
+
const src = path.join(data.paths.root, "render-detail-log.txt");
|
|
249
|
+
const dst = path.join(debugDir, `${dateString}-render-detail-log.txt`);
|
|
250
|
+
|
|
251
|
+
// Move log to exports
|
|
252
|
+
await fsp.cp(src, dst);
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
const lifeCycleNames: Record<LifeCyclesNames, LifeCyclesNames> = {
|
|
256
|
+
Sync: "Sync",
|
|
257
|
+
Clean: "Clean",
|
|
258
|
+
Close: "Close",
|
|
259
|
+
Data: "Data",
|
|
260
|
+
HealthCheck: "HealthCheck",
|
|
261
|
+
Init: "Init",
|
|
262
|
+
Meta: "Meta",
|
|
263
|
+
Prepare: "Prepare",
|
|
264
|
+
Relocation: "Relocation",
|
|
265
|
+
Restore: "Restore",
|
|
266
|
+
SSG: "SSG",
|
|
267
|
+
} as const;
|
|
268
|
+
|
|
269
|
+
/**
|
|
270
|
+
* Busca de forma recursiva si ALGUNA de las claves de un array existe como propiedad propia
|
|
271
|
+
* en un objeto anidado. La búsqueda se detiene en cuanto se encuentra la primera coincidencia.
|
|
272
|
+
*
|
|
273
|
+
* @param obj El objeto a inspeccionar.
|
|
274
|
+
* @param keysToFind Un array de claves que se buscan.
|
|
275
|
+
* @param visited Un WeakSet para evitar ciclos de referencia.
|
|
276
|
+
* @returns Retorna `true` si al menos una de las claves se encuentra, de lo contrario `false`.
|
|
277
|
+
*/
|
|
278
|
+
function hasAnyKeyDeep<T extends object>(
|
|
279
|
+
obj: T,
|
|
280
|
+
keysToFind: string[],
|
|
281
|
+
visited = new WeakSet<object>(),
|
|
282
|
+
): boolean {
|
|
283
|
+
// 1. Casos base: no procesar no-objetos, si ya lo visitamos, o si el array de claves está vacío.
|
|
284
|
+
if (typeof obj !== "object" || obj === null || visited.has(obj)) {
|
|
285
|
+
return false;
|
|
286
|
+
}
|
|
287
|
+
if (keysToFind.length === 0) {
|
|
288
|
+
return false;
|
|
289
|
+
}
|
|
290
|
+
visited.add(obj);
|
|
291
|
+
|
|
292
|
+
// 2. Comprobar si ALGUNA de las claves buscadas es una propiedad propia del objeto actual.
|
|
293
|
+
// Usamos .some() porque se detiene en la primera coincidencia (eficiencia).
|
|
294
|
+
const foundKey = keysToFind.some((key) => Object.hasOwn(obj, key));
|
|
295
|
+
if (foundKey) {
|
|
296
|
+
return true;
|
|
297
|
+
}
|
|
433
298
|
|
|
434
|
-
//
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
`<pre><a href="${dateString}.json">${dateString}</a></pre>\n`,
|
|
299
|
+
// 3. Si no se encontró ninguna clave en este nivel, recorrer los valores y buscar recursivamente.
|
|
300
|
+
return Object.values(obj).some(
|
|
301
|
+
(value) => typeof value === "object" && hasAnyKeyDeep(value, keysToFind, visited),
|
|
438
302
|
);
|
|
439
303
|
}
|
|
440
304
|
|
|
441
305
|
export {
|
|
442
|
-
createDomainMetadata,
|
|
443
306
|
delay,
|
|
444
307
|
doLifeCycle,
|
|
445
|
-
|
|
308
|
+
executeAndReturnExecutionTime,
|
|
309
|
+
getFormattedDateTime,
|
|
446
310
|
getSafeSiteId,
|
|
447
|
-
|
|
311
|
+
hasAnyKeyDeep,
|
|
448
312
|
isTruthy,
|
|
449
|
-
|
|
313
|
+
lifeCycleNames,
|
|
450
314
|
msToSec,
|
|
451
|
-
pause,
|
|
452
315
|
removeAllSiteDirsFromStore,
|
|
453
316
|
removeProperties,
|
|
454
|
-
|
|
455
|
-
saveBuildEndLogs,
|
|
456
|
-
walk,
|
|
317
|
+
saveDetailRenderLog,
|
|
457
318
|
walkStore,
|
|
458
319
|
};
|
|
@@ -1,17 +1,20 @@
|
|
|
1
1
|
import type { Domains } from "../types/global";
|
|
2
2
|
|
|
3
|
+
import { DOMAINS } from "../constants/endpoints";
|
|
4
|
+
import { NoDomainsFoundError } from "../constants/errors";
|
|
5
|
+
import { get } from "./api";
|
|
6
|
+
import { throwError } from "./errors";
|
|
3
7
|
import { verboseLog } from "./loggin";
|
|
4
|
-
import { throwError } from "../errors";
|
|
5
|
-
import { NoDomainsFoundError } from "../errors/errors-data";
|
|
6
|
-
import { AuthService } from "../services/auth";
|
|
7
|
-
import { getAllDomains } from "../services/domains";
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* Return an array of domains name (string) of the current instance.
|
|
11
11
|
*/
|
|
12
12
|
async function getInstanceDomains() {
|
|
13
|
-
await AuthService.login();
|
|
14
|
-
const domains = await
|
|
13
|
+
// await AuthService.login();
|
|
14
|
+
const domains = await get<Domains>({
|
|
15
|
+
endpoint: DOMAINS,
|
|
16
|
+
useApiCacheDir: false,
|
|
17
|
+
});
|
|
15
18
|
|
|
16
19
|
if (!domains.length) {
|
|
17
20
|
throwError(NoDomainsFoundError);
|
|
@@ -36,4 +39,4 @@ function getDomainSlugs(domains: Domains) {
|
|
|
36
39
|
return [...new Set(filteredDomains)];
|
|
37
40
|
}
|
|
38
41
|
|
|
39
|
-
export {
|
|
42
|
+
export { getDomainSlugs, getInstanceDomains };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { ErrorsType } from "
|
|
1
|
+
import type { ErrorsType } from "../constants/errors";
|
|
2
2
|
|
|
3
|
-
import
|
|
3
|
+
import { brush } from "./brush";
|
|
4
4
|
|
|
5
5
|
export type ErrorData = {
|
|
6
6
|
error: ErrorsType;
|
|
@@ -10,20 +10,21 @@ export type ErrorData = {
|
|
|
10
10
|
};
|
|
11
11
|
|
|
12
12
|
export class RenderError extends Error {
|
|
13
|
-
constructor() {
|
|
14
|
-
super();
|
|
13
|
+
constructor(originalError?: unknown) {
|
|
14
|
+
super(originalError instanceof Error ? originalError.message : String(originalError));
|
|
15
|
+
|
|
15
16
|
this.name = "InternalCXError";
|
|
16
|
-
this.stack = "";
|
|
17
|
+
this.stack = originalError instanceof Error ? originalError.stack : "";
|
|
17
18
|
}
|
|
18
19
|
}
|
|
19
20
|
|
|
20
21
|
/**
|
|
21
22
|
* Throws an error with the provided error message, expected value, and hint.
|
|
22
23
|
*/
|
|
23
|
-
function throwError(options: ErrorData, stack?: unknown) {
|
|
24
|
+
function throwError(options: ErrorData, stack?: unknown): never {
|
|
24
25
|
const { error, message, expected, hint } = options;
|
|
25
26
|
|
|
26
|
-
const errorColor =
|
|
27
|
+
const errorColor = console.log(brush.red(`[ ${error} ]`));
|
|
27
28
|
const extraText = [expected, hint].filter(Boolean).join("\n");
|
|
28
29
|
|
|
29
30
|
console.log(`
|
|
@@ -31,10 +32,10 @@ ${errorColor}
|
|
|
31
32
|
${message}
|
|
32
33
|
${extraText}
|
|
33
34
|
|
|
34
|
-
${
|
|
35
|
+
${brush.red("stack")}
|
|
35
36
|
${JSON.stringify(stack, null, 2)}`);
|
|
36
37
|
|
|
37
|
-
throw new RenderError();
|
|
38
|
+
throw new RenderError(stack);
|
|
38
39
|
}
|
|
39
40
|
|
|
40
41
|
export { throwError };
|