@griddo/cx 10.6.5 → 10.6.7

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.
@@ -3,7 +3,6 @@ import type { Core, Fields } from "@griddo/core";
3
3
 
4
4
  import { Site } from "./sites";
5
5
 
6
- // TODO: JSDoc
7
6
  interface Settings {
8
7
  apiVersion?: string;
9
8
  avoidCanonicalsOnSitemaps?: boolean;
@@ -28,10 +27,8 @@ interface Settings {
28
27
  welcomeText2?: string;
29
28
  }
30
29
 
31
- // TODO: JSDoc
32
30
  type Petition = Record<string, unknown>;
33
31
 
34
- // TODO: JSDoc
35
32
  interface PostSearchInfoProps {
36
33
  title?: string;
37
34
  description: string | null | undefined;
@@ -44,7 +41,6 @@ interface PostSearchInfoProps {
44
41
  url?: string;
45
42
  }
46
43
 
47
- // TODO: JSDoc
48
44
  interface FetchDataProps {
49
45
  page: Core.Page;
50
46
  component: {
@@ -54,7 +50,6 @@ interface FetchDataProps {
54
50
  cacheKey: string;
55
51
  }
56
52
 
57
- // TODO: JSDoc
58
53
  type Domains = Array<{
59
54
  id: number;
60
55
  slug: string;
@@ -64,10 +59,8 @@ type Domains = Array<{
64
59
  /** Describes the type of build process data object. */
65
60
  type BuildProcessData = Record<string, EndSiteRenderBody>;
66
61
 
67
- // TODO: JSDoc
68
62
  type Robot = { path: string; content: string };
69
63
 
70
- // TODO: JSDoc
71
64
  type Robots = Array<Robot>;
72
65
 
73
66
  interface RenderInfo {
@@ -89,7 +82,7 @@ type LifeCyclesNames =
89
82
  | "Close"
90
83
  | "__DEBUG__";
91
84
 
92
- type CXDir =
85
+ type PlaceholderPath =
93
86
  | "__exports"
94
87
  | "__caches"
95
88
  | "__cx"
@@ -102,17 +95,7 @@ type CXDir =
102
95
  interface CXConfig {
103
96
  proDomain: string;
104
97
  griddoVersion: string;
105
- CXDir: {
106
- EXPORTS: "__exports";
107
- CACHE: "__caches";
108
- CX: "__cx";
109
- SSG: "__ssg";
110
- COMPONENTS: "__components";
111
- ROOT: "__root";
112
- EXPORTS_DIST: "__exports_dist";
113
- CX_DIST: "__cx_dist";
114
- };
115
- paths: (domain?: string) => Record<CXDir, string>;
98
+ paths: (domain?: string) => Record<PlaceholderPath, string>;
116
99
  }
117
100
 
118
101
  interface AIEmbeddingsResponse {
@@ -120,18 +103,26 @@ interface AIEmbeddingsResponse {
120
103
  message: string;
121
104
  }
122
105
 
123
- export {
106
+ interface Artifacts {
107
+ disposables: Array<string>;
108
+ cacheables: Array<string>;
109
+ initials: Array<string>;
110
+ archivables: Array<string>;
111
+ }
112
+
113
+ export type {
114
+ AIEmbeddingsResponse,
115
+ Artifacts,
124
116
  BuildProcessData,
125
117
  CXConfig,
126
- CXDir,
127
118
  Domains,
128
119
  FetchDataProps,
129
120
  LifeCyclesNames,
130
121
  Petition,
122
+ PlaceholderPath,
131
123
  PostSearchInfoProps,
132
124
  RenderInfo,
133
125
  Robot,
134
126
  Robots,
135
127
  Settings,
136
- type AIEmbeddingsResponse,
137
128
  };
@@ -10,13 +10,11 @@ export type APIPageObject = Core.Page & { id: number } & {
10
10
  footer: number | null;
11
11
  };
12
12
 
13
- // TODO: JSDoc
14
13
  export type CleanPage = Core.Page & {
15
14
  isRoot: boolean;
16
15
  defaultLang?: Core.SiteLanguage | undefined;
17
16
  };
18
17
 
19
- // TODO: JSDoc
20
18
  export type RenderPage = Core.Page & {
21
19
  isRoot?: boolean;
22
20
  multiPageElements: MultiPageElements;
@@ -31,12 +29,10 @@ export type RenderPage = Core.Page & {
31
29
  mode: "list";
32
30
  };
33
31
 
34
- // TODO: JSDoc
35
32
  export type GriddoSinglePage = Core.Page & {
36
33
  defaultLang?: Core.SiteLanguage;
37
34
  };
38
35
 
39
- // TODO: JSDoc
40
36
  export type GriddoListPage = Core.Page & {
41
37
  page: APIPageObject;
42
38
  pages: Array<Array<Fields.QueriedDataItem>>;
@@ -52,7 +48,6 @@ export type GriddoListPage = Core.Page & {
52
48
  totalQueriedItems: Array<Fields.QueriedDataItem>;
53
49
  };
54
50
 
55
- // TODO: JSDoc
56
51
  export type GriddoMultiPage = Core.Page & {
57
52
  header: number | null;
58
53
  footer: number | null;
@@ -61,7 +56,6 @@ export type GriddoMultiPage = Core.Page & {
61
56
  defaultLang?: Core.SiteLanguage | undefined;
62
57
  };
63
58
 
64
- // TODO: JSDoc
65
59
  export interface AdditionalInfo {
66
60
  baseUrl: string;
67
61
  cloudinaryName?: string;
@@ -86,7 +80,6 @@ export interface AdditionalInfo {
86
80
  theme: string;
87
81
  }
88
82
 
89
- // TODO: JSDoc
90
83
  export interface PageAdditionalInfo extends AdditionalInfo {
91
84
  navigations: {
92
85
  header: Record<string, unknown> | null;
@@ -94,7 +87,6 @@ export interface PageAdditionalInfo extends AdditionalInfo {
94
87
  };
95
88
  }
96
89
 
97
- // TODO: JSDoc
98
90
  export type MultiPageElement = {
99
91
  component: string;
100
92
  title: string | Required<Fields.Heading>;
@@ -105,7 +97,6 @@ export type MultiPageElement = {
105
97
  metaDescription: string;
106
98
  };
107
99
 
108
- // TODO: JSDoc
109
100
  export type MultiPageElements = Array<MultiPageElement>;
110
101
 
111
102
  /**
@@ -46,7 +46,6 @@ export interface Site
46
46
  updated: boolean;
47
47
  }
48
48
 
49
- // TODO: JSDoc
50
49
  export interface SiteData {
51
50
  siteInfo: Site;
52
51
  validPagesIds: Array<number>;
@@ -59,8 +58,6 @@ export interface SiteData {
59
58
  socials: SocialsResponse;
60
59
  }
61
60
 
62
- // TODO: JSDoc
63
61
  export type SiteHash = string | null;
64
62
 
65
- // TODO: JSDoc
66
63
  export type HashSites = Record<string, number | string>;
@@ -13,7 +13,9 @@ import pkgDir from "pkg-dir";
13
13
 
14
14
  import { createDirsSync, removeDirsSync } from "./folders";
15
15
  import { boxLog, verboseLog } from "./loggin";
16
+ import { generateBuildReport, generateSitemaps } from "./sites";
16
17
  import { envs } from "../constants";
18
+ import { writeRobots } from "../services/robots";
17
19
 
18
20
  dotenv.config();
19
21
 
@@ -212,7 +214,6 @@ function sanitizeAPICacheDir() {
212
214
  if (validPageFile) filesByIdMap[id] = fileName;
213
215
  }
214
216
 
215
- // TODO: Remove this counter for production
216
217
  let counter = 0;
217
218
 
218
219
  // Delete files using the store object filesById as reference map.
@@ -280,6 +281,7 @@ function pause(title: string) {
280
281
  * retries.
281
282
  *
282
283
  * @async
284
+ * @param name - The name of the life cycle.
283
285
  * @param options - The arguments object.
284
286
  * @param options.steps - An array of functions to execute.
285
287
  * @param options.delay - Delay between steps functions.
@@ -361,7 +363,21 @@ function isVersionLowerThan(versionA: string, versionB: string) {
361
363
  return !isVersionGreaterThan(versionA, versionB);
362
364
  }
363
365
 
366
+ /**
367
+ * Creates additional files after the render: sitemaps, robots and a report of
368
+ * the finished render.
369
+ *
370
+ * @async
371
+ * @param domain
372
+ */
373
+ async function createRenderMetadata(domain: string) {
374
+ await generateBuildReport();
375
+ await generateSitemaps();
376
+ await writeRobots(domain);
377
+ }
378
+
364
379
  export {
380
+ createRenderMetadata,
365
381
  delay,
366
382
  doLifeCycle,
367
383
  exporterCleanDisposableDirectories,
@@ -4,6 +4,7 @@ import path from "node:path";
4
4
  import fsx, { MakeDirectoryOptions } from "fs-extra";
5
5
 
6
6
  import { getConfig } from "./core-utils";
7
+ import { verboseLog } from "./loggin";
7
8
  import { getPageInStoreDir, removePagesFromStore } from "./store";
8
9
 
9
10
  const config = getConfig();
@@ -132,53 +133,6 @@ function copyDirsSync(
132
133
  }
133
134
  }
134
135
 
135
- /**
136
- * Move artifacts between CX valid directories.
137
- *
138
- * @param src - Source directory.
139
- * @param dst - Destination directory.
140
- * @param dirs - Directories to move.
141
- * @param options - Options.
142
- */
143
- function moveDirsSync(
144
- src: string,
145
- dst: string,
146
- dirs: Array<string>,
147
- options?: { withBackup?: boolean; override?: boolean },
148
- ) {
149
- const { override, withBackup } = options || {};
150
-
151
- for (const dir of dirs) {
152
- const srcCompose = path.join(src, dir);
153
- const dstCompose = path.join(dst, dir);
154
-
155
- if (!fsx.existsSync(srcCompose)) {
156
- continue;
157
- }
158
-
159
- if (withBackup) {
160
- createBackup(dstCompose);
161
- }
162
-
163
- try {
164
- // Clean destination
165
- if (override && fsx.existsSync(dstCompose)) {
166
- fs.rmSync(dstCompose, { recursive: true, force: true });
167
- }
168
- fs.renameSync(srcCompose, dstCompose);
169
- if (withBackup) {
170
- deleteBackup(dstCompose);
171
- }
172
- } catch (e) {
173
- console.log("Move failed!");
174
- if (withBackup) {
175
- restoreBackup(dstCompose);
176
- console.log("Backup has been restored.");
177
- }
178
- }
179
- }
180
- }
181
-
182
136
  /**
183
137
  * Remove directories from `basePath` directory.
184
138
  *
@@ -293,12 +247,171 @@ function clearSitemapsFromDirs(initialFolder: string) {
293
247
  removeXmlFiles(initialFolder);
294
248
  }
295
249
 
250
+ /**
251
+ * Removes multiple artifact directories.
252
+ *
253
+ * @param artifacts - An array of artifact directory paths.
254
+ */
255
+ function removeArtifacts(artifacts: Array<string>) {
256
+ for (const dir of artifacts) {
257
+ if (!dir) {
258
+ continue;
259
+ }
260
+
261
+ if (fsx.existsSync(dir)) {
262
+ fs.rmSync(dir, { recursive: true, force: true });
263
+ verboseLog(`removed directory: ${dir}`);
264
+ }
265
+ }
266
+ }
267
+
268
+ /**
269
+ * Creates multiple directories.
270
+ *
271
+ * @param dirs - An array of directory paths.
272
+ * @param options - Same option as `fs.mkdirSync()`
273
+ */
274
+ function createArtifacts(dirs: Array<string>, options?: MakeDirectoryOptions) {
275
+ for (const dir of dirs) {
276
+ if (!fs.existsSync(dir)) {
277
+ fs.mkdirSync(dir, { recursive: true, ...options });
278
+ verboseLog(`create directory: ${dir}`);
279
+ }
280
+ }
281
+ }
282
+
283
+ /**
284
+ * Copy multiple directories with backup option.
285
+ *
286
+ * @param src - Source directory.
287
+ * @param dst - Destination directory.
288
+ * @param dirs - Directories to copy.
289
+ * @param options.withBackup - Create a previous backup before copy.
290
+ */
291
+ function copyArtifacts(
292
+ src: string,
293
+ dst: string,
294
+ dirs: Array<string>,
295
+ options = {
296
+ withBackup: false,
297
+ },
298
+ ) {
299
+ const { withBackup } = options;
300
+ for (const dir of dirs) {
301
+ const srcCompose = path.join(src, dir);
302
+ const dstCompose = path.join(dst, dir);
303
+
304
+ // The dir we want to copy, doesn't exist.
305
+ if (!fsx.existsSync(srcCompose)) {
306
+ console.log(
307
+ `(Maybe first render) Source directory does not exist: ${srcCompose}`,
308
+ );
309
+ continue;
310
+ }
311
+
312
+ // Create the backup
313
+ if (withBackup) {
314
+ createBackup(dstCompose);
315
+ verboseLog(`create backup: ${dstCompose}`);
316
+ }
317
+
318
+ // Copy directory
319
+ try {
320
+ // First clean destination
321
+ if (fsx.existsSync(dstCompose)) {
322
+ fs.rmSync(dstCompose, { recursive: true, force: true });
323
+ verboseLog(`clean destination: ${dstCompose}`);
324
+ }
325
+
326
+ // Then copy src to dst
327
+ fs.cpSync(srcCompose, dstCompose, {
328
+ recursive: true,
329
+ preserveTimestamps: true,
330
+ });
331
+ verboseLog(`copy: ${srcCompose} to ${dstCompose}`);
332
+
333
+ if (withBackup) {
334
+ deleteBackup(dstCompose);
335
+ verboseLog(`delete backup: ${dstCompose}`);
336
+ }
337
+ } catch (e) {
338
+ console.log("copy failed!");
339
+ if (withBackup) {
340
+ restoreBackup(dstCompose);
341
+ console.log("Backup has been restored.");
342
+ }
343
+ }
344
+ }
345
+ }
346
+
347
+ function renameArtifact(src: string, dst: string) {
348
+ if (fs.existsSync(src)) {
349
+ fs.renameSync(src, dst);
350
+ verboseLog(`rename ${src} to ${dst}`);
351
+ }
352
+ }
353
+
354
+ /**
355
+ * Move artifacts between cx-paths
356
+ *
357
+ * @param src - Source directory.
358
+ * @param dst - Destination directory.
359
+ * @param dirs - Directories to move.
360
+ * @param options - Options.
361
+ */
362
+ function moveArtifacts(
363
+ src: string,
364
+ dst: string,
365
+ dirs: Array<string>,
366
+ options?: { withBackup?: boolean; override?: boolean },
367
+ ) {
368
+ const { override, withBackup } = options || {};
369
+
370
+ for (const dir of dirs) {
371
+ const srcCompose = path.join(src, dir);
372
+ const dstCompose = path.join(dst, dir);
373
+
374
+ if (!fsx.existsSync(srcCompose)) {
375
+ continue;
376
+ }
377
+
378
+ if (withBackup) {
379
+ createBackup(dstCompose);
380
+ }
381
+
382
+ try {
383
+ // Clean destination
384
+ if (override && fsx.existsSync(dstCompose)) {
385
+ fs.rmSync(dstCompose, { recursive: true, force: true });
386
+ }
387
+
388
+ fs.renameSync(srcCompose, dstCompose);
389
+ verboseLog(`moved: ${srcCompose} to ${dstCompose}`);
390
+
391
+ if (withBackup) {
392
+ deleteBackup(dstCompose);
393
+ }
394
+ } catch (e) {
395
+ if (withBackup) {
396
+ restoreBackup(dstCompose);
397
+ console.log("Backup has been restored.");
398
+ }
399
+
400
+ throw new Error(JSON.stringify(e));
401
+ }
402
+ }
403
+ }
404
+
296
405
  export {
297
406
  clearEmptyDirs,
298
407
  clearSitemapsFromDirs,
408
+ copyArtifacts,
299
409
  copyDirsSync,
410
+ createArtifacts,
300
411
  createDirsSync,
301
- moveDirsSync,
412
+ moveArtifacts,
413
+ removeArtifacts,
302
414
  removeDirsSync,
303
415
  removeVirtualPagesFromStore,
416
+ renameArtifact,
304
417
  };
@@ -12,13 +12,13 @@ const config = getConfig();
12
12
  * This file is used to track later if node_modules/@griddo/cx was cleaned by a
13
13
  * npm install from a deploy.
14
14
  */
15
- function createSentinelDomainRenderFile() {
15
+ function createSentinelRenderFile() {
16
16
  const { __cx } = config.paths();
17
17
  const renderSentinelFile = path.join(__cx, ".render-sentinel");
18
18
  fs.writeFileSync(renderSentinelFile, new Date().toISOString());
19
19
  }
20
20
 
21
- function deleteSentinelFile() {
21
+ function deleteSentinelRenderFile() {
22
22
  const { __cx } = config.paths();
23
23
  const renderSentinelFile = path.join(__cx, ".render-sentinel");
24
24
  fs.unlinkSync(renderSentinelFile);
@@ -33,7 +33,7 @@ function isValidRenderProcessOrThrow() {
33
33
  }
34
34
 
35
35
  function initRender() {
36
- createSentinelDomainRenderFile();
36
+ createSentinelRenderFile();
37
37
  }
38
38
 
39
39
  function finishRender() {
@@ -44,6 +44,6 @@ export {
44
44
  finishRender,
45
45
  initRender,
46
46
  isValidRenderProcessOrThrow,
47
- createSentinelDomainRenderFile,
48
- deleteSentinelFile,
47
+ createSentinelRenderFile,
48
+ deleteSentinelRenderFile,
49
49
  };
@@ -85,7 +85,6 @@ function getBuildPagesPath() {
85
85
 
86
86
  /**
87
87
  * Get the build metadata from the Store.
88
- * TODO: Refactorizar para leer un solo archivo: __metadata__.json
89
88
  */
90
89
  async function getBuildMetadata(): Promise<BuildMetaData> {
91
90
  const { __cx } = config.paths();
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.6.5",
4
+ "version": "10.6.7",
5
5
  "authors": [
6
6
  "Álvaro Sánchez' <alvaro.sanches@secuoyas.com>",
7
7
  "Diego M. Béjar <diego.bejar@secuoyas.com>",
@@ -32,7 +32,7 @@
32
32
  "complete-render": "node ./build/build-complete.js",
33
33
  "reset-render": "node ./build/reset-render.js",
34
34
  "// SSG": "",
35
- "clean": "gatsby clean; rm -rf .cache public assets",
35
+ "clean": "gatsby clean; rm -rf assets caches store apiCache build .render-sentinel",
36
36
  "gatsby-build": "gatsby telemetry --disable && gatsby build --prefix-paths",
37
37
  "// LINTER": "",
38
38
  "watch:typescript-lint": "tsc --noEmit --watch",
@@ -46,7 +46,7 @@
46
46
  "@babel/preset-env": "^7.14.5",
47
47
  "@babel/preset-react": "^7.14.5",
48
48
  "@babel/preset-typescript": "^7.16.5",
49
- "@griddo/core": "10.6.5",
49
+ "@griddo/core": "10.6.7",
50
50
  "@svgr/webpack": "^5.5.0",
51
51
  "babel-loader": "^8.0.6",
52
52
  "babel-plugin-transform-runtime": "^6.23.0",
@@ -75,7 +75,7 @@
75
75
  "@types/react-dom": "18.0.11",
76
76
  "@types/react-helmet": "^6.1.6",
77
77
  "@types/webpack": "^5.28.0",
78
- "cheerio": "^1.0.0-rc.12",
78
+ "cheerio": "^0.22.0",
79
79
  "eslint": "^8.0.0",
80
80
  "eslint-plugin-node": "^11.1.0",
81
81
  "eslint-plugin-react": "7.34.2",
@@ -114,5 +114,5 @@
114
114
  "publishConfig": {
115
115
  "access": "public"
116
116
  },
117
- "gitHead": "4a065853330bcae74912ddb0f0785af16b0e261a"
117
+ "gitHead": "7518a5fa486026aeeceee57d87fac1841e9e35a6"
118
118
  }
package/src/types.ts CHANGED
@@ -41,7 +41,6 @@ interface HtmlProps {
41
41
  preBodyComponents: React.ReactNode;
42
42
  }
43
43
 
44
- // TODO: JSDoc
45
44
  type GatsbyPageObject = {
46
45
  matchPath?: string;
47
46
  path: string;