@griddo/cx 10.4.21 → 10.4.23
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/build/adapters/gatsby/utils.d.ts +21 -15
- package/build/browser/index.d.ts +1 -1
- package/build/browser/index.js +1 -1
- package/build/build-complete.js +21 -21
- package/build/index.d.ts +2 -3
- package/build/index.js +30 -34
- package/build/react/Foo/index.d.ts +3 -0
- package/build/react/index.d.ts +1 -1
- package/build/react/index.js +1 -0
- package/build/reset-render.js +21 -21
- package/build/run-start-render.js +29 -33
- package/build/start-render.js +30 -34
- package/build/types/global.d.ts +1 -0
- package/build/upload-search-content.js +22 -22
- package/build/utils/{shared.d.ts → core-utils.d.ts} +44 -2
- package/build/utils/folders.d.ts +6 -1
- package/build/utils/store.d.ts +1 -1
- package/cx.config.js +7 -0
- package/exporter/adapters/gatsby/index.ts +67 -14
- package/exporter/adapters/gatsby/utils.ts +116 -31
- package/exporter/browser/index.ts +1 -1
- package/exporter/build-complete.ts +5 -5
- package/exporter/index.ts +6 -5
- package/exporter/react/Foo/index.tsx +7 -0
- package/exporter/react/index.tsx +3 -0
- package/exporter/services/distributors.ts +1 -1
- package/exporter/services/robots.ts +1 -1
- package/exporter/services/store.ts +9 -16
- package/exporter/start-render.ts +1 -1
- package/exporter/types/global.ts +1 -0
- package/exporter/utils/api.ts +1 -1
- package/exporter/utils/cache.ts +1 -1
- package/exporter/utils/{shared.ts → core-utils.ts} +120 -20
- package/exporter/utils/create-build-data.ts +1 -1
- package/exporter/utils/domains.ts +3 -0
- package/exporter/utils/folders.ts +38 -2
- package/exporter/utils/health-checks.ts +1 -1
- package/exporter/utils/searches.ts +1 -1
- package/exporter/utils/sites.ts +12 -18
- package/exporter/utils/store.ts +2 -3
- package/gatsby-config.ts +10 -6
- package/gatsby-node.ts +20 -11
- package/package.json +8 -5
- package/src/components/template.tsx +2 -1
- package/src/gatsby-node-utils.ts +2 -39
- package/src/types.ts +6 -7
- package/build/utils/temp-utils.d.ts +0 -10
- package/exporter/react/index.ts +0 -5
- package/exporter/utils/temp-utils.ts +0 -103
|
@@ -1,8 +1,50 @@
|
|
|
1
1
|
import type { Adapters } from "../adapters";
|
|
2
2
|
import type { APIResponses } from "../types/api";
|
|
3
|
-
import type { LifeCyclesNames } from "../types/global";
|
|
3
|
+
import type { CXConfig, LifeCyclesNames } from "../types/global";
|
|
4
4
|
import type { Site } from "../types/sites";
|
|
5
5
|
declare const instanceRootDir: string;
|
|
6
|
+
declare const attempts: {
|
|
7
|
+
clean: any;
|
|
8
|
+
prepare: any;
|
|
9
|
+
restore: any;
|
|
10
|
+
data: any;
|
|
11
|
+
ssg: any;
|
|
12
|
+
relocation: any;
|
|
13
|
+
meta: any;
|
|
14
|
+
archive: any;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Returns the configuration file content.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* const config = getConfig()
|
|
21
|
+
* const { __cx } = config.paths()
|
|
22
|
+
* const { griddoVersion, proDomain } = config
|
|
23
|
+
*/
|
|
24
|
+
declare function getConfig(): CXConfig;
|
|
25
|
+
/**
|
|
26
|
+
* Create the initial mandatory directories for a render.
|
|
27
|
+
*
|
|
28
|
+
* @param domain The current domain in render.
|
|
29
|
+
*/
|
|
30
|
+
declare function exporterCreateInitialDirectories(domain: string): Promise<void>;
|
|
31
|
+
/**
|
|
32
|
+
* Remove trash directories from __cx, maybe from a failed render.
|
|
33
|
+
*
|
|
34
|
+
* @param domain The current domain in render.
|
|
35
|
+
*/
|
|
36
|
+
declare function exporterCleanDisposableDirectories(domain: string): Promise<void>;
|
|
37
|
+
/**
|
|
38
|
+
* Custom basic logging function controlled by a environment variable.
|
|
39
|
+
*
|
|
40
|
+
* @param str The string to be logged.
|
|
41
|
+
*/
|
|
42
|
+
declare function verbose(str: string): void;
|
|
43
|
+
/**
|
|
44
|
+
* Returns true for `true`, true, positive numbers
|
|
45
|
+
* Returns false for `false`, false, 0, negative integers and anything else
|
|
46
|
+
*/
|
|
47
|
+
declare function isTruthy(value: any): boolean;
|
|
6
48
|
/**
|
|
7
49
|
* Walk a directory and returns the file pathts.
|
|
8
50
|
*
|
|
@@ -107,4 +149,4 @@ declare function doLifeCycle(args: {
|
|
|
107
149
|
}): Promise<void>;
|
|
108
150
|
declare function isVersionGreaterThan(versionA: string, versionB: string): boolean;
|
|
109
151
|
declare function isVersionLowerThan(versionA: string, versionB: string): boolean;
|
|
110
|
-
export { debug, delay, doLifeCycle, instanceRootDir, isVersionGreaterThan, isVersionLowerThan, logBox, logInfo, logPageSize, measureExecutionTime, pause, printExporterLogo, removeProperties, sanitizeAPICacheDir, siteList, startLifeCycle, successLifeCyle, walk, };
|
|
152
|
+
export { attempts, debug, delay, doLifeCycle, exporterCleanDisposableDirectories, exporterCreateInitialDirectories, getConfig, instanceRootDir, isTruthy, isVersionGreaterThan, isVersionLowerThan, logBox, logInfo, logPageSize, measureExecutionTime, pause, printExporterLogo, removeProperties, sanitizeAPICacheDir, siteList, startLifeCycle, successLifeCyle, verbose, walk, };
|
package/build/utils/folders.d.ts
CHANGED
|
@@ -45,4 +45,9 @@ declare function moveDirsSync(src: string, dst: string, dirs: Array<string>, opt
|
|
|
45
45
|
*/
|
|
46
46
|
declare function removeDirsSync(basePath: string, dirs: Array<string>): void;
|
|
47
47
|
declare function removeVirtualPagesFromStore(): Promise<void>;
|
|
48
|
-
|
|
48
|
+
/**
|
|
49
|
+
* Remove every .xml file in the directories in a recursive way
|
|
50
|
+
* @param initialFolder - The initial folder to start the searching...
|
|
51
|
+
*/
|
|
52
|
+
declare function clearSitemapsFromDirs(initialFolder: string): void;
|
|
53
|
+
export { clearEmptyDirs, clearSitemapsFromDirs, copyDirsSync, createDirsSync, moveDirsSync, removeDirsSync, removeVirtualPagesFromStore, };
|
package/build/utils/store.d.ts
CHANGED
|
@@ -76,4 +76,4 @@ declare function getPagesToCreateOrDelete(storeDir: string, sitePages: {
|
|
|
76
76
|
pagesToDeleteFromStore: number[];
|
|
77
77
|
pagesToWriteToStore: number[];
|
|
78
78
|
}>;
|
|
79
|
-
export { createStoreDir, getBuildMetadata,
|
|
79
|
+
export { createStoreDir, getBuildMetadata, getBuildPagesFromCachedStore, getBuildPagesFromStore, getBuildPagesPath, getPageInStoreDir, getPagesToCreateOrDelete, removePagesFromStore, savePagesInStore, saveRenderInfoInStore, };
|
package/cx.config.js
CHANGED
|
@@ -12,8 +12,15 @@ const CX_CACHE_DIR = path.resolve(CX_ROOT_DIR, "caches");
|
|
|
12
12
|
const COMPONENTS_DIR = resolveComponentsPath();
|
|
13
13
|
const EXPORTS_DIR = path.join(REPO_ROOT_DIR, "exports/sites");
|
|
14
14
|
|
|
15
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
16
|
+
const { version: griddoVersion } = require(path.join(
|
|
17
|
+
CX_ROOT_DIR,
|
|
18
|
+
"package.json"
|
|
19
|
+
));
|
|
20
|
+
|
|
15
21
|
const config = {
|
|
16
22
|
proDomain: "pro-",
|
|
23
|
+
griddoVersion,
|
|
17
24
|
CXDir: {
|
|
18
25
|
EXPORTS: "__exports",
|
|
19
26
|
CACHE: "__caches",
|
|
@@ -1,8 +1,21 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
getGatsbyAssetPrefixWithDomain,
|
|
6
|
+
legacy__createDistFromGatsbyPublic,
|
|
7
|
+
runGatsbyBuildCommand,
|
|
8
|
+
} from "./utils";
|
|
5
9
|
import { RobotsService } from "../../services/robots";
|
|
10
|
+
import {
|
|
11
|
+
attempts,
|
|
12
|
+
doLifeCycle,
|
|
13
|
+
getConfig,
|
|
14
|
+
logBox,
|
|
15
|
+
pause,
|
|
16
|
+
printExporterLogo,
|
|
17
|
+
verbose,
|
|
18
|
+
} from "../../utils/core-utils";
|
|
6
19
|
import { createBuildData } from "../../utils/create-build-data";
|
|
7
20
|
import { getInstanceDomains } from "../../utils/domains";
|
|
8
21
|
import {
|
|
@@ -13,17 +26,7 @@ import {
|
|
|
13
26
|
removeDirsSync,
|
|
14
27
|
removeVirtualPagesFromStore,
|
|
15
28
|
} from "../../utils/folders";
|
|
16
|
-
import {
|
|
17
|
-
doLifeCycle,
|
|
18
|
-
logBox,
|
|
19
|
-
pause,
|
|
20
|
-
printExporterLogo,
|
|
21
|
-
} from "../../utils/shared";
|
|
22
29
|
import { generateBuildReport, generateSitemaps } from "../../utils/sites";
|
|
23
|
-
import {
|
|
24
|
-
getConfig,
|
|
25
|
-
legacy__createDistFromGatsbyPublic,
|
|
26
|
-
} from "../../utils/temp-utils";
|
|
27
30
|
|
|
28
31
|
async function runGatsbyAdapter() {
|
|
29
32
|
printExporterLogo("gatsby");
|
|
@@ -38,7 +41,9 @@ async function runGatsbyAdapter() {
|
|
|
38
41
|
|
|
39
42
|
logBox(`Initializing render for the domain ${domain}`, "", 1, 0);
|
|
40
43
|
|
|
41
|
-
|
|
44
|
+
// This variables are for both, create the dist directory from public
|
|
45
|
+
// and pass to the gatsby-build command via spawnSync.
|
|
46
|
+
const assetPrefix = getGatsbyAssetPrefixWithDomain(domain);
|
|
42
47
|
const needsAssetPrefix = !!assetPrefix && assetPrefix !== "";
|
|
43
48
|
|
|
44
49
|
/*
|
|
@@ -52,7 +57,15 @@ async function runGatsbyAdapter() {
|
|
|
52
57
|
attempts: attempts.clean,
|
|
53
58
|
steps: [
|
|
54
59
|
() => removeDirsSync(__cx, ["store", "apiCache", "dist"]),
|
|
60
|
+
() =>
|
|
61
|
+
verbose(
|
|
62
|
+
"clean `store`, `apiCache` and `dist` directories from `__cx`"
|
|
63
|
+
),
|
|
55
64
|
() => removeDirsSync(__ssg, ["dist", "public", "static", ".cache"]),
|
|
65
|
+
() =>
|
|
66
|
+
verbose(
|
|
67
|
+
"clean `dist`, `public`, `static` and `.cache` directories from `__ssg`"
|
|
68
|
+
),
|
|
56
69
|
() => pause("Clean LifeCycle"),
|
|
57
70
|
],
|
|
58
71
|
});
|
|
@@ -68,8 +81,10 @@ async function runGatsbyAdapter() {
|
|
|
68
81
|
attempts: attempts.prepare,
|
|
69
82
|
steps: [
|
|
70
83
|
() => createDirsSync([__exports]),
|
|
84
|
+
() => verbose("create `exports/sites/<domain>` directory"),
|
|
71
85
|
() => createDirsSync([__caches]),
|
|
72
|
-
() =>
|
|
86
|
+
() => verbose("create `caches/<domain>` directory"),
|
|
87
|
+
() => pause("prepare LifeCycle"),
|
|
73
88
|
],
|
|
74
89
|
});
|
|
75
90
|
|
|
@@ -82,8 +97,17 @@ async function runGatsbyAdapter() {
|
|
|
82
97
|
steps: [
|
|
83
98
|
// Copy instance static directory into the gatsby one.
|
|
84
99
|
() => copyDirsSync(__components, __ssg, ["static"]),
|
|
100
|
+
() => verbose("copy `static` directory from `__components` to `__ssg`"),
|
|
85
101
|
() => copyDirsSync(__exports, __cx, ["assets"]),
|
|
102
|
+
() => verbose("copy `assets` directory from `__exports` to `__cx`"),
|
|
86
103
|
() => copyDirsSync(__exports, __ssg, ["dist"]),
|
|
104
|
+
// Eliminamos archivos de sitemaps para que Gatsby no los tenga
|
|
105
|
+
// en cuenta y evitar que se invalide el caché de HTMLs.
|
|
106
|
+
// De todas maneras estos .xml se generan siempre en cada
|
|
107
|
+
// render, y si hay algún problema no pasa nada porque se están
|
|
108
|
+
// eliminando los sitemaps de la copia de dist en el directorio
|
|
109
|
+
// de __cx.
|
|
110
|
+
// () => clearSitemapsFromDirs(path.join(__cx, "dist")),
|
|
87
111
|
// Renames dist to public.
|
|
88
112
|
// En este paso de dist to public también se sacan los "assets"
|
|
89
113
|
// de public si el dominio es "pro-". Este proceso es sacar
|
|
@@ -94,8 +118,14 @@ async function runGatsbyAdapter() {
|
|
|
94
118
|
fs.renameSync(path.join(__ssg, "dist"), path.join(__ssg, "public"));
|
|
95
119
|
}
|
|
96
120
|
},
|
|
121
|
+
() => verbose("rename `__ssg/dist` to `__ssg/public` directory."),
|
|
97
122
|
() => moveDirsSync(__caches, __cx, ["apiCache", "store"]),
|
|
123
|
+
() =>
|
|
124
|
+
verbose(
|
|
125
|
+
"move `apiCache` and `store` directories from `__caches` to `__cx`"
|
|
126
|
+
),
|
|
98
127
|
() => moveDirsSync(__caches, __ssg, [".cache"]),
|
|
128
|
+
() => verbose("move `.cache` directory from `__caches` to `__ssg`"),
|
|
99
129
|
() => pause("Restore LifeCycle"),
|
|
100
130
|
],
|
|
101
131
|
});
|
|
@@ -119,7 +149,10 @@ async function runGatsbyAdapter() {
|
|
|
119
149
|
await doLifeCycle({
|
|
120
150
|
name: "SSG",
|
|
121
151
|
attempts: attempts.ssg,
|
|
122
|
-
steps: [
|
|
152
|
+
steps: [
|
|
153
|
+
() => runGatsbyBuildCommand(assetPrefix),
|
|
154
|
+
() => pause("SSG LifeCycle"),
|
|
155
|
+
],
|
|
123
156
|
});
|
|
124
157
|
|
|
125
158
|
/*
|
|
@@ -130,6 +163,7 @@ async function runGatsbyAdapter() {
|
|
|
130
163
|
attempts: attempts.relocation,
|
|
131
164
|
steps: [
|
|
132
165
|
() => legacy__createDistFromGatsbyPublic(domain, needsAssetPrefix),
|
|
166
|
+
() => verbose("create an `assets` directory from `public`"),
|
|
133
167
|
() => pause("Relocation LifeCycle"),
|
|
134
168
|
],
|
|
135
169
|
});
|
|
@@ -142,8 +176,12 @@ async function runGatsbyAdapter() {
|
|
|
142
176
|
attempts: attempts.meta,
|
|
143
177
|
steps: [
|
|
144
178
|
() => generateBuildReport(),
|
|
179
|
+
() =>
|
|
180
|
+
verbose("create build report from `store/metadata/render-info.json`"),
|
|
145
181
|
() => RobotsService.writeFiles(domain),
|
|
182
|
+
() => verbose("create Robots.txt"),
|
|
146
183
|
() => generateSitemaps(),
|
|
184
|
+
() => verbose("generate sitemaps"),
|
|
147
185
|
() => pause("Meta LifeCycle"),
|
|
148
186
|
],
|
|
149
187
|
});
|
|
@@ -163,15 +201,30 @@ async function runGatsbyAdapter() {
|
|
|
163
201
|
// tenidas en cuenta por la API y por lo tanto escapan a la
|
|
164
202
|
// lógica de `changedPages` y la persistencia del store.
|
|
165
203
|
() => removeVirtualPagesFromStore(),
|
|
204
|
+
() =>
|
|
205
|
+
verbose(
|
|
206
|
+
"remove virtual pages from store (multipage and static list)"
|
|
207
|
+
),
|
|
166
208
|
// Eliminamos carpetas vacías que puedan quedar de sites
|
|
167
209
|
// despublicados. Incluye aquellas que solo tengan archivos .xml
|
|
168
210
|
() => clearEmptyDirs(path.join(__cx, "dist")),
|
|
211
|
+
() => verbose("remove empty site directories from `__cx/dist`"),
|
|
169
212
|
() =>
|
|
170
213
|
moveDirsSync(__cx, __exports, ["dist", "assets"], {
|
|
171
214
|
withBackup: true,
|
|
172
215
|
}),
|
|
216
|
+
|
|
217
|
+
() =>
|
|
218
|
+
verbose(
|
|
219
|
+
"move `dist` and `assets` directories from `__cx` to `__exports`"
|
|
220
|
+
),
|
|
173
221
|
() => moveDirsSync(__cx, __caches, ["apiCache", "store"]),
|
|
222
|
+
() =>
|
|
223
|
+
verbose(
|
|
224
|
+
"move `apiCache` and `store` directories from `__cx` to `__caches`"
|
|
225
|
+
),
|
|
174
226
|
() => moveDirsSync(__ssg, __caches, [".cache"]),
|
|
227
|
+
() => verbose("move `.cache` directory from `__ssg` to `__caches`"),
|
|
175
228
|
() => pause("Archive LifeCycle"),
|
|
176
229
|
],
|
|
177
230
|
});
|
|
@@ -1,31 +1,27 @@
|
|
|
1
|
+
import type { Fields } from "@griddo/core";
|
|
2
|
+
|
|
1
3
|
import { spawnSync } from "node:child_process";
|
|
4
|
+
import path from "node:path";
|
|
2
5
|
|
|
3
|
-
import { Fields } from "@griddo/core";
|
|
4
6
|
import dotenv from "dotenv";
|
|
7
|
+
import fsx from "fs-extra";
|
|
5
8
|
|
|
6
|
-
import { getConfig } from "../../utils/
|
|
9
|
+
import { getConfig, verbose } from "../../utils/core-utils";
|
|
7
10
|
|
|
8
11
|
dotenv.config();
|
|
9
12
|
|
|
10
13
|
const config = getConfig();
|
|
11
14
|
|
|
12
|
-
const attempts = {
|
|
13
|
-
prepare: JSON.parse(process.env.GRIDDO_PREPARE_LIFECYCLE_MAX_ATTEMPTS || "1"),
|
|
14
|
-
restore: JSON.parse(process.env.GRIDDO_RESTORE_LIFECYCLE_MAX_ATTEMPTS || "1"),
|
|
15
|
-
data: JSON.parse(process.env.GRIDDO_DATA_LIFECYCLE_MAX_ATTEMPTS || "1"),
|
|
16
|
-
ssg: JSON.parse(process.env.GRIDDO_SSG_LIFECYCLE_MAX_ATTEMPTS || "1"),
|
|
17
|
-
relocation: JSON.parse(
|
|
18
|
-
process.env.GRIDDO_RELOCATION_LIFECYCLE_MAX_ATTEMPTS || "1"
|
|
19
|
-
),
|
|
20
|
-
meta: JSON.parse(process.env.GRIDDO_META_LIFECYCLE_MAX_ATTEMPTS || "1"),
|
|
21
|
-
archive: JSON.parse(process.env.GRIDDO_ARCHIVE_LIFECYCLE_MAX_ATTEMPTS || "1"),
|
|
22
|
-
clean: JSON.parse(process.env.GRIDDO_CLEAN_LIFECYCLE_MAX_ATTEMPTS || "1"),
|
|
23
|
-
};
|
|
24
|
-
|
|
25
15
|
/**
|
|
26
|
-
* Return the assetPrefix
|
|
16
|
+
* Return the assetPrefix with the domain concatenated `assetPrefix/domain` only
|
|
17
|
+
* if the domain is "pro-" **and** there is a env `GRIDDO_ASSET_PREFIX` with any
|
|
18
|
+
* value different from `null`, `undefined` or `empty string`
|
|
19
|
+
*
|
|
20
|
+
* else...
|
|
21
|
+
* - If assetPrefix or domain is falsy, returns ""
|
|
22
|
+
* - If the domain is not "pro-", returns ""
|
|
27
23
|
*/
|
|
28
|
-
function
|
|
24
|
+
function getGatsbyAssetPrefixWithDomain(domain: string) {
|
|
29
25
|
const { proDomain } = getConfig();
|
|
30
26
|
const assetPrefix =
|
|
31
27
|
process.env.GRIDDO_ASSET_PREFIX || process.env.ASSET_PREFIX;
|
|
@@ -33,7 +29,16 @@ function getGatsbyAssetPrefixSlug(domain: string) {
|
|
|
33
29
|
if (!assetPrefix || !domain) return "";
|
|
34
30
|
if (!domain.startsWith(proDomain)) return "";
|
|
35
31
|
|
|
36
|
-
|
|
32
|
+
const assetPrefixWithDomain = `${assetPrefix}/${domain}`;
|
|
33
|
+
|
|
34
|
+
verbose(
|
|
35
|
+
`Reading env.GRIDDO_ASSET_PREFIX, ${process.env.GRIDDO_ASSET_PREFIX}`
|
|
36
|
+
);
|
|
37
|
+
verbose(
|
|
38
|
+
`Setting the asset prefix with the domain concatenated, ${assetPrefixWithDomain}`
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
return assetPrefixWithDomain;
|
|
37
42
|
}
|
|
38
43
|
|
|
39
44
|
/**
|
|
@@ -86,24 +91,104 @@ function addCloudinaryParams(image: string, params: string) {
|
|
|
86
91
|
return `https://${head}/${params}${fullId}`;
|
|
87
92
|
}
|
|
88
93
|
|
|
89
|
-
|
|
90
|
-
|
|
94
|
+
/**
|
|
95
|
+
* Spawn a new node process `yarn gatsby-build`
|
|
96
|
+
* @note This proccess (`yarn gatsby-build`) can not access to the custom Griddo
|
|
97
|
+
* `process.env` so it needs variables passed to it via the `env` prop.
|
|
98
|
+
*/
|
|
99
|
+
function runGatsbyBuildCommand(assetPrefixWithDomain: string) {
|
|
100
|
+
verbose(`read assetPrefixWithDomain, ${assetPrefixWithDomain}`);
|
|
101
|
+
|
|
91
102
|
const { __ssg } = config.paths();
|
|
92
103
|
|
|
93
|
-
const command = spawnSync(
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
104
|
+
const command = spawnSync(
|
|
105
|
+
"yarn",
|
|
106
|
+
["gatsby-build", process.env.GRIDDO_SSG_VERBOSE ? "--verbose" : ""],
|
|
107
|
+
{
|
|
108
|
+
cwd: __ssg,
|
|
109
|
+
stdio: ["ignore", "inherit", "ignore"],
|
|
110
|
+
encoding: "utf8",
|
|
111
|
+
shell: true,
|
|
112
|
+
env: Object.assign(process.env, {
|
|
113
|
+
GRIDDO_EXPORTER: "true",
|
|
114
|
+
SPAWN_ASSET_PREFIX_WITH_DOMAIN: assetPrefixWithDomain,
|
|
115
|
+
}),
|
|
116
|
+
}
|
|
117
|
+
);
|
|
103
118
|
|
|
104
119
|
if (command.status !== 0) {
|
|
105
120
|
throw new Error("Error in 'yarn gatsby-build'");
|
|
106
121
|
}
|
|
107
122
|
}
|
|
108
123
|
|
|
109
|
-
|
|
124
|
+
/**
|
|
125
|
+
* Update the Griddo's `/dist` dir with the contents from `public` dir only
|
|
126
|
+
* with files of type: js, json and css.
|
|
127
|
+
*/
|
|
128
|
+
async function legacy__createDistFromGatsbyPublic(
|
|
129
|
+
domain: string,
|
|
130
|
+
needsAssetPrefix: boolean
|
|
131
|
+
) {
|
|
132
|
+
const { __cx, __ssg } = config.paths(domain);
|
|
133
|
+
|
|
134
|
+
const cxDistDir = path.join(__cx, "dist");
|
|
135
|
+
const cxAssetsDir = path.join(__cx, "assets");
|
|
136
|
+
const cxDistDirWithDomain = path.join(__cx, "dist", domain);
|
|
137
|
+
const publicDir = path.join(__ssg, "public");
|
|
138
|
+
|
|
139
|
+
const validFilesFromPublic = fsx
|
|
140
|
+
.readdirSync(publicDir)
|
|
141
|
+
.filter(
|
|
142
|
+
(file) =>
|
|
143
|
+
path.extname(file) === ".js" ||
|
|
144
|
+
path.extname(file) === ".json" ||
|
|
145
|
+
path.extname(file) === ".css"
|
|
146
|
+
);
|
|
147
|
+
|
|
148
|
+
const pageDataSrc = `${publicDir}/page-data`;
|
|
149
|
+
const pageDataDest = `${cxAssetsDir}/page-data`;
|
|
150
|
+
|
|
151
|
+
const projectStaticSrc = path.join(__ssg, "static");
|
|
152
|
+
const projectStaticDest = cxAssetsDir;
|
|
153
|
+
|
|
154
|
+
const gatsbyStaticSrc = `${cxDistDir}/static`;
|
|
155
|
+
const gatsbyStaticDest = `${cxAssetsDir}/static`;
|
|
156
|
+
|
|
157
|
+
try {
|
|
158
|
+
fsx.mkdirSync(cxAssetsDir, { recursive: true });
|
|
159
|
+
fsx.copySync(publicDir, cxDistDir);
|
|
160
|
+
|
|
161
|
+
if (needsAssetPrefix) {
|
|
162
|
+
fsx.copySync(pageDataSrc, pageDataDest);
|
|
163
|
+
if (fsx.existsSync(projectStaticSrc)) {
|
|
164
|
+
fsx.copySync(projectStaticSrc, projectStaticDest, {
|
|
165
|
+
overwrite: false,
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
fsx.copySync(gatsbyStaticSrc, gatsbyStaticDest, {
|
|
169
|
+
overwrite: false,
|
|
170
|
+
});
|
|
171
|
+
if (fsx.existsSync(projectStaticSrc)) {
|
|
172
|
+
fsx.copySync(projectStaticSrc, cxDistDirWithDomain, {
|
|
173
|
+
overwrite: false,
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
// Copia el resto de archivos...
|
|
178
|
+
validFilesFromPublic.map(async (file) => {
|
|
179
|
+
const fileSrc = `${publicDir}/${file}`;
|
|
180
|
+
const fileDest = `${cxAssetsDir}/${file}`;
|
|
181
|
+
fsx.copySync(fileSrc, fileDest);
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
} catch (err) {
|
|
185
|
+
console.error(err);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
export {
|
|
190
|
+
formatImage,
|
|
191
|
+
getGatsbyAssetPrefixWithDomain,
|
|
192
|
+
legacy__createDistFromGatsbyPublic,
|
|
193
|
+
runGatsbyBuildCommand,
|
|
194
|
+
};
|
|
@@ -34,15 +34,15 @@ type Report = {
|
|
|
34
34
|
export async function buildComplete(report: Report) {
|
|
35
35
|
await AuthService.login();
|
|
36
36
|
|
|
37
|
-
const
|
|
37
|
+
const sites = report.sites;
|
|
38
|
+
|
|
39
|
+
for (const site of sites) {
|
|
38
40
|
const { siteId, ...body } = site;
|
|
39
41
|
|
|
40
42
|
console.info(`Deploying ending call to site ${siteId}:`);
|
|
41
43
|
|
|
42
|
-
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
await Promise.all(promises);
|
|
44
|
+
await SitesService.endSiteRender(siteId, body);
|
|
45
|
+
}
|
|
46
46
|
|
|
47
47
|
console.info(`Build end's signal sent for ${report.sites.length} site(s)`);
|
|
48
48
|
}
|
package/exporter/index.ts
CHANGED
|
@@ -24,10 +24,9 @@
|
|
|
24
24
|
/* prettier-ignore */ import type { Site } from "./types/sites";
|
|
25
25
|
|
|
26
26
|
/* prettier-ignore */ import { startRender } from "./start-render";
|
|
27
|
+
/* prettier-ignore */ import { getConfig, logInfo, logPageSize, verbose, walk } from "./utils/core-utils";
|
|
27
28
|
/* prettier-ignore */ import { IS_COMPONENT_LIBRARY, PROJECT_ALIASES, resolveComponentsPath } from "./utils/instance";
|
|
28
|
-
/* prettier-ignore */ import { logInfo, logPageSize, walk } from "./utils/shared";
|
|
29
29
|
/* prettier-ignore */ import { getBuildPagesFromCachedStore, getBuildPagesFromStore, getBuildPagesPath } from "./utils/store";
|
|
30
|
-
/* prettier-ignore */ import { getConfig } from "./utils/temp-utils";
|
|
31
30
|
|
|
32
31
|
export {
|
|
33
32
|
AdditionalInfo,
|
|
@@ -40,11 +39,13 @@ export {
|
|
|
40
39
|
Site,
|
|
41
40
|
SocialsResponse,
|
|
42
41
|
getBuildPagesFromCachedStore,
|
|
43
|
-
getBuildPagesFromStore,
|
|
42
|
+
getBuildPagesFromStore,
|
|
43
|
+
getBuildPagesPath,
|
|
44
|
+
getConfig,
|
|
44
45
|
logInfo,
|
|
45
46
|
logPageSize,
|
|
46
47
|
resolveComponentsPath,
|
|
47
48
|
startRender,
|
|
48
|
-
|
|
49
|
+
verbose,
|
|
50
|
+
walk,
|
|
49
51
|
};
|
|
50
|
-
|
|
@@ -7,7 +7,6 @@ import type {
|
|
|
7
7
|
PageAdditionalInfo,
|
|
8
8
|
} from "../types/pages";
|
|
9
9
|
|
|
10
|
-
import fs from "node:fs";
|
|
11
10
|
import path from "node:path";
|
|
12
11
|
|
|
13
12
|
import dotenv from "dotenv";
|
|
@@ -18,6 +17,7 @@ import { NavigationService } from "./navigation";
|
|
|
18
17
|
import { SettingsService } from "./settings";
|
|
19
18
|
import { SitesService } from "./sites";
|
|
20
19
|
import { updatedSiteHash } from "../utils/cache";
|
|
20
|
+
import { getConfig, logInfo, siteList, verbose } from "../utils/core-utils";
|
|
21
21
|
import {
|
|
22
22
|
createGriddoListPages,
|
|
23
23
|
createGriddoMultiPages,
|
|
@@ -25,7 +25,6 @@ import {
|
|
|
25
25
|
getMultiPageElements,
|
|
26
26
|
getPaginatedPages,
|
|
27
27
|
} from "../utils/pages";
|
|
28
|
-
import { logBox, logInfo, siteList } from "../utils/shared";
|
|
29
28
|
import { checkSites, getSiteData, unpublishSites } from "../utils/sites";
|
|
30
29
|
import {
|
|
31
30
|
createStoreDir,
|
|
@@ -34,7 +33,6 @@ import {
|
|
|
34
33
|
savePagesInStore,
|
|
35
34
|
saveRenderInfoInStore,
|
|
36
35
|
} from "../utils/store";
|
|
37
|
-
import { getConfig } from "../utils/temp-utils";
|
|
38
36
|
|
|
39
37
|
const config = getConfig();
|
|
40
38
|
|
|
@@ -57,10 +55,8 @@ async function createStore(domain: string) {
|
|
|
57
55
|
console.info(`API calls with ${API_CONCURRENCY_COUNT} threads`);
|
|
58
56
|
|
|
59
57
|
const { __cx } = config.paths();
|
|
58
|
+
const { griddoVersion } = config;
|
|
60
59
|
const storeDir = path.join(__cx, "store");
|
|
61
|
-
const { version: griddoVersion } = JSON.parse(
|
|
62
|
-
fs.readFileSync(path.join(__cx, "package.json"), "utf-8")
|
|
63
|
-
);
|
|
64
60
|
|
|
65
61
|
try {
|
|
66
62
|
// Vars to save later in the report file
|
|
@@ -293,16 +289,13 @@ async function createStore(domain: string) {
|
|
|
293
289
|
removePagesFromStore(pagesToDeleteFromStore);
|
|
294
290
|
|
|
295
291
|
// Debug time
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
if (JSON.parse(process.env.GRIDDO_DEBUG_LOGS || "false")) {
|
|
304
|
-
logBox(changedPageLogs, `Site store: ${site.name}`, 1, 0);
|
|
305
|
-
}
|
|
292
|
+
|
|
293
|
+
verbose(`Store site: ${site.name}`);
|
|
294
|
+
verbose(`${validPagesIds.length} valid pages from API`);
|
|
295
|
+
verbose(`changed ${pagesToDeleteFromStore.length} pages from API`);
|
|
296
|
+
verbose(`deleted ${changedPages.length} pages in store`);
|
|
297
|
+
verbose(`missing ${pagesMissingInStore.length} pages in store`);
|
|
298
|
+
verbose(`write ${pagesToWriteToStore.length} pages to store`);
|
|
306
299
|
|
|
307
300
|
// Create (async)
|
|
308
301
|
const limit = pLimit(API_CONCURRENCY_COUNT);
|
package/exporter/start-render.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
/* eslint-disable node/shebang */
|
|
3
3
|
|
|
4
4
|
import { runGatsbyAdapter } from "./adapters";
|
|
5
|
-
import { logBox, measureExecutionTime } from "./utils/
|
|
5
|
+
import { logBox, measureExecutionTime } from "./utils/core-utils";
|
|
6
6
|
|
|
7
7
|
async function startRender() {
|
|
8
8
|
const exeTime = await measureExecutionTime(runGatsbyAdapter).catch(() => {
|
package/exporter/types/global.ts
CHANGED
package/exporter/utils/api.ts
CHANGED
|
@@ -13,7 +13,7 @@ import chalk from "chalk";
|
|
|
13
13
|
import dotenv from "dotenv";
|
|
14
14
|
|
|
15
15
|
import { saveCache, searchCacheData } from "./cache";
|
|
16
|
-
import { delay, getSafeSiteId, logInfo, msToSec } from "./
|
|
16
|
+
import { delay, getSafeSiteId, logInfo, msToSec } from "./core-utils";
|
|
17
17
|
import { AuthService } from "../services/auth";
|
|
18
18
|
|
|
19
19
|
dotenv.config();
|