@griddo/cx 11.7.11 → 11.7.12-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +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
package/exporter/utils/cache.ts
CHANGED
|
@@ -2,24 +2,21 @@ import type { Petition } from "../types/global";
|
|
|
2
2
|
import type { HashSites, SiteHash } from "../types/sites";
|
|
3
3
|
|
|
4
4
|
import crypto from "node:crypto";
|
|
5
|
-
import
|
|
5
|
+
import fsp from "node:fs/promises";
|
|
6
6
|
import path from "node:path";
|
|
7
7
|
|
|
8
|
-
import
|
|
9
|
-
|
|
10
|
-
import { getConfig } from "./core-utils";
|
|
11
|
-
|
|
12
|
-
const config = getConfig();
|
|
8
|
+
import { pathExists } from "../utils/folders";
|
|
9
|
+
import { getRenderPathsFromDB } from "./render";
|
|
13
10
|
|
|
14
11
|
/**
|
|
15
12
|
* Creates an `apiCache` dir to store pages fetched from them API.
|
|
16
13
|
*/
|
|
17
|
-
function createAPICacheDir() {
|
|
18
|
-
const {
|
|
19
|
-
const apiCacheDir = path.join(
|
|
14
|
+
async function createAPICacheDir(options: { basePath: string }) {
|
|
15
|
+
const { basePath } = options;
|
|
16
|
+
const apiCacheDir = path.join(basePath, "apiCache");
|
|
20
17
|
|
|
21
|
-
if (!
|
|
22
|
-
|
|
18
|
+
if (!(await pathExists(apiCacheDir))) {
|
|
19
|
+
await fsp.mkdir(apiCacheDir);
|
|
23
20
|
}
|
|
24
21
|
|
|
25
22
|
console.info("Cache initialized");
|
|
@@ -27,13 +24,11 @@ function createAPICacheDir() {
|
|
|
27
24
|
|
|
28
25
|
/**
|
|
29
26
|
* Generate a filename with a hash using a Petition object
|
|
30
|
-
*
|
|
31
|
-
* @todo Merge with createSha256
|
|
32
27
|
* @param petition An object
|
|
33
28
|
*/
|
|
34
|
-
function generateFilenameWithHash(petition: Petition) {
|
|
35
|
-
const {
|
|
36
|
-
const apiCacheDir = path.join(
|
|
29
|
+
async function generateFilenameWithHash(petition: Petition) {
|
|
30
|
+
const { __root } = await getRenderPathsFromDB();
|
|
31
|
+
const apiCacheDir = path.join(__root, "apiCache");
|
|
37
32
|
|
|
38
33
|
const hashSum = crypto.createHash("sha256");
|
|
39
34
|
hashSum.update(JSON.stringify(petition));
|
|
@@ -41,35 +36,22 @@ function generateFilenameWithHash(petition: Petition) {
|
|
|
41
36
|
return `${apiCacheDir}/${hashSum.digest("hex")}`;
|
|
42
37
|
}
|
|
43
38
|
|
|
44
|
-
/**
|
|
45
|
-
* Generate a filename with a hash using a string.
|
|
46
|
-
*
|
|
47
|
-
* @todo Merge with generateFilenameWithHash
|
|
48
|
-
* @param data A string to create a sha256 based on.
|
|
49
|
-
*/
|
|
50
|
-
function createSha256(data: string) {
|
|
51
|
-
const uniqueString = crypto.randomBytes(16).toString("hex");
|
|
52
|
-
const hash = crypto.createHash("sha256");
|
|
53
|
-
hash.update(`${data}${uniqueString}`);
|
|
54
|
-
|
|
55
|
-
return hash.digest("hex");
|
|
56
|
-
}
|
|
57
|
-
|
|
58
39
|
/**
|
|
59
40
|
* Save a file using a hash name.
|
|
60
41
|
*
|
|
61
42
|
* @param petition An object.
|
|
62
43
|
* @param content Content to be saved.
|
|
63
44
|
*/
|
|
64
|
-
function saveCache<T>(petition: Petition, content: T) {
|
|
65
|
-
const stringContent =
|
|
66
|
-
|
|
67
|
-
const filename = generateFilenameWithHash(petition);
|
|
45
|
+
async function saveCache<T>(petition: Petition, content: T) {
|
|
46
|
+
const stringContent = typeof content === "string" ? content : JSON.stringify(content);
|
|
47
|
+
const filename = await generateFilenameWithHash(petition);
|
|
68
48
|
const filepath = path.dirname(filename);
|
|
69
|
-
|
|
70
|
-
|
|
49
|
+
|
|
50
|
+
if (!(await pathExists(filepath))) {
|
|
51
|
+
await fsp.mkdir(filepath, { recursive: true });
|
|
71
52
|
}
|
|
72
|
-
|
|
53
|
+
|
|
54
|
+
await fsp.writeFile(filename, stringContent, "utf8");
|
|
73
55
|
}
|
|
74
56
|
|
|
75
57
|
/**
|
|
@@ -78,13 +60,13 @@ function saveCache<T>(petition: Petition, content: T) {
|
|
|
78
60
|
*
|
|
79
61
|
* @param petition An object
|
|
80
62
|
*/
|
|
81
|
-
function searchCacheData<T>(petition: Petition) {
|
|
63
|
+
async function searchCacheData<T>(petition: Petition) {
|
|
82
64
|
try {
|
|
83
|
-
const file = generateFilenameWithHash(petition);
|
|
84
|
-
const
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
return jsonData
|
|
65
|
+
const file = await generateFilenameWithHash(petition);
|
|
66
|
+
const fileContent = await fsp.readFile(file, "utf8");
|
|
67
|
+
const jsonData = JSON.parse(fileContent) as T;
|
|
68
|
+
|
|
69
|
+
return jsonData;
|
|
88
70
|
} catch {
|
|
89
71
|
return null;
|
|
90
72
|
}
|
|
@@ -93,15 +75,14 @@ function searchCacheData<T>(petition: Petition) {
|
|
|
93
75
|
/**
|
|
94
76
|
* Get site hashes from the file as an object
|
|
95
77
|
*/
|
|
96
|
-
function getHashSites(): HashSites {
|
|
97
|
-
const {
|
|
98
|
-
const apiCacheDir = path.join(
|
|
78
|
+
async function getHashSites(): Promise<HashSites> {
|
|
79
|
+
const { __root } = await getRenderPathsFromDB();
|
|
80
|
+
const apiCacheDir = path.join(__root, "apiCache");
|
|
99
81
|
const siteHasFilename = `${apiCacheDir}/siteHash.json`;
|
|
100
82
|
|
|
101
83
|
try {
|
|
102
|
-
const
|
|
103
|
-
|
|
104
|
-
});
|
|
84
|
+
const fileContent = await fsp.readFile(siteHasFilename, "utf8");
|
|
85
|
+
const jsonData = JSON.parse(fileContent);
|
|
105
86
|
return jsonData || {};
|
|
106
87
|
} catch {
|
|
107
88
|
return {};
|
|
@@ -114,18 +95,18 @@ function getHashSites(): HashSites {
|
|
|
114
95
|
* @param siteId The id of the site.
|
|
115
96
|
* @param siteHash The has of the site.
|
|
116
97
|
*/
|
|
117
|
-
function updatedSiteHash(siteId: number, siteHash: SiteHash) {
|
|
118
|
-
const allHash = getHashSites();
|
|
98
|
+
async function updatedSiteHash(siteId: number, siteHash: SiteHash) {
|
|
99
|
+
const allHash = await getHashSites();
|
|
119
100
|
const lastHash = allHash[siteId];
|
|
120
|
-
const currentHash = siteHash || lastHash ||
|
|
101
|
+
const currentHash = siteHash || lastHash || Date.now();
|
|
121
102
|
|
|
122
|
-
const {
|
|
123
|
-
const apiCacheDir = path.join(
|
|
103
|
+
const { __root } = await getRenderPathsFromDB();
|
|
104
|
+
const apiCacheDir = path.join(__root, "apiCache");
|
|
124
105
|
const siteHasFilename = `${apiCacheDir}/siteHash.json`;
|
|
125
106
|
|
|
126
107
|
if (currentHash !== lastHash) {
|
|
127
108
|
allHash[siteId] = currentHash;
|
|
128
|
-
|
|
109
|
+
await fsp.writeFile(siteHasFilename, JSON.stringify(allHash), {
|
|
129
110
|
encoding: "utf-8",
|
|
130
111
|
});
|
|
131
112
|
}
|
|
@@ -133,10 +114,4 @@ function updatedSiteHash(siteId: number, siteHash: SiteHash) {
|
|
|
133
114
|
return currentHash.toString();
|
|
134
115
|
}
|
|
135
116
|
|
|
136
|
-
export {
|
|
137
|
-
createAPICacheDir,
|
|
138
|
-
createSha256,
|
|
139
|
-
saveCache,
|
|
140
|
-
searchCacheData,
|
|
141
|
-
updatedSiteHash,
|
|
142
|
-
};
|
|
117
|
+
export { createAPICacheDir, saveCache, searchCacheData, updatedSiteHash };
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { CheckHealthError } from "../constants/errors";
|
|
4
|
+
import { isTruthy } from "./core-utils";
|
|
5
|
+
import { throwError } from "./errors";
|
|
6
|
+
import { infoLog } from "./loggin";
|
|
7
|
+
|
|
8
|
+
const GRIDDO_ENVS_VARS: ReadonlyArray<string> = [];
|
|
9
|
+
const GRIDDO_SKIP_BUILD_CHECKS = isTruthy(process.env.GRIDDO_SKIP_BUILD_CHECKS);
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Check if a list of environments variables exist with any value.
|
|
13
|
+
*
|
|
14
|
+
* @todo Also check the value.
|
|
15
|
+
* @param envs An array of environments variables
|
|
16
|
+
* @returns exists with (1) if there are missing envs vars
|
|
17
|
+
*/
|
|
18
|
+
function checkEnvsVars(envs: ReadonlyArray<string>) {
|
|
19
|
+
const missingEnvs = envs.filter((envName) => {
|
|
20
|
+
return !process.env[envName];
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
if (missingEnvs.length) {
|
|
24
|
+
const missingEnvsMsg = missingEnvs.join("\n");
|
|
25
|
+
console.error(`Env check failed. These envs vars are missing: \n\n${missingEnvsMsg}`);
|
|
26
|
+
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return true;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function checkEnvsVarsAndValues(envs: Array<Record<string, string>>): boolean {
|
|
34
|
+
for (const env of envs) {
|
|
35
|
+
const [key, expected] = Object.entries(env)[0];
|
|
36
|
+
const actual = process.env[key];
|
|
37
|
+
|
|
38
|
+
if (actual !== expected) {
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return true;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Check if the environment is secure to launch a render.
|
|
47
|
+
* If something fails then log an error message and exit from the process.
|
|
48
|
+
* Otherwise just return true.
|
|
49
|
+
*/
|
|
50
|
+
export function checkEnvironmentHealth() {
|
|
51
|
+
// Bypass the check using this env var, handy for local renders.
|
|
52
|
+
if (GRIDDO_SKIP_BUILD_CHECKS) {
|
|
53
|
+
infoLog("Build health check skipped");
|
|
54
|
+
|
|
55
|
+
return true;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// Checklist
|
|
59
|
+
// check if it's setted
|
|
60
|
+
const areRequiredEnvsSet = checkEnvsVars(GRIDDO_ENVS_VARS);
|
|
61
|
+
// check if it's setted and the value
|
|
62
|
+
const areEnvsMatchingExpected = checkEnvsVarsAndValues([
|
|
63
|
+
{
|
|
64
|
+
GRIDDO_RENDER_BY_DOMAINS: "true",
|
|
65
|
+
},
|
|
66
|
+
]);
|
|
67
|
+
|
|
68
|
+
// Render is safe if...
|
|
69
|
+
const isSafeToRender = areRequiredEnvsSet && areEnvsMatchingExpected;
|
|
70
|
+
|
|
71
|
+
// The environment is suitable for a build-render
|
|
72
|
+
if (isSafeToRender) {
|
|
73
|
+
console.info("\nBuild health check passed\n");
|
|
74
|
+
|
|
75
|
+
return true;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// Error
|
|
79
|
+
throwError(CheckHealthError);
|
|
80
|
+
}
|