@griddo/cx 10.4.6 → 10.4.8
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/build/build-complete.js +13 -13
- package/build/create-build-data.js +16 -16
- package/build/index.js +30 -30
- package/build/reset-render.js +16 -16
- package/exporter/adapters/gatsby/index.ts +9 -4
- package/exporter/adapters/gatsby/utils.ts +16 -17
- package/exporter/types/global.ts +3 -1
- package/exporter/utils/folders.ts +28 -25
- package/exporter/utils/runners.ts +2 -3
- package/exporter/utils/shared.ts +1 -2
- package/exporter/utils/temp-utils.ts +13 -0
- package/package.json +2 -12
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { getGatsbyDomainRunner } from "./utils";
|
|
1
|
+
import { attempts, getGatsbyDomainRunner } from "./utils";
|
|
2
2
|
import { getInstanceDomains } from "../../utils/domains";
|
|
3
3
|
import { createBuildData } from "../../utils/download-build-data";
|
|
4
4
|
import { clearEmptyDirs, removeMultiPagesFromStore } from "../../utils/folders";
|
|
@@ -20,6 +20,7 @@ async function runGatsbyAdapter() {
|
|
|
20
20
|
*/
|
|
21
21
|
await doLifeCycle({
|
|
22
22
|
name: "Restore",
|
|
23
|
+
attempts: attempts.restore,
|
|
23
24
|
steps: [
|
|
24
25
|
runner.init,
|
|
25
26
|
() => pause("init done!"),
|
|
@@ -38,9 +39,10 @@ async function runGatsbyAdapter() {
|
|
|
38
39
|
*/
|
|
39
40
|
await doLifeCycle({
|
|
40
41
|
name: "Data",
|
|
42
|
+
attempts: attempts.data,
|
|
41
43
|
steps: [
|
|
42
|
-
|
|
43
|
-
() => pause("Download data from API to `store`
|
|
44
|
+
() => createBuildData(domain),
|
|
45
|
+
() => pause("Download data from API to `store` done!"),
|
|
44
46
|
],
|
|
45
47
|
});
|
|
46
48
|
|
|
@@ -53,6 +55,7 @@ async function runGatsbyAdapter() {
|
|
|
53
55
|
*/
|
|
54
56
|
await doLifeCycle({
|
|
55
57
|
name: "SSG",
|
|
58
|
+
attempts: attempts.ssg,
|
|
56
59
|
steps: [runner.runGatsbyBuild, () => pause("Gatsby build done!")],
|
|
57
60
|
});
|
|
58
61
|
|
|
@@ -67,6 +70,7 @@ async function runGatsbyAdapter() {
|
|
|
67
70
|
);
|
|
68
71
|
await doLifeCycle({
|
|
69
72
|
name: "Meta",
|
|
73
|
+
attempts: attempts.meta,
|
|
70
74
|
steps: [
|
|
71
75
|
() => (shouldUploadSearchData ? uploadSearchContentToAPI() : undefined),
|
|
72
76
|
],
|
|
@@ -80,11 +84,12 @@ async function runGatsbyAdapter() {
|
|
|
80
84
|
*/
|
|
81
85
|
await doLifeCycle({
|
|
82
86
|
name: "Archive",
|
|
87
|
+
attempts: attempts.archive,
|
|
83
88
|
steps: [
|
|
84
89
|
// Elimina las páginas MultiPage del `store`. De este modo nos
|
|
85
90
|
// aseguramos que se vuelven a crear por Gatsby siempre
|
|
86
91
|
// actualizadas.
|
|
87
|
-
removeMultiPagesFromStore,
|
|
92
|
+
removeMultiPagesFromStore,
|
|
88
93
|
() => pause("MultiPages removed from `store`"),
|
|
89
94
|
() => clearEmptyDirs(),
|
|
90
95
|
() => pause("Clean empty dirs done!"),
|
|
@@ -11,6 +11,20 @@ import { checkSites } from "../../utils/sites";
|
|
|
11
11
|
|
|
12
12
|
dotenv.config();
|
|
13
13
|
|
|
14
|
+
const attempts = {
|
|
15
|
+
prepare: JSON.parse(process.env.GRIDDO_PREPARE_LIFECYCLE_MAX_ATTEMPTS || "1"),
|
|
16
|
+
restore: JSON.parse(process.env.GRIDDO_RESTORE_LIFECYCLE_MAX_ATTEMPTS || "1"),
|
|
17
|
+
data: JSON.parse(process.env.GRIDDO_DATA_LIFECYCLE_MAX_ATTEMPTS || "1"),
|
|
18
|
+
ssg: JSON.parse(process.env.GRIDDO_SSG_LIFECYCLE_MAX_ATTEMPTS || "1"),
|
|
19
|
+
relocation: JSON.parse(
|
|
20
|
+
process.env.GRIDDO_RELOCATION_LIFECYCLE_MAX_ATTEMPTS || "1"
|
|
21
|
+
),
|
|
22
|
+
meta: JSON.parse(process.env.GRIDDO_META_LIFECYCLE_MAX_ATTEMPTS || "1"),
|
|
23
|
+
archive: JSON.parse(process.env.GRIDDO_ARCHIVE_LIFECYCLE_MAX_ATTEMPTS || "1"),
|
|
24
|
+
clean: JSON.parse(process.env.GRIDDO_CLEAN_LIFECYCLE_MAX_ATTEMPTS || "1"),
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
|
|
14
28
|
/**
|
|
15
29
|
* Return a runner, a serie of functions to manage the Gatsby render artifacts.
|
|
16
30
|
*/
|
|
@@ -317,17 +331,6 @@ function getGatsbyDomainRunner(domain: string) {
|
|
|
317
331
|
}
|
|
318
332
|
};
|
|
319
333
|
|
|
320
|
-
// TODO: Esto no debería hacerse desde infra
|
|
321
|
-
// const movePublicToDist = () => {
|
|
322
|
-
// const { currentExportWorkingPath: publicPath } = getArtifactPaths("public");
|
|
323
|
-
// const { currentExportWorkingPath: distPath } = getArtifactPaths("dist");
|
|
324
|
-
|
|
325
|
-
// if (fs.existsSync(publicPath)) {
|
|
326
|
-
// console.log(`Moving ${publicPath} to ${distPath}`);
|
|
327
|
-
// run(`mv ${publicPath} ${distPath}`);
|
|
328
|
-
// }
|
|
329
|
-
// };
|
|
330
|
-
|
|
331
334
|
/**
|
|
332
335
|
* Delete disposable artifacts between renders.
|
|
333
336
|
*/
|
|
@@ -344,11 +347,6 @@ function getGatsbyDomainRunner(domain: string) {
|
|
|
344
347
|
}
|
|
345
348
|
};
|
|
346
349
|
|
|
347
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
348
|
-
const cleanAfterFail = () => {
|
|
349
|
-
cleanDirtyArtifactPaths();
|
|
350
|
-
};
|
|
351
|
-
|
|
352
350
|
return {
|
|
353
351
|
init,
|
|
354
352
|
getArtifactPaths,
|
|
@@ -379,4 +377,5 @@ function getGatsbyAssetPrefixSlug(domain: string) {
|
|
|
379
377
|
return `${assetPrefix}/${domain}`;
|
|
380
378
|
}
|
|
381
379
|
|
|
382
|
-
export { getGatsbyDomainRunner };
|
|
380
|
+
export { attempts, getGatsbyDomainRunner };
|
|
381
|
+
|
package/exporter/types/global.ts
CHANGED
|
@@ -95,8 +95,10 @@ interface CXConfig {
|
|
|
95
95
|
CACHE: "__cache";
|
|
96
96
|
CX: "__cx";
|
|
97
97
|
SSG: "__ssg";
|
|
98
|
+
COMPONENTS: "__components";
|
|
99
|
+
ROOT: "__root";
|
|
98
100
|
};
|
|
99
|
-
dirs: (domain
|
|
101
|
+
dirs: (domain?: string) => Record<CXDir, string>;
|
|
100
102
|
}
|
|
101
103
|
|
|
102
104
|
export {
|
|
@@ -4,12 +4,11 @@ import type { Site } from "../types/sites";
|
|
|
4
4
|
import { spawnSync } from "node:child_process";
|
|
5
5
|
import path from "node:path";
|
|
6
6
|
|
|
7
|
-
import
|
|
7
|
+
import fsx from "fs-extra";
|
|
8
8
|
|
|
9
9
|
import { CXRootDir, instanceRootDir, logInfo } from "./shared";
|
|
10
10
|
import { getPageInStoreDir, removePagesFromStore } from "./store";
|
|
11
|
-
|
|
12
|
-
import config from "../../cx.config";
|
|
11
|
+
import { getConfig } from "./temp-utils";
|
|
13
12
|
|
|
14
13
|
export const STORE_DIR = path.resolve(__dirname, "../store/");
|
|
15
14
|
export const DIST_DIR = path.resolve(__dirname, "../dist/");
|
|
@@ -45,19 +44,19 @@ async function deleteSites(updatedSites: Array<Site>, DOMAIN: string) {
|
|
|
45
44
|
logInfo(`Page data dir ${pageDataDir}`);
|
|
46
45
|
|
|
47
46
|
// delete directory recursively
|
|
48
|
-
if (!
|
|
47
|
+
if (!fsx.existsSync(siteDir)) continue;
|
|
49
48
|
|
|
50
49
|
try {
|
|
51
|
-
await
|
|
50
|
+
await fsx.rm(siteDir, { recursive: true });
|
|
52
51
|
logInfo(`${siteDir} was deleted!`);
|
|
53
52
|
} catch (err) {
|
|
54
53
|
console.log(err);
|
|
55
54
|
}
|
|
56
55
|
|
|
57
|
-
if (!
|
|
56
|
+
if (!fsx.existsSync(pageDataDir)) continue;
|
|
58
57
|
|
|
59
58
|
try {
|
|
60
|
-
await
|
|
59
|
+
await fsx.rm(pageDataDir, { recursive: true });
|
|
61
60
|
console.info(`${pageDataDir} was deleted!`);
|
|
62
61
|
} catch (err) {
|
|
63
62
|
console.log(err);
|
|
@@ -72,13 +71,13 @@ async function deleteSites(updatedSites: Array<Site>, DOMAIN: string) {
|
|
|
72
71
|
const clearEmptyDirs = (baseDir?: string) => {
|
|
73
72
|
const dir = baseDir || path.resolve(CXRootDir, "dist");
|
|
74
73
|
|
|
75
|
-
const isDir =
|
|
74
|
+
const isDir = fsx.statSync(dir).isDirectory();
|
|
76
75
|
if (!isDir) {
|
|
77
76
|
return;
|
|
78
77
|
}
|
|
79
78
|
|
|
80
79
|
// archivos o direvtorios dentro de `dir`
|
|
81
|
-
let children =
|
|
80
|
+
let children = fsx.readdirSync(dir);
|
|
82
81
|
// let children = childrenRaw.filter((file) => {
|
|
83
82
|
// return path.extname(file).toLowerCase() !== ".xml";
|
|
84
83
|
// });
|
|
@@ -97,9 +96,9 @@ const clearEmptyDirs = (baseDir?: string) => {
|
|
|
97
96
|
if (childrenCount === xmlCount) {
|
|
98
97
|
children.forEach(function (xmlFile) {
|
|
99
98
|
const fullPath = path.join(dir, xmlFile);
|
|
100
|
-
|
|
99
|
+
fsx.rmSync(fullPath);
|
|
101
100
|
});
|
|
102
|
-
children =
|
|
101
|
+
children = fsx.readdirSync(dir);
|
|
103
102
|
}
|
|
104
103
|
|
|
105
104
|
children.forEach(function (file) {
|
|
@@ -109,12 +108,12 @@ const clearEmptyDirs = (baseDir?: string) => {
|
|
|
109
108
|
|
|
110
109
|
// re-evaluate files; after deleting subdir we may have parent dir
|
|
111
110
|
// empty now...
|
|
112
|
-
children =
|
|
111
|
+
children = fsx.readdirSync(dir);
|
|
113
112
|
}
|
|
114
113
|
|
|
115
114
|
// Si no tiene hijos, lo borramos
|
|
116
115
|
if (children.length === 0) {
|
|
117
|
-
|
|
116
|
+
fsx.rmdirSync(dir);
|
|
118
117
|
return;
|
|
119
118
|
}
|
|
120
119
|
};
|
|
@@ -137,6 +136,7 @@ async function copyArtifacts(args: {
|
|
|
137
136
|
}) {
|
|
138
137
|
const { artifacts, domain, from, to, withBackup } = args;
|
|
139
138
|
|
|
139
|
+
const config = await getConfig();
|
|
140
140
|
const dirs = config.dirs(domain);
|
|
141
141
|
|
|
142
142
|
for (const artifact of artifacts) {
|
|
@@ -144,7 +144,7 @@ async function copyArtifacts(args: {
|
|
|
144
144
|
const dest = path.join(dirs[to], artifact);
|
|
145
145
|
|
|
146
146
|
// The dir we want to copy, doesn't exist.
|
|
147
|
-
if (!
|
|
147
|
+
if (!fsx.existsSync(src)) {
|
|
148
148
|
console.log(`Source directory does not exist: ${src}`);
|
|
149
149
|
continue;
|
|
150
150
|
}
|
|
@@ -157,7 +157,7 @@ async function copyArtifacts(args: {
|
|
|
157
157
|
// Copy artifact
|
|
158
158
|
try {
|
|
159
159
|
// First clean destination
|
|
160
|
-
if (
|
|
160
|
+
if (fsx.existsSync(dest)) {
|
|
161
161
|
spawnSync("rm", ["-rf", dest]);
|
|
162
162
|
}
|
|
163
163
|
spawnSync("cp", ["-Rp", src, dest]);
|
|
@@ -198,7 +198,7 @@ async function copyArtifacts(args: {
|
|
|
198
198
|
* // with backup
|
|
199
199
|
* moveArtifacts({domain: domain, from: "__cx", to: "__ssg", ["dist"]})
|
|
200
200
|
*/
|
|
201
|
-
function moveArtifacts(args: {
|
|
201
|
+
async function moveArtifacts(args: {
|
|
202
202
|
domain: string;
|
|
203
203
|
from: CXDir;
|
|
204
204
|
to: CXDir;
|
|
@@ -207,6 +207,7 @@ function moveArtifacts(args: {
|
|
|
207
207
|
}) {
|
|
208
208
|
const { artifacts, domain, from, to, withBackup } = args;
|
|
209
209
|
|
|
210
|
+
const config = await getConfig();
|
|
210
211
|
const dirs = config.dirs(domain);
|
|
211
212
|
|
|
212
213
|
for (const artifact of artifacts) {
|
|
@@ -214,7 +215,7 @@ function moveArtifacts(args: {
|
|
|
214
215
|
const dest = path.join(dirs[to], artifact);
|
|
215
216
|
|
|
216
217
|
// The dir we want to move, doesn't exist.
|
|
217
|
-
if (!
|
|
218
|
+
if (!fsx.existsSync(src)) {
|
|
218
219
|
console.log(`Source directory does not exist: ${src}`);
|
|
219
220
|
continue;
|
|
220
221
|
}
|
|
@@ -225,7 +226,7 @@ function moveArtifacts(args: {
|
|
|
225
226
|
|
|
226
227
|
try {
|
|
227
228
|
// First clean destination
|
|
228
|
-
if (
|
|
229
|
+
if (fsx.existsSync(dest)) {
|
|
229
230
|
spawnSync("rm", ["-rf", dest]);
|
|
230
231
|
}
|
|
231
232
|
spawnSync("mv", [src, dest]);
|
|
@@ -253,19 +254,20 @@ function moveArtifacts(args: {
|
|
|
253
254
|
* @example
|
|
254
255
|
* removeArtifacts(domain, "__cx", "__ssg", ["dist"], ["public"])
|
|
255
256
|
*/
|
|
256
|
-
function removeArtifacts(args: {
|
|
257
|
+
async function removeArtifacts(args: {
|
|
257
258
|
domain: string;
|
|
258
259
|
from: CXDir;
|
|
259
260
|
artifacts: Array<string>;
|
|
260
261
|
}) {
|
|
261
262
|
const { artifacts, domain, from } = args;
|
|
262
263
|
|
|
264
|
+
const config = await getConfig();
|
|
263
265
|
const dirs = config.dirs(domain);
|
|
264
266
|
|
|
265
267
|
for (const artifact of artifacts) {
|
|
266
268
|
if (artifact) {
|
|
267
269
|
const src = path.join(dirs[from], artifact);
|
|
268
|
-
if (
|
|
270
|
+
if (fsx.existsSync(src)) {
|
|
269
271
|
spawnSync("rm", ["-rf", src]);
|
|
270
272
|
}
|
|
271
273
|
}
|
|
@@ -285,7 +287,7 @@ function restoreBackup(src: string, suffix = "-BACKUP") {
|
|
|
285
287
|
function deleteBackup(src: string, suffix = "-BACKUP") {
|
|
286
288
|
const dest = src + suffix;
|
|
287
289
|
|
|
288
|
-
if (!
|
|
290
|
+
if (!fsx.existsSync(dest)) {
|
|
289
291
|
console.log(`Source ${dest} does not exist`);
|
|
290
292
|
return;
|
|
291
293
|
}
|
|
@@ -301,12 +303,12 @@ function deleteBackup(src: string, suffix = "-BACKUP") {
|
|
|
301
303
|
function createBackup(src: string, suffix = "-BACKUP") {
|
|
302
304
|
const dest = src + suffix;
|
|
303
305
|
|
|
304
|
-
if (!
|
|
306
|
+
if (!fsx.existsSync(src)) {
|
|
305
307
|
console.log(`Source ${src} does not exist`);
|
|
306
308
|
return;
|
|
307
309
|
}
|
|
308
310
|
|
|
309
|
-
if (
|
|
311
|
+
if (fsx.existsSync(dest)) {
|
|
310
312
|
console.log(`Destination ${dest} already exists`);
|
|
311
313
|
return;
|
|
312
314
|
}
|
|
@@ -323,8 +325,9 @@ function isMultiPageId(id: number) {
|
|
|
323
325
|
return Number.isInteger(id) && id < 0;
|
|
324
326
|
}
|
|
325
327
|
|
|
326
|
-
function removeMultiPagesFromStore() {
|
|
327
|
-
const
|
|
328
|
+
async function removeMultiPagesFromStore() {
|
|
329
|
+
const config = await getConfig();
|
|
330
|
+
const dirs = config.dirs();
|
|
328
331
|
const storePath = path.join(dirs.__cx, "store");
|
|
329
332
|
try {
|
|
330
333
|
const multiPageFiles = getPageInStoreDir(storePath).filter(isMultiPageId);
|
|
@@ -41,12 +41,11 @@ function runner(command: string, env: Env) {
|
|
|
41
41
|
|
|
42
42
|
if (error) {
|
|
43
43
|
console.error(error);
|
|
44
|
-
|
|
44
|
+
throw new Error(error.toString());
|
|
45
45
|
}
|
|
46
46
|
|
|
47
47
|
if (status !== 0) {
|
|
48
|
-
|
|
49
|
-
process.exit(1);
|
|
48
|
+
throw new Error(`Command \`${command}\` exited with code ${status}`);
|
|
50
49
|
}
|
|
51
50
|
}
|
|
52
51
|
|
package/exporter/utils/shared.ts
CHANGED
|
@@ -327,8 +327,7 @@ async function doLifeCycle(args: {
|
|
|
327
327
|
}) {
|
|
328
328
|
const { steps, name, attempts } = args;
|
|
329
329
|
let trysCount = 0;
|
|
330
|
-
const maxTrysAccepted =
|
|
331
|
-
Number(process.env.GRIDDO_LIFECYCLE_MAX_RETRY_ATTEMPTS) || attempts || 1;
|
|
330
|
+
const maxTrysAccepted = attempts || 1;
|
|
332
331
|
|
|
333
332
|
while (trysCount < maxTrysAccepted) {
|
|
334
333
|
try {
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
async function getConfig() {
|
|
2
|
+
try {
|
|
3
|
+
// eslint-disable-next-line node/no-unpublished-import
|
|
4
|
+
const configModule = await import("../../cx.config");
|
|
5
|
+
const config = configModule.default;
|
|
6
|
+
|
|
7
|
+
return config;
|
|
8
|
+
} catch (error) {
|
|
9
|
+
process.exit(1);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export { getConfig };
|
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.4.
|
|
4
|
+
"version": "10.4.8",
|
|
5
5
|
"authors": [
|
|
6
6
|
"Álvaro Sánchez' <alvaro.sanches@secuoyas.com>",
|
|
7
7
|
"Diego M. Béjar <diego.bejar@secuoyas.com>",
|
|
@@ -47,22 +47,16 @@
|
|
|
47
47
|
"babel-plugin-styled-components": "^1.10.7",
|
|
48
48
|
"babel-plugin-transform-runtime": "^6.23.0",
|
|
49
49
|
"babel-polyfill": "^6.26.0",
|
|
50
|
-
"branch-name": "^1.0.0",
|
|
51
50
|
"chalk": "^2.4.2",
|
|
52
|
-
"csvtojson": "^2.0.10",
|
|
53
51
|
"dotenv": "^8.1.0",
|
|
54
52
|
"find-up": "^5.0.0",
|
|
55
53
|
"fs-extra": "^9.0.1",
|
|
56
54
|
"gatsby": "^4.8.0",
|
|
57
|
-
"gatsby-plugin-polyfill-io": "^1.1.0",
|
|
58
55
|
"gatsby-plugin-react-helmet": "^5.8.0",
|
|
59
|
-
"gatsby-plugin-sass": "^5.21.0",
|
|
60
|
-
"gatsby-plugin-styled-components": "^5.8.0",
|
|
61
56
|
"gatsby-plugin-svgr-loader": "^0.1.0",
|
|
62
57
|
"gradient-string": "^2.0.2",
|
|
63
58
|
"html-react-parser": "^1.4.10",
|
|
64
59
|
"js2xmlparser": "^4.0.1",
|
|
65
|
-
"opn": "^6.0.0",
|
|
66
60
|
"p-limit": "^3.0.0",
|
|
67
61
|
"path-browserify": "^1.0.1",
|
|
68
62
|
"pkg-dir": "^5.0.0",
|
|
@@ -70,10 +64,6 @@
|
|
|
70
64
|
"react-helmet": "^6.0.0"
|
|
71
65
|
},
|
|
72
66
|
"devDependencies": {
|
|
73
|
-
"@griddo/eslint-config-back": "^10.4.6",
|
|
74
|
-
"@types/babel__core": "^7.20.0",
|
|
75
|
-
"@types/babel__preset-env": "^7.9.2",
|
|
76
|
-
"@types/csvtojson": "^2.0.0",
|
|
77
67
|
"@types/eslint": "^7.29.0",
|
|
78
68
|
"@types/fs-extra": "^9.0.13",
|
|
79
69
|
"@types/gradient-string": "^1.1.2",
|
|
@@ -117,5 +107,5 @@
|
|
|
117
107
|
"publishConfig": {
|
|
118
108
|
"access": "public"
|
|
119
109
|
},
|
|
120
|
-
"gitHead": "
|
|
110
|
+
"gitHead": "1390ad1d87acd73442f46bed3f505df9b6fd4adc"
|
|
121
111
|
}
|