@griddo/cx 11.7.7-rc.0 → 11.7.7-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 +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 +147 -67
- 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 +69 -73
- package/exporter/commands/move-assets.ts +11 -0
- package/exporter/commands/prepare-domains-render.ts +31 -144
- package/exporter/commands/reset-render.ts +1 -10
- package/exporter/commands/start-render.ts +44 -23
- package/exporter/commands/upload-search-content.ts +20 -194
- 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 +14 -6
- package/{react → exporter/react}/GriddoIntegrations/utils.ts +9 -4
- 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 +23 -8
- 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 -35
- package/exporter/services/store.ts +78 -120
- package/exporter/types/api.ts +27 -24
- package/exporter/types/global.ts +10 -7
- 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 +82 -46
- package/exporter/utils/cache.ts +62 -37
- package/exporter/utils/core-utils.ts +248 -129
- package/exporter/utils/create-build-data.ts +17 -0
- package/exporter/utils/domains.ts +7 -10
- package/exporter/utils/folders.ts +95 -187
- package/exporter/utils/health-checks.ts +64 -0
- package/exporter/utils/images.ts +6 -1
- package/exporter/utils/instance.ts +12 -9
- package/exporter/utils/loggin.ts +91 -32
- package/exporter/utils/pages.ts +88 -23
- package/exporter/utils/render.ts +48 -149
- package/exporter/utils/searches.ts +156 -0
- package/exporter/utils/sites.ts +90 -81
- package/exporter/utils/store.ts +180 -87
- package/gatsby-browser.tsx +58 -41
- package/gatsby-config.ts +12 -6
- package/gatsby-node.ts +77 -15
- package/gatsby-ssr.tsx +1 -2
- package/package.json +78 -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 -91
- 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 -9
- package/build/adapters/gatsby/actions/init.js.map +0 -1
- package/build/adapters/gatsby/actions/meta.js +0 -14
- 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 -79
- package/build/adapters/gatsby/index.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 -49
- 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 -88
- package/build/commands/end-render.js.map +0 -1
- package/build/commands/prepare-assets-directory.js +0 -32
- 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 -22
- package/build/commands/reset-render.js.map +0 -1
- package/build/commands/start-render.js +0 -45
- 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 -42
- 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 -109
- package/build/services/sites.js.map +0 -1
- package/build/services/store.js +0 -282
- 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 -161
- package/build/utils/api.js.map +0 -1
- package/build/utils/artifacts.js +0 -34
- 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-health.js +0 -68
- package/build/utils/check-health.js.map +0 -1
- package/build/utils/core-utils.js +0 -283
- 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 -362
- 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 -108
- package/build/utils/loggin.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 -144
- package/build/utils/render.js.map +0 -1
- package/build/utils/sites.js +0 -240
- package/build/utils/sites.js.map +0 -1
- package/build/utils/store.js +0 -193
- package/build/utils/store.js.map +0 -1
- 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 -12
- package/exporter/adapters/gatsby/actions/meta.ts +0 -18
- 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/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 -54
- 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 -33
- 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 -34
- package/exporter/utils/brush.ts +0 -34
- package/exporter/utils/check-health.ts +0 -79
- package/plugins/gatsby-plugin-svgr-loader/gatsby-node.js +0 -55
- package/plugins/gatsby-plugin-svgr-loader/package.json +0 -8
- /package/{react → exporter/react}/Favicon/utils.ts +0 -0
|
@@ -1,82 +1,162 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type {
|
|
2
|
+
Artifacts,
|
|
3
|
+
LifeCyclesNames,
|
|
4
|
+
LifeCycleSteps,
|
|
5
|
+
} from "../../types/global";
|
|
2
6
|
|
|
3
7
|
import path from "node:path";
|
|
4
8
|
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
+
import {
|
|
10
|
+
createDistFromGatsbyPublic,
|
|
11
|
+
getGatsbyAssetPrefixWithDomain,
|
|
12
|
+
runGatsbyBuildCommand,
|
|
13
|
+
} from "./utils";
|
|
14
|
+
import getCxArtifacts from "../../artifacts";
|
|
15
|
+
import { AuthService } from "../../services/auth";
|
|
16
|
+
import {
|
|
17
|
+
createDomainMetadata,
|
|
18
|
+
doLifeCycle,
|
|
19
|
+
getConfig,
|
|
20
|
+
saveBuildEndLogs,
|
|
21
|
+
} from "../../utils/core-utils";
|
|
22
|
+
import { createDomainRenderData } from "../../utils/create-build-data";
|
|
23
|
+
import {
|
|
24
|
+
copyArtifacts,
|
|
25
|
+
createArtifacts,
|
|
26
|
+
deleteDisposableSiteDirs,
|
|
27
|
+
moveArtifacts,
|
|
28
|
+
removeArtifacts,
|
|
29
|
+
removeVirtualPagesFromStore,
|
|
30
|
+
renameArtifact,
|
|
31
|
+
} from "../../utils/folders";
|
|
9
32
|
import { infoLog } from "../../utils/loggin";
|
|
10
|
-
import {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
import { initAction } from "./actions/init";
|
|
16
|
-
import { metaAction } from "./actions/meta";
|
|
17
|
-
import { prepareAction } from "./actions/prepare";
|
|
18
|
-
import { relocationAction } from "./actions/relocation";
|
|
19
|
-
import { restoreAction } from "./actions/restore";
|
|
20
|
-
import { ssgAction } from "./actions/ssg";
|
|
21
|
-
import { syncAction } from "./actions/sync";
|
|
22
|
-
import { RenderContext } from "./shared/context";
|
|
33
|
+
import {
|
|
34
|
+
createSentinelRenderFile,
|
|
35
|
+
deleteSentinelRenderFile,
|
|
36
|
+
isValidRender,
|
|
37
|
+
} from "../../utils/render";
|
|
23
38
|
|
|
24
39
|
/**
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
* The render process consists of multiple lifecycle steps that handle cleaning,
|
|
28
|
-
* preparing, building and syncing the site. It can run in two modes:
|
|
29
|
-
* - FROM_SCRATCH: Performs a complete rebuild of the site
|
|
30
|
-
* - INCREMENTAL: Only rebuilds changed pages while preserving the rest
|
|
40
|
+
* Render every instance domain with the Gatsby adapter.
|
|
31
41
|
*/
|
|
32
|
-
export async function
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
const
|
|
39
|
-
|
|
40
|
-
|
|
42
|
+
export async function renderDomainsWithGatsbyAdapter(domain: string) {
|
|
43
|
+
await AuthService.login();
|
|
44
|
+
const config = getConfig();
|
|
45
|
+
|
|
46
|
+
infoLog(`Initializing render for the domain ${domain}\n`);
|
|
47
|
+
|
|
48
|
+
const {
|
|
49
|
+
//
|
|
50
|
+
__ssg,
|
|
51
|
+
__exports,
|
|
52
|
+
__cache,
|
|
53
|
+
__cx,
|
|
54
|
+
__components,
|
|
55
|
+
} = config.paths(domain);
|
|
56
|
+
|
|
57
|
+
// Griddo artifacts
|
|
58
|
+
const cxArtifacts = getCxArtifacts(domain);
|
|
59
|
+
|
|
60
|
+
// Gatsby artifacts
|
|
61
|
+
const gatsbyArtifacts: Pick<Artifacts, "disposables" | "cacheables"> = {
|
|
41
62
|
disposables: [
|
|
42
|
-
path.join(
|
|
43
|
-
path.join(
|
|
44
|
-
path.join(
|
|
45
|
-
path.join(paths.__ssg, "domains.json"), // Este disposable es de griddo pero está en la ruta __ssg
|
|
46
|
-
path.join(paths.__ssg, "domains.txt"), // Este disposable es de griddo pero está en la ruta __ssg
|
|
63
|
+
path.join(__ssg, "public"),
|
|
64
|
+
path.join(__ssg, "static"),
|
|
65
|
+
path.join(__ssg, ".cache"),
|
|
47
66
|
],
|
|
48
67
|
cacheables: [".cache"],
|
|
49
68
|
};
|
|
50
69
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
const
|
|
70
|
+
// These variables are involved in the build for create the dist directory
|
|
71
|
+
// from public and pass to the gatsby-build command via spawnSync.
|
|
72
|
+
const assetPrefix = getGatsbyAssetPrefixWithDomain(domain);
|
|
73
|
+
const needsAssetPrefix = !!assetPrefix && assetPrefix !== "";
|
|
54
74
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
75
|
+
// Compose artifacts
|
|
76
|
+
const disposableArtifacts = [
|
|
77
|
+
...cxArtifacts.disposables,
|
|
78
|
+
...gatsbyArtifacts.disposables,
|
|
79
|
+
];
|
|
80
|
+
|
|
81
|
+
// LifeCycles
|
|
82
|
+
|
|
83
|
+
const allLifeCycles: Array<{
|
|
84
|
+
name: LifeCyclesNames;
|
|
85
|
+
steps: LifeCycleSteps;
|
|
86
|
+
}> = [
|
|
87
|
+
{
|
|
88
|
+
name: "Init",
|
|
89
|
+
steps: [() => createSentinelRenderFile()],
|
|
90
|
+
},
|
|
91
|
+
|
|
92
|
+
{
|
|
93
|
+
name: "Clean",
|
|
94
|
+
steps: [() => removeArtifacts(disposableArtifacts)],
|
|
95
|
+
},
|
|
96
|
+
|
|
97
|
+
{
|
|
98
|
+
name: "Prepare",
|
|
99
|
+
steps: [() => createArtifacts(cxArtifacts.initials)],
|
|
100
|
+
},
|
|
58
101
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
102
|
+
{
|
|
103
|
+
name: "Restore",
|
|
104
|
+
steps: [
|
|
105
|
+
() => copyArtifacts(__components, __ssg, ["static"]),
|
|
106
|
+
() => copyArtifacts(__exports, __cx, cxArtifacts.archivables),
|
|
107
|
+
() =>
|
|
108
|
+
renameArtifact(path.join(__cx, "dist"), path.join(__ssg, "public")),
|
|
109
|
+
() => moveArtifacts(__cache, __cx, cxArtifacts.cacheables),
|
|
110
|
+
() => moveArtifacts(__cache, __ssg, gatsbyArtifacts.cacheables),
|
|
111
|
+
],
|
|
112
|
+
},
|
|
113
|
+
|
|
114
|
+
{
|
|
115
|
+
name: "Data",
|
|
116
|
+
steps: [() => createDomainRenderData(domain)],
|
|
117
|
+
},
|
|
118
|
+
|
|
119
|
+
{
|
|
120
|
+
name: "SSG",
|
|
121
|
+
steps: [() => runGatsbyBuildCommand(assetPrefix)],
|
|
122
|
+
},
|
|
123
|
+
|
|
124
|
+
{
|
|
125
|
+
name: "Relocation",
|
|
126
|
+
steps: [() => createDistFromGatsbyPublic(domain, needsAssetPrefix)],
|
|
127
|
+
},
|
|
128
|
+
|
|
129
|
+
{
|
|
130
|
+
name: "Meta",
|
|
131
|
+
steps: [() => createDomainMetadata(domain), () => saveBuildEndLogs()],
|
|
132
|
+
},
|
|
133
|
+
|
|
134
|
+
{
|
|
135
|
+
name: "Archive",
|
|
136
|
+
steps: [
|
|
137
|
+
() => removeVirtualPagesFromStore(),
|
|
138
|
+
() => deleteDisposableSiteDirs(),
|
|
139
|
+
() =>
|
|
140
|
+
moveArtifacts(__cx, __exports, cxArtifacts.archivables, {
|
|
141
|
+
withBackup: true,
|
|
142
|
+
}),
|
|
143
|
+
() => moveArtifacts(__cx, __cache, cxArtifacts.cacheables),
|
|
144
|
+
() => moveArtifacts(__ssg, __cache, gatsbyArtifacts.cacheables),
|
|
145
|
+
],
|
|
146
|
+
},
|
|
147
|
+
|
|
148
|
+
{
|
|
149
|
+
name: "Close",
|
|
150
|
+
steps: [() => removeArtifacts(disposableArtifacts)],
|
|
151
|
+
},
|
|
152
|
+
|
|
153
|
+
{
|
|
154
|
+
name: "HealthCheck",
|
|
155
|
+
steps: [() => isValidRender(), () => deleteSentinelRenderFile()],
|
|
156
|
+
},
|
|
157
|
+
];
|
|
158
|
+
|
|
159
|
+
for (const { name, steps } of allLifeCycles) {
|
|
160
|
+
await doLifeCycle(name, steps);
|
|
161
|
+
}
|
|
82
162
|
}
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import { spawnSync } from "node:child_process";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
|
|
4
|
+
import fsx from "fs-extra";
|
|
5
|
+
|
|
6
|
+
import { envs } from "../../constants";
|
|
7
|
+
import { throwError } from "../../errors";
|
|
8
|
+
import { ErrorInSSGBuildProcess } from "../../errors/errors-data";
|
|
9
|
+
import { getConfig } from "../../utils/core-utils";
|
|
10
|
+
import { verboseLog } from "../../utils/loggin";
|
|
11
|
+
|
|
12
|
+
const config = getConfig();
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Return the assetPrefix with the domain concatenated `assetPrefix/domain` only
|
|
16
|
+
* if the domain is "pro-" **and** there is a env `GRIDDO_ASSET_PREFIX` with any
|
|
17
|
+
* value different from `null`, `undefined` or `empty string`
|
|
18
|
+
*
|
|
19
|
+
* else...
|
|
20
|
+
* - If assetPrefix or domain is falsy, returns ""
|
|
21
|
+
* - If the domain is not "pro-", returns ""
|
|
22
|
+
*/
|
|
23
|
+
function getGatsbyAssetPrefixWithDomain(domain: string) {
|
|
24
|
+
const { proDomain } = getConfig();
|
|
25
|
+
|
|
26
|
+
if (!envs.GRIDDO_ASSET_PREFIX || !domain) {
|
|
27
|
+
return "";
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (!domain.startsWith(proDomain)) {
|
|
31
|
+
return "";
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const assetPrefixWithDomain = `${envs.GRIDDO_ASSET_PREFIX}/${domain}`;
|
|
35
|
+
|
|
36
|
+
verboseLog(
|
|
37
|
+
`Reading process.env.GRIDDO_ASSET_PREFIX, ${envs.GRIDDO_ASSET_PREFIX}`,
|
|
38
|
+
);
|
|
39
|
+
verboseLog(
|
|
40
|
+
`Setting the asset prefix with the domain concatenated, ${assetPrefixWithDomain}`,
|
|
41
|
+
);
|
|
42
|
+
|
|
43
|
+
return assetPrefixWithDomain;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Spawn a new node process `yarn gatsby-build`
|
|
48
|
+
* @note This proccess (`yarn gatsby-build`) can not access to the custom Griddo
|
|
49
|
+
* `process.env` so it needs variables passed to it via the `env` prop.
|
|
50
|
+
*/
|
|
51
|
+
function runGatsbyBuildCommand(assetPrefixWithDomain: string) {
|
|
52
|
+
verboseLog(`read assetPrefixWithDomain, ${assetPrefixWithDomain}`);
|
|
53
|
+
verboseLog(
|
|
54
|
+
`using this NODE_OPTIONS in gatsby command: ${process.env.NODE_OPTIONS}`,
|
|
55
|
+
);
|
|
56
|
+
|
|
57
|
+
const { __ssg } = config.paths();
|
|
58
|
+
|
|
59
|
+
// Remove `--openssl-legacy-provider` from NODE_OPTIONS because this value
|
|
60
|
+
// break Gataby render.
|
|
61
|
+
const nodeOptionsWithoutLegacyOpenSSL = process.env.NODE_OPTIONS
|
|
62
|
+
? process.env.NODE_OPTIONS.replace(
|
|
63
|
+
/--openssl-legacy-provider\s*/g,
|
|
64
|
+
"",
|
|
65
|
+
).trim()
|
|
66
|
+
: "";
|
|
67
|
+
|
|
68
|
+
const command = spawnSync(
|
|
69
|
+
"yarn",
|
|
70
|
+
["gatsby-build", envs.GRIDDO_SSG_VERBOSE_LOGS ? "--verbose" : ""],
|
|
71
|
+
{
|
|
72
|
+
cwd: __ssg,
|
|
73
|
+
stdio: ["ignore", "inherit", "ignore"],
|
|
74
|
+
encoding: "utf8",
|
|
75
|
+
shell: true,
|
|
76
|
+
env: Object.assign(process.env, {
|
|
77
|
+
GRIDDO_EXPORTER: "true",
|
|
78
|
+
SPAWN_ASSET_PREFIX_WITH_DOMAIN: assetPrefixWithDomain,
|
|
79
|
+
NODE_OPTIONS: nodeOptionsWithoutLegacyOpenSSL,
|
|
80
|
+
}),
|
|
81
|
+
},
|
|
82
|
+
);
|
|
83
|
+
|
|
84
|
+
if (command.status !== 0) {
|
|
85
|
+
throwError(ErrorInSSGBuildProcess(command));
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Update the Griddo's `/dist` dir with the contents from `public` dir only
|
|
91
|
+
* with files of type: js, json and css.
|
|
92
|
+
*/
|
|
93
|
+
async function createDistFromGatsbyPublic(
|
|
94
|
+
domain: string,
|
|
95
|
+
needsAssetPrefix: boolean,
|
|
96
|
+
) {
|
|
97
|
+
const { __cx, __ssg } = config.paths(domain);
|
|
98
|
+
|
|
99
|
+
const cxDistDir = path.join(__cx, "dist");
|
|
100
|
+
const cxAssetsDir = path.join(__cx, "assets");
|
|
101
|
+
const cxDistDirWithDomain = path.join(__cx, "dist", domain);
|
|
102
|
+
const publicDir = path.join(__ssg, "public");
|
|
103
|
+
|
|
104
|
+
const validFilesFromPublic = fsx
|
|
105
|
+
.readdirSync(publicDir)
|
|
106
|
+
.filter(
|
|
107
|
+
(file) =>
|
|
108
|
+
path.extname(file) === ".js" ||
|
|
109
|
+
path.extname(file) === ".json" ||
|
|
110
|
+
path.extname(file) === ".css",
|
|
111
|
+
);
|
|
112
|
+
|
|
113
|
+
const pageDataSrc = `${publicDir}/page-data`;
|
|
114
|
+
const pageDataDest = `${cxAssetsDir}/page-data`;
|
|
115
|
+
|
|
116
|
+
const projectStaticSrc = path.join(__ssg, "static");
|
|
117
|
+
const projectStaticDest = cxAssetsDir;
|
|
118
|
+
|
|
119
|
+
const gatsbyStaticSrc = `${cxDistDir}/static`;
|
|
120
|
+
const gatsbyStaticDest = `${cxAssetsDir}/static`;
|
|
121
|
+
|
|
122
|
+
try {
|
|
123
|
+
fsx.mkdirSync(cxAssetsDir, { recursive: true });
|
|
124
|
+
fsx.copySync(publicDir, cxDistDir, { preserveTimestamps: true });
|
|
125
|
+
|
|
126
|
+
if (needsAssetPrefix) {
|
|
127
|
+
fsx.copySync(pageDataSrc, pageDataDest, { preserveTimestamps: true });
|
|
128
|
+
if (fsx.existsSync(projectStaticSrc)) {
|
|
129
|
+
fsx.copySync(projectStaticSrc, projectStaticDest, {
|
|
130
|
+
overwrite: false,
|
|
131
|
+
preserveTimestamps: true,
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
fsx.copySync(gatsbyStaticSrc, gatsbyStaticDest, {
|
|
135
|
+
overwrite: false,
|
|
136
|
+
preserveTimestamps: true,
|
|
137
|
+
});
|
|
138
|
+
if (fsx.existsSync(projectStaticSrc)) {
|
|
139
|
+
fsx.copySync(projectStaticSrc, cxDistDirWithDomain, {
|
|
140
|
+
overwrite: false,
|
|
141
|
+
preserveTimestamps: true,
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// Copia el resto de archivos...
|
|
146
|
+
validFilesFromPublic.map((file) => {
|
|
147
|
+
const fileSrc = `${publicDir}/${file}`;
|
|
148
|
+
const fileDest = `${cxAssetsDir}/${file}`;
|
|
149
|
+
fsx.copySync(fileSrc, fileDest, { preserveTimestamps: true });
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
} catch (err) {
|
|
153
|
+
console.error(err);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
export {
|
|
158
|
+
createDistFromGatsbyPublic,
|
|
159
|
+
getGatsbyAssetPrefixWithDomain,
|
|
160
|
+
runGatsbyBuildCommand,
|
|
161
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# CX Artifacs
|
|
2
|
+
|
|
3
|
+
## How to add an artifact.
|
|
4
|
+
|
|
5
|
+
An artifact is a **full path** to a file or directory if it has a fixed
|
|
6
|
+
location or only a **name** when it is going to be moved (archived/restored)
|
|
7
|
+
between directories in the rendering process and therefore doesn't have a
|
|
8
|
+
single location.
|
|
9
|
+
|
|
10
|
+
Only the exporter knows where the artifacts are archived and restored, so the
|
|
11
|
+
artifacts don't need to know anything other than their own location or name.
|
|
12
|
+
|
|
13
|
+
Si estás creando un adaptador, sus artefactos deberán ir en un archivo separado (igual que `artifacts/cx.ts`) y exportar una función por defecto que devuelva un `Artifacts`. Todo deberá estar exportado desde `artifacts/index.ts`.
|
|
14
|
+
|
|
15
|
+
**Artifacts have four categories:**
|
|
16
|
+
|
|
17
|
+
- **initials**: Are directories that need to be created for their
|
|
18
|
+
future use.
|
|
19
|
+
|
|
20
|
+
- **archivables**: Are stored in `__exports` which is the one uploaded to the
|
|
21
|
+
server as the final render and restored in `__cx` and `__ssg` to be reused in the
|
|
22
|
+
render. Therefore, they don't have a single location and should be added only
|
|
23
|
+
with the artifact name (directory/file)
|
|
24
|
+
|
|
25
|
+
- **cacheables**: Are stored in `__cache` and restored in `__cx` and `__ssg` to be
|
|
26
|
+
reused in each domain render. Therefore, they don't have a single location.
|
|
27
|
+
|
|
28
|
+
- **disposables**: Are generated alwais in `__cx` and `__ssg` or fixed locations.
|
|
29
|
+
These artifacts are discarded (deleted) in each domain render. They are
|
|
30
|
+
temporary directories and/or files.
|
|
31
|
+
|
|
32
|
+
## Example
|
|
33
|
+
|
|
34
|
+
Check `cx.ts` inside `./artifacts` directory to see how to add an artifact.
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { Artifacts } from "../types/global";
|
|
2
|
+
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
|
|
5
|
+
import { getConfig } from "../utils/core-utils";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Returns the artifacts of CX.
|
|
9
|
+
*/
|
|
10
|
+
function getCxArtifacts(domain: string): Artifacts {
|
|
11
|
+
const config = getConfig();
|
|
12
|
+
const { __cx, __exports, __cache } = config.paths(domain);
|
|
13
|
+
|
|
14
|
+
return {
|
|
15
|
+
initials: [
|
|
16
|
+
__exports, // `/exports/<domain>`
|
|
17
|
+
__cache, // `__cx/.cx-cache/<domain>`
|
|
18
|
+
path.join(__cx, "store"),
|
|
19
|
+
path.join(__cx, "apiCache"),
|
|
20
|
+
],
|
|
21
|
+
disposables: [
|
|
22
|
+
path.join(__cx, "store"),
|
|
23
|
+
path.join(__cx, "apiCache"),
|
|
24
|
+
path.join(__cx, "render-metadata.json"),
|
|
25
|
+
path.join(__cx, "dist"),
|
|
26
|
+
path.join(__cx, "debug"),
|
|
27
|
+
],
|
|
28
|
+
cacheables: ["apiCache", "store"],
|
|
29
|
+
archivables: ["dist", "assets", "debug"],
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export default getCxArtifacts;
|
package/exporter/build.sh
CHANGED
|
@@ -1,5 +1,39 @@
|
|
|
1
|
-
|
|
1
|
+
# Build CX script file
|
|
2
|
+
#
|
|
3
|
+
# This file generates the necessary builds for CX.
|
|
4
|
+
# - Setup, to generate necessary elements (tsconfig, etc..)
|
|
5
|
+
# - Library, CX library that will be used by the SSG framework.
|
|
6
|
+
# - Scripts, CX scripts that will be used by infra during the render process.
|
|
7
|
+
#
|
|
8
|
+
# @todo:
|
|
9
|
+
# In the future, we will try to eliminate the bundling processes and use
|
|
10
|
+
# TypeScript or ESModules directly.
|
|
2
11
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
12
|
+
# start
|
|
13
|
+
echo "📦 Building ..."
|
|
14
|
+
|
|
15
|
+
# CLI options
|
|
16
|
+
log="--log-level=error"
|
|
17
|
+
production_node_opts="--bundle --platform=node --minify --sourcemap"
|
|
18
|
+
debugging_node_opts="--bundle --platform=node --sourcemap"
|
|
19
|
+
react_opts="--platform=node --external:@griddo-instance --external:react --external:react-dom --bundle --minify"
|
|
20
|
+
|
|
21
|
+
# Manage --minify for debugging
|
|
22
|
+
bundle_node_opts=$production_node_opts
|
|
23
|
+
if [ "$1" = "--debug" ]; then
|
|
24
|
+
bundle_node_opts=$debugging_node_opts
|
|
25
|
+
fi
|
|
26
|
+
|
|
27
|
+
# library
|
|
28
|
+
esbuild ${log} ./exporter/index.ts ${bundle_node_opts} --outfile=./build/index.js
|
|
29
|
+
esbuild ${log} ./exporter/react/index.tsx ${react_opts} --outfile=./build/react/index.js
|
|
30
|
+
|
|
31
|
+
# scripts
|
|
32
|
+
esbuild ${log} ./exporter/commands/end-render.ts ${bundle_node_opts} --outfile=./build/end-render.js
|
|
33
|
+
esbuild ${log} ./exporter/commands/upload-search-content.ts ${bundle_node_opts} --outfile=./build/upload-search-content.js
|
|
34
|
+
esbuild ${log} ./exporter/commands/reset-render.ts ${bundle_node_opts} --outfile=./build/reset-render.js
|
|
35
|
+
esbuild ${log} ./exporter/commands/start-render.ts ${bundle_node_opts} --outfile=./build/start-render.js
|
|
36
|
+
esbuild ${log} ./exporter/commands/prepare-domains-render.ts ${bundle_node_opts} --outfile=./build/prepare-domains-render.js
|
|
37
|
+
|
|
38
|
+
# types
|
|
39
|
+
tsc --emitDeclarationOnly --declaration --outDir build --project tsconfig.exporter.json
|
|
@@ -1,109 +1,105 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
import fsp from "node:fs/promises";
|
|
3
|
+
import fs from "node:fs";
|
|
6
4
|
import path from "node:path";
|
|
7
5
|
|
|
8
|
-
import
|
|
6
|
+
import pkgDir from "pkg-dir";
|
|
7
|
+
|
|
9
8
|
import { AuthService } from "../services/auth";
|
|
10
9
|
import { endSiteRender } from "../services/sites";
|
|
10
|
+
import { getConfig } from "../utils/core-utils";
|
|
11
11
|
import { getInstanceDomains } from "../utils/domains";
|
|
12
|
-
import { throwError } from "../utils/errors";
|
|
13
|
-
import { pathExists } from "../utils/folders";
|
|
14
12
|
import { infoLog } from "../utils/loggin";
|
|
15
|
-
import { getRenderMetadataFromDB, getRenderMode, getRenderPathsFromDB } from "../utils/render";
|
|
16
13
|
|
|
17
|
-
const
|
|
14
|
+
const RENDER_BY_DOMAIN = process.env.GRIDDO_RENDER_BY_DOMAINS || "";
|
|
15
|
+
|
|
16
|
+
// Where we are going to find export dirs
|
|
17
|
+
const execBasePath = pkgDir.sync(path.resolve(__dirname, "../.."))!;
|
|
18
|
+
|
|
19
|
+
// Where we are going to find archived exports
|
|
20
|
+
const exportArchiveBasePath = path.resolve(execBasePath, "exports/sites");
|
|
21
|
+
|
|
22
|
+
type Report = {
|
|
23
|
+
authControl:
|
|
24
|
+
| {
|
|
25
|
+
Authorization: string;
|
|
26
|
+
"Cache-Control": string;
|
|
27
|
+
lang?: string | undefined;
|
|
28
|
+
}
|
|
29
|
+
| undefined;
|
|
30
|
+
sites: Array<{
|
|
31
|
+
siteId: number;
|
|
32
|
+
publishHashes: Array<string>;
|
|
33
|
+
siteHash: string | null;
|
|
34
|
+
unpublishHashes: Array<string>;
|
|
35
|
+
publishPagesIds: Array<number>;
|
|
36
|
+
}>;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
function getDomainRenderReport(domain: string) {
|
|
40
|
+
const reports: Array<Report> = [];
|
|
41
|
+
const { buildReportFileName } = getConfig();
|
|
18
42
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
const buildReportFile = path.resolve(exportArchiveBasePath, domain, "dist", buildReportFileName);
|
|
43
|
+
const buildReportFile = path.resolve(
|
|
44
|
+
exportArchiveBasePath,
|
|
45
|
+
domain,
|
|
46
|
+
"dist",
|
|
47
|
+
buildReportFileName,
|
|
48
|
+
);
|
|
26
49
|
|
|
27
|
-
if (!(
|
|
28
|
-
|
|
29
|
-
throwError(ArtifactError);
|
|
50
|
+
if (!fs.existsSync(buildReportFile)) {
|
|
51
|
+
console.info(`Build report file "${buildReportFile}" not found.`);
|
|
30
52
|
}
|
|
31
53
|
|
|
32
|
-
|
|
33
|
-
}
|
|
54
|
+
const buildReport = JSON.parse(fs.readFileSync(buildReportFile, "utf-8"));
|
|
34
55
|
|
|
35
|
-
|
|
36
|
-
const sites = report.sites;
|
|
56
|
+
reports.push(buildReport);
|
|
37
57
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
58
|
+
return reports;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
(async () => {
|
|
62
|
+
const sendEndSiteRender = async (reports: Array<Report>) => {
|
|
63
|
+
for (const report of reports) {
|
|
64
|
+
const sites = report.sites;
|
|
44
65
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
const { __sites } = await getRenderPathsFromDB();
|
|
66
|
+
for (const site of sites) {
|
|
67
|
+
const { siteId, ...body } = site;
|
|
48
68
|
|
|
49
|
-
|
|
50
|
-
if (renderByDomains) {
|
|
51
|
-
const [domain] = process.argv.slice(2);
|
|
52
|
-
const { renderMode } = await getRenderMode(domain);
|
|
69
|
+
console.info(`Site (${siteId})`);
|
|
53
70
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
return;
|
|
71
|
+
await endSiteRender(siteId, body);
|
|
72
|
+
}
|
|
57
73
|
}
|
|
74
|
+
};
|
|
58
75
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
});
|
|
76
|
+
if (RENDER_BY_DOMAIN) {
|
|
77
|
+
await AuthService.login();
|
|
78
|
+
const domain = process.argv.splice(2)[0];
|
|
79
|
+
const reports = getDomainRenderReport(domain);
|
|
64
80
|
|
|
65
81
|
infoLog(`Sending ending call to ${domain} sites`);
|
|
66
82
|
|
|
67
|
-
for (const
|
|
68
|
-
site
|
|
69
|
-
|
|
83
|
+
for (const report of reports) {
|
|
84
|
+
for (const site of report.sites) {
|
|
85
|
+
site.publishHashes = [...new Set(site.publishHashes)];
|
|
86
|
+
site.unpublishHashes = [...new Set(site.unpublishHashes)];
|
|
87
|
+
}
|
|
70
88
|
}
|
|
71
89
|
|
|
72
|
-
await sendEndSiteRender(
|
|
90
|
+
await sendEndSiteRender(reports);
|
|
73
91
|
} else {
|
|
74
|
-
|
|
92
|
+
// Legacy render
|
|
75
93
|
const domains = await getInstanceDomains();
|
|
76
94
|
for (const domain of domains) {
|
|
77
|
-
const
|
|
78
|
-
|
|
79
|
-
if (renderMode === "IDLE") {
|
|
80
|
-
infoLog(`Skipping build-end for domain ${domain} as it is marked as IDLE.`);
|
|
81
|
-
return;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
const report = await getRenderReport({
|
|
85
|
-
domain,
|
|
86
|
-
exportsSiteDir: __sites,
|
|
87
|
-
buildReportFileName,
|
|
88
|
-
});
|
|
95
|
+
const reports = getDomainRenderReport(domain);
|
|
89
96
|
|
|
90
97
|
infoLog(`Sending ending call to ${domain} sites`);
|
|
91
98
|
|
|
92
|
-
|
|
93
|
-
site.publishHashes = [...new Set(site.publishHashes)];
|
|
94
|
-
site.unpublishHashes = [...new Set(site.unpublishHashes)];
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
await sendEndSiteRender(report);
|
|
99
|
+
await sendEndSiteRender(reports);
|
|
98
100
|
}
|
|
99
101
|
}
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
async function main() {
|
|
103
|
-
await endRender();
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
main().catch((err) => {
|
|
102
|
+
})().catch((err) => {
|
|
107
103
|
console.error("Error", err?.stdout?.toString() || err);
|
|
108
104
|
process.exit(1);
|
|
109
105
|
});
|