@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
package/gatsby-node.js
DELETED
|
@@ -1,273 +0,0 @@
|
|
|
1
|
-
const utils = require('./src/utils').default;
|
|
2
|
-
const helpers = require('./src/utils/helpers');
|
|
3
|
-
const sites = require('./src/utils/sites');
|
|
4
|
-
const folders = require('./src/utils/folders');
|
|
5
|
-
const DistributorService = require('./src/services/distributors').default;
|
|
6
|
-
const NavigationService = require('./src/services/navigation').default;
|
|
7
|
-
const SitesService = require('./src/services/sites').default;
|
|
8
|
-
const SettingsService = require('./src/services/settings').default;
|
|
9
|
-
const RobotsService = require('./src/services/robots').default;
|
|
10
|
-
const { initCache, updatedSiteHash } = require('./src/utils/cache');
|
|
11
|
-
|
|
12
|
-
const {
|
|
13
|
-
isComponentLibraryEnv,
|
|
14
|
-
projectAliases,
|
|
15
|
-
} = require('./src/utils/component-lib-helpers');
|
|
16
|
-
|
|
17
|
-
const { getComponentsVersion } = require('./src/utils/package');
|
|
18
|
-
|
|
19
|
-
require('dotenv').config();
|
|
20
|
-
|
|
21
|
-
// Envs
|
|
22
|
-
const baseUrl = process.env.API_URL;
|
|
23
|
-
const publicBaseUrl = process.env.PUBLIC_API_URL;
|
|
24
|
-
const instance = process.env.REACT_APP_INSTANCE;
|
|
25
|
-
const IS_SERVE = !!process.env.IS_SERVE && JSON.parse(process.env.IS_SERVE);
|
|
26
|
-
const BUILD_MODE = process.env.CXBRANCH;
|
|
27
|
-
const CX_THREADS = process.env.CX_THREADS;
|
|
28
|
-
|
|
29
|
-
// Share info between actions (createPages and onPostBuild)
|
|
30
|
-
let updatedSites;
|
|
31
|
-
let createdPages = [];
|
|
32
|
-
let buildProcessData = {};
|
|
33
|
-
const { componentsVersion, griddoVersion } = getComponentsVersion();
|
|
34
|
-
|
|
35
|
-
const renderId = process.env.RENDERID || new Date().valueOf();
|
|
36
|
-
|
|
37
|
-
// -----------------------------------------------------------------------------
|
|
38
|
-
// Component System alias
|
|
39
|
-
// -----------------------------------------------------------------------------
|
|
40
|
-
exports.onCreateWebpackConfig = ({ actions, plugins, loaders, getConfig }) => {
|
|
41
|
-
if (isComponentLibraryEnv) {
|
|
42
|
-
const config = getConfig();
|
|
43
|
-
config.module.rules = [
|
|
44
|
-
// Omit the default rule where test === '\.jsx?$'
|
|
45
|
-
...config.module.rules.filter(
|
|
46
|
-
rule => String(rule.test) !== String(/\.jsx?$/)
|
|
47
|
-
),
|
|
48
|
-
// Recreate it with custom exclude filter
|
|
49
|
-
{
|
|
50
|
-
...loaders.js(),
|
|
51
|
-
test: /\.jsx?$/,
|
|
52
|
-
// Exclude all node_modules from transpilation, except for '@griddo/cx'
|
|
53
|
-
exclude: modulePath =>
|
|
54
|
-
/node_modules/.test(modulePath) && !/@griddo\/cx/.test(modulePath),
|
|
55
|
-
},
|
|
56
|
-
];
|
|
57
|
-
actions.replaceWebpackConfig(config);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
// Add component-system aliases to Webpack's Resolve:
|
|
61
|
-
actions.setWebpackConfig({
|
|
62
|
-
resolve: {
|
|
63
|
-
fallback: { path: require.resolve('path-browserify') },
|
|
64
|
-
alias: projectAliases,
|
|
65
|
-
},
|
|
66
|
-
plugins: [plugins.provide({ process: 'process/browser' })],
|
|
67
|
-
});
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
// -----------------------------------------------------------------------------
|
|
71
|
-
// onPreInit (hook)
|
|
72
|
-
// -----------------------------------------------------------------------------
|
|
73
|
-
exports.onPreInit = async () => {
|
|
74
|
-
initCache();
|
|
75
|
-
await folders.prepareStaticFolder();
|
|
76
|
-
await SettingsService.getAll();
|
|
77
|
-
try {
|
|
78
|
-
const { sitesToRender, sitesToUnpublish } = await sites.checkSites();
|
|
79
|
-
|
|
80
|
-
if (sitesToRender.length === 0 && sitesToUnpublish.length === 0) {
|
|
81
|
-
console.log(
|
|
82
|
-
'\n',
|
|
83
|
-
JSON.stringify({ sitesToRender, sitesToUnpublish }, null, 2),
|
|
84
|
-
'\n'
|
|
85
|
-
);
|
|
86
|
-
|
|
87
|
-
helpers.log('warning', 'There are no sites to update');
|
|
88
|
-
process.exit(0);
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
helpers.log('info', 'RENDERING SITES ===>', sitesToRender);
|
|
92
|
-
await sites.unpublishSites(sitesToUnpublish);
|
|
93
|
-
helpers.log('success', 'UNPUBLISHED SITES ->', sitesToUnpublish);
|
|
94
|
-
await folders.deleteSites([...sitesToRender]);
|
|
95
|
-
await RobotsService.loadRobots();
|
|
96
|
-
|
|
97
|
-
updatedSites = sitesToRender;
|
|
98
|
-
} catch (err) {
|
|
99
|
-
console.log(err.message);
|
|
100
|
-
process.exit(1);
|
|
101
|
-
}
|
|
102
|
-
};
|
|
103
|
-
|
|
104
|
-
// -----------------------------------------------------------------------------
|
|
105
|
-
// createPages (hook)
|
|
106
|
-
// -----------------------------------------------------------------------------
|
|
107
|
-
exports.createPages = async ({ actions }) => {
|
|
108
|
-
// fetch
|
|
109
|
-
for (const site of updatedSites) {
|
|
110
|
-
const NavService = new NavigationService();
|
|
111
|
-
const { id: siteId, slug: siteSlug, theme, favicon } = site;
|
|
112
|
-
const {
|
|
113
|
-
siteInfo,
|
|
114
|
-
validPagesIds,
|
|
115
|
-
siteHash,
|
|
116
|
-
unpublishHashes,
|
|
117
|
-
siteLangs,
|
|
118
|
-
defaultLang,
|
|
119
|
-
headers,
|
|
120
|
-
footers,
|
|
121
|
-
socials,
|
|
122
|
-
} = await sites.getSiteData(siteId);
|
|
123
|
-
|
|
124
|
-
const cache = updatedSiteHash(siteId, siteHash);
|
|
125
|
-
|
|
126
|
-
site.languages = siteLangs;
|
|
127
|
-
|
|
128
|
-
const {
|
|
129
|
-
cloudinaryName,
|
|
130
|
-
useMetaTitle,
|
|
131
|
-
showBasicMetaRobots,
|
|
132
|
-
avoidHrefLangsOnCanonicals,
|
|
133
|
-
avoidSelfReferenceCanonicals,
|
|
134
|
-
avoidHrefLangXDefault,
|
|
135
|
-
avoidDebugMetas,
|
|
136
|
-
} = SettingsService.settings;
|
|
137
|
-
|
|
138
|
-
NavService.navigations = {
|
|
139
|
-
headers,
|
|
140
|
-
footers,
|
|
141
|
-
};
|
|
142
|
-
|
|
143
|
-
buildProcessData[siteId] = {
|
|
144
|
-
siteHash,
|
|
145
|
-
unpublishHashes,
|
|
146
|
-
publishHashes: [],
|
|
147
|
-
};
|
|
148
|
-
|
|
149
|
-
// SITE METADATA
|
|
150
|
-
const siteMetadata = {
|
|
151
|
-
siteUrl: siteInfo.slug,
|
|
152
|
-
title: siteInfo.name,
|
|
153
|
-
favicon,
|
|
154
|
-
};
|
|
155
|
-
|
|
156
|
-
const siteScript = siteInfo.siteScript;
|
|
157
|
-
|
|
158
|
-
let additionalInfo = {
|
|
159
|
-
baseUrl,
|
|
160
|
-
publicBaseUrl,
|
|
161
|
-
instance,
|
|
162
|
-
siteSlug,
|
|
163
|
-
theme,
|
|
164
|
-
siteMetadata,
|
|
165
|
-
socials,
|
|
166
|
-
siteLangs,
|
|
167
|
-
cloudinaryName,
|
|
168
|
-
componentsVersion,
|
|
169
|
-
griddoVersion,
|
|
170
|
-
siteOptions: {
|
|
171
|
-
useMetaTitle,
|
|
172
|
-
showBasicMetaRobots,
|
|
173
|
-
avoidHrefLangsOnCanonicals,
|
|
174
|
-
avoidSelfReferenceCanonicals,
|
|
175
|
-
avoidHrefLangXDefault,
|
|
176
|
-
avoidDebugMetas,
|
|
177
|
-
},
|
|
178
|
-
BUILD_MODE,
|
|
179
|
-
siteScript,
|
|
180
|
-
};
|
|
181
|
-
|
|
182
|
-
helpers.log('info', 'VALID PAGES -->', validPagesIds);
|
|
183
|
-
|
|
184
|
-
const renderPageProcess = async pageId => {
|
|
185
|
-
// Get page data
|
|
186
|
-
const page = await SitesService.getPage(pageId, cache);
|
|
187
|
-
|
|
188
|
-
if (!page) return;
|
|
189
|
-
|
|
190
|
-
createdPages.push(pageId);
|
|
191
|
-
|
|
192
|
-
const pageAdditionalInfo = JSON.parse(JSON.stringify(additionalInfo));
|
|
193
|
-
|
|
194
|
-
helpers.log(
|
|
195
|
-
'info',
|
|
196
|
-
`RENDERING PAGE ${pageId} -->`,
|
|
197
|
-
page.fullPath.compose
|
|
198
|
-
);
|
|
199
|
-
|
|
200
|
-
// Template data with the distributor data added.
|
|
201
|
-
const distributorTemplate = await DistributorService.getDistributorData(
|
|
202
|
-
page,
|
|
203
|
-
renderId
|
|
204
|
-
);
|
|
205
|
-
|
|
206
|
-
pageAdditionalInfo.navigations = NavService.getPageNavigations(page);
|
|
207
|
-
|
|
208
|
-
const isList = page?.mode === 'list';
|
|
209
|
-
|
|
210
|
-
const multiPageElements = await helpers.getMultiPageElements(
|
|
211
|
-
distributorTemplate
|
|
212
|
-
);
|
|
213
|
-
|
|
214
|
-
// Multi-page (pagination) or single-page
|
|
215
|
-
isList
|
|
216
|
-
? await utils.renderListPages(
|
|
217
|
-
{
|
|
218
|
-
rootPage: page,
|
|
219
|
-
pages: utils.getList(distributorTemplate),
|
|
220
|
-
totalQueriedItems: distributorTemplate?.queriedItems,
|
|
221
|
-
isRoot: false,
|
|
222
|
-
defaultLang,
|
|
223
|
-
distributorTemplate,
|
|
224
|
-
},
|
|
225
|
-
pageAdditionalInfo,
|
|
226
|
-
actions.createPage
|
|
227
|
-
)
|
|
228
|
-
: await utils.renderPage(
|
|
229
|
-
{
|
|
230
|
-
...page,
|
|
231
|
-
template: distributorTemplate,
|
|
232
|
-
isRoot: false,
|
|
233
|
-
defaultLang,
|
|
234
|
-
multiPageElements,
|
|
235
|
-
},
|
|
236
|
-
pageAdditionalInfo,
|
|
237
|
-
actions.createPage
|
|
238
|
-
);
|
|
239
|
-
|
|
240
|
-
buildProcessData[siteId].publishHashes.push(page.hash);
|
|
241
|
-
};
|
|
242
|
-
|
|
243
|
-
const cxThreads = (CX_THREADS && parseInt(CX_THREADS)) || 10;
|
|
244
|
-
helpers.log('info', `Processing createPages with ${cxThreads} threads`);
|
|
245
|
-
|
|
246
|
-
await import('p-limit').then(async pLimit => {
|
|
247
|
-
const limit = pLimit.default(cxThreads);
|
|
248
|
-
const pagesToRender = validPagesIds.map(id =>
|
|
249
|
-
limit(() => renderPageProcess(id))
|
|
250
|
-
);
|
|
251
|
-
await Promise.all(pagesToRender);
|
|
252
|
-
});
|
|
253
|
-
}
|
|
254
|
-
};
|
|
255
|
-
|
|
256
|
-
// -----------------------------------------------------------------------------
|
|
257
|
-
// onPostBuild (hook)
|
|
258
|
-
// -----------------------------------------------------------------------------
|
|
259
|
-
|
|
260
|
-
exports.onPostBuild = async () => {
|
|
261
|
-
helpers.log('success', 'POSTBUILD');
|
|
262
|
-
helpers.log('info', 'UPDATED SITES', updatedSites);
|
|
263
|
-
|
|
264
|
-
await sites.setPageRenderEnd(buildProcessData, createdPages);
|
|
265
|
-
|
|
266
|
-
await RobotsService.writeFiles(`${__dirname}/public`);
|
|
267
|
-
|
|
268
|
-
await sites.generateSitemaps(updatedSites);
|
|
269
|
-
|
|
270
|
-
await folders.updateDist();
|
|
271
|
-
|
|
272
|
-
IS_SERVE && (await folders.prepareServe());
|
|
273
|
-
};
|
package/gatsby-ssr.js
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
/* eslint-disable node/no-extraneous-import */
|
|
2
|
-
/* eslint-disable node/no-missing-require */
|
|
3
|
-
import React from 'react';
|
|
4
|
-
import { ssr } from 'components';
|
|
5
|
-
import { SessionProvider } from '@griddo/core';
|
|
6
|
-
|
|
7
|
-
export const wrapPageElement = ({ props }) => {
|
|
8
|
-
if (ssr.wrapPageElement) {
|
|
9
|
-
return ssr.wrapPageElement(props);
|
|
10
|
-
}
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
export const onRenderBody = props => {
|
|
14
|
-
if (ssr.onRenderBody) {
|
|
15
|
-
ssr.onRenderBody(props);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
// ** Comentado porque ahora mismo no queremos añadir headers adicionales desde aquí,
|
|
19
|
-
// ** los estamos metiendo en SEO.
|
|
20
|
-
// const { setHeadComponents } = props;
|
|
21
|
-
// const additionalHeadComponents = [];
|
|
22
|
-
// if (additionalHeadComponents.length) setHeadComponents([...additionalHeadComponents]);
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
export const onPreRenderHTML = props => {
|
|
26
|
-
if (ssr.onPreRenderHTML) {
|
|
27
|
-
ssr.onPreRenderHTML(props);
|
|
28
|
-
}
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
export const replaceRenderer = props => {
|
|
32
|
-
if (ssr.replaceRenderer) {
|
|
33
|
-
ssr.replaceRenderer(props);
|
|
34
|
-
}
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
export const wrapRootElement = props => {
|
|
38
|
-
return (
|
|
39
|
-
<SessionProvider>
|
|
40
|
-
{ssr.wrapRootElement ? ssr.wrapRootElement(props) : props.element}
|
|
41
|
-
</SessionProvider>
|
|
42
|
-
);
|
|
43
|
-
};
|
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
require('dotenv').config();
|
|
3
|
-
|
|
4
|
-
const { execSync } = require('child_process');
|
|
5
|
-
const fs = require('fs');
|
|
6
|
-
const path = require('path');
|
|
7
|
-
const pkgDir = require('pkg-dir');
|
|
8
|
-
|
|
9
|
-
const helpers = require('../src/utils/helpers');
|
|
10
|
-
const { initCache } = require('../src/utils/cache');
|
|
11
|
-
const { findDomains } = require('../src/utils/domains');
|
|
12
|
-
|
|
13
|
-
const artifacts = ['dist', 'assets'];
|
|
14
|
-
|
|
15
|
-
const currentPath = pkgDir.sync();
|
|
16
|
-
const workingDirPath = pkgDir.sync(__dirname);
|
|
17
|
-
const baseOutputPath = path.resolve(currentPath, 'public');
|
|
18
|
-
const destDirPath = path.resolve(currentPath, 'exports/sites');
|
|
19
|
-
|
|
20
|
-
// -----------------------------------------------------------------------------
|
|
21
|
-
// Process Runner
|
|
22
|
-
// -----------------------------------------------------------------------------
|
|
23
|
-
const getEnvRunner = env => command => runner(command, env);
|
|
24
|
-
|
|
25
|
-
const runner = (command, env = {}) =>
|
|
26
|
-
execSync(command, {
|
|
27
|
-
cwd: workingDirPath,
|
|
28
|
-
stdio: 'inherit',
|
|
29
|
-
shell: true,
|
|
30
|
-
env: {
|
|
31
|
-
...process.env,
|
|
32
|
-
...env,
|
|
33
|
-
GRIDDO_EXPORTER: true,
|
|
34
|
-
},
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
const getAssetPrefix = domain => {
|
|
38
|
-
// TODO: Usar asset_prefix del dominio
|
|
39
|
-
if (!process.env.ASSET_PREFIX || !domain) return '';
|
|
40
|
-
|
|
41
|
-
if (!domain.startsWith('pro-')) return '';
|
|
42
|
-
|
|
43
|
-
return `${process.env.ASSET_PREFIX}/${domain}`;
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
// -----------------------------------------------------------------------------
|
|
47
|
-
// Loggers
|
|
48
|
-
// -----------------------------------------------------------------------------
|
|
49
|
-
const logError = (...message) => helpers.log('error', ...message);
|
|
50
|
-
const logInfo = (...message) => helpers.log('info', ...message);
|
|
51
|
-
const logSuccess = (...message) => helpers.log('success', ...message);
|
|
52
|
-
const logWarning = (...message) => helpers.log('warning', ...message);
|
|
53
|
-
|
|
54
|
-
// -----------------------------------------------------------------------------
|
|
55
|
-
// Main Stuff
|
|
56
|
-
// -----------------------------------------------------------------------------
|
|
57
|
-
const runExportDomain = async domain => {
|
|
58
|
-
const assetPrefix = getAssetPrefix(domain);
|
|
59
|
-
|
|
60
|
-
const run = getEnvRunner({
|
|
61
|
-
DOMAIN: domain,
|
|
62
|
-
ASSET_PREFIX: assetPrefix,
|
|
63
|
-
HAS_ASSET_DOMAIN: assetPrefix && assetPrefix !== '',
|
|
64
|
-
RENDERID: new Date().valueOf(),
|
|
65
|
-
});
|
|
66
|
-
const domainDestDirPath = path.resolve(destDirPath, domain);
|
|
67
|
-
|
|
68
|
-
if (fs.existsSync(baseOutputPath)) {
|
|
69
|
-
logInfo(`Deleting base output path: ${baseOutputPath}`);
|
|
70
|
-
run(`rm -rf ${baseOutputPath}`);
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
run('npm run build');
|
|
74
|
-
|
|
75
|
-
logSuccess('Your sites have been exported correctly');
|
|
76
|
-
|
|
77
|
-
run(`mkdir -p ${domainDestDirPath}`);
|
|
78
|
-
|
|
79
|
-
for (const dir of artifacts) {
|
|
80
|
-
const cxDirSource = path.resolve(workingDirPath, dir);
|
|
81
|
-
const cxDirDest = path.resolve(domainDestDirPath, dir);
|
|
82
|
-
const cxDirDestBackup = `${cxDirDest}-BACKUP`;
|
|
83
|
-
|
|
84
|
-
if (!fs.existsSync(cxDirSource)) {
|
|
85
|
-
logError('Source directory has not been created:', cxDirSource);
|
|
86
|
-
continue;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
try {
|
|
90
|
-
if (fs.existsSync(cxDirDest)) {
|
|
91
|
-
logInfo(`Creando backup de ${cxDirDest}...`);
|
|
92
|
-
run(`mv ${cxDirDest} ${cxDirDestBackup}`);
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
logInfo(`Moviendo ficheros de ${cxDirSource} a ${cxDirDest}...`);
|
|
96
|
-
|
|
97
|
-
run(`mv ${cxDirSource} ${cxDirDest}`);
|
|
98
|
-
|
|
99
|
-
logInfo(`Eliminando backup de ${cxDirDest}...`);
|
|
100
|
-
run(`rm -rf ${cxDirDestBackup}`);
|
|
101
|
-
|
|
102
|
-
logSuccess(`Your sites are ready to deploy at ${domainDestDirPath}`);
|
|
103
|
-
} catch (error) {
|
|
104
|
-
logError(`Error moving files to ${cxDirDest}`, error.message);
|
|
105
|
-
|
|
106
|
-
if (fs.existsSync(cxDirDestBackup)) {
|
|
107
|
-
logWarning(`Restaurando ${cxDirDest}...`);
|
|
108
|
-
run(`mv ${cxDirDestBackup} ${cxDirDest}`);
|
|
109
|
-
}
|
|
110
|
-
continue;
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
};
|
|
114
|
-
|
|
115
|
-
const launchExports = async () => {
|
|
116
|
-
logInfo('Griddo Exporter');
|
|
117
|
-
|
|
118
|
-
initCache();
|
|
119
|
-
|
|
120
|
-
const domains = await findDomains();
|
|
121
|
-
|
|
122
|
-
for (const domain of domains) {
|
|
123
|
-
logInfo(`Exporting domain ${domain}`);
|
|
124
|
-
await runExportDomain(domain);
|
|
125
|
-
}
|
|
126
|
-
};
|
|
127
|
-
|
|
128
|
-
console.clear();
|
|
129
|
-
|
|
130
|
-
launchExports().catch(err => {
|
|
131
|
-
console.error('ERROR', err?.stdout?.toString() || err);
|
|
132
|
-
process.exit(1);
|
|
133
|
-
});
|
package/src/api/index.js
DELETED
|
@@ -1,172 +0,0 @@
|
|
|
1
|
-
const axios = require('axios');
|
|
2
|
-
const auth = require('../services/auth').default;
|
|
3
|
-
const { saveCache, getCache } = require('../utils/cache');
|
|
4
|
-
const { delay } = require('../utils/delay');
|
|
5
|
-
|
|
6
|
-
require('dotenv').config();
|
|
7
|
-
|
|
8
|
-
const {
|
|
9
|
-
env: { RETRY_WAIT_SECONDS = 4, RETRY_ATTEMPTS = 1 },
|
|
10
|
-
} = process;
|
|
11
|
-
|
|
12
|
-
const getApi = async (endpoint, body, cached = false, attempt = 0) => {
|
|
13
|
-
const cacheOptions = { endpoint, body, cached };
|
|
14
|
-
const starts = new Date();
|
|
15
|
-
|
|
16
|
-
if (cached) {
|
|
17
|
-
const cachedResponse = getCache(cacheOptions);
|
|
18
|
-
console.log(`API CALL CACHED: GET ${endpoint} ${new Date() - starts} ms`);
|
|
19
|
-
|
|
20
|
-
if (cachedResponse) return cachedResponse;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
try {
|
|
24
|
-
const { data } = await axios({
|
|
25
|
-
url: endpoint,
|
|
26
|
-
method: 'get',
|
|
27
|
-
headers: { ...auth.headers },
|
|
28
|
-
data: body,
|
|
29
|
-
});
|
|
30
|
-
console.log(`API CALL ENDS: GET ${endpoint} ${new Date() - starts} ms`);
|
|
31
|
-
saveCache(cacheOptions, data);
|
|
32
|
-
|
|
33
|
-
return data;
|
|
34
|
-
} catch (e) {
|
|
35
|
-
showApiError(e, { endpoint, body, attempt }, e.response.status !== 404);
|
|
36
|
-
|
|
37
|
-
if (e.response.status === 404) return null;
|
|
38
|
-
|
|
39
|
-
if (attempt < parseInt(RETRY_ATTEMPTS)) {
|
|
40
|
-
console.log('WAITING FOR RETRY: GET', endpoint);
|
|
41
|
-
await delay(parseInt(RETRY_WAIT_SECONDS) * 1000);
|
|
42
|
-
|
|
43
|
-
return getApi(endpoint, body, cached, attempt + 1);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
const putApi = async (endpoint, body, cached = false, attempt = 0) => {
|
|
49
|
-
const cacheOptions = { endpoint, body, cached };
|
|
50
|
-
const starts = new Date();
|
|
51
|
-
|
|
52
|
-
if (cached) {
|
|
53
|
-
const cachedResponse = getCache(cacheOptions);
|
|
54
|
-
console.log(`API CALL CACHED: PUT ${endpoint} ${new Date() - starts} ms`);
|
|
55
|
-
|
|
56
|
-
if (cachedResponse) return cachedResponse;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
try {
|
|
60
|
-
const { data } = await axios({
|
|
61
|
-
url: endpoint,
|
|
62
|
-
method: 'put',
|
|
63
|
-
headers: { ...auth.headers },
|
|
64
|
-
data: body,
|
|
65
|
-
});
|
|
66
|
-
console.log(`API CALL ENDS: PUT ${endpoint} ${new Date() - starts} ms`);
|
|
67
|
-
saveCache(cacheOptions, data);
|
|
68
|
-
|
|
69
|
-
return data;
|
|
70
|
-
} catch (e) {
|
|
71
|
-
showApiError(e, { endpoint, body, attempt }, e.response.status !== 404);
|
|
72
|
-
|
|
73
|
-
if (e.response.status === 404) return null;
|
|
74
|
-
|
|
75
|
-
if (attempt < parseInt(RETRY_ATTEMPTS)) {
|
|
76
|
-
console.log('WAITING FOR RETRY: PUT', endpoint);
|
|
77
|
-
await delay(parseInt(RETRY_WAIT_SECONDS) * 1000);
|
|
78
|
-
|
|
79
|
-
return putApi(endpoint, body, cached, attempt + 1);
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
const postApi = async (endpoint, body, headers, cached, attempt = 0) => {
|
|
85
|
-
const cacheOptions = { endpoint, body, headers, cached };
|
|
86
|
-
const starts = new Date();
|
|
87
|
-
const distributorBodyParams = endpoint.endsWith('/distributor')
|
|
88
|
-
? `# Distributor body: ${JSON.stringify(body)} - lang: ${JSON.stringify(
|
|
89
|
-
headers?.lang
|
|
90
|
-
)}`
|
|
91
|
-
: '';
|
|
92
|
-
|
|
93
|
-
if (cached) {
|
|
94
|
-
const cachedResponse = getCache(cacheOptions);
|
|
95
|
-
|
|
96
|
-
console.log(
|
|
97
|
-
`API CALL CACHED: POST ${endpoint} ${
|
|
98
|
-
new Date() - starts
|
|
99
|
-
} ms ${distributorBodyParams}`
|
|
100
|
-
);
|
|
101
|
-
|
|
102
|
-
if (cachedResponse) return cachedResponse;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
try {
|
|
106
|
-
const { data } = await axios({
|
|
107
|
-
url: endpoint,
|
|
108
|
-
method: 'post',
|
|
109
|
-
headers: { ...headers, ...auth.headers },
|
|
110
|
-
data: body,
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
console.log(
|
|
114
|
-
`API CALL ENDS: POST ${endpoint} ${
|
|
115
|
-
new Date() - starts
|
|
116
|
-
} ms ${distributorBodyParams}`
|
|
117
|
-
);
|
|
118
|
-
saveCache(cacheOptions, data);
|
|
119
|
-
|
|
120
|
-
return data;
|
|
121
|
-
} catch (e) {
|
|
122
|
-
showApiError(e, { endpoint, body, attempt }, e.response.status !== 404);
|
|
123
|
-
|
|
124
|
-
if (e.response.status === 404) return null;
|
|
125
|
-
|
|
126
|
-
if (attempt < parseInt(RETRY_ATTEMPTS)) {
|
|
127
|
-
console.log('WAITING FOR RETRY: POST', endpoint);
|
|
128
|
-
await delay(parseInt(RETRY_WAIT_SECONDS) * 1000);
|
|
129
|
-
|
|
130
|
-
return postApi(endpoint, body, headers, cached, attempt + 1);
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
};
|
|
134
|
-
|
|
135
|
-
const showApiError = (e, callInfo = {}, breakProcess = true) => {
|
|
136
|
-
const { response, message, stack } = e;
|
|
137
|
-
const { status, statusText, data } = response || {};
|
|
138
|
-
const callInfoArray = [];
|
|
139
|
-
|
|
140
|
-
for (const item of Object.keys(callInfo)) {
|
|
141
|
-
callInfoArray.push(
|
|
142
|
-
`- ${item}: ${
|
|
143
|
-
typeof callInfo[item] === 'object'
|
|
144
|
-
? JSON.stringify(callInfo[item])
|
|
145
|
-
: callInfo[item]
|
|
146
|
-
}`
|
|
147
|
-
);
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
console.error(
|
|
151
|
-
`===========================\n*** CALL INFO ***\n${callInfoArray.join(
|
|
152
|
-
'\n'
|
|
153
|
-
)}\n\n${
|
|
154
|
-
response
|
|
155
|
-
? `*** API RESPONSE ***\nCode: ${status} - ${statusText}\nResponse: ${JSON.stringify(
|
|
156
|
-
data
|
|
157
|
-
)}\n\n`
|
|
158
|
-
: ''
|
|
159
|
-
}*** ERROR DETAILS***\n${message}\n${stack}\n===========================`
|
|
160
|
-
);
|
|
161
|
-
|
|
162
|
-
if (
|
|
163
|
-
breakProcess &&
|
|
164
|
-
(typeof callInfo?.attempt !== 'number' ||
|
|
165
|
-
callInfo.attempt >= parseInt(RETRY_ATTEMPTS))
|
|
166
|
-
)
|
|
167
|
-
process.exit(1);
|
|
168
|
-
};
|
|
169
|
-
|
|
170
|
-
exports.get = getApi;
|
|
171
|
-
exports.put = putApi;
|
|
172
|
-
exports.post = postApi;
|