@griddo/cx 10.4.12 → 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 +21 -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
@@ -1,318 +0,0 @@
1
- import type { Site } from "../types/sites";
2
-
3
- import { spawnSync } from "node:child_process";
4
- import path from "node:path";
5
-
6
- import fsx from "fs-extra";
7
-
8
- import { CXRootDir, instanceRootDir, logInfo } from "./shared";
9
- import { getPageInStoreDir, removePagesFromStore } from "./store";
10
- import { getConfig } from "./temp-utils";
11
-
12
- export const STORE_DIR = path.resolve(__dirname, "../store/");
13
- export const DIST_DIR = path.resolve(__dirname, "../dist/");
14
-
15
- export const gatsbyRootDir = path.resolve(__dirname, "../");
16
- export const exportArchiveBasePath = path.resolve(
17
- instanceRootDir,
18
- "exports/sites"
19
- );
20
-
21
- /**
22
- * Delete sites dirs that will be updated from de file system.
23
- *
24
- * @param updateSites An array of sites to be updated.
25
- */
26
- async function deleteSites(updatedSites: Array<Site>, DOMAIN: string) {
27
- for await (const site of updatedSites) {
28
- for (const domain of site.domains) {
29
- const domainFromSite = Object.values(domain)[0];
30
- const domainPath = JSON.parse(
31
- process.env.GRIDDO_EXPORT_STRIP_DOMAIN_FROM_PATH || "false"
32
- )
33
- ? domainFromSite.split(DOMAIN).join("")
34
- : domainFromSite;
35
-
36
- const siteDir = path.resolve(__dirname, `../public${domainPath}`);
37
- const pageDataDir = path.resolve(
38
- __dirname,
39
- `../public/page-data${domainPath}`
40
- );
41
-
42
- logInfo(`Site dir ${siteDir}`);
43
- logInfo(`Page data dir ${pageDataDir}`);
44
-
45
- // delete directory recursively
46
- if (!fsx.existsSync(siteDir)) continue;
47
-
48
- try {
49
- await fsx.rm(siteDir, { recursive: true });
50
- logInfo(`${siteDir} was deleted!`);
51
- } catch (err) {
52
- console.log(err);
53
- }
54
-
55
- if (!fsx.existsSync(pageDataDir)) continue;
56
-
57
- try {
58
- await fsx.rm(pageDataDir, { recursive: true });
59
- console.info(`${pageDataDir} was deleted!`);
60
- } catch (err) {
61
- console.log(err);
62
- }
63
- }
64
- }
65
- }
66
-
67
- /**
68
- * Remove empty site dirst (with or without sitemaps xmls)
69
- */
70
- const clearEmptyDirs = (baseDir?: string) => {
71
- const dir = baseDir || path.resolve(CXRootDir, "dist");
72
-
73
- const isDir = fsx.statSync(dir).isDirectory();
74
- if (!isDir) {
75
- return;
76
- }
77
-
78
- // archivos o direvtorios dentro de `dir`
79
- let children = fsx.readdirSync(dir);
80
- // let children = childrenRaw.filter((file) => {
81
- // return path.extname(file).toLowerCase() !== ".xml";
82
- // });
83
- const dirHasChildren = children.length > 0;
84
-
85
- // Por cada uno de ellos miramos si tiene hijos, enviamos cada uno de ellos
86
- // a `clearEmptyDirsWithXML`
87
- if (dirHasChildren) {
88
- const childrenCount = children.length;
89
- const xmlCount = children.filter((file) => {
90
- return path.extname(file).toLowerCase() === ".xml";
91
- }).length;
92
-
93
- // Todos los hijos son archivos .xml
94
- // Podemos borrarlos y dejar el dir vacío.
95
- if (childrenCount === xmlCount) {
96
- children.forEach(function (xmlFile) {
97
- const fullPath = path.join(dir, xmlFile);
98
- fsx.rmSync(fullPath);
99
- });
100
- children = fsx.readdirSync(dir);
101
- }
102
-
103
- children.forEach(function (file) {
104
- const fullPath = path.join(dir, file);
105
- clearEmptyDirs(fullPath);
106
- });
107
-
108
- // re-evaluate files; after deleting subdir we may have parent dir
109
- // empty now...
110
- children = fsx.readdirSync(dir);
111
- }
112
-
113
- // Si no tiene hijos, lo borramos
114
- if (children.length === 0) {
115
- fsx.rmdirSync(dir);
116
- return;
117
- }
118
- };
119
-
120
- /**
121
- * Copy artifacts between CX valid directories.
122
- *
123
- * @param args.from - Source dir
124
- * @param args.to - Destination dir
125
- * @param args.artifacts - Artifact names
126
- * @param args.withBackup - Create a previous backup
127
- */
128
- function copyArtifacts(args: {
129
- from: string;
130
- to: string;
131
- artifacts: Array<string>;
132
- withBackup?: boolean;
133
- }) {
134
- const { artifacts, from, to, withBackup } = args;
135
-
136
- for (const artifact of artifacts) {
137
- const src = path.join(from, artifact);
138
- const dest = path.join(to, artifact);
139
-
140
- // The dir we want to copy, doesn't exist.
141
- if (!fsx.existsSync(src)) {
142
- console.log(`Source directory does not exist: ${src}`);
143
- continue;
144
- }
145
-
146
- // Create the backup
147
- if (withBackup) {
148
- createBackup(dest);
149
- }
150
-
151
- // Copy artifact
152
- try {
153
- // First clean destination
154
- if (fsx.existsSync(dest)) {
155
- spawnSync("rm", ["-rf", dest]);
156
- }
157
- spawnSync("cp", ["-Rp", src, dest]);
158
- if (withBackup) {
159
- deleteBackup(dest);
160
- }
161
- } catch (e) {
162
- console.log("Copy failed!");
163
- if (withBackup) {
164
- restoreBackup(dest);
165
- console.log("Backup has been restored.");
166
- }
167
- }
168
- }
169
- }
170
-
171
- /**
172
- * Move artifacts between CX valid directories.
173
- *
174
- * @param from - Source dir
175
- * @param to - Destination dir
176
- * @param artifacts - Artifact names
177
- *
178
- * @example
179
- * // normal
180
- * moveArtifacts({from: __cx, to: __ssg, ["dist"]})
181
- * // with backup
182
- * moveArtifacts({from: __cx, to: __ssg, ["dist"]})
183
- */
184
- function moveArtifacts(args: {
185
- from: string;
186
- to: string;
187
- artifacts: Array<string>;
188
- withBackup?: boolean;
189
- }) {
190
- const { artifacts, from, to, withBackup } = args;
191
-
192
- for (const artifact of artifacts) {
193
- const src = path.join(from, artifact);
194
- const dest = path.join(to, artifact);
195
-
196
- // The dir we want to move, doesn't exist.
197
- if (!fsx.existsSync(src)) {
198
- console.log(`Source directory does not exist: ${src}`);
199
- continue;
200
- }
201
-
202
- if (withBackup) {
203
- createBackup(dest);
204
- }
205
-
206
- try {
207
- // First clean destination
208
- if (fsx.existsSync(dest)) {
209
- spawnSync("rm", ["-rf", dest]);
210
- }
211
- spawnSync("mv", [src, dest]);
212
- if (withBackup) {
213
- deleteBackup(dest);
214
- }
215
- } catch (e) {
216
- console.log("Move failed!");
217
- if (withBackup) {
218
- restoreBackup(dest);
219
- console.log("Backup has been restored.");
220
- }
221
- }
222
- }
223
- }
224
-
225
- /**
226
- * Remove artifacts from CX valid directories.
227
- *
228
- * @param from - Source dir
229
- * @param to - Destination dir
230
- * @param artifacts - Artifact names
231
- *
232
- * @example
233
- * removeArtifacts({from: __cx, to: __ssg, ["dist", "public"]})
234
- */
235
- function removeArtifacts(args: { from: string; artifacts: Array<string> }) {
236
- const { artifacts, from } = args;
237
-
238
- for (const artifact of artifacts) {
239
- if (artifact) {
240
- const src = path.join(from, artifact);
241
- if (fsx.existsSync(src)) {
242
- spawnSync("rm", ["-rf", src]);
243
- }
244
- }
245
- }
246
- }
247
-
248
- function restoreBackup(src: string, suffix = "-BACKUP") {
249
- const dest = src + suffix;
250
- try {
251
- spawnSync("mv", [dest, src]);
252
- console.log(`Backup ${dest} has been restored`);
253
- } catch (e) {
254
- console.log(`Error while delete ${dest} backup`);
255
- }
256
- }
257
-
258
- function deleteBackup(src: string, suffix = "-BACKUP") {
259
- const dest = src + suffix;
260
-
261
- if (!fsx.existsSync(dest)) {
262
- console.log(`Source ${dest} does not exist`);
263
- return;
264
- }
265
-
266
- try {
267
- spawnSync("rm", ["-rf", dest]);
268
- console.log(`Backup ${dest} has been deleted`);
269
- } catch (e) {
270
- console.log(`Error while delete ${dest} backup`);
271
- }
272
- }
273
-
274
- function createBackup(src: string, suffix = "-BACKUP") {
275
- const dest = src + suffix;
276
-
277
- if (!fsx.existsSync(src)) {
278
- console.log(`Source ${src} does not exist`);
279
- return;
280
- }
281
-
282
- if (fsx.existsSync(dest)) {
283
- console.log(`Destination ${dest} already exists`);
284
- return;
285
- }
286
-
287
- try {
288
- spawnSync("mv", [src, dest]);
289
- console.log(`Backup of ${src} has been created in ${dest}`);
290
- } catch (e) {
291
- console.log(`Error while coping ${src} to ${dest} backup`);
292
- }
293
- }
294
-
295
- function isMultiPageId(id: number) {
296
- return Number.isInteger(id) && id < 0;
297
- }
298
-
299
- async function removeMultiPagesFromStore() {
300
- const config = getConfig();
301
- const dirs = config.dirs();
302
- const storePath = path.join(dirs.__cx, "store");
303
- try {
304
- const multiPageFiles = getPageInStoreDir(storePath).filter(isMultiPageId);
305
- removePagesFromStore(storePath, multiPageFiles);
306
- } catch (e) {
307
- console.info("`store` folder does not exist. Skipping multipage clean up.");
308
- }
309
- }
310
-
311
- export {
312
- clearEmptyDirs,
313
- copyArtifacts,
314
- deleteSites,
315
- moveArtifacts,
316
- removeArtifacts,
317
- removeMultiPagesFromStore,
318
- };
@@ -1,36 +0,0 @@
1
- import { Core } from "@griddo/core";
2
-
3
- export const filterBodyIntegrationFromPosition = (
4
- integrations: Array<Core.PageIntegration>,
5
- position: "start" | "end"
6
- ) =>
7
- integrations
8
- ?.filter(
9
- (integration) =>
10
- integration.contentBody !== null &&
11
- integration.contentBody !== "" &&
12
- integration.contentBodyPosition === position
13
- )
14
- .map((integration) => integration.contentBody!) || [];
15
-
16
- export const filterHeadIntegrations = (
17
- integrations: Array<Core.PageIntegration>
18
- ) =>
19
- integrations
20
- ?.filter(
21
- (integration) =>
22
- integration.contentHead !== null && integration.contentHead !== ""
23
- )
24
- .map((integration) => integration.contentHead!) || [];
25
-
26
- export const filterPositionIntegrations = (
27
- integrations: Array<Core.PageIntegration>,
28
- position: "head" | "start" | "end"
29
- ) => {
30
- switch (position) {
31
- case "head":
32
- return filterHeadIntegrations(integrations);
33
- default:
34
- return filterBodyIntegrationFromPosition(integrations, position);
35
- }
36
- };
@@ -1,52 +0,0 @@
1
- import { spawnSync } from "node:child_process";
2
-
3
- import dotenv from "dotenv";
4
- import pkgDir from "pkg-dir";
5
-
6
- dotenv.config();
7
-
8
- type Env = Record<string, unknown>;
9
-
10
- // Where we are going to run the export command
11
- const workingPath = pkgDir.sync(__dirname)!;
12
-
13
- /**
14
- * Get a command runner function using the environments variables passed in
15
- * `env`.
16
- *
17
- * @example
18
- * const run = getEnvRunner({
19
- * ENV_VAR_1: "Foo",
20
- * ENV_VAR_2: "Bar"
21
- * });
22
- * run("cp file.txt file2.txt");
23
- */
24
- function getEnvRunner(env: Env) {
25
- return (command: string) => runner(command, env);
26
- }
27
-
28
- /**
29
- * Execute a command using the environments variables passed as arguments in env
30
- */
31
- function runner(command: string, env: Env) {
32
- // TODO: Cuando esto falle, ejecutar `cleanAfterFail`
33
- const [commandName, ...args] = command.split(" ");
34
- const { error, status } = spawnSync(commandName, args, {
35
- cwd: workingPath,
36
- stdio: ["ignore", "inherit", "ignore"],
37
- encoding: "utf8",
38
- shell: true,
39
- env: Object.assign({ GRIDDO_EXPORTER: "true" }, process.env, env),
40
- });
41
-
42
- if (error) {
43
- console.error(error);
44
- throw new Error(error.toString());
45
- }
46
-
47
- if (status !== 0) {
48
- throw new Error(`Command \`${command}\` exited with code ${status}`);
49
- }
50
- }
51
-
52
- export { getEnvRunner };
package/index.js DELETED
@@ -1,7 +0,0 @@
1
- #!/usr/bin/env node
2
- /* eslint-disable node/no-missing-require */
3
-
4
- // This is the griddo-cx package entry point.
5
- // `./build/index.js` is for the Griddo Exporter, where everything start.
6
- // The source code (TypeScript) is in ./exporter dir
7
- require("./build/index.js");
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes