@griddo/cx 10.4.2 → 10.4.4

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.
@@ -14,14 +14,14 @@ async function runAstroAdapter() {
14
14
  for (const domain of domains) {
15
15
  const runner = getAstroDomainRunner(domain);
16
16
  // ---------------------------------------------------------------------- //
17
- // Init the render, restore Gatsby /.cache and /public folders //
17
+ // Init the render, restore Gatsby /.cache and /public dirs //
18
18
  // ---------------------------------------------------------------------- //
19
19
  runner.init();
20
20
  // runner.whatEverAction();
21
21
  // runner.otherAstroRelatedFunction();
22
22
 
23
23
  // ---------------------------------------------------------------------- //
24
- // Download domain build data (sites, pages, etc) and generator a folder //
24
+ // Download domain build data (sites, pages, etc) and generator a dirs //
25
25
  // called `store` where all the domain render data is saved. //
26
26
  // ---------------------------------------------------------------------- //
27
27
  await createBuildData(domain);
@@ -1,174 +1,96 @@
1
- import type { LifeCycles } from "../../types/global";
2
-
3
1
  import { getGatsbyDomainRunner } from "./utils";
4
2
  import { getInstanceDomains } from "../../utils/domains";
5
3
  import { createBuildData } from "../../utils/download-build-data";
6
4
  import { clearEmptyDirs } from "../../utils/folders";
7
- import { printWarningMessage } from "../../utils/messages";
8
5
  import { uploadSearchContentToAPI } from "../../utils/searches";
9
- import {
10
- measureExecutionTime,
11
- pause,
12
- printExporterLogo,
13
- startLifeCycle,
14
- successLifeCyle,
15
- } from "../../utils/shared";
6
+ import { doLifeCycle, pause, printExporterLogo } from "../../utils/shared";
16
7
 
17
- /**
18
- * Gatsby adapter for Griddo.
19
- */
20
- async function runGatsbyAdapter(lifeCycles: LifeCycles) {
8
+ async function runGatsbyAdapter() {
21
9
  printExporterLogo("gatsby");
22
- const { doArchive, doData, doRestore, doMeta, doSSG } = lifeCycles;
23
10
 
24
- let exeTime = 0;
25
11
  const domains = await getInstanceDomains();
26
- if (!domains.length) {
27
- printWarningMessage(
28
- "We didn't find any domains to render during the adapter phase.",
29
- "getInstanceDomains",
30
- "Function getInstanceDomains returned an empty array of domains. Check if the domains are correctly set in the instance's database."
31
- );
32
- process.exit(1);
33
- }
34
12
 
35
13
  for (const domain of domains) {
36
14
  const runner = getGatsbyDomainRunner(domain);
37
15
 
38
16
  /**
39
- * Phases:
40
- * - Prepare.
41
- * - Folders.
42
- * - Restore.
17
+ * Restore
43
18
  *
44
- * Init the render, restore Gatsby `.cache` and `public` folders.
19
+ * Init the render, restore Gatsby `.cache` and `public` dirs.
45
20
  */
46
- if (doRestore) {
47
- startLifeCycle(`Restore ${domain}`);
48
-
49
- exeTime = await measureExecutionTime(
21
+ await doLifeCycle({
22
+ name: "Restore",
23
+ steps: [
50
24
  runner.init,
51
25
  () => pause("init done!"),
52
26
  runner.restoreArtifacts,
53
- () => pause("Restore `dist` and `assets` folders done!"),
27
+ () => pause("Restore `dist` and `assets` dirs done!"),
54
28
  runner.restoreCacheArtifacts,
55
- () => pause("Restore `apiCache`, `store` and `.cache` restored!")
56
- // runner.cleanUpSites,
57
- // () => pause("cleanUpSites done!")
58
- ).catch((err) => {
59
- console.error(
60
- "Error in init() || restoreArtifacts() || restoreCacheArtifacts() :",
61
- err?.stdout?.toString() || err
62
- );
63
- process.exit(1);
64
- });
65
-
66
- successLifeCyle(`Restore ${domain} - ${exeTime}s`);
67
- }
29
+ () => pause("Restore `apiCache`, `store` and `.cache` restored!"),
30
+ ],
31
+ });
68
32
 
69
33
  /**
70
- * Phases:
71
- * - Data.
34
+ * Data
72
35
  *
73
- * Download domain build data (sites, pages, etc) and generator a folder
36
+ * Download domain build data (sites, pages, etc) and create a dir
74
37
  * called `store` where all the domain render data is saved.
75
38
  */
76
- if (doData) {
77
- startLifeCycle(`Data ${domain}`);
78
-
79
- exeTime = await measureExecutionTime(
39
+ await doLifeCycle({
40
+ name: "Data",
41
+ steps: [
80
42
  async () => await createBuildData(domain),
81
- () => pause("Download data from API to store folder done!")
82
- ).catch((err) => {
83
- console.error(
84
- "Error in createBuildData() :",
85
- err?.stdout?.toString() || err
86
- );
87
- process.exit(1);
88
- });
89
-
90
- successLifeCyle(`Data ${domain} - ${exeTime}s`);
91
- }
43
+ () => pause("Download data from API to `store` dir done!"),
44
+ ],
45
+ });
92
46
 
93
47
  /**
94
- * Phases:
95
- * - SSG.
48
+ * SSG
96
49
  *
97
50
  * Call the `gatsby build` command.
98
51
  * Gatsby will use the downloaded data and create the static build.
99
52
  * `gatsby-node.ts` is the main file where the stati generation happens.
100
53
  */
101
- if (doSSG) {
102
- startLifeCycle(`SSG ${domain}`);
103
-
104
- exeTime = await measureExecutionTime(runner.runGatsbyBuild, () =>
105
- pause("Gatsby build done!")
106
- ).catch((err) => {
107
- console.error(
108
- "Error in runGatsbyBuild() :",
109
- err?.stdout?.toString() || err
110
- );
111
- process.exit(1);
112
- });
54
+ await doLifeCycle({
55
+ name: "SSG",
56
+ steps: [runner.runGatsbyBuild, () => pause("Gatsby build done!")],
57
+ });
113
58
 
114
- successLifeCyle(`SSG ${domain} - ${exeTime}s`);
115
- }
116
-
117
- /*
118
- * Gatsby build is done, if the .env GRIDDO_SEARCH_FEATURE is set to true
119
- * we save the search data in the API.
59
+ /**
60
+ * Meta
61
+ *
62
+ * Gatsby build is done, if the .env GRIDDO_SEARCH_FEATURE is set to
63
+ * true we save the search data in the API.
120
64
  */
121
- if (doMeta) {
122
- startLifeCycle(`Meta ${domain}`);
123
-
124
- const shouldUploadSearchData = JSON.parse(
125
- process.env.GRIDDO_SEARCH_FEATURE || "false"
126
- );
127
- if (shouldUploadSearchData) {
128
- exeTime = await measureExecutionTime(uploadSearchContentToAPI).catch(
129
- (err) => {
130
- console.error(
131
- "Error while uploads search content in DDBB :",
132
- err?.stdout?.toString() || err
133
- );
134
- process.exit(1);
135
- }
136
- );
137
-
138
- successLifeCyle(`Meta ${domain} - ${exeTime}s`);
139
- }
140
- }
65
+ const shouldUploadSearchData = JSON.parse(
66
+ process.env.GRIDDO_SEARCH_FEATURE || "false"
67
+ );
68
+ await doLifeCycle({
69
+ name: "Meta",
70
+ steps: [
71
+ () => (shouldUploadSearchData ? uploadSearchContentToAPI() : undefined),
72
+ ],
73
+ });
141
74
 
142
75
  /**
143
- * Phases:
144
- * - Clean.
145
- * - Archive.
76
+ * Archive
146
77
  *
147
78
  * When Gatsby ends, remove disposable artifacts and save .cache and
148
79
  * public foler to use in the next render.
149
80
  */
150
- if (doArchive) {
151
- startLifeCycle(`Archive ${domain}`);
152
-
153
- exeTime = await measureExecutionTime(
81
+ await doLifeCycle({
82
+ name: "Archive",
83
+ steps: [
154
84
  () => clearEmptyDirs(),
155
- () => pause("Clean empty dirs!"),
85
+ () => pause("Clean empty dirs done!"),
156
86
  runner.removeDisposableArtifacts,
157
87
  () => pause("Clean `public` done!"),
158
88
  runner.archiveArtifacts,
159
- () => pause("Archive dist and assets done!"),
89
+ () => pause("Archive `dist` and `assets` done!"),
160
90
  runner.archiveCacheArtifacts,
161
- () => pause("Archive apiCache, .cache and store done!")
162
- ).catch((err) => {
163
- console.error(
164
- "Error in removeDisposableArtifacts() || archiveArtifacts()|| archiveCacheArtifacts() :",
165
- err?.stdout?.toString() || err
166
- );
167
- process.exit(1);
168
- });
169
-
170
- successLifeCyle(`Archive ${domain} - ${exeTime}s`);
171
- }
91
+ () => pause("Archive `apiCache`, `.cache` and `store` done!"),
92
+ ],
93
+ });
172
94
  }
173
95
  }
174
96
 
@@ -6,7 +6,7 @@ import dotenv from "dotenv";
6
6
 
7
7
  import { deleteSites } from "../../utils/folders";
8
8
  import { getEnvRunner } from "../../utils/runners";
9
- import { CXRootFolder, instanceRootFolder } from "../../utils/shared";
9
+ import { CXRootDir, instanceRootDir } from "../../utils/shared";
10
10
  import { checkSites } from "../../utils/sites";
11
11
 
12
12
  dotenv.config();
@@ -38,10 +38,7 @@ function getGatsbyDomainRunner(domain: string) {
38
38
  }
39
39
 
40
40
  // Where we are going to find archived exports
41
- const exportArchiveBasePath = path.resolve(
42
- instanceRootFolder,
43
- "exports/sites"
44
- );
41
+ const exportArchiveBasePath = path.resolve(instanceRootDir, "exports/sites");
45
42
  const exportCachesArchivePath = path.resolve(__dirname, "../caches");
46
43
 
47
44
  const assetPrefix = getGatsbyAssetPrefixSlug(domain);
@@ -55,7 +52,7 @@ function getGatsbyDomainRunner(domain: string) {
55
52
 
56
53
  /**
57
54
  * Initialize exporter clearing artifacts data from a unsuccessful build and
58
- * creating necesary folders to store a new build.
55
+ * creating necesary dirs to store a new build.
59
56
  */
60
57
  const init = () => {
61
58
  console.info(`Initializing exporter for the domain ${domain}`);
@@ -115,7 +112,7 @@ function getGatsbyDomainRunner(domain: string) {
115
112
  );
116
113
 
117
114
  const currentExportBackupPath = `${currentExportArchivePath}-BACKUP`;
118
- const currentExportWorkingPath = path.resolve(CXRootFolder, artifact);
115
+ const currentExportWorkingPath = path.resolve(CXRootDir, artifact);
119
116
 
120
117
  return {
121
118
  domainExportArchiveBasePath,
@@ -148,7 +145,7 @@ function getGatsbyDomainRunner(domain: string) {
148
145
  };
149
146
 
150
147
  /**
151
- * Creates necesary folders.
148
+ * Creates necesary dirs.
152
149
  */
153
150
  const createBaseExportPaths = () => {
154
151
  const {
@@ -272,7 +269,7 @@ function getGatsbyDomainRunner(domain: string) {
272
269
  };
273
270
 
274
271
  /**
275
- * Remove sites folder from restoring phase.
272
+ * Remove sites dir from restoring phase.
276
273
  */
277
274
  const cleanUpSites = async () => {
278
275
  const { sitesToPublish, sitesToUnpublish } = await checkSites(domain);
@@ -6,7 +6,7 @@ import pkgDir from "pkg-dir";
6
6
  import { AuthService } from "./services/auth";
7
7
  import { SitesService } from "./services/sites";
8
8
 
9
- // Where we are going to find export folders
9
+ // Where we are going to find export dirs
10
10
  const execBasePath = pkgDir.sync(path.resolve(__dirname, "../.."))!;
11
11
 
12
12
  // Where we are going to find archived exports
package/exporter/index.ts CHANGED
@@ -5,15 +5,12 @@ import { runGatsbyAdapter } from "./adapters";
5
5
  import { logBox, measureExecutionTime } from "./utils/shared";
6
6
 
7
7
  async function main() {
8
- const exeTime = await measureExecutionTime(() =>
9
- runGatsbyAdapter({
10
- doRestore: true,
11
- doData: true,
12
- doSSG: true,
13
- doRelocation: true,
14
- doMeta: true,
15
- doArchive: true,
16
- })
8
+ const exeTime = await measureExecutionTime(() => runGatsbyAdapter()).catch(
9
+ (e) => {
10
+ console.log(e);
11
+ console.log("[[[ Render will be reset ]]]");
12
+ process.exit(1);
13
+ }
17
14
  );
18
15
  logBox(`All domains rendered in ${exeTime}s.`, "", 1, 0);
19
16
  process.exit(0);
@@ -49,7 +49,7 @@ const buildProcessData: BuildProcessData = {};
49
49
  * Fetch, process and save object pages and sites data into the file system to
50
50
  * be consumed by other services (Griddo itself, Adapters, etc.)
51
51
  */
52
- async function createStore(storeFolder: string, domain: string) {
52
+ async function createStore(storeDir: string, domain: string) {
53
53
  console.info(`API calls with ${API_CONCURRENCY_COUNT} threads`);
54
54
 
55
55
  try {
@@ -259,7 +259,7 @@ async function createStore(storeFolder: string, domain: string) {
259
259
  }
260
260
 
261
261
  // Save build data to store
262
- savePagesInStore(storeFolder, griddoPageObjects);
262
+ savePagesInStore(storeDir, griddoPageObjects);
263
263
  };
264
264
 
265
265
  // Pages to be created or deleted in the store
@@ -268,7 +268,7 @@ async function createStore(storeFolder: string, domain: string) {
268
268
  pagesMissingInStore,
269
269
  pagesToDeleteFromStore,
270
270
  pagesToWriteToStore,
271
- } = await getPagesToCreateOrDelete(storeFolder, {
271
+ } = await getPagesToCreateOrDelete(storeDir, {
272
272
  sitesToPublish,
273
273
  pages,
274
274
  validPagesIds,
@@ -276,7 +276,7 @@ async function createStore(storeFolder: string, domain: string) {
276
276
  });
277
277
 
278
278
  // Delete pages from published, unpublished and deleted sites.
279
- removePagesFromStore(storeFolder, pagesToDeleteFromStore);
279
+ removePagesFromStore(storeDir, pagesToDeleteFromStore);
280
280
 
281
281
  // Debug time
282
282
  const changedPageLogs = `Store: ${pagesInStore.length} -> ${pagesInStore}
@@ -302,7 +302,7 @@ async function createStore(storeFolder: string, domain: string) {
302
302
  // Después de renderizar todos los sites y sus páginas (las que sean que
303
303
  // hayan cambiado etc.) guardamos un archivo con la información del
304
304
  // render para usos posteriores.
305
- saveRenderInfoInStore(storeFolder, {
305
+ saveRenderInfoInStore(storeDir, {
306
306
  buildProcessData,
307
307
  createdPages,
308
308
  sitesToPublish,
@@ -76,20 +76,36 @@ interface RenderInfo {
76
76
  sitesToPublish: Array<Site>;
77
77
  }
78
78
 
79
- type LifeCycles = {
80
- doRestore?: boolean;
81
- doData?: boolean;
82
- doSSG?: boolean;
83
- doRelocation?: boolean;
84
- doMeta?: boolean;
85
- doArchive?: boolean;
86
- };
79
+ type LifeCyclesNames =
80
+ | "Prepare"
81
+ | "Restore"
82
+ | "Data"
83
+ | "SSG"
84
+ | "Relocation"
85
+ | "Meta"
86
+ | "Archive"
87
+ | "Clean";
88
+
89
+ type CXDir = "__exports" | "__cache" | "__cx" | "__ssg";
90
+
91
+ interface CXConfig {
92
+ proDomain: string;
93
+ CXDir: {
94
+ EXPORTS: "__exports";
95
+ CACHE: "__cache";
96
+ CX: "__cx";
97
+ SSG: "__ssg";
98
+ };
99
+ dirs: (domain: string) => Record<CXDir, string>;
100
+ }
87
101
 
88
102
  export {
89
103
  BuildProcessData,
104
+ CXConfig,
105
+ CXDir,
90
106
  Domains,
91
107
  FetchDataProps,
92
- LifeCycles,
108
+ LifeCyclesNames,
93
109
  Petition,
94
110
  PostSearchInfoProps,
95
111
  RenderInfo,
@@ -12,9 +12,9 @@ const API_CACHE_DIR_PATH = path.resolve(__dirname, "./../apiCache");
12
12
  const SITE_HASH_FILENAME = `${API_CACHE_DIR_PATH}/siteHash.json`;
13
13
 
14
14
  /**
15
- * Creates an `apiCache` folder to store pages fetched from them API.
15
+ * Creates an `apiCache` dir to store pages fetched from them API.
16
16
  */
17
- function createAPICacheFolder() {
17
+ function createAPICacheDir() {
18
18
  if (!fs.existsSync(API_CACHE_DIR_PATH)) {
19
19
  fs.mkdirSync(API_CACHE_DIR_PATH);
20
20
  }
@@ -67,7 +67,7 @@ function saveCache<T>(petition: Petition, content: T) {
67
67
  }
68
68
 
69
69
  /**
70
- * Search in the `apiCache` folder for a file using the petition as hash generator.
70
+ * Search in the `apiCache` dir for a file using the petition as hash generator.
71
71
  * Return the file content if found or null if not.
72
72
  *
73
73
  * @param petition An object
@@ -124,5 +124,5 @@ export {
124
124
  updatedSiteHash,
125
125
  searchCacheData,
126
126
  saveCache,
127
- createAPICacheFolder,
127
+ createAPICacheDir,
128
128
  };
@@ -1,24 +1,24 @@
1
1
  import path from "node:path";
2
2
 
3
- import { createAPICacheFolder } from "./cache";
4
- import { sanitizeAPICacheFolder } from "./shared";
5
- import { createStoreFolder } from "./store";
3
+ import { createAPICacheDir } from "./cache";
4
+ import { sanitizeAPICacheDir } from "./shared";
5
+ import { createStoreDir } from "./store";
6
6
  import { createStore } from "../services/store";
7
7
 
8
- const storeFolder = path.resolve(__dirname, "../store/");
9
- const apiCacheFolder = path.resolve(__dirname, "../apiCache");
8
+ const storeDir = path.resolve(__dirname, "../store/");
9
+ const apiCacheDir = path.resolve(__dirname, "../apiCache");
10
10
 
11
11
  /**
12
12
  * Download all data: sites, pages etc.. from the instance private Griddo API.
13
13
  * Then you can use the generator funcion `getBuildPages()` to get the pages and
14
14
  * `getBuildMetadata()` to get build and sites metadata as objects. Both from
15
- * exporter utils sites folder.
15
+ * exporter utils sites dir.
16
16
  */
17
17
  async function createBuildData(domain: string) {
18
- createAPICacheFolder();
19
- createStoreFolder(storeFolder);
20
- await createStore(storeFolder, domain);
21
- sanitizeAPICacheFolder(apiCacheFolder);
18
+ createAPICacheDir();
19
+ createStoreDir(storeDir);
20
+ await createStore(storeDir, domain);
21
+ sanitizeAPICacheDir(apiCacheDir);
22
22
  }
23
23
 
24
24
  export { createBuildData };