@griddo/cx 10.3.13 → 10.3.15

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.
Files changed (61) hide show
  1. package/README.md +53 -30
  2. package/build/build-complete.js +24 -20
  3. package/build/download-data.js +53 -0
  4. package/build/index.js +35 -47
  5. package/build/reset-render.js +25 -21
  6. package/exporter/adapters/astro/index.ts +37 -0
  7. package/exporter/adapters/astro/utils.ts +29 -0
  8. package/exporter/adapters/gatsby/index.ts +86 -0
  9. package/exporter/adapters/gatsby/utils.ts +352 -0
  10. package/exporter/adapters/index.ts +5 -0
  11. package/{scripts → exporter}/build-complete.ts +16 -14
  12. package/exporter/download-data.ts +6 -0
  13. package/exporter/index-width-adapter.ts +25 -0
  14. package/exporter/index.ts +14 -0
  15. package/exporter/reset-render.ts +12 -0
  16. package/{src → exporter}/services/auth.ts +0 -2
  17. package/{src → exporter}/services/distributors.ts +10 -1
  18. package/{src → exporter}/services/robots.ts +9 -6
  19. package/exporter/services/store.ts +351 -0
  20. package/{src → exporter}/types/api.ts +6 -0
  21. package/{src → exporter}/types/pages.ts +18 -17
  22. package/{src → exporter}/types/sites.ts +1 -1
  23. package/{src → exporter}/utils/api.ts +10 -7
  24. package/{src → exporter}/utils/cache.ts +14 -8
  25. package/{src → exporter}/utils/domains.ts +3 -3
  26. package/exporter/utils/download-build-data.ts +22 -0
  27. package/exporter/utils/folders.ts +49 -0
  28. package/{src → exporter}/utils/health-checks.ts +8 -7
  29. package/{src → exporter}/utils/instance.ts +1 -1
  30. package/{src/utils/integrations.tsx → exporter/utils/integrations.ts} +6 -4
  31. package/{src → exporter}/utils/pages.ts +21 -24
  32. package/exporter/utils/runners.ts +53 -0
  33. package/{src → exporter}/utils/shared.ts +31 -29
  34. package/{src → exporter}/utils/sites.ts +7 -7
  35. package/exporter/utils/store.ts +56 -0
  36. package/gatsby-config.ts +1 -1
  37. package/gatsby-node.ts +38 -72
  38. package/index.js +4 -1
  39. package/package.json +13 -10
  40. package/src/README.md +7 -0
  41. package/src/components/Head.tsx +3 -3
  42. package/src/components/template.tsx +3 -4
  43. package/src/gatsby-node-utils.ts +154 -0
  44. package/src/html.tsx +1 -1
  45. package/src/types.ts +98 -0
  46. package/src/{components/utils.ts → utils.ts} +6 -8
  47. package/static/robots.txt +1 -0
  48. package/scripts/griddo-exporter.ts +0 -431
  49. package/scripts/reset-render.ts +0 -9
  50. package/src/components/types.ts +0 -40
  51. package/src/services/store.ts +0 -423
  52. package/src/utils/folders.ts +0 -125
  53. package/src/utils/gatsby.ts +0 -47
  54. /package/{src → exporter}/services/domains.ts +0 -0
  55. /package/{src → exporter}/services/navigation.ts +0 -0
  56. /package/{src → exporter}/services/settings.ts +0 -0
  57. /package/{src → exporter}/services/sites.ts +0 -0
  58. /package/{src → exporter}/types/global.ts +0 -0
  59. /package/{src → exporter}/types/navigation.ts +0 -0
  60. /package/{src → exporter}/types/templates.ts +0 -0
  61. /package/{src → exporter}/utils/searches.ts +0 -0
@@ -1,7 +1,7 @@
1
- import { PageIntegration } from "@griddo/core/dist/types/core";
1
+ import { Core } from "@griddo/core";
2
2
 
3
3
  export const filterBodyIntegrationFromPosition = (
4
- integrations: PageIntegration[],
4
+ integrations: Array<Core.PageIntegration>,
5
5
  position: "start" | "end"
6
6
  ) =>
7
7
  integrations
@@ -13,7 +13,9 @@ export const filterBodyIntegrationFromPosition = (
13
13
  )
14
14
  .map((integration) => integration.contentBody!) || [];
15
15
 
16
- export const filterHeadIntegrations = (integrations: PageIntegration[]) =>
16
+ export const filterHeadIntegrations = (
17
+ integrations: Array<Core.PageIntegration>
18
+ ) =>
17
19
  integrations
18
20
  ?.filter(
19
21
  (integration) =>
@@ -22,7 +24,7 @@ export const filterHeadIntegrations = (integrations: PageIntegration[]) =>
22
24
  .map((integration) => integration.contentHead!) || [];
23
25
 
24
26
  export const filterPositionIntegrations = (
25
- integrations: PageIntegration[],
27
+ integrations: Array<Core.PageIntegration>,
26
28
  position: "head" | "start" | "end"
27
29
  ) => {
28
30
  switch (position) {
@@ -1,8 +1,8 @@
1
1
  import type {
2
2
  APIPageObject,
3
- GatsbyPageObject,
4
3
  GriddoListPage,
5
4
  GriddoMultiPage,
5
+ GriddoPageObject,
6
6
  GriddoSinglePage,
7
7
  MultiPageElement,
8
8
  MultiPageElements,
@@ -11,13 +11,13 @@ import type {
11
11
  import type { TemplateWithDistributor } from "../types/templates";
12
12
  import type { Core, Fields } from "@griddo/core";
13
13
 
14
- import fs from "fs";
15
- import path from "path";
14
+ import fs from "node:fs";
15
+ import path from "node:path";
16
16
 
17
17
  import dotenv from "dotenv";
18
18
 
19
19
  import { postSearchInfo } from "./searches";
20
- import { formatImage } from "../components/utils";
20
+ import { formatImage } from "../../src/utils";
21
21
 
22
22
  dotenv.config();
23
23
 
@@ -25,13 +25,12 @@ dotenv.config();
25
25
  const GRIDDO_SEARCH_FEATURE = !!JSON.parse(
26
26
  process.env.GRIDDO_SEARCH_FEATURE || "false"
27
27
  );
28
- const NEEDS_ASSET_PREFIX = !!process.env.NEEDS_ASSET_DOMAIN_PREFIX;
29
- const STRIP_DOMAIN_FROM_PATH =
30
- !!process.env.GRIDDO_EXPORT_STRIP_DOMAIN_FROM_PATH;
28
+ const STRIP_DOMAIN_FROM_PATH = JSON.parse(
29
+ process.env.GRIDDO_EXPORT_STRIP_DOMAIN_FROM_PATH || "false"
30
+ );
31
31
 
32
32
  // Consts
33
33
  const DEFAULT_ITEMS_PER_PAGE_FOR_LIST_TEMPLATES = 25;
34
- const COMPONENT = path.resolve(__dirname, "../../src/components/template.tsx");
35
34
 
36
35
  /**
37
36
  * Return an OpenGraph object.
@@ -110,17 +109,17 @@ function getPageMetaData(params: Core.Page): Core.Page["pageMetaData"] {
110
109
  }
111
110
 
112
111
  /**
113
- * Create a page object to be processes by Gatsby `createPage()`
112
+ * Create a Griddo page object
114
113
  *
115
114
  * @param page A page object ready to pass as content of the `pageContext` to use in the React template.
116
115
  * @param additionalInfo Additional page info to pass as content of `pageContext` to use in the React template.
117
116
  * @param excludeFromSearch Boolean to avoid this page to be indexed in internal search tool.
118
117
  */
119
- async function createGatsbyPageObject(
118
+ async function createGriddoPageObject(
120
119
  page: GriddoSinglePage | GriddoListPage | GriddoMultiPage,
121
120
  additionalInfo: PageAdditionalInfo,
122
121
  excludeFromSearch = false
123
- ): Promise<GatsbyPageObject> {
122
+ ): Promise<GriddoPageObject> {
124
123
  // Extract some props from page
125
124
  const {
126
125
  id,
@@ -175,10 +174,8 @@ async function createGatsbyPageObject(
175
174
 
176
175
  const renderDate = new Date().toString();
177
176
 
178
- const pageObjectForGatsby: GatsbyPageObject = {
177
+ const griddoPageObject: GriddoPageObject = {
179
178
  path: pagePath,
180
- matchPath: NEEDS_ASSET_PREFIX ? fullPath.compose : "",
181
- component: COMPONENT,
182
179
  size: undefined,
183
180
  context: {
184
181
  // Page
@@ -239,7 +236,7 @@ async function createGatsbyPageObject(
239
236
  });
240
237
  }
241
238
 
242
- return pageObjectForGatsby;
239
+ return griddoPageObject;
243
240
  }
244
241
 
245
242
  /**
@@ -248,17 +245,17 @@ async function createGatsbyPageObject(
248
245
  * @param page A Griddo single page object.
249
246
  * @param additionalInfo Additional page info.
250
247
  */
251
- async function createGriddoSinglePageForGatsby(
248
+ async function createGriddoSinglePage(
252
249
  page: GriddoSinglePage,
253
250
  additionalInfo: PageAdditionalInfo
254
251
  ) {
255
- return await createGatsbyPageObject(page, additionalInfo);
252
+ return await createGriddoPageObject(page, additionalInfo);
256
253
  }
257
254
 
258
255
  /**
259
256
  * Create multiples pages from one page as list paginated pages
260
257
  */
261
- async function createGriddoListPagesForGatsby(
258
+ async function createGriddoListPages(
262
259
  {
263
260
  page,
264
261
  pages,
@@ -305,7 +302,7 @@ async function createGriddoListPagesForGatsby(
305
302
  defaultLang,
306
303
  };
307
304
 
308
- return await createGatsbyPageObject(
305
+ return await createGriddoPageObject(
309
306
  paginatedPage,
310
307
  additionalInfo,
311
308
  !isFirstPage
@@ -321,7 +318,7 @@ async function createGriddoListPagesForGatsby(
321
318
  * @param page A Griddo Multipage object.
322
319
  * @param additionalInfo Additional page info.
323
320
  */
324
- function createGriddoMultiPagesForGatsby(
321
+ function createGriddoMultiPages(
325
322
  page: GriddoMultiPage,
326
323
  additionalInfo: PageAdditionalInfo
327
324
  ) {
@@ -378,7 +375,7 @@ function createGriddoMultiPagesForGatsby(
378
375
  paginatedPage.metaTitle =
379
376
  metaTitle.trim() || title.trim() || paginatedPage.metaTitle;
380
377
 
381
- return await createGatsbyPageObject(paginatedPage, additionalInfo);
378
+ return await createGriddoPageObject(paginatedPage, additionalInfo);
382
379
  });
383
380
 
384
381
  return Promise.all(allPages);
@@ -558,9 +555,9 @@ function addPageNumberToTitle(title: string, pageNumber: number) {
558
555
  }
559
556
 
560
557
  export {
561
- createGriddoListPagesForGatsby,
562
- createGriddoMultiPagesForGatsby,
563
- createGriddoSinglePageForGatsby,
558
+ createGriddoListPages,
559
+ createGriddoMultiPages,
560
+ createGriddoSinglePage,
564
561
  getMultiPageElements,
565
562
  getPaginatedPages,
566
563
  };
@@ -0,0 +1,53 @@
1
+ import { spawnSync } from "node:child_process";
2
+
3
+ import dotenv from "dotenv";
4
+ import pkgDir from "pkg-dir";
5
+
6
+ dotenv.config();
7
+
8
+ type Env = Record<string, unknown>;
9
+
10
+ // Where we are going to run the export command
11
+ const workingPath = pkgDir.sync(__dirname)!;
12
+
13
+ /**
14
+ * Get a command runner function using the environments variables passed in
15
+ * `env`.
16
+ *
17
+ * @example
18
+ * const run = getEnvRunner({
19
+ * ENV_VAR_1: "Foo",
20
+ * ENV_VAR_2: "Bar"
21
+ * });
22
+ * run("cp file.txt file2.txt");
23
+ */
24
+ function getEnvRunner(env: Env) {
25
+ return (command: string) => runner(command, env);
26
+ }
27
+
28
+ /**
29
+ * Execute a command using the environments variables passed as arguments in env
30
+ */
31
+ function runner(command: string, env: Env) {
32
+ // TODO: Cuando esto falle, ejecutar `cleanAfterFail`
33
+ const [commandName, ...args] = command.split(" ");
34
+ const { error, status } = spawnSync(commandName, args, {
35
+ cwd: workingPath,
36
+ stdio: ["ignore", "inherit", "ignore"],
37
+ encoding: "utf8",
38
+ shell: true,
39
+ env: Object.assign({ GRIDDO_EXPORTER: "true" }, process.env, env),
40
+ });
41
+
42
+ if (error) {
43
+ console.error(error);
44
+ process.exit(1);
45
+ }
46
+
47
+ if (status !== 0) {
48
+ console.error(`Command \`${command}\` exited with code ${status}`);
49
+ process.exit(1);
50
+ }
51
+ }
52
+
53
+ export { getEnvRunner };
@@ -2,21 +2,25 @@ import type { APIResponses } from "../types/api";
2
2
  import type { APIPageObject } from "../types/pages";
3
3
  import type { Site } from "../types/sites";
4
4
 
5
+ import { Adapters } from "@exporter/adapters";
5
6
  import chalk from "chalk";
6
7
  import dotenv from "dotenv";
7
8
  import fs from "fs-extra";
8
9
  import gradient from "gradient-string";
10
+ import pkgDir from "pkg-dir";
9
11
 
10
12
  import { version } from "../../package.json";
11
13
 
12
14
  dotenv.config();
13
15
 
14
- // Envs
15
16
  const GRIDDO_BUILD_LOGS =
16
17
  (!!process.env.GRIDDO_BUILD_LOGS &&
17
18
  !!JSON.parse(process.env.GRIDDO_BUILD_LOGS)) ||
18
19
  (!!process.env.LOGS && !!JSON.parse(process.env.LOGS));
19
20
 
21
+ const CXRootFolder = pkgDir.sync(__dirname)!; // usually monorepo/packages/griddo-cx/
22
+ const instanceRootFolder = pkgDir.sync()!; // instace root folder
23
+
20
24
  /**
21
25
  * Walk a directory and returns the file pathts.
22
26
  *
@@ -116,18 +120,6 @@ export function getSafeSiteId(response: APIResponses) {
116
120
  return "site" in response && response.site ? response?.site : undefined;
117
121
  }
118
122
 
119
- /**
120
- * Execute functions and return time it takes for functions to execute
121
- * @param funcs Array of functions
122
- * @returns seconds it takes for functions to execute
123
- */
124
- function measureFunctions(...funcs: Array<() => void>) {
125
- const start = performance.now();
126
- funcs.forEach((func) => func());
127
-
128
- return msToSec(performance.now() - start);
129
- }
130
-
131
123
  /**
132
124
  * Remove props from an object
133
125
  *
@@ -166,24 +158,17 @@ function splash() {
166
158
  }
167
159
 
168
160
  /**
169
- * Print a f**king great Griddo builder logo.
161
+ * Print the great Griddo Exporter logo in ASCII.
170
162
  */
171
- function exporterLogo() {
163
+ function printExporterLogo(adapter: Adapters) {
172
164
  const logo = `
173
165
  ··
174
- ··
175
- ··
176
- ·· ______ ______ _____ ______ ______ _____
177
- ·· | ____ |_____/ | | \\ | \\ | |
178
- ·· |_____| | \\_ __|__ |_____/ |_____/ |_____|
179
166
  ·· _______ _ _ _____ _____ ______ _______ _______ ______
180
167
  ·· |______ \\___/ |_____] | | |_____/ | |______ |_____/
181
168
  ·· |______ _/ \\_ | |_____| | \\_ | |______ | \\_
182
169
  ··
183
- ·· Griddo exporter orchestrator
184
- ·· ${version}
185
- ··
186
- ··
170
+ ·· Griddo Exporter ${version}
171
+ ·· Adapter: ${adapter}
187
172
  ··
188
173
  `;
189
174
 
@@ -196,7 +181,7 @@ function exporterLogo() {
196
181
  * @param folderPath The path for the `apiCache` folder
197
182
  * @todo remove other file types: sites, socials, etc..
198
183
  */
199
- function sanitizeApiCache(folderPath: string) {
184
+ function sanitizeAPICacheFolder(folderPath: string) {
200
185
  // Read all `apiCache` file paths
201
186
  const allCachedFiles = fs.readdirSync(folderPath);
202
187
 
@@ -251,18 +236,35 @@ function sanitizeApiCache(folderPath: string) {
251
236
  }
252
237
  }
253
238
 
254
- console.log(`>>> Sanitize apiCache folder for ${counter} files <<<`);
239
+ console.log(`Sanitize apiCache folder for ${counter} files`);
240
+ }
241
+
242
+ async function measureExecutionTime(
243
+ ...fns: Array<(...args: Array<unknown>) => unknown | Promise<any>>
244
+ ) {
245
+ const start = process.hrtime();
246
+
247
+ for (const f of fns) {
248
+ await f();
249
+ }
250
+
251
+ const [s, ms] = process.hrtime(start);
252
+ const timeInSeconds = s + ms / 1e9;
253
+
254
+ return +timeInSeconds.toFixed(3);
255
255
  }
256
256
 
257
257
  export {
258
+ CXRootFolder,
258
259
  delay,
259
- exporterLogo,
260
+ instanceRootFolder,
260
261
  logBox,
261
262
  logInfo,
262
263
  logPageSize,
263
- measureFunctions,
264
+ measureExecutionTime,
265
+ printExporterLogo,
264
266
  removeProperties,
265
- sanitizeApiCache,
267
+ sanitizeAPICacheFolder,
266
268
  siteList,
267
269
  splash,
268
270
  walk,
@@ -1,9 +1,8 @@
1
1
  import type { BuildProcessData } from "../types/global";
2
2
  import type { Site, SiteData } from "../types/sites";
3
3
 
4
- import path from "path";
4
+ import path from "node:path";
5
5
 
6
- import chalk from "chalk";
7
6
  import fs from "fs-extra";
8
7
  import { parse } from "js2xmlparser";
9
8
 
@@ -30,14 +29,15 @@ const GRIDDO_RENDER_PAGES = (
30
29
  .map((item) => parseInt(item))
31
30
  .filter(Boolean);
32
31
 
33
- const STRIP_DOMAIN_FROM_PATH =
34
- !!process.env.GRIDDO_EXPORT_STRIP_DOMAIN_FROM_PATH;
32
+ const STRIP_DOMAIN_FROM_PATH = JSON.parse(
33
+ process.env.GRIDDO_EXPORT_STRIP_DOMAIN_FROM_PATH || "false"
34
+ );
35
35
 
36
36
  /**
37
37
  * Check the instance sites and returns site prepared to be published and unpublished.
38
38
  */
39
39
  async function checkSites() {
40
- console.log(`🔗 API URL ${chalk.underline(API_URL as string)}`);
40
+ console.info(`API URL ${API_URL as string}`);
41
41
 
42
42
  // Login to API
43
43
  await AuthService.login();
@@ -282,8 +282,8 @@ function saveFile(filePath: string, content: string) {
282
282
 
283
283
  export {
284
284
  checkSites,
285
- unpublishSites,
286
285
  generateBuildReport,
287
- getSiteData,
288
286
  generateSitemaps,
287
+ getSiteData,
288
+ unpublishSites,
289
289
  };
@@ -0,0 +1,56 @@
1
+ import fsp from "node:fs/promises";
2
+ import path from "node:path";
3
+
4
+ import fsx from "fs-extra";
5
+
6
+ import { walk } from "./shared";
7
+ import { BuildMetaData } from "../types/api";
8
+ import { GriddoPageObject } from "../types/pages";
9
+
10
+ /**
11
+ * Read all pages stored in `store` Griddo folder and return one by one with a
12
+ * generator.
13
+ */
14
+ async function* getBuildPages<PageType extends GriddoPageObject>(
15
+ basePath: string
16
+ ) {
17
+ const pagesDirPath = path.resolve(basePath);
18
+ const jsonFilePaths = walk(pagesDirPath).filter(
19
+ (file) => path.extname(file) === ".json"
20
+ );
21
+
22
+ for (const filePath of jsonFilePaths) {
23
+ try {
24
+ const fileStats = await fsp.stat(filePath);
25
+ const page = (await fsx.readJSON(filePath, {
26
+ encoding: "utf-8",
27
+ })) as PageType;
28
+ page.size = fileStats.size / 1024;
29
+ yield page;
30
+ } catch (error) {
31
+ console.error(`Error: The file ${filePath} doesn't exist`, error);
32
+ }
33
+ }
34
+ }
35
+
36
+ /**
37
+ * Get the build metadata from the Store.
38
+ */
39
+ function getBuildMetadata(basePath: string): BuildMetaData {
40
+ const buildProcessData = fsx.readJSONSync(
41
+ path.resolve(basePath, "metadata", "buildProcessData.json")
42
+ );
43
+ const createdPages = fsx.readJSONSync(
44
+ path.resolve(basePath, "metadata", "createdPages.json")
45
+ );
46
+ const sitesToPublish = fsx.readJSONSync(
47
+ path.resolve(basePath, "metadata", "sitesToPublish.json")
48
+ );
49
+ return {
50
+ buildProcessData,
51
+ createdPages,
52
+ sitesToPublish,
53
+ };
54
+ }
55
+
56
+ export { getBuildMetadata, getBuildPages };
package/gatsby-config.ts CHANGED
@@ -2,7 +2,7 @@ import type { GatsbyConfig } from "gatsby";
2
2
 
3
3
  import dotenv from "dotenv";
4
4
 
5
- import { resolveComponentsPath } from "./src/utils/instance";
5
+ import { resolveComponentsPath } from "./exporter/utils/instance";
6
6
 
7
7
  dotenv.config();
8
8
 
package/gatsby-node.ts CHANGED
@@ -1,99 +1,65 @@
1
1
  import type { GatsbyNode } from "gatsby";
2
2
 
3
- import path from "path";
3
+ import path from "node:path";
4
4
 
5
- import dotenv from "dotenv";
6
-
7
- import { RobotsService } from "./src/services/robots";
8
- import { StoreService } from "./src/services/store";
9
- import { initCache } from "./src/utils/cache";
10
- import { prepareStaticFolder, updateDist } from "./src/utils/folders";
5
+ import { RobotsService } from "./exporter/services/robots";
6
+ import { logInfo, logPageSize } from "./exporter/utils/shared";
7
+ import { generateBuildReport, generateSitemaps } from "./exporter/utils/sites";
8
+ import { getBuildMetadata, getBuildPages } from "./exporter/utils/store";
11
9
  import {
12
- logInfo,
13
- logPageSize,
14
- msToSec,
15
- sanitizeApiCache,
16
- splash,
17
- } from "./src/utils/shared";
18
- import { generateBuildReport, generateSitemaps } from "./src/utils/sites";
19
-
20
- dotenv.config();
10
+ getMatchPath,
11
+ prepareStaticFolder,
12
+ updateDist,
13
+ } from "./src/gatsby-node-utils";
14
+ import { GatsbyPageObject } from "./src/types";
15
+
16
+ const publicFolderPath = path.resolve(__dirname, "./public");
17
+ const storeFolderPath = path.resolve(__dirname, "./store/");
18
+ const reportFilePath = path.resolve(publicFolderPath, "__build-report__.json");
19
+ const gatsbyTemplateFile = path.resolve(
20
+ __dirname,
21
+ "./src/components/template.tsx"
22
+ );
21
23
 
22
- // Consts
23
- const PUBLIC_FOLDER = path.resolve(__dirname, "./public");
24
- const STORE_DIR_PATH = path.resolve(__dirname, "./store/");
25
- const API_CACHE_FOLDER = path.resolve(__dirname, "./apiCache");
26
- const REPORT_FILE = path.resolve(PUBLIC_FOLDER, "__build-report__.json");
27
-
28
- // -----------------------------------------------------------------------------
29
24
  // onPreInit
30
- // -----------------------------------------------------------------------------
31
- export const onPreInit = async () => {
32
- splash();
33
- initCache();
25
+ const onPreInit = async () => {
34
26
  prepareStaticFolder();
35
-
36
- StoreService.init(STORE_DIR_PATH);
37
- await StoreService.createBuildSource();
38
-
39
- // Remove old cahe page files
40
- sanitizeApiCache(API_CACHE_FOLDER);
41
-
42
- console.log("\n✨ onPreInit\n");
43
27
  };
44
28
 
45
- // -----------------------------------------------------------------------------
46
29
  // createPages
47
- // -----------------------------------------------------------------------------
48
- export const createPages: GatsbyNode["createPages"] = async ({
30
+ const createPages: GatsbyNode["createPages"] = async ({
49
31
  actions: { createPage },
50
32
  }) => {
51
- const pages = StoreService.getPages();
52
-
53
- let totalPagesSize = 0;
33
+ const pages = getBuildPages<GatsbyPageObject>(storeFolderPath);
54
34
 
55
- // We need to use a `for..of` to iterate over `pages` since it could be a
56
- // generator and for example a `forEach` doesn't work on it. Besides a
57
- // `for..of` is probably the best performance option.
58
35
  for await (const page of pages) {
59
- const startTime = performance.now();
36
+ const { domain, compose } = page.context.fullPath;
37
+ const matchPath = getMatchPath(domain, compose);
60
38
 
61
- createPage(page);
62
-
63
- const {
64
- size: pageSize,
65
- context: { id },
66
- path: pagePath,
67
- } = page;
68
- const duration = msToSec(performance.now() - startTime);
69
- const size = pageSize ? logPageSize(Math.round(pageSize)) : 0;
39
+ page.component = gatsbyTemplateFile;
40
+ page.matchPath = matchPath;
70
41
 
71
- logInfo(`Creating page ${pagePath} - ${duration}s - ${id} - ${size}`);
42
+ createPage(page);
72
43
 
73
- totalPagesSize += pageSize || 0;
44
+ logInfo(
45
+ `Creating page ${page.path} - ${page.context.id} - ${logPageSize(
46
+ Math.round(page.size || 0)
47
+ )}`
48
+ );
74
49
  }
75
-
76
- const totalPagesSizeMsg = (totalPagesSize / 1024).toFixed(3);
77
- console.info(`Total page-data.json size: ${totalPagesSizeMsg}MB`);
78
-
79
- console.log("\n✨ createPages\n");
80
50
  };
81
51
 
82
- // -----------------------------------------------------------------------------
83
52
  // onPostBuild
84
- // -----------------------------------------------------------------------------
85
- export const onPostBuild = async () => {
86
- const { buildProcessData, sitesToPublish } = StoreService.getMetadata();
53
+ const onPostBuild = async () => {
54
+ const { buildProcessData, sitesToPublish } =
55
+ getBuildMetadata(storeFolderPath);
87
56
 
88
- await generateBuildReport(REPORT_FILE, buildProcessData);
89
- await RobotsService.writeFiles(PUBLIC_FOLDER);
57
+ await generateBuildReport(reportFilePath, buildProcessData);
58
+ await RobotsService.writeFiles(publicFolderPath);
90
59
  await generateSitemaps(sitesToPublish);
91
60
  await updateDist();
92
-
93
- console.log("\n✨ onPostBuild\n");
94
61
  };
95
62
 
96
- // -----------------------------------------------------------------------------
97
63
  // onCreateWebpackConfig
98
- // -----------------------------------------------------------------------------
99
- export { onCreateWebpackConfig } from "./src/utils/gatsby";
64
+ export { onCreateWebpackConfig } from "./src/gatsby-node-utils";
65
+ export { createPages, onPostBuild, onPreInit };
package/index.js CHANGED
@@ -1,4 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  /* eslint-disable node/no-missing-require */
3
3
 
4
- require("./build");
4
+ // This is the griddo-cx package entry point.
5
+ // `./build/index.js` is for the Griddo Exporter, where everything start.
6
+ // The source code (TypeScript) is in ./exporter folder
7
+ require("./build/index.js");
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.3.13",
4
+ "version": "10.3.15",
5
5
  "authors": [
6
6
  "Álvaro Sánchez' <alvaro.sanches@secuoyas.com>",
7
7
  "Diego M. Béjar <diego.bejar@secuoyas.com>",
@@ -20,18 +20,21 @@
20
20
  "griddo-cx": "./index.js"
21
21
  },
22
22
  "scripts": {
23
- "build": "yarn run build:exporter && yarn run build:reset-render && yarn run build:build-complete",
24
- "build:exporter": "esbuild ./scripts/griddo-exporter.ts --bundle --platform=node --minify --outfile=./build/index.js",
25
- "build:build-complete": "esbuild ./scripts/build-complete.ts --bundle --platform=node --minify --outfile=./build/build-complete.js",
26
- "build:reset-render": "esbuild ./scripts/reset-render.ts --bundle --platform=node --minify --outfile=./build/reset-render.js",
23
+ "build": "yarn build:exporter && yarn build:reset-render && yarn build:build-complete && yarn build:download-data",
24
+ "build:exporter": "esbuild ./exporter/index.ts --bundle --platform=node --minify --outfile=./build/index.js",
25
+ "build:build-complete": "esbuild ./exporter/build-complete.ts --bundle --platform=node --minify --outfile=./build/build-complete.js",
26
+ "build:reset-render": "esbuild ./exporter/reset-render.ts --bundle --platform=node --minify --outfile=./build/reset-render.js",
27
+ "build:download-data": "esbuild ./exporter/download-data.ts --bundle --platform=node --minify --outfile=./build/download-data.js",
27
28
  "clean": "gatsby clean; rm -rf .cache public assets dist build store",
28
- "export": "gatsby telemetry --disable && gatsby build --prefix-paths",
29
+ "export": "yarn build && yarn download:data && yarn gatsby-build",
30
+ "gatsby-build": "gatsby telemetry --disable && gatsby build --prefix-paths",
29
31
  "export:complete": "node ./build/build-complete.js",
30
32
  "export:reset": "node ./build/reset-render.js",
31
33
  "prepare": "yarn run build",
32
34
  "watch:tscheck": "tsc --noEmit --watch",
33
35
  "complete-render": "node ./build/build-complete.js",
34
- "reset-render": "node ./build/reset-render.js"
36
+ "reset-render": "node ./build/reset-render.js",
37
+ "download:data": "node ./build/download-data.js"
35
38
  },
36
39
  "dependencies": {
37
40
  "@babel/core": "^7.21.0",
@@ -67,7 +70,7 @@
67
70
  "react-helmet": "^6.0.0"
68
71
  },
69
72
  "devDependencies": {
70
- "@griddo/eslint-config-back": "^10.3.13",
73
+ "@griddo/eslint-config-back": "^10.3.15",
71
74
  "@types/babel__core": "^7.20.0",
72
75
  "@types/babel__preset-env": "^7.9.2",
73
76
  "@types/csvtojson": "^2.0.0",
@@ -99,8 +102,8 @@
99
102
  "gatsby-config.ts",
100
103
  "gatsby-node.ts",
101
104
  "gatsby-ssr.tsx",
105
+ "exporter",
102
106
  "index.js",
103
- "scripts",
104
107
  "src",
105
108
  "static"
106
109
  ],
@@ -114,5 +117,5 @@
114
117
  "publishConfig": {
115
118
  "access": "public"
116
119
  },
117
- "gitHead": "b81973d594889bec73fd319f26528ba0555ea9bb"
120
+ "gitHead": "4fc7697e23d1eb162e0675498f9fb13d17078cf6"
118
121
  }
package/src/README.md ADDED
@@ -0,0 +1,7 @@
1
+ # Griddo CX + Gatsby
2
+
3
+ The `/src` folder and almost every file in the root folder is now 100% Gatsby related code along with the historical `/public`, `/dist`, `/apiCache`, `/store`, etc.. render folders.
4
+
5
+ Griddo CX code (the business logic) is now in `/exporter` folder.
6
+
7
+ In the future, Griddo CX and Gatsby will split int their own packages folders inside the mono-repo.