@griddo/cx 10.4.19 → 10.4.21
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 +11 -76
- package/build/adapters/gatsby/index.d.ts +2 -0
- package/build/adapters/gatsby/utils.d.ts +27 -0
- package/build/adapters/index.d.ts +3 -0
- package/build/browser/index.d.ts +5 -0
- package/build/build-complete.d.ts +18 -0
- package/build/build-complete.js +22 -22
- package/build/errors/index.d.ts +1 -0
- package/build/index.d.ts +29 -0
- package/build/index.js +37 -35
- package/build/move-assets.d.ts +1 -0
- package/build/react/index.d.ts +2 -0
- package/build/reset-render.d.ts +1 -0
- package/build/reset-render.js +22 -22
- package/build/run-start-render.d.ts +1 -0
- package/build/run-start-render.js +37 -35
- package/build/services/auth.d.ts +21 -0
- package/build/services/distributors.d.ts +45 -0
- package/build/services/domains.d.ts +8 -0
- package/build/services/navigation.d.ts +77 -0
- package/build/services/robots.d.ts +21 -0
- package/build/services/settings.d.ts +23 -0
- package/build/services/sites.d.ts +42 -0
- package/build/services/store.d.ts +6 -0
- package/build/start-render.d.ts +3 -0
- package/build/start-render.js +37 -35
- package/build/types/api.d.ts +130 -0
- package/build/types/global.d.ts +78 -0
- package/build/types/navigation.d.ts +28 -0
- package/build/types/pages.d.ts +128 -0
- package/build/types/sites.d.ts +43 -0
- package/build/types/templates.d.ts +8 -0
- package/build/upload-search-content.d.ts +1 -0
- package/build/upload-search-content.js +21 -21
- package/build/utils/api.d.ts +23 -0
- package/build/utils/cache.d.ts +35 -0
- package/build/utils/create-build-data.d.ts +8 -0
- package/build/utils/domains.d.ts +5 -0
- package/build/utils/folders.d.ts +48 -0
- package/build/utils/health-checks.d.ts +7 -0
- package/build/utils/instance.d.ts +21 -0
- package/build/utils/messages.d.ts +2 -0
- package/build/utils/pages.d.ts +34 -0
- package/build/utils/searches.d.ts +14 -0
- package/build/utils/shared.d.ts +110 -0
- package/build/utils/sites.d.ts +36 -0
- package/build/utils/store.d.ts +79 -0
- package/build/utils/temp-utils.d.ts +10 -0
- package/cx.config.js +1 -1
- package/exporter/adapters/gatsby/index.ts +6 -20
- package/exporter/adapters/gatsby/utils.ts +25 -1
- package/exporter/errors/index.ts +2 -0
- package/exporter/index.ts +6 -4
- package/exporter/services/robots.ts +4 -3
- package/exporter/services/store.ts +13 -4
- package/exporter/start-render.ts +1 -2
- package/exporter/types/global.ts +1 -1
- package/exporter/utils/cache.ts +25 -11
- package/exporter/utils/create-build-data.ts +3 -10
- package/exporter/utils/folders.ts +14 -15
- package/exporter/utils/searches.ts +4 -4
- package/exporter/utils/shared.ts +18 -8
- package/exporter/utils/sites.ts +10 -10
- package/exporter/utils/store.ts +77 -27
- package/exporter/utils/temp-utils.ts +12 -11
- package/gatsby-config.ts +2 -2
- package/gatsby-node.ts +9 -10
- package/package.json +12 -6
- package/src/components/Head.tsx +1 -1
- package/src/components/template.tsx +1 -1
- package/src/gatsby-node-utils.ts +13 -2
- package/src/types.ts +1 -1
- package/tsconfig.json +13 -3
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { APIResponses, GetAPI, PostAPI, PutAPI } from "../types/api";
|
|
2
|
+
/**
|
|
3
|
+
* Make a GET request to the Griddo API.
|
|
4
|
+
*
|
|
5
|
+
* @template T Response Type returned.
|
|
6
|
+
* @returns A promise that is resolved with the data from the API response.
|
|
7
|
+
*/
|
|
8
|
+
declare function getApi<T extends APIResponses>(props: GetAPI): Promise<T>;
|
|
9
|
+
/**
|
|
10
|
+
* Make a PUT request to the Griddo API.
|
|
11
|
+
*
|
|
12
|
+
* @template T Response Type returned.
|
|
13
|
+
* @returns A promise that is resolved with the data from the API response.
|
|
14
|
+
*/
|
|
15
|
+
declare function putApi<T extends APIResponses>(props: PutAPI): Promise<T>;
|
|
16
|
+
/**
|
|
17
|
+
* Make a POST request to the Griddo API.
|
|
18
|
+
*
|
|
19
|
+
* @template T Response Type returned.
|
|
20
|
+
* @returns A promise that is resolved with the data from the API response.
|
|
21
|
+
*/
|
|
22
|
+
declare function postApi<T extends APIResponses>(props: PostAPI): Promise<T>;
|
|
23
|
+
export { getApi as get, postApi as post, putApi as put };
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { Petition } from "../types/global";
|
|
2
|
+
import type { SiteHash } from "../types/sites";
|
|
3
|
+
/**
|
|
4
|
+
* Creates an `apiCache` dir to store pages fetched from them API.
|
|
5
|
+
*/
|
|
6
|
+
declare function createAPICacheDir(): void;
|
|
7
|
+
/**
|
|
8
|
+
* Generate a filename with a hash using a string.
|
|
9
|
+
*
|
|
10
|
+
* @todo Merge with generateFilenameWithHash
|
|
11
|
+
* @param data A string to create a sha256 based on.
|
|
12
|
+
*/
|
|
13
|
+
declare function createSha256(data: string): string;
|
|
14
|
+
/**
|
|
15
|
+
* Save a file using a hash name.
|
|
16
|
+
*
|
|
17
|
+
* @param petition An object.
|
|
18
|
+
* @param content Content to be saved.
|
|
19
|
+
*/
|
|
20
|
+
declare function saveCache<T>(petition: Petition, content: T): void;
|
|
21
|
+
/**
|
|
22
|
+
* Search in the `apiCache` dir for a file using the petition as hash generator.
|
|
23
|
+
* Return the file content if found or null if not.
|
|
24
|
+
*
|
|
25
|
+
* @param petition An object
|
|
26
|
+
*/
|
|
27
|
+
declare function searchCacheData<T>(petition: Petition): T | null;
|
|
28
|
+
/**
|
|
29
|
+
* Update (write) the site hash file.
|
|
30
|
+
*
|
|
31
|
+
* @param siteId The id of the site.
|
|
32
|
+
* @param siteHash The has of the site.
|
|
33
|
+
*/
|
|
34
|
+
declare function updatedSiteHash(siteId: number, siteHash: SiteHash): string;
|
|
35
|
+
export { createAPICacheDir, createSha256, saveCache, searchCacheData, updatedSiteHash, };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Download all data: sites, pages etc.. from the instance private Griddo API.
|
|
3
|
+
* Then you can use the generator funcion `getBuildPagesFromStore()` to get the pages and
|
|
4
|
+
* `getBuildMetadata()` to get build and sites metadata as objects. Both from
|
|
5
|
+
* exporter utils sites dir.
|
|
6
|
+
*/
|
|
7
|
+
declare function createBuildData(domain: string): Promise<void>;
|
|
8
|
+
export { createBuildData };
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { MakeDirectoryOptions } from "fs-extra";
|
|
3
|
+
/**
|
|
4
|
+
* Remove an empty directory from the basePath recursively.
|
|
5
|
+
* If the directory has only .xml files it will handle as empty too (empty site)
|
|
6
|
+
*
|
|
7
|
+
* @param baseDir - The base directory.
|
|
8
|
+
*/
|
|
9
|
+
declare const clearEmptyDirs: (baseDir: string) => void;
|
|
10
|
+
/**
|
|
11
|
+
* Creates multiple directories.
|
|
12
|
+
*
|
|
13
|
+
* @param dirs - An array of directory paths.
|
|
14
|
+
* @param options - Same option as `fs.mkdirSync()`
|
|
15
|
+
*/
|
|
16
|
+
declare function createDirsSync(dirs: Array<string>, options?: MakeDirectoryOptions): void;
|
|
17
|
+
/**
|
|
18
|
+
* Copy multiple directories with backup option.
|
|
19
|
+
*
|
|
20
|
+
* @param src - Source directory.
|
|
21
|
+
* @param dst - Destination directory.
|
|
22
|
+
* @param dirs - Directories to copy.
|
|
23
|
+
* @param options.withBackup - Create a previous backup before copy.
|
|
24
|
+
*/
|
|
25
|
+
declare function copyDirsSync(src: string, dst: string, dirs: Array<string>, options?: {
|
|
26
|
+
withBackup: boolean;
|
|
27
|
+
}): void;
|
|
28
|
+
/**
|
|
29
|
+
* Move artifacts between CX valid directories.
|
|
30
|
+
*
|
|
31
|
+
* @param src - Source directory.
|
|
32
|
+
* @param dst - Destination directory.
|
|
33
|
+
* @param dirs - Directories to move.
|
|
34
|
+
* @param options - Options.
|
|
35
|
+
*/
|
|
36
|
+
declare function moveDirsSync(src: string, dst: string, dirs: Array<string>, options?: {
|
|
37
|
+
withBackup?: boolean;
|
|
38
|
+
override?: boolean;
|
|
39
|
+
}): void;
|
|
40
|
+
/**
|
|
41
|
+
* Remove directories from `basePath` directory.
|
|
42
|
+
*
|
|
43
|
+
* @param basePath - Base directory.
|
|
44
|
+
* @param dirs - Directory to remove.
|
|
45
|
+
*/
|
|
46
|
+
declare function removeDirsSync(basePath: string, dirs: Array<string>): void;
|
|
47
|
+
declare function removeVirtualPagesFromStore(): Promise<void>;
|
|
48
|
+
export { clearEmptyDirs, copyDirsSync, createDirsSync, moveDirsSync, removeDirsSync, removeVirtualPagesFromStore, };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Check if the environment is secure to launch a render.
|
|
3
|
+
* If something fails then log an error message and exit from the process.
|
|
4
|
+
* Otherwise just return true.
|
|
5
|
+
*/
|
|
6
|
+
declare function checkRenderHealthOrExit(): boolean;
|
|
7
|
+
export { checkRenderHealthOrExit };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
declare const IS_COMPONENT_LIBRARY: boolean;
|
|
2
|
+
declare const PROJECT_ALIASES: {
|
|
3
|
+
"@griddo-instance": string;
|
|
4
|
+
};
|
|
5
|
+
/**
|
|
6
|
+
* Returns the instance or monorepo paths.
|
|
7
|
+
*
|
|
8
|
+
* @param customPath The path for the instance components
|
|
9
|
+
*/
|
|
10
|
+
declare function resolveComponentsPath(customPath?: string): string;
|
|
11
|
+
/**
|
|
12
|
+
* Return the instance or monorepo components {t|j}sconfig.json file.
|
|
13
|
+
*/
|
|
14
|
+
declare function getComponentsJSConfig(): string | undefined;
|
|
15
|
+
/**
|
|
16
|
+
* Get the instance webpack aliases
|
|
17
|
+
*/
|
|
18
|
+
declare function getComponentsLibAliases(): {
|
|
19
|
+
"@griddo-instance": string;
|
|
20
|
+
};
|
|
21
|
+
export { IS_COMPONENT_LIBRARY, PROJECT_ALIASES, getComponentsJSConfig, getComponentsLibAliases, resolveComponentsPath, };
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { GriddoListPage, GriddoMultiPage, GriddoPageObject, GriddoSinglePage, MultiPageElements, PageAdditionalInfo } from "../types/pages";
|
|
2
|
+
import type { TemplateWithDistributor } from "../types/templates";
|
|
3
|
+
import type { Fields } from "@griddo/core";
|
|
4
|
+
/**
|
|
5
|
+
* Create a single Griddo page object.
|
|
6
|
+
*
|
|
7
|
+
* @param page A Griddo single page object.
|
|
8
|
+
* @param additionalInfo Additional page info.
|
|
9
|
+
*/
|
|
10
|
+
declare function createGriddoSinglePage(page: GriddoSinglePage, additionalInfo: PageAdditionalInfo): Promise<GriddoPageObject>;
|
|
11
|
+
/**
|
|
12
|
+
* Create multiples pages from one page as list paginated pages
|
|
13
|
+
*/
|
|
14
|
+
declare function createGriddoListPages({ page, pages, isRoot, defaultLang, template, totalQueriedItems, }: GriddoListPage, additionalInfo: PageAdditionalInfo): Promise<GriddoPageObject[]>;
|
|
15
|
+
/**
|
|
16
|
+
* Create multiples pages from a MultiPage module
|
|
17
|
+
*
|
|
18
|
+
* @param page A Griddo Multipage object.
|
|
19
|
+
* @param additionalInfo Additional page info.
|
|
20
|
+
*/
|
|
21
|
+
declare function createGriddoMultiPages(page: GriddoMultiPage, additionalInfo: PageAdditionalInfo): Promise<GriddoPageObject[]>;
|
|
22
|
+
/**
|
|
23
|
+
* Get the multi pages elements.
|
|
24
|
+
*
|
|
25
|
+
* @param page The page to get the multipage parts.
|
|
26
|
+
*/
|
|
27
|
+
declare function getMultiPageElements(page: TemplateWithDistributor): Promise<MultiPageElements> | null;
|
|
28
|
+
/**
|
|
29
|
+
* Takes a template object and split the whole queriedItems into separated queriedItems to use in Griddo static list templates.
|
|
30
|
+
*
|
|
31
|
+
* @param listTemplate A template schema with the distributor data included.
|
|
32
|
+
*/
|
|
33
|
+
declare function getPaginatedPages(listTemplate: TemplateWithDistributor): Fields.SimpleContentType<Omit<unknown, "__contentTypeKind">>[][];
|
|
34
|
+
export { createGriddoListPages, createGriddoMultiPages, createGriddoSinglePage, getMultiPageElements, getPaginatedPages, };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { PostSearchInfoResponse } from "../types/api";
|
|
2
|
+
import type { PostSearchInfoProps } from "../types/global";
|
|
3
|
+
/**
|
|
4
|
+
* Save in the BBDD the content of a page parsed without HTML tags.
|
|
5
|
+
*
|
|
6
|
+
* @param props Object with parts of the final page object to be saved in the BBDD.
|
|
7
|
+
*/
|
|
8
|
+
declare function postSearchInfo(props: PostSearchInfoProps): Promise<PostSearchInfoResponse>;
|
|
9
|
+
/**
|
|
10
|
+
* Function that search in the `/public` dir the content info of the pages and
|
|
11
|
+
* send it to the search table in the ddbb using the API.
|
|
12
|
+
*/
|
|
13
|
+
declare function uploadRenderedSearchContentToAPI(distDomainPath: string, domain: string): Promise<void>;
|
|
14
|
+
export { postSearchInfo, uploadRenderedSearchContentToAPI };
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import type { Adapters } from "../adapters";
|
|
2
|
+
import type { APIResponses } from "../types/api";
|
|
3
|
+
import type { LifeCyclesNames } from "../types/global";
|
|
4
|
+
import type { Site } from "../types/sites";
|
|
5
|
+
declare const instanceRootDir: string;
|
|
6
|
+
/**
|
|
7
|
+
* Walk a directory and returns the file pathts.
|
|
8
|
+
*
|
|
9
|
+
* @param dir A directory path.
|
|
10
|
+
*/
|
|
11
|
+
declare function walk(dir: string): string[];
|
|
12
|
+
/**
|
|
13
|
+
* Custom log inside a line-box.
|
|
14
|
+
*
|
|
15
|
+
* @param stringValue The string to be logged.
|
|
16
|
+
* @param paddingInline The number of white spaces inside the box at left and right.
|
|
17
|
+
* @param paddingBlock The number of white spaces inside the box at top and bottom.
|
|
18
|
+
*/
|
|
19
|
+
declare function logBox(stringValue: string, title?: string, paddingInline?: number, paddingBlock?: number): void;
|
|
20
|
+
/**
|
|
21
|
+
* Custom basic logging function controlled by a environment variable.
|
|
22
|
+
* Strip double spaces.
|
|
23
|
+
*
|
|
24
|
+
* @param str The string to be logged.
|
|
25
|
+
*/
|
|
26
|
+
declare function logInfo(str: string): void;
|
|
27
|
+
/**
|
|
28
|
+
* Internal log
|
|
29
|
+
* @param values The values to be logged.
|
|
30
|
+
*/
|
|
31
|
+
declare function debug(...values: Array<unknown>): void;
|
|
32
|
+
/**
|
|
33
|
+
* Custom delay using the "promise hack",
|
|
34
|
+
*
|
|
35
|
+
* @param ms Amount of miliseconds to be delayed
|
|
36
|
+
*/
|
|
37
|
+
declare function delay(ms: number): Promise<unknown>;
|
|
38
|
+
/**
|
|
39
|
+
* Return a scale size colors with a number and a measure string (KB by default).
|
|
40
|
+
*
|
|
41
|
+
* @param size The page size in KB.
|
|
42
|
+
* @param measure The measure string to be added in the log.
|
|
43
|
+
*/
|
|
44
|
+
declare function logPageSize(size: number, measure?: string): string;
|
|
45
|
+
/**
|
|
46
|
+
* Converts milliseconds to seconds with a fixed number of decimals.
|
|
47
|
+
*
|
|
48
|
+
* @param ms The number in milliseconds.
|
|
49
|
+
* @param fixed The amount of fixed decimals.
|
|
50
|
+
* @returns The converted number in seconds with the fixed number of decimals.
|
|
51
|
+
*/
|
|
52
|
+
export declare function msToSec(ms: number, decimals?: number): string;
|
|
53
|
+
/**
|
|
54
|
+
* Return a siteID from a response object if exist
|
|
55
|
+
* @param response A response object
|
|
56
|
+
*/
|
|
57
|
+
export declare function getSafeSiteId(response: APIResponses): number | undefined;
|
|
58
|
+
/**
|
|
59
|
+
* Remove props from an object
|
|
60
|
+
*
|
|
61
|
+
* @param obj The object
|
|
62
|
+
* @param props An array of props to be removed
|
|
63
|
+
*/
|
|
64
|
+
declare function removeProperties(obj: Record<string, unknown>, props: Array<string>): void;
|
|
65
|
+
/**
|
|
66
|
+
* Return a list of sites with their names and ids.
|
|
67
|
+
*
|
|
68
|
+
* @param sites An array of sites objects
|
|
69
|
+
*/
|
|
70
|
+
declare function siteList(sites: Array<Site>): string;
|
|
71
|
+
/**
|
|
72
|
+
* Print the great Griddo Exporter logo in ASCII.
|
|
73
|
+
*/
|
|
74
|
+
declare function printExporterLogo(adapter: Adapters): void;
|
|
75
|
+
/**
|
|
76
|
+
* Remove unused files (old) inside the `apiCache` dir
|
|
77
|
+
*
|
|
78
|
+
* @todo remove other file types: sites, socials, etc..
|
|
79
|
+
*/
|
|
80
|
+
declare function sanitizeAPICacheDir(): void;
|
|
81
|
+
/**
|
|
82
|
+
* Measures the execution time of a series of sync or async functions.
|
|
83
|
+
* @param functions - Functions to be executed to measure their execution time.
|
|
84
|
+
* @returns A promise that resolves with the total execution time in seconds.
|
|
85
|
+
*/
|
|
86
|
+
declare function measureExecutionTime(...functions: Array<(...args: Array<unknown>) => unknown | Promise<any>>): Promise<number>;
|
|
87
|
+
declare function pause(title: string): Promise<void> | undefined;
|
|
88
|
+
declare function startLifeCycle(lifeCyleName: string): void;
|
|
89
|
+
declare function successLifeCyle(value: string): void;
|
|
90
|
+
/**
|
|
91
|
+
* Executes a life cycle process, which involves executing an array of
|
|
92
|
+
* functions, printing to the console, and handling errors with optional
|
|
93
|
+
* retries.
|
|
94
|
+
*
|
|
95
|
+
* @async
|
|
96
|
+
* @param args - The arguments object.
|
|
97
|
+
* @param args.steps - An array of functions to execute.
|
|
98
|
+
* @param args.name - The name of the life cycle.
|
|
99
|
+
* @param args.attempts=1 - The number of retry attempts allowed in case of errors.
|
|
100
|
+
* @param args.bypass - Skip the step functions.
|
|
101
|
+
* @returns - A promise that resolves when the life cycle process is completed.
|
|
102
|
+
*/
|
|
103
|
+
declare function doLifeCycle(args: {
|
|
104
|
+
steps: Array<(...args: Array<unknown>) => unknown | Promise<any>>;
|
|
105
|
+
name: LifeCyclesNames;
|
|
106
|
+
attempts?: number;
|
|
107
|
+
}): Promise<void>;
|
|
108
|
+
declare function isVersionGreaterThan(versionA: string, versionB: string): boolean;
|
|
109
|
+
declare function isVersionLowerThan(versionA: string, versionB: string): boolean;
|
|
110
|
+
export { debug, delay, doLifeCycle, instanceRootDir, isVersionGreaterThan, isVersionLowerThan, logBox, logInfo, logPageSize, measureExecutionTime, pause, printExporterLogo, removeProperties, sanitizeAPICacheDir, siteList, startLifeCycle, successLifeCyle, walk, };
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { Site, SiteData } from "../types/sites";
|
|
2
|
+
/**
|
|
3
|
+
* Check the instance sites and returns site prepared to be published and unpublished.
|
|
4
|
+
*/
|
|
5
|
+
declare function checkSites(domain: string): Promise<{
|
|
6
|
+
sitesToPublish: Site[];
|
|
7
|
+
sitesToUnpublish: Site[];
|
|
8
|
+
}>;
|
|
9
|
+
/**
|
|
10
|
+
* Unpublish an array of sites in two steps:
|
|
11
|
+
* - Sending the information to the API
|
|
12
|
+
*
|
|
13
|
+
* @param sites An array of sites
|
|
14
|
+
* @see https://griddoio.notion.site/Sites-d7bb0b7cb8d24894a5337e1139fc3d09#2019d3255bda4d219c7e19cf28d0c4fe
|
|
15
|
+
*/
|
|
16
|
+
declare function unpublishSites(sites: Array<Site>): Promise<void>;
|
|
17
|
+
/**
|
|
18
|
+
* Return a single site generic data.
|
|
19
|
+
*
|
|
20
|
+
* @param siteID The site id.
|
|
21
|
+
* @param cacheKey Boolean that indicates if we want to get cache version.
|
|
22
|
+
*
|
|
23
|
+
* @see SiteData
|
|
24
|
+
*/
|
|
25
|
+
declare function getSiteData(siteID: number): Promise<SiteData>;
|
|
26
|
+
/**
|
|
27
|
+
* Save a file with the end of build process
|
|
28
|
+
*/
|
|
29
|
+
declare function generateBuildReport(): Promise<void>;
|
|
30
|
+
/**
|
|
31
|
+
* Generate sitemaps and save them into file system.
|
|
32
|
+
*
|
|
33
|
+
* @param sites An array of sites
|
|
34
|
+
*/
|
|
35
|
+
declare function generateSitemaps(): Promise<void>;
|
|
36
|
+
export { checkSites, generateBuildReport, generateSitemaps, getSiteData, unpublishSites, };
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import type { BuildMetaData } from "../types/api";
|
|
2
|
+
import type { RenderInfo } from "../types/global";
|
|
3
|
+
import type { GriddoPageObject } from "../types/pages";
|
|
4
|
+
import type { Site } from "../types/sites";
|
|
5
|
+
/**
|
|
6
|
+
* Read all path pages stored in the `store` Griddo directory and returns the
|
|
7
|
+
* absolute file path.
|
|
8
|
+
*
|
|
9
|
+
* @param domain - The domain to get the pages from.
|
|
10
|
+
*/
|
|
11
|
+
declare function getBuildPagesFromCachedStore<PageType extends GriddoPageObject>(domain: string): Generator<PageType, void, unknown>;
|
|
12
|
+
/**
|
|
13
|
+
* Read all pages stored in the `store` Griddo directory and returns one by one
|
|
14
|
+
* with a generator.
|
|
15
|
+
*
|
|
16
|
+
* @param basePath - Base directory to get pages from.
|
|
17
|
+
* @param options.withSizeProp - Add size prop to the page object.
|
|
18
|
+
* @todo throw error if the basePath is not an store folder
|
|
19
|
+
*/
|
|
20
|
+
declare function getBuildPagesFromStore<PageType extends GriddoPageObject>(args?: {
|
|
21
|
+
basePath?: string;
|
|
22
|
+
withSizeProp?: boolean;
|
|
23
|
+
}): Generator<PageType, void, unknown>;
|
|
24
|
+
/**
|
|
25
|
+
* Read all pages stored in `store` Griddo directory and return the absolute path.
|
|
26
|
+
*/
|
|
27
|
+
declare function getBuildPagesPath(): string[];
|
|
28
|
+
/**
|
|
29
|
+
* Get the build metadata from the Store.
|
|
30
|
+
* TODO: Refactorizar para leer un solo archivo: __metadata__.json
|
|
31
|
+
*/
|
|
32
|
+
declare function getBuildMetadata(): Promise<BuildMetaData>;
|
|
33
|
+
/**
|
|
34
|
+
* Creates an `store` dir to store pages transformed by createStore
|
|
35
|
+
*/
|
|
36
|
+
declare function createStoreDir(): void;
|
|
37
|
+
/**
|
|
38
|
+
* Write render info into a file.
|
|
39
|
+
* @param basePath - Absolute path of the dir from which files will be saved.
|
|
40
|
+
* @param renderInfo - Data that will be saved related to the render process.
|
|
41
|
+
*/
|
|
42
|
+
declare function saveRenderInfoInStore(basePath: string, renderInfo: RenderInfo): void;
|
|
43
|
+
/**
|
|
44
|
+
* Return an array of ids only from `.json` files (no dirs) in the `basePath` dir based in the file name.
|
|
45
|
+
* @param basePath - Absolute path of the dir from which files will be read.
|
|
46
|
+
* @returns A Array<number> of pages ids in `basePath` dir.
|
|
47
|
+
*/
|
|
48
|
+
declare function getPageInStoreDir(basePath: string): Array<number>;
|
|
49
|
+
/**
|
|
50
|
+
* Save the pages into the file system.
|
|
51
|
+
* @param pages - An array of Griddo page objects to be saved.
|
|
52
|
+
*/
|
|
53
|
+
declare function savePagesInStore(pages: Array<GriddoPageObject>): void;
|
|
54
|
+
/**
|
|
55
|
+
* Remove files from dir.
|
|
56
|
+
* @param filenames - An array of ids representing file page names.
|
|
57
|
+
*/
|
|
58
|
+
declare function removePagesFromStore(filenames: Array<number>): void;
|
|
59
|
+
/**
|
|
60
|
+
* Returns pages that need to be created or deleted for a site in the store based on the provided arguments.
|
|
61
|
+
* @param sitePages - Properties for page retrieval.
|
|
62
|
+
* @param props.storeDir - Absolute path of the Griddo store.
|
|
63
|
+
* @param props.pages - Exhaustive array of all pages in the site.
|
|
64
|
+
* @param props.validPagesIds - Array of valid pages in the site.
|
|
65
|
+
* @param props.changedPages - Array of pages that have been modified in the site.
|
|
66
|
+
* @returns - An object containing the pages to be created and deleted in the site.
|
|
67
|
+
*/
|
|
68
|
+
declare function getPagesToCreateOrDelete(storeDir: string, sitePages: {
|
|
69
|
+
sitesToPublish: Array<Site>;
|
|
70
|
+
pages: Array<number>;
|
|
71
|
+
validPagesIds: Array<number>;
|
|
72
|
+
changedPages: Array<number>;
|
|
73
|
+
}): Promise<{
|
|
74
|
+
pagesInStore: number[];
|
|
75
|
+
pagesMissingInStore: number[];
|
|
76
|
+
pagesToDeleteFromStore: number[];
|
|
77
|
+
pagesToWriteToStore: number[];
|
|
78
|
+
}>;
|
|
79
|
+
export { createStoreDir, getBuildMetadata, getBuildPagesPath, getBuildPagesFromCachedStore, getBuildPagesFromStore, getPageInStoreDir, getPagesToCreateOrDelete, removePagesFromStore, savePagesInStore, saveRenderInfoInStore, };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { CXConfig } from "../types/global";
|
|
2
|
+
declare function getConfig(): CXConfig;
|
|
3
|
+
/**
|
|
4
|
+
* Update the Griddo's `/dist` dir with the contents from `public` dir only
|
|
5
|
+
* with files of type: js, json and css.
|
|
6
|
+
*/
|
|
7
|
+
declare function legacy__createDistFromGatsbyPublic(domain: string, needsAssetPrefix: boolean): Promise<void>;
|
|
8
|
+
declare function griddoCreateInitialDirectories(domain: string): Promise<void>;
|
|
9
|
+
declare function griddoCleanDisposableDirectories(domain: string): Promise<void>;
|
|
10
|
+
export { getConfig, griddoCleanDisposableDirectories, griddoCreateInitialDirectories, legacy__createDistFromGatsbyPublic, };
|
package/cx.config.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import { spawnSync } from "node:child_process";
|
|
2
1
|
import fs from "node:fs";
|
|
3
2
|
import path from "node:path";
|
|
4
3
|
|
|
5
|
-
import { attempts, getGatsbyAssetPrefixSlug } from "./utils";
|
|
4
|
+
import { attempts, gatsbyBuild, getGatsbyAssetPrefixSlug } from "./utils";
|
|
6
5
|
import { RobotsService } from "../../services/robots";
|
|
7
6
|
import { createBuildData } from "../../utils/create-build-data";
|
|
8
7
|
import { getInstanceDomains } from "../../utils/domains";
|
|
@@ -33,7 +32,7 @@ async function runGatsbyAdapter() {
|
|
|
33
32
|
const config = getConfig();
|
|
34
33
|
|
|
35
34
|
for (const domain of domains) {
|
|
36
|
-
const { __ssg, __exports, __caches, __cx, __components } = config.
|
|
35
|
+
const { __ssg, __exports, __caches, __cx, __components } = config.paths(
|
|
37
36
|
domain
|
|
38
37
|
);
|
|
39
38
|
|
|
@@ -120,21 +119,7 @@ async function runGatsbyAdapter() {
|
|
|
120
119
|
await doLifeCycle({
|
|
121
120
|
name: "SSG",
|
|
122
121
|
attempts: attempts.ssg,
|
|
123
|
-
steps: [
|
|
124
|
-
() =>
|
|
125
|
-
// Run Gatsby
|
|
126
|
-
spawnSync("yarn", ["gatsby-build"], {
|
|
127
|
-
cwd: __ssg,
|
|
128
|
-
stdio: ["ignore", "inherit", "ignore"],
|
|
129
|
-
encoding: "utf8",
|
|
130
|
-
shell: true,
|
|
131
|
-
env: Object.assign(process.env, {
|
|
132
|
-
GRIDDO_EXPORTER: "true",
|
|
133
|
-
GRIDDO_ASSET_PREFIX: assetPrefix,
|
|
134
|
-
}),
|
|
135
|
-
}),
|
|
136
|
-
() => pause("SSG LifeCycle"),
|
|
137
|
-
],
|
|
122
|
+
steps: [() => gatsbyBuild(domain), () => pause("SSG LifeCycle")],
|
|
138
123
|
});
|
|
139
124
|
|
|
140
125
|
/*
|
|
@@ -142,6 +127,7 @@ async function runGatsbyAdapter() {
|
|
|
142
127
|
*/
|
|
143
128
|
await doLifeCycle({
|
|
144
129
|
name: "Relocation",
|
|
130
|
+
attempts: attempts.relocation,
|
|
145
131
|
steps: [
|
|
146
132
|
() => legacy__createDistFromGatsbyPublic(domain, needsAssetPrefix),
|
|
147
133
|
() => pause("Relocation LifeCycle"),
|
|
@@ -179,7 +165,7 @@ async function runGatsbyAdapter() {
|
|
|
179
165
|
() => removeVirtualPagesFromStore(),
|
|
180
166
|
// Eliminamos carpetas vacías que puedan quedar de sites
|
|
181
167
|
// despublicados. Incluye aquellas que solo tengan archivos .xml
|
|
182
|
-
() => clearEmptyDirs(),
|
|
168
|
+
() => clearEmptyDirs(path.join(__cx, "dist")),
|
|
183
169
|
() =>
|
|
184
170
|
moveDirsSync(__cx, __exports, ["dist", "assets"], {
|
|
185
171
|
withBackup: true,
|
|
@@ -195,11 +181,11 @@ async function runGatsbyAdapter() {
|
|
|
195
181
|
*/
|
|
196
182
|
await doLifeCycle({
|
|
197
183
|
name: "Clean",
|
|
184
|
+
attempts: attempts.clean,
|
|
198
185
|
steps: [
|
|
199
186
|
() => removeDirsSync(__ssg, ["static", "public", "dist"]),
|
|
200
187
|
() => pause("Clean LifeCycle"),
|
|
201
188
|
],
|
|
202
|
-
attempts: attempts.clean,
|
|
203
189
|
});
|
|
204
190
|
}
|
|
205
191
|
}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { spawnSync } from "node:child_process";
|
|
2
|
+
|
|
1
3
|
import { Fields } from "@griddo/core";
|
|
2
4
|
import dotenv from "dotenv";
|
|
3
5
|
|
|
@@ -5,6 +7,8 @@ import { getConfig } from "../../utils/temp-utils";
|
|
|
5
7
|
|
|
6
8
|
dotenv.config();
|
|
7
9
|
|
|
10
|
+
const config = getConfig();
|
|
11
|
+
|
|
8
12
|
const attempts = {
|
|
9
13
|
prepare: JSON.parse(process.env.GRIDDO_PREPARE_LIFECYCLE_MAX_ATTEMPTS || "1"),
|
|
10
14
|
restore: JSON.parse(process.env.GRIDDO_RESTORE_LIFECYCLE_MAX_ATTEMPTS || "1"),
|
|
@@ -82,4 +86,24 @@ function addCloudinaryParams(image: string, params: string) {
|
|
|
82
86
|
return `https://${head}/${params}${fullId}`;
|
|
83
87
|
}
|
|
84
88
|
|
|
85
|
-
|
|
89
|
+
function gatsbyBuild(domain: string) {
|
|
90
|
+
const assetPrefix = getGatsbyAssetPrefixSlug(domain);
|
|
91
|
+
const { __ssg } = config.paths();
|
|
92
|
+
|
|
93
|
+
const command = spawnSync("yarn", ["gatsby-build"], {
|
|
94
|
+
cwd: __ssg,
|
|
95
|
+
stdio: ["ignore", "inherit", "ignore"],
|
|
96
|
+
encoding: "utf8",
|
|
97
|
+
shell: true,
|
|
98
|
+
env: Object.assign(process.env, {
|
|
99
|
+
GRIDDO_EXPORTER: "true",
|
|
100
|
+
LOCAL_GRIDDO_ASSET_PREFIX: assetPrefix,
|
|
101
|
+
}),
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
if (command.status !== 0) {
|
|
105
|
+
throw new Error("Error in 'yarn gatsby-build'");
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export { attempts, formatImage, gatsbyBuild, getGatsbyAssetPrefixSlug };
|
package/exporter/index.ts
CHANGED
|
@@ -25,8 +25,8 @@
|
|
|
25
25
|
|
|
26
26
|
/* prettier-ignore */ import { startRender } from "./start-render";
|
|
27
27
|
/* prettier-ignore */ import { IS_COMPONENT_LIBRARY, PROJECT_ALIASES, resolveComponentsPath } from "./utils/instance";
|
|
28
|
-
/* prettier-ignore */ import { logInfo, logPageSize } from "./utils/shared";
|
|
29
|
-
/* prettier-ignore */ import {
|
|
28
|
+
/* prettier-ignore */ import { logInfo, logPageSize, walk } from "./utils/shared";
|
|
29
|
+
/* prettier-ignore */ import { getBuildPagesFromCachedStore, getBuildPagesFromStore, getBuildPagesPath } from "./utils/store";
|
|
30
30
|
/* prettier-ignore */ import { getConfig } from "./utils/temp-utils";
|
|
31
31
|
|
|
32
32
|
export {
|
|
@@ -39,10 +39,12 @@ export {
|
|
|
39
39
|
PROJECT_ALIASES,
|
|
40
40
|
Site,
|
|
41
41
|
SocialsResponse,
|
|
42
|
-
|
|
43
|
-
getConfig,
|
|
42
|
+
getBuildPagesFromCachedStore,
|
|
43
|
+
getBuildPagesFromStore, getBuildPagesPath, getConfig,
|
|
44
44
|
logInfo,
|
|
45
45
|
logPageSize,
|
|
46
46
|
resolveComponentsPath,
|
|
47
47
|
startRender,
|
|
48
|
+
walk
|
|
48
49
|
};
|
|
50
|
+
|
|
@@ -10,6 +10,8 @@ import dotenv from "dotenv";
|
|
|
10
10
|
import { get } from "../utils/api";
|
|
11
11
|
import { getConfig } from "../utils/temp-utils";
|
|
12
12
|
|
|
13
|
+
const config = getConfig();
|
|
14
|
+
|
|
13
15
|
/**
|
|
14
16
|
* TODO: JSDoc
|
|
15
17
|
*/
|
|
@@ -50,9 +52,8 @@ class RobotsService {
|
|
|
50
52
|
* Write robots.txt files for the current rendering domain.
|
|
51
53
|
*/
|
|
52
54
|
async writeFiles(domain: string) {
|
|
53
|
-
const
|
|
54
|
-
const
|
|
55
|
-
const distDirectory = path.join(dirs.__cx, "dist");
|
|
55
|
+
const { __cx } = config.paths(domain);
|
|
56
|
+
const distDirectory = path.join(__cx, "dist");
|
|
56
57
|
|
|
57
58
|
await this.getRobots();
|
|
58
59
|
|