@griddo/cx 11.7.5 → 11.7.6-rc.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +25 -228
- 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 +12 -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 +9 -0
- package/build/adapters/gatsby/actions/init.js.map +1 -0
- package/build/adapters/gatsby/actions/meta.js +14 -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 +50 -0
- package/build/adapters/gatsby/actions/sync.js.map +1 -0
- package/build/adapters/gatsby/index.js +74 -0
- package/build/adapters/gatsby/index.js.map +1 -0
- package/build/adapters/gatsby/shared/context.js +25 -0
- package/build/adapters/gatsby/shared/context.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 +49 -0
- package/build/adapters/gatsby/shared/gatsby-build.js.map +1 -0
- package/build/adapters/gatsby/shared/sync-render.js +208 -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 +63 -0
- package/build/commands/end-render.js.map +1 -0
- package/build/commands/prepare-assets-directory.js +32 -0
- package/build/commands/prepare-assets-directory.js.map +1 -0
- package/build/commands/prepare-domains-render.js +138 -0
- package/build/commands/prepare-domains-render.js.map +1 -0
- package/build/commands/reset-render.js +22 -0
- package/build/commands/reset-render.js.map +1 -0
- package/build/commands/start-render.js +35 -0
- package/build/commands/start-render.js.map +1 -0
- package/build/commands/upload-search-content.js +189 -0
- package/build/commands/upload-search-content.js.map +1 -0
- package/build/constants/endpoints.js +42 -0
- package/build/constants/endpoints.js.map +1 -0
- package/build/constants/envs.js +73 -0
- package/build/constants/envs.js.map +1 -0
- package/build/constants/errors.js +89 -0
- package/build/constants/errors.js.map +1 -0
- package/build/exporter/adapters/gatsby/actions/clean.d.ts +3 -0
- package/build/exporter/adapters/gatsby/actions/close.d.ts +3 -0
- package/build/exporter/adapters/gatsby/actions/data.d.ts +2 -0
- package/build/exporter/adapters/gatsby/actions/healthCheck.d.ts +2 -0
- package/build/exporter/adapters/gatsby/actions/init.d.ts +2 -0
- package/build/exporter/adapters/gatsby/actions/meta.d.ts +2 -0
- package/build/exporter/adapters/gatsby/actions/prepare.d.ts +2 -0
- package/build/exporter/adapters/gatsby/actions/relocation.d.ts +2 -0
- package/build/exporter/adapters/gatsby/actions/restore.d.ts +3 -0
- package/build/exporter/adapters/gatsby/actions/ssg.d.ts +3 -0
- package/build/exporter/adapters/gatsby/actions/sync.d.ts +3 -0
- package/build/exporter/adapters/gatsby/index.d.ts +9 -0
- package/build/exporter/adapters/gatsby/shared/context.d.ts +38 -0
- package/build/exporter/adapters/gatsby/shared/extract-assets.d.ts +7 -0
- package/build/exporter/adapters/gatsby/shared/gatsby-build.d.ts +7 -0
- package/build/exporter/adapters/gatsby/shared/sync-render.d.ts +36 -0
- package/build/exporter/adapters/gatsby/shared/types.d.ts +34 -0
- package/build/exporter/commands/start-render.d.ts +2 -0
- package/build/exporter/commands/upload-search-content.d.ts +2 -0
- package/build/{constants → exporter/constants}/envs.d.ts +1 -7
- package/build/{errors/errors-data.d.ts → exporter/constants/errors.d.ts} +5 -3
- package/build/{services → exporter/services}/auth.d.ts +1 -1
- package/build/exporter/services/db.d.ts +4 -0
- package/build/{services → exporter/services}/robots.d.ts +0 -6
- package/build/{services → exporter/services}/sites.d.ts +5 -2
- package/build/exporter/services/store.d.ts +15 -0
- package/build/{types → exporter/types}/api.d.ts +3 -4
- package/build/{types → exporter/types}/global.d.ts +6 -6
- package/build/{types → exporter/types}/navigation.d.ts +1 -1
- package/build/exporter/types/render.d.ts +50 -0
- package/build/{types → exporter/types}/sites.d.ts +1 -2
- package/build/exporter/utils/artifacts.d.ts +6 -0
- package/build/exporter/utils/brush.d.ts +18 -0
- package/build/{utils → exporter/utils}/cache.d.ts +7 -12
- package/build/{utils/health-checks.d.ts → exporter/utils/check-health.d.ts} +2 -2
- package/build/exporter/utils/core-utils.d.ts +77 -0
- package/build/{utils → exporter/utils}/domains.d.ts +1 -1
- package/build/{errors/index.d.ts → exporter/utils/errors.d.ts} +3 -3
- package/build/exporter/utils/folders.d.ts +66 -0
- package/build/{utils → exporter/utils}/loggin.d.ts +2 -16
- package/build/{utils → exporter/utils}/pages.d.ts +2 -2
- package/build/exporter/utils/render.d.ts +49 -0
- package/build/{utils → exporter/utils}/sites.d.ts +3 -3
- package/build/{utils → exporter/utils}/store.d.ts +10 -38
- package/build/services/auth.js +39 -0
- package/build/services/auth.js.map +1 -0
- package/build/services/db.js +34 -0
- package/build/services/db.js.map +1 -0
- package/build/services/navigation.js +93 -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 +58 -0
- package/build/services/robots.js.map +1 -0
- package/build/services/sites.js +109 -0
- package/build/services/sites.js.map +1 -0
- package/build/services/store.js +282 -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 +161 -0
- package/build/utils/api.js.map +1 -0
- package/build/utils/artifacts.js +34 -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-health.js +68 -0
- package/build/utils/check-health.js.map +1 -0
- package/build/utils/core-utils.js +251 -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 +339 -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 +102 -0
- package/build/utils/loggin.js.map +1 -0
- package/build/utils/pages.js +359 -0
- package/build/utils/pages.js.map +1 -0
- package/build/utils/render.js +144 -0
- package/build/utils/render.js.map +1 -0
- package/build/utils/sites.js +239 -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 +17 -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 +12 -0
- package/exporter/adapters/gatsby/actions/meta.ts +18 -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 +70 -0
- package/exporter/adapters/gatsby/index.ts +60 -146
- package/exporter/adapters/gatsby/shared/context.ts +50 -0
- package/exporter/adapters/gatsby/shared/extract-assets.ts +61 -0
- package/exporter/adapters/gatsby/shared/gatsby-build.ts +54 -0
- package/exporter/adapters/gatsby/shared/sync-render.ts +294 -0
- package/exporter/adapters/gatsby/shared/types.ts +35 -0
- package/exporter/build-esbuild.noop +42 -0
- package/exporter/build.sh +5 -38
- package/exporter/commands/end-render.ts +56 -81
- package/exporter/commands/prepare-assets-directory.ts +33 -0
- package/exporter/commands/prepare-domains-render.ts +149 -31
- package/exporter/commands/reset-render.ts +12 -3
- package/exporter/commands/start-render.ts +18 -47
- package/exporter/commands/upload-search-content.ts +206 -21
- package/exporter/constants/envs.ts +59 -51
- package/exporter/{errors/errors-data.ts → constants/errors.ts} +24 -15
- package/exporter/services/auth.ts +7 -6
- package/exporter/services/db.ts +32 -0
- package/exporter/services/navigation.ts +4 -10
- package/exporter/services/reference-fields.ts +8 -23
- package/exporter/services/robots.ts +8 -15
- package/exporter/services/sites.ts +35 -24
- package/exporter/services/store.ts +118 -76
- package/exporter/types/api.ts +24 -27
- package/exporter/types/global.ts +8 -10
- 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 +46 -82
- package/exporter/{artifacts/index.ts → utils/artifacts.ts} +9 -8
- package/exporter/utils/brush.ts +34 -0
- package/exporter/utils/cache.ts +34 -59
- package/exporter/utils/check-health.ts +79 -0
- package/exporter/utils/core-utils.ts +86 -247
- package/exporter/utils/domains.ts +10 -7
- package/exporter/{errors/index.ts → utils/errors.ts} +10 -9
- package/exporter/utils/folders.ts +161 -92
- package/exporter/utils/images.ts +1 -6
- package/exporter/utils/instance.ts +9 -12
- package/exporter/utils/loggin.ts +24 -89
- package/exporter/utils/pages.ts +23 -88
- package/exporter/utils/render.ts +147 -48
- package/exporter/utils/sites.ts +67 -77
- package/exporter/utils/store.ts +85 -178
- package/gatsby-browser.tsx +41 -58
- package/gatsby-config.ts +6 -12
- package/gatsby-node.ts +30 -89
- package/gatsby-ssr.tsx +2 -1
- package/package.json +32 -73
- package/plugins/gatsby-plugin-svgr-loader/gatsby-node.js +55 -0
- package/plugins/gatsby-plugin-svgr-loader/package.json +8 -0
- package/{exporter/react → react}/Favicon/index.tsx +1 -7
- package/{exporter/react → react}/GriddoIntegrations/index.tsx +6 -14
- package/{exporter/react → react}/GriddoIntegrations/utils.ts +4 -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 +91 -2
- package/src/html.tsx +2 -11
- package/src/types.ts +5 -5
- package/start-render.js +1 -3
- package/tsconfig.json +3 -2
- 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/move-assets.d.ts +0 -1
- package/build/commands/prepare-domains-render.d.ts +0 -1
- 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/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/domains.d.ts +0 -6
- package/build/services/register.d.ts +0 -36
- package/build/services/settings.d.ts +0 -4
- 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/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/core-utils.d.ts +0 -107
- package/build/utils/create-build-data.d.ts +0 -8
- package/build/utils/folders.d.ts +0 -53
- package/build/utils/render.d.ts +0 -13
- package/build/utils/searches.d.ts +0 -15
- 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/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 -179
- package/src/README.md +0 -7
- package/build/{commands → exporter/commands}/end-render.d.ts +0 -0
- package/build/{commands/reset-render.d.ts → exporter/commands/prepare-assets-directory.d.ts} +0 -0
- package/build/{commands/start-render.d.ts → exporter/commands/prepare-domains-render.d.ts} +0 -0
- package/build/{commands/upload-search-content.d.ts → exporter/commands/reset-render.d.ts} +0 -0
- package/build/{constants → exporter/constants}/endpoints.d.ts +0 -0
- package/build/{services → exporter/services}/navigation.d.ts +0 -0
- package/build/{services → exporter/services}/reference-fields.d.ts +0 -0
- package/build/{types → exporter/types}/pages.d.ts +1 -1
- /package/build/{types → exporter/types}/templates.d.ts +0 -0
- /package/build/{utils → exporter/utils}/api.d.ts +0 -0
- /package/build/{utils → exporter/utils}/images.d.ts +0 -0
- /package/build/{utils → exporter/utils}/instance.d.ts +0 -0
- /package/{exporter/react → react}/Favicon/utils.ts +0 -0
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import type { RenderContext } from "../shared/context";
|
|
2
|
+
import type { SSG } from "../shared/types";
|
|
3
|
+
|
|
4
|
+
import fsp from "node:fs/promises";
|
|
5
|
+
import path from "node:path";
|
|
6
|
+
|
|
7
|
+
import { RENDER_MODE } from "../../../types/render";
|
|
8
|
+
import {
|
|
9
|
+
deleteDisposableSiteDirs,
|
|
10
|
+
deleteEmptyDirectories,
|
|
11
|
+
moveDirs,
|
|
12
|
+
removeVirtualPages,
|
|
13
|
+
} from "../../../utils/folders";
|
|
14
|
+
import { extractAssetsFromDist } from "../shared/extract-assets";
|
|
15
|
+
import { SyncRender } from "../shared/sync-render";
|
|
16
|
+
|
|
17
|
+
export async function syncAction(context: RenderContext<SSG>) {
|
|
18
|
+
const {
|
|
19
|
+
renderMode,
|
|
20
|
+
cxArtifacts,
|
|
21
|
+
domain,
|
|
22
|
+
pagesToCreate,
|
|
23
|
+
pagesToDelete,
|
|
24
|
+
paths: { __cx, __ssg, __cache, __exports },
|
|
25
|
+
ssg: { ssgArtifacts, assetPrefix },
|
|
26
|
+
} = context;
|
|
27
|
+
|
|
28
|
+
const needsAssetPrefix = !!assetPrefix && assetPrefix !== "";
|
|
29
|
+
const distDir = path.join(__cx, "dist");
|
|
30
|
+
const distRestoredDir = path.join(__cx, "dist-restored");
|
|
31
|
+
const storeDir = path.join(context.paths.__cx, "store");
|
|
32
|
+
|
|
33
|
+
await removeVirtualPages(storeDir);
|
|
34
|
+
// caching...
|
|
35
|
+
await moveDirs(__cx, __cache, cxArtifacts.cacheables);
|
|
36
|
+
await moveDirs(__ssg, __cache, ssgArtifacts.cacheables);
|
|
37
|
+
|
|
38
|
+
if (renderMode === RENDER_MODE.FROM_SCRATCH) {
|
|
39
|
+
await deleteDisposableSiteDirs(distDir);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if (renderMode === RENDER_MODE.INCREMENTAL) {
|
|
43
|
+
await deleteDisposableSiteDirs(distRestoredDir);
|
|
44
|
+
|
|
45
|
+
const syncRender = new SyncRender({
|
|
46
|
+
src: distDir,
|
|
47
|
+
dst: distRestoredDir,
|
|
48
|
+
pagesToCreate,
|
|
49
|
+
pagesToDelete,
|
|
50
|
+
artifactsToCopyToExports: ["build-report.json"],
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
syncRender.setPagesToDelete();
|
|
54
|
+
syncRender.setPagesToAdd();
|
|
55
|
+
syncRender.sync();
|
|
56
|
+
|
|
57
|
+
await fsp.rm(distDir, { force: true, recursive: true });
|
|
58
|
+
await fsp.rename(distRestoredDir, distDir);
|
|
59
|
+
await deleteEmptyDirectories(distDir);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
if (needsAssetPrefix) {
|
|
63
|
+
await extractAssetsFromDist(domain);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// archiving...
|
|
67
|
+
await moveDirs(__cx, __exports, cxArtifacts.archivables, {
|
|
68
|
+
withBackup: true,
|
|
69
|
+
});
|
|
70
|
+
}
|
|
@@ -1,162 +1,76 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
Artifacts,
|
|
3
|
-
LifeCyclesNames,
|
|
4
|
-
LifeCycleSteps,
|
|
5
|
-
} from "../../types/global";
|
|
1
|
+
import type { SSG } from "./shared/types";
|
|
6
2
|
|
|
7
3
|
import path from "node:path";
|
|
8
4
|
|
|
9
|
-
import {
|
|
10
|
-
|
|
11
|
-
|
|
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";
|
|
5
|
+
import { GRIDDO_ASSET_PREFIX } from "../../constants/envs";
|
|
6
|
+
import { getCxArtifacts } from "../../utils/artifacts";
|
|
7
|
+
import { doLifeCycle } from "../../utils/core-utils";
|
|
32
8
|
import { infoLog } from "../../utils/loggin";
|
|
33
|
-
import {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
} from "
|
|
9
|
+
import { getRenderMetadataFromDB, getRenderMode, getRenderPathsFromDB } from "../../utils/render";
|
|
10
|
+
import { cleanAction } from "./actions/clean";
|
|
11
|
+
import { closeAction } from "./actions/close";
|
|
12
|
+
import { dataAction } from "./actions/data";
|
|
13
|
+
import { healthCheckAction } from "./actions/healthCheck";
|
|
14
|
+
import { initAction } from "./actions/init";
|
|
15
|
+
import { metaAction } from "./actions/meta";
|
|
16
|
+
import { prepareAction } from "./actions/prepare";
|
|
17
|
+
import { relocationAction } from "./actions/relocation";
|
|
18
|
+
import { restoreAction } from "./actions/restore";
|
|
19
|
+
import { ssgAction } from "./actions/ssg";
|
|
20
|
+
import { syncAction } from "./actions/sync";
|
|
21
|
+
import { RenderContext } from "./shared/context";
|
|
38
22
|
|
|
39
23
|
/**
|
|
40
|
-
*
|
|
24
|
+
* Executes a complete Gatsby render process for a given domain.
|
|
25
|
+
*
|
|
26
|
+
* The render process consists of multiple lifecycle steps that handle cleaning,
|
|
27
|
+
* preparing, building and syncing the site. It can run in two modes:
|
|
28
|
+
* - FROM_SCRATCH: Performs a complete rebuild of the site
|
|
29
|
+
* - INCREMENTAL: Only rebuilds changed pages while preserving the rest
|
|
41
30
|
*/
|
|
42
|
-
export async function
|
|
43
|
-
await
|
|
44
|
-
const config = getConfig();
|
|
31
|
+
export async function gatsbyRenderDomain(domain: string) {
|
|
32
|
+
const { renderMode, reason } = await getRenderMode(domain);
|
|
45
33
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
//
|
|
50
|
-
__ssg,
|
|
51
|
-
__exports,
|
|
52
|
-
__cache,
|
|
53
|
-
__cx,
|
|
54
|
-
__components,
|
|
55
|
-
} = config.paths(domain);
|
|
34
|
+
if (renderMode === "IDLE") {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
56
37
|
|
|
57
|
-
|
|
58
|
-
|
|
38
|
+
const renderReason = reason ? `<${reason}>` : "";
|
|
39
|
+
infoLog(`Init render (${renderMode}) ${renderReason} for domain ${domain}\n`);
|
|
59
40
|
|
|
60
|
-
|
|
61
|
-
const
|
|
41
|
+
const renderMetadata = await getRenderMetadataFromDB();
|
|
42
|
+
const paths = await getRenderPathsFromDB({ domain });
|
|
43
|
+
const cxArtifacts = await getCxArtifacts(domain);
|
|
44
|
+
const domainNeedsAssetPrefix = GRIDDO_ASSET_PREFIX && domain.startsWith(renderMetadata.proDomain);
|
|
45
|
+
const assetPrefix = domainNeedsAssetPrefix ? `${GRIDDO_ASSET_PREFIX}/${domain}` : "";
|
|
46
|
+
const ssgArtifacts = {
|
|
62
47
|
disposables: [
|
|
63
|
-
path.join(__ssg, "public"),
|
|
64
|
-
path.join(__ssg, "static"),
|
|
65
|
-
path.join(__ssg, ".cache"),
|
|
48
|
+
path.join(paths.__ssg, "public"),
|
|
49
|
+
path.join(paths.__ssg, "static"),
|
|
50
|
+
path.join(paths.__ssg, ".cache"),
|
|
51
|
+
path.join(paths.__ssg, "domains.json"), // Este disposable es de griddo pero está en la ruta __ssg
|
|
66
52
|
],
|
|
67
53
|
cacheables: [".cache"],
|
|
68
54
|
};
|
|
69
55
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
},
|
|
91
|
-
|
|
92
|
-
{
|
|
93
|
-
name: "Clean",
|
|
94
|
-
steps: [() => removeArtifacts(disposableArtifacts)],
|
|
95
|
-
},
|
|
96
|
-
|
|
97
|
-
{
|
|
98
|
-
name: "Prepare",
|
|
99
|
-
steps: [() => createArtifacts(cxArtifacts.initials)],
|
|
100
|
-
},
|
|
101
|
-
|
|
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
|
-
}
|
|
56
|
+
const context = new RenderContext<SSG>({
|
|
57
|
+
domain,
|
|
58
|
+
renderMode,
|
|
59
|
+
paths,
|
|
60
|
+
renderMetadata,
|
|
61
|
+
cxArtifacts,
|
|
62
|
+
ssg: { assetPrefix, ssgArtifacts },
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
await doLifeCycle("Init", async () => initAction(context));
|
|
66
|
+
await doLifeCycle("Clean", async () => cleanAction(context));
|
|
67
|
+
await doLifeCycle("Prepare", async () => prepareAction(context));
|
|
68
|
+
await doLifeCycle("Restore", async () => restoreAction(context));
|
|
69
|
+
await doLifeCycle("Data", async () => dataAction(context));
|
|
70
|
+
await doLifeCycle("SSG", async () => ssgAction(context));
|
|
71
|
+
await doLifeCycle("Relocation", async () => relocationAction(context));
|
|
72
|
+
await doLifeCycle("Meta", async () => metaAction(context));
|
|
73
|
+
await doLifeCycle("Sync", async () => syncAction(context));
|
|
74
|
+
await doLifeCycle("Close", async () => closeAction(context));
|
|
75
|
+
await doLifeCycle("HealthCheck", async () => healthCheckAction(context));
|
|
162
76
|
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { Artifacts, PlaceholderPath } from "../../../types/global";
|
|
2
|
+
import type { RenderMode } from "../../../types/render";
|
|
3
|
+
|
|
4
|
+
interface RenderContextProps<T> {
|
|
5
|
+
domain: string;
|
|
6
|
+
renderMode: RenderMode;
|
|
7
|
+
paths: Record<string, string>;
|
|
8
|
+
ssg: T;
|
|
9
|
+
renderMetadata: {
|
|
10
|
+
proDomain: string;
|
|
11
|
+
griddoVersion: string;
|
|
12
|
+
buildReportFileName: string;
|
|
13
|
+
};
|
|
14
|
+
cxArtifacts: Artifacts;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Encapsulates the state, configuration, and artifacts for a single SSG
|
|
19
|
+
* render process.
|
|
20
|
+
*
|
|
21
|
+
* This class is instantiated at the beginning of a render and passed through
|
|
22
|
+
* each lifecycle step, providing a centralized and consistent context for all
|
|
23
|
+
* operations. It is agnostic to the specific SSG being used.
|
|
24
|
+
*/
|
|
25
|
+
export class RenderContext<T = unknown> {
|
|
26
|
+
readonly domain: string;
|
|
27
|
+
readonly renderMode: RenderMode;
|
|
28
|
+
readonly paths: Record<PlaceholderPath, string>;
|
|
29
|
+
pagesToCreate: number[] = [];
|
|
30
|
+
pagesToDelete: number[] = [];
|
|
31
|
+
ssg: T;
|
|
32
|
+
renderMetadata: { proDomain: string; griddoVersion: string; buildReportFileName: string };
|
|
33
|
+
cxArtifacts: Artifacts;
|
|
34
|
+
|
|
35
|
+
constructor({
|
|
36
|
+
domain,
|
|
37
|
+
renderMode,
|
|
38
|
+
ssg,
|
|
39
|
+
paths,
|
|
40
|
+
renderMetadata,
|
|
41
|
+
cxArtifacts,
|
|
42
|
+
}: RenderContextProps<T>) {
|
|
43
|
+
this.domain = domain;
|
|
44
|
+
this.renderMode = renderMode;
|
|
45
|
+
this.paths = paths;
|
|
46
|
+
this.renderMetadata = renderMetadata;
|
|
47
|
+
this.cxArtifacts = cxArtifacts;
|
|
48
|
+
this.ssg = ssg;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import fsp from "node:fs/promises";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
|
|
4
|
+
import { pathExists } from "../../../utils/folders";
|
|
5
|
+
import { getRenderPathsFromDB } from "../../../utils/render";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Update the Griddo's `/dist` dir with the contents from `public` dir only
|
|
9
|
+
* with files of type: js, json and css.
|
|
10
|
+
* TODO: Explicar que el static se copia a assets porque el js va en el subdominio de assets.
|
|
11
|
+
*/
|
|
12
|
+
async function extractAssetsFromDist(domain: string) {
|
|
13
|
+
const { __cx } = await getRenderPathsFromDB({ domain });
|
|
14
|
+
|
|
15
|
+
// Archivos (no carpetas) válidos de public
|
|
16
|
+
const filesFromDist = (await fsp.readdir(path.join(__cx, "dist"))).filter(
|
|
17
|
+
(file) =>
|
|
18
|
+
path.extname(file) === ".js" ||
|
|
19
|
+
path.extname(file) === ".json" ||
|
|
20
|
+
path.extname(file) === ".css",
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
// Creamos assets si es necesario (needsAssetPrefix)
|
|
24
|
+
await fsp.mkdir(path.join(__cx, "assets"), { recursive: true });
|
|
25
|
+
// page-data folder
|
|
26
|
+
await fsp.cp(path.join(__cx, "dist", "page-data"), path.join(__cx, "assets", "page-data"), {
|
|
27
|
+
preserveTimestamps: true,
|
|
28
|
+
recursive: true,
|
|
29
|
+
});
|
|
30
|
+
// static folder si existe
|
|
31
|
+
if (await pathExists(path.join(__cx, "static"))) {
|
|
32
|
+
await fsp.cp(path.join(__cx, "static"), path.join(__cx, "assets"), {
|
|
33
|
+
force: false,
|
|
34
|
+
preserveTimestamps: true,
|
|
35
|
+
recursive: true,
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
// dist/static -> assets/static
|
|
39
|
+
await fsp.cp(path.join(__cx, "dist", "static"), path.join(__cx, "assets", "static"), {
|
|
40
|
+
force: false,
|
|
41
|
+
preserveTimestamps: true,
|
|
42
|
+
recursive: true,
|
|
43
|
+
});
|
|
44
|
+
// otro static...
|
|
45
|
+
if (await pathExists(path.join(__cx, "static"))) {
|
|
46
|
+
await fsp.cp(path.join(__cx, "static"), path.join(__cx, "dist", domain), {
|
|
47
|
+
preserveTimestamps: true,
|
|
48
|
+
recursive: true,
|
|
49
|
+
force: false,
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// Copia el resto de archivos...
|
|
54
|
+
for (const file of filesFromDist) {
|
|
55
|
+
const fileSrc = path.join(__cx, "dist", file);
|
|
56
|
+
const fileDest = path.join(__cx, "assets", file);
|
|
57
|
+
await fsp.cp(fileSrc, fileDest, { preserveTimestamps: true, recursive: true });
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export { extractAssetsFromDist };
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { spawn } from "node:child_process";
|
|
2
|
+
|
|
3
|
+
import { GRIDDO_SSG_VERBOSE_LOGS } from "../../../constants/envs";
|
|
4
|
+
import { verboseLog } from "../../../utils/loggin";
|
|
5
|
+
import { getRenderPathsFromDB } from "../../../utils/render";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Spawn a new node process `yarn gatsby-build`
|
|
9
|
+
* @note This proccess (`yarn gatsby-build`) can not access to the custom Griddo
|
|
10
|
+
* `process.env` so it needs variables passed to it via the `env` prop.
|
|
11
|
+
*/
|
|
12
|
+
async function gatsbyBuild(assetPrefixWithDomain: string): Promise<void> {
|
|
13
|
+
verboseLog(`read assetPrefixWithDomain, ${assetPrefixWithDomain}`);
|
|
14
|
+
verboseLog(`using this NODE_OPTIONS in gatsby command: ${process.env.NODE_OPTIONS}`);
|
|
15
|
+
|
|
16
|
+
const { __ssg } = await getRenderPathsFromDB();
|
|
17
|
+
|
|
18
|
+
// Remove `--openssl-legacy-provider` from NODE_OPTIONS because this value
|
|
19
|
+
// break Gatsby render.
|
|
20
|
+
const nodeOptionsWithoutLegacyOpenSSL = process.env.NODE_OPTIONS
|
|
21
|
+
? process.env.NODE_OPTIONS.replace(/--openssl-legacy-provider\s*/g, "").trim()
|
|
22
|
+
: "";
|
|
23
|
+
|
|
24
|
+
const args = ["gatsby-build"];
|
|
25
|
+
if (GRIDDO_SSG_VERBOSE_LOGS) {
|
|
26
|
+
args.push("--verbose");
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return new Promise((resolve, reject) => {
|
|
30
|
+
const child = spawn("yarn", args, {
|
|
31
|
+
cwd: __ssg,
|
|
32
|
+
stdio: ["ignore", "inherit", "inherit"], // stdout y stderr van a consola directamente
|
|
33
|
+
env: Object.assign(process.env, {
|
|
34
|
+
GRIDDO_EXPORTER: "true",
|
|
35
|
+
SPAWN_ASSET_PREFIX_WITH_DOMAIN: assetPrefixWithDomain,
|
|
36
|
+
NODE_OPTIONS: nodeOptionsWithoutLegacyOpenSSL,
|
|
37
|
+
}),
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
child.on("close", (code) => {
|
|
41
|
+
if (code === 0) {
|
|
42
|
+
resolve();
|
|
43
|
+
} else {
|
|
44
|
+
reject(new Error(`Gatsby build failed with exit code ${code}`));
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
child.on("error", (error) => {
|
|
49
|
+
reject(new Error(`Failed to start Gatsby build process: ${error.message}`));
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export { gatsbyBuild };
|