@griddo/cx 10.4.7 → 10.4.8

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.
@@ -95,8 +95,10 @@ interface CXConfig {
95
95
  CACHE: "__cache";
96
96
  CX: "__cx";
97
97
  SSG: "__ssg";
98
+ COMPONENTS: "__components";
99
+ ROOT: "__root";
98
100
  };
99
- dirs: (domain: string) => Record<CXDir, string>;
101
+ dirs: (domain?: string) => Record<CXDir, string>;
100
102
  }
101
103
 
102
104
  export {
@@ -4,12 +4,11 @@ import type { Site } from "../types/sites";
4
4
  import { spawnSync } from "node:child_process";
5
5
  import path from "node:path";
6
6
 
7
- import fs from "fs-extra";
7
+ import fsx from "fs-extra";
8
8
 
9
9
  import { CXRootDir, instanceRootDir, logInfo } from "./shared";
10
10
  import { getPageInStoreDir, removePagesFromStore } from "./store";
11
- // eslint-disable-next-line node/no-unpublished-import
12
- import config from "../../cx.config";
11
+ import { getConfig } from "./temp-utils";
13
12
 
14
13
  export const STORE_DIR = path.resolve(__dirname, "../store/");
15
14
  export const DIST_DIR = path.resolve(__dirname, "../dist/");
@@ -45,19 +44,19 @@ async function deleteSites(updatedSites: Array<Site>, DOMAIN: string) {
45
44
  logInfo(`Page data dir ${pageDataDir}`);
46
45
 
47
46
  // delete directory recursively
48
- if (!fs.existsSync(siteDir)) continue;
47
+ if (!fsx.existsSync(siteDir)) continue;
49
48
 
50
49
  try {
51
- await fs.rm(siteDir, { recursive: true });
50
+ await fsx.rm(siteDir, { recursive: true });
52
51
  logInfo(`${siteDir} was deleted!`);
53
52
  } catch (err) {
54
53
  console.log(err);
55
54
  }
56
55
 
57
- if (!fs.existsSync(pageDataDir)) continue;
56
+ if (!fsx.existsSync(pageDataDir)) continue;
58
57
 
59
58
  try {
60
- await fs.rm(pageDataDir, { recursive: true });
59
+ await fsx.rm(pageDataDir, { recursive: true });
61
60
  console.info(`${pageDataDir} was deleted!`);
62
61
  } catch (err) {
63
62
  console.log(err);
@@ -72,13 +71,13 @@ async function deleteSites(updatedSites: Array<Site>, DOMAIN: string) {
72
71
  const clearEmptyDirs = (baseDir?: string) => {
73
72
  const dir = baseDir || path.resolve(CXRootDir, "dist");
74
73
 
75
- const isDir = fs.statSync(dir).isDirectory();
74
+ const isDir = fsx.statSync(dir).isDirectory();
76
75
  if (!isDir) {
77
76
  return;
78
77
  }
79
78
 
80
79
  // archivos o direvtorios dentro de `dir`
81
- let children = fs.readdirSync(dir);
80
+ let children = fsx.readdirSync(dir);
82
81
  // let children = childrenRaw.filter((file) => {
83
82
  // return path.extname(file).toLowerCase() !== ".xml";
84
83
  // });
@@ -97,9 +96,9 @@ const clearEmptyDirs = (baseDir?: string) => {
97
96
  if (childrenCount === xmlCount) {
98
97
  children.forEach(function (xmlFile) {
99
98
  const fullPath = path.join(dir, xmlFile);
100
- fs.rmSync(fullPath);
99
+ fsx.rmSync(fullPath);
101
100
  });
102
- children = fs.readdirSync(dir);
101
+ children = fsx.readdirSync(dir);
103
102
  }
104
103
 
105
104
  children.forEach(function (file) {
@@ -109,12 +108,12 @@ const clearEmptyDirs = (baseDir?: string) => {
109
108
 
110
109
  // re-evaluate files; after deleting subdir we may have parent dir
111
110
  // empty now...
112
- children = fs.readdirSync(dir);
111
+ children = fsx.readdirSync(dir);
113
112
  }
114
113
 
115
114
  // Si no tiene hijos, lo borramos
116
115
  if (children.length === 0) {
117
- fs.rmdirSync(dir);
116
+ fsx.rmdirSync(dir);
118
117
  return;
119
118
  }
120
119
  };
@@ -137,6 +136,7 @@ async function copyArtifacts(args: {
137
136
  }) {
138
137
  const { artifacts, domain, from, to, withBackup } = args;
139
138
 
139
+ const config = await getConfig();
140
140
  const dirs = config.dirs(domain);
141
141
 
142
142
  for (const artifact of artifacts) {
@@ -144,7 +144,7 @@ async function copyArtifacts(args: {
144
144
  const dest = path.join(dirs[to], artifact);
145
145
 
146
146
  // The dir we want to copy, doesn't exist.
147
- if (!fs.existsSync(src)) {
147
+ if (!fsx.existsSync(src)) {
148
148
  console.log(`Source directory does not exist: ${src}`);
149
149
  continue;
150
150
  }
@@ -157,7 +157,7 @@ async function copyArtifacts(args: {
157
157
  // Copy artifact
158
158
  try {
159
159
  // First clean destination
160
- if (fs.existsSync(dest)) {
160
+ if (fsx.existsSync(dest)) {
161
161
  spawnSync("rm", ["-rf", dest]);
162
162
  }
163
163
  spawnSync("cp", ["-Rp", src, dest]);
@@ -198,7 +198,7 @@ async function copyArtifacts(args: {
198
198
  * // with backup
199
199
  * moveArtifacts({domain: domain, from: "__cx", to: "__ssg", ["dist"]})
200
200
  */
201
- function moveArtifacts(args: {
201
+ async function moveArtifacts(args: {
202
202
  domain: string;
203
203
  from: CXDir;
204
204
  to: CXDir;
@@ -207,6 +207,7 @@ function moveArtifacts(args: {
207
207
  }) {
208
208
  const { artifacts, domain, from, to, withBackup } = args;
209
209
 
210
+ const config = await getConfig();
210
211
  const dirs = config.dirs(domain);
211
212
 
212
213
  for (const artifact of artifacts) {
@@ -214,7 +215,7 @@ function moveArtifacts(args: {
214
215
  const dest = path.join(dirs[to], artifact);
215
216
 
216
217
  // The dir we want to move, doesn't exist.
217
- if (!fs.existsSync(src)) {
218
+ if (!fsx.existsSync(src)) {
218
219
  console.log(`Source directory does not exist: ${src}`);
219
220
  continue;
220
221
  }
@@ -225,7 +226,7 @@ function moveArtifacts(args: {
225
226
 
226
227
  try {
227
228
  // First clean destination
228
- if (fs.existsSync(dest)) {
229
+ if (fsx.existsSync(dest)) {
229
230
  spawnSync("rm", ["-rf", dest]);
230
231
  }
231
232
  spawnSync("mv", [src, dest]);
@@ -253,19 +254,20 @@ function moveArtifacts(args: {
253
254
  * @example
254
255
  * removeArtifacts(domain, "__cx", "__ssg", ["dist"], ["public"])
255
256
  */
256
- function removeArtifacts(args: {
257
+ async function removeArtifacts(args: {
257
258
  domain: string;
258
259
  from: CXDir;
259
260
  artifacts: Array<string>;
260
261
  }) {
261
262
  const { artifacts, domain, from } = args;
262
263
 
264
+ const config = await getConfig();
263
265
  const dirs = config.dirs(domain);
264
266
 
265
267
  for (const artifact of artifacts) {
266
268
  if (artifact) {
267
269
  const src = path.join(dirs[from], artifact);
268
- if (fs.existsSync(src)) {
270
+ if (fsx.existsSync(src)) {
269
271
  spawnSync("rm", ["-rf", src]);
270
272
  }
271
273
  }
@@ -285,7 +287,7 @@ function restoreBackup(src: string, suffix = "-BACKUP") {
285
287
  function deleteBackup(src: string, suffix = "-BACKUP") {
286
288
  const dest = src + suffix;
287
289
 
288
- if (!fs.existsSync(dest)) {
290
+ if (!fsx.existsSync(dest)) {
289
291
  console.log(`Source ${dest} does not exist`);
290
292
  return;
291
293
  }
@@ -301,12 +303,12 @@ function deleteBackup(src: string, suffix = "-BACKUP") {
301
303
  function createBackup(src: string, suffix = "-BACKUP") {
302
304
  const dest = src + suffix;
303
305
 
304
- if (!fs.existsSync(src)) {
306
+ if (!fsx.existsSync(src)) {
305
307
  console.log(`Source ${src} does not exist`);
306
308
  return;
307
309
  }
308
310
 
309
- if (fs.existsSync(dest)) {
311
+ if (fsx.existsSync(dest)) {
310
312
  console.log(`Destination ${dest} already exists`);
311
313
  return;
312
314
  }
@@ -323,8 +325,9 @@ function isMultiPageId(id: number) {
323
325
  return Number.isInteger(id) && id < 0;
324
326
  }
325
327
 
326
- function removeMultiPagesFromStore() {
327
- const dirs = config.dirs("");
328
+ async function removeMultiPagesFromStore() {
329
+ const config = await getConfig();
330
+ const dirs = config.dirs();
328
331
  const storePath = path.join(dirs.__cx, "store");
329
332
  try {
330
333
  const multiPageFiles = getPageInStoreDir(storePath).filter(isMultiPageId);
@@ -0,0 +1,13 @@
1
+ async function getConfig() {
2
+ try {
3
+ // eslint-disable-next-line node/no-unpublished-import
4
+ const configModule = await import("../../cx.config");
5
+ const config = configModule.default;
6
+
7
+ return config;
8
+ } catch (error) {
9
+ process.exit(1);
10
+ }
11
+ }
12
+
13
+ export { getConfig };
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": "10.4.7",
4
+ "version": "10.4.8",
5
5
  "authors": [
6
6
  "Álvaro Sánchez' <alvaro.sanches@secuoyas.com>",
7
7
  "Diego M. Béjar <diego.bejar@secuoyas.com>",
@@ -107,5 +107,5 @@
107
107
  "publishConfig": {
108
108
  "access": "public"
109
109
  },
110
- "gitHead": "0280c78de79a2b1f534c9aaaf16e6bb72bd5b652"
110
+ "gitHead": "1390ad1d87acd73442f46bed3f505df9b6fd4adc"
111
111
  }