@griddo/cx 11.7.6 → 11.7.7-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 +27 -226
- package/build/adapters/gatsby/actions/clean.js +10 -0
- package/build/adapters/gatsby/actions/clean.js.map +1 -0
- package/build/adapters/gatsby/actions/close.js +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 +51 -0
- package/build/adapters/gatsby/actions/sync.js.map +1 -0
- package/build/adapters/gatsby/index.js +79 -0
- package/build/adapters/gatsby/index.js.map +1 -0
- package/build/adapters/gatsby/shared/context.js +31 -0
- package/build/adapters/gatsby/shared/context.js.map +1 -0
- package/build/adapters/gatsby/shared/diff-assets.js +101 -0
- package/build/adapters/gatsby/shared/diff-assets.js.map +1 -0
- package/build/adapters/gatsby/shared/extract-assets.js +58 -0
- package/build/adapters/gatsby/shared/extract-assets.js.map +1 -0
- package/build/adapters/gatsby/shared/gatsby-build.js +49 -0
- package/build/adapters/gatsby/shared/gatsby-build.js.map +1 -0
- package/build/adapters/gatsby/shared/sync-render.js +210 -0
- package/build/adapters/gatsby/shared/sync-render.js.map +1 -0
- package/build/adapters/gatsby/shared/types.js +3 -0
- package/build/adapters/gatsby/shared/types.js.map +1 -0
- package/build/commands/end-render.js +88 -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 +133 -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 +45 -0
- package/build/commands/start-render.js.map +1 -0
- package/build/commands/upload-search-content.js +180 -0
- package/build/commands/upload-search-content.js.map +1 -0
- package/build/constants/endpoints.js +42 -0
- package/build/constants/endpoints.js.map +1 -0
- package/build/constants/envs.js +68 -0
- package/build/constants/envs.js.map +1 -0
- package/build/constants/errors.js +81 -0
- package/build/constants/errors.js.map +1 -0
- package/build/services/auth.js +40 -0
- package/build/services/auth.js.map +1 -0
- package/build/services/db-class.js +49 -0
- package/build/services/db-class.js.map +1 -0
- package/build/services/db.js +34 -0
- package/build/services/db.js.map +1 -0
- package/build/services/navigation.js +96 -0
- package/build/services/navigation.js.map +1 -0
- package/build/services/reference-fields.js +131 -0
- package/build/services/reference-fields.js.map +1 -0
- package/build/services/robots.js +60 -0
- package/build/services/robots.js.map +1 -0
- package/build/services/sites.js +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 +283 -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 +362 -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 +108 -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 +240 -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 +71 -0
- package/exporter/adapters/gatsby/index.ts +67 -147
- package/exporter/adapters/gatsby/shared/context.ts +50 -0
- package/exporter/adapters/gatsby/shared/diff-assets.ts +113 -0
- package/exporter/adapters/gatsby/shared/extract-assets.ts +61 -0
- package/exporter/adapters/gatsby/shared/gatsby-build.ts +54 -0
- package/exporter/adapters/gatsby/shared/sync-render.ts +276 -0
- package/exporter/adapters/gatsby/shared/types.ts +35 -0
- package/exporter/build-esbuild.noop +42 -0
- package/exporter/build.sh +4 -38
- package/exporter/commands/end-render.ts +73 -69
- package/exporter/commands/prepare-assets-directory.ts +33 -0
- package/exporter/commands/prepare-domains-render.ts +144 -31
- package/exporter/commands/reset-render.ts +10 -1
- package/exporter/commands/start-render.ts +23 -44
- package/exporter/commands/upload-search-content.ts +194 -20
- package/exporter/constants/envs.ts +57 -55
- package/exporter/{errors/errors-data.ts → constants/errors.ts} +24 -14
- package/exporter/services/auth.ts +7 -6
- package/exporter/services/db-class.ts +54 -0
- package/exporter/services/db.ts +32 -0
- package/exporter/services/navigation.ts +4 -10
- package/exporter/services/reference-fields.ts +8 -23
- package/exporter/services/robots.ts +9 -16
- package/exporter/services/sites.ts +35 -24
- package/exporter/services/store.ts +120 -78
- package/exporter/types/api.ts +24 -27
- package/exporter/types/global.ts +7 -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/utils/artifacts.ts +34 -0
- package/exporter/utils/brush.ts +34 -0
- package/exporter/utils/cache.ts +37 -62
- package/exporter/utils/check-health.ts +79 -0
- package/exporter/utils/core-utils.ts +129 -248
- package/exporter/utils/domains.ts +10 -7
- package/exporter/{errors/index.ts → utils/errors.ts} +10 -9
- package/exporter/utils/folders.ts +187 -95
- package/exporter/utils/images.ts +1 -6
- package/exporter/utils/instance.ts +9 -12
- package/exporter/utils/loggin.ts +32 -91
- package/exporter/utils/pages.ts +23 -88
- package/exporter/utils/render.ts +149 -48
- package/exporter/utils/sites.ts +81 -90
- package/exporter/utils/store.ts +87 -180
- package/gatsby-browser.tsx +41 -58
- package/gatsby-config.ts +6 -12
- package/gatsby-node.ts +15 -77
- package/gatsby-ssr.tsx +2 -1
- package/package.json +36 -78
- 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/tsconfig.json +5 -3
- package/build/adapters/gatsby/index.d.ts +0 -4
- package/build/adapters/gatsby/utils.d.ts +0 -22
- package/build/artifacts/index.d.ts +0 -6
- package/build/commands/end-render.d.ts +0 -2
- package/build/commands/move-assets.d.ts +0 -1
- package/build/commands/prepare-domains-render.d.ts +0 -1
- package/build/commands/reset-render.d.ts +0 -2
- package/build/commands/start-render.d.ts +0 -2
- package/build/commands/upload-search-content.d.ts +0 -2
- package/build/constants/endpoints.d.ts +0 -19
- package/build/constants/envs.d.ts +0 -37
- package/build/constants/index.d.ts +0 -57
- package/build/end-render.js +0 -74
- package/build/end-render.js.map +0 -7
- package/build/errors/errors-data.d.ts +0 -22
- package/build/errors/index.d.ts +0 -15
- package/build/index.d.ts +0 -29
- package/build/index.js +0 -73
- package/build/index.js.map +0 -7
- package/build/prepare-domains-render.js +0 -73
- package/build/prepare-domains-render.js.map +0 -7
- package/build/react/Favicon/index.d.ts +0 -5
- package/build/react/Favicon/utils.d.ts +0 -9
- package/build/react/GriddoIntegrations/index.d.ts +0 -20
- package/build/react/GriddoIntegrations/utils.d.ts +0 -26
- package/build/react/index.js +0 -3
- package/build/registers/api.d.ts +0 -9
- package/build/registers/gatsby.d.ts +0 -9
- package/build/registers/index.d.ts +0 -3
- package/build/reset-render.js +0 -74
- package/build/reset-render.js.map +0 -7
- package/build/services/auth.d.ts +0 -10
- package/build/services/domains.d.ts +0 -6
- package/build/services/navigation.d.ts +0 -50
- package/build/services/reference-fields.d.ts +0 -20
- package/build/services/register.d.ts +0 -36
- package/build/services/robots.d.ts +0 -19
- package/build/services/settings.d.ts +0 -4
- package/build/services/sites.d.ts +0 -29
- package/build/services/store.d.ts +0 -6
- package/build/start-render.js +0 -100
- package/build/start-render.js.map +0 -7
- package/build/types/api.d.ts +0 -142
- package/build/types/global.d.ts +0 -84
- package/build/types/navigation.d.ts +0 -28
- package/build/types/pages.d.ts +0 -144
- package/build/types/sites.d.ts +0 -57
- package/build/types/templates.d.ts +0 -8
- package/build/upload-search-content.js +0 -74
- package/build/upload-search-content.js.map +0 -7
- package/build/utils/alerts.d.ts +0 -3
- package/build/utils/api.d.ts +0 -23
- package/build/utils/cache.d.ts +0 -35
- package/build/utils/core-utils.d.ts +0 -107
- package/build/utils/create-build-data.d.ts +0 -8
- package/build/utils/domains.d.ts +0 -13
- package/build/utils/folders.d.ts +0 -53
- package/build/utils/health-checks.d.ts +0 -7
- package/build/utils/images.d.ts +0 -16
- package/build/utils/instance.d.ts +0 -21
- package/build/utils/loggin.d.ts +0 -51
- package/build/utils/pages.d.ts +0 -34
- package/build/utils/render.d.ts +0 -13
- package/build/utils/searches.d.ts +0 -15
- package/build/utils/sites.d.ts +0 -31
- package/build/utils/store.d.ts +0 -81
- package/cx.config.d.ts +0 -5
- package/cx.config.js +0 -36
- package/exporter/adapters/gatsby/utils.ts +0 -161
- package/exporter/artifacts/README.md +0 -34
- package/exporter/artifacts/index.ts +0 -33
- package/exporter/commands/move-assets.ts +0 -11
- package/exporter/constants/index.ts +0 -129
- package/exporter/index.ts +0 -82
- package/exporter/react/index.tsx +0 -11
- package/exporter/registers/api.ts +0 -14
- package/exporter/registers/gatsby.ts +0 -14
- package/exporter/registers/index.ts +0 -4
- package/exporter/services/domains.ts +0 -16
- package/exporter/services/register.ts +0 -113
- package/exporter/services/settings.ts +0 -17
- package/exporter/utils/alerts.ts +0 -29
- package/exporter/utils/create-build-data.ts +0 -17
- package/exporter/utils/health-checks.ts +0 -64
- package/exporter/utils/searches.ts +0 -156
- package/src/README.md +0 -7
- package/start-render.js +0 -7
- /package/{exporter/react → react}/Favicon/utils.ts +0 -0
package/exporter/utils/sites.ts
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
import type { Site, SiteData } from "../types/sites";
|
|
2
2
|
|
|
3
|
+
import fsp from "node:fs/promises";
|
|
3
4
|
import path from "node:path";
|
|
4
5
|
|
|
5
|
-
import
|
|
6
|
-
import { parse } from "js2xmlparser";
|
|
6
|
+
import { create } from "xmlbuilder2";
|
|
7
7
|
|
|
8
|
-
import {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
import {
|
|
9
|
+
GRIDDO_API_URL,
|
|
10
|
+
GRIDDO_RENDER_ALL_SITES,
|
|
11
|
+
GRIDDO_RENDER_PAGES,
|
|
12
|
+
GRIDDO_RENDER_SITE,
|
|
13
|
+
} from "../constants/envs";
|
|
12
14
|
import { AuthService } from "../services/auth";
|
|
13
15
|
import {
|
|
14
16
|
endSiteRender,
|
|
@@ -19,31 +21,28 @@ import {
|
|
|
19
21
|
getSiteSocials,
|
|
20
22
|
startSiteRender,
|
|
21
23
|
} from "../services/sites";
|
|
22
|
-
|
|
23
|
-
|
|
24
|
+
import { pathExists } from "./folders";
|
|
25
|
+
import { verboseLog } from "./loggin";
|
|
26
|
+
import { getRenderMetadataFromDB, getRenderPathsFromDB } from "./render";
|
|
27
|
+
import { getBuildMetadata } from "./store";
|
|
24
28
|
|
|
25
29
|
/**
|
|
26
30
|
* Check the instance sites and returns site prepared to be published and unpublished.
|
|
27
31
|
*/
|
|
28
32
|
async function getSitesToRender(domain: string) {
|
|
29
|
-
console.info(`API URL ${
|
|
33
|
+
console.info(`API URL ${GRIDDO_API_URL as string}`);
|
|
30
34
|
|
|
31
35
|
// Login to API
|
|
32
|
-
await AuthService.login();
|
|
36
|
+
// await AuthService.login();
|
|
33
37
|
|
|
34
38
|
// Get all sites. An array of Site
|
|
35
39
|
const allSites = await getAllSites(domain);
|
|
36
40
|
|
|
37
41
|
// Filter the array of sites to get only the ones to build/render
|
|
38
|
-
const validSites =
|
|
39
|
-
? allSites.filter(
|
|
40
|
-
(site) =>
|
|
41
|
-
!envs.GRIDDO_RENDER_SITE || site.id === envs.GRIDDO_RENDER_SITE,
|
|
42
|
-
)
|
|
42
|
+
const validSites = GRIDDO_RENDER_ALL_SITES
|
|
43
|
+
? allSites.filter((site) => !GRIDDO_RENDER_SITE || site.id === GRIDDO_RENDER_SITE)
|
|
43
44
|
: allSites.filter((site) =>
|
|
44
|
-
|
|
45
|
-
? site.id === envs.GRIDDO_RENDER_SITE
|
|
46
|
-
: !!site.shouldBeUpdated,
|
|
45
|
+
GRIDDO_RENDER_SITE ? site.id === GRIDDO_RENDER_SITE : !!site.shouldBeUpdated,
|
|
47
46
|
);
|
|
48
47
|
|
|
49
48
|
// If there are valid sites...
|
|
@@ -58,8 +57,7 @@ async function getSitesToRender(domain: string) {
|
|
|
58
57
|
site.domains = items
|
|
59
58
|
.filter(
|
|
60
59
|
(item) =>
|
|
61
|
-
item.domain &&
|
|
62
|
-
(item.domain.slug === domain || item.domain.slug === `/${domain}`),
|
|
60
|
+
item.domain && (item.domain.slug === domain || item.domain.slug === `/${domain}`),
|
|
63
61
|
)
|
|
64
62
|
.map((item) => ({ [item.id]: `${item.domain.slug}${item.path}` }));
|
|
65
63
|
}
|
|
@@ -67,15 +65,11 @@ async function getSitesToRender(domain: string) {
|
|
|
67
65
|
|
|
68
66
|
// Save sites object to publish
|
|
69
67
|
const sitesToPublish = validSites.filter((site) =>
|
|
70
|
-
|
|
71
|
-
? site.id === envs.GRIDDO_RENDER_SITE
|
|
72
|
-
: !!site.isPublished,
|
|
68
|
+
GRIDDO_RENDER_SITE ? site.id === GRIDDO_RENDER_SITE : !!site.isPublished,
|
|
73
69
|
);
|
|
74
70
|
|
|
75
71
|
// Save sites object to unpublish
|
|
76
|
-
const sitesToUnpublish = validSites.filter(
|
|
77
|
-
(site) => !site.isPublished && site.shouldBeUpdated,
|
|
78
|
-
);
|
|
72
|
+
const sitesToUnpublish = validSites.filter((site) => !site.isPublished && site.shouldBeUpdated);
|
|
79
73
|
|
|
80
74
|
return {
|
|
81
75
|
sitesToPublish,
|
|
@@ -90,7 +84,7 @@ async function getSitesToRender(domain: string) {
|
|
|
90
84
|
* @see https://griddoio.notion.site/Sites-d7bb0b7cb8d24894a5337e1139fc3d09#2019d3255bda4d219c7e19cf28d0c4fe
|
|
91
85
|
*/
|
|
92
86
|
async function unpublishSites(sites: Array<Site>) {
|
|
93
|
-
const {
|
|
87
|
+
const { __root } = await getRenderPathsFromDB();
|
|
94
88
|
|
|
95
89
|
for (const site of sites) {
|
|
96
90
|
// API
|
|
@@ -107,7 +101,8 @@ async function unpublishSites(sites: Array<Site>) {
|
|
|
107
101
|
|
|
108
102
|
// STORE
|
|
109
103
|
// Remove site directory from the Store
|
|
110
|
-
|
|
104
|
+
// @todo: quitar. Como ya no hay persistenci de store, esto debería eliminarse de forma segura.
|
|
105
|
+
await fsp.rm(path.join(__root, "store", site.id.toString()), {
|
|
111
106
|
force: true,
|
|
112
107
|
recursive: true,
|
|
113
108
|
});
|
|
@@ -130,8 +125,8 @@ async function getSiteData(siteID: number) {
|
|
|
130
125
|
|
|
131
126
|
const { siteHash, unpublishHashes, publishIds } = buildData;
|
|
132
127
|
const { headers, footers } = siteInfo;
|
|
133
|
-
const validPagesIds =
|
|
134
|
-
?
|
|
128
|
+
const validPagesIds = GRIDDO_RENDER_PAGES.length
|
|
129
|
+
? GRIDDO_RENDER_PAGES.filter((item) => publishIds.includes(item))
|
|
135
130
|
: publishIds;
|
|
136
131
|
|
|
137
132
|
const siteData: SiteData = {
|
|
@@ -152,15 +147,13 @@ async function getSiteData(siteID: number) {
|
|
|
152
147
|
/**
|
|
153
148
|
* Save a file with the end of build process to use as `build-end` signal.
|
|
154
149
|
*/
|
|
155
|
-
async function generateBuildReport() {
|
|
156
|
-
const { __cx } = config.paths();
|
|
157
|
-
const { buildReportFileName } = config;
|
|
158
|
-
|
|
159
|
-
const { buildProcessData } = await getBuildMetadata();
|
|
160
|
-
|
|
161
|
-
// Get the token
|
|
150
|
+
async function generateBuildReport(domain: string) {
|
|
162
151
|
const authControl = await AuthService.login();
|
|
163
152
|
|
|
153
|
+
const { __root } = await getRenderPathsFromDB();
|
|
154
|
+
const { buildReportFileName } = await getRenderMetadataFromDB();
|
|
155
|
+
const { buildProcessData } = await getBuildMetadata(domain);
|
|
156
|
+
|
|
164
157
|
const buildSitesInfo = Object.keys(buildProcessData).map((siteID) => ({
|
|
165
158
|
...buildProcessData[siteID],
|
|
166
159
|
siteId: Number.parseInt(siteID),
|
|
@@ -171,52 +164,55 @@ async function generateBuildReport() {
|
|
|
171
164
|
sites: buildSitesInfo,
|
|
172
165
|
};
|
|
173
166
|
|
|
174
|
-
const reportFilePath = path.join(
|
|
175
|
-
fs.writeFileSync(reportFilePath, JSON.stringify(report));
|
|
167
|
+
const reportFilePath = path.join(__root, "dist", buildReportFileName);
|
|
176
168
|
|
|
177
|
-
|
|
169
|
+
await fsp.writeFile(reportFilePath, JSON.stringify(report));
|
|
178
170
|
|
|
179
|
-
|
|
171
|
+
verboseLog(`build report saved in ${reportFilePath}`);
|
|
180
172
|
}
|
|
181
173
|
|
|
182
174
|
/**
|
|
183
175
|
* Generate sitemaps and save them into file system.
|
|
184
176
|
*/
|
|
185
|
-
async function generateSitemaps() {
|
|
186
|
-
const {
|
|
187
|
-
const {
|
|
188
|
-
const distDir = path.join(
|
|
189
|
-
|
|
177
|
+
async function generateSitemaps(domain: string) {
|
|
178
|
+
const { __root } = await getRenderPathsFromDB();
|
|
179
|
+
const { sitesToPublish } = await getBuildMetadata(domain);
|
|
180
|
+
const distDir = path.join(__root, "dist");
|
|
190
181
|
const templateSitemapPrefix = "sitemap-";
|
|
191
182
|
|
|
192
183
|
const isGriddoSitemapFile = (file: string) =>
|
|
193
|
-
file === "sitemap.xml" ||
|
|
194
|
-
(file.startsWith(templateSitemapPrefix) && file.endsWith(".xml"));
|
|
184
|
+
file === "sitemap.xml" || (file.startsWith(templateSitemapPrefix) && file.endsWith(".xml"));
|
|
195
185
|
|
|
196
186
|
for (const site of sitesToPublish) {
|
|
197
187
|
const { id, languages } = site;
|
|
198
188
|
|
|
199
189
|
for (const lang of languages) {
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
190
|
+
// Local copy of headers to avoid mutating the shared object
|
|
191
|
+
const localHeaders: Record<string, string> = AuthService.headers
|
|
192
|
+
? { ...AuthService.headers }
|
|
193
|
+
: {};
|
|
194
|
+
localHeaders.lang = lang.id.toString();
|
|
203
195
|
|
|
204
|
-
const response = await getSitemap(id);
|
|
196
|
+
const response = await getSitemap({ siteId: id, headers: localHeaders });
|
|
205
197
|
|
|
206
|
-
if (!response)
|
|
198
|
+
if (!response) {
|
|
199
|
+
continue;
|
|
200
|
+
}
|
|
207
201
|
|
|
208
|
-
const {
|
|
209
|
-
|
|
210
|
-
url: { home, domain },
|
|
211
|
-
} = response;
|
|
202
|
+
const { items: sitemapPagesGroup, url } = response;
|
|
203
|
+
const { home, domain } = url;
|
|
212
204
|
|
|
213
|
-
if (!home)
|
|
205
|
+
if (!home) {
|
|
206
|
+
continue;
|
|
207
|
+
}
|
|
214
208
|
|
|
215
209
|
const domainLanguage = site.domains.find(
|
|
216
210
|
(domain) => Object.keys(domain)[0] === lang.id.toString(),
|
|
217
211
|
);
|
|
218
212
|
|
|
219
|
-
if (!domainLanguage)
|
|
213
|
+
if (!domainLanguage) {
|
|
214
|
+
continue;
|
|
215
|
+
}
|
|
220
216
|
|
|
221
217
|
const slug = Object.values(domainLanguage)[0];
|
|
222
218
|
const sitemaps: Array<string> = [];
|
|
@@ -224,16 +220,16 @@ async function generateSitemaps() {
|
|
|
224
220
|
const sitemapBasePath = path.join(distDir, slug.replace(domain, ""));
|
|
225
221
|
|
|
226
222
|
/** delete every griddo sitemap file before create the new ones */
|
|
227
|
-
if (
|
|
223
|
+
if (await pathExists(sitemapBasePath)) {
|
|
228
224
|
try {
|
|
229
|
-
const files =
|
|
225
|
+
const files = await fsp.readdir(sitemapBasePath);
|
|
230
226
|
for (const file of files) {
|
|
231
227
|
if (isGriddoSitemapFile(file)) {
|
|
232
228
|
const filePath = path.join(sitemapBasePath, file);
|
|
233
229
|
try {
|
|
234
|
-
|
|
230
|
+
await fsp.rm(filePath);
|
|
235
231
|
} catch (err) {
|
|
236
|
-
console.error(`Error
|
|
232
|
+
console.error(`Error deleting file ${filePath}:`, err);
|
|
237
233
|
}
|
|
238
234
|
}
|
|
239
235
|
}
|
|
@@ -245,40 +241,41 @@ async function generateSitemaps() {
|
|
|
245
241
|
for (const templateId of sitemapPageGroupKeys) {
|
|
246
242
|
const sitemapPages = sitemapPagesGroup[templateId];
|
|
247
243
|
|
|
248
|
-
if (!sitemapPages.length)
|
|
244
|
+
if (!sitemapPages.length) {
|
|
245
|
+
continue;
|
|
246
|
+
}
|
|
249
247
|
|
|
250
|
-
const siteMap =
|
|
251
|
-
"
|
|
248
|
+
const siteMap = create({ version: "1.0", encoding: "UTF-8" })
|
|
249
|
+
.ele("urlset", {
|
|
252
250
|
xmlns: "http://www.sitemaps.org/schemas/sitemap/0.9",
|
|
253
251
|
"xmlns:xsi": "http://www.w3.org/2001/XMLSchema-instance",
|
|
254
252
|
"xsi:schemaLocation":
|
|
255
|
-
"http://www.sitemaps.org/schemas/sitemap/0.9
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
253
|
+
"http://www.sitemaps.org/schemas/sitemap/0.9 " +
|
|
254
|
+
"http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd",
|
|
255
|
+
})
|
|
256
|
+
.ele(sitemapPages.map((page) => ({ url: page })))
|
|
257
|
+
.end({ prettyPrint: true });
|
|
259
258
|
|
|
260
259
|
const sitemapName = `/${templateSitemapPrefix}${templateId.toLowerCase()}.xml`;
|
|
261
260
|
const exactPath = path.join(sitemapBasePath, sitemapName);
|
|
262
261
|
|
|
263
|
-
saveFile(exactPath, siteMap);
|
|
262
|
+
await saveFile(exactPath, siteMap);
|
|
264
263
|
|
|
265
|
-
sitemaps.push(
|
|
266
|
-
`${home.endsWith("/") ? home.slice(0, -1) : home}${sitemapName}`,
|
|
267
|
-
);
|
|
264
|
+
sitemaps.push(`${home.endsWith("/") ? home.slice(0, -1) : home}${sitemapName}`);
|
|
268
265
|
}
|
|
269
266
|
|
|
270
267
|
if (!sitemaps.length) {
|
|
271
268
|
continue;
|
|
272
269
|
}
|
|
273
270
|
|
|
274
|
-
const siteMap =
|
|
275
|
-
"
|
|
276
|
-
|
|
277
|
-
|
|
271
|
+
const siteMap = create({ version: "1.0", encoding: "UTF-8" })
|
|
272
|
+
.ele("sitemapindex", { xmlns: "http://www.sitemaps.org/schemas/sitemap/0.9" })
|
|
273
|
+
.ele(sitemaps.map((loc) => ({ sitemap: { loc } })))
|
|
274
|
+
.end({ prettyPrint: true });
|
|
278
275
|
|
|
279
276
|
const exactPath = path.join(sitemapBasePath, "sitemap.xml");
|
|
280
277
|
|
|
281
|
-
saveFile(exactPath, siteMap);
|
|
278
|
+
await saveFile(exactPath, siteMap);
|
|
282
279
|
verboseLog(`sitemap generated in ${exactPath}`);
|
|
283
280
|
}
|
|
284
281
|
}
|
|
@@ -290,23 +287,17 @@ async function generateSitemaps() {
|
|
|
290
287
|
* @param filePath The path of the file to save the content to.
|
|
291
288
|
* @param content The content to save to the file.
|
|
292
289
|
*/
|
|
293
|
-
function saveFile(filePath: string, content: string) {
|
|
290
|
+
async function saveFile(filePath: string, content: string) {
|
|
294
291
|
try {
|
|
295
292
|
const pathName = path.dirname(filePath);
|
|
296
|
-
if (!
|
|
297
|
-
|
|
293
|
+
if (!(await pathExists(pathName))) {
|
|
294
|
+
await fsp.mkdir(pathName, { recursive: true });
|
|
298
295
|
}
|
|
299
|
-
|
|
296
|
+
await fsp.writeFile(filePath, content);
|
|
300
297
|
} catch (error) {
|
|
301
298
|
console.log(error);
|
|
302
299
|
throw new Error(`Error saving a file`);
|
|
303
300
|
}
|
|
304
301
|
}
|
|
305
302
|
|
|
306
|
-
export {
|
|
307
|
-
generateBuildReport,
|
|
308
|
-
generateSitemaps,
|
|
309
|
-
getSiteData,
|
|
310
|
-
getSitesToRender,
|
|
311
|
-
unpublishSites,
|
|
312
|
-
};
|
|
303
|
+
export { generateBuildReport, generateSitemaps, getSiteData, getSitesToRender, unpublishSites };
|
package/exporter/utils/store.ts
CHANGED
|
@@ -3,99 +3,27 @@ import type { RenderInfo } from "../types/global";
|
|
|
3
3
|
import type { GriddoPageObject } from "../types/pages";
|
|
4
4
|
import type { Site } from "../types/sites";
|
|
5
5
|
|
|
6
|
-
import
|
|
6
|
+
import fsp from "node:fs/promises";
|
|
7
7
|
import path from "node:path";
|
|
8
8
|
|
|
9
|
-
import
|
|
10
|
-
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
9
|
+
import { WriteToStoreError } from "../constants/errors";
|
|
10
|
+
import { readDB, writeDB } from "../services/db";
|
|
11
|
+
import { removeProperties } from "./core-utils";
|
|
12
|
+
import { throwError } from "./errors";
|
|
13
|
+
import { pathExists } from "./folders";
|
|
13
14
|
import { verboseLog } from "./loggin";
|
|
14
|
-
import {
|
|
15
|
-
|
|
16
|
-
const config = getConfig();
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Read all path pages stored in the `store` Griddo directory and returns the
|
|
20
|
-
* absolute file path.
|
|
21
|
-
*
|
|
22
|
-
* @param domain - The domain to get the pages from.
|
|
23
|
-
*/
|
|
24
|
-
function getBuildPagesFromCachedStore<PageType extends GriddoPageObject>(
|
|
25
|
-
domain: string,
|
|
26
|
-
) {
|
|
27
|
-
const { __cache } = config.paths(domain);
|
|
28
|
-
return getBuildPagesFromStore<PageType>({
|
|
29
|
-
basePath: path.join(__cache, "store"),
|
|
30
|
-
withSizeProp: false,
|
|
31
|
-
});
|
|
32
|
-
}
|
|
15
|
+
import { getRenderPathsFromDB } from "./render";
|
|
33
16
|
|
|
34
17
|
/**
|
|
35
|
-
*
|
|
36
|
-
* with a generator.
|
|
37
|
-
*
|
|
38
|
-
* @param basePath - Base directory to get pages from.
|
|
39
|
-
* @param options.withSizeProp - Add size prop to the page object.
|
|
40
|
-
* @todo throw error if the basePath is not an store folder
|
|
18
|
+
* Get the build metadata from the Store.
|
|
41
19
|
*/
|
|
42
|
-
function
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
}) {
|
|
46
|
-
const { basePath, withSizeProp } = args || {};
|
|
47
|
-
const { __cx } = config.paths();
|
|
48
|
-
const pagesDirPath = basePath || path.join(__cx, "store");
|
|
49
|
-
|
|
50
|
-
const jsonFilePaths = walkStore(pagesDirPath).filter(
|
|
51
|
-
(file) => path.extname(file) === ".json",
|
|
52
|
-
);
|
|
53
|
-
|
|
54
|
-
for (const filePath of jsonFilePaths) {
|
|
55
|
-
try {
|
|
56
|
-
const page = fsx.readJsonSync(filePath, {
|
|
57
|
-
encoding: "utf-8",
|
|
58
|
-
}) as PageType;
|
|
59
|
-
|
|
60
|
-
if (withSizeProp) {
|
|
61
|
-
const fileStats = fs.statSync(filePath);
|
|
62
|
-
page.size = fileStats.size / 1024;
|
|
63
|
-
}
|
|
20
|
+
async function getBuildMetadata(domain: string): Promise<BuildMetaData> {
|
|
21
|
+
const db = await readDB();
|
|
22
|
+
const { sitesToPublish, createdPages, buildProcessData } = db.domains[domain].renderInfo || {};
|
|
64
23
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
yield page;
|
|
68
|
-
}
|
|
69
|
-
} catch (error) {
|
|
70
|
-
throwError(ReadFromStoreError, error);
|
|
71
|
-
}
|
|
24
|
+
if (!sitesToPublish || !createdPages || !buildProcessData) {
|
|
25
|
+
throw new Error("Build metadata not found");
|
|
72
26
|
}
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* Read all pages stored in `store` Griddo directory and return the absolute
|
|
77
|
-
* path.
|
|
78
|
-
*/
|
|
79
|
-
function getBuildPagesPath() {
|
|
80
|
-
const config = getConfig();
|
|
81
|
-
const { __cx } = config.paths();
|
|
82
|
-
|
|
83
|
-
const PAGES_DIR = path.join(__cx, "store");
|
|
84
|
-
const PAGE_FILES = walk(PAGES_DIR).filter(
|
|
85
|
-
(file) => path.extname(file) === ".json",
|
|
86
|
-
);
|
|
87
|
-
|
|
88
|
-
return PAGE_FILES;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
* Get the build metadata from the Store.
|
|
93
|
-
*/
|
|
94
|
-
async function getBuildMetadata(): Promise<BuildMetaData> {
|
|
95
|
-
const { __cx } = config.paths();
|
|
96
|
-
const { sitesToPublish, createdPages, buildProcessData } = fsx.readJSONSync(
|
|
97
|
-
path.join(__cx, "render-metadata.json"),
|
|
98
|
-
);
|
|
99
27
|
|
|
100
28
|
return {
|
|
101
29
|
buildProcessData,
|
|
@@ -108,13 +36,11 @@ async function getBuildMetadata(): Promise<BuildMetaData> {
|
|
|
108
36
|
* Write render info into a file.
|
|
109
37
|
* @param renderInfo - Data that will be saved related to the render process.
|
|
110
38
|
*/
|
|
111
|
-
function saveRenderInfoInStore(renderInfo: RenderInfo) {
|
|
112
|
-
const
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
JSON.stringify(renderInfo),
|
|
117
|
-
);
|
|
39
|
+
async function saveRenderInfoInStore(renderInfo: RenderInfo, domain: string) {
|
|
40
|
+
const db = await readDB();
|
|
41
|
+
db.domains[domain] = db.domains[domain] || {};
|
|
42
|
+
db.domains[domain].renderInfo = renderInfo;
|
|
43
|
+
await writeDB(db);
|
|
118
44
|
}
|
|
119
45
|
|
|
120
46
|
/**
|
|
@@ -133,59 +59,49 @@ function saveRenderInfoInStore(renderInfo: RenderInfo) {
|
|
|
133
59
|
// }
|
|
134
60
|
|
|
135
61
|
/**
|
|
136
|
-
* Return an array of
|
|
62
|
+
* Return an array of paths only from `.json` files (no dirs) in the `basePath` dir based in the file name.
|
|
137
63
|
* @param basePath - Absolute path of the dir from which files will be read.
|
|
138
64
|
* @returns A Array<number> of pages ids in `basePath` dir.
|
|
139
65
|
*/
|
|
140
|
-
function getPageInStoreDir(basePath: string)
|
|
141
|
-
const filesInStore =
|
|
66
|
+
async function getPageInStoreDir(basePath: string) {
|
|
67
|
+
const filesInStore = await fsp.readdir(basePath);
|
|
68
|
+
|
|
69
|
+
return filesInStore
|
|
70
|
+
.filter(async (file) => {
|
|
71
|
+
const fullPathFile = `${basePath}/${file}`;
|
|
72
|
+
const stat = await fsp.stat(fullPathFile);
|
|
73
|
+
// Si es un directorio, no lo incluimos.
|
|
74
|
+
if (stat?.isDirectory()) {
|
|
75
|
+
return false;
|
|
76
|
+
}
|
|
142
77
|
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
const stat = fs.statSync(fullPathFile);
|
|
148
|
-
// Si es un directorio, no lo incluimos.
|
|
149
|
-
if (stat?.isDirectory()) {
|
|
150
|
-
return false;
|
|
151
|
-
}
|
|
152
|
-
// Si es un archivo pero no tiene la extensión `.json`, no lo incluimos
|
|
153
|
-
if (path.extname(file) !== ".json") {
|
|
154
|
-
return false;
|
|
155
|
-
}
|
|
156
|
-
// Si es un archivo con el nombre NO pasable a número (NaN), no lo incluimos.
|
|
157
|
-
const baseFilename = path.basename(file, path.extname(file));
|
|
158
|
-
if (Number.isNaN(Number.parseInt(baseFilename))) {
|
|
159
|
-
return false;
|
|
160
|
-
}
|
|
78
|
+
// Si es un archivo pero no tiene la extensión `.json`, no lo incluimos
|
|
79
|
+
if (path.extname(file) !== ".json") {
|
|
80
|
+
return false;
|
|
81
|
+
}
|
|
161
82
|
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
.
|
|
167
|
-
|
|
168
|
-
return Number.parseInt(filename);
|
|
169
|
-
})
|
|
170
|
-
);
|
|
83
|
+
// no es dir, es json.
|
|
84
|
+
return true;
|
|
85
|
+
})
|
|
86
|
+
.map((page) => {
|
|
87
|
+
return path.join(basePath, page);
|
|
88
|
+
});
|
|
171
89
|
}
|
|
172
90
|
|
|
173
91
|
/**
|
|
174
92
|
* Save the pages into the file system.
|
|
175
93
|
* @param pages - An array of Griddo page objects to be saved.
|
|
176
94
|
*/
|
|
177
|
-
function saveSitePagesInStore(
|
|
178
|
-
|
|
179
|
-
pages: Array<GriddoPageObject>,
|
|
180
|
-
) {
|
|
181
|
-
const { __cx } = config.paths();
|
|
95
|
+
async function saveSitePagesInStore(siteDirName: string, pages: Array<GriddoPageObject>) {
|
|
96
|
+
const { __root } = await getRenderPathsFromDB();
|
|
182
97
|
|
|
183
98
|
try {
|
|
184
99
|
for (const page of pages) {
|
|
185
100
|
removeProperties(page, ["editorID", "parentEditorID"]);
|
|
186
101
|
const filename = `${page.context.page.id}.json`;
|
|
187
|
-
const filePath = path.join(
|
|
188
|
-
|
|
102
|
+
const filePath = path.join(__root, "store", siteDirName, filename);
|
|
103
|
+
// En los listados estáticos y multipage los ids de las páginas son iguales
|
|
104
|
+
await writeUniqueFileSync(filePath, JSON.stringify(page));
|
|
189
105
|
}
|
|
190
106
|
} catch (error) {
|
|
191
107
|
throwError(WriteToStoreError, error);
|
|
@@ -203,23 +119,15 @@ function saveSitePagesInStore(
|
|
|
203
119
|
* @param siteDirName - The name of the site directory containing the pages.
|
|
204
120
|
* @param pageIdsArray - A two-dimensional array where each inner array contains numbers representing page files to be removed.
|
|
205
121
|
*/
|
|
206
|
-
function removeSitePagesFromStore(
|
|
207
|
-
|
|
208
|
-
pageIdsArray: Array<Array<number>>,
|
|
209
|
-
) {
|
|
210
|
-
const { __cx } = config.paths();
|
|
122
|
+
async function removeSitePagesFromStore(siteDirName: string, pageIdsArray: Array<Array<number>>) {
|
|
123
|
+
const { __root } = await getRenderPathsFromDB();
|
|
211
124
|
|
|
212
|
-
const processPageIdsArray = (pageIds: Array<number>) => {
|
|
125
|
+
const processPageIdsArray = async (pageIds: Array<number>) => {
|
|
213
126
|
for (const filename of pageIds) {
|
|
214
|
-
const filePath = path.join(
|
|
215
|
-
__cx,
|
|
216
|
-
"store",
|
|
217
|
-
siteDirName,
|
|
218
|
-
`${filename}.json`,
|
|
219
|
-
);
|
|
127
|
+
const filePath = path.join(__root, "store", siteDirName, `${filename}.json`);
|
|
220
128
|
try {
|
|
221
|
-
if (
|
|
222
|
-
|
|
129
|
+
if (await pathExists(filePath)) {
|
|
130
|
+
await fsp.unlink(filePath);
|
|
223
131
|
verboseLog(`Removed file: ${filePath}`);
|
|
224
132
|
}
|
|
225
133
|
} catch (error) {
|
|
@@ -230,7 +138,7 @@ function removeSitePagesFromStore(
|
|
|
230
138
|
};
|
|
231
139
|
|
|
232
140
|
for (const pageIds of pageIdsArray) {
|
|
233
|
-
processPageIdsArray(pageIds);
|
|
141
|
+
await processPageIdsArray(pageIds);
|
|
234
142
|
}
|
|
235
143
|
}
|
|
236
144
|
|
|
@@ -239,48 +147,33 @@ function removeSitePagesFromStore(
|
|
|
239
147
|
* the domain has been changed. This is necessary because those sites will not
|
|
240
148
|
* be marked as `sitesToUnpublish` so they must be removed manually.
|
|
241
149
|
*/
|
|
242
|
-
function removeOrphanSites(sitesToPublish: Array<Site>, domain: string) {
|
|
243
|
-
const {
|
|
244
|
-
const
|
|
150
|
+
async function removeOrphanSites(sitesToPublish: Array<Site>, domain: string) {
|
|
151
|
+
const { __root } = await getRenderPathsFromDB({ domain });
|
|
152
|
+
const storePath = path.join(__root, "store");
|
|
153
|
+
|
|
154
|
+
if (!(await pathExists(storePath))) {
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
const currentSitesInStore = await fsp.readdir(storePath);
|
|
245
159
|
const sitesFromAPI = sitesToPublish.map(({ id }) => `${id}`);
|
|
246
|
-
const sitesToDelete = currentSitesInStore.filter(
|
|
247
|
-
(site) => !sitesFromAPI.includes(site),
|
|
248
|
-
);
|
|
160
|
+
const sitesToDelete = currentSitesInStore.filter((site) => !sitesFromAPI.includes(site));
|
|
249
161
|
|
|
250
162
|
for (const site of sitesToDelete) {
|
|
251
|
-
|
|
163
|
+
await fsp.rm(path.join(storePath, site), { recursive: true, force: true });
|
|
252
164
|
verboseLog(`Removed orphan site id: ${site}`);
|
|
253
165
|
}
|
|
254
166
|
}
|
|
255
167
|
|
|
256
|
-
/**
|
|
257
|
-
* Returns the list of `activePages` pages that do not currently exist in a
|
|
258
|
-
* site's store (probably due to a failed render).
|
|
259
|
-
*/
|
|
260
|
-
function getMissingPublishedPagesInStore(
|
|
261
|
-
siteName: string,
|
|
262
|
-
activePages: Array<number>,
|
|
263
|
-
) {
|
|
264
|
-
const { __cx } = config.paths();
|
|
265
|
-
const pagesInStore = getPageInStoreDir(path.join(__cx, "store", siteName));
|
|
266
|
-
const missingActivePages: Array<number> = [];
|
|
267
|
-
for (const activePage of activePages) {
|
|
268
|
-
if (!pagesInStore.includes(activePage)) {
|
|
269
|
-
missingActivePages.push(activePage);
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
return missingActivePages;
|
|
273
|
-
}
|
|
274
|
-
|
|
275
168
|
/**
|
|
276
169
|
* Get pages that are not active anymore but are in the store.
|
|
277
170
|
*/
|
|
278
|
-
function getZombiePagesInStore(siteDir: string, activePages: Array<number>) {
|
|
279
|
-
const {
|
|
280
|
-
const storeDir = path.join(
|
|
281
|
-
const sitePages =
|
|
171
|
+
async function getZombiePagesInStore(siteDir: string, activePages: Array<number>) {
|
|
172
|
+
const { __root } = await getRenderPathsFromDB();
|
|
173
|
+
const storeDir = path.join(__root, "store", siteDir);
|
|
174
|
+
const sitePages = await fsp.readdir(storeDir);
|
|
282
175
|
|
|
283
|
-
|
|
176
|
+
const zombiePages: Array<number> = [];
|
|
284
177
|
for (const pageFileName of sitePages) {
|
|
285
178
|
const pageFileNameWithoutExtension = pageFileName.split(".")[0];
|
|
286
179
|
const pageInStore = Number.parseInt(pageFileNameWithoutExtension);
|
|
@@ -299,16 +192,30 @@ function getZombiePagesInStore(siteDir: string, activePages: Array<number>) {
|
|
|
299
192
|
return zombiePages;
|
|
300
193
|
}
|
|
301
194
|
|
|
195
|
+
async function writeUniqueFileSync(filePath: string, content: string) {
|
|
196
|
+
const dir = path.dirname(filePath);
|
|
197
|
+
const ext = path.extname(filePath);
|
|
198
|
+
const base = path.basename(filePath, ext);
|
|
199
|
+
|
|
200
|
+
let uniquePath = filePath;
|
|
201
|
+
let counter = 1;
|
|
202
|
+
|
|
203
|
+
while (await pathExists(uniquePath)) {
|
|
204
|
+
const newName = `${base}-${counter}${ext}`;
|
|
205
|
+
uniquePath = path.join(dir, newName);
|
|
206
|
+
counter++;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
await fsp.writeFile(uniquePath, content);
|
|
210
|
+
}
|
|
211
|
+
|
|
302
212
|
export {
|
|
303
213
|
getBuildMetadata,
|
|
304
|
-
getBuildPagesFromCachedStore,
|
|
305
|
-
getBuildPagesFromStore,
|
|
306
|
-
getBuildPagesPath,
|
|
307
|
-
getMissingPublishedPagesInStore,
|
|
308
214
|
getPageInStoreDir,
|
|
309
215
|
getZombiePagesInStore,
|
|
310
216
|
removeOrphanSites,
|
|
311
217
|
removeSitePagesFromStore,
|
|
312
|
-
saveSitePagesInStore,
|
|
313
218
|
saveRenderInfoInStore,
|
|
219
|
+
saveSitePagesInStore,
|
|
220
|
+
writeUniqueFileSync,
|
|
314
221
|
};
|