@griddo/cx 10.4.18 → 10.4.20

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 (70) hide show
  1. package/build/adapters/gatsby/index.d.ts +2 -0
  2. package/build/adapters/gatsby/utils.d.ts +26 -0
  3. package/build/adapters/index.d.ts +3 -0
  4. package/build/browser/index.d.ts +5 -0
  5. package/build/build-complete.d.ts +18 -0
  6. package/build/build-complete.js +22 -22
  7. package/build/index.d.ts +29 -0
  8. package/build/index.js +35 -35
  9. package/build/move-assets.d.ts +1 -0
  10. package/build/react/index.d.ts +2 -0
  11. package/build/reset-render.d.ts +1 -0
  12. package/build/reset-render.js +22 -22
  13. package/build/run-start-render.d.ts +1 -0
  14. package/build/run-start-render.js +35 -35
  15. package/build/services/auth.d.ts +21 -0
  16. package/build/services/distributors.d.ts +45 -0
  17. package/build/services/domains.d.ts +8 -0
  18. package/build/services/navigation.d.ts +77 -0
  19. package/build/services/robots.d.ts +21 -0
  20. package/build/services/settings.d.ts +23 -0
  21. package/build/services/sites.d.ts +42 -0
  22. package/build/services/store.d.ts +6 -0
  23. package/build/start-render.d.ts +3 -0
  24. package/build/start-render.js +35 -35
  25. package/build/types/api.d.ts +130 -0
  26. package/build/types/global.d.ts +78 -0
  27. package/build/types/navigation.d.ts +28 -0
  28. package/build/types/pages.d.ts +128 -0
  29. package/build/types/sites.d.ts +43 -0
  30. package/build/types/templates.d.ts +8 -0
  31. package/build/upload-search-content.d.ts +1 -0
  32. package/build/upload-search-content.js +50 -0
  33. package/build/utils/api.d.ts +23 -0
  34. package/build/utils/cache.d.ts +35 -0
  35. package/build/utils/create-build-data.d.ts +8 -0
  36. package/build/utils/domains.d.ts +5 -0
  37. package/build/utils/folders.d.ts +48 -0
  38. package/build/utils/health-checks.d.ts +7 -0
  39. package/build/utils/instance.d.ts +21 -0
  40. package/build/utils/messages.d.ts +2 -0
  41. package/build/utils/pages.d.ts +34 -0
  42. package/build/utils/searches.d.ts +14 -0
  43. package/build/utils/shared.d.ts +110 -0
  44. package/build/utils/sites.d.ts +36 -0
  45. package/build/utils/store.d.ts +79 -0
  46. package/build/utils/temp-utils.d.ts +10 -0
  47. package/cx.config.js +1 -1
  48. package/exporter/adapters/gatsby/index.ts +11 -10
  49. package/exporter/index.ts +6 -4
  50. package/exporter/services/robots.ts +4 -3
  51. package/exporter/services/store.ts +13 -4
  52. package/exporter/types/global.ts +1 -1
  53. package/exporter/upload-search-content.ts +38 -0
  54. package/exporter/utils/api.ts +2 -2
  55. package/exporter/utils/cache.ts +25 -11
  56. package/exporter/utils/create-build-data.ts +3 -10
  57. package/exporter/utils/folders.ts +14 -15
  58. package/exporter/utils/searches.ts +26 -10
  59. package/exporter/utils/shared.ts +33 -7
  60. package/exporter/utils/sites.ts +10 -10
  61. package/exporter/utils/store.ts +77 -27
  62. package/exporter/utils/temp-utils.ts +12 -11
  63. package/gatsby-config.ts +1 -1
  64. package/gatsby-node.ts +9 -10
  65. package/package.json +20 -11
  66. package/src/components/Head.tsx +1 -1
  67. package/src/components/template.tsx +1 -1
  68. package/src/gatsby-node-utils.ts +1 -1
  69. package/src/types.ts +1 -1
  70. package/tsconfig.json +26 -0
@@ -3,26 +3,25 @@ import path from "node:path";
3
3
 
4
4
  import fsx, { MakeDirectoryOptions } from "fs-extra";
5
5
 
6
- import { CXRootDir } from "./shared";
7
6
  import { getPageInStoreDir, removePagesFromStore } from "./store";
8
7
  import { getConfig } from "./temp-utils";
9
8
 
9
+ const config = getConfig();
10
+
10
11
  /**
11
12
  * Remove an empty directory from the basePath recursively.
12
13
  * If the directory has only .xml files it will handle as empty too (empty site)
13
14
  *
14
15
  * @param baseDir - The base directory.
15
16
  */
16
- const clearEmptyDirs = (baseDir?: string) => {
17
- const dir = baseDir || path.resolve(CXRootDir, "dist");
18
-
19
- const isDir = fsx.statSync(dir).isDirectory();
17
+ const clearEmptyDirs = (baseDir: string) => {
18
+ const isDir = fsx.statSync(baseDir).isDirectory();
20
19
  if (!isDir) {
21
20
  return;
22
21
  }
23
22
 
24
23
  // archivos o direvtorios dentro de `dir`
25
- let children = fsx.readdirSync(dir);
24
+ let children = fsx.readdirSync(baseDir);
26
25
  // let children = childrenRaw.filter((file) => {
27
26
  // return path.extname(file).toLowerCase() !== ".xml";
28
27
  // });
@@ -40,25 +39,25 @@ const clearEmptyDirs = (baseDir?: string) => {
40
39
  // Podemos borrarlos y dejar el dir vacío.
41
40
  if (childrenCount === xmlCount) {
42
41
  children.forEach(function (xmlFile) {
43
- const fullPath = path.join(dir, xmlFile);
42
+ const fullPath = path.join(baseDir, xmlFile);
44
43
  fsx.rmSync(fullPath);
45
44
  });
46
- children = fsx.readdirSync(dir);
45
+ children = fsx.readdirSync(baseDir);
47
46
  }
48
47
 
49
48
  children.forEach(function (file) {
50
- const fullPath = path.join(dir, file);
49
+ const fullPath = path.join(baseDir, file);
51
50
  clearEmptyDirs(fullPath);
52
51
  });
53
52
 
54
53
  // re-evaluate files; after deleting subdir we may have parent dir
55
54
  // empty now...
56
- children = fsx.readdirSync(dir);
55
+ children = fsx.readdirSync(baseDir);
57
56
  }
58
57
 
59
58
  // Si no tiene hijos, lo borramos
60
59
  if (children.length === 0) {
61
- fsx.rmdirSync(dir);
60
+ fsx.rmdirSync(baseDir);
62
61
  return;
63
62
  }
64
63
  };
@@ -245,12 +244,12 @@ function isVirtualPage(id: number) {
245
244
  }
246
245
 
247
246
  async function removeVirtualPagesFromStore() {
248
- const config = getConfig();
249
- const dirs = config.dirs();
250
- const storePath = path.join(dirs.__cx, "store");
247
+ const { __cx } = config.paths();
248
+ const storePath = path.join(__cx, "store");
249
+
251
250
  try {
252
251
  const multiPageFiles = getPageInStoreDir(storePath).filter(isVirtualPage);
253
- removePagesFromStore(storePath, multiPageFiles);
252
+ removePagesFromStore(multiPageFiles);
254
253
  } catch (e) {
255
254
  console.info(
256
255
  "`store` folder does not exist. Skipping multipage or static list template cleaning."
@@ -5,7 +5,8 @@ import fs from "node:fs";
5
5
  import path from "node:path";
6
6
 
7
7
  import { post } from "./api";
8
- import { getBuildPages } from "./store";
8
+ import { getBuildPagesFromCachedStore } from "./store";
9
+ import { getConfig } from "./temp-utils";
9
10
 
10
11
  // Envs
11
12
  const API_URL = process.env.API_URL as string;
@@ -106,21 +107,36 @@ function stripSpaces(str: string) {
106
107
  * Function that search in the `/public` dir the content info of the pages and
107
108
  * send it to the search table in the ddbb using the API.
108
109
  */
109
- async function uploadSearchContentToAPI() {
110
- // Extraemos el path de la carpeta store
111
- const storeDir = path.resolve(__dirname, `../store`);
110
+ async function uploadRenderedSearchContentToAPI(
111
+ distDomainPath: string,
112
+ domain: string
113
+ ) {
114
+ const config = getConfig();
115
+ const { __caches } = config.paths(domain);
116
+
117
+ // Extraemos el path de la carpeta store dentro de un dominio
118
+ const storeFolder = path.join(__caches, "store");
119
+
120
+ // Este caso sería que el dominio existe en la instancia pero no hay sites
121
+ // renderizardos bajo el mismo. Por lo que `store` no existe.
122
+ if (!fs.existsSync(storeFolder)) {
123
+ console.log(
124
+ `Skipping uploading content to the search endpoint for the domain ${domain}, it has not exported sites.`
125
+ );
126
+ return;
127
+ }
112
128
 
113
- for await (const store of getBuildPages(storeDir)) {
129
+ // Obtenemos las páginas del store cacheado de un dominio
130
+ const storePages = getBuildPagesFromCachedStore(domain);
131
+
132
+ for await (const store of storePages) {
114
133
  const {
115
134
  context: { page, openGraph },
116
135
  } = store;
117
136
 
118
137
  const { compose } = page.fullPath;
119
138
 
120
- const contextPath = path.resolve(
121
- __dirname,
122
- `../dist/${compose}/index.html`
123
- );
139
+ const contextPath = path.resolve(`${distDomainPath}/${compose}/index.html`);
124
140
 
125
141
  const content = fs.readFileSync(contextPath).toString();
126
142
 
@@ -140,4 +156,4 @@ async function uploadSearchContentToAPI() {
140
156
  }
141
157
  }
142
158
 
143
- export { postSearchInfo, uploadSearchContentToAPI };
159
+ export { postSearchInfo, uploadRenderedSearchContentToAPI };
@@ -12,6 +12,10 @@ import fs from "fs-extra";
12
12
  import gradient from "gradient-string";
13
13
  import pkgDir from "pkg-dir";
14
14
 
15
+ import { getConfig } from "./temp-utils";
16
+
17
+ const config = getConfig();
18
+
15
19
  dotenv.config();
16
20
 
17
21
  const GRIDDO_DEBUG_LOGS =
@@ -21,7 +25,6 @@ const GRIDDO_BUILD_LOGS =
21
25
  (!!process.env.GRIDDO_BUILD_LOGS &&
22
26
  !!JSON.parse(process.env.GRIDDO_BUILD_LOGS)) ||
23
27
  (!!process.env.LOGS && !!JSON.parse(process.env.LOGS));
24
- const CXRootDir = pkgDir.sync(__dirname)!; // usually monorepo/packages/griddo-cx/
25
28
  const instanceRootDir = pkgDir.sync()!; // instance root dir
26
29
 
27
30
  /**
@@ -188,8 +191,9 @@ function siteList(sites: Array<Site>) {
188
191
  * Print the great Griddo Exporter logo in ASCII.
189
192
  */
190
193
  function printExporterLogo(adapter: Adapters) {
194
+ const { __cx } = config.paths();
191
195
  const { version } = JSON.parse(
192
- fs.readFileSync(path.resolve(__dirname, "../package.json"), "utf-8")
196
+ fs.readFileSync(path.join(__cx, "package.json"), "utf-8")
193
197
  );
194
198
  const logo = `
195
199
  ··
@@ -204,11 +208,11 @@ function printExporterLogo(adapter: Adapters) {
204
208
  /**
205
209
  * Remove unused files (old) inside the `apiCache` dir
206
210
  *
207
- * @param dirPath The path for the `apiCache` dir
208
211
  * @todo remove other file types: sites, socials, etc..
209
212
  */
210
- function sanitizeAPICacheDir(dirPath: string) {
211
- // Read all `apiCache` file paths
213
+ function sanitizeAPICacheDir() {
214
+ const { __cx } = config.paths();
215
+ const dirPath = path.join(__cx, "apiCache");
212
216
  const allCachedFiles = fs.readdirSync(dirPath);
213
217
 
214
218
  // Object to store the the more rencent file names
@@ -320,7 +324,8 @@ function successLifeCyle(value: string) {
320
324
  * @param args - The arguments object.
321
325
  * @param args.steps - An array of functions to execute.
322
326
  * @param args.name - The name of the life cycle.
323
- * @param [args.attempts=1] - The number of retry attempts allowed in case of errors.
327
+ * @param args.attempts=1 - The number of retry attempts allowed in case of errors.
328
+ * @param args.bypass - Skip the step functions.
324
329
  * @returns - A promise that resolves when the life cycle process is completed.
325
330
  */
326
331
  async function doLifeCycle(args: {
@@ -329,6 +334,7 @@ async function doLifeCycle(args: {
329
334
  attempts?: number;
330
335
  }) {
331
336
  const { steps, name, attempts } = args;
337
+
332
338
  let trysCount = 0;
333
339
  const maxTrysAccepted = attempts || 1;
334
340
 
@@ -351,12 +357,32 @@ async function doLifeCycle(args: {
351
357
  }
352
358
  }
353
359
 
360
+ function isVersionGreaterThan(versionA: string, versionB: string) {
361
+ const [majorA, minorA, patchA] = versionA.split(".").map(Number);
362
+ const [majorB, minorB, patchB] = versionB.split(".").map(Number);
363
+
364
+ if (majorA !== majorB) {
365
+ return majorA > majorB;
366
+ }
367
+
368
+ if (minorA !== minorB) {
369
+ return minorA > minorB;
370
+ }
371
+
372
+ return patchA > patchB;
373
+ }
374
+
375
+ function isVersionLowerThan(versionA: string, versionB: string) {
376
+ return !isVersionGreaterThan(versionA, versionB);
377
+ }
378
+
354
379
  export {
355
- CXRootDir,
356
380
  debug,
357
381
  delay,
358
382
  doLifeCycle,
359
383
  instanceRootDir,
384
+ isVersionGreaterThan,
385
+ isVersionLowerThan,
360
386
  logBox,
361
387
  logInfo,
362
388
  logPageSize,
@@ -29,6 +29,8 @@ const GRIDDO_RENDER_PAGES = (
29
29
  .map((item) => parseInt(item))
30
30
  .filter(Boolean);
31
31
 
32
+ const config = getConfig();
33
+
32
34
  /**
33
35
  * Check the instance sites and returns site prepared to be published and unpublished.
34
36
  */
@@ -147,13 +149,9 @@ async function getSiteData(siteID: number) {
147
149
  * Save a file with the end of build process
148
150
  */
149
151
  async function generateBuildReport() {
150
- const config = getConfig();
151
- const dirs = config.dirs();
152
-
153
- const DIST_FOLDER = path.join(dirs.__cx, "dist");
152
+ const { __cx } = config.paths();
154
153
 
155
154
  const { buildProcessData } = await getBuildMetadata();
156
- const filePathName = path.join(DIST_FOLDER, "__build-report__.json");
157
155
 
158
156
  // Get the token
159
157
  const authControl = await AuthService.login();
@@ -168,7 +166,10 @@ async function generateBuildReport() {
168
166
  sites: buildSitesInfo,
169
167
  };
170
168
 
171
- fs.writeFileSync(filePathName, JSON.stringify(report));
169
+ fs.writeFileSync(
170
+ path.join(__cx, "dist", "__build-report__.json"),
171
+ JSON.stringify(report)
172
+ );
172
173
 
173
174
  logInfo(`Build report saved for ${buildSitesInfo.length} site(s)`);
174
175
  }
@@ -180,9 +181,8 @@ async function generateBuildReport() {
180
181
  */
181
182
  async function generateSitemaps() {
182
183
  const { sitesToPublish } = await getBuildMetadata();
183
- const config = getConfig();
184
- const dirs = config.dirs();
185
- const basePath = path.resolve(dirs.__cx, "dist");
184
+ const { __cx } = config.paths();
185
+ const distDir = path.join(__cx, "dist");
186
186
 
187
187
  const promisesOfSites = sitesToPublish.map(async (site) => {
188
188
  const { id: siteID, languages } = site;
@@ -211,7 +211,7 @@ async function generateSitemaps() {
211
211
  const sitemaps: Array<string> = [];
212
212
  const sitemapPageGroupKeys = Object.keys(sitemapPagesGroup);
213
213
 
214
- const sitemapBasePath = path.join(basePath, slug.replace(domain, ""));
214
+ const sitemapBasePath = path.join(distDir, slug.replace(domain, ""));
215
215
 
216
216
  for (const templateId of sitemapPageGroupKeys) {
217
217
  const sitemapPages = sitemapPagesGroup[templateId];
@@ -1,36 +1,64 @@
1
1
  import type { BuildMetaData } from "../types/api";
2
2
  import type { RenderInfo } from "../types/global";
3
3
  import type { GriddoPageObject } from "../types/pages";
4
+ import type { Site } from "../types/sites";
4
5
 
5
6
  import fs from "node:fs";
6
- import fsp from "node:fs/promises";
7
7
  import path from "node:path";
8
8
 
9
9
  import fsx from "fs-extra";
10
10
 
11
11
  import { removeProperties, walk } from "./shared";
12
12
  import { getConfig } from "./temp-utils";
13
- import { Site } from "../types/sites";
13
+
14
+ const config = getConfig();
14
15
 
15
16
  /**
16
- * Read all pages stored in `store` Griddo directory and return one by one with
17
- * a generator.
17
+ * Read all path pages stored in the `store` Griddo directory and returns the
18
+ * absolute file path.
19
+ *
20
+ * @param domain - The domain to get the pages from.
18
21
  */
19
- async function* getBuildPages<PageType extends GriddoPageObject>(
20
- basePath: string
22
+ function getBuildPagesFromCachedStore<PageType extends GriddoPageObject>(
23
+ domain: string
21
24
  ) {
22
- const pagesDirPath = path.resolve(basePath);
25
+ const { __caches } = config.paths(domain);
26
+ return getBuildPagesFromStore<PageType>({
27
+ basePath: path.join(__caches, "store"),
28
+ withSizeProp: false,
29
+ });
30
+ }
31
+
32
+ /**
33
+ * Read all pages stored in the `store` Griddo directory and returns one by one
34
+ * with a generator.
35
+ *
36
+ * @param basePath - Base directory to get pages from.
37
+ * @param options.withSizeProp - Add size prop to the page object.
38
+ * @todo throw error if the basePath is not an store folder
39
+ */
40
+ function* getBuildPagesFromStore<PageType extends GriddoPageObject>(args?: {
41
+ basePath?: string;
42
+ withSizeProp?: boolean;
43
+ }) {
44
+ const { basePath, withSizeProp } = args || {};
45
+ const { __cx } = config.paths();
46
+ const pagesDirPath = basePath || path.join(__cx, "store");
23
47
  const jsonFilePaths = walk(pagesDirPath).filter(
24
48
  (file) => path.extname(file) === ".json"
25
49
  );
26
50
 
27
51
  for (const filePath of jsonFilePaths) {
28
52
  try {
29
- const fileStats = await fsp.stat(filePath);
30
- const page = (await fsx.readJSON(filePath, {
53
+ const page = fsx.readJsonSync(filePath, {
31
54
  encoding: "utf-8",
32
- })) as PageType;
33
- page.size = fileStats.size / 1024;
55
+ }) as PageType;
56
+
57
+ if (withSizeProp) {
58
+ const fileStats = fs.statSync(filePath);
59
+ page.size = fileStats.size / 1024;
60
+ }
61
+
34
62
  // SECURITY: Only returns valid page objects
35
63
  if (page.path) {
36
64
  yield page;
@@ -41,18 +69,31 @@ async function* getBuildPages<PageType extends GriddoPageObject>(
41
69
  }
42
70
  }
43
71
 
72
+ /**
73
+ * Read all pages stored in `store` Griddo directory and return the absolute path.
74
+ */
75
+ function getBuildPagesPath() {
76
+ const config = getConfig();
77
+ const { __cx } = config.paths();
78
+
79
+ const PAGES_DIR = path.join(__cx, "store");
80
+ const PAGE_FILES = walk(PAGES_DIR).filter(
81
+ (file) => path.extname(file) === ".json"
82
+ );
83
+
84
+ return PAGE_FILES;
85
+ }
86
+
44
87
  /**
45
88
  * Get the build metadata from the Store.
46
89
  * TODO: Refactorizar para leer un solo archivo: __metadata__.json
47
90
  */
48
91
  async function getBuildMetadata(): Promise<BuildMetaData> {
49
- const config = getConfig();
50
- const dirs = config.dirs();
51
- const storePath = path.join(dirs.__cx, "store");
52
-
92
+ const { __cx } = config.paths();
53
93
  const { sitesToPublish, createdPages, buildProcessData } = fsx.readJSONSync(
54
- path.resolve(storePath, "metadata", "render-info.json")
94
+ path.join(__cx, "store", "metadata", "render-info.json")
55
95
  );
96
+
56
97
  return {
57
98
  buildProcessData,
58
99
  createdPages,
@@ -63,10 +104,13 @@ async function getBuildMetadata(): Promise<BuildMetaData> {
63
104
  /**
64
105
  * Creates an `store` dir to store pages transformed by createStore
65
106
  */
66
- function createStoreDir(storeDir: string) {
107
+ function createStoreDir() {
108
+ const { __cx } = config.paths();
109
+ const storeDir = path.join(__cx, "store");
110
+
67
111
  if (!fs.existsSync(storeDir)) {
68
112
  fs.mkdirSync(storeDir);
69
- fs.mkdirSync(path.resolve(storeDir, "metadata"));
113
+ fs.mkdirSync(path.join(storeDir, "metadata"));
70
114
  }
71
115
 
72
116
  console.info("Store initialized");
@@ -78,8 +122,10 @@ function createStoreDir(storeDir: string) {
78
122
  * @param renderInfo - Data that will be saved related to the render process.
79
123
  */
80
124
  function saveRenderInfoInStore(basePath: string, renderInfo: RenderInfo) {
125
+ const { __cx } = config.paths();
126
+
81
127
  fs.writeFileSync(
82
- path.resolve(basePath, "metadata", "render-info.json"),
128
+ path.join(__cx, "store", "metadata", "render-info.json"),
83
129
  JSON.stringify(renderInfo)
84
130
  );
85
131
  }
@@ -139,30 +185,32 @@ function getPageInStoreDir(basePath: string): Array<number> {
139
185
 
140
186
  /**
141
187
  * Save the pages into the file system.
142
- * @param basePath - Absolute path of the dir from which files will be saved.
143
188
  * @param pages - An array of Griddo page objects to be saved.
144
189
  */
145
- function savePagesInStore(basePath: string, pages: Array<GriddoPageObject>) {
190
+ function savePagesInStore(pages: Array<GriddoPageObject>) {
191
+ const { __cx } = config.paths();
192
+
146
193
  pages.forEach((page) => {
147
194
  removeProperties(page, ["editorID", "parentEditorID"]);
148
195
  const filename = `${page.context.page.id}.json`;
149
- const filePath = path.resolve(basePath, filename);
196
+ const filePath = path.join(__cx, "store", filename);
150
197
  fsx.writeJSONSync(filePath, page);
151
198
  });
152
199
  }
153
200
 
154
201
  /**
155
202
  * Remove files from dir.
156
- * @param basePath - Absolute path of the dir from which files will be removed.
157
203
  * @param filenames - An array of ids representing file page names.
158
204
  */
159
- function removePagesFromStore(basePath: string, filenames: Array<number>) {
205
+ function removePagesFromStore(filenames: Array<number>) {
206
+ const { __cx } = config.paths();
207
+
160
208
  if (filenames.length === 0) {
161
209
  return;
162
210
  }
163
211
 
164
212
  filenames.forEach((filename) => {
165
- const filePath = path.resolve(basePath, `${filename}.json`);
213
+ const filePath = path.join(__cx, "store", `${filename}.json`);
166
214
  try {
167
215
  fs.unlinkSync(filePath);
168
216
  } catch (error) {
@@ -219,7 +267,7 @@ async function getPagesToCreateOrDelete(
219
267
 
220
268
  // 1 - Leer el store
221
269
  // 2 - eliminar las páginas que tengan como site uno despublicado o borrado
222
- const allPagesInStore = getBuildPages(path.resolve(__dirname, "../store"));
270
+ const allPagesInStore = getBuildPagesFromStore();
223
271
 
224
272
  const pagesFromInvalidSites: Array<number> = [];
225
273
  for await (const page of allPagesInStore) {
@@ -247,7 +295,9 @@ async function getPagesToCreateOrDelete(
247
295
  export {
248
296
  createStoreDir,
249
297
  getBuildMetadata,
250
- getBuildPages,
298
+ getBuildPagesPath,
299
+ getBuildPagesFromCachedStore,
300
+ getBuildPagesFromStore,
251
301
  getPageInStoreDir,
252
302
  getPagesToCreateOrDelete,
253
303
  removePagesFromStore,
@@ -5,6 +5,8 @@ import fsx from "fs-extra";
5
5
  import { createDirsSync, removeDirsSync } from "./folders";
6
6
  import { CXConfig } from "../types/global";
7
7
 
8
+ const config = getConfig();
9
+
8
10
  function getConfig(): CXConfig {
9
11
  try {
10
12
  // eslint-disable-next-line @typescript-eslint/no-var-requires, node/no-missing-require, node/no-unpublished-require
@@ -26,13 +28,12 @@ async function legacy__createDistFromGatsbyPublic(
26
28
  domain: string,
27
29
  needsAssetPrefix: boolean
28
30
  ) {
29
- const config = getConfig();
30
- const dirs = config.dirs(domain);
31
+ const { __cx, __ssg } = config.paths(domain);
31
32
 
32
- const cxDistDir = path.resolve(dirs.__cx, "dist");
33
- const cxAssetsDir = path.resolve(dirs.__cx, "assets");
34
- const cxDistDirWithDomain = path.join(dirs.__cx, "dist", domain);
35
- const publicDir = path.resolve(dirs.__ssg, "public");
33
+ const cxDistDir = path.join(__cx, "dist");
34
+ const cxAssetsDir = path.join(__cx, "assets");
35
+ const cxDistDirWithDomain = path.join(__cx, "dist", domain);
36
+ const publicDir = path.join(__ssg, "public");
36
37
 
37
38
  console.log(publicDir);
38
39
  const validFilesFromPublic = fsx
@@ -47,7 +48,7 @@ async function legacy__createDistFromGatsbyPublic(
47
48
  const pageDataSrc = `${publicDir}/page-data`;
48
49
  const pageDataDest = `${cxAssetsDir}/page-data`;
49
50
 
50
- const projectStaticSrc = path.resolve(dirs.__ssg, "static");
51
+ const projectStaticSrc = path.join(__ssg, "static");
51
52
  const projectStaticDest = cxAssetsDir;
52
53
 
53
54
  const gatsbyStaticSrc = `${cxDistDir}/static`;
@@ -82,15 +83,15 @@ async function legacy__createDistFromGatsbyPublic(
82
83
  }
83
84
 
84
85
  async function griddoCreateInitialDirectories(domain: string) {
85
- const config = getConfig();
86
- const { __exports, __caches } = config.dirs(domain);
86
+ const { __exports, __caches } = config.paths(domain);
87
+
87
88
  createDirsSync([__exports]);
88
89
  createDirsSync([__caches]);
89
90
  }
90
91
 
91
92
  async function griddoCleanDisposableDirectories(domain: string) {
92
- const config = getConfig();
93
- const { __cx } = config.dirs(domain);
93
+ const { __cx } = config.paths(domain);
94
+
94
95
  removeDirsSync(__cx, ["store", "apiCache", "dist"]);
95
96
  }
96
97
 
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 "./exporter/utils/instance";
5
+ import { resolveComponentsPath } from "./build";
6
6
 
7
7
  dotenv.config();
8
8
 
package/gatsby-node.ts CHANGED
@@ -1,22 +1,21 @@
1
+ import type { GatsbyPageObject } from "./src/types";
1
2
  import type { GatsbyNode } from "gatsby";
2
3
 
3
4
  import path from "node:path";
4
5
 
5
- import { logInfo, logPageSize } from "./exporter/utils/shared";
6
- import { getBuildPages } from "./exporter/utils/store";
7
- import { getConfig } from "./exporter/utils/temp-utils";
6
+ import { getConfig, logInfo, logPageSize } from "./build";
7
+ import { getBuildPagesFromStore } from "./exporter/utils/store";
8
8
  import { getMatchPath } from "./src/gatsby-node-utils";
9
- import { GatsbyPageObject } from "./src/types";
10
-
11
- const dirs = getConfig().dirs();
12
- const store = path.join(dirs.__cx, "store");
13
- const template = path.join(dirs.__ssg, "src/components/template.tsx");
14
9
 
15
10
  const GRIDDO_BUILD_LOGS = JSON.parse(process.env.GRIDDO_BUILD_LOGS || "false");
16
11
 
17
- const createPages: GatsbyNode["createPages"] = async ({ actions }) => {
18
- const pages = getBuildPages<GatsbyPageObject>(store);
12
+ const { __ssg } = getConfig().paths();
13
+ const template = path.join(__ssg, "src/components/template.tsx");
14
+ const pages = getBuildPagesFromStore<GatsbyPageObject>({
15
+ withSizeProp: GRIDDO_BUILD_LOGS,
16
+ });
19
17
 
18
+ const createPages: GatsbyNode["createPages"] = async ({ actions }) => {
20
19
  for await (const page of pages) {
21
20
  if (!page) return;
22
21