@griddo/cx 11.2.4 → 11.2.5-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/build/adapters/gatsby/index.d.ts +1 -1
- package/build/commands/prepare-domains-render.d.ts +1 -0
- package/build/commands/upload-search-content.d.ts +2 -0
- package/build/constants/envs.d.ts +2 -1
- package/build/end-render.js +25 -25
- package/build/end-render.js.map +4 -4
- package/build/index.d.ts +1 -2
- package/build/index.js +28 -51
- package/build/index.js.map +4 -4
- package/build/prepare-domains-render.js +73 -0
- package/build/prepare-domains-render.js.map +7 -0
- package/build/reset-render.js +21 -21
- package/build/reset-render.js.map +4 -4
- package/build/services/sites.d.ts +5 -1
- package/build/start-render.js +41 -38
- package/build/start-render.js.map +4 -4
- package/build/types/global.d.ts +5 -4
- package/build/types/sites.d.ts +7 -0
- package/build/upload-search-content.js +18 -18
- package/build/upload-search-content.js.map +4 -4
- package/build/utils/core-utils.d.ts +4 -8
- package/build/utils/create-build-data.d.ts +2 -2
- package/build/utils/domains.d.ts +9 -1
- package/build/utils/publish.d.ts +7 -0
- package/build/utils/render.d.ts +1 -1
- package/build/utils/sites.d.ts +2 -2
- package/build/utils/store.d.ts +28 -3
- package/exporter/adapters/gatsby/index.ts +124 -126
- package/exporter/build.sh +5 -5
- package/exporter/commands/end-render.ts +107 -0
- package/exporter/commands/prepare-domains-render.ts +89 -0
- package/exporter/commands/start-render.ts +68 -0
- package/exporter/{scripts → commands}/upload-search-content.ts +1 -1
- package/exporter/constants/envs.ts +4 -2
- package/exporter/constants/index.ts +1 -0
- package/exporter/index.ts +0 -2
- package/exporter/services/sites.ts +26 -0
- package/exporter/services/store.ts +33 -81
- package/exporter/types/global.ts +6 -2
- package/exporter/types/sites.ts +7 -0
- package/exporter/utils/core-utils.ts +5 -21
- package/exporter/utils/create-build-data.ts +2 -2
- package/exporter/utils/domains.ts +1 -1
- package/exporter/utils/folders.ts +2 -1
- package/exporter/utils/loggin.ts +7 -4
- package/exporter/utils/publish.ts +29 -0
- package/exporter/utils/render.ts +2 -1
- package/exporter/utils/sites.ts +12 -52
- package/exporter/utils/store.ts +88 -42
- package/package.json +7 -4
- package/start-render.js +1 -1
- package/build/run-start-render.js +0 -97
- package/build/run-start-render.js.map +0 -7
- package/build/scripts/end-render.d.ts +0 -20
- package/build/scripts/start-render.d.ts +0 -3
- package/exporter/scripts/end-render.ts +0 -102
- package/exporter/scripts/run-start-render.ts +0 -5
- package/exporter/scripts/start-render.ts +0 -25
- /package/build/{scripts/reset-render.d.ts → commands/end-render.d.ts} +0 -0
- /package/build/{scripts → commands}/move-assets.d.ts +0 -0
- /package/build/{scripts/run-start-render.d.ts → commands/reset-render.d.ts} +0 -0
- /package/build/{scripts/upload-search-content.d.ts → commands/start-render.d.ts} +0 -0
- /package/exporter/{scripts → commands}/move-assets.ts +0 -0
- /package/exporter/{scripts → commands}/reset-render.ts +0 -0
|
@@ -69,7 +69,7 @@ declare function sanitizeAPICacheDir(): void;
|
|
|
69
69
|
* @param functions - Functions to be executed to measure their execution time.
|
|
70
70
|
* @returns A promise that resolves with the total execution time in seconds.
|
|
71
71
|
*/
|
|
72
|
-
declare function measureExecutionTime(functions: Array<(...args: Array<unknown>) => unknown | Promise<unknown
|
|
72
|
+
declare function measureExecutionTime(functions: Array<(...args: Array<unknown>) => unknown | Promise<unknown>>): Promise<number>;
|
|
73
73
|
/**
|
|
74
74
|
* Pause the process until a key is pressed.
|
|
75
75
|
*
|
|
@@ -90,11 +90,7 @@ declare function pause(title: string): Promise<void> | undefined;
|
|
|
90
90
|
* @param options.bypass - Skip the step functions.
|
|
91
91
|
* @returns - A promise that resolves when the life cycle process is completed.
|
|
92
92
|
*/
|
|
93
|
-
declare function doLifeCycle(name: LifeCyclesNames,
|
|
94
|
-
steps: LifeCycleSteps;
|
|
95
|
-
delay?: number;
|
|
96
|
-
bypass?: boolean;
|
|
97
|
-
}): Promise<void>;
|
|
93
|
+
declare function doLifeCycle(name: LifeCyclesNames, steps: LifeCycleSteps): Promise<void>;
|
|
98
94
|
/**
|
|
99
95
|
* Creates additional files after the render: sitemaps, robots and a report of
|
|
100
96
|
* the finished render.
|
|
@@ -102,7 +98,7 @@ declare function doLifeCycle(name: LifeCyclesNames, options: {
|
|
|
102
98
|
* @async
|
|
103
99
|
* @param domain
|
|
104
100
|
*/
|
|
105
|
-
declare function
|
|
101
|
+
declare function createDomainMetadata(domain: string): Promise<void>;
|
|
106
102
|
declare function removeAllSiteDirsFromStore(): void;
|
|
107
103
|
/**
|
|
108
104
|
* Save render information to a file to use as debug log.
|
|
@@ -110,4 +106,4 @@ declare function removeAllSiteDirsFromStore(): void;
|
|
|
110
106
|
* This information will **not** be sent to any API.
|
|
111
107
|
*/
|
|
112
108
|
declare function saveBuildEndLogs(): void;
|
|
113
|
-
export {
|
|
109
|
+
export { createDomainMetadata, delay, doLifeCycle, getConfig, getSafeSiteId, instanceRootDir, isTruthy, measureExecutionTime, msToSec, pause, removeAllSiteDirsFromStore, removeProperties, sanitizeAPICacheDir, saveBuildEndLogs, walk, walkStore, };
|
|
@@ -4,5 +4,5 @@
|
|
|
4
4
|
* `getBuildMetadata()` to get build and sites metadata as objects. Both from
|
|
5
5
|
* exporter utils sites dir.
|
|
6
6
|
*/
|
|
7
|
-
declare function
|
|
8
|
-
export {
|
|
7
|
+
declare function createDomainRenderData(domain: string): Promise<void>;
|
|
8
|
+
export { createDomainRenderData };
|
package/build/utils/domains.d.ts
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
|
+
import type { Domains } from "../types/global";
|
|
1
2
|
/**
|
|
2
3
|
* Return an array of domains name (string) of the current instance.
|
|
3
4
|
*/
|
|
4
5
|
declare function getInstanceDomains(): Promise<string[]>;
|
|
5
|
-
|
|
6
|
+
/**
|
|
7
|
+
* Return an unique array of domains, filtered without "/".
|
|
8
|
+
*
|
|
9
|
+
* @param domains An array of domains
|
|
10
|
+
* @see Domains
|
|
11
|
+
*/
|
|
12
|
+
declare function getDomainSlugs(domains: Domains): string[];
|
|
13
|
+
export { getInstanceDomains, getDomainSlugs };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Spawn a new node process to upload the domain content.
|
|
3
|
+
* @note This proccess can not access to the custom Griddo `process.env` so it
|
|
4
|
+
* needs variables passed to it via the `env` prop
|
|
5
|
+
*/
|
|
6
|
+
declare function publishDomain(domain: string): string;
|
|
7
|
+
export { publishDomain };
|
package/build/utils/render.d.ts
CHANGED
|
@@ -12,4 +12,4 @@ declare function finishRender(): undefined;
|
|
|
12
12
|
* Send the default registers through Griddo alerts.
|
|
13
13
|
*/
|
|
14
14
|
declare function sendGriddoDefaultAlerts(): void;
|
|
15
|
-
export { createSentinelRenderFile, deleteSentinelRenderFile, finishRender, initRender, isValidRenderProcessOrThrow, sendGriddoDefaultAlerts
|
|
15
|
+
export { createSentinelRenderFile, deleteSentinelRenderFile, finishRender, initRender, isValidRenderProcessOrThrow, sendGriddoDefaultAlerts };
|
package/build/utils/sites.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import type { Site, SiteData } from "../types/sites";
|
|
|
2
2
|
/**
|
|
3
3
|
* Check the instance sites and returns site prepared to be published and unpublished.
|
|
4
4
|
*/
|
|
5
|
-
declare function
|
|
5
|
+
declare function getSitesToRender(domain: string): Promise<{
|
|
6
6
|
sitesToPublish: Site[];
|
|
7
7
|
sitesToUnpublish: Site[];
|
|
8
8
|
}>;
|
|
@@ -28,4 +28,4 @@ declare function generateBuildReport(): Promise<void>;
|
|
|
28
28
|
* Generate sitemaps and save them into file system.
|
|
29
29
|
*/
|
|
30
30
|
declare function generateSitemaps(): Promise<void>;
|
|
31
|
-
export {
|
|
31
|
+
export { generateBuildReport, generateSitemaps, getSiteData, getSitesToRender, unpublishSites, };
|
package/build/utils/store.d.ts
CHANGED
|
@@ -59,7 +59,7 @@ declare function savePagesInStore(siteFolderName: string, pages: Array<GriddoPag
|
|
|
59
59
|
* Remove files from dir.
|
|
60
60
|
* @param filenames - An array of ids representing file page names.
|
|
61
61
|
*/
|
|
62
|
-
declare function
|
|
62
|
+
declare function removeSitePagesFromStore(siteDirName: string, filenames: Array<number>): void;
|
|
63
63
|
/**
|
|
64
64
|
* Returns pages that need to be created or deleted for a site in the store based on the provided arguments.
|
|
65
65
|
* @param sitePages - Properties for page retrieval.
|
|
@@ -69,7 +69,7 @@ declare function removePagesFromStore(siteDirName: string, filenames: Array<numb
|
|
|
69
69
|
* @param props.changedPages - Array of pages that have been modified in the site.
|
|
70
70
|
* @returns - An object containing the pages to be created and deleted in the site.
|
|
71
71
|
*/
|
|
72
|
-
declare function
|
|
72
|
+
declare function getSitePagesToCreateOrDelete(sitePages: {
|
|
73
73
|
sitesToPublish: Array<Site>;
|
|
74
74
|
validPagesIds: Array<number>;
|
|
75
75
|
changedPages: Array<number>;
|
|
@@ -80,10 +80,35 @@ declare function getPagesToCreateOrDelete(sitePages: {
|
|
|
80
80
|
pagesToDeleteFromStore: number[];
|
|
81
81
|
pagesToWriteToStore: number[];
|
|
82
82
|
}>;
|
|
83
|
+
/**
|
|
84
|
+
* Returns pages that need to be created or deleted for a site in the store based on the provided arguments.
|
|
85
|
+
* @param sitePages - Properties for page retrieval.
|
|
86
|
+
* @param props.storeDir - Absolute path of the Griddo store.
|
|
87
|
+
* @param props.pages - Exhaustive array of all pages in the site.
|
|
88
|
+
* @param props.validPagesIds - Array of valid pages in the site.
|
|
89
|
+
* @param props.changedPages - Array of pages that have been modified in the site.
|
|
90
|
+
* @returns - An object containing the pages to be created and deleted in the site.
|
|
91
|
+
*/
|
|
92
|
+
declare function getSitePagesToCreateOrDeleteCached(sitePages: {
|
|
93
|
+
sitesToPublish: Array<Site>;
|
|
94
|
+
validPagesIds: Array<number>;
|
|
95
|
+
changedPages: Array<number>;
|
|
96
|
+
siteDirName: string;
|
|
97
|
+
domain: string;
|
|
98
|
+
}): Promise<{
|
|
99
|
+
pagesInStore: number[];
|
|
100
|
+
pagesMissingInStore: number[];
|
|
101
|
+
pagesToDeleteFromStore: number[];
|
|
102
|
+
pagesToWriteToStore: number[];
|
|
103
|
+
}>;
|
|
104
|
+
/**
|
|
105
|
+
* Removes sites from store that are not in `sitesToPublish` array.
|
|
106
|
+
*/
|
|
107
|
+
declare function deleteZombieSitesFoldersFromStore(sitesToPublish: Array<Site>): void;
|
|
83
108
|
/**
|
|
84
109
|
* Removes sites that exist in the store that should no longer be there because
|
|
85
110
|
* the domain has been changed. This is necessary because those sites will not
|
|
86
111
|
* be marked as `sitesToUnpublish` so they must be removed manually.
|
|
87
112
|
*/
|
|
88
113
|
declare function removeOrphanSites(sitesToPublish: Array<Site>, domain: string): void;
|
|
89
|
-
export { createStoreDir, getBuildMetadata, getBuildPagesFromCachedStore, getBuildPagesFromStore, getBuildPagesPath, getPageInStoreDir,
|
|
114
|
+
export { createStoreDir, deleteZombieSitesFoldersFromStore, getBuildMetadata, getBuildPagesFromCachedStore, getBuildPagesFromStore, getBuildPagesPath, getPageInStoreDir, getSitePagesToCreateOrDelete, getSitePagesToCreateOrDeleteCached, removeOrphanSites, removeSitePagesFromStore, savePagesInStore, saveRenderInfoInStore, };
|
|
@@ -12,14 +12,14 @@ import {
|
|
|
12
12
|
runGatsbyBuildCommand,
|
|
13
13
|
} from "./utils";
|
|
14
14
|
import getCxArtifacts from "../../artifacts";
|
|
15
|
+
import { AuthService } from "../../services/auth";
|
|
15
16
|
import {
|
|
16
|
-
|
|
17
|
+
createDomainMetadata,
|
|
17
18
|
doLifeCycle,
|
|
18
19
|
getConfig,
|
|
19
20
|
saveBuildEndLogs,
|
|
20
21
|
} from "../../utils/core-utils";
|
|
21
|
-
import {
|
|
22
|
-
import { getInstanceDomains } from "../../utils/domains";
|
|
22
|
+
import { createDomainRenderData } from "../../utils/create-build-data";
|
|
23
23
|
import {
|
|
24
24
|
clearEmptyDirs,
|
|
25
25
|
copyArtifacts,
|
|
@@ -36,132 +36,130 @@ import {
|
|
|
36
36
|
isValidRenderProcessOrThrow,
|
|
37
37
|
} from "../../utils/render";
|
|
38
38
|
|
|
39
|
-
const config = getConfig();
|
|
40
|
-
|
|
41
39
|
/**
|
|
42
40
|
* Render every instance domain with the Gatsby adapter.
|
|
43
41
|
*/
|
|
44
|
-
export async function renderDomainsWithGatsbyAdapter() {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
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"> = {
|
|
62
|
+
disposables: [
|
|
63
|
+
path.join(__ssg, "public"),
|
|
64
|
+
path.join(__ssg, "static"),
|
|
65
|
+
path.join(__ssg, ".cache"),
|
|
66
|
+
],
|
|
67
|
+
cacheables: [".cache"],
|
|
68
|
+
};
|
|
69
|
+
|
|
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 !== "";
|
|
74
|
+
|
|
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
|
+
},
|
|
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
|
+
() => clearEmptyDirs(path.join(__cx, "dist")),
|
|
139
|
+
() =>
|
|
140
|
+
moveArtifacts(__cx, __exports, cxArtifacts.archivables, {
|
|
141
|
+
withBackup: true,
|
|
142
|
+
}),
|
|
143
|
+
() => moveArtifacts(__cx, __cache, cxArtifacts.cacheables),
|
|
144
|
+
() => moveArtifacts(__ssg, __cache, gatsbyArtifacts.cacheables),
|
|
70
145
|
],
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
name: LifeCyclesNames;
|
|
90
|
-
steps: LifeCycleSteps;
|
|
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: [() => createBuildData(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: [() => createRenderMetadata(domain), () => saveBuildEndLogs()],
|
|
132
|
-
},
|
|
133
|
-
|
|
134
|
-
{
|
|
135
|
-
name: "Archive",
|
|
136
|
-
steps: [
|
|
137
|
-
() => removeVirtualPagesFromStore(),
|
|
138
|
-
() => clearEmptyDirs(path.join(__cx, "dist")),
|
|
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: [() => isValidRenderProcessOrThrow()],
|
|
156
|
-
},
|
|
157
|
-
];
|
|
158
|
-
|
|
159
|
-
for (const { name, steps } of allLifeCycles) {
|
|
160
|
-
await doLifeCycle(name, {
|
|
161
|
-
steps: steps,
|
|
162
|
-
});
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
deleteSentinelRenderFile();
|
|
146
|
+
},
|
|
147
|
+
|
|
148
|
+
{
|
|
149
|
+
name: "Clean",
|
|
150
|
+
steps: [() => removeArtifacts(disposableArtifacts)],
|
|
151
|
+
},
|
|
152
|
+
|
|
153
|
+
{
|
|
154
|
+
name: "HealthCheck",
|
|
155
|
+
steps: [
|
|
156
|
+
() => isValidRenderProcessOrThrow(),
|
|
157
|
+
() => deleteSentinelRenderFile(),
|
|
158
|
+
],
|
|
159
|
+
},
|
|
160
|
+
];
|
|
161
|
+
|
|
162
|
+
for (const { name, steps } of allLifeCycles) {
|
|
163
|
+
await doLifeCycle(name, steps);
|
|
166
164
|
}
|
|
167
165
|
}
|
package/exporter/build.sh
CHANGED
|
@@ -29,11 +29,11 @@ esbuild ${log} ./exporter/index.ts ${bundle_node_opts} --outfile=./build/index.j
|
|
|
29
29
|
esbuild ${log} ./exporter/react/index.tsx ${react_opts} --outfile=./build/react/index.js
|
|
30
30
|
|
|
31
31
|
# scripts
|
|
32
|
-
esbuild ${log} ./exporter/
|
|
33
|
-
esbuild ${log} ./exporter/
|
|
34
|
-
esbuild ${log} ./exporter/
|
|
35
|
-
esbuild ${log} ./exporter/
|
|
36
|
-
esbuild ${log} ./exporter/
|
|
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
37
|
|
|
38
38
|
# types
|
|
39
39
|
tsc --emitDeclarationOnly --declaration --outDir build --project tsconfig.exporter.json
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import fs from "node:fs";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
|
|
6
|
+
import pkgDir from "pkg-dir";
|
|
7
|
+
|
|
8
|
+
import { AuthService } from "../services/auth";
|
|
9
|
+
import { endSiteRender } from "../services/sites";
|
|
10
|
+
import { getConfig } from "../utils/core-utils";
|
|
11
|
+
import { getInstanceDomains } from "../utils/domains";
|
|
12
|
+
import { infoLog } from "../utils/loggin";
|
|
13
|
+
|
|
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 getExportedDomains() {
|
|
40
|
+
// const domains = fs
|
|
41
|
+
// .readdirSync(exportArchiveBasePath)
|
|
42
|
+
// // Avoid empty files, usually .DS_Store from local renders.
|
|
43
|
+
// .filter((file) => !file.startsWith("."));
|
|
44
|
+
|
|
45
|
+
// return domains;
|
|
46
|
+
// }
|
|
47
|
+
|
|
48
|
+
function getDomainRenderReport(domain: string) {
|
|
49
|
+
const reports: Array<Report> = [];
|
|
50
|
+
const { buildReportFileName } = getConfig();
|
|
51
|
+
|
|
52
|
+
const buildReportFile = path.resolve(
|
|
53
|
+
exportArchiveBasePath,
|
|
54
|
+
domain,
|
|
55
|
+
"dist",
|
|
56
|
+
buildReportFileName,
|
|
57
|
+
);
|
|
58
|
+
|
|
59
|
+
if (!fs.existsSync(buildReportFile)) {
|
|
60
|
+
console.info(`Build report file "${buildReportFile}" not found.`);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const buildReport = JSON.parse(fs.readFileSync(buildReportFile, "utf-8"));
|
|
64
|
+
|
|
65
|
+
reports.push(buildReport);
|
|
66
|
+
|
|
67
|
+
return reports;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
(async () => {
|
|
71
|
+
const sendEndSiteRender = async (reports: Array<Report>) => {
|
|
72
|
+
for (const report of reports) {
|
|
73
|
+
const sites = report.sites;
|
|
74
|
+
|
|
75
|
+
for (const site of sites) {
|
|
76
|
+
const { siteId, ...body } = site;
|
|
77
|
+
|
|
78
|
+
console.info(`Site (${siteId})`);
|
|
79
|
+
|
|
80
|
+
await endSiteRender(siteId, body);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
if (RENDER_BY_DOMAIN) {
|
|
86
|
+
await AuthService.login();
|
|
87
|
+
const domain = process.argv.splice(2)[0];
|
|
88
|
+
const reports = getDomainRenderReport(domain);
|
|
89
|
+
|
|
90
|
+
infoLog(`Sending ending call to ${domain} sites`);
|
|
91
|
+
|
|
92
|
+
sendEndSiteRender(reports);
|
|
93
|
+
} else {
|
|
94
|
+
// Legacy render
|
|
95
|
+
const domains = await getInstanceDomains();
|
|
96
|
+
for (const domain of domains) {
|
|
97
|
+
const reports = getDomainRenderReport(domain);
|
|
98
|
+
|
|
99
|
+
infoLog(`Sending ending call to ${domain} sites`);
|
|
100
|
+
|
|
101
|
+
sendEndSiteRender(reports);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
})().catch((err) => {
|
|
105
|
+
console.error("Error", err?.stdout?.toString() || err);
|
|
106
|
+
process.exit(1);
|
|
107
|
+
});
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
|
|
4
|
+
import { getConfig } from "../utils/core-utils";
|
|
5
|
+
import { getInstanceDomains } from "../utils/domains";
|
|
6
|
+
import { infoLog, successLog } from "../utils/loggin";
|
|
7
|
+
import { getSitesToRender } from "../utils/sites";
|
|
8
|
+
|
|
9
|
+
const { GRIDDO_EXPERIMENTAL_DOMAIN_RENDERING_ORDER } = process.env;
|
|
10
|
+
|
|
11
|
+
(async () => {
|
|
12
|
+
infoLog("Checking domains size");
|
|
13
|
+
|
|
14
|
+
const { __cx } = getConfig().paths();
|
|
15
|
+
|
|
16
|
+
// Get domains and calculate order
|
|
17
|
+
const domains = await getInstanceDomains();
|
|
18
|
+
const domainsInfo = [];
|
|
19
|
+
const domainsFilePath = path.join(__cx, "domains.json");
|
|
20
|
+
|
|
21
|
+
// Domains order from .env file
|
|
22
|
+
if (GRIDDO_EXPERIMENTAL_DOMAIN_RENDERING_ORDER) {
|
|
23
|
+
const domainsOrderArray: Array<string> = JSON.parse(
|
|
24
|
+
GRIDDO_EXPERIMENTAL_DOMAIN_RENDERING_ORDER,
|
|
25
|
+
);
|
|
26
|
+
const validDomains = domainsOrderArray.every((domain) =>
|
|
27
|
+
domains.includes(domain),
|
|
28
|
+
);
|
|
29
|
+
if (validDomains) {
|
|
30
|
+
fs.writeFileSync(domainsFilePath, JSON.stringify(domainsOrderArray));
|
|
31
|
+
successLog(`Checking domains size`);
|
|
32
|
+
return;
|
|
33
|
+
} else {
|
|
34
|
+
console.log("Domains in .env are not valid, using the API");
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
for (const domain of domains) {
|
|
39
|
+
const { sitesToPublish, sitesToUnpublish } = await getSitesToRender(domain);
|
|
40
|
+
|
|
41
|
+
if (process.env.GRIDDO_EXPERIMENTAL_SKIP_EMPTY_DOMAINS) {
|
|
42
|
+
if (sitesToPublish.length === 0 && sitesToUnpublish.length === 0) {
|
|
43
|
+
infoLog(`Skipping rendering domain ${domain}`);
|
|
44
|
+
|
|
45
|
+
// Delete assets/* y dist/*
|
|
46
|
+
// vanishDomainAssets(domain);
|
|
47
|
+
continue;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// Only count pages (changedPages) if sitesToPublish is not empty.
|
|
52
|
+
// Otherwise we set the domain has having 0 pages.
|
|
53
|
+
const pages = [];
|
|
54
|
+
if (sitesToPublish.length > 0) {
|
|
55
|
+
for (const site of sitesToPublish) {
|
|
56
|
+
pages.push(site.changedPages.length);
|
|
57
|
+
}
|
|
58
|
+
} else {
|
|
59
|
+
pages.push(0);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// eslint-disable-next-line no-array-reduce/no-reduce
|
|
63
|
+
const totalPages = pages.reduce((a, b) => a + b);
|
|
64
|
+
domainsInfo.push({ domain, totalPages });
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
console.log(domainsInfo);
|
|
68
|
+
// sort domains, smaller first
|
|
69
|
+
domainsInfo.sort((a, b) => a.totalPages - b.totalPages);
|
|
70
|
+
const domainSorted = domainsInfo.map(({ domain }) => domain);
|
|
71
|
+
|
|
72
|
+
fs.writeFileSync(domainsFilePath, JSON.stringify(domainSorted));
|
|
73
|
+
|
|
74
|
+
successLog(`Checking domains size`);
|
|
75
|
+
})().catch((err) => {
|
|
76
|
+
console.error(err);
|
|
77
|
+
process.exit(1);
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
// function vanishDomainAssets(domain: string) {
|
|
81
|
+
// const { __exports } = getConfig().paths(domain);
|
|
82
|
+
|
|
83
|
+
// if (fs.existsSync(__exports)) {
|
|
84
|
+
// fs.rmSync(__exports, { recursive: true, force: true });
|
|
85
|
+
// }
|
|
86
|
+
|
|
87
|
+
// fs.mkdirSync(path.join(__exports, "dist"), { recursive: true });
|
|
88
|
+
// fs.mkdirSync(path.join(__exports, "assets"), { recursive: true });
|
|
89
|
+
// }
|