@griddo/cx 1.75.178 ā 1.75.180
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/README.md +22 -14
- package/build/index.js +49 -0
- package/gatsby-browser.tsx +140 -0
- package/gatsby-config.ts +40 -0
- package/gatsby-node.ts +130 -0
- package/gatsby-ssr.tsx +63 -0
- package/index.js +4 -0
- package/package.json +119 -100
- package/scripts/build-reset.ts +9 -0
- package/scripts/griddo-exporter.ts +302 -0
- package/src/components/Head.tsx +207 -0
- package/src/components/template.tsx +90 -0
- package/src/components/types.ts +35 -0
- package/src/components/utils.ts +138 -0
- package/src/html.tsx +31 -0
- package/src/services/auth.ts +64 -0
- package/src/services/distributors.ts +153 -0
- package/src/services/domains.ts +27 -0
- package/src/services/navigation.ts +169 -0
- package/src/services/robots.ts +64 -0
- package/src/services/settings.ts +52 -0
- package/src/services/sites.ts +199 -0
- package/src/services/store-with-for-loop.ts +513 -0
- package/src/services/store-with-promise-all.ts +515 -0
- package/src/services/store.ts +513 -0
- package/src/types/api.ts +155 -0
- package/src/types/global.ts +72 -0
- package/src/types/navigation.ts +25 -0
- package/src/types/pages.ts +145 -0
- package/src/types/sites.ts +64 -0
- package/src/types/templates.ts +11 -0
- package/src/utils/api.ts +326 -0
- package/src/utils/cache.ts +114 -0
- package/src/utils/domains.ts +32 -0
- package/src/utils/folders.ts +147 -0
- package/src/utils/instance.ts +71 -0
- package/src/utils/pages.ts +534 -0
- package/src/utils/searches.ts +102 -0
- package/src/utils/shared.ts +131 -0
- package/src/utils/sites.ts +280 -0
- package/.babelrc +0 -7
- package/LICENSE +0 -1
- package/gatsby-browser.js +0 -115
- package/gatsby-config.js +0 -38
- package/gatsby-node.js +0 -273
- package/gatsby-ssr.js +0 -43
- package/scripts/griddo-exporter.js +0 -133
- package/src/api/index.js +0 -172
- package/src/components/template.js +0 -261
- package/src/html.js +0 -30
- package/src/images/readme.md +0 -1
- package/src/scripts/build-reset.js +0 -12
- package/src/services/auth.js +0 -44
- package/src/services/distributors.js +0 -85
- package/src/services/domains.js +0 -16
- package/src/services/navigation.js +0 -104
- package/src/services/robots.js +0 -37
- package/src/services/settings.js +0 -25
- package/src/services/sites.js +0 -110
- package/src/utils/cache.js +0 -70
- package/src/utils/component-lib-helpers.js +0 -56
- package/src/utils/dataLayer.js +0 -47
- package/src/utils/delay.js +0 -5
- package/src/utils/domains.js +0 -24
- package/src/utils/folders.js +0 -123
- package/src/utils/helpers.js +0 -144
- package/src/utils/index.js +0 -44
- package/src/utils/package.js +0 -20
- package/src/utils/pages.js +0 -236
- package/src/utils/searches.js +0 -62
- package/src/utils/sites.js +0 -207
- package/static/griddo-full-logo.png +0 -0
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
// Types
|
|
2
|
+
import type { Petition } from "../types/global";
|
|
3
|
+
import type { HashSites, SiteHash } from "../types/sites";
|
|
4
|
+
|
|
5
|
+
// External libraries
|
|
6
|
+
import crypto from "crypto";
|
|
7
|
+
import fs from "fs";
|
|
8
|
+
import path from "path";
|
|
9
|
+
|
|
10
|
+
// Constants
|
|
11
|
+
const API_CACHE_DIR_PATH = path.resolve(__dirname, "./../../apiCache");
|
|
12
|
+
const SITE_HASH_FILENAME = `${API_CACHE_DIR_PATH}/siteHash.json`;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Creates an `apiCache` folder to store pages from API
|
|
16
|
+
*/
|
|
17
|
+
function initCache() {
|
|
18
|
+
if (!fs.existsSync(API_CACHE_DIR_PATH)) {
|
|
19
|
+
fs.mkdirSync(API_CACHE_DIR_PATH);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
console.log("\nšŖ Cache initialized");
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Generate a filename with a hash using a Petition object
|
|
27
|
+
* TODO: Merge with createSha256
|
|
28
|
+
*
|
|
29
|
+
* @param petition An object
|
|
30
|
+
*/
|
|
31
|
+
function generateFilenameWithHash(petition: Petition) {
|
|
32
|
+
const hashSum = crypto.createHash("sha256");
|
|
33
|
+
hashSum.update(JSON.stringify(petition));
|
|
34
|
+
|
|
35
|
+
return `${API_CACHE_DIR_PATH}/${hashSum.digest("hex")}`;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Generate a filename with a hash using a string.
|
|
40
|
+
* TODO: Merge with generateFilenameWithHash
|
|
41
|
+
*
|
|
42
|
+
* @param data A string to create a sha256 based on.
|
|
43
|
+
*/
|
|
44
|
+
function createSha256(data: string) {
|
|
45
|
+
const hash = crypto.createHash("sha256");
|
|
46
|
+
hash.update(data);
|
|
47
|
+
|
|
48
|
+
return hash.digest("hex");
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Save a file using a hash name.
|
|
53
|
+
*
|
|
54
|
+
* @param petition An object.
|
|
55
|
+
* @param content Content to be saved.
|
|
56
|
+
*/
|
|
57
|
+
const saveCache = <T>(petition: Petition, content: T) => {
|
|
58
|
+
const stringContent =
|
|
59
|
+
typeof content === "string" ? content : JSON.stringify(content);
|
|
60
|
+
fs.writeFileSync(generateFilenameWithHash(petition), stringContent, "utf8");
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Read a cache file and return it as an object
|
|
65
|
+
*
|
|
66
|
+
* @param petition An object
|
|
67
|
+
*/
|
|
68
|
+
function getCache<T>(petition: Petition) {
|
|
69
|
+
try {
|
|
70
|
+
const content = fs.readFileSync(generateFilenameWithHash(petition), {
|
|
71
|
+
encoding: "utf-8",
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
return JSON.parse(content) as T;
|
|
75
|
+
} catch {
|
|
76
|
+
return null;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Get site hashes from the file as an object
|
|
82
|
+
*/
|
|
83
|
+
function getHashSites(): HashSites {
|
|
84
|
+
try {
|
|
85
|
+
const content = fs.readFileSync(SITE_HASH_FILENAME, { encoding: "utf-8" });
|
|
86
|
+
|
|
87
|
+
return JSON.parse(content) || {};
|
|
88
|
+
} catch {
|
|
89
|
+
return {};
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Update (write) the site hash file.
|
|
95
|
+
*
|
|
96
|
+
* @param siteId The id of the site.
|
|
97
|
+
* @param siteHash The has of the site.
|
|
98
|
+
*/
|
|
99
|
+
function updatedSiteHash(siteId: number, siteHash: SiteHash) {
|
|
100
|
+
const allHash = getHashSites();
|
|
101
|
+
const lastHash = allHash[siteId];
|
|
102
|
+
const currentHash = siteHash || lastHash || new Date().valueOf();
|
|
103
|
+
|
|
104
|
+
if (currentHash !== lastHash) {
|
|
105
|
+
allHash[siteId] = currentHash;
|
|
106
|
+
fs.writeFileSync(SITE_HASH_FILENAME, JSON.stringify(allHash), {
|
|
107
|
+
encoding: "utf-8",
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
return currentHash;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export { createSha256, updatedSiteHash, getCache, saveCache, initCache };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// Types
|
|
2
|
+
import type { Domains } from "../types/global";
|
|
3
|
+
|
|
4
|
+
// Services
|
|
5
|
+
import { AuthService } from "../services/auth";
|
|
6
|
+
import { DomainsService } from "../services/domains";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Return an array of slug domains.
|
|
10
|
+
*/
|
|
11
|
+
async function findDomains() {
|
|
12
|
+
await AuthService.login();
|
|
13
|
+
const domains = await DomainsService.getAll();
|
|
14
|
+
|
|
15
|
+
return getDomainSlugs(domains);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Return an unique array of domains, filtered without "/".
|
|
20
|
+
*
|
|
21
|
+
* @param domains An array of domains
|
|
22
|
+
* @see Domains
|
|
23
|
+
*/
|
|
24
|
+
function getDomainSlugs(domains: Domains) {
|
|
25
|
+
const filteredDomains = domains
|
|
26
|
+
.filter(({ slug }) => !!slug)
|
|
27
|
+
.map(({ slug }) => slug.replace("/", ""));
|
|
28
|
+
|
|
29
|
+
return [...new Set(filteredDomains)];
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export { findDomains };
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
// Types
|
|
2
|
+
import type { Site } from "../types/sites";
|
|
3
|
+
|
|
4
|
+
// External libraries
|
|
5
|
+
import fs from "fs-extra";
|
|
6
|
+
import path from "path";
|
|
7
|
+
|
|
8
|
+
// Utils
|
|
9
|
+
import { resolveComponentsPath } from "./instance";
|
|
10
|
+
import { logInfo } from "./shared";
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Delete sites folders that will be updated from de file system.
|
|
14
|
+
*
|
|
15
|
+
* @param updateSites An array of sites to be updated.
|
|
16
|
+
*/
|
|
17
|
+
async function deleteSites(updatedSites: Array<Site>) {
|
|
18
|
+
for await (const site of updatedSites) {
|
|
19
|
+
for (const domain of site.domains) {
|
|
20
|
+
const mappedDomain = Object.values(domain)[0];
|
|
21
|
+
const dir = path.resolve(__dirname, `../../dist${mappedDomain}`);
|
|
22
|
+
const pageDataDir = path.resolve(
|
|
23
|
+
__dirname,
|
|
24
|
+
`../../assets/page-data${mappedDomain}`
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
logInfo("Site dir", dir);
|
|
28
|
+
logInfo("Page data dir", pageDataDir);
|
|
29
|
+
|
|
30
|
+
// delete directory recursively
|
|
31
|
+
if (!fs.existsSync(dir)) return;
|
|
32
|
+
|
|
33
|
+
try {
|
|
34
|
+
await fs.rm(dir, { recursive: true });
|
|
35
|
+
logInfo(`${dir} is deleted!`);
|
|
36
|
+
} catch (err) {
|
|
37
|
+
console.log(err);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
if (!fs.existsSync(pageDataDir)) return;
|
|
41
|
+
|
|
42
|
+
try {
|
|
43
|
+
await fs.rm(pageDataDir, { recursive: true });
|
|
44
|
+
console.log(`${pageDataDir} is deleted!`);
|
|
45
|
+
} catch (err) {
|
|
46
|
+
console.log(err);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Update the Griddo's `/dist` folder with the contents from `/public` only with files of type:
|
|
54
|
+
* - js
|
|
55
|
+
* - json
|
|
56
|
+
* - css
|
|
57
|
+
*/
|
|
58
|
+
async function updateDist() {
|
|
59
|
+
const isGriddoExporter =
|
|
60
|
+
process.env.GRIDDO_EXPORTER && process.env.GRIDDO_EXPORTER === "on";
|
|
61
|
+
|
|
62
|
+
const src = "./public";
|
|
63
|
+
const dest = "./dist";
|
|
64
|
+
|
|
65
|
+
const domainDestPath = `${dest}/${process.env.DOMAIN}`;
|
|
66
|
+
|
|
67
|
+
const files = fs
|
|
68
|
+
.readdirSync(src)
|
|
69
|
+
.filter(
|
|
70
|
+
(file) =>
|
|
71
|
+
path.extname(file) === ".js" ||
|
|
72
|
+
path.extname(file) === ".json" ||
|
|
73
|
+
path.extname(file) === ".css"
|
|
74
|
+
);
|
|
75
|
+
|
|
76
|
+
const assetsDest = "./assets";
|
|
77
|
+
|
|
78
|
+
const pageDataSrc = `${src}/page-data`;
|
|
79
|
+
const pageDataDest = `${assetsDest}/page-data`;
|
|
80
|
+
|
|
81
|
+
const projectStaticSrc = "./static";
|
|
82
|
+
const projectStaticDest = assetsDest;
|
|
83
|
+
|
|
84
|
+
const gatsbyStaticSrc = `${dest}/static`;
|
|
85
|
+
const gatsbyStaticDest = `${assetsDest}/static`;
|
|
86
|
+
|
|
87
|
+
try {
|
|
88
|
+
fs.mkdirSync(assetsDest, { recursive: true });
|
|
89
|
+
fs.copySync(src, dest);
|
|
90
|
+
|
|
91
|
+
if (process.env.HAS_ASSET_DOMAIN) {
|
|
92
|
+
fs.copySync(pageDataSrc, pageDataDest);
|
|
93
|
+
fs.copySync(projectStaticSrc, projectStaticDest, { overwrite: false });
|
|
94
|
+
fs.copySync(gatsbyStaticSrc, gatsbyStaticDest, { overwrite: false });
|
|
95
|
+
fs.copySync(projectStaticSrc, domainDestPath, { overwrite: false });
|
|
96
|
+
|
|
97
|
+
files.map(async (file) => {
|
|
98
|
+
const fileSrc = `${src}/${file}`;
|
|
99
|
+
const fileDest = `${assetsDest}/${file}`;
|
|
100
|
+
fs.copySync(fileSrc, fileDest);
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
if (isGriddoExporter) fs.rmSync(src, { recursive: true });
|
|
105
|
+
} catch (err) {
|
|
106
|
+
console.error(err);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Copy the Griddo's `/dist` folder into the Griddo's `/public` folder.
|
|
112
|
+
*/
|
|
113
|
+
async function prepareServe() {
|
|
114
|
+
const src = "./dist";
|
|
115
|
+
const dest = "./public";
|
|
116
|
+
|
|
117
|
+
try {
|
|
118
|
+
await fs.copy(src, dest);
|
|
119
|
+
logInfo("Public copied");
|
|
120
|
+
} catch (err) {
|
|
121
|
+
console.warn("error", err);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Copy the instance's `/static` folder into the Gatsby's to take it into account for bundle.
|
|
127
|
+
*/
|
|
128
|
+
function prepareStaticFolder() {
|
|
129
|
+
const src = resolveComponentsPath("static");
|
|
130
|
+
const dest = "./static";
|
|
131
|
+
|
|
132
|
+
const files = fs.readdirSync(src);
|
|
133
|
+
|
|
134
|
+
try {
|
|
135
|
+
files.map(async (file) => {
|
|
136
|
+
const fileSrc = `${src}/${file}`;
|
|
137
|
+
const fileDest = `${dest}/${file}`;
|
|
138
|
+
fs.copySync(fileSrc, fileDest);
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
console.log("š Components static folder copied");
|
|
142
|
+
} catch (err) {
|
|
143
|
+
console.error(err);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
export { deleteSites, updateDist, prepareServe, prepareStaticFolder };
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
// External libraries
|
|
2
|
+
import findUp from "find-up";
|
|
3
|
+
import path from "path";
|
|
4
|
+
import pkgDir from "pkg-dir";
|
|
5
|
+
|
|
6
|
+
// Envs
|
|
7
|
+
const isComponentLibraryEnv = __dirname.includes("node_modules");
|
|
8
|
+
const projectAliases = getComponentsLibAliases();
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Returns the instance or monorepo paths.
|
|
12
|
+
*
|
|
13
|
+
* @param customPath The path for the instance components
|
|
14
|
+
*/
|
|
15
|
+
function resolveComponentsPath(customPath = "") {
|
|
16
|
+
return isComponentLibraryEnv
|
|
17
|
+
? path.resolve(pkgDir.sync(__dirname) as string, "../../../", customPath)
|
|
18
|
+
: path.resolve(
|
|
19
|
+
pkgDir.sync(__dirname) as string,
|
|
20
|
+
"../griddo-components",
|
|
21
|
+
customPath
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Return the instance or monorepo components {t|j}sconfig.json file.
|
|
27
|
+
*/
|
|
28
|
+
function getComponentsJSConfig() {
|
|
29
|
+
const jsConfigPath = findUp.sync("jsconfig.json", {
|
|
30
|
+
cwd: resolveComponentsPath(),
|
|
31
|
+
});
|
|
32
|
+
const tsConfigPath = findUp.sync("tsconfig.json", {
|
|
33
|
+
cwd: resolveComponentsPath(),
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
return tsConfigPath || jsConfigPath;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Get the instance webpack aliases
|
|
41
|
+
*/
|
|
42
|
+
function getComponentsLibAliases() {
|
|
43
|
+
const xsConfig = require(getComponentsJSConfig() as string);
|
|
44
|
+
|
|
45
|
+
return Object.keys(xsConfig?.compilerOptions?.paths).reduce(
|
|
46
|
+
(currentAlias, pathKey) => {
|
|
47
|
+
const [aliasKey] = pathKey.split("/");
|
|
48
|
+
const [pathAtJsConfig] = xsConfig?.compilerOptions?.paths[pathKey];
|
|
49
|
+
|
|
50
|
+
const [relativePathToDir] = pathAtJsConfig.split("/*");
|
|
51
|
+
|
|
52
|
+
const absolutePath = resolveComponentsPath(relativePathToDir);
|
|
53
|
+
|
|
54
|
+
return {
|
|
55
|
+
...currentAlias,
|
|
56
|
+
[aliasKey]: absolutePath,
|
|
57
|
+
};
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
components: `${resolveComponentsPath()}/src/index.js`,
|
|
61
|
+
}
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export {
|
|
66
|
+
getComponentsJSConfig,
|
|
67
|
+
getComponentsLibAliases,
|
|
68
|
+
isComponentLibraryEnv,
|
|
69
|
+
projectAliases,
|
|
70
|
+
resolveComponentsPath,
|
|
71
|
+
};
|