@griddo/cx 10.4.12 → 10.4.13
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 +1 -1
- package/build/adapters/gatsby/index.d.ts +2 -0
- package/build/adapters/gatsby/utils.d.ts +26 -0
- package/build/adapters/index.d.ts +3 -0
- package/build/browser/index.d.ts +5 -0
- package/build/browser/index.js +1 -0
- package/build/build-complete.d.ts +18 -0
- package/build/index.d.ts +29 -0
- package/build/index.js +37 -38
- 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/run-start-render.d.ts +1 -0
- package/build/run-start-render.js +69 -0
- 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 +70 -0
- 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/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 +109 -0
- package/build/utils/sites.d.ts +36 -0
- package/build/utils/store.d.ts +63 -0
- package/build/utils/temp-utils.d.ts +10 -0
- package/{exporter/cx.config.d.ts → cx.config.d.ts} +1 -2
- package/{exporter/cx.config.js → cx.config.js} +5 -8
- package/package.json +21 -29
- package/src/adapters/gatsby/index.ts +219 -0
- package/src/adapters/gatsby/utils.ts +85 -0
- package/src/browser/README.md +3 -0
- package/src/browser/index.ts +46 -0
- package/src/index.ts +48 -0
- package/src/move-assets.ts +8 -0
- package/src/react/index.ts +5 -0
- package/src/run-start-render.ts +3 -0
- package/{exporter → src}/services/robots.ts +1 -5
- package/{exporter → src}/services/store.ts +6 -1
- package/src/start-render.ts +19 -0
- package/{exporter → src}/types/global.ts +4 -3
- package/src/utils/folders.ts +268 -0
- package/{exporter → src}/utils/instance.ts +2 -2
- package/{exporter → src}/utils/pages.ts +2 -9
- package/{exporter → src}/utils/searches.ts +5 -8
- package/{exporter → src}/utils/shared.ts +5 -2
- package/{exporter → src}/utils/sites.ts +1 -8
- package/{exporter → src}/utils/temp-utils.ts +35 -8
- package/ssg/README.md +1 -0
- package/ssg/astro/.gitkeep +0 -0
- package/ssg/gatsby/.eslintrc.json +51 -0
- package/ssg/gatsby/.prettierignore +6 -0
- package/ssg/gatsby/.prettierrc.json +3 -0
- package/{gatsby-browser.tsx → ssg/gatsby/gatsby-browser.tsx} +42 -44
- package/{gatsby-config.ts → ssg/gatsby/gatsby-config.ts} +1 -2
- package/{gatsby-node.ts → ssg/gatsby/gatsby-node.ts} +11 -8
- package/{gatsby-ssr.tsx → ssg/gatsby/gatsby-ssr.tsx} +1 -1
- package/ssg/gatsby/global.d.ts +1 -0
- package/ssg/gatsby/package.json +85 -0
- package/{src → ssg/gatsby/src}/components/Head.tsx +2 -2
- package/{src → ssg/gatsby/src}/components/template.tsx +2 -3
- package/{src → ssg/gatsby/src}/gatsby-node-utils.ts +6 -5
- package/{src → ssg/gatsby/src}/types.ts +5 -4
- package/ssg/gatsby/tsconfig.json +15 -0
- package/start-render.js +7 -0
- package/build/create-build-data.js +0 -60
- package/exporter/adapters/gatsby/index.ts +0 -159
- package/exporter/adapters/gatsby/utils.ts +0 -377
- package/exporter/create-build-data.ts +0 -22
- package/exporter/index.ts +0 -23
- package/exporter/utils/folders.ts +0 -318
- package/exporter/utils/integrations.ts +0 -36
- package/exporter/utils/runners.ts +0 -52
- package/index.js +0 -7
- /package/{exporter → src}/adapters/index.ts +0 -0
- /package/{exporter → src}/build-complete.ts +0 -0
- /package/{exporter → src}/reset-render.ts +0 -0
- /package/{exporter → src}/services/auth.ts +0 -0
- /package/{exporter → src}/services/distributors.ts +0 -0
- /package/{exporter → src}/services/domains.ts +0 -0
- /package/{exporter → src}/services/navigation.ts +0 -0
- /package/{exporter → src}/services/settings.ts +0 -0
- /package/{exporter → src}/services/sites.ts +0 -0
- /package/{exporter → src}/types/api.ts +0 -0
- /package/{exporter → src}/types/navigation.ts +0 -0
- /package/{exporter → src}/types/pages.ts +0 -0
- /package/{exporter → src}/types/sites.ts +0 -0
- /package/{exporter → src}/types/templates.ts +0 -0
- /package/{exporter → src}/utils/api.ts +0 -0
- /package/{exporter → src}/utils/cache.ts +0 -0
- /package/{exporter/utils/download-build-data.ts → src/utils/create-build-data.ts} +0 -0
- /package/{exporter → src}/utils/domains.ts +0 -0
- /package/{exporter → src}/utils/health-checks.ts +0 -0
- /package/{exporter → src}/utils/messages.ts +0 -0
- /package/{exporter → src}/utils/store.ts +0 -0
- /package/{src → ssg/gatsby/src}/README.md +0 -0
- /package/{src → ssg/gatsby/src}/html.tsx +0 -0
- /package/{src → ssg/gatsby/src}/utils.ts +0 -0
|
@@ -0,0 +1,109 @@
|
|
|
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 CXRootDir: string;
|
|
6
|
+
declare const instanceRootDir: string;
|
|
7
|
+
/**
|
|
8
|
+
* Walk a directory and returns the file pathts.
|
|
9
|
+
*
|
|
10
|
+
* @param dir A directory path.
|
|
11
|
+
*/
|
|
12
|
+
declare function walk(dir: string): string[];
|
|
13
|
+
/**
|
|
14
|
+
* Custom log inside a line-box.
|
|
15
|
+
*
|
|
16
|
+
* @param stringValue The string to be logged.
|
|
17
|
+
* @param paddingInline The number of white spaces inside the box at left and right.
|
|
18
|
+
* @param paddingBlock The number of white spaces inside the box at top and bottom.
|
|
19
|
+
*/
|
|
20
|
+
declare function logBox(stringValue: string, title?: string, paddingInline?: number, paddingBlock?: number): void;
|
|
21
|
+
/**
|
|
22
|
+
* Custom basic logging function controlled by a environment variable.
|
|
23
|
+
* Strip double spaces.
|
|
24
|
+
*
|
|
25
|
+
* @param str The string to be logged.
|
|
26
|
+
*/
|
|
27
|
+
declare function logInfo(str: string): void;
|
|
28
|
+
/**
|
|
29
|
+
* Internal log
|
|
30
|
+
* @param values The values to be logged.
|
|
31
|
+
*/
|
|
32
|
+
declare function debug(...values: Array<unknown>): void;
|
|
33
|
+
/**
|
|
34
|
+
* Custom delay using the "promise hack",
|
|
35
|
+
*
|
|
36
|
+
* @param ms Amount of miliseconds to be delayed
|
|
37
|
+
*/
|
|
38
|
+
declare function delay(ms: number): Promise<unknown>;
|
|
39
|
+
/**
|
|
40
|
+
* Return a scale size colors with a number and a measure string (KB by default).
|
|
41
|
+
*
|
|
42
|
+
* @param size The page size in KB.
|
|
43
|
+
* @param measure The measure string to be added in the log.
|
|
44
|
+
*/
|
|
45
|
+
declare function logPageSize(size: number, measure?: string): string;
|
|
46
|
+
/**
|
|
47
|
+
* Converts milliseconds to seconds with a fixed number of decimals.
|
|
48
|
+
*
|
|
49
|
+
* @param ms The number in milliseconds.
|
|
50
|
+
* @param fixed The amount of fixed decimals.
|
|
51
|
+
* @returns The converted number in seconds with the fixed number of decimals.
|
|
52
|
+
*/
|
|
53
|
+
export declare function msToSec(ms: number, decimals?: number): string;
|
|
54
|
+
/**
|
|
55
|
+
* Return a siteID from a response object if exist
|
|
56
|
+
* @param response A response object
|
|
57
|
+
*/
|
|
58
|
+
export declare function getSafeSiteId(response: APIResponses): number | undefined;
|
|
59
|
+
/**
|
|
60
|
+
* Remove props from an object
|
|
61
|
+
*
|
|
62
|
+
* @param obj The object
|
|
63
|
+
* @param props An array of props to be removed
|
|
64
|
+
*/
|
|
65
|
+
declare function removeProperties(obj: Record<string, unknown>, props: Array<string>): void;
|
|
66
|
+
/**
|
|
67
|
+
* Return a list of sites with their names and ids.
|
|
68
|
+
*
|
|
69
|
+
* @param sites An array of sites objects
|
|
70
|
+
*/
|
|
71
|
+
declare function siteList(sites: Array<Site>): string;
|
|
72
|
+
/**
|
|
73
|
+
* Print the great Griddo Exporter logo in ASCII.
|
|
74
|
+
*/
|
|
75
|
+
declare function printExporterLogo(adapter: Adapters): void;
|
|
76
|
+
/**
|
|
77
|
+
* Remove unused files (old) inside the `apiCache` dir
|
|
78
|
+
*
|
|
79
|
+
* @param dirPath The path for the `apiCache` dir
|
|
80
|
+
* @todo remove other file types: sites, socials, etc..
|
|
81
|
+
*/
|
|
82
|
+
declare function sanitizeAPICacheDir(dirPath: string): void;
|
|
83
|
+
/**
|
|
84
|
+
* Measures the execution time of a series of sync or async functions.
|
|
85
|
+
* @param functions - Functions to be executed to measure their execution time.
|
|
86
|
+
* @returns A promise that resolves with the total execution time in seconds.
|
|
87
|
+
*/
|
|
88
|
+
declare function measureExecutionTime(...functions: Array<(...args: Array<unknown>) => unknown | Promise<any>>): Promise<number>;
|
|
89
|
+
declare function pause(title: string): Promise<void> | undefined;
|
|
90
|
+
declare function startLifeCycle(lifeCyleName: string): void;
|
|
91
|
+
declare function successLifeCyle(value: string): void;
|
|
92
|
+
/**
|
|
93
|
+
* Executes a life cycle process, which involves executing an array of
|
|
94
|
+
* functions, printing to the console, and handling errors with optional
|
|
95
|
+
* retries.
|
|
96
|
+
*
|
|
97
|
+
* @async
|
|
98
|
+
* @param args - The arguments object.
|
|
99
|
+
* @param args.steps - An array of functions to execute.
|
|
100
|
+
* @param args.name - The name of the life cycle.
|
|
101
|
+
* @param [args.attempts=1] - The number of retry attempts allowed in case of errors.
|
|
102
|
+
* @returns - A promise that resolves when the life cycle process is completed.
|
|
103
|
+
*/
|
|
104
|
+
declare function doLifeCycle(args: {
|
|
105
|
+
steps: Array<(...args: Array<unknown>) => unknown | Promise<any>>;
|
|
106
|
+
name: LifeCyclesNames;
|
|
107
|
+
attempts?: number;
|
|
108
|
+
}): Promise<void>;
|
|
109
|
+
export { CXRootDir, debug, delay, doLifeCycle, instanceRootDir, 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,63 @@
|
|
|
1
|
+
import type { BuildMetaData } from "../types/api";
|
|
2
|
+
import type { RenderInfo } from "../types/global";
|
|
3
|
+
import type { GriddoPageObject } from "../types/pages";
|
|
4
|
+
import { Site } from "../types/sites";
|
|
5
|
+
/**
|
|
6
|
+
* Read all pages stored in `store` Griddo directory and return one by one with
|
|
7
|
+
* a generator.
|
|
8
|
+
*/
|
|
9
|
+
declare function getBuildPages<PageType extends GriddoPageObject>(basePath: string): AsyncGenerator<PageType, void, unknown>;
|
|
10
|
+
/**
|
|
11
|
+
* Get the build metadata from the Store.
|
|
12
|
+
* TODO: Refactorizar para leer un solo archivo: __metadata__.json
|
|
13
|
+
*/
|
|
14
|
+
declare function getBuildMetadata(): Promise<BuildMetaData>;
|
|
15
|
+
/**
|
|
16
|
+
* Creates an `store` dir to store pages transformed by createStore
|
|
17
|
+
*/
|
|
18
|
+
declare function createStoreDir(storeDir: string): void;
|
|
19
|
+
/**
|
|
20
|
+
* Write render info into a file.
|
|
21
|
+
* @param basePath - Absolute path of the dir from which files will be saved.
|
|
22
|
+
* @param renderInfo - Data that will be saved related to the render process.
|
|
23
|
+
*/
|
|
24
|
+
declare function saveRenderInfoInStore(basePath: string, renderInfo: RenderInfo): void;
|
|
25
|
+
/**
|
|
26
|
+
* Return an array of ids only from `.json` files (no dirs) in the `basePath` dir based in the file name.
|
|
27
|
+
* @param basePath - Absolute path of the dir from which files will be read.
|
|
28
|
+
* @returns A Array<number> of pages ids in `basePath` dir.
|
|
29
|
+
*/
|
|
30
|
+
declare function getPageInStoreDir(basePath: string): Array<number>;
|
|
31
|
+
/**
|
|
32
|
+
* Save the pages into the file system.
|
|
33
|
+
* @param basePath - Absolute path of the dir from which files will be saved.
|
|
34
|
+
* @param pages - An array of Griddo page objects to be saved.
|
|
35
|
+
*/
|
|
36
|
+
declare function savePagesInStore(basePath: string, pages: Array<GriddoPageObject>): void;
|
|
37
|
+
/**
|
|
38
|
+
* Remove files from dir.
|
|
39
|
+
* @param basePath - Absolute path of the dir from which files will be removed.
|
|
40
|
+
* @param filenames - An array of ids representing file page names.
|
|
41
|
+
*/
|
|
42
|
+
declare function removePagesFromStore(basePath: string, filenames: Array<number>): void;
|
|
43
|
+
/**
|
|
44
|
+
* Returns pages that need to be created or deleted for a site in the store based on the provided arguments.
|
|
45
|
+
* @param sitePages - Properties for page retrieval.
|
|
46
|
+
* @param props.storeDir - Absolute path of the Griddo store.
|
|
47
|
+
* @param props.pages - Exhaustive array of all pages in the site.
|
|
48
|
+
* @param props.validPagesIds - Array of valid pages in the site.
|
|
49
|
+
* @param props.changedPages - Array of pages that have been modified in the site.
|
|
50
|
+
* @returns - An object containing the pages to be created and deleted in the site.
|
|
51
|
+
*/
|
|
52
|
+
declare function getPagesToCreateOrDelete(storeDir: string, sitePages: {
|
|
53
|
+
sitesToPublish: Array<Site>;
|
|
54
|
+
pages: Array<number>;
|
|
55
|
+
validPagesIds: Array<number>;
|
|
56
|
+
changedPages: Array<number>;
|
|
57
|
+
}): Promise<{
|
|
58
|
+
pagesInStore: number[];
|
|
59
|
+
pagesMissingInStore: number[];
|
|
60
|
+
pagesToDeleteFromStore: number[];
|
|
61
|
+
pagesToWriteToStore: number[];
|
|
62
|
+
}>;
|
|
63
|
+
export { createStoreDir, getBuildMetadata, getBuildPages, 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, };
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { CXConfig } from "./src/types/global";
|
|
2
2
|
|
|
3
|
-
declare const artifacts: readonly ["public", ".cache", "static"];
|
|
4
3
|
declare const config: CXConfig;
|
|
5
4
|
|
|
6
5
|
export default config;
|
|
@@ -21,4 +20,4 @@ export type Artifact =
|
|
|
21
20
|
| "dist"
|
|
22
21
|
| "assets";
|
|
23
22
|
|
|
24
|
-
export { CXDir
|
|
23
|
+
export { CXDir };
|
|
@@ -2,30 +2,28 @@ import path from "node:path";
|
|
|
2
2
|
|
|
3
3
|
import pkgDir from "pkg-dir";
|
|
4
4
|
|
|
5
|
-
import { resolveComponentsPath } from "./utils/instance";
|
|
5
|
+
import { resolveComponentsPath } from "./src/utils/instance";
|
|
6
6
|
|
|
7
7
|
// Paths
|
|
8
8
|
const REPO_ROOT_DIR = pkgDir.sync(path.resolve(__dirname, "../.."));
|
|
9
9
|
const CX_ROOT_DIR = pkgDir.sync(__dirname);
|
|
10
|
-
const SSG_DIR = pkgDir.sync(__dirname);
|
|
10
|
+
const SSG_DIR = path.resolve(pkgDir.sync(__dirname), "./ssg/gatsby");
|
|
11
11
|
const CX_CACHE_DIR = path.resolve(CX_ROOT_DIR, "caches");
|
|
12
12
|
const COMPONENTS_DIR = resolveComponentsPath();
|
|
13
13
|
const EXPORTS_DIR = path.join(REPO_ROOT_DIR, "exports/sites");
|
|
14
14
|
|
|
15
|
-
const artifacts = ["public", ".cache", "static"];
|
|
16
|
-
|
|
17
15
|
const config = {
|
|
18
16
|
proDomain: "pro-",
|
|
19
17
|
CXDir: {
|
|
20
18
|
EXPORTS: "__exports",
|
|
21
|
-
CACHE: "
|
|
19
|
+
CACHE: "__caches",
|
|
22
20
|
CX: "__cx",
|
|
23
21
|
SSG: "__ssg",
|
|
24
22
|
COMPONENTS: "__components",
|
|
25
23
|
ROOT: "__root",
|
|
26
24
|
},
|
|
27
25
|
dirs: (domain) => ({
|
|
28
|
-
|
|
26
|
+
__caches: path.join(CX_CACHE_DIR, domain || ""),
|
|
29
27
|
__components: COMPONENTS_DIR,
|
|
30
28
|
__cx: CX_ROOT_DIR,
|
|
31
29
|
__exports: path.join(EXPORTS_DIR, domain || ""),
|
|
@@ -36,5 +34,4 @@ const config = {
|
|
|
36
34
|
|
|
37
35
|
export default config;
|
|
38
36
|
const CXDir = config.CXDir;
|
|
39
|
-
|
|
40
|
-
export { CXDir, artifacts };
|
|
37
|
+
export { CXDir };
|
package/package.json
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@griddo/cx",
|
|
3
3
|
"description": "Griddo SSG based on Gatsby",
|
|
4
|
-
"version": "10.4.
|
|
4
|
+
"version": "10.4.13",
|
|
5
5
|
"authors": [
|
|
6
6
|
"Álvaro Sánchez' <alvaro.sanches@secuoyas.com>",
|
|
7
7
|
"Diego M. Béjar <diego.bejar@secuoyas.com>",
|
|
8
8
|
"Francis Vega <francis.vega@secuoyas.com>",
|
|
9
9
|
"Gonzalo Hernández <gonzalo.hernandez@secuoyas.com>",
|
|
10
|
-
"Sergio Ródenas <sergio.rodenas@secuoyas.com>"
|
|
11
|
-
"Txema León <txema.leon@secuoyas.com>"
|
|
10
|
+
"Sergio Ródenas <sergio.rodenas@secuoyas.com>"
|
|
12
11
|
],
|
|
13
12
|
"license": "UNLICENSED",
|
|
14
13
|
"homepage": "https://griddo.io",
|
|
@@ -17,31 +16,31 @@
|
|
|
17
16
|
"url": "https://github.com/griddo/griddo"
|
|
18
17
|
},
|
|
19
18
|
"bin": {
|
|
20
|
-
"griddo-cx": "./
|
|
19
|
+
"griddo-cx": "./start-render.js"
|
|
21
20
|
},
|
|
22
21
|
"scripts": {
|
|
23
|
-
"build": "yarn build:exporter && yarn build:reset-render && yarn build:build-complete && yarn build:
|
|
24
|
-
"build:exporter": "esbuild ./
|
|
25
|
-
"build:build-complete": "esbuild ./
|
|
26
|
-
"build:reset-render": "esbuild ./
|
|
27
|
-
"build:
|
|
28
|
-
"
|
|
29
|
-
"
|
|
30
|
-
"
|
|
22
|
+
"build": "yarn build:exporter && yarn build:reset-render && yarn build:build-complete && yarn build:start-render && yarn build:run-start-render && yarn build:browser && yarn build:types",
|
|
23
|
+
"build:exporter": "esbuild ./src/index.ts --bundle --platform=node --minify --outfile=./build/index.js",
|
|
24
|
+
"build:build-complete": "esbuild ./src/build-complete.ts --bundle --platform=node --minify --outfile=./build/build-complete.js",
|
|
25
|
+
"build:reset-render": "esbuild ./src/reset-render.ts --bundle --platform=node --minify --outfile=./build/reset-render.js",
|
|
26
|
+
"build:start-render": "esbuild ./src/start-render.ts --bundle --platform=node --minify --outfile=./build/start-render.js",
|
|
27
|
+
"build:run-start-render": "esbuild ./src/run-start-render.ts --bundle --platform=node --minify --outfile=./build/run-start-render.js",
|
|
28
|
+
"build:browser": "esbuild ./src/browser/index.ts --platform=node --bundle --minify --outfile=./build/browser/index.js",
|
|
29
|
+
"build:types": "npx tsc --emitDeclarationOnly --declaration --outDir build --project tsconfig.json",
|
|
31
30
|
"export:complete": "node ./build/build-complete.js",
|
|
32
31
|
"export:reset": "node ./build/reset-render.js",
|
|
33
32
|
"prepare": "yarn run build",
|
|
34
33
|
"watch:tscheck": "tsc --noEmit --watch",
|
|
35
34
|
"complete-render": "node ./build/build-complete.js",
|
|
36
|
-
"reset-render": "node ./build/reset-render.js"
|
|
37
|
-
"download:data": "node ./build/create-build-data.js"
|
|
35
|
+
"reset-render": "node ./build/reset-render.js"
|
|
38
36
|
},
|
|
39
37
|
"dependencies": {
|
|
40
38
|
"@babel/core": "^7.21.0",
|
|
41
|
-
"@babel/plugin-
|
|
39
|
+
"@babel/plugin-transform-class-properties": "^7.24.1",
|
|
42
40
|
"@babel/preset-env": "^7.14.5",
|
|
43
41
|
"@babel/preset-react": "^7.14.5",
|
|
44
42
|
"@babel/preset-typescript": "^7.16.5",
|
|
43
|
+
"@griddo/core": "^10.4.13",
|
|
45
44
|
"@svgr/webpack": "^5.5.0",
|
|
46
45
|
"babel-loader": "^8.0.6",
|
|
47
46
|
"babel-plugin-styled-components": "^1.10.7",
|
|
@@ -51,9 +50,7 @@
|
|
|
51
50
|
"dotenv": "^8.1.0",
|
|
52
51
|
"find-up": "^5.0.0",
|
|
53
52
|
"fs-extra": "^9.0.1",
|
|
54
|
-
"gatsby": "
|
|
55
|
-
"gatsby-plugin-react-helmet": "^5.8.0",
|
|
56
|
-
"gatsby-plugin-svgr-loader": "^0.1.0",
|
|
53
|
+
"gatsby": "file:./ssg/gatsby",
|
|
57
54
|
"gradient-string": "^2.0.2",
|
|
58
55
|
"html-react-parser": "^1.4.10",
|
|
59
56
|
"js2xmlparser": "^4.0.1",
|
|
@@ -86,19 +83,14 @@
|
|
|
86
83
|
"node": ">=16.17.0"
|
|
87
84
|
},
|
|
88
85
|
"files": [
|
|
89
|
-
".babelrc",
|
|
90
|
-
"build",
|
|
91
|
-
"gatsby-browser.tsx",
|
|
92
|
-
"gatsby-config.ts",
|
|
93
|
-
"gatsby-node.ts",
|
|
94
|
-
"gatsby-ssr.tsx",
|
|
95
|
-
"exporter",
|
|
96
|
-
"index.js",
|
|
97
86
|
"src",
|
|
98
|
-
"
|
|
87
|
+
"ssg",
|
|
88
|
+
"build",
|
|
89
|
+
"start-render.js",
|
|
90
|
+
"cx.config.js",
|
|
91
|
+
"cx.config.d.ts"
|
|
99
92
|
],
|
|
100
93
|
"keywords": [
|
|
101
|
-
"gatsby",
|
|
102
94
|
"griddo",
|
|
103
95
|
"secuoyas",
|
|
104
96
|
"typescript",
|
|
@@ -110,5 +102,5 @@
|
|
|
110
102
|
"resolutions": {
|
|
111
103
|
"memoizee": "0.4.15"
|
|
112
104
|
},
|
|
113
|
-
"gitHead": "
|
|
105
|
+
"gitHead": "860786a44231619fd5c046df325e77e5e183d289"
|
|
114
106
|
}
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
import { spawnSync } from "node:child_process";
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
|
|
5
|
+
import { attempts, getGatsbyAssetPrefixSlug } from "./utils";
|
|
6
|
+
import { RobotsService } from "../../services/robots";
|
|
7
|
+
import { createBuildData } from "../../utils/create-build-data";
|
|
8
|
+
import { getInstanceDomains } from "../../utils/domains";
|
|
9
|
+
import {
|
|
10
|
+
clearEmptyDirs,
|
|
11
|
+
copyDirsSync,
|
|
12
|
+
createDirsSync,
|
|
13
|
+
moveDirsSync,
|
|
14
|
+
removeDirsSync,
|
|
15
|
+
removeVirtualPagesFromStore,
|
|
16
|
+
} from "../../utils/folders";
|
|
17
|
+
import { uploadSearchContentToAPI } from "../../utils/searches";
|
|
18
|
+
import {
|
|
19
|
+
doLifeCycle,
|
|
20
|
+
logBox,
|
|
21
|
+
pause,
|
|
22
|
+
printExporterLogo,
|
|
23
|
+
} from "../../utils/shared";
|
|
24
|
+
import { generateBuildReport, generateSitemaps } from "../../utils/sites";
|
|
25
|
+
import {
|
|
26
|
+
getConfig,
|
|
27
|
+
legacy__createDistFromGatsbyPublic,
|
|
28
|
+
} from "../../utils/temp-utils";
|
|
29
|
+
|
|
30
|
+
async function runGatsbyAdapter() {
|
|
31
|
+
printExporterLogo("gatsby");
|
|
32
|
+
|
|
33
|
+
const domains = await getInstanceDomains();
|
|
34
|
+
const config = getConfig();
|
|
35
|
+
|
|
36
|
+
for (const domain of domains) {
|
|
37
|
+
const {
|
|
38
|
+
__ssg: __gatsby,
|
|
39
|
+
__exports,
|
|
40
|
+
__caches,
|
|
41
|
+
__cx,
|
|
42
|
+
__components,
|
|
43
|
+
} = config.dirs(domain);
|
|
44
|
+
|
|
45
|
+
logBox(`Initializing render for the domain ${domain}`, "", 1, 0);
|
|
46
|
+
|
|
47
|
+
const assetPrefix = getGatsbyAssetPrefixSlug(domain);
|
|
48
|
+
const needsAssetPrefix = !!assetPrefix && assetPrefix !== "";
|
|
49
|
+
const shouldUploadSearchData = JSON.parse(
|
|
50
|
+
process.env.GRIDDO_SEARCH_FEATURE || "false"
|
|
51
|
+
);
|
|
52
|
+
|
|
53
|
+
/*
|
|
54
|
+
* Clean LifeCycle.
|
|
55
|
+
*
|
|
56
|
+
* We first secure the stage by removing artifacts from previous failed
|
|
57
|
+
* render. Both, griddo and gatsby artifacts.
|
|
58
|
+
*/
|
|
59
|
+
await doLifeCycle({
|
|
60
|
+
name: "Clean",
|
|
61
|
+
attempts: attempts.clean,
|
|
62
|
+
steps: [
|
|
63
|
+
() => removeDirsSync(__cx, ["store", "apiCache", "dist"]),
|
|
64
|
+
() => removeDirsSync(__gatsby, ["dist", "public", "static", ".cache"]),
|
|
65
|
+
() => pause("Clean LifeCycle"),
|
|
66
|
+
],
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
/*
|
|
70
|
+
* Prepare LifeCycle.
|
|
71
|
+
*
|
|
72
|
+
* We prepare the stage creating necessary directories: exports and
|
|
73
|
+
* caches.
|
|
74
|
+
*/
|
|
75
|
+
await doLifeCycle({
|
|
76
|
+
name: "Prepare",
|
|
77
|
+
attempts: attempts.prepare,
|
|
78
|
+
steps: [
|
|
79
|
+
() => createDirsSync([__exports]),
|
|
80
|
+
() => createDirsSync([__caches]),
|
|
81
|
+
() => pause("Prepare LifeCycle"),
|
|
82
|
+
],
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
/*
|
|
86
|
+
* Restore LifeCycle.
|
|
87
|
+
*/
|
|
88
|
+
await doLifeCycle({
|
|
89
|
+
name: "Restore",
|
|
90
|
+
attempts: attempts.restore,
|
|
91
|
+
steps: [
|
|
92
|
+
// Copy instance static directory into the gatsby one.
|
|
93
|
+
() => copyDirsSync(__components, __gatsby, ["static"]),
|
|
94
|
+
() => copyDirsSync(__exports, __cx, ["assets"]),
|
|
95
|
+
() => copyDirsSync(__exports, __gatsby, ["dist"]),
|
|
96
|
+
// Renames dist to public.
|
|
97
|
+
// En este paso de dist to public también se sacan los "assets"
|
|
98
|
+
// de public si el dominio es "pro-". Este proceso es sacar
|
|
99
|
+
// elementos del public y guardarlos en una carpeta "assets"
|
|
100
|
+
// para que infra los suba un subdominio.
|
|
101
|
+
() => {
|
|
102
|
+
if (fs.existsSync(path.join(__gatsby, "dist"))) {
|
|
103
|
+
fs.renameSync(
|
|
104
|
+
path.join(__gatsby, "dist"),
|
|
105
|
+
path.join(__gatsby, "public")
|
|
106
|
+
);
|
|
107
|
+
}
|
|
108
|
+
},
|
|
109
|
+
() => moveDirsSync(__caches, __cx, ["apiCache", "store"]),
|
|
110
|
+
() => moveDirsSync(__caches, __gatsby, [".cache"]),
|
|
111
|
+
() => pause("Restore LifeCycle"),
|
|
112
|
+
],
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
/*
|
|
116
|
+
* Data LifeCycle.
|
|
117
|
+
*/
|
|
118
|
+
await doLifeCycle({
|
|
119
|
+
name: "Data",
|
|
120
|
+
attempts: attempts.data,
|
|
121
|
+
steps: [
|
|
122
|
+
// API -> Store
|
|
123
|
+
() => createBuildData(domain),
|
|
124
|
+
() => pause("Data LifeCycle"),
|
|
125
|
+
],
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
/*
|
|
129
|
+
* SSG LifeCycle.
|
|
130
|
+
*/
|
|
131
|
+
await doLifeCycle({
|
|
132
|
+
name: "SSG",
|
|
133
|
+
attempts: attempts.ssg,
|
|
134
|
+
steps: [
|
|
135
|
+
() =>
|
|
136
|
+
// Run Gatsby
|
|
137
|
+
spawnSync("yarn", ["gatsby-build"], {
|
|
138
|
+
cwd: __gatsby,
|
|
139
|
+
stdio: ["ignore", "inherit", "ignore"],
|
|
140
|
+
encoding: "utf8",
|
|
141
|
+
shell: true,
|
|
142
|
+
env: Object.assign(process.env, {
|
|
143
|
+
GRIDDO_EXPORTER: "true",
|
|
144
|
+
GRIDDO_ASSET_PREFIX: assetPrefix,
|
|
145
|
+
}),
|
|
146
|
+
}),
|
|
147
|
+
() => pause("SSG LifeCycle"),
|
|
148
|
+
],
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
/*
|
|
152
|
+
* Relocation LifeCycle.
|
|
153
|
+
*/
|
|
154
|
+
await doLifeCycle({
|
|
155
|
+
name: "Relocation",
|
|
156
|
+
steps: [
|
|
157
|
+
() => legacy__createDistFromGatsbyPublic(domain, needsAssetPrefix),
|
|
158
|
+
() => pause("Relocation LifeCycle"),
|
|
159
|
+
],
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
/*
|
|
163
|
+
* Meta LifeCycle.
|
|
164
|
+
*/
|
|
165
|
+
await doLifeCycle({
|
|
166
|
+
name: "Meta",
|
|
167
|
+
attempts: attempts.meta,
|
|
168
|
+
steps: [
|
|
169
|
+
() => generateBuildReport(),
|
|
170
|
+
() => RobotsService.writeFiles(domain),
|
|
171
|
+
() => generateSitemaps(),
|
|
172
|
+
() => (shouldUploadSearchData ? uploadSearchContentToAPI() : undefined),
|
|
173
|
+
() => pause("Meta LifeCycle"),
|
|
174
|
+
],
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
/*
|
|
178
|
+
* Archive LifeCycle.
|
|
179
|
+
*/
|
|
180
|
+
await doLifeCycle({
|
|
181
|
+
name: "Archive",
|
|
182
|
+
attempts: attempts.archive,
|
|
183
|
+
steps: [
|
|
184
|
+
// Elimina las páginas de MultiPages y de templates de listados
|
|
185
|
+
// estáticos (mode: list) del `store`. De este modo nos
|
|
186
|
+
// aseguramos que se vuelven a crear por Gatsby siempre
|
|
187
|
+
// actualizadas. Esto es debido a que estas páinas son creadas
|
|
188
|
+
// en el contexto de CX y no tienen id único por lo que no son
|
|
189
|
+
// tenidas en cuenta por la API y por lo tanto escapan a la
|
|
190
|
+
// lógica de `changedPages` y la persistencia del store.
|
|
191
|
+
() => removeVirtualPagesFromStore(),
|
|
192
|
+
// Eliminamos carpetas vacías que puedan quedar de sites
|
|
193
|
+
// despublicados. Incluye aquellas que solo tengan archivos .xml
|
|
194
|
+
() => clearEmptyDirs(),
|
|
195
|
+
() =>
|
|
196
|
+
moveDirsSync(__cx, __exports, ["dist", "assets"], {
|
|
197
|
+
withBackup: true,
|
|
198
|
+
}),
|
|
199
|
+
() => moveDirsSync(__cx, __caches, ["apiCache", "store"]),
|
|
200
|
+
() => moveDirsSync(__gatsby, __caches, [".cache"]),
|
|
201
|
+
() => pause("Archive LifeCycle"),
|
|
202
|
+
],
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
/*
|
|
206
|
+
* Clean LifeCycle.
|
|
207
|
+
*/
|
|
208
|
+
await doLifeCycle({
|
|
209
|
+
name: "Clean",
|
|
210
|
+
steps: [
|
|
211
|
+
() => removeDirsSync(__gatsby, ["static", "public", "dist"]),
|
|
212
|
+
() => pause("Clean LifeCycle"),
|
|
213
|
+
],
|
|
214
|
+
attempts: attempts.clean,
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
export { runGatsbyAdapter };
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { Fields } from "@griddo/core";
|
|
2
|
+
import dotenv from "dotenv";
|
|
3
|
+
|
|
4
|
+
import { getConfig } from "../../utils/temp-utils";
|
|
5
|
+
|
|
6
|
+
dotenv.config();
|
|
7
|
+
|
|
8
|
+
const attempts = {
|
|
9
|
+
prepare: JSON.parse(process.env.GRIDDO_PREPARE_LIFECYCLE_MAX_ATTEMPTS || "1"),
|
|
10
|
+
restore: JSON.parse(process.env.GRIDDO_RESTORE_LIFECYCLE_MAX_ATTEMPTS || "1"),
|
|
11
|
+
data: JSON.parse(process.env.GRIDDO_DATA_LIFECYCLE_MAX_ATTEMPTS || "1"),
|
|
12
|
+
ssg: JSON.parse(process.env.GRIDDO_SSG_LIFECYCLE_MAX_ATTEMPTS || "1"),
|
|
13
|
+
relocation: JSON.parse(
|
|
14
|
+
process.env.GRIDDO_RELOCATION_LIFECYCLE_MAX_ATTEMPTS || "1"
|
|
15
|
+
),
|
|
16
|
+
meta: JSON.parse(process.env.GRIDDO_META_LIFECYCLE_MAX_ATTEMPTS || "1"),
|
|
17
|
+
archive: JSON.parse(process.env.GRIDDO_ARCHIVE_LIFECYCLE_MAX_ATTEMPTS || "1"),
|
|
18
|
+
clean: JSON.parse(process.env.GRIDDO_CLEAN_LIFECYCLE_MAX_ATTEMPTS || "1"),
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Return the assetPrefix url `assetPrefix/domain`
|
|
23
|
+
*/
|
|
24
|
+
function getGatsbyAssetPrefixSlug(domain: string) {
|
|
25
|
+
const { proDomain } = getConfig();
|
|
26
|
+
const assetPrefix =
|
|
27
|
+
process.env.GRIDDO_ASSET_PREFIX || process.env.ASSET_PREFIX;
|
|
28
|
+
|
|
29
|
+
if (!assetPrefix || !domain) return "";
|
|
30
|
+
if (!domain.startsWith(proDomain)) return "";
|
|
31
|
+
|
|
32
|
+
return `${assetPrefix}/${domain}`;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Format Cloudinary or DAM URL
|
|
37
|
+
*
|
|
38
|
+
* @param image The image url
|
|
39
|
+
* @param width With of the image
|
|
40
|
+
* @param height Height of the image
|
|
41
|
+
* @param format Format of the image
|
|
42
|
+
* @returns A composed URL for the Cloudinary or DAM service
|
|
43
|
+
*/
|
|
44
|
+
function formatImage(
|
|
45
|
+
image: Fields.Image | string,
|
|
46
|
+
width: number,
|
|
47
|
+
height: number,
|
|
48
|
+
format = "jpg"
|
|
49
|
+
) {
|
|
50
|
+
const url = typeof image === "string" ? image : image?.url;
|
|
51
|
+
|
|
52
|
+
if (!url) {
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const isCloudinary = url.split("/")[2].includes("cloudinary.com");
|
|
57
|
+
|
|
58
|
+
return isCloudinary
|
|
59
|
+
? addCloudinaryParams(url, `c_fill,w_${width},h_${height}`)
|
|
60
|
+
: addGriddoDamParams(url, `f/${format}/w/${width}/h/${height}`);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Format Griddo DAM image url.
|
|
65
|
+
*/
|
|
66
|
+
function addGriddoDamParams(image: string, params: string) {
|
|
67
|
+
const urlParts = image.split("/");
|
|
68
|
+
const imagePath = urlParts.slice(0, -1).join("/");
|
|
69
|
+
const imageName = urlParts.slice(-1)[0];
|
|
70
|
+
|
|
71
|
+
return `${imagePath}/${params}/${imageName}`;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Take a cloudinary url and add query params.
|
|
76
|
+
*/
|
|
77
|
+
function addCloudinaryParams(image: string, params: string) {
|
|
78
|
+
const plainUrl = image.replace("https://", "");
|
|
79
|
+
const head = plainUrl.split("/").slice(0, 4).join("/");
|
|
80
|
+
const fullId = plainUrl.replace(head, "");
|
|
81
|
+
|
|
82
|
+
return `https://${head}/${params}${fullId}`;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export { attempts, formatImage, getGatsbyAssetPrefixSlug };
|