@griddo/cx 1.75.192 → 1.75.193
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 +27 -25
- package/gatsby-node.ts +5 -2
- package/package.json +119 -119
- package/scripts/griddo-exporter.ts +238 -206
- package/src/utils/shared.ts +22 -1
|
@@ -15,7 +15,7 @@ import pkgDir from "pkg-dir";
|
|
|
15
15
|
// Utils
|
|
16
16
|
import { initCache } from "../src/utils/cache";
|
|
17
17
|
import { findDomains } from "../src/utils/domains";
|
|
18
|
-
import { exporterLogo as splash } from "../src/utils/shared";
|
|
18
|
+
import { exporterLogo as splash, measureFunctions } from "../src/utils/shared";
|
|
19
19
|
|
|
20
20
|
// Envs
|
|
21
21
|
const artifactsArchivable = ["dist", "assets", "apiCache", ".cache"];
|
|
@@ -39,24 +39,24 @@ type Env = Record<string, unknown>;
|
|
|
39
39
|
const getEnvRunner = (env: Env) => (command: string) => runner(command, env);
|
|
40
40
|
|
|
41
41
|
const runner = (command: string, env: Env = {}) =>
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
42
|
+
// TODO: Cuando esto falle, ejecutar `cleanAfterFail`
|
|
43
|
+
execSync(command, {
|
|
44
|
+
cwd: workingPath,
|
|
45
|
+
stdio: "inherit",
|
|
46
|
+
env: {
|
|
47
|
+
...process.env,
|
|
48
|
+
...env,
|
|
49
|
+
GRIDDO_EXPORTER: "true",
|
|
50
|
+
},
|
|
51
|
+
});
|
|
52
52
|
|
|
53
53
|
const getAssetPrefix = (domain: string) => {
|
|
54
|
-
|
|
55
|
-
|
|
54
|
+
// TODO: Usar asset_prefix del dominio
|
|
55
|
+
if (!process.env.GRIDDO_ASSET_PREFIX || !domain) return "";
|
|
56
56
|
|
|
57
|
-
|
|
57
|
+
if (!domain.startsWith("pro-")) return "";
|
|
58
58
|
|
|
59
|
-
|
|
59
|
+
return `${process.env.GRIDDO_ASSET_PREFIX}/${domain}`;
|
|
60
60
|
};
|
|
61
61
|
|
|
62
62
|
// -----------------------------------------------------------------------------
|
|
@@ -71,208 +71,240 @@ const logWarning = (...message: Array<any>) => console.log(...message);
|
|
|
71
71
|
// Main Stuff
|
|
72
72
|
// -----------------------------------------------------------------------------
|
|
73
73
|
const domainExport = async (domain: string) => {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
74
|
+
const runner = getDomainRunner(domain);
|
|
75
|
+
// onPreExporter
|
|
76
|
+
const endRestore = measureFunctions(runner.init, runner.restoreArtifacts);
|
|
77
|
+
logInfo(`\n⌛️ Domain ${domain} restaured: ${endRestore}s`);
|
|
78
|
+
|
|
79
|
+
// Gatsby
|
|
80
|
+
runner.runExporter();
|
|
81
|
+
|
|
82
|
+
// onPostExporter
|
|
83
|
+
const endArchive = measureFunctions(runner.archiveArtifacts);
|
|
84
|
+
logInfo(`\n⌛️ Domain ${domain} archived: ${endArchive}s`);
|
|
79
85
|
};
|
|
80
86
|
|
|
81
87
|
const launchExports = async () => {
|
|
82
|
-
|
|
83
|
-
|
|
88
|
+
splash();
|
|
89
|
+
initCache();
|
|
84
90
|
|
|
85
|
-
|
|
91
|
+
const domains = await findDomains();
|
|
86
92
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
93
|
+
for (const domain of domains) {
|
|
94
|
+
logInfo(`️🚢 Exporting domain ${chalk.underline(domain)}`);
|
|
95
|
+
await domainExport(domain);
|
|
96
|
+
}
|
|
91
97
|
};
|
|
92
98
|
|
|
93
99
|
const getDomainRunner = (domain: string) => {
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
100
|
+
const assetPrefix = getAssetPrefix(domain);
|
|
101
|
+
|
|
102
|
+
const run = getEnvRunner({
|
|
103
|
+
DOMAIN: domain,
|
|
104
|
+
GRIDDO_ASSET_PREFIX: assetPrefix,
|
|
105
|
+
HAS_ASSET_DOMAIN: assetPrefix && assetPrefix !== "",
|
|
106
|
+
RENDERID: new Date().valueOf(),
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
const init = () => {
|
|
110
|
+
logInfo(`🚀 Initializing ${chalk.underline(domain)} exporter`);
|
|
111
|
+
|
|
112
|
+
cleanDirtyArtifactPaths();
|
|
113
|
+
createBaseExportPaths();
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
const getArtifactPaths = (artifact = "") => {
|
|
117
|
+
const domainExportArchiveBasePath = path.resolve(
|
|
118
|
+
exportArchiveBasePath,
|
|
119
|
+
domain
|
|
120
|
+
);
|
|
121
|
+
const currentExportArchivePath = path.resolve(
|
|
122
|
+
domainExportArchiveBasePath,
|
|
123
|
+
artifact
|
|
124
|
+
);
|
|
125
|
+
const currentExportBackupPath = `${currentExportArchivePath}-BACKUP`;
|
|
126
|
+
const currentExportWorkingPath = path.resolve(workingPath, artifact);
|
|
127
|
+
|
|
128
|
+
return {
|
|
129
|
+
domainExportArchiveBasePath,
|
|
130
|
+
currentExportArchivePath,
|
|
131
|
+
currentExportBackupPath,
|
|
132
|
+
currentExportWorkingPath,
|
|
133
|
+
};
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
const cleanDirtyArtifactPaths = () => {
|
|
137
|
+
for (const artifact of [...artifactsArchivable, ...artifactsDisposable]) {
|
|
138
|
+
const { currentExportWorkingPath } = getArtifactPaths(artifact);
|
|
139
|
+
|
|
140
|
+
if (fs.existsSync(currentExportWorkingPath)) {
|
|
141
|
+
logWarning(`🧹 Cleanup dirty ${chalk.gray(currentExportWorkingPath)}`);
|
|
142
|
+
run(`rm -rf ${currentExportWorkingPath}`);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
const createBaseExportPaths = () => {
|
|
148
|
+
const { domainExportArchiveBasePath } = getArtifactPaths();
|
|
149
|
+
|
|
150
|
+
if (!fs.existsSync(domainExportArchiveBasePath)) {
|
|
151
|
+
logInfo(`✨ Creating ${domainExportArchiveBasePath}`);
|
|
152
|
+
run(`mkdir -p ${domainExportArchiveBasePath}`);
|
|
153
|
+
}
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
const archiveExportArtifact = (artifact: string) => {
|
|
157
|
+
const { currentExportArchivePath, currentExportWorkingPath } =
|
|
158
|
+
getArtifactPaths(artifact);
|
|
159
|
+
|
|
160
|
+
logInfo(
|
|
161
|
+
`🚚 Moving files from ${chalk.gray(
|
|
162
|
+
currentExportWorkingPath
|
|
163
|
+
)} to ${chalk.gray(currentExportArchivePath)}`
|
|
164
|
+
);
|
|
165
|
+
run(`mv ${currentExportWorkingPath} ${currentExportArchivePath}`);
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
const archiveArtifacts = () => {
|
|
169
|
+
for (const artifact of artifactsArchivable) {
|
|
170
|
+
const { currentExportWorkingPath, currentExportArchivePath } =
|
|
171
|
+
getArtifactPaths(artifact);
|
|
172
|
+
|
|
173
|
+
if (!fs.existsSync(currentExportWorkingPath)) {
|
|
174
|
+
logError(
|
|
175
|
+
"📁 Source directory has not been created:",
|
|
176
|
+
currentExportWorkingPath
|
|
177
|
+
);
|
|
178
|
+
continue;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
try {
|
|
182
|
+
createArtifactBackup(artifact);
|
|
183
|
+
archiveExportArtifact(artifact);
|
|
184
|
+
deleteArtifactBackup(artifact);
|
|
185
|
+
} catch (error) {
|
|
186
|
+
logError(
|
|
187
|
+
`🚚 Error moving files to ${currentExportArchivePath}`,
|
|
188
|
+
error.message
|
|
189
|
+
);
|
|
190
|
+
restoreArtifactBackup(artifact);
|
|
191
|
+
continue;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
};
|
|
195
|
+
|
|
196
|
+
const restoreArtifacts = () => {
|
|
197
|
+
for (const artifact of artifactsArchivable) {
|
|
198
|
+
const { currentExportArchivePath, currentExportWorkingPath } =
|
|
199
|
+
getArtifactPaths(artifact);
|
|
200
|
+
|
|
201
|
+
if (fs.existsSync(currentExportArchivePath)) {
|
|
202
|
+
logWarning(`️♻️ Restoring ${chalk.gray(currentExportArchivePath)}`);
|
|
203
|
+
run(`cp -R ${currentExportArchivePath} ${currentExportWorkingPath}`);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
moveDistToPublic();
|
|
208
|
+
};
|
|
209
|
+
|
|
210
|
+
const createArtifactBackup = (artifact: string) => {
|
|
211
|
+
const { currentExportArchivePath, currentExportBackupPath } =
|
|
212
|
+
getArtifactPaths(artifact);
|
|
213
|
+
|
|
214
|
+
if (fs.existsSync(currentExportArchivePath)) {
|
|
215
|
+
logInfo(`💿 Creating backup of ${chalk.gray(currentExportArchivePath)}`);
|
|
216
|
+
run(`mv ${currentExportArchivePath} ${currentExportBackupPath}`);
|
|
217
|
+
}
|
|
218
|
+
};
|
|
219
|
+
|
|
220
|
+
const restoreArtifactBackup = (artifact: string) => {
|
|
221
|
+
const { currentExportArchivePath, currentExportBackupPath } =
|
|
222
|
+
getArtifactPaths(artifact);
|
|
223
|
+
|
|
224
|
+
if (fs.existsSync(currentExportBackupPath)) {
|
|
225
|
+
logWarning(
|
|
226
|
+
`️♻️ Restoring backup ${chalk.gray(currentExportArchivePath)}`
|
|
227
|
+
);
|
|
228
|
+
run(`mv ${currentExportBackupPath} ${currentExportArchivePath}`);
|
|
229
|
+
}
|
|
230
|
+
};
|
|
231
|
+
|
|
232
|
+
const deleteArtifactBackup = (artifact: string) => {
|
|
233
|
+
const { currentExportArchivePath, currentExportBackupPath } =
|
|
234
|
+
getArtifactPaths(artifact);
|
|
235
|
+
|
|
236
|
+
logWarning(`️❌ Removing backup ${chalk.gray(currentExportArchivePath)}`);
|
|
237
|
+
run(`rm -rf ${currentExportBackupPath}`);
|
|
238
|
+
};
|
|
239
|
+
|
|
240
|
+
const runExporter = () => {
|
|
241
|
+
console.log(`\n${chalk.black(chalk.bgGreen(" Gatsby (start) "))}\n`);
|
|
242
|
+
|
|
243
|
+
run("yarn export");
|
|
244
|
+
logSuccess("Your sites have been exported correctly");
|
|
245
|
+
|
|
246
|
+
console.log(`\n${chalk.black(chalk.bgGreen(" Gatsby (end) "))}\n`);
|
|
247
|
+
|
|
248
|
+
removeDisposableArtifacts();
|
|
249
|
+
};
|
|
250
|
+
|
|
251
|
+
// TODO: Hacer que infra tire de `public` en vez de `dist` y quitar esto
|
|
252
|
+
const moveDistToPublic = () => {
|
|
253
|
+
const { currentExportWorkingPath: distPath } = getArtifactPaths("dist");
|
|
254
|
+
const { currentExportWorkingPath: publicPath } = getArtifactPaths("public");
|
|
255
|
+
|
|
256
|
+
if (fs.existsSync(distPath)) {
|
|
257
|
+
logWarning(
|
|
258
|
+
`🚚 Moving ${chalk.gray(distPath)} to ${chalk.gray(publicPath)}`
|
|
259
|
+
);
|
|
260
|
+
run(`mv ${distPath} ${publicPath}`);
|
|
261
|
+
}
|
|
262
|
+
};
|
|
263
|
+
|
|
264
|
+
// TODO: Esto no debería hacerse desde infra
|
|
265
|
+
const movePublicToDist = () => {
|
|
266
|
+
const { currentExportWorkingPath: publicPath } = getArtifactPaths("public");
|
|
267
|
+
const { currentExportWorkingPath: distPath } = getArtifactPaths("dist");
|
|
268
|
+
|
|
269
|
+
if (fs.existsSync(publicPath)) {
|
|
270
|
+
logWarning(`🚚 Moving ${publicPath} to ${distPath}`);
|
|
271
|
+
run(`mv ${publicPath} ${distPath}`);
|
|
272
|
+
}
|
|
273
|
+
};
|
|
274
|
+
|
|
275
|
+
const removeDisposableArtifacts = () => {
|
|
276
|
+
for (const artifact of artifactsDisposable) {
|
|
277
|
+
const { currentExportWorkingPath: artifactPath } =
|
|
278
|
+
getArtifactPaths(artifact);
|
|
279
|
+
|
|
280
|
+
if (fs.existsSync(artifactPath)) {
|
|
281
|
+
logWarning(`❌ Removing ${chalk.gray(artifactPath)}`);
|
|
282
|
+
run(`rm -rf ${artifactPath}`);
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
};
|
|
286
|
+
|
|
287
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
288
|
+
const cleanAfterFail = () => {
|
|
289
|
+
cleanDirtyArtifactPaths();
|
|
290
|
+
};
|
|
291
|
+
|
|
292
|
+
return {
|
|
293
|
+
init,
|
|
294
|
+
getArtifactPaths,
|
|
295
|
+
archiveExportArtifact,
|
|
296
|
+
archiveArtifacts,
|
|
297
|
+
restoreArtifacts,
|
|
298
|
+
createArtifactBackup,
|
|
299
|
+
restoreArtifactBackup,
|
|
300
|
+
deleteArtifactBackup,
|
|
301
|
+
runExporter,
|
|
302
|
+
};
|
|
271
303
|
};
|
|
272
304
|
|
|
273
305
|
console.clear();
|
|
274
306
|
|
|
275
307
|
launchExports().catch((err) => {
|
|
276
|
-
|
|
277
|
-
|
|
308
|
+
console.error("❌ ERROR", err?.stdout?.toString() || err);
|
|
309
|
+
process.exit(1);
|
|
278
310
|
});
|
package/src/utils/shared.ts
CHANGED
|
@@ -111,6 +111,18 @@ export function getSafeSiteId(response: APIResponses) {
|
|
|
111
111
|
return "site" in response && response.site ? response?.site : undefined;
|
|
112
112
|
}
|
|
113
113
|
|
|
114
|
+
/**
|
|
115
|
+
* Execute functions and return time it takes for functions to execute
|
|
116
|
+
* @param funcs Array of functions
|
|
117
|
+
* @returns seconds it takes for functions to execute
|
|
118
|
+
*/
|
|
119
|
+
function measureFunctions(...funcs: Array<() => void>) {
|
|
120
|
+
const start = performance.now();
|
|
121
|
+
funcs.forEach((func) => func());
|
|
122
|
+
|
|
123
|
+
return msToSec(performance.now() - start);
|
|
124
|
+
}
|
|
125
|
+
|
|
114
126
|
/**
|
|
115
127
|
* Print a f**king great Griddo builder logo.
|
|
116
128
|
*/
|
|
@@ -152,4 +164,13 @@ function exporterLogo() {
|
|
|
152
164
|
console.log(gradient.cristal(logo));
|
|
153
165
|
}
|
|
154
166
|
|
|
155
|
-
export {
|
|
167
|
+
export {
|
|
168
|
+
delay,
|
|
169
|
+
exporterLogo,
|
|
170
|
+
logBox,
|
|
171
|
+
logInfo,
|
|
172
|
+
logPageSize,
|
|
173
|
+
measureFunctions,
|
|
174
|
+
splash,
|
|
175
|
+
walk,
|
|
176
|
+
};
|