@griddo/cx 1.75.227 → 1.75.228

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.
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": "1.75.227",
4
+ "version": "1.75.228",
5
5
  "authors": [
6
6
  "Álvaro Sánchez' <alvaro.sanches@secuoyas.com>",
7
7
  "Diego M. Béjar <diego.bejar@secuoyas.com>",
@@ -68,7 +68,7 @@
68
68
  "react-helmet": "^6.0.0"
69
69
  },
70
70
  "devDependencies": {
71
- "@griddo/eslint-config-back": "^1.75.227",
71
+ "@griddo/eslint-config-back": "^1.75.228",
72
72
  "@types/babel__core": "^7.20.0",
73
73
  "@types/babel__preset-env": "^7.9.2",
74
74
  "@types/csvtojson": "^2.0.0",
@@ -116,5 +116,5 @@
116
116
  "publishConfig": {
117
117
  "access": "public"
118
118
  },
119
- "gitHead": "fd5fee42aaf938991fd8d51f24eecbe740c65cc4"
119
+ "gitHead": "c0187f02712eadfb4a2f7632180a4276c126ef91"
120
120
  }
@@ -8,7 +8,7 @@ import { SitesService } from "../src/services/sites";
8
8
  import { logInfo } from "../src/utils/shared";
9
9
 
10
10
  // Where we are going to find export folders
11
- const execBasePath = pkgDir.sync()!;
11
+ const execBasePath = pkgDir.sync(path.resolve(__dirname, "../.."))!;
12
12
 
13
13
  // Where we are going to find archived exports
14
14
  const exportArchiveBasePath = path.resolve(execBasePath, "exports/sites");
@@ -18,27 +18,32 @@ import { exporterLogo as splash, measureFunctions } from "../src/utils/shared";
18
18
  dotenv.config();
19
19
 
20
20
  // Envs
21
- const artifactsArchivable = ["dist", "assets", "apiCache"];
21
+ // Artifacts to preserve between CX installs
22
+ const artifactsArchivable = ["dist", "assets"];
23
+ // Artifacts to remove after export
22
24
  const artifactsDisposable = ["public", ".store"];
23
-
24
- // TODO: Remove GRIDDO_INFRA_BUILD_COMPLETES behaviour when all instances are over 1.75.227 and infra calls export:complete
25
- const INFRA_COMPLETES_BUILD = !!process.env.GRIDDO_INFRA_BUILD_COMPLETES;
25
+ // Artifacts to make exports faster
26
+ const artifactsCache = ["apiCache" /* , ".cache" */];
26
27
 
27
28
  // TODO: Remove STRIP_DOMAIN_FROM_PATH behaviour when all instances are over 1.75.219
28
29
  const STRIP_DOMAIN_FROM_PATH =
29
30
  !!process.env.GRIDDO_EXPORT_STRIP_DOMAIN_FROM_PATH;
30
31
 
31
32
  if (STRIP_DOMAIN_FROM_PATH) {
32
- artifactsArchivable.push(".cache");
33
+ artifactsCache.push(".cache");
33
34
  } else {
34
35
  artifactsDisposable.push(".cache");
35
36
  }
36
37
 
38
+ // TODO: Remove GRIDDO_INFRA_BUILD_COMPLETES behaviour when all instances are over 1.75.227 and infra calls export:complete
39
+ const INFRA_COMPLETES_BUILD = !!process.env.GRIDDO_INFRA_BUILD_COMPLETES;
40
+
37
41
  // Where we are going to find export folders
38
42
  const execBasePath = pkgDir.sync()!;
39
43
 
40
44
  // Where we are going to find archived exports
41
45
  const exportArchiveBasePath = path.resolve(execBasePath, "exports/sites");
46
+ const exportCachesArchivePath = path.resolve(__dirname, "../caches");
42
47
 
43
48
  // Where we are going to run the export command
44
49
  const workingPath = pkgDir.sync(__dirname)!;
@@ -89,32 +94,39 @@ const logWarning = (...message: Array<any>) => console.log(...message);
89
94
  const domainExport = async (domain: string) => {
90
95
  const runner = getDomainRunner(domain);
91
96
  // onPreExporter
92
- const endRestore = measureFunctions(runner.init, runner.restoreArtifacts);
93
- logInfo(`\n⌛️ Domain ${domain} restaured: ${endRestore}s`);
97
+ const endRestore = measureFunctions(
98
+ runner.init,
99
+ runner.restoreArtifacts,
100
+ runner.restoreCacheArtifacts
101
+ );
102
+ logInfo(`\n⌛️ Domain ${domain} restored: ${endRestore}s`);
94
103
 
95
104
  // Gatsby
96
105
  runner.runExporter();
97
106
 
98
107
  // onPostExporter
99
- const endArchive = measureFunctions(runner.archiveArtifacts);
108
+ const endArchive = measureFunctions(
109
+ runner.archiveArtifacts,
110
+ runner.archiveCacheArtifacts
111
+ );
100
112
  logInfo(`\n⌛️ Domain ${domain} archived: ${endArchive}s`);
101
113
  };
102
114
 
103
115
  const launchExports = async () => {
104
116
  splash();
105
- initCache();
117
+ // initCache();
106
118
 
107
- const domains = await findDomains();
119
+ // const domains = await findDomains();
108
120
 
109
- for (const domain of domains) {
110
- logInfo(`️🚢 Exporting domain ${chalk.underline(domain)}`);
111
- await domainExport(domain);
112
- }
121
+ // for (const domain of domains) {
122
+ // logInfo(`️🚢 Exporting domain ${chalk.underline(domain)}`);
123
+ // await domainExport(domain);
124
+ // }
113
125
 
114
126
  // TODO: Remove when all instances are over 1.75.227 and infra calls export:complete
115
127
  if (!INFRA_COMPLETES_BUILD) {
116
128
  const runner = getEnvRunner({ cwd: __dirname });
117
- runner("yarn export:complete");
129
+ runner("pwd; ls; node ./build/build-complete.js");
118
130
  }
119
131
  };
120
132
 
@@ -136,6 +148,10 @@ const getDomainRunner = (domain: string) => {
136
148
  };
137
149
 
138
150
  const getArtifactPaths = (artifact = "") => {
151
+ if (artifact === "/")
152
+ throw new Error(`Artifact path cannot be root: ${artifact}`);
153
+
154
+ // Archives
139
155
  const domainExportArchiveBasePath = path.resolve(
140
156
  exportArchiveBasePath,
141
157
  domain
@@ -148,6 +164,21 @@ const getDomainRunner = (domain: string) => {
148
164
  currentExportArchivePath,
149
165
  domain
150
166
  );
167
+
168
+ // Cachés
169
+ const domainCacheArchiveBasePath = path.resolve(
170
+ exportCachesArchivePath,
171
+ domain
172
+ );
173
+ const currentExportArchiveCachePath = path.resolve(
174
+ domainCacheArchiveBasePath,
175
+ artifact
176
+ );
177
+ const currentExportArchiveCachePathInDomain = path.resolve(
178
+ currentExportArchiveCachePath,
179
+ domain
180
+ );
181
+
151
182
  const currentExportBackupPath = `${currentExportArchivePath}-BACKUP`;
152
183
  const currentExportWorkingPath = path.resolve(workingPath, artifact);
153
184
 
@@ -157,11 +188,18 @@ const getDomainRunner = (domain: string) => {
157
188
  currentExportBackupPath,
158
189
  currentExportWorkingPath,
159
190
  currentExportArchivePathInDomain,
191
+ domainCacheArchiveBasePath,
192
+ currentExportArchiveCachePath,
193
+ currentExportArchiveCachePathInDomain,
160
194
  };
161
195
  };
162
196
 
163
197
  const cleanDirtyArtifactPaths = () => {
164
- for (const artifact of [...artifactsArchivable, ...artifactsDisposable]) {
198
+ for (const artifact of [
199
+ ...artifactsArchivable,
200
+ ...artifactsDisposable,
201
+ ...artifactsCache,
202
+ ]) {
165
203
  const { currentExportWorkingPath } = getArtifactPaths(artifact);
166
204
 
167
205
  if (fs.existsSync(currentExportWorkingPath)) {
@@ -172,11 +210,17 @@ const getDomainRunner = (domain: string) => {
172
210
  };
173
211
 
174
212
  const createBaseExportPaths = () => {
175
- const { domainExportArchiveBasePath } = getArtifactPaths();
213
+ const { domainExportArchiveBasePath, domainCacheArchiveBasePath } =
214
+ getArtifactPaths();
176
215
 
177
- if (!fs.existsSync(domainExportArchiveBasePath)) {
178
- logInfo(`✨ Creating ${domainExportArchiveBasePath}`);
179
- run(`mkdir -p ${domainExportArchiveBasePath}`);
216
+ for (const _path of [
217
+ domainExportArchiveBasePath,
218
+ domainCacheArchiveBasePath,
219
+ ]) {
220
+ if (!fs.existsSync(_path)) {
221
+ logInfo(`✨ Creating ${_path}`);
222
+ run(`mkdir -p ${_path}`);
223
+ }
180
224
  }
181
225
  };
182
226
 
@@ -264,6 +308,39 @@ const getDomainRunner = (domain: string) => {
264
308
  run(`rm -rf ${currentExportBackupPath}`);
265
309
  };
266
310
 
311
+ const archiveCacheArtifacts = () => {
312
+ for (const artifact of artifactsCache) {
313
+ const { currentExportArchiveCachePath, currentExportWorkingPath } =
314
+ getArtifactPaths(artifact);
315
+
316
+ if (fs.existsSync(currentExportWorkingPath)) {
317
+ logInfo(
318
+ `🚚 Moving files from ${chalk.gray(
319
+ currentExportWorkingPath
320
+ )} to ${chalk.gray(currentExportArchiveCachePath)}`
321
+ );
322
+ run(`mv ${currentExportWorkingPath} ${currentExportArchiveCachePath}`);
323
+ } else {
324
+ throw new Error(
325
+ `🚚 Error moving files from ${currentExportWorkingPath}: Path does not exist.`
326
+ );
327
+ }
328
+ }
329
+ };
330
+ const restoreCacheArtifacts = () => {
331
+ for (const artifact of artifactsCache) {
332
+ const { currentExportArchiveCachePath, currentExportWorkingPath } =
333
+ getArtifactPaths(artifact);
334
+
335
+ if (fs.existsSync(currentExportArchiveCachePath)) {
336
+ logWarning(
337
+ `️♻️ Restoring ${chalk.gray(currentExportArchiveCachePath)}`
338
+ );
339
+ run(`mv ${currentExportArchiveCachePath} ${currentExportWorkingPath}`);
340
+ }
341
+ }
342
+ };
343
+
267
344
  const runExporter = () => {
268
345
  console.log(`\n${chalk.black(chalk.bgGreen(" Gatsby (start) "))}\n`);
269
346
 
@@ -326,6 +403,8 @@ const getDomainRunner = (domain: string) => {
326
403
  createArtifactBackup,
327
404
  restoreArtifactBackup,
328
405
  deleteArtifactBackup,
406
+ archiveCacheArtifacts,
407
+ restoreCacheArtifacts,
329
408
  runExporter,
330
409
  };
331
410
  };