@griddo/cx 11.2.8 → 11.2.9

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.
@@ -86,8 +86,6 @@ declare function pause(title: string): Promise<void> | undefined;
86
86
  * @param name - The name of the life cycle.
87
87
  * @param options - The arguments object.
88
88
  * @param options.steps - An array of functions to execute.
89
- * @param options.delay - Delay between steps functions.
90
- * @param options.bypass - Skip the step functions.
91
89
  * @returns - A promise that resolves when the life cycle process is completed.
92
90
  */
93
91
  declare function doLifeCycle(name: LifeCyclesNames, steps: LifeCycleSteps): Promise<void>;
@@ -5,7 +5,7 @@ import { type MakeDirectoryOptions } from "fs-extra";
5
5
  *
6
6
  * @param baseDir - The base directory.
7
7
  */
8
- declare const clearEmptyDirs: (baseDir: string) => void;
8
+ declare function deleteDisposableSiteDirs(): void;
9
9
  /**
10
10
  * Creates multiple directories.
11
11
  *
@@ -49,11 +49,5 @@ declare function removeArtifacts(artifacts: Array<string>): void;
49
49
  * La solución por ahora es borrarlas del store y rehacerlas en todos los renders.
50
50
  */
51
51
  declare function removeVirtualPagesFromStore(): Promise<void>;
52
- /**
53
- * Remove every .xml file in the directories in a recursive way
54
- * @param initialFolder - The initial folder to start the searching...
55
- * @deprecated - This funcion is deprecated.
56
- */
57
- declare function clearSitemapsFromDirs(initialFolder: string): void;
58
52
  declare function prependFileSync(filePath: string, content: string): void;
59
- export { clearEmptyDirs, clearSitemapsFromDirs, copyArtifacts, createArtifacts, moveArtifacts, prependFileSync, removeArtifacts, removeVirtualPagesFromStore, renameArtifact, };
53
+ export { copyArtifacts, createArtifacts, deleteDisposableSiteDirs, moveArtifacts, prependFileSync, removeArtifacts, removeVirtualPagesFromStore, renameArtifact, };
@@ -5,11 +5,9 @@
5
5
  */
6
6
  declare function createSentinelRenderFile(): void;
7
7
  declare function deleteSentinelRenderFile(): void;
8
- declare function isValidRenderProcessOrThrow(): void;
9
- declare function initRender(): void;
10
- declare function finishRender(): undefined;
8
+ declare function isValidRender(): void;
11
9
  /**
12
10
  * Send the default registers through Griddo alerts.
13
11
  */
14
12
  declare function sendGriddoDefaultAlerts(): void;
15
- export { createSentinelRenderFile, deleteSentinelRenderFile, finishRender, initRender, isValidRenderProcessOrThrow, sendGriddoDefaultAlerts };
13
+ export { createSentinelRenderFile, deleteSentinelRenderFile, isValidRender, sendGriddoDefaultAlerts, };
@@ -30,10 +30,6 @@ declare function getBuildPagesPath(): string[];
30
30
  * Get the build metadata from the Store.
31
31
  */
32
32
  declare function getBuildMetadata(): Promise<BuildMetaData>;
33
- /**
34
- * Creates an `store` dir to store pages transformed by createStore
35
- */
36
- declare function createStoreDir(): void;
37
33
  /**
38
34
  * Write render info into a file.
39
35
  * @param renderInfo - Data that will be saved related to the render process.
@@ -54,61 +50,32 @@ declare function getPageInStoreDir(basePath: string): Array<number>;
54
50
  * Save the pages into the file system.
55
51
  * @param pages - An array of Griddo page objects to be saved.
56
52
  */
57
- declare function savePagesInStore(siteFolderName: string, pages: Array<GriddoPageObject>): void;
58
- /**
59
- * Remove files from dir.
60
- * @param filenames - An array of ids representing file page names.
61
- */
62
- declare function removeSitePagesFromStore(siteDirName: string, filenames: Array<number>): void;
63
- /**
64
- * Returns pages that need to be created or deleted for a site in the store based on the provided arguments.
65
- * @param sitePages - Properties for page retrieval.
66
- * @param props.storeDir - Absolute path of the Griddo store.
67
- * @param props.pages - Exhaustive array of all pages in the site.
68
- * @param props.validPagesIds - Array of valid pages in the site.
69
- * @param props.changedPages - Array of pages that have been modified in the site.
70
- * @returns - An object containing the pages to be created and deleted in the site.
71
- */
72
- declare function getSitePagesToCreateOrDelete(sitePages: {
73
- sitesToPublish: Array<Site>;
74
- validPagesIds: Array<number>;
75
- changedPages: Array<number>;
76
- siteDirName: string;
77
- }): Promise<{
78
- pagesInStore: number[];
79
- pagesMissingInStore: number[];
80
- pagesToDeleteFromStore: number[];
81
- pagesToWriteToStore: number[];
82
- }>;
83
- /**
84
- * Returns pages that need to be created or deleted for a site in the store based on the provided arguments.
85
- * @param sitePages - Properties for page retrieval.
86
- * @param props.storeDir - Absolute path of the Griddo store.
87
- * @param props.pages - Exhaustive array of all pages in the site.
88
- * @param props.validPagesIds - Array of valid pages in the site.
89
- * @param props.changedPages - Array of pages that have been modified in the site.
90
- * @returns - An object containing the pages to be created and deleted in the site.
91
- */
92
- declare function getSitePagesToCreateOrDeleteCached(sitePages: {
93
- sitesToPublish: Array<Site>;
94
- validPagesIds: Array<number>;
95
- changedPages: Array<number>;
96
- siteDirName: string;
97
- domain: string;
98
- }): Promise<{
99
- pagesInStore: number[];
100
- pagesMissingInStore: number[];
101
- pagesToDeleteFromStore: number[];
102
- pagesToWriteToStore: number[];
103
- }>;
53
+ declare function saveSitePagesInStore(siteDirName: string, pages: Array<GriddoPageObject>): void;
104
54
  /**
105
- * Removes sites from store that are not in `sitesToPublish` array.
55
+ * Removes JSON files from the specified site directory based on the provided arrays of page numbers.
56
+ * For each number in the arrays, a corresponding file with the format `<number>.json` is removed if it exists.
57
+ *
58
+ * WARNING: This function may end up handling large arrays, so don't be tempted
59
+ * to refactor it to use something cool like the spread operator and make a
60
+ * single array, etc..
61
+ *
62
+ * @param siteDirName - The name of the site directory containing the pages.
63
+ * @param pageIdsArray - A two-dimensional array where each inner array contains numbers representing page files to be removed.
106
64
  */
107
- declare function deleteZombieSitesFoldersFromStore(sitesToPublish: Array<Site>): void;
65
+ declare function removeSitePagesFromStore(siteDirName: string, pageIdsArray: Array<Array<number>>): void;
108
66
  /**
109
67
  * Removes sites that exist in the store that should no longer be there because
110
68
  * the domain has been changed. This is necessary because those sites will not
111
69
  * be marked as `sitesToUnpublish` so they must be removed manually.
112
70
  */
113
71
  declare function removeOrphanSites(sitesToPublish: Array<Site>, domain: string): void;
114
- export { createStoreDir, deleteZombieSitesFoldersFromStore, getBuildMetadata, getBuildPagesFromCachedStore, getBuildPagesFromStore, getBuildPagesPath, getPageInStoreDir, getSitePagesToCreateOrDelete, getSitePagesToCreateOrDeleteCached, removeOrphanSites, removeSitePagesFromStore, savePagesInStore, saveRenderInfoInStore, };
72
+ /**
73
+ * Returns the list of `activePages` pages that do not currently exist in a
74
+ * site's store (probably due to a failed render).
75
+ */
76
+ declare function getMissingPublishedPagesInStore(siteName: string, activePages: Array<number>): number[];
77
+ /**
78
+ * Get pages that are not active anymore but are in the store.
79
+ */
80
+ declare function getZombiePagesInStore(siteDir: string, pages: Array<number>): number[];
81
+ export { getBuildMetadata, getBuildPagesFromCachedStore, getBuildPagesFromStore, getBuildPagesPath, getMissingPublishedPagesInStore, getPageInStoreDir, getZombiePagesInStore, removeOrphanSites, removeSitePagesFromStore, saveSitePagesInStore, saveRenderInfoInStore, };
@@ -21,9 +21,9 @@ import {
21
21
  } from "../../utils/core-utils";
22
22
  import { createDomainRenderData } from "../../utils/create-build-data";
23
23
  import {
24
- clearEmptyDirs,
25
24
  copyArtifacts,
26
25
  createArtifacts,
26
+ deleteDisposableSiteDirs,
27
27
  moveArtifacts,
28
28
  removeArtifacts,
29
29
  removeVirtualPagesFromStore,
@@ -33,7 +33,7 @@ import { infoLog } from "../../utils/loggin";
33
33
  import {
34
34
  createSentinelRenderFile,
35
35
  deleteSentinelRenderFile,
36
- isValidRenderProcessOrThrow,
36
+ isValidRender,
37
37
  } from "../../utils/render";
38
38
 
39
39
  /**
@@ -135,7 +135,7 @@ export async function renderDomainsWithGatsbyAdapter(domain: string) {
135
135
  name: "Archive",
136
136
  steps: [
137
137
  () => removeVirtualPagesFromStore(),
138
- () => clearEmptyDirs(path.join(__cx, "dist")),
138
+ () => deleteDisposableSiteDirs(),
139
139
  () =>
140
140
  moveArtifacts(__cx, __exports, cxArtifacts.archivables, {
141
141
  withBackup: true,
@@ -146,16 +146,13 @@ export async function renderDomainsWithGatsbyAdapter(domain: string) {
146
146
  },
147
147
 
148
148
  {
149
- name: "Clean",
149
+ name: "Close",
150
150
  steps: [() => removeArtifacts(disposableArtifacts)],
151
151
  },
152
152
 
153
153
  {
154
154
  name: "HealthCheck",
155
- steps: [
156
- () => isValidRenderProcessOrThrow(),
157
- () => deleteSentinelRenderFile(),
158
- ],
155
+ steps: [() => isValidRender(), () => deleteSentinelRenderFile()],
159
156
  },
160
157
  ];
161
158
 
@@ -112,18 +112,18 @@ const envs = {
112
112
  };
113
113
 
114
114
  const lifeCycleNames: Record<LifeCyclesNames, LifeCyclesNames> = {
115
- Init: "Init",
116
- HealthCheck: "HealthCheck",
117
115
  __DEBUG__: "__DEBUG__",
116
+ Archive: "Archive",
118
117
  Clean: "Clean",
119
118
  Close: "Close",
119
+ Data: "Data",
120
+ HealthCheck: "HealthCheck",
121
+ Init: "Init",
122
+ Meta: "Meta",
120
123
  Prepare: "Prepare",
124
+ Relocation: "Relocation",
121
125
  Restore: "Restore",
122
- Data: "Data",
123
126
  SSG: "SSG",
124
- Relocation: "Relocation",
125
- Meta: "Meta",
126
- Archive: "Archive",
127
127
  } as const;
128
128
 
129
129
  export { endpoints, envs, lifeCycleNames };
@@ -19,8 +19,10 @@ import { get, post } from "../utils/api";
19
19
  /**
20
20
  * Get a list of site objects.
21
21
  */
22
- async function getAllSites() {
23
- return await get<AllSitesReponse>({ endpoint: endpoints.GET_ALL });
22
+ async function getAllSites(domain: string) {
23
+ return await get<AllSitesReponse>({
24
+ endpoint: `${endpoints.GET_ALL}?domainSlug=${domain}`,
25
+ });
24
26
  }
25
27
 
26
28
  /**
@@ -18,8 +18,8 @@ import { getReferenceFieldData } from "./reference-fields";
18
18
  import { getAllSettings } from "./settings";
19
19
  import { getPage } from "./sites";
20
20
  import { updatedSiteHash } from "../utils/cache";
21
- import { getConfig } from "../utils/core-utils";
22
- import { buildLog, listSitesLog, verboseLog } from "../utils/loggin";
21
+ import { getConfig, removeAllSiteDirsFromStore } from "../utils/core-utils";
22
+ import { buildLog, listSitesLog } from "../utils/loggin";
23
23
  import {
24
24
  createGriddoListPages,
25
25
  createGriddoMultiPages,
@@ -29,36 +29,27 @@ import {
29
29
  } from "../utils/pages";
30
30
  import { getSiteData, getSitesToRender, unpublishSites } from "../utils/sites";
31
31
  import {
32
- createStoreDir,
32
+ getMissingPublishedPagesInStore,
33
+ getZombiePagesInStore,
33
34
  removeOrphanSites,
34
- savePagesInStore,
35
- saveRenderInfoInStore,
36
- } from "../utils/store";
37
- import {
38
- deleteZombieSitesFoldersFromStore,
39
- getSitePagesToCreateOrDelete,
40
35
  removeSitePagesFromStore,
36
+ saveRenderInfoInStore,
37
+ saveSitePagesInStore,
41
38
  } from "../utils/store";
42
39
 
43
- const config = getConfig();
44
-
45
- // Envs
46
- const RENDER_ID = new Date().valueOf().toString();
40
+ const renderId = new Date().valueOf().toString();
41
+ const { griddoVersion, paths } = getConfig();
42
+ const { __cx } = paths();
43
+ const storeDir = path.join(__cx, "store");
47
44
 
48
45
  /**
49
46
  * Fetch, process and save object pages and sites data into the file system to
50
47
  * be consumed by other services (Griddo itself, Adapters, etc.)
51
48
  */
52
49
  async function createStore(domain: string) {
53
- createStoreDir();
54
-
55
50
  console.info(`API calls with ${envs.GRIDDO_API_CONCURRENCY_COUNT} threads`);
56
51
  console.info(`API URL ${envs.GRIDDO_API_URL as string}`);
57
52
 
58
- const { __cx } = config.paths();
59
- const { griddoVersion } = config;
60
- const storeDir = path.join(__cx, "store");
61
-
62
53
  try {
63
54
  // Vars to save later in the report file
64
55
  const createdPages: Array<number> = [];
@@ -67,6 +58,13 @@ async function createStore(domain: string) {
67
58
  // Get sites objects to publish and unpublish from this domain
68
59
  const { sitesToPublish, sitesToUnpublish } = await getSitesToRender(domain);
69
60
 
61
+ const domainHasSites =
62
+ sitesToPublish.length > 0 || sitesToUnpublish.length > 0;
63
+
64
+ if (!domainHasSites) {
65
+ console.warn(`There are no sites to update in the domain ${domain}`);
66
+ }
67
+
70
68
  listSitesLog("Sites to publish:", sitesToPublish);
71
69
  listSitesLog("Sites to unpublish:", sitesToUnpublish);
72
70
 
@@ -83,11 +81,11 @@ async function createStore(domain: string) {
83
81
 
84
82
  // Solo los sites to publish...
85
83
  for (const site of sitesToPublish) {
86
- const { id: siteId, slug: siteSlug, theme, favicon, changedPages = [] } = site;
84
+ const { id: siteId, slug: siteSlug, theme, favicon, pagesStatus } = site;
85
+ const siteDirName = siteId.toString();
87
86
 
88
87
  const {
89
88
  siteInfo,
90
- validPagesIds,
91
89
  siteHash,
92
90
  unpublishHashes,
93
91
  siteLangs,
@@ -156,7 +154,7 @@ async function createStore(domain: string) {
156
154
  buildLog(`${site.name} site`);
157
155
 
158
156
  /// Creates the store directory for each site using the id
159
- fs.mkdirSync(path.join(storeDir, siteId.toString()), {
157
+ fs.mkdirSync(path.join(storeDir, siteDirName), {
160
158
  recursive: true,
161
159
  });
162
160
 
@@ -165,7 +163,10 @@ async function createStore(domain: string) {
165
163
  // -------------------------------------------------------------------------
166
164
  // Async function that process every page for one site to use later in the
167
165
  // `Promise.all` with pLimit.
168
- const fetchSitePageAndSaveInStore = async (siteIdName: string, pageId: number) => {
166
+ const fetchSitePageAndSaveInStore = async (
167
+ siteIdName: string,
168
+ pageId: number,
169
+ ) => {
169
170
  // Here will be store every page returned by the API and processed
170
171
  let griddoPageObjects: Array<GriddoPageObject> = [];
171
172
 
@@ -184,7 +185,9 @@ async function createStore(domain: string) {
184
185
  // SHAME: This new pageAdditionalInfo needs to be a copy because
185
186
  // additionalInfo referenced from outside this function and
186
187
  // its used by other pages.
187
- const pageAdditionalInfo = JSON.parse(JSON.stringify(additionalInfo)) as PageAdditionalInfo;
188
+ const pageAdditionalInfo = JSON.parse(
189
+ JSON.stringify(additionalInfo),
190
+ ) as PageAdditionalInfo;
188
191
 
189
192
  // Updated with navigations (header & footer)
190
193
  pageAdditionalInfo.navigations = NavService.getPageNavigations(page);
@@ -196,7 +199,7 @@ async function createStore(domain: string) {
196
199
  // fetch for the data.
197
200
  const template = await getReferenceFieldData({
198
201
  page,
199
- cacheKey: RENDER_ID,
202
+ cacheKey: renderId,
200
203
  });
201
204
 
202
205
  // MultiPage Query
@@ -214,7 +217,8 @@ async function createStore(domain: string) {
214
217
  // - Single: just one page
215
218
 
216
219
  // Griddo page types
217
- const isStaticListPage = page?.mode === "list" || page?.mode === "paginated-data";
220
+ const isStaticListPage =
221
+ page?.mode === "list" || page?.mode === "paginated-data";
218
222
  const isMultiPage = !isStaticListPage && multiPageElements;
219
223
  const isSinglePage = !isMultiPage && !isStaticListPage;
220
224
 
@@ -230,7 +234,10 @@ async function createStore(domain: string) {
230
234
  } as GriddoListPage;
231
235
 
232
236
  // pageObjects = await createGriddoListPages({ adapter: "Gatsby" })
233
- griddoPageObjects = await createGriddoListPages(griddoListPage, pageAdditionalInfo);
237
+ griddoPageObjects = await createGriddoListPages(
238
+ griddoListPage,
239
+ pageAdditionalInfo,
240
+ );
234
241
  }
235
242
 
236
243
  // >> Multi-page <<
@@ -242,7 +249,10 @@ async function createStore(domain: string) {
242
249
  griddoMultipage.multiPageElements = multiPageElements;
243
250
  griddoMultipage.defaultLang = defaultLang;
244
251
 
245
- griddoPageObjects = await createGriddoMultiPages(griddoMultipage, pageAdditionalInfo);
252
+ griddoPageObjects = await createGriddoMultiPages(
253
+ griddoMultipage,
254
+ pageAdditionalInfo,
255
+ );
246
256
  }
247
257
 
248
258
  // >> Single template <<
@@ -253,7 +263,9 @@ async function createStore(domain: string) {
253
263
  griddoSinglePage.template = template;
254
264
  griddoSinglePage.defaultLang = defaultLang;
255
265
 
256
- griddoPageObjects = [await createGriddoSinglePage(griddoSinglePage, pageAdditionalInfo)];
266
+ griddoPageObjects = [
267
+ await createGriddoSinglePage(griddoSinglePage, pageAdditionalInfo),
268
+ ];
257
269
  }
258
270
 
259
271
  // Upload only the valid pages hashes or ids of pages that has
@@ -264,49 +276,80 @@ async function createStore(domain: string) {
264
276
  }
265
277
 
266
278
  // Save build data to store
267
- savePagesInStore(siteIdName, griddoPageObjects);
279
+ saveSitePagesInStore(siteIdName, griddoPageObjects);
268
280
  };
269
281
 
270
- // Pages to be created or deleted in the store
271
- const { pagesMissingInStore, pagesToDeleteFromStore, pagesToWriteToStore } =
272
- await getSitePagesToCreateOrDelete({
273
- sitesToPublish,
274
- validPagesIds,
275
- changedPages,
276
- siteDirName: siteId.toString(),
277
- });
278
-
279
- // 1 - Delete pages from the store (just remove from disk)
280
- removeSitePagesFromStore(siteId.toString(), pagesToDeleteFromStore);
281
-
282
- // 2 - Create pages to the store (fetch from API, transform, etc..)
282
+ // Pages that needs to be fetched from the API and written to the
283
+ // store.
284
+ const pagesToFetchFromAPI = [
285
+ // These pages are news or has been updated.
286
+ ...pagesStatus.uploadPending,
287
+ // You should take into account the pages that, even though they are
288
+ // already published and therefore should be avoided from requesting
289
+ // them to the API, are not in the store, probably due to a failed
290
+ // render. In that case, you have to request them again from the API
291
+ // to include them in the store.
292
+ ...getMissingPublishedPagesInStore(siteDirName, pagesStatus.active),
293
+ ];
294
+
295
+ // Create pages to the store. First requesting from API,
296
+ // transform, etc., and then writing them to disk.
283
297
  const limit = pLimit(envs.GRIDDO_API_CONCURRENCY_COUNT);
284
- const pagesToStore = pagesToWriteToStore.map((id: number) =>
285
- limit(() => fetchSitePageAndSaveInStore(siteId.toString(), id)),
298
+ const pagesToStore = pagesToFetchFromAPI.map((id: number) =>
299
+ limit(() => fetchSitePageAndSaveInStore(siteDirName, id)),
286
300
  );
287
301
 
288
- // Debug time
289
- verboseLog(`Store site: ${site.name}`);
290
- verboseLog(`${validPagesIds.length} valid pages from API`);
291
- verboseLog(`changed ${changedPages.length} pages from API`);
292
- verboseLog(`deleted ${pagesToDeleteFromStore.length} pages from store`);
293
- verboseLog(`missing ${pagesMissingInStore.length} pages in store`);
294
- verboseLog(`write ${pagesToWriteToStore.length} pages to store`);
295
-
296
302
  await Promise.all(pagesToStore);
303
+
304
+ // @ts-expect-error Mutate pagesStatus for reading pourposes.
305
+ pagesStatus.zombie = getZombiePagesInStore(siteDirName, [
306
+ ...pagesStatus.active,
307
+ ...pagesStatus.uploadPending,
308
+ ]);
309
+
310
+ // Delete pages from the store removing them from disk.
311
+ removeSitePagesFromStore(siteDirName, [
312
+ pagesStatus.deleted,
313
+ pagesStatus.offline,
314
+ pagesStatus.offlinePending,
315
+ // @ts-expect-error Mutate pagesStatus for reading pourposes.
316
+ pagesStatus.zombie,
317
+ ]);
297
318
  }
298
319
 
299
- // Remove zombie sites from store
300
- deleteZombieSitesFoldersFromStore(sitesToPublish);
301
-
302
- // Después de renderizar todos los sites y sus páginas (las que sean que
303
- // hayan cambiado etc.) guardamos un archivo con la información del
304
- // render para usos posteriores.
305
- saveRenderInfoInStore({
306
- buildProcessData,
307
- createdPages,
308
- sitesToPublish,
309
- });
320
+ // Después de guardar en el store todos los sites y sus páginas (las que
321
+ // sean que hayan cambiado etc.) guardamos un archivo con la información
322
+ // del render para usos posteriores.
323
+
324
+ // Tenemos dos casos:
325
+
326
+ // ( 1 ) - Render de dominios con sites para publicar o despublicar. Se
327
+ // guarda la infor del render normalmente.
328
+
329
+ // ( 2 ) - Render de un dominio que no tiene sites ni para publicar ni para
330
+ // despublicar, lo que llamamos un dominio "vacío".
331
+ // Entonces se eliminan las páginas "huérfanas" de la carpeta `store`
332
+ // así el proceso de SSG se encontrará efectivamente con un dominio "sin
333
+ // páginas" y "borrará" lo que exista en ese momento en el store para
334
+ // ese dominio y se guarda la información del render con arrays vacíos
335
+ // directamente en `createdPages` y `sitesToPublish`.
336
+
337
+ if (domainHasSites) {
338
+ // ( 1 )
339
+ saveRenderInfoInStore({
340
+ buildProcessData,
341
+ createdPages,
342
+ sitesToPublish,
343
+ });
344
+ } else {
345
+ // ( 2 )
346
+ removeAllSiteDirsFromStore();
347
+ saveRenderInfoInStore({
348
+ buildProcessData,
349
+ createdPages: [],
350
+ sitesToPublish: [],
351
+ });
352
+ }
310
353
  } catch (e) {
311
354
  const error = e as { message: string };
312
355
  console.error(error.message);
@@ -51,6 +51,13 @@ export interface Site
51
51
  siteScript: string;
52
52
  smallAvatar: string;
53
53
  updated: boolean;
54
+ pagesStatus: {
55
+ active: Array<number>;
56
+ uploadPending: Array<number>;
57
+ offlinePending: Array<number>;
58
+ offline: Array<number>;
59
+ deleted: Array<number>;
60
+ };
54
61
  }
55
62
 
56
63
  export interface SiteData {
@@ -304,8 +304,6 @@ function pause(title: string) {
304
304
  * @param name - The name of the life cycle.
305
305
  * @param options - The arguments object.
306
306
  * @param options.steps - An array of functions to execute.
307
- * @param options.delay - Delay between steps functions.
308
- * @param options.bypass - Skip the step functions.
309
307
  * @returns - A promise that resolves when the life cycle process is completed.
310
308
  */
311
309
  async function doLifeCycle(name: LifeCyclesNames, steps: LifeCycleSteps) {
@@ -16,53 +16,25 @@ const config = getConfig();
16
16
  *
17
17
  * @param baseDir - The base directory.
18
18
  */
19
- const clearEmptyDirs = (baseDir: string) => {
20
- const isDir = fsx.statSync(baseDir).isDirectory();
21
- if (!isDir) {
19
+ function deleteDisposableSiteDirs() {
20
+ const { __cx } = config.paths();
21
+ const baseDir = path.join(__cx, "dist");
22
+
23
+ if (!fs.existsSync(baseDir)) {
22
24
  return;
23
25
  }
24
26
 
25
- // archivos o direvtorios dentro de `dir`
26
- let children = fsx.readdirSync(baseDir);
27
- // let children = childrenRaw.filter((file) => {
28
- // return path.extname(file).toLowerCase() !== ".xml";
29
- // });
30
- const dirHasChildren = children.length > 0;
31
-
32
- // Por cada uno de ellos miramos si tiene hijos, enviamos cada uno de ellos
33
- // a `clearEmptyDirsWithXML`
34
- if (dirHasChildren) {
35
- const childrenCount = children.length;
36
- const xmlCount = children.filter((file) => {
37
- return path.extname(file).toLowerCase() === ".xml";
38
- }).length;
39
-
40
- // Todos los hijos son archivos .xml
41
- // Podemos borrarlos y dejar el dir vacío.
42
- if (childrenCount === xmlCount) {
43
- for (const xmlFile of children) {
44
- const fullPath = path.join(baseDir, xmlFile);
45
- fsx.rmSync(fullPath);
46
- }
47
- children = fsx.readdirSync(baseDir);
48
- }
27
+ const sitesDirs = fs
28
+ .readdirSync(baseDir, { withFileTypes: true })
29
+ .filter((file) => file.isDirectory());
49
30
 
50
- for (const file of children) {
51
- const fullPath = path.join(baseDir, file);
52
- clearEmptyDirs(fullPath);
31
+ for (const siteDir of sitesDirs) {
32
+ const sitePath = path.join(baseDir, siteDir.name);
33
+ if (siteIsEmpty(sitePath)) {
34
+ fs.rmSync(sitePath, { recursive: true });
53
35
  }
54
-
55
- // re-evaluate files; after deleting subdir we may have parent dir
56
- // empty now...
57
- children = fsx.readdirSync(baseDir);
58
36
  }
59
-
60
- // Si no tiene hijos, lo borramos
61
- if (children.length === 0) {
62
- fsx.rmdirSync(baseDir);
63
- return;
64
- }
65
- };
37
+ }
66
38
 
67
39
  /**
68
40
  * Creates multiple directories.
@@ -307,38 +279,23 @@ async function removeVirtualPagesFromStore() {
307
279
  }
308
280
 
309
281
  /**
310
- * Remove every .xml file in the directories in a recursive way
311
- * @param initialFolder - The initial folder to start the searching...
312
- * @deprecated - This funcion is deprecated.
282
+ * Return true if the site folder is empty or only has xml files. (Recursively)
313
283
  */
314
- function clearSitemapsFromDirs(initialFolder: string) {
315
- // Recursively remove .xml files
284
+ function siteIsEmpty(sitePath: string) {
285
+ const siteFiles = fs
286
+ .readdirSync(sitePath, {
287
+ withFileTypes: true,
288
+ recursive: true,
289
+ })
290
+ .filter(
291
+ (file) => file.isFile() && !path.basename(file.name).startsWith("."),
292
+ );
316
293
 
317
- function removeXmlFiles(folder: string): void {
318
- try {
319
- // Read the content of the directory
320
- const files = fs.readdirSync(folder);
321
- // Iterate over each file/folder in the directory
322
- for (const file of files) {
323
- const fullPath = path.join(folder, file);
324
- // Check if the current path is a directory or file
325
- const stats = fs.statSync(fullPath);
326
- if (stats.isDirectory()) {
327
- // Recursively call removeXmlFiles if it's a directory
328
- removeXmlFiles(fullPath);
329
- } else if (stats.isFile() && path.extname(fullPath) === ".xml") {
330
- // Remove the file if it's an .xml file
331
- fs.unlinkSync(fullPath);
332
- }
333
- }
334
- } catch (error) {
335
- console.error(error);
336
- throw new Error(`Error processing directory: ${folder}`);
337
- }
338
- }
294
+ const xmlFiles = siteFiles.filter((file) => file.name.endsWith(".xml"));
339
295
 
340
- // Start the process from the initial folder
341
- removeXmlFiles(initialFolder);
296
+ if (siteFiles.length === xmlFiles.length) {
297
+ return true;
298
+ }
342
299
  }
343
300
 
344
301
  function prependFileSync(filePath: string, content: string) {
@@ -352,10 +309,9 @@ function prependFileSync(filePath: string, content: string) {
352
309
  }
353
310
 
354
311
  export {
355
- clearEmptyDirs,
356
- clearSitemapsFromDirs,
357
312
  copyArtifacts,
358
313
  createArtifacts,
314
+ deleteDisposableSiteDirs,
359
315
  moveArtifacts,
360
316
  prependFileSync,
361
317
  removeArtifacts,