@griddo/cx 10.4.11 → 10.4.13

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 (116) hide show
  1. package/README.md +1 -1
  2. package/build/adapters/gatsby/index.d.ts +2 -0
  3. package/build/adapters/gatsby/utils.d.ts +26 -0
  4. package/build/adapters/index.d.ts +3 -0
  5. package/build/browser/index.d.ts +5 -0
  6. package/build/browser/index.js +1 -0
  7. package/build/build-complete.d.ts +18 -0
  8. package/build/index.d.ts +29 -0
  9. package/build/index.js +37 -38
  10. package/build/move-assets.d.ts +1 -0
  11. package/build/react/index.d.ts +2 -0
  12. package/build/reset-render.d.ts +1 -0
  13. package/build/run-start-render.d.ts +1 -0
  14. package/build/run-start-render.js +69 -0
  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 +70 -0
  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/utils/api.d.ts +23 -0
  32. package/build/utils/cache.d.ts +35 -0
  33. package/build/utils/create-build-data.d.ts +8 -0
  34. package/build/utils/domains.d.ts +5 -0
  35. package/build/utils/folders.d.ts +48 -0
  36. package/build/utils/health-checks.d.ts +7 -0
  37. package/build/utils/instance.d.ts +21 -0
  38. package/build/utils/messages.d.ts +2 -0
  39. package/build/utils/pages.d.ts +34 -0
  40. package/build/utils/searches.d.ts +14 -0
  41. package/build/utils/shared.d.ts +109 -0
  42. package/build/utils/sites.d.ts +36 -0
  43. package/build/utils/store.d.ts +63 -0
  44. package/build/utils/temp-utils.d.ts +10 -0
  45. package/{exporter/cx.config.d.ts → cx.config.d.ts} +1 -2
  46. package/{exporter/cx.config.js → cx.config.js} +5 -8
  47. package/package.json +24 -29
  48. package/src/adapters/gatsby/index.ts +219 -0
  49. package/src/adapters/gatsby/utils.ts +85 -0
  50. package/src/browser/README.md +3 -0
  51. package/src/browser/index.ts +46 -0
  52. package/src/index.ts +48 -0
  53. package/src/move-assets.ts +8 -0
  54. package/src/react/index.ts +5 -0
  55. package/src/run-start-render.ts +3 -0
  56. package/{exporter → src}/services/robots.ts +1 -5
  57. package/{exporter → src}/services/store.ts +6 -1
  58. package/src/start-render.ts +19 -0
  59. package/{exporter → src}/types/global.ts +4 -3
  60. package/src/utils/folders.ts +268 -0
  61. package/{exporter → src}/utils/instance.ts +2 -2
  62. package/{exporter → src}/utils/pages.ts +2 -9
  63. package/{exporter → src}/utils/searches.ts +5 -8
  64. package/{exporter → src}/utils/shared.ts +5 -2
  65. package/{exporter → src}/utils/sites.ts +1 -8
  66. package/{exporter → src}/utils/temp-utils.ts +35 -8
  67. package/ssg/README.md +1 -0
  68. package/ssg/astro/.gitkeep +0 -0
  69. package/ssg/gatsby/.eslintrc.json +51 -0
  70. package/ssg/gatsby/.prettierignore +6 -0
  71. package/ssg/gatsby/.prettierrc.json +3 -0
  72. package/{gatsby-browser.tsx → ssg/gatsby/gatsby-browser.tsx} +42 -44
  73. package/{gatsby-config.ts → ssg/gatsby/gatsby-config.ts} +1 -2
  74. package/{gatsby-node.ts → ssg/gatsby/gatsby-node.ts} +11 -8
  75. package/{gatsby-ssr.tsx → ssg/gatsby/gatsby-ssr.tsx} +1 -1
  76. package/ssg/gatsby/global.d.ts +1 -0
  77. package/ssg/gatsby/package.json +85 -0
  78. package/{src → ssg/gatsby/src}/components/Head.tsx +2 -2
  79. package/{src → ssg/gatsby/src}/components/template.tsx +2 -3
  80. package/{src → ssg/gatsby/src}/gatsby-node-utils.ts +6 -5
  81. package/{src → ssg/gatsby/src}/types.ts +5 -4
  82. package/ssg/gatsby/tsconfig.json +15 -0
  83. package/start-render.js +7 -0
  84. package/build/create-build-data.js +0 -60
  85. package/exporter/adapters/gatsby/index.ts +0 -159
  86. package/exporter/adapters/gatsby/utils.ts +0 -377
  87. package/exporter/create-build-data.ts +0 -22
  88. package/exporter/index.ts +0 -23
  89. package/exporter/utils/folders.ts +0 -318
  90. package/exporter/utils/integrations.ts +0 -36
  91. package/exporter/utils/runners.ts +0 -52
  92. package/index.js +0 -7
  93. /package/{exporter → src}/adapters/index.ts +0 -0
  94. /package/{exporter → src}/build-complete.ts +0 -0
  95. /package/{exporter → src}/reset-render.ts +0 -0
  96. /package/{exporter → src}/services/auth.ts +0 -0
  97. /package/{exporter → src}/services/distributors.ts +0 -0
  98. /package/{exporter → src}/services/domains.ts +0 -0
  99. /package/{exporter → src}/services/navigation.ts +0 -0
  100. /package/{exporter → src}/services/settings.ts +0 -0
  101. /package/{exporter → src}/services/sites.ts +0 -0
  102. /package/{exporter → src}/types/api.ts +0 -0
  103. /package/{exporter → src}/types/navigation.ts +0 -0
  104. /package/{exporter → src}/types/pages.ts +0 -0
  105. /package/{exporter → src}/types/sites.ts +0 -0
  106. /package/{exporter → src}/types/templates.ts +0 -0
  107. /package/{exporter → src}/utils/api.ts +0 -0
  108. /package/{exporter → src}/utils/cache.ts +0 -0
  109. /package/{exporter/utils/download-build-data.ts → src/utils/create-build-data.ts} +0 -0
  110. /package/{exporter → src}/utils/domains.ts +0 -0
  111. /package/{exporter → src}/utils/health-checks.ts +0 -0
  112. /package/{exporter → src}/utils/messages.ts +0 -0
  113. /package/{exporter → src}/utils/store.ts +0 -0
  114. /package/{src → ssg/gatsby/src}/README.md +0 -0
  115. /package/{src → ssg/gatsby/src}/html.tsx +0 -0
  116. /package/{src → ssg/gatsby/src}/utils.ts +0 -0
@@ -0,0 +1,3 @@
1
+ # browser code
2
+
3
+ browser/index.ts can't contain nodejs code, only browser compatible.
@@ -0,0 +1,46 @@
1
+ import { Core } from "@griddo/core";
2
+
3
+ function filterBodyIntegrationFromPosition(
4
+ integrations: Array<Core.PageIntegration>,
5
+ position: "start" | "end"
6
+ ) {
7
+ return (
8
+ integrations
9
+ ?.filter(
10
+ (integration) =>
11
+ integration.contentBody !== null &&
12
+ integration.contentBody !== "" &&
13
+ integration.contentBodyPosition === position
14
+ )
15
+ .map((integration) => integration.contentBody!) || []
16
+ );
17
+ }
18
+
19
+ function filterHeadIntegrations(integrations: Array<Core.PageIntegration>) {
20
+ return (
21
+ integrations
22
+ ?.filter(
23
+ (integration) =>
24
+ integration.contentHead !== null && integration.contentHead !== ""
25
+ )
26
+ .map((integration) => integration.contentHead!) || []
27
+ );
28
+ }
29
+
30
+ function filterPositionIntegrations(
31
+ integrations: Array<Core.PageIntegration>,
32
+ position: "head" | "start" | "end"
33
+ ) {
34
+ switch (position) {
35
+ case "head":
36
+ return filterHeadIntegrations(integrations);
37
+ default:
38
+ return filterBodyIntegrationFromPosition(integrations, position);
39
+ }
40
+ }
41
+
42
+ export {
43
+ filterBodyIntegrationFromPosition,
44
+ filterHeadIntegrations,
45
+ filterPositionIntegrations,
46
+ };
package/src/index.ts ADDED
@@ -0,0 +1,48 @@
1
+ /**
2
+ *
3
+ * Griddo CX library main export file.
4
+ *
5
+ * This file exports functions to use in both: adapters and SSG's frameworks.
6
+ * Turning CX basically in a javascript library.
7
+ *
8
+ * # Browser context.
9
+ * There is another export in the `/browser` directory to use exclusivelly in
10
+ * the browser context where nodejs (path, fs, etc..) is not available.
11
+ *
12
+ * # Render script (bin)
13
+ * The binary file of the package is `run-start-render.ts`.
14
+ *
15
+ * # Separate scripts.
16
+ * There are some separate .ts files as build-complete.ts or reset-render.ts
17
+ * that are intended to be used by infra via npm script like `npm run
18
+ * build-complete`
19
+ *
20
+ */
21
+
22
+ /* prettier-ignore */ import type { SocialsResponse } from "./types/api";
23
+ /* prettier-ignore */ import type { AdditionalInfo, GriddoListPage, GriddoMultiPage, GriddoPageObject, GriddoSinglePage, } from "./types/pages";
24
+ /* prettier-ignore */ import type { Site } from "./types/sites";
25
+
26
+ /* prettier-ignore */ import { startRender } from "./start-render";
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";
30
+ /* prettier-ignore */ import { getConfig } from "./utils/temp-utils";
31
+
32
+ export {
33
+ AdditionalInfo,
34
+ GriddoListPage,
35
+ GriddoMultiPage,
36
+ GriddoPageObject,
37
+ GriddoSinglePage,
38
+ IS_COMPONENT_LIBRARY,
39
+ PROJECT_ALIASES,
40
+ Site,
41
+ SocialsResponse,
42
+ getBuildPages,
43
+ getConfig,
44
+ logInfo,
45
+ logPageSize,
46
+ resolveComponentsPath,
47
+ startRender,
48
+ };
@@ -0,0 +1,8 @@
1
+ import { execSync } from "child_process";
2
+ import path from "path";
3
+
4
+ const domainName = "pro-griddo";
5
+ const domainPath = path.resolve(__dirname, `../../exports/sites/${domainName}`);
6
+
7
+ execSync(`mkdir -p ${domainPath}/assets/${domainName}`);
8
+ execSync(`cp -R ${domainPath}/assets/* ${domainPath}/assets/${domainName}`);
@@ -0,0 +1,5 @@
1
+ function Foo() {
2
+ return null;
3
+ }
4
+
5
+ export { Foo };
@@ -0,0 +1,3 @@
1
+ import { startRender } from "./start-render";
2
+
3
+ startRender();
@@ -64,11 +64,7 @@ class RobotsService {
64
64
  }
65
65
 
66
66
  if (fs.existsSync(distDirectory)) {
67
- const fileLocation = JSON.parse(
68
- process.env.GRIDDO_EXPORT_STRIP_DOMAIN_FROM_PATH || "false"
69
- )
70
- ? path.join(distDirectory, "robots.txt")
71
- : path.join(distDirectory, robot.path, "robots.txt");
67
+ const fileLocation = path.join(distDirectory, "robots.txt");
72
68
  fs.writeFileSync(fileLocation, robot?.content);
73
69
  } else {
74
70
  console.log(`${distDirectory} not found`);
@@ -7,6 +7,9 @@ import type {
7
7
  PageAdditionalInfo,
8
8
  } from "../types/pages";
9
9
 
10
+ import fs from "node:fs";
11
+ import path from "node:path";
12
+
10
13
  import dotenv from "dotenv";
11
14
  import pLimit from "p-limit";
12
15
 
@@ -14,7 +17,6 @@ import { DistributorService } from "./distributors";
14
17
  import { NavigationService } from "./navigation";
15
18
  import { SettingsService } from "./settings";
16
19
  import { SitesService } from "./sites";
17
- import { version as griddoVersion } from "../../package.json";
18
20
  import { updatedSiteHash } from "../utils/cache";
19
21
  import {
20
22
  createGriddoListPages,
@@ -47,6 +49,9 @@ dotenv.config();
47
49
  */
48
50
  async function createStore(storeDir: string, domain: string) {
49
51
  console.info(`API calls with ${API_CONCURRENCY_COUNT} threads`);
52
+ const { version: griddoVersion } = JSON.parse(
53
+ fs.readFileSync(path.resolve(__dirname, "../package.json"), "utf-8")
54
+ );
50
55
 
51
56
  try {
52
57
  // Vars to save later in the report file
@@ -0,0 +1,19 @@
1
+ #!/usr/bin/env node
2
+ /* eslint-disable node/shebang */
3
+
4
+ import { runGatsbyAdapter } from "./adapters";
5
+ import { logBox, measureExecutionTime } from "./utils/shared";
6
+
7
+ async function startRender() {
8
+ const exeTime = await measureExecutionTime(runGatsbyAdapter).catch((e) => {
9
+ console.log(e);
10
+ console.log("<[ Render will be reset ]>");
11
+ process.exit(1);
12
+ });
13
+
14
+ logBox(`All domains rendered in ${exeTime}s.`, "", 1, 0);
15
+
16
+ process.exit(0);
17
+ }
18
+
19
+ export { startRender };
@@ -84,11 +84,12 @@ type LifeCyclesNames =
84
84
  | "Relocation"
85
85
  | "Meta"
86
86
  | "Archive"
87
- | "Clean";
87
+ | "Clean"
88
+ | "__DEBUG__";
88
89
 
89
90
  type CXDir =
90
91
  | "__exports"
91
- | "__cache"
92
+ | "__caches"
92
93
  | "__cx"
93
94
  | "__ssg"
94
95
  | "__components"
@@ -98,7 +99,7 @@ interface CXConfig {
98
99
  proDomain: string;
99
100
  CXDir: {
100
101
  EXPORTS: "__exports";
101
- CACHE: "__cache";
102
+ CACHE: "__caches";
102
103
  CX: "__cx";
103
104
  SSG: "__ssg";
104
105
  COMPONENTS: "__components";
@@ -0,0 +1,268 @@
1
+ import fs from "node:fs";
2
+ import path from "node:path";
3
+
4
+ import fsx, { MakeDirectoryOptions } from "fs-extra";
5
+
6
+ import { CXRootDir } from "./shared";
7
+ import { getPageInStoreDir, removePagesFromStore } from "./store";
8
+ import { getConfig } from "./temp-utils";
9
+
10
+ /**
11
+ * Remove an empty directory from the basePath recursively.
12
+ * If the directory has only .xml files it will handle as empty too (empty site)
13
+ *
14
+ * @param baseDir - The base directory.
15
+ */
16
+ const clearEmptyDirs = (baseDir?: string) => {
17
+ const dir = baseDir || path.resolve(CXRootDir, "dist");
18
+
19
+ const isDir = fsx.statSync(dir).isDirectory();
20
+ if (!isDir) {
21
+ return;
22
+ }
23
+
24
+ // archivos o direvtorios dentro de `dir`
25
+ let children = fsx.readdirSync(dir);
26
+ // let children = childrenRaw.filter((file) => {
27
+ // return path.extname(file).toLowerCase() !== ".xml";
28
+ // });
29
+ const dirHasChildren = children.length > 0;
30
+
31
+ // Por cada uno de ellos miramos si tiene hijos, enviamos cada uno de ellos
32
+ // a `clearEmptyDirsWithXML`
33
+ if (dirHasChildren) {
34
+ const childrenCount = children.length;
35
+ const xmlCount = children.filter((file) => {
36
+ return path.extname(file).toLowerCase() === ".xml";
37
+ }).length;
38
+
39
+ // Todos los hijos son archivos .xml
40
+ // Podemos borrarlos y dejar el dir vacío.
41
+ if (childrenCount === xmlCount) {
42
+ children.forEach(function (xmlFile) {
43
+ const fullPath = path.join(dir, xmlFile);
44
+ fsx.rmSync(fullPath);
45
+ });
46
+ children = fsx.readdirSync(dir);
47
+ }
48
+
49
+ children.forEach(function (file) {
50
+ const fullPath = path.join(dir, file);
51
+ clearEmptyDirs(fullPath);
52
+ });
53
+
54
+ // re-evaluate files; after deleting subdir we may have parent dir
55
+ // empty now...
56
+ children = fsx.readdirSync(dir);
57
+ }
58
+
59
+ // Si no tiene hijos, lo borramos
60
+ if (children.length === 0) {
61
+ fsx.rmdirSync(dir);
62
+ return;
63
+ }
64
+ };
65
+
66
+ /**
67
+ * Creates multiple directories.
68
+ *
69
+ * @param dirs - An array of directory paths.
70
+ * @param options - Same option as `fs.mkdirSync()`
71
+ */
72
+ function createDirsSync(dirs: Array<string>, options?: MakeDirectoryOptions) {
73
+ for (const dir of dirs) {
74
+ if (!fs.existsSync(dir)) {
75
+ fs.mkdirSync(dir, { recursive: true, ...options });
76
+ }
77
+ }
78
+ }
79
+
80
+ /**
81
+ * Copy multiple directories with backup option.
82
+ *
83
+ * @param src - Source directory.
84
+ * @param dst - Destination directory.
85
+ * @param dirs - Directories to copy.
86
+ * @param options.withBackup - Create a previous backup before copy.
87
+ */
88
+ function copyDirsSync(
89
+ src: string,
90
+ dst: string,
91
+ dirs: Array<string>,
92
+ options = {
93
+ withBackup: false,
94
+ }
95
+ ) {
96
+ const { withBackup } = options;
97
+ for (const dir of dirs) {
98
+ const srcCompose = path.join(src, dir);
99
+ const dstCompose = path.join(dst, dir);
100
+
101
+ // The dir we want to copy, doesn't exist.
102
+ if (!fsx.existsSync(srcCompose)) {
103
+ console.log(`Source directory does not exist: ${srcCompose}`);
104
+ continue;
105
+ }
106
+
107
+ // Create the backup
108
+ if (withBackup) {
109
+ createBackup(dstCompose);
110
+ }
111
+
112
+ // Copy directory
113
+ try {
114
+ // First clean destination
115
+ if (fsx.existsSync(dstCompose)) {
116
+ fs.rmSync(dstCompose, { recursive: true, force: true });
117
+ }
118
+ // Then copy src to dst
119
+ fs.cpSync(srcCompose, dstCompose, { recursive: true });
120
+ if (withBackup) {
121
+ deleteBackup(dstCompose);
122
+ }
123
+ } catch (e) {
124
+ console.log("Copy failed!");
125
+ if (withBackup) {
126
+ restoreBackup(dstCompose);
127
+ console.log("Backup has been restored.");
128
+ }
129
+ }
130
+ }
131
+ }
132
+
133
+ /**
134
+ * Move artifacts between CX valid directories.
135
+ *
136
+ * @param src - Source directory.
137
+ * @param dst - Destination directory.
138
+ * @param dirs - Directories to move.
139
+ * @param options - Options.
140
+ */
141
+ function moveDirsSync(
142
+ src: string,
143
+ dst: string,
144
+ dirs: Array<string>,
145
+ options?: { withBackup?: boolean; override?: boolean }
146
+ ) {
147
+ const { override, withBackup } = options || {};
148
+
149
+ for (const dir of dirs) {
150
+ const srcCompose = path.join(src, dir);
151
+ const dstCompose = path.join(dst, dir);
152
+
153
+ if (!fsx.existsSync(srcCompose)) {
154
+ continue;
155
+ }
156
+
157
+ if (withBackup) {
158
+ createBackup(dstCompose);
159
+ }
160
+
161
+ try {
162
+ // Clean destination
163
+ if (override && fsx.existsSync(dstCompose)) {
164
+ fs.rmSync(dstCompose, { recursive: true, force: true });
165
+ }
166
+ fs.renameSync(srcCompose, dstCompose);
167
+ if (withBackup) {
168
+ deleteBackup(dstCompose);
169
+ }
170
+ } catch (e) {
171
+ console.log("Move failed!");
172
+ if (withBackup) {
173
+ restoreBackup(dstCompose);
174
+ console.log("Backup has been restored.");
175
+ }
176
+ }
177
+ }
178
+ }
179
+
180
+ /**
181
+ * Remove directories from `basePath` directory.
182
+ *
183
+ * @param basePath - Base directory.
184
+ * @param dirs - Directory to remove.
185
+ */
186
+ function removeDirsSync(basePath: string, dirs: Array<string>) {
187
+ for (const dir of dirs) {
188
+ if (!dir) continue;
189
+
190
+ const composePath = path.join(basePath, dir);
191
+
192
+ if (fsx.existsSync(composePath)) {
193
+ fs.rmSync(composePath, { recursive: true, force: true });
194
+ }
195
+ }
196
+ }
197
+
198
+ function restoreBackup(src: string, suffix = "-BACKUP") {
199
+ const dst = src + suffix;
200
+ try {
201
+ fs.renameSync(dst, src);
202
+ console.log(`Backup ${dst} has been restored`);
203
+ } catch (e) {
204
+ console.log(`Error while delete ${dst} backup`);
205
+ }
206
+ }
207
+
208
+ function deleteBackup(src: string, suffix = "-BACKUP") {
209
+ const dst = src + suffix;
210
+
211
+ if (!fsx.existsSync(dst)) {
212
+ return;
213
+ }
214
+
215
+ try {
216
+ fs.rmSync(dst, { recursive: true, force: true });
217
+ console.log(`Backup ${dst} has been deleted`);
218
+ } catch (e) {
219
+ console.log(`Error while delete ${dst} backup`);
220
+ }
221
+ }
222
+
223
+ function createBackup(src: string, suffix = "-BACKUP") {
224
+ const dst = src + suffix;
225
+
226
+ if (!fsx.existsSync(src)) {
227
+ return;
228
+ }
229
+
230
+ if (fsx.existsSync(dst)) {
231
+ console.log(`Destination ${dst} already exists`);
232
+ return;
233
+ }
234
+
235
+ try {
236
+ fs.renameSync(src, dst);
237
+ console.log(`Backup of ${src} has been created in ${dst}`);
238
+ } catch (e) {
239
+ console.log(`Error while coping ${src} to ${dst} backup`);
240
+ }
241
+ }
242
+
243
+ function isVirtualPage(id: number) {
244
+ return Number.isInteger(id) && id < 0;
245
+ }
246
+
247
+ async function removeVirtualPagesFromStore() {
248
+ const config = getConfig();
249
+ const dirs = config.dirs();
250
+ const storePath = path.join(dirs.__cx, "store");
251
+ try {
252
+ const multiPageFiles = getPageInStoreDir(storePath).filter(isVirtualPage);
253
+ removePagesFromStore(storePath, multiPageFiles);
254
+ } catch (e) {
255
+ console.info(
256
+ "`store` folder does not exist. Skipping multipage or static list template cleaning."
257
+ );
258
+ }
259
+ }
260
+
261
+ export {
262
+ clearEmptyDirs,
263
+ copyDirsSync,
264
+ createDirsSync,
265
+ moveDirsSync,
266
+ removeDirsSync,
267
+ removeVirtualPagesFromStore,
268
+ };
@@ -62,9 +62,9 @@ function getComponentsLibAliases() {
62
62
  };
63
63
  },
64
64
  {
65
- // Por este motivo se puede hacer `... import from "components" en
65
+ // Por este motivo se puede hacer `... import from "@components" en
66
66
  // los packages del monorepo.
67
- components: `${resolveComponentsPath()}/src/index.js`,
67
+ "@components": `${resolveComponentsPath()}/src/index.js`,
68
68
  }
69
69
  );
70
70
  }
@@ -13,15 +13,10 @@ import type { Core, Fields } from "@griddo/core";
13
13
 
14
14
  import dotenv from "dotenv";
15
15
 
16
- import { formatImage } from "../../src/utils";
16
+ import { formatImage } from "../adapters/gatsby/utils";
17
17
 
18
18
  dotenv.config();
19
19
 
20
- // Envs
21
- const STRIP_DOMAIN_FROM_PATH = JSON.parse(
22
- process.env.GRIDDO_EXPORT_STRIP_DOMAIN_FROM_PATH || "false"
23
- );
24
-
25
20
  // Consts
26
21
  const DEFAULT_ITEMS_PER_PAGE_FOR_LIST_TEMPLATES = 25;
27
22
 
@@ -159,9 +154,7 @@ async function createGriddoPageObject(
159
154
  socialTitle,
160
155
  });
161
156
 
162
- const pagePath = STRIP_DOMAIN_FROM_PATH
163
- ? fullPath.compose
164
- : `${fullPath.domain}${fullPath.compose}`;
157
+ const pagePath = fullPath.compose;
165
158
 
166
159
  const renderDate = new Date().toString();
167
160
 
@@ -109,21 +109,18 @@ function stripSpaces(str: string) {
109
109
  async function uploadSearchContentToAPI() {
110
110
  // Extraemos el path de la carpeta store
111
111
  const storeDir = path.resolve(__dirname, `../store`);
112
- // Convertimos el string que nos devuelve el env en un booleano
113
- const isDomainStrippedFromPath: boolean = JSON.parse(
114
- process.env.GRIDDO_EXPORT_STRIP_DOMAIN_FROM_PATH || "false"
115
- );
116
112
 
117
113
  for await (const store of getBuildPages(storeDir)) {
118
114
  const {
119
115
  context: { page, openGraph },
120
116
  } = store;
121
117
 
122
- const { compose, domain } = page.fullPath;
118
+ const { compose } = page.fullPath;
123
119
 
124
- const contextPath = isDomainStrippedFromPath
125
- ? path.resolve(__dirname, `../dist/${compose}/index.html`)
126
- : path.resolve(__dirname, `../dist${domain}${compose}/index.html`);
120
+ const contextPath = path.resolve(
121
+ __dirname,
122
+ `../dist/${compose}/index.html`
123
+ );
127
124
 
128
125
  const content = fs.readFileSync(contextPath).toString();
129
126
 
@@ -4,14 +4,14 @@ import type { LifeCyclesNames } from "../types/global";
4
4
  import type { APIPageObject } from "../types/pages";
5
5
  import type { Site } from "../types/sites";
6
6
 
7
+ import path from "node:path";
8
+
7
9
  import chalk from "chalk";
8
10
  import dotenv from "dotenv";
9
11
  import fs from "fs-extra";
10
12
  import gradient from "gradient-string";
11
13
  import pkgDir from "pkg-dir";
12
14
 
13
- import { version } from "../../package.json";
14
-
15
15
  dotenv.config();
16
16
 
17
17
  const GRIDDO_DEBUG_LOGS =
@@ -188,6 +188,9 @@ function siteList(sites: Array<Site>) {
188
188
  * Print the great Griddo Exporter logo in ASCII.
189
189
  */
190
190
  function printExporterLogo(adapter: Adapters) {
191
+ const { version } = JSON.parse(
192
+ fs.readFileSync(path.resolve(__dirname, "../package.json"), "utf-8")
193
+ );
191
194
  const logo = `
192
195
  ··
193
196
  ·· Griddo Exporter ${version}
@@ -29,10 +29,6 @@ const GRIDDO_RENDER_PAGES = (
29
29
  .map((item) => parseInt(item))
30
30
  .filter(Boolean);
31
31
 
32
- const STRIP_DOMAIN_FROM_PATH = JSON.parse(
33
- process.env.GRIDDO_EXPORT_STRIP_DOMAIN_FROM_PATH || "false"
34
- );
35
-
36
32
  /**
37
33
  * Check the instance sites and returns site prepared to be published and unpublished.
38
34
  */
@@ -215,10 +211,7 @@ async function generateSitemaps() {
215
211
  const sitemaps: Array<string> = [];
216
212
  const sitemapPageGroupKeys = Object.keys(sitemapPagesGroup);
217
213
 
218
- const sitemapBasePath = path.join(
219
- basePath,
220
- `${STRIP_DOMAIN_FROM_PATH ? slug.replace(domain, "") : slug}`
221
- );
214
+ const sitemapBasePath = path.join(basePath, slug.replace(domain, ""));
222
215
 
223
216
  for (const templateId of sitemapPageGroupKeys) {
224
217
  const sitemapPages = sitemapPagesGroup[templateId];
@@ -2,14 +2,18 @@ import path from "node:path";
2
2
 
3
3
  import fsx from "fs-extra";
4
4
 
5
- function getConfig() {
5
+ import { createDirsSync, removeDirsSync } from "./folders";
6
+ import { CXConfig } from "../types/global";
7
+
8
+ function getConfig(): CXConfig {
6
9
  try {
7
10
  // eslint-disable-next-line @typescript-eslint/no-var-requires, node/no-missing-require, node/no-unpublished-require
8
- const configModule = require("../cx.config.js");
11
+ const configModule = require("../../cx.config.js");
9
12
  const config = configModule.default;
10
13
 
11
14
  return config;
12
15
  } catch (error) {
16
+ console.log("Error while reading configuration file");
13
17
  process.exit(1);
14
18
  }
15
19
  }
@@ -42,7 +46,7 @@ async function legacy__createDistFromGatsbyPublic(
42
46
  const pageDataSrc = `${publicDir}/page-data`;
43
47
  const pageDataDest = `${cxAssetsDir}/page-data`;
44
48
 
45
- const projectStaticSrc = path.resolve(dirs.__cx, "./static");
49
+ const projectStaticSrc = path.resolve(dirs.__ssg, "./static");
46
50
  const projectStaticDest = cxAssetsDir;
47
51
 
48
52
  const gatsbyStaticSrc = `${cxDistDir}/static`;
@@ -54,12 +58,17 @@ async function legacy__createDistFromGatsbyPublic(
54
58
 
55
59
  if (needsAssetPrefix) {
56
60
  fsx.copySync(pageDataSrc, pageDataDest);
57
- fsx.copySync(projectStaticSrc, projectStaticDest, { overwrite: false });
61
+ if (fsx.existsSync(projectStaticSrc)) {
62
+ fsx.copySync(projectStaticSrc, projectStaticDest, { overwrite: false });
63
+ }
58
64
  fsx.copySync(gatsbyStaticSrc, gatsbyStaticDest, { overwrite: false });
59
- fsx.copySync(projectStaticSrc, cxDistDirWithDomain, {
60
- overwrite: false,
61
- });
65
+ if (fsx.existsSync(projectStaticSrc)) {
66
+ fsx.copySync(projectStaticSrc, cxDistDirWithDomain, {
67
+ overwrite: false,
68
+ });
69
+ }
62
70
 
71
+ // Copia el resto de archivos...
63
72
  validFiles.map(async (file) => {
64
73
  const fileSrc = `${publicDir}/${file}`;
65
74
  const fileDest = `${cxAssetsDir}/${file}`;
@@ -71,4 +80,22 @@ async function legacy__createDistFromGatsbyPublic(
71
80
  }
72
81
  }
73
82
 
74
- export { legacy__createDistFromGatsbyPublic, getConfig };
83
+ async function griddoCreateInitialDirectories(domain: string) {
84
+ const config = getConfig();
85
+ const { __exports, __caches } = config.dirs(domain);
86
+ createDirsSync([__exports]);
87
+ createDirsSync([__caches]);
88
+ }
89
+
90
+ async function griddoCleanDisposableDirectories(domain: string) {
91
+ const config = getConfig();
92
+ const { __cx } = config.dirs(domain);
93
+ removeDirsSync(__cx, ["store", "apiCache", "dist"]);
94
+ }
95
+
96
+ export {
97
+ getConfig,
98
+ griddoCleanDisposableDirectories,
99
+ griddoCreateInitialDirectories,
100
+ legacy__createDistFromGatsbyPublic,
101
+ };
package/ssg/README.md ADDED
@@ -0,0 +1 @@
1
+ # SGG Directory
File without changes