@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
@@ -0,0 +1,34 @@
1
+ import type { GriddoListPage, GriddoMultiPage, GriddoPageObject, GriddoSinglePage, MultiPageElements, PageAdditionalInfo } from "../types/pages";
2
+ import type { TemplateWithDistributor } from "../types/templates";
3
+ import type { Fields } from "@griddo/core";
4
+ /**
5
+ * Create a single Griddo page object.
6
+ *
7
+ * @param page A Griddo single page object.
8
+ * @param additionalInfo Additional page info.
9
+ */
10
+ declare function createGriddoSinglePage(page: GriddoSinglePage, additionalInfo: PageAdditionalInfo): Promise<GriddoPageObject>;
11
+ /**
12
+ * Create multiples pages from one page as list paginated pages
13
+ */
14
+ declare function createGriddoListPages({ page, pages, isRoot, defaultLang, template, totalQueriedItems, }: GriddoListPage, additionalInfo: PageAdditionalInfo): Promise<GriddoPageObject[]>;
15
+ /**
16
+ * Create multiples pages from a MultiPage module
17
+ *
18
+ * @param page A Griddo Multipage object.
19
+ * @param additionalInfo Additional page info.
20
+ */
21
+ declare function createGriddoMultiPages(page: GriddoMultiPage, additionalInfo: PageAdditionalInfo): Promise<GriddoPageObject[]>;
22
+ /**
23
+ * Get the multi pages elements.
24
+ *
25
+ * @param page The page to get the multipage parts.
26
+ */
27
+ declare function getMultiPageElements(page: TemplateWithDistributor): Promise<MultiPageElements> | null;
28
+ /**
29
+ * Takes a template object and split the whole queriedItems into separated queriedItems to use in Griddo static list templates.
30
+ *
31
+ * @param listTemplate A template schema with the distributor data included.
32
+ */
33
+ declare function getPaginatedPages(listTemplate: TemplateWithDistributor): Fields.SimpleContentType<Omit<unknown, "__contentTypeKind">>[][];
34
+ export { createGriddoListPages, createGriddoMultiPages, createGriddoSinglePage, getMultiPageElements, getPaginatedPages, };
@@ -0,0 +1,14 @@
1
+ import type { PostSearchInfoResponse } from "../types/api";
2
+ import type { PostSearchInfoProps } from "../types/global";
3
+ /**
4
+ * Save in the BBDD the content of a page parsed without HTML tags.
5
+ *
6
+ * @param props Object with parts of the final page object to be saved in the BBDD.
7
+ */
8
+ declare function postSearchInfo(props: PostSearchInfoProps): Promise<PostSearchInfoResponse>;
9
+ /**
10
+ * Function that search in the `/public` dir the content info of the pages and
11
+ * send it to the search table in the ddbb using the API.
12
+ */
13
+ declare function uploadRenderedSearchContentToAPI(distDomainPath: string, domain: string): Promise<void>;
14
+ export { postSearchInfo, uploadRenderedSearchContentToAPI };
@@ -0,0 +1,110 @@
1
+ import type { Adapters } from "../adapters";
2
+ import type { APIResponses } from "../types/api";
3
+ import type { LifeCyclesNames } from "../types/global";
4
+ import type { Site } from "../types/sites";
5
+ declare const instanceRootDir: string;
6
+ /**
7
+ * Walk a directory and returns the file pathts.
8
+ *
9
+ * @param dir A directory path.
10
+ */
11
+ declare function walk(dir: string): string[];
12
+ /**
13
+ * Custom log inside a line-box.
14
+ *
15
+ * @param stringValue The string to be logged.
16
+ * @param paddingInline The number of white spaces inside the box at left and right.
17
+ * @param paddingBlock The number of white spaces inside the box at top and bottom.
18
+ */
19
+ declare function logBox(stringValue: string, title?: string, paddingInline?: number, paddingBlock?: number): void;
20
+ /**
21
+ * Custom basic logging function controlled by a environment variable.
22
+ * Strip double spaces.
23
+ *
24
+ * @param str The string to be logged.
25
+ */
26
+ declare function logInfo(str: string): void;
27
+ /**
28
+ * Internal log
29
+ * @param values The values to be logged.
30
+ */
31
+ declare function debug(...values: Array<unknown>): void;
32
+ /**
33
+ * Custom delay using the "promise hack",
34
+ *
35
+ * @param ms Amount of miliseconds to be delayed
36
+ */
37
+ declare function delay(ms: number): Promise<unknown>;
38
+ /**
39
+ * Return a scale size colors with a number and a measure string (KB by default).
40
+ *
41
+ * @param size The page size in KB.
42
+ * @param measure The measure string to be added in the log.
43
+ */
44
+ declare function logPageSize(size: number, measure?: string): string;
45
+ /**
46
+ * Converts milliseconds to seconds with a fixed number of decimals.
47
+ *
48
+ * @param ms The number in milliseconds.
49
+ * @param fixed The amount of fixed decimals.
50
+ * @returns The converted number in seconds with the fixed number of decimals.
51
+ */
52
+ export declare function msToSec(ms: number, decimals?: number): string;
53
+ /**
54
+ * Return a siteID from a response object if exist
55
+ * @param response A response object
56
+ */
57
+ export declare function getSafeSiteId(response: APIResponses): number | undefined;
58
+ /**
59
+ * Remove props from an object
60
+ *
61
+ * @param obj The object
62
+ * @param props An array of props to be removed
63
+ */
64
+ declare function removeProperties(obj: Record<string, unknown>, props: Array<string>): void;
65
+ /**
66
+ * Return a list of sites with their names and ids.
67
+ *
68
+ * @param sites An array of sites objects
69
+ */
70
+ declare function siteList(sites: Array<Site>): string;
71
+ /**
72
+ * Print the great Griddo Exporter logo in ASCII.
73
+ */
74
+ declare function printExporterLogo(adapter: Adapters): void;
75
+ /**
76
+ * Remove unused files (old) inside the `apiCache` dir
77
+ *
78
+ * @todo remove other file types: sites, socials, etc..
79
+ */
80
+ declare function sanitizeAPICacheDir(): void;
81
+ /**
82
+ * Measures the execution time of a series of sync or async functions.
83
+ * @param functions - Functions to be executed to measure their execution time.
84
+ * @returns A promise that resolves with the total execution time in seconds.
85
+ */
86
+ declare function measureExecutionTime(...functions: Array<(...args: Array<unknown>) => unknown | Promise<any>>): Promise<number>;
87
+ declare function pause(title: string): Promise<void> | undefined;
88
+ declare function startLifeCycle(lifeCyleName: string): void;
89
+ declare function successLifeCyle(value: string): void;
90
+ /**
91
+ * Executes a life cycle process, which involves executing an array of
92
+ * functions, printing to the console, and handling errors with optional
93
+ * retries.
94
+ *
95
+ * @async
96
+ * @param args - The arguments object.
97
+ * @param args.steps - An array of functions to execute.
98
+ * @param args.name - The name of the life cycle.
99
+ * @param args.attempts=1 - The number of retry attempts allowed in case of errors.
100
+ * @param args.bypass - Skip the step functions.
101
+ * @returns - A promise that resolves when the life cycle process is completed.
102
+ */
103
+ declare function doLifeCycle(args: {
104
+ steps: Array<(...args: Array<unknown>) => unknown | Promise<any>>;
105
+ name: LifeCyclesNames;
106
+ attempts?: number;
107
+ }): Promise<void>;
108
+ declare function isVersionGreaterThan(versionA: string, versionB: string): boolean;
109
+ declare function isVersionLowerThan(versionA: string, versionB: string): boolean;
110
+ export { debug, delay, doLifeCycle, instanceRootDir, isVersionGreaterThan, isVersionLowerThan, logBox, logInfo, logPageSize, measureExecutionTime, pause, printExporterLogo, removeProperties, sanitizeAPICacheDir, siteList, startLifeCycle, successLifeCyle, walk, };
@@ -0,0 +1,36 @@
1
+ import type { Site, SiteData } from "../types/sites";
2
+ /**
3
+ * Check the instance sites and returns site prepared to be published and unpublished.
4
+ */
5
+ declare function checkSites(domain: string): Promise<{
6
+ sitesToPublish: Site[];
7
+ sitesToUnpublish: Site[];
8
+ }>;
9
+ /**
10
+ * Unpublish an array of sites in two steps:
11
+ * - Sending the information to the API
12
+ *
13
+ * @param sites An array of sites
14
+ * @see https://griddoio.notion.site/Sites-d7bb0b7cb8d24894a5337e1139fc3d09#2019d3255bda4d219c7e19cf28d0c4fe
15
+ */
16
+ declare function unpublishSites(sites: Array<Site>): Promise<void>;
17
+ /**
18
+ * Return a single site generic data.
19
+ *
20
+ * @param siteID The site id.
21
+ * @param cacheKey Boolean that indicates if we want to get cache version.
22
+ *
23
+ * @see SiteData
24
+ */
25
+ declare function getSiteData(siteID: number): Promise<SiteData>;
26
+ /**
27
+ * Save a file with the end of build process
28
+ */
29
+ declare function generateBuildReport(): Promise<void>;
30
+ /**
31
+ * Generate sitemaps and save them into file system.
32
+ *
33
+ * @param sites An array of sites
34
+ */
35
+ declare function generateSitemaps(): Promise<void>;
36
+ export { checkSites, generateBuildReport, generateSitemaps, getSiteData, unpublishSites, };
@@ -0,0 +1,79 @@
1
+ import type { BuildMetaData } from "../types/api";
2
+ import type { RenderInfo } from "../types/global";
3
+ import type { GriddoPageObject } from "../types/pages";
4
+ import type { Site } from "../types/sites";
5
+ /**
6
+ * Read all path pages stored in the `store` Griddo directory and returns the
7
+ * absolute file path.
8
+ *
9
+ * @param domain - The domain to get the pages from.
10
+ */
11
+ declare function getBuildPagesFromCachedStore<PageType extends GriddoPageObject>(domain: string): Generator<PageType, void, unknown>;
12
+ /**
13
+ * Read all pages stored in the `store` Griddo directory and returns one by one
14
+ * with a generator.
15
+ *
16
+ * @param basePath - Base directory to get pages from.
17
+ * @param options.withSizeProp - Add size prop to the page object.
18
+ * @todo throw error if the basePath is not an store folder
19
+ */
20
+ declare function getBuildPagesFromStore<PageType extends GriddoPageObject>(args?: {
21
+ basePath?: string;
22
+ withSizeProp?: boolean;
23
+ }): Generator<PageType, void, unknown>;
24
+ /**
25
+ * Read all pages stored in `store` Griddo directory and return the absolute path.
26
+ */
27
+ declare function getBuildPagesPath(): string[];
28
+ /**
29
+ * Get the build metadata from the Store.
30
+ * TODO: Refactorizar para leer un solo archivo: __metadata__.json
31
+ */
32
+ declare function getBuildMetadata(): Promise<BuildMetaData>;
33
+ /**
34
+ * Creates an `store` dir to store pages transformed by createStore
35
+ */
36
+ declare function createStoreDir(): void;
37
+ /**
38
+ * Write render info into a file.
39
+ * @param basePath - Absolute path of the dir from which files will be saved.
40
+ * @param renderInfo - Data that will be saved related to the render process.
41
+ */
42
+ declare function saveRenderInfoInStore(basePath: string, renderInfo: RenderInfo): void;
43
+ /**
44
+ * Return an array of ids only from `.json` files (no dirs) in the `basePath` dir based in the file name.
45
+ * @param basePath - Absolute path of the dir from which files will be read.
46
+ * @returns A Array<number> of pages ids in `basePath` dir.
47
+ */
48
+ declare function getPageInStoreDir(basePath: string): Array<number>;
49
+ /**
50
+ * Save the pages into the file system.
51
+ * @param pages - An array of Griddo page objects to be saved.
52
+ */
53
+ declare function savePagesInStore(pages: Array<GriddoPageObject>): void;
54
+ /**
55
+ * Remove files from dir.
56
+ * @param filenames - An array of ids representing file page names.
57
+ */
58
+ declare function removePagesFromStore(filenames: Array<number>): void;
59
+ /**
60
+ * Returns pages that need to be created or deleted for a site in the store based on the provided arguments.
61
+ * @param sitePages - Properties for page retrieval.
62
+ * @param props.storeDir - Absolute path of the Griddo store.
63
+ * @param props.pages - Exhaustive array of all pages in the site.
64
+ * @param props.validPagesIds - Array of valid pages in the site.
65
+ * @param props.changedPages - Array of pages that have been modified in the site.
66
+ * @returns - An object containing the pages to be created and deleted in the site.
67
+ */
68
+ declare function getPagesToCreateOrDelete(storeDir: string, sitePages: {
69
+ sitesToPublish: Array<Site>;
70
+ pages: Array<number>;
71
+ validPagesIds: Array<number>;
72
+ changedPages: Array<number>;
73
+ }): Promise<{
74
+ pagesInStore: number[];
75
+ pagesMissingInStore: number[];
76
+ pagesToDeleteFromStore: number[];
77
+ pagesToWriteToStore: number[];
78
+ }>;
79
+ export { createStoreDir, getBuildMetadata, getBuildPagesPath, getBuildPagesFromCachedStore, getBuildPagesFromStore, getPageInStoreDir, getPagesToCreateOrDelete, removePagesFromStore, savePagesInStore, saveRenderInfoInStore, };
@@ -0,0 +1,10 @@
1
+ import { CXConfig } from "../types/global";
2
+ declare function getConfig(): CXConfig;
3
+ /**
4
+ * Update the Griddo's `/dist` dir with the contents from `public` dir only
5
+ * with files of type: js, json and css.
6
+ */
7
+ declare function legacy__createDistFromGatsbyPublic(domain: string, needsAssetPrefix: boolean): Promise<void>;
8
+ declare function griddoCreateInitialDirectories(domain: string): Promise<void>;
9
+ declare function griddoCleanDisposableDirectories(domain: string): Promise<void>;
10
+ export { getConfig, griddoCleanDisposableDirectories, griddoCreateInitialDirectories, legacy__createDistFromGatsbyPublic, };
package/cx.config.js CHANGED
@@ -22,7 +22,7 @@ const config = {
22
22
  COMPONENTS: "__components",
23
23
  ROOT: "__root",
24
24
  },
25
- dirs: (domain) => ({
25
+ paths: (domain) => ({
26
26
  __caches: path.join(CX_CACHE_DIR, domain || ""),
27
27
  __components: COMPONENTS_DIR,
28
28
  __cx: CX_ROOT_DIR,
@@ -14,7 +14,6 @@ import {
14
14
  removeDirsSync,
15
15
  removeVirtualPagesFromStore,
16
16
  } from "../../utils/folders";
17
- import { uploadSearchContentToAPI } from "../../utils/searches";
18
17
  import {
19
18
  doLifeCycle,
20
19
  logBox,
@@ -34,7 +33,7 @@ async function runGatsbyAdapter() {
34
33
  const config = getConfig();
35
34
 
36
35
  for (const domain of domains) {
37
- const { __ssg, __exports, __caches, __cx, __components } = config.dirs(
36
+ const { __ssg, __exports, __caches, __cx, __components } = config.paths(
38
37
  domain
39
38
  );
40
39
 
@@ -42,9 +41,6 @@ async function runGatsbyAdapter() {
42
41
 
43
42
  const assetPrefix = getGatsbyAssetPrefixSlug(domain);
44
43
  const needsAssetPrefix = !!assetPrefix && assetPrefix !== "";
45
- const shouldUploadSearchData = JSON.parse(
46
- process.env.GRIDDO_SEARCH_FEATURE || "false"
47
- );
48
44
 
49
45
  /*
50
46
  * Clean LifeCycle.
@@ -125,9 +121,9 @@ async function runGatsbyAdapter() {
125
121
  name: "SSG",
126
122
  attempts: attempts.ssg,
127
123
  steps: [
128
- () =>
124
+ () => {
129
125
  // Run Gatsby
130
- spawnSync("yarn", ["gatsby-build"], {
126
+ const render = spawnSync("yarn", ["gatsby-build"], {
131
127
  cwd: __ssg,
132
128
  stdio: ["ignore", "inherit", "ignore"],
133
129
  encoding: "utf8",
@@ -136,7 +132,13 @@ async function runGatsbyAdapter() {
136
132
  GRIDDO_EXPORTER: "true",
137
133
  GRIDDO_ASSET_PREFIX: assetPrefix,
138
134
  }),
139
- }),
135
+ });
136
+
137
+ // @todo gestionar esto desde doLifeCycle.
138
+ if (render.status !== 0) {
139
+ throw new Error("Error in 'yarn gatsby-build'");
140
+ }
141
+ },
140
142
  () => pause("SSG LifeCycle"),
141
143
  ],
142
144
  });
@@ -162,7 +164,6 @@ async function runGatsbyAdapter() {
162
164
  () => generateBuildReport(),
163
165
  () => RobotsService.writeFiles(domain),
164
166
  () => generateSitemaps(),
165
- () => (shouldUploadSearchData ? uploadSearchContentToAPI() : undefined),
166
167
  () => pause("Meta LifeCycle"),
167
168
  ],
168
169
  });
@@ -184,7 +185,7 @@ async function runGatsbyAdapter() {
184
185
  () => removeVirtualPagesFromStore(),
185
186
  // Eliminamos carpetas vacías que puedan quedar de sites
186
187
  // despublicados. Incluye aquellas que solo tengan archivos .xml
187
- () => clearEmptyDirs(),
188
+ () => clearEmptyDirs(path.join(__cx, "dist")),
188
189
  () =>
189
190
  moveDirsSync(__cx, __exports, ["dist", "assets"], {
190
191
  withBackup: true,
package/exporter/index.ts CHANGED
@@ -25,8 +25,8 @@
25
25
 
26
26
  /* prettier-ignore */ import { startRender } from "./start-render";
27
27
  /* prettier-ignore */ import { IS_COMPONENT_LIBRARY, PROJECT_ALIASES, resolveComponentsPath } from "./utils/instance";
28
- /* prettier-ignore */ import { logInfo, logPageSize } from "./utils/shared";
29
- /* prettier-ignore */ import { getBuildPages } from "./utils/store";
28
+ /* prettier-ignore */ import { logInfo, logPageSize, walk } from "./utils/shared";
29
+ /* prettier-ignore */ import { getBuildPagesFromCachedStore, getBuildPagesFromStore, getBuildPagesPath } from "./utils/store";
30
30
  /* prettier-ignore */ import { getConfig } from "./utils/temp-utils";
31
31
 
32
32
  export {
@@ -39,10 +39,12 @@ export {
39
39
  PROJECT_ALIASES,
40
40
  Site,
41
41
  SocialsResponse,
42
- getBuildPages,
43
- getConfig,
42
+ getBuildPagesFromCachedStore,
43
+ getBuildPagesFromStore, getBuildPagesPath, getConfig,
44
44
  logInfo,
45
45
  logPageSize,
46
46
  resolveComponentsPath,
47
47
  startRender,
48
+ walk
48
49
  };
50
+
@@ -10,6 +10,8 @@ import dotenv from "dotenv";
10
10
  import { get } from "../utils/api";
11
11
  import { getConfig } from "../utils/temp-utils";
12
12
 
13
+ const config = getConfig();
14
+
13
15
  /**
14
16
  * TODO: JSDoc
15
17
  */
@@ -50,9 +52,8 @@ class RobotsService {
50
52
  * Write robots.txt files for the current rendering domain.
51
53
  */
52
54
  async writeFiles(domain: string) {
53
- const config = getConfig();
54
- const dirs = config.dirs(domain);
55
- const distDirectory = path.join(dirs.__cx, "dist");
55
+ const { __cx } = config.paths(domain);
56
+ const distDirectory = path.join(__cx, "dist");
56
57
 
57
58
  await this.getRobots();
58
59
 
@@ -28,11 +28,15 @@ import {
28
28
  import { logBox, logInfo, siteList } from "../utils/shared";
29
29
  import { checkSites, getSiteData, unpublishSites } from "../utils/sites";
30
30
  import {
31
+ createStoreDir,
31
32
  getPagesToCreateOrDelete,
32
33
  removePagesFromStore,
33
34
  savePagesInStore,
34
35
  saveRenderInfoInStore,
35
36
  } from "../utils/store";
37
+ import { getConfig } from "../utils/temp-utils";
38
+
39
+ const config = getConfig();
36
40
 
37
41
  dotenv.config();
38
42
 
@@ -47,10 +51,15 @@ dotenv.config();
47
51
  * Fetch, process and save object pages and sites data into the file system to
48
52
  * be consumed by other services (Griddo itself, Adapters, etc.)
49
53
  */
50
- async function createStore(storeDir: string, domain: string) {
54
+ async function createStore(domain: string) {
55
+ createStoreDir();
56
+
51
57
  console.info(`API calls with ${API_CONCURRENCY_COUNT} threads`);
58
+
59
+ const { __cx } = config.paths();
60
+ const storeDir = path.join(__cx, "store");
52
61
  const { version: griddoVersion } = JSON.parse(
53
- fs.readFileSync(path.resolve(__dirname, "../package.json"), "utf-8")
62
+ fs.readFileSync(path.join(__cx, "package.json"), "utf-8")
54
63
  );
55
64
 
56
65
  try {
@@ -264,7 +273,7 @@ async function createStore(storeDir: string, domain: string) {
264
273
  }
265
274
 
266
275
  // Save build data to store
267
- savePagesInStore(storeDir, griddoPageObjects);
276
+ savePagesInStore(griddoPageObjects);
268
277
  };
269
278
 
270
279
  // Pages to be created or deleted in the store
@@ -281,7 +290,7 @@ async function createStore(storeDir: string, domain: string) {
281
290
  });
282
291
 
283
292
  // Delete pages from published, unpublished and deleted sites.
284
- removePagesFromStore(storeDir, pagesToDeleteFromStore);
293
+ removePagesFromStore(pagesToDeleteFromStore);
285
294
 
286
295
  // Debug time
287
296
  const changedPageLogs = `Store: ${pagesInStore.length} -> ${pagesInStore}
@@ -105,7 +105,7 @@ interface CXConfig {
105
105
  COMPONENTS: "__components";
106
106
  ROOT: "__root";
107
107
  };
108
- dirs: (domain?: string) => Record<CXDir, string>;
108
+ paths: (domain?: string) => Record<CXDir, string>;
109
109
  }
110
110
 
111
111
  export {
@@ -0,0 +1,38 @@
1
+ import fs from "node:fs";
2
+ import path from "node:path";
3
+
4
+ import pkgDir from "pkg-dir";
5
+
6
+ import { getInstanceDomains } from "./utils/domains";
7
+ import { uploadRenderedSearchContentToAPI } from "./utils/searches";
8
+
9
+ const doSearch = JSON.parse(process.env.GRIDDO_SEARCH_FEATURE || "false");
10
+
11
+ // Where we are going to find export folders
12
+ const execBasePath = pkgDir.sync(path.resolve(__dirname, "../.."))!;
13
+
14
+ // Where we are going to find archived exports
15
+ const exportArchiveBasePath = path.resolve(execBasePath, "exports/sites");
16
+
17
+ async function main() {
18
+ // Feature not enabled
19
+ if (!doSearch) {
20
+ return;
21
+ }
22
+
23
+ const domains = await getInstanceDomains();
24
+
25
+ for (const domain of domains) {
26
+ const distDomainPath = path.resolve(exportArchiveBasePath, domain, "dist");
27
+
28
+ // If the export/sites/domain has not exported sites, do not upload search content.
29
+ if (fs.existsSync(distDomainPath)) {
30
+ await uploadRenderedSearchContentToAPI(distDomainPath, domain);
31
+ }
32
+ }
33
+ }
34
+
35
+ main().catch((err) => {
36
+ console.error("Error", err?.stdout?.toString() || err);
37
+ process.exit(1);
38
+ });
@@ -12,7 +12,7 @@ import axios from "axios";
12
12
  import chalk from "chalk";
13
13
  import dotenv from "dotenv";
14
14
 
15
- import { searchCacheData, saveCache } from "./cache";
15
+ import { saveCache, searchCacheData } from "./cache";
16
16
  import { delay, getSafeSiteId, logInfo, msToSec } from "./shared";
17
17
  import { AuthService } from "../services/auth";
18
18
 
@@ -210,4 +210,4 @@ ${errorDetailsStr}
210
210
  );
211
211
  }
212
212
 
213
- export { getApi as get, putApi as put, postApi as post };
213
+ export { getApi as get, postApi as post, putApi as put };
@@ -7,16 +7,19 @@ import path from "node:path";
7
7
 
8
8
  import fsx from "fs-extra";
9
9
 
10
- // Consts
11
- const API_CACHE_DIR_PATH = path.resolve(__dirname, "./../apiCache");
12
- const SITE_HASH_FILENAME = `${API_CACHE_DIR_PATH}/siteHash.json`;
10
+ import { getConfig } from "./temp-utils";
11
+
12
+ const config = getConfig();
13
13
 
14
14
  /**
15
15
  * Creates an `apiCache` dir to store pages fetched from them API.
16
16
  */
17
17
  function createAPICacheDir() {
18
- if (!fs.existsSync(API_CACHE_DIR_PATH)) {
19
- fs.mkdirSync(API_CACHE_DIR_PATH);
18
+ const { __cx } = config.paths();
19
+ const apiCacheDir = path.join(__cx, "apiCache");
20
+
21
+ if (!fs.existsSync(apiCacheDir)) {
22
+ fs.mkdirSync(apiCacheDir);
20
23
  }
21
24
 
22
25
  console.info("Cache initialized");
@@ -29,10 +32,13 @@ function createAPICacheDir() {
29
32
  * @param petition An object
30
33
  */
31
34
  function generateFilenameWithHash(petition: Petition) {
35
+ const { __cx } = config.paths();
36
+ const apiCacheDir = path.join(__cx, "apiCache");
37
+
32
38
  const hashSum = crypto.createHash("sha256");
33
39
  hashSum.update(JSON.stringify(petition));
34
40
 
35
- return `${API_CACHE_DIR_PATH}/${hashSum.digest("hex")}`;
41
+ return `${apiCacheDir}/${hashSum.digest("hex")}`;
36
42
  }
37
43
 
38
44
  /**
@@ -88,8 +94,12 @@ function searchCacheData<T>(petition: Petition) {
88
94
  * Get site hashes from the file as an object
89
95
  */
90
96
  function getHashSites(): HashSites {
97
+ const { __cx } = config.paths();
98
+ const apiCacheDir = path.join(__cx, "apiCache");
99
+ const siteHasFilename = `${apiCacheDir}/siteHash.json`;
100
+
91
101
  try {
92
- const jsonData = fsx.readJSONSync(SITE_HASH_FILENAME, {
102
+ const jsonData = fsx.readJSONSync(siteHasFilename, {
93
103
  encoding: "utf-8",
94
104
  });
95
105
  return jsonData || {};
@@ -109,9 +119,13 @@ function updatedSiteHash(siteId: number, siteHash: SiteHash) {
109
119
  const lastHash = allHash[siteId];
110
120
  const currentHash = siteHash || lastHash || new Date().valueOf();
111
121
 
122
+ const { __cx } = config.paths();
123
+ const apiCacheDir = path.join(__cx, "apiCache");
124
+ const siteHasFilename = `${apiCacheDir}/siteHash.json`;
125
+
112
126
  if (currentHash !== lastHash) {
113
127
  allHash[siteId] = currentHash;
114
- fs.writeFileSync(SITE_HASH_FILENAME, JSON.stringify(allHash), {
128
+ fs.writeFileSync(siteHasFilename, JSON.stringify(allHash), {
115
129
  encoding: "utf-8",
116
130
  });
117
131
  }
@@ -120,9 +134,9 @@ function updatedSiteHash(siteId: number, siteHash: SiteHash) {
120
134
  }
121
135
 
122
136
  export {
137
+ createAPICacheDir,
123
138
  createSha256,
124
- updatedSiteHash,
125
- searchCacheData,
126
139
  saveCache,
127
- createAPICacheDir,
140
+ searchCacheData,
141
+ updatedSiteHash,
128
142
  };
@@ -1,24 +1,17 @@
1
- import path from "node:path";
2
-
3
1
  import { createAPICacheDir } from "./cache";
4
2
  import { sanitizeAPICacheDir } from "./shared";
5
- import { createStoreDir } from "./store";
6
3
  import { createStore } from "../services/store";
7
4
 
8
- const storeDir = path.resolve(__dirname, "../store/");
9
- const apiCacheDir = path.resolve(__dirname, "../apiCache");
10
-
11
5
  /**
12
6
  * Download all data: sites, pages etc.. from the instance private Griddo API.
13
- * Then you can use the generator funcion `getBuildPages()` to get the pages and
7
+ * Then you can use the generator funcion `getBuildPagesFromStore()` to get the pages and
14
8
  * `getBuildMetadata()` to get build and sites metadata as objects. Both from
15
9
  * exporter utils sites dir.
16
10
  */
17
11
  async function createBuildData(domain: string) {
18
12
  createAPICacheDir();
19
- createStoreDir(storeDir);
20
- await createStore(storeDir, domain);
21
- sanitizeAPICacheDir(apiCacheDir);
13
+ await createStore(domain);
14
+ sanitizeAPICacheDir();
22
15
  }
23
16
 
24
17
  export { createBuildData };