@griddo/cx 10.4.2 → 10.4.3
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/build-complete.js +18 -18
- package/build/create-build-data.js +19 -19
- package/build/index.js +30 -35
- package/build/reset-render.js +16 -16
- package/exporter/adapters/astro/index.ts +2 -2
- package/exporter/adapters/gatsby/index.ts +47 -125
- package/exporter/adapters/gatsby/utils.ts +6 -9
- package/exporter/build-complete.ts +1 -1
- package/exporter/index.ts +6 -9
- package/exporter/services/store.ts +5 -5
- package/exporter/types/global.ts +25 -9
- package/exporter/utils/cache.ts +4 -4
- package/exporter/utils/download-build-data.ts +10 -10
- package/exporter/utils/folders.ts +236 -43
- package/exporter/utils/searches.ts +14 -18
- package/exporter/utils/shared.ts +58 -33
- package/exporter/utils/store.ts +24 -24
- package/gatsby-node.ts +8 -10
- package/index.js +1 -1
- package/package.json +3 -3
- package/src/README.md +3 -3
- package/src/gatsby-node-utils.ts +5 -5
- package/src/types.ts +13 -5
- package/static/robots.txt +1 -1
package/exporter/utils/store.ts
CHANGED
|
@@ -12,8 +12,8 @@ import { removeProperties, walk } from "./shared";
|
|
|
12
12
|
import { Site } from "../types/sites";
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
|
-
* Read all pages stored in `store` Griddo
|
|
16
|
-
* generator.
|
|
15
|
+
* Read all pages stored in `store` Griddo directory and return one by one with
|
|
16
|
+
* a generator.
|
|
17
17
|
*/
|
|
18
18
|
async function* getBuildPages<PageType extends GriddoPageObject>(
|
|
19
19
|
basePath: string
|
|
@@ -56,12 +56,12 @@ function getBuildMetadata(basePath: string): BuildMetaData {
|
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
/**
|
|
59
|
-
* Creates an `store`
|
|
59
|
+
* Creates an `store` dir to store pages transformed by createStore
|
|
60
60
|
*/
|
|
61
|
-
function
|
|
62
|
-
if (!fs.existsSync(
|
|
63
|
-
fs.mkdirSync(
|
|
64
|
-
fs.mkdirSync(path.resolve(
|
|
61
|
+
function createStoreDir(storeDir: string) {
|
|
62
|
+
if (!fs.existsSync(storeDir)) {
|
|
63
|
+
fs.mkdirSync(storeDir);
|
|
64
|
+
fs.mkdirSync(path.resolve(storeDir, "metadata"));
|
|
65
65
|
}
|
|
66
66
|
|
|
67
67
|
console.info("Store initialized");
|
|
@@ -69,7 +69,7 @@ function createStoreFolder(storeFolder: string) {
|
|
|
69
69
|
|
|
70
70
|
/**
|
|
71
71
|
* Write render info into a file.
|
|
72
|
-
* @param basePath - Absolute path of the
|
|
72
|
+
* @param basePath - Absolute path of the dir from which files will be saved.
|
|
73
73
|
* @param renderInfo - Data that will be saved related to the render process.
|
|
74
74
|
*/
|
|
75
75
|
function saveRenderInfoInStore(basePath: string, renderInfo: RenderInfo) {
|
|
@@ -80,26 +80,26 @@ function saveRenderInfoInStore(basePath: string, renderInfo: RenderInfo) {
|
|
|
80
80
|
}
|
|
81
81
|
|
|
82
82
|
/**
|
|
83
|
-
* Return an array of ids only from `.json` files (no dirs) in the `basePath`
|
|
84
|
-
* @param basePath - Absolute path of the
|
|
85
|
-
* @returns A Array<number> of pages ids in `basePath`
|
|
83
|
+
* Return an array of ids only from `.json` files (no dirs) in the `basePath` dir based in the file name and filtered by the pages ids in a concrete site.
|
|
84
|
+
* @param basePath - Absolute path of the dir from which files will be read.
|
|
85
|
+
* @returns A Array<number> of pages ids in `basePath` dir filtered by pages ids in a concrete site.
|
|
86
86
|
*/
|
|
87
|
-
function
|
|
87
|
+
function getPagesInStoreDirBySitePages(
|
|
88
88
|
basePath: string,
|
|
89
89
|
pages: Array<number>
|
|
90
90
|
): Array<number> {
|
|
91
|
-
const allPagesInStore =
|
|
91
|
+
const allPagesInStore = getPageInStoreDir(basePath);
|
|
92
92
|
const pagesBySite = allPagesInStore.filter((page) => pages.includes(page));
|
|
93
93
|
|
|
94
94
|
return pagesBySite;
|
|
95
95
|
}
|
|
96
96
|
|
|
97
97
|
/**
|
|
98
|
-
* Return an array of ids only from `.json` files (no dirs) in the `basePath`
|
|
99
|
-
* @param basePath - Absolute path of the
|
|
100
|
-
* @returns A Array<number> of pages ids in `basePath`
|
|
98
|
+
* Return an array of ids only from `.json` files (no dirs) in the `basePath` dir based in the file name.
|
|
99
|
+
* @param basePath - Absolute path of the dir from which files will be read.
|
|
100
|
+
* @returns A Array<number> of pages ids in `basePath` dir.
|
|
101
101
|
*/
|
|
102
|
-
function
|
|
102
|
+
function getPageInStoreDir(basePath: string): Array<number> {
|
|
103
103
|
const filesInStore = fs.readdirSync(basePath);
|
|
104
104
|
|
|
105
105
|
return (
|
|
@@ -134,7 +134,7 @@ function getPageInStoreFolder(basePath: string): Array<number> {
|
|
|
134
134
|
|
|
135
135
|
/**
|
|
136
136
|
* Save the pages into the file system.
|
|
137
|
-
* @param basePath - Absolute path of the
|
|
137
|
+
* @param basePath - Absolute path of the dir from which files will be saved.
|
|
138
138
|
* @param pages - An array of Griddo page objects to be saved.
|
|
139
139
|
*/
|
|
140
140
|
function savePagesInStore(basePath: string, pages: Array<GriddoPageObject>) {
|
|
@@ -147,8 +147,8 @@ function savePagesInStore(basePath: string, pages: Array<GriddoPageObject>) {
|
|
|
147
147
|
}
|
|
148
148
|
|
|
149
149
|
/**
|
|
150
|
-
* Remove files from
|
|
151
|
-
* @param basePath - Absolute path of the
|
|
150
|
+
* Remove files from dir.
|
|
151
|
+
* @param basePath - Absolute path of the dir from which files will be removed.
|
|
152
152
|
* @param filenames - An array of ids representing file page names.
|
|
153
153
|
*/
|
|
154
154
|
function removePagesFromStore(basePath: string, filenames: Array<number>) {
|
|
@@ -169,14 +169,14 @@ function removePagesFromStore(basePath: string, filenames: Array<number>) {
|
|
|
169
169
|
/**
|
|
170
170
|
* Returns pages that need to be created or deleted for a site in the store based on the provided arguments.
|
|
171
171
|
* @param sitePages - Properties for page retrieval.
|
|
172
|
-
* @param props.
|
|
172
|
+
* @param props.storeDir - Absolute path of the Griddo store.
|
|
173
173
|
* @param props.pages - Exhaustive array of all pages in the site.
|
|
174
174
|
* @param props.validPagesIds - Array of valid pages in the site.
|
|
175
175
|
* @param props.changedPages - Array of pages that have been modified in the site.
|
|
176
176
|
* @returns - An object containing the pages to be created and deleted in the site.
|
|
177
177
|
*/
|
|
178
178
|
async function getPagesToCreateOrDelete(
|
|
179
|
-
|
|
179
|
+
storeDir: string,
|
|
180
180
|
sitePages: {
|
|
181
181
|
sitesToPublish: Array<Site>;
|
|
182
182
|
pages: Array<number>;
|
|
@@ -187,7 +187,7 @@ async function getPagesToCreateOrDelete(
|
|
|
187
187
|
const { changedPages, pages, validPagesIds, sitesToPublish } = sitePages;
|
|
188
188
|
// Array<ids> de las páginas que están físicamente en el store en el
|
|
189
189
|
// site actual del bucle.
|
|
190
|
-
const pagesInStore =
|
|
190
|
+
const pagesInStore = getPagesInStoreDirBySitePages(storeDir, pages);
|
|
191
191
|
|
|
192
192
|
// Array<ids> que están el `validPagesIds` pero no están por algún
|
|
193
193
|
// motivo en el store. Se incluyen porque deben ser creadas.
|
|
@@ -240,7 +240,7 @@ async function getPagesToCreateOrDelete(
|
|
|
240
240
|
}
|
|
241
241
|
|
|
242
242
|
export {
|
|
243
|
-
|
|
243
|
+
createStoreDir,
|
|
244
244
|
getBuildMetadata,
|
|
245
245
|
getBuildPages,
|
|
246
246
|
getPagesToCreateOrDelete,
|
package/gatsby-node.ts
CHANGED
|
@@ -8,14 +8,14 @@ import { generateBuildReport, generateSitemaps } from "./exporter/utils/sites";
|
|
|
8
8
|
import { getBuildMetadata, getBuildPages } from "./exporter/utils/store";
|
|
9
9
|
import {
|
|
10
10
|
getMatchPath,
|
|
11
|
-
|
|
11
|
+
prepareStaticDir,
|
|
12
12
|
updateDist,
|
|
13
13
|
} from "./src/gatsby-node-utils";
|
|
14
14
|
import { GatsbyPageObject } from "./src/types";
|
|
15
15
|
|
|
16
|
-
const
|
|
17
|
-
const
|
|
18
|
-
const reportFilePath = path.resolve(
|
|
16
|
+
const publicDirPath = path.resolve(__dirname, "./public");
|
|
17
|
+
const storeDirPath = path.resolve(__dirname, "./store/");
|
|
18
|
+
const reportFilePath = path.resolve(publicDirPath, "__build-report__.json");
|
|
19
19
|
const gatsbyTemplateFile = path.resolve(
|
|
20
20
|
__dirname,
|
|
21
21
|
"./src/components/template.tsx"
|
|
@@ -23,14 +23,14 @@ const gatsbyTemplateFile = path.resolve(
|
|
|
23
23
|
|
|
24
24
|
// onPreInit
|
|
25
25
|
const onPreInit = async () => {
|
|
26
|
-
|
|
26
|
+
prepareStaticDir();
|
|
27
27
|
};
|
|
28
28
|
|
|
29
29
|
// createPages
|
|
30
30
|
const createPages: GatsbyNode["createPages"] = async ({
|
|
31
31
|
actions: { createPage },
|
|
32
32
|
}) => {
|
|
33
|
-
const pages = getBuildPages<GatsbyPageObject>(
|
|
33
|
+
const pages = getBuildPages<GatsbyPageObject>(storeDirPath);
|
|
34
34
|
|
|
35
35
|
for await (const page of pages) {
|
|
36
36
|
// SECURITY
|
|
@@ -55,12 +55,10 @@ const createPages: GatsbyNode["createPages"] = async ({
|
|
|
55
55
|
|
|
56
56
|
// onPostBuild
|
|
57
57
|
const onPostBuild = async () => {
|
|
58
|
-
const { buildProcessData, sitesToPublish } = getBuildMetadata(
|
|
59
|
-
storeFolderPath
|
|
60
|
-
);
|
|
58
|
+
const { buildProcessData, sitesToPublish } = getBuildMetadata(storeDirPath);
|
|
61
59
|
|
|
62
60
|
await generateBuildReport(reportFilePath, buildProcessData);
|
|
63
|
-
await RobotsService.writeFiles(
|
|
61
|
+
await RobotsService.writeFiles(publicDirPath);
|
|
64
62
|
await generateSitemaps(sitesToPublish);
|
|
65
63
|
await updateDist();
|
|
66
64
|
};
|
package/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@griddo/cx",
|
|
3
3
|
"description": "Griddo SSG based on Gatsby",
|
|
4
|
-
"version": "10.4.
|
|
4
|
+
"version": "10.4.3",
|
|
5
5
|
"authors": [
|
|
6
6
|
"Álvaro Sánchez' <alvaro.sanches@secuoyas.com>",
|
|
7
7
|
"Diego M. Béjar <diego.bejar@secuoyas.com>",
|
|
@@ -70,7 +70,7 @@
|
|
|
70
70
|
"react-helmet": "^6.0.0"
|
|
71
71
|
},
|
|
72
72
|
"devDependencies": {
|
|
73
|
-
"@griddo/eslint-config-back": "^10.4.
|
|
73
|
+
"@griddo/eslint-config-back": "^10.4.3",
|
|
74
74
|
"@types/babel__core": "^7.20.0",
|
|
75
75
|
"@types/babel__preset-env": "^7.9.2",
|
|
76
76
|
"@types/csvtojson": "^2.0.0",
|
|
@@ -117,5 +117,5 @@
|
|
|
117
117
|
"publishConfig": {
|
|
118
118
|
"access": "public"
|
|
119
119
|
},
|
|
120
|
-
"gitHead": "
|
|
120
|
+
"gitHead": "e75e4dc2c9fbc163ccbf9050792be04591530b6a"
|
|
121
121
|
}
|
package/src/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# Griddo CX + Gatsby
|
|
2
2
|
|
|
3
|
-
The `/src`
|
|
3
|
+
The `/src` dir and almost every file in the root dir is now 100% Gatsby related code along with the historical `/public`, `/dist`, `/apiCache`, `/store`, etc.. render dirs.
|
|
4
4
|
|
|
5
|
-
Griddo CX code (the business logic) is now in `/exporter`
|
|
5
|
+
Griddo CX code (the business logic) is now in `/exporter` dir.
|
|
6
6
|
|
|
7
|
-
In the future, Griddo CX and Gatsby will split int their own packages
|
|
7
|
+
In the future, Griddo CX and Gatsby will split int their own packages dirs inside the mono-repo.
|
package/src/gatsby-node-utils.ts
CHANGED
|
@@ -11,9 +11,9 @@ import {
|
|
|
11
11
|
} from "../exporter/utils/instance";
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
|
-
* Copy the instance's `/static`
|
|
14
|
+
* Copy the instance's `/static` dir into the Gatsby's to include it in the render assets.
|
|
15
15
|
*/
|
|
16
|
-
function
|
|
16
|
+
function prepareStaticDir() {
|
|
17
17
|
const src = resolveComponentsPath("static");
|
|
18
18
|
const dest = "./static";
|
|
19
19
|
|
|
@@ -26,14 +26,14 @@ function prepareStaticFolder() {
|
|
|
26
26
|
fs.copySync(fileSrc, fileDest);
|
|
27
27
|
});
|
|
28
28
|
|
|
29
|
-
console.info("Components static
|
|
29
|
+
console.info("Components `static` dir copied");
|
|
30
30
|
} catch (err) {
|
|
31
31
|
console.error(err);
|
|
32
32
|
}
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
/**
|
|
36
|
-
* Update the Griddo's `/dist`
|
|
36
|
+
* Update the Griddo's `/dist` dir with the contents from `/public` only with files of type:
|
|
37
37
|
* - js
|
|
38
38
|
* - json
|
|
39
39
|
* - css
|
|
@@ -148,7 +148,7 @@ function getMatchPath(domain: string, compose: string) {
|
|
|
148
148
|
export {
|
|
149
149
|
getMatchPath,
|
|
150
150
|
onCreateWebpackConfig,
|
|
151
|
-
|
|
151
|
+
prepareStaticDir,
|
|
152
152
|
updateDist,
|
|
153
153
|
getGatsbyAssetPrefixSlug,
|
|
154
154
|
};
|
package/src/types.ts
CHANGED
|
@@ -10,7 +10,7 @@ import type { Site } from "../exporter/types/sites";
|
|
|
10
10
|
import type { Core } from "@griddo/core";
|
|
11
11
|
import type { HeadProps } from "gatsby";
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
interface CustomHeadProps extends HeadProps {
|
|
14
14
|
pageContext: GriddoPageObject["context"] & {
|
|
15
15
|
page: Core.Page & {
|
|
16
16
|
defaultLang: { id: number };
|
|
@@ -20,7 +20,7 @@ export interface CustomHeadProps extends HeadProps {
|
|
|
20
20
|
};
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
|
|
23
|
+
interface TemplateProps extends Omit<GriddoPageObject, "context"> {
|
|
24
24
|
pageContext: GriddoPageObject["context"] & {
|
|
25
25
|
page: Core.Page;
|
|
26
26
|
};
|
|
@@ -31,7 +31,7 @@ export interface TemplateProps extends Omit<GriddoPageObject, "context"> {
|
|
|
31
31
|
};
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
-
|
|
34
|
+
interface HtmlProps {
|
|
35
35
|
body: string;
|
|
36
36
|
bodyAttributes: React.HtmlHTMLAttributes<HTMLBodyElement>;
|
|
37
37
|
headComponents: React.ReactNode;
|
|
@@ -40,7 +40,7 @@ export interface HtmlProps {
|
|
|
40
40
|
preBodyComponents: React.ReactNode;
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
-
|
|
43
|
+
interface Dimensions {
|
|
44
44
|
values: Record<string, string> | null;
|
|
45
45
|
contentSelect?: "group" | "individual" | null;
|
|
46
46
|
groupSelect?: string;
|
|
@@ -48,7 +48,7 @@ export interface Dimensions {
|
|
|
48
48
|
}
|
|
49
49
|
|
|
50
50
|
// TODO: JSDoc
|
|
51
|
-
|
|
51
|
+
type GatsbyPageObject = {
|
|
52
52
|
matchPath?: string;
|
|
53
53
|
path: string;
|
|
54
54
|
component: string;
|
|
@@ -95,3 +95,11 @@ export type GatsbyPageObject = {
|
|
|
95
95
|
page: GriddoSinglePage | GriddoListPage | GriddoMultiPage;
|
|
96
96
|
};
|
|
97
97
|
};
|
|
98
|
+
|
|
99
|
+
export {
|
|
100
|
+
CustomHeadProps,
|
|
101
|
+
Dimensions,
|
|
102
|
+
GatsbyPageObject,
|
|
103
|
+
HtmlProps,
|
|
104
|
+
TemplateProps,
|
|
105
|
+
};
|
package/static/robots.txt
CHANGED