@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,16 +1,50 @@
|
|
|
1
1
|
import type { APIResponses } from "../types/api";
|
|
2
|
-
import type {
|
|
3
|
-
|
|
4
|
-
|
|
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";
|
|
5
10
|
import path from "node:path";
|
|
6
11
|
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import {
|
|
10
|
-
import
|
|
11
|
-
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
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";
|
|
24
|
+
|
|
25
|
+
const config = getConfig();
|
|
26
|
+
|
|
27
|
+
const instanceRootDir = pkgDir.sync()!; // instance root dir
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Returns the configuration file content.
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* const config = getConfig()
|
|
34
|
+
* const { __cx } = config.paths()
|
|
35
|
+
* const { griddoVersion, proDomain } = config
|
|
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
|
+
}
|
|
14
48
|
|
|
15
49
|
/**
|
|
16
50
|
* Returns true for "true", "on", true and positive numbers.
|
|
@@ -56,25 +90,53 @@ function isTruthy(value: any): boolean {
|
|
|
56
90
|
return false;
|
|
57
91
|
}
|
|
58
92
|
|
|
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
|
+
|
|
59
108
|
/**
|
|
60
109
|
* Walk a directory and returns the JSON file absolute paths with one level of depth.
|
|
110
|
+
* Bypass the `metadata` folder.
|
|
61
111
|
* /abs/.../sotre/<siteId>/jsonfile.json
|
|
62
112
|
* /abs/.../sotre/<siteId>/jsonfile.json
|
|
63
113
|
* /abs/.../sotre/<siteId>/jsonfile.json
|
|
64
114
|
* /abs/.../sotre/<siteId>/jsonfile.json
|
|
65
115
|
*/
|
|
66
|
-
|
|
67
|
-
const
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
116
|
+
function walkStore(dir: string): Array<string> {
|
|
117
|
+
const results: Array<string> = [];
|
|
118
|
+
|
|
119
|
+
// Listamos todas las subcarpetas y evitamos entrar en 'metadata'
|
|
120
|
+
const subdirs = fs.readdirSync(dir).filter((file) => {
|
|
121
|
+
const fullPath = path.join(dir, file);
|
|
122
|
+
return fs.statSync(fullPath).isDirectory() && file !== "metadata";
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
// Iteramos sobre las subcarpetas
|
|
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));
|
|
76
136
|
}
|
|
77
137
|
}
|
|
138
|
+
|
|
139
|
+
return results;
|
|
78
140
|
}
|
|
79
141
|
|
|
80
142
|
/**
|
|
@@ -125,6 +187,70 @@ function removeProperties(obj: Record<string, unknown>, props: Array<string>) {
|
|
|
125
187
|
}
|
|
126
188
|
}
|
|
127
189
|
|
|
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
|
+
|
|
128
254
|
/**
|
|
129
255
|
* Measures the execution time of a series of sync or async functions.
|
|
130
256
|
*
|
|
@@ -132,64 +258,84 @@ function removeProperties(obj: Record<string, unknown>, props: Array<string>) {
|
|
|
132
258
|
* @param functions - Functions to be executed to measure their execution time.
|
|
133
259
|
* @returns A promise that resolves with the total execution time in seconds.
|
|
134
260
|
*/
|
|
135
|
-
async function
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
const
|
|
139
|
-
|
|
261
|
+
async function measureExecutionTime(
|
|
262
|
+
functions: Array<(...args: Array<unknown>) => unknown | Promise<unknown>>,
|
|
263
|
+
) {
|
|
264
|
+
const start = process.hrtime();
|
|
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);
|
|
140
274
|
}
|
|
141
275
|
|
|
142
276
|
/**
|
|
143
|
-
*
|
|
144
|
-
* function, printing to the console, and handling errors with optional retries.
|
|
277
|
+
* Pause the process until a key is pressed.
|
|
145
278
|
*
|
|
146
|
-
* @
|
|
147
|
-
* @
|
|
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.
|
|
152
|
-
* @returns - A promise that resolves when the life cycle process is completed.
|
|
279
|
+
* @param title
|
|
280
|
+
* @returns
|
|
153
281
|
*/
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
action: LifeCycleAction,
|
|
157
|
-
options?: {
|
|
158
|
-
maxRetrys?: number;
|
|
159
|
-
spinner?: boolean;
|
|
160
|
-
skip?: undefined | false | string;
|
|
161
|
-
},
|
|
162
|
-
) {
|
|
163
|
-
const { maxRetrys = 3, skip } = options || {};
|
|
282
|
+
function pause(title: string) {
|
|
283
|
+
const isPauseEnabled = !!envs.GRIDDO_RENDER_BREAKPOINTS_FEATURE;
|
|
164
284
|
|
|
165
|
-
if (
|
|
166
|
-
console.log(`Skiping life-cycle. Reason: ${skip}`);
|
|
285
|
+
if (!isPauseEnabled) {
|
|
167
286
|
return;
|
|
168
287
|
}
|
|
169
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.
|
|
302
|
+
*
|
|
303
|
+
* @async
|
|
304
|
+
* @param name - The name of the life cycle.
|
|
305
|
+
* @param options - The arguments object.
|
|
306
|
+
* @param options.steps - An array of functions to execute.
|
|
307
|
+
* @returns - A promise that resolves when the life cycle process is completed.
|
|
308
|
+
*/
|
|
309
|
+
async function doLifeCycle(name: LifeCyclesNames, steps: LifeCycleSteps) {
|
|
310
|
+
const attemptsByLifeCycleName: Record<LifeCyclesNames, number> = {
|
|
311
|
+
Init: envs.GRIDDO_ARCHIVE_LIFECYCLE_MAX_ATTEMPTS,
|
|
312
|
+
Archive: envs.GRIDDO_ARCHIVE_LIFECYCLE_MAX_ATTEMPTS,
|
|
313
|
+
Data: envs.GRIDDO_DATA_LIFECYCLE_MAX_ATTEMPTS,
|
|
314
|
+
Meta: envs.GRIDDO_META_LIFECYCLE_MAX_ATTEMPTS,
|
|
315
|
+
Relocation: envs.GRIDDO_RELOCATION_LIFECYCLE_MAX_ATTEMPTS,
|
|
316
|
+
Clean: envs.GRIDDO_CLEAN_LIFECYCLE_MAX_ATTEMPTS,
|
|
317
|
+
Restore: envs.GRIDDO_RESTORE_LIFECYCLE_MAX_ATTEMPTS,
|
|
318
|
+
Prepare: envs.GRIDDO_PREPARE_LIFECYCLE_MAX_ATTEMPTS,
|
|
319
|
+
Close: envs.GRIDDO_CLOSE_LIFECYCLE_MAX_ATTEMPTS,
|
|
320
|
+
SSG: envs.GRIDDO_SSG_LIFECYCLE_MAX_ATTEMPTS,
|
|
321
|
+
HealthCheck: 1,
|
|
322
|
+
__DEBUG__: 1,
|
|
323
|
+
};
|
|
324
|
+
|
|
170
325
|
let trysCount = 0;
|
|
326
|
+
const maxTrysAccepted = attemptsByLifeCycleName[name] || 1;
|
|
171
327
|
|
|
172
|
-
while (trysCount <
|
|
328
|
+
while (trysCount < maxTrysAccepted) {
|
|
173
329
|
try {
|
|
174
330
|
infoLog(`start ${name} life-cycle`);
|
|
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");
|
|
331
|
+
const exeTime = await measureExecutionTime(steps);
|
|
188
332
|
successLog(`${name} - ${exeTime}s\n`);
|
|
333
|
+
// if no errors, print and go out
|
|
334
|
+
await pause(`${name} LifeCycle`);
|
|
189
335
|
break;
|
|
190
336
|
} catch (error) {
|
|
191
|
-
const errorString =
|
|
192
|
-
const attemptsString =
|
|
337
|
+
const errorString = bgRed(black(` Error in ${name} LifeCycle `));
|
|
338
|
+
const attemptsString = kleur.yellow(`Attempt (${trysCount + 1})`);
|
|
193
339
|
console.log(`\n${errorString} ${attemptsString}\n`);
|
|
194
340
|
console.log(error);
|
|
195
341
|
console.log();
|
|
@@ -198,23 +344,38 @@ async function doLifeCycle(
|
|
|
198
344
|
}
|
|
199
345
|
}
|
|
200
346
|
|
|
201
|
-
if (trysCount ===
|
|
202
|
-
throwError(LifecycleExecutionError(
|
|
347
|
+
if (trysCount === maxTrysAccepted) {
|
|
348
|
+
throwError(LifecycleExecutionError(maxTrysAccepted, name));
|
|
203
349
|
}
|
|
204
350
|
}
|
|
205
351
|
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
352
|
+
/**
|
|
353
|
+
* Creates additional files after the render: sitemaps, robots and a report of
|
|
354
|
+
* the finished render.
|
|
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);
|
|
210
369
|
|
|
211
370
|
const allSiteDirs = allDirs.filter((dirname) => dirname !== "metadata");
|
|
212
371
|
|
|
213
|
-
const allSiteDirsFullPath = allSiteDirs.map((name) =>
|
|
372
|
+
const allSiteDirsFullPath = allSiteDirs.map((name) =>
|
|
373
|
+
path.join(storeDir, name),
|
|
374
|
+
);
|
|
214
375
|
|
|
215
376
|
// Remove all site directories except "metadata" directory.
|
|
216
377
|
for (const site of allSiteDirsFullPath) {
|
|
217
|
-
|
|
378
|
+
fs.rmSync(site, { recursive: true, force: true });
|
|
218
379
|
}
|
|
219
380
|
}
|
|
220
381
|
|
|
@@ -235,85 +396,63 @@ function getFormattedDateTime() {
|
|
|
235
396
|
return `${date}_${time}`;
|
|
236
397
|
}
|
|
237
398
|
|
|
238
|
-
async function saveDetailRenderLog(domain: string) {
|
|
239
|
-
const data = await readDB();
|
|
240
|
-
|
|
241
|
-
const dateString = getFormattedDateTime();
|
|
242
|
-
const debugDir = path.join(data.paths.exportsDir, domain, "logs");
|
|
243
|
-
|
|
244
|
-
if (!(await pathExists(debugDir))) {
|
|
245
|
-
await fsp.mkdir(debugDir);
|
|
246
|
-
}
|
|
247
|
-
|
|
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
399
|
/**
|
|
270
|
-
*
|
|
271
|
-
* en un objeto anidado. La búsqueda se detiene en cuanto se encuentra la primera coincidencia.
|
|
400
|
+
* Save render information to a file to use as debug log.
|
|
272
401
|
*
|
|
273
|
-
*
|
|
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`.
|
|
402
|
+
* This information will **not** be sent to any API.
|
|
277
403
|
*/
|
|
278
|
-
function
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
)
|
|
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);
|
|
404
|
+
function saveBuildEndLogs() {
|
|
405
|
+
const { __cx } = config.paths();
|
|
406
|
+
const { sitesToPublish, createdPages, buildProcessData } = fsx.readJSONSync(
|
|
407
|
+
path.join(__cx, "render-metadata.json"),
|
|
408
|
+
);
|
|
291
409
|
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
if (
|
|
296
|
-
|
|
410
|
+
const dateString = getFormattedDateTime();
|
|
411
|
+
const buildEndLogsDir = path.join(__cx, "debug", "build-end");
|
|
412
|
+
|
|
413
|
+
if (!fs.existsSync(buildEndLogsDir)) {
|
|
414
|
+
fs.mkdirSync(buildEndLogsDir, { recursive: true });
|
|
297
415
|
}
|
|
298
416
|
|
|
299
|
-
//
|
|
300
|
-
|
|
301
|
-
(
|
|
417
|
+
// Log
|
|
418
|
+
fs.writeFileSync(
|
|
419
|
+
path.join(buildEndLogsDir, `${dateString}.json`),
|
|
420
|
+
JSON.stringify(
|
|
421
|
+
{
|
|
422
|
+
date: new Date().toLocaleString(),
|
|
423
|
+
log: {
|
|
424
|
+
sitesToPublish,
|
|
425
|
+
createdPages,
|
|
426
|
+
buildProcessData,
|
|
427
|
+
},
|
|
428
|
+
},
|
|
429
|
+
null,
|
|
430
|
+
2,
|
|
431
|
+
),
|
|
432
|
+
);
|
|
433
|
+
|
|
434
|
+
// Update index
|
|
435
|
+
prependFileSync(
|
|
436
|
+
path.join(buildEndLogsDir, "index.html"),
|
|
437
|
+
`<pre><a href="${dateString}.json">${dateString}</a></pre>\n`,
|
|
302
438
|
);
|
|
303
439
|
}
|
|
304
440
|
|
|
305
441
|
export {
|
|
442
|
+
createDomainMetadata,
|
|
306
443
|
delay,
|
|
307
444
|
doLifeCycle,
|
|
308
|
-
|
|
309
|
-
getFormattedDateTime,
|
|
445
|
+
getConfig,
|
|
310
446
|
getSafeSiteId,
|
|
311
|
-
|
|
447
|
+
instanceRootDir,
|
|
312
448
|
isTruthy,
|
|
313
|
-
|
|
449
|
+
measureExecutionTime,
|
|
314
450
|
msToSec,
|
|
451
|
+
pause,
|
|
315
452
|
removeAllSiteDirsFromStore,
|
|
316
453
|
removeProperties,
|
|
317
|
-
|
|
454
|
+
sanitizeAPICacheDir,
|
|
455
|
+
saveBuildEndLogs,
|
|
456
|
+
walk,
|
|
318
457
|
walkStore,
|
|
319
458
|
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { createAPICacheDir } from "./cache";
|
|
2
|
+
import { sanitizeAPICacheDir } from "./core-utils";
|
|
3
|
+
import { createStore } from "../services/store";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Download all data: sites, pages etc.. from the instance private Griddo API.
|
|
7
|
+
* Then you can use the generator funcion `getBuildPagesFromStore()` to get the pages and
|
|
8
|
+
* `getBuildMetadata()` to get build and sites metadata as objects. Both from
|
|
9
|
+
* exporter utils sites dir.
|
|
10
|
+
*/
|
|
11
|
+
async function createDomainRenderData(domain: string) {
|
|
12
|
+
createAPICacheDir();
|
|
13
|
+
await createStore(domain);
|
|
14
|
+
sanitizeAPICacheDir();
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export { createDomainRenderData };
|
|
@@ -1,20 +1,17 @@
|
|
|
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";
|
|
7
3
|
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
|
-
|
|
14
|
-
const domains = await
|
|
15
|
-
endpoint: DOMAINS,
|
|
16
|
-
useApiCacheDir: false,
|
|
17
|
-
});
|
|
13
|
+
await AuthService.login();
|
|
14
|
+
const domains = await getAllDomains();
|
|
18
15
|
|
|
19
16
|
if (!domains.length) {
|
|
20
17
|
throwError(NoDomainsFoundError);
|
|
@@ -39,4 +36,4 @@ function getDomainSlugs(domains: Domains) {
|
|
|
39
36
|
return [...new Set(filteredDomains)];
|
|
40
37
|
}
|
|
41
38
|
|
|
42
|
-
export {
|
|
39
|
+
export { getInstanceDomains, getDomainSlugs };
|