@griddo/cx 1.75.208 → 1.75.210
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/index.js +2 -2
- package/gatsby-node.ts +28 -31
- package/package.json +5 -5
- package/scripts/griddo-exporter.ts +1 -1
- package/src/services/store.ts +7 -13
- package/src/types/pages.ts +1 -1
- package/src/utils/pages.ts +1 -1
package/build/index.js
CHANGED
|
@@ -25,7 +25,7 @@ GFS4: `),console.error(e)});G[Q]||(ea=global[Q]||[],ra(G,ea),G.close=function(e)
|
|
|
25
25
|
\u2502 Access credentials failure \u2502
|
|
26
26
|
\u2502 Check that the login details are correct in your .env file \u2502
|
|
27
27
|
\u2570\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u256F
|
|
28
|
-
`)),process.exit(1)}}},hr=new On;var Yu=Y(Rn()),Xu=Y(mt()),Ku=Y(Gt());var fp=Y(mt()),Uu=Y(Gt()),hp=Y(eu()),Gu=Y($u());var Hu="1.75.
|
|
28
|
+
`)),process.exit(1)}}},hr=new On;var Yu=Y(Rn()),Xu=Y(mt()),Ku=Y(Gt());var fp=Y(mt()),Uu=Y(Gt()),hp=Y(eu()),Gu=Y($u());var Hu="1.75.210";Uu.default.config();var dp=!!process.env.GRIDDO_BUILD_LOGS&&!!JSON.parse(process.env.GRIDDO_BUILD_LOGS);function zu(...e){dp&&console.info(...e)}function Wu(e){return new Promise(t=>setTimeout(t,e))}function ai(e,t=3){return(e/1e3).toFixed(t)}function Ju(e){return"site"in e&&e.site?e?.site:void 0}function ci(...e){let t=performance.now();return e.forEach(r=>r()),ai(performance.now()-t)}function Vu(){let e=`
|
|
29
29
|
\xB7\xB7
|
|
30
30
|
\xB7\xB7
|
|
31
31
|
\xB7\xB7
|
|
@@ -57,7 +57,7 @@ ${m}
|
|
|
57
57
|
${y}
|
|
58
58
|
|
|
59
59
|
=============
|
|
60
|
-
`)),s&&(typeof o?.attempt!="number"||o.attempt>=parseInt(Qu))&&process.exit(1)}var yp=process.env.API_URL,gp={GET_ALL:`${yp}/domains`},Dr=class{static async getAll(){let{GET_ALL:t}=gp;return await el({endpoint:t})}};async function tl(){await hr.login();let e=await Dr.getAll();return vp(e)}function vp(e){let t=e.filter(({slug:r})=>!!r).map(({slug:r})=>r.replace("/",""));return[...new Set(t)]}sl.default.config();var ui=["dist","assets","apiCache"],rl=["public","
|
|
60
|
+
`)),s&&(typeof o?.attempt!="number"||o.attempt>=parseInt(Qu))&&process.exit(1)}var yp=process.env.API_URL,gp={GET_ALL:`${yp}/domains`},Dr=class{static async getAll(){let{GET_ALL:t}=gp;return await el({endpoint:t})}};async function tl(){await hr.login();let e=await Dr.getAll();return vp(e)}function vp(e){let t=e.filter(({slug:r})=>!!r).map(({slug:r})=>r.replace("/",""));return[...new Set(t)]}sl.default.config();var ui=["dist","assets","apiCache"],rl=["public","store",".cache"],bp=li.default.sync(),wp=It.default.resolve(bp,"exports/sites"),ol=li.default.sync(__dirname),_p=e=>t=>xp(t,e),xp=(e,t={})=>(0,il.execSync)(e,{cwd:ol,stdio:"inherit",env:{...process.env,...t,GRIDDO_EXPORTER:"true"}}),Ep=e=>!process.env.GRIDDO_ASSET_PREFIX||!e||!e.startsWith("pro-")?"":`${process.env.GRIDDO_ASSET_PREFIX}/${e}`,nl=(...e)=>console.log(...e),Ge=(...e)=>console.log(...e),Sp=(...e)=>console.log(...e),Ue=(...e)=>console.log(...e),kp=async e=>{let t=Rp(e),r=ci(t.init,t.restoreArtifacts);Ge(`
|
|
61
61
|
\u231B\uFE0F Domain ${e} restaured: ${r}s`),t.runExporter();let n=ci(t.archiveArtifacts);Ge(`
|
|
62
62
|
\u231B\uFE0F Domain ${e} archived: ${n}s`)},Cp=async()=>{Vu(),us();let e=await tl();for(let t of e)Ge(`\uFE0F\u{1F6A2} Exporting domain ${Z.default.underline(t)}`),await kp(t)},Rp=e=>{let t=Ep(e),r=_p({DOMAIN:e,GRIDDO_ASSET_PREFIX:t,HAS_ASSET_DOMAIN:t&&t!=="",RENDERID:new Date().valueOf()}),n=()=>{Ge(`\u{1F680} Initializing ${Z.default.underline(e)} exporter`),s(),o()},i=(S="")=>{let C=It.default.resolve(wp,e),P=It.default.resolve(C,S),J=`${P}-BACKUP`,de=It.default.resolve(ol,S);return{domainExportArchiveBasePath:C,currentExportArchivePath:P,currentExportBackupPath:J,currentExportWorkingPath:de}},s=()=>{for(let S of[...ui,...rl]){let{currentExportWorkingPath:C}=i(S);Se.default.existsSync(C)&&(Ue(`\u{1F9F9} Cleanup dirty ${Z.default.gray(C)}`),r(`rm -rf ${C}`))}},o=()=>{let{domainExportArchiveBasePath:S}=i();Se.default.existsSync(S)||(Ge(`\u2728 Creating ${S}`),r(`mkdir -p ${S}`))},a=S=>{let{currentExportArchivePath:C,currentExportWorkingPath:P}=i(S);Ge(`\u{1F69A} Moving files from ${Z.default.gray(P)} to ${Z.default.gray(C)}`),r(`mv ${P} ${C}`)},c=()=>{for(let S of ui){let{currentExportWorkingPath:C,currentExportArchivePath:P}=i(S);if(!Se.default.existsSync(C)){nl("\u{1F4C1} Source directory has not been created:",C);continue}try{h(S),a(S),m(S)}catch(J){nl(`\u{1F69A} Error moving files to ${P}`,J.message),p(S);continue}}},d=()=>{for(let S of ui){let{currentExportArchivePath:C,currentExportWorkingPath:P}=i(S);Se.default.existsSync(C)&&(Ue(`\uFE0F\u267B\uFE0F Restoring ${Z.default.gray(C)}`),r(`cp -R ${C} ${P}`))}_()},h=S=>{let{currentExportArchivePath:C,currentExportBackupPath:P}=i(S);Se.default.existsSync(C)&&(Ge(`\u{1F4BF} Creating backup of ${Z.default.gray(C)}`),r(`mv ${C} ${P}`))},p=S=>{let{currentExportArchivePath:C,currentExportBackupPath:P}=i(S);Se.default.existsSync(P)&&(Ue(`\uFE0F\u267B\uFE0F Restoring backup ${Z.default.gray(C)}`),r(`mv ${P} ${C}`))},m=S=>{let{currentExportArchivePath:C,currentExportBackupPath:P}=i(S);Ue(`\uFE0F\u{1F5D1}\uFE0F Removing backup ${Z.default.gray(C)}`),r(`rm -rf ${P}`)},y=()=>{console.log(`
|
|
63
63
|
${Z.default.black(Z.default.bgGreen(" Gatsby (start) "))}
|
package/gatsby-node.ts
CHANGED
|
@@ -15,11 +15,12 @@ import { generateBuildReport, generateSitemaps } from "./src/utils/sites";
|
|
|
15
15
|
dotenv.config();
|
|
16
16
|
|
|
17
17
|
// Envs
|
|
18
|
-
const GRIDDO_STORE_MODE =
|
|
18
|
+
const GRIDDO_STORE_MODE = (process.env.GRIDDO_STORE_MODE ||
|
|
19
|
+
"file") as StoreMode;
|
|
19
20
|
|
|
20
21
|
// Consts
|
|
21
22
|
const PUBLIC_FOLDER = path.resolve(__dirname, "./public");
|
|
22
|
-
const STORE_DIR_PATH = path.resolve(__dirname, "
|
|
23
|
+
const STORE_DIR_PATH = path.resolve(__dirname, "./store/");
|
|
23
24
|
const REPORT_FILE = path.resolve(PUBLIC_FOLDER, "__build-report__.json");
|
|
24
25
|
const GRIDDO_SANITIZE_PAGES = false;
|
|
25
26
|
const envVars: Record<string, any> = {};
|
|
@@ -37,11 +38,11 @@ export const onPreInit = async () => {
|
|
|
37
38
|
splash();
|
|
38
39
|
initCache();
|
|
39
40
|
prepareStaticFolder();
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
41
|
+
StoreService.init(STORE_DIR_PATH, {
|
|
42
|
+
sanitize: GRIDDO_SANITIZE_PAGES,
|
|
43
|
+
mode: GRIDDO_STORE_MODE,
|
|
44
|
+
});
|
|
45
|
+
await StoreService.createBuildSource();
|
|
45
46
|
|
|
46
47
|
console.log("\n✨ onPreInit\n");
|
|
47
48
|
};
|
|
@@ -52,37 +53,33 @@ export const onPreInit = async () => {
|
|
|
52
53
|
export const createPages: GatsbyNode["createPages"] = async ({
|
|
53
54
|
actions: { createPage },
|
|
54
55
|
}) => {
|
|
55
|
-
StoreService.
|
|
56
|
-
sanitize: GRIDDO_SANITIZE_PAGES,
|
|
57
|
-
mode: GRIDDO_STORE_MODE,
|
|
58
|
-
});
|
|
59
|
-
await StoreService.createBuildSource(createPage);
|
|
56
|
+
const pages = StoreService.getPages();
|
|
60
57
|
|
|
61
|
-
|
|
58
|
+
let totalPagesSize = 0;
|
|
62
59
|
|
|
63
|
-
//
|
|
64
|
-
//
|
|
65
|
-
//
|
|
66
|
-
|
|
67
|
-
|
|
60
|
+
// We need to use a `for..of` to iterate over `pages` since it could be a
|
|
61
|
+
// generator and for example a `forEach` doesn't work on it. Besides a
|
|
62
|
+
// `for..of` is probably the best performance option.
|
|
63
|
+
for (const page of pages) {
|
|
64
|
+
const startTime = performance.now();
|
|
68
65
|
|
|
69
|
-
|
|
66
|
+
createPage(page);
|
|
70
67
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
68
|
+
const {
|
|
69
|
+
size: pageSize,
|
|
70
|
+
context: { id },
|
|
71
|
+
path: pagePath,
|
|
72
|
+
} = page;
|
|
73
|
+
const duration = msToSec(performance.now() - startTime);
|
|
74
|
+
const size = pageSize ? logPageSize(Math.round(pageSize)) : 0;
|
|
78
75
|
|
|
79
|
-
|
|
76
|
+
logInfo(`Creating page ${pagePath} - ${duration}s - ${id} - ${size}`);
|
|
80
77
|
|
|
81
|
-
|
|
82
|
-
|
|
78
|
+
totalPagesSize += pageSize || 0;
|
|
79
|
+
}
|
|
83
80
|
|
|
84
|
-
|
|
85
|
-
|
|
81
|
+
const totalPagesSizeMsg = (totalPagesSize / 1024).toFixed(3);
|
|
82
|
+
console.info(`Total page-data.json size: ${totalPagesSizeMsg}MB`);
|
|
86
83
|
|
|
87
84
|
console.log("\n✨ createPages\n");
|
|
88
85
|
};
|
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.
|
|
4
|
+
"version": "1.75.210",
|
|
5
5
|
"authors": [
|
|
6
6
|
"Álvaro Sánchez' <alvaro.sanches@secuoyas.com>",
|
|
7
7
|
"Diego M. Béjar <diego.bejar@secuoyas.com>",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"build": "yarn run build:exporter",
|
|
24
24
|
"build:exporter": "esbuild ./scripts/griddo-exporter.ts --bundle --platform=node --minify --outfile=./build/index.js",
|
|
25
25
|
"export": "gatsby build --prefix-paths",
|
|
26
|
-
"clean": "gatsby clean; rm -rf .cache public assets dist build
|
|
26
|
+
"clean": "gatsby clean; rm -rf .cache public assets dist build store",
|
|
27
27
|
"prepare": "yarn run build:exporter",
|
|
28
28
|
"watch:tscheck": "tsc --noEmit --watch"
|
|
29
29
|
},
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"@babel/preset-env": "^7.14.5",
|
|
34
34
|
"@babel/preset-react": "^7.14.5",
|
|
35
35
|
"@babel/preset-typescript": "^7.16.5",
|
|
36
|
-
"@griddo/core": "^1.75.
|
|
36
|
+
"@griddo/core": "^1.75.210",
|
|
37
37
|
"@svgr/webpack": "^5.5.0",
|
|
38
38
|
"babel-loader": "^8.0.6",
|
|
39
39
|
"babel-plugin-styled-components": "^1.10.7",
|
|
@@ -63,7 +63,7 @@
|
|
|
63
63
|
"react-helmet": "^6.0.0"
|
|
64
64
|
},
|
|
65
65
|
"devDependencies": {
|
|
66
|
-
"@griddo/eslint-config-back": "^1.75.
|
|
66
|
+
"@griddo/eslint-config-back": "^1.75.210",
|
|
67
67
|
"@types/babel__core": "^7.20.0",
|
|
68
68
|
"@types/babel__preset-env": "^7.9.2",
|
|
69
69
|
"@types/csvtojson": "^2.0.0",
|
|
@@ -111,5 +111,5 @@
|
|
|
111
111
|
"publishConfig": {
|
|
112
112
|
"access": "public"
|
|
113
113
|
},
|
|
114
|
-
"gitHead": "
|
|
114
|
+
"gitHead": "2b9df0e7e16083025b24814e8952c45078a732a8"
|
|
115
115
|
}
|
|
@@ -19,7 +19,7 @@ dotenv.config();
|
|
|
19
19
|
|
|
20
20
|
// Envs
|
|
21
21
|
const artifactsArchivable = ["dist", "assets", "apiCache"];
|
|
22
|
-
const artifactsDisposable = ["public", "
|
|
22
|
+
const artifactsDisposable = ["public", "store", ".cache"];
|
|
23
23
|
|
|
24
24
|
// Where we are going to find export folders
|
|
25
25
|
const execBasePath = pkgDir.sync()!;
|
package/src/services/store.ts
CHANGED
|
@@ -132,8 +132,8 @@ class StoreService {
|
|
|
132
132
|
fs.mkdirSync(basePath);
|
|
133
133
|
}
|
|
134
134
|
|
|
135
|
-
if (!fs.existsSync(path.resolve(basePath
|
|
136
|
-
fs.mkdirSync(path.resolve(basePath
|
|
135
|
+
if (!fs.existsSync(path.resolve(basePath))) {
|
|
136
|
+
fs.mkdirSync(path.resolve(basePath));
|
|
137
137
|
}
|
|
138
138
|
}
|
|
139
139
|
}
|
|
@@ -141,7 +141,7 @@ class StoreService {
|
|
|
141
141
|
/**
|
|
142
142
|
* Create a complete build fetching the necessary data from API.
|
|
143
143
|
*/
|
|
144
|
-
public static async createBuildSource(
|
|
144
|
+
public static async createBuildSource() {
|
|
145
145
|
try {
|
|
146
146
|
// Get sites objects to publish and unpublish.
|
|
147
147
|
const { sitesToPublish, sitesToUnpublish } = await checkSites();
|
|
@@ -357,16 +357,10 @@ class StoreService {
|
|
|
357
357
|
BUILD_PROCESS_DATA[siteId].publishHashes.push(page.hash);
|
|
358
358
|
|
|
359
359
|
// Save build data to store
|
|
360
|
-
|
|
360
|
+
await this.savePages(gatsbyPageObjects); // gatsbyPageObjects is always an array regardless of whether it's just one page
|
|
361
361
|
this.saveSitesToPublish(sitesToPublish);
|
|
362
362
|
this.saveBuildProcessData(BUILD_PROCESS_DATA);
|
|
363
363
|
this.saveCreatedPages(CREATED_PAGES);
|
|
364
|
-
|
|
365
|
-
// Create Gatsby Page
|
|
366
|
-
// TODO: Testing purposes
|
|
367
|
-
gatsbyPageObjects.forEach((gatsbyPageObject) => {
|
|
368
|
-
createPage(gatsbyPageObject);
|
|
369
|
-
});
|
|
370
364
|
};
|
|
371
365
|
|
|
372
366
|
const griddoCxThreads = parseInt(GRIDDO_API_CONCURRENCY_COUNT || "10");
|
|
@@ -470,7 +464,7 @@ class StoreService {
|
|
|
470
464
|
* Return an iterator with pages read from the file system.
|
|
471
465
|
*/
|
|
472
466
|
private static *getPagesFromFiles() {
|
|
473
|
-
const pagesDirPath = path.resolve(this.basePath
|
|
467
|
+
const pagesDirPath = path.resolve(this.basePath);
|
|
474
468
|
const jsonFilePaths = walk(pagesDirPath).filter(
|
|
475
469
|
(file) => path.extname(file) === ".json"
|
|
476
470
|
);
|
|
@@ -480,7 +474,7 @@ class StoreService {
|
|
|
480
474
|
const jsonContent = fs.readFileSync(filePath, "utf-8");
|
|
481
475
|
const page = JSON.parse(jsonContent) as GatsbyPageObject;
|
|
482
476
|
page.size = fs.statSync(filePath).size / 1024;
|
|
483
|
-
yield
|
|
477
|
+
yield page;
|
|
484
478
|
} catch {
|
|
485
479
|
console.error(`Error: The file ${filePath} doesn't exist`);
|
|
486
480
|
}
|
|
@@ -503,7 +497,7 @@ class StoreService {
|
|
|
503
497
|
const promises = pages.map(async (pageObject) => {
|
|
504
498
|
const filename = `${createSha256(pageObject.path)}.json`;
|
|
505
499
|
const fileContent = JSON.stringify(pageObject);
|
|
506
|
-
const filePath = path.resolve(this.basePath,
|
|
500
|
+
const filePath = path.resolve(this.basePath, filename);
|
|
507
501
|
await fsp.writeFile(filePath, fileContent);
|
|
508
502
|
});
|
|
509
503
|
|
package/src/types/pages.ts
CHANGED