@griddo/cx 11.9.17-rc.1 → 11.10.0
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 +13 -240
- package/build/commands/end-render.d.ts +0 -1
- package/build/commands/end-render.js +31 -0
- package/build/commands/end-render.js.map +7 -0
- package/build/commands/prepare-assets-directory.js +9 -0
- package/build/commands/prepare-assets-directory.js.map +7 -0
- package/build/commands/prepare-domains-render.js +40 -0
- package/build/commands/prepare-domains-render.js.map +7 -0
- package/build/commands/reset-render.d.ts +0 -1
- package/build/commands/reset-render.js +31 -0
- package/build/commands/reset-render.js.map +7 -0
- package/build/commands/single-domain-upload-search-content.d.ts +1 -0
- package/build/commands/start-render.d.ts +0 -1
- package/build/commands/start-render.js +66 -0
- package/build/commands/start-render.js.map +7 -0
- package/build/commands/upload-search-content.d.ts +0 -1
- package/build/commands/upload-search-content.js +32 -0
- package/build/commands/upload-search-content.js.map +7 -0
- package/build/core/GriddoLog.d.ts +16 -0
- package/build/{utils/health-checks.d.ts → core/check-env-health.d.ts} +4 -2
- package/build/core/db-class.d.ts +11 -0
- package/build/core/db.d.ts +4 -0
- package/build/core/dist-rollback.d.ts +11 -0
- package/build/core/errors.d.ts +26 -0
- package/build/core/fs.d.ts +69 -0
- package/build/core/life-cycle.d.ts +26 -0
- package/build/core/logger.d.ts +18 -0
- package/build/core/objects.d.ts +11 -0
- package/build/core/print-logos.d.ts +5 -0
- package/build/index.d.ts +10 -29
- package/build/index.js +404 -73
- package/build/react/DynamicScript/index.d.ts +4 -0
- package/build/react/GriddoFavicon/index.d.ts +4 -0
- package/build/react/GriddoIntegrations/index.d.ts +3 -4
- package/build/react/GriddoIntegrations/utils.d.ts +7 -6
- package/build/react/GriddoOpenGraph/index.d.ts +10 -0
- package/build/react/index.d.ts +3 -2
- package/build/react/index.js +1 -3
- package/build/{utils → services}/api.d.ts +1 -1
- package/build/services/auth.d.ts +2 -5
- package/build/services/domains.d.ts +3 -4
- package/build/services/manage-sites.d.ts +22 -0
- package/build/services/manage-store.d.ts +32 -0
- package/build/services/navigation.d.ts +16 -16
- package/build/{utils → services}/pages.d.ts +3 -3
- package/build/services/reference-fields.d.ts +3 -3
- package/build/services/render-artifacts.d.ts +6 -0
- package/build/services/render.d.ts +70 -0
- package/build/services/robots.d.ts +2 -19
- package/build/services/sitemaps.d.ts +5 -0
- package/build/services/sites.d.ts +8 -5
- package/build/services/store.d.ts +10 -1
- package/build/shared/context.d.ts +36 -0
- package/build/shared/envs.d.ts +17 -0
- package/build/{errors/errors-data.d.ts → shared/errors.d.ts} +5 -3
- package/build/shared/npm-modules/brush.d.ts +18 -0
- package/build/shared/npm-modules/find-up-simple.d.ts +34 -0
- package/build/shared/npm-modules/pkg-dir.d.ts +7 -0
- package/build/shared/npm-modules/xml-parser.d.ts +4 -0
- package/build/{types → shared/types}/api.d.ts +18 -18
- package/build/{types → shared/types}/global.d.ts +15 -16
- package/build/{types → shared/types}/navigation.d.ts +5 -5
- package/build/{types → shared/types}/pages.d.ts +9 -9
- package/build/shared/types/render.d.ts +56 -0
- package/build/{types → shared/types}/sites.d.ts +18 -19
- package/build/shared/types.d.ts +15 -0
- package/build/ssg-adapters/gatsby/actions/clean.d.ts +3 -0
- package/build/ssg-adapters/gatsby/actions/close.d.ts +3 -0
- package/build/ssg-adapters/gatsby/actions/data.d.ts +2 -0
- package/build/ssg-adapters/gatsby/actions/healthCheck.d.ts +2 -0
- package/build/ssg-adapters/gatsby/actions/init.d.ts +2 -0
- package/build/ssg-adapters/gatsby/actions/logs.d.ts +3 -0
- package/build/ssg-adapters/gatsby/actions/meta.d.ts +2 -0
- package/build/ssg-adapters/gatsby/actions/prepare.d.ts +2 -0
- package/build/ssg-adapters/gatsby/actions/relocation.d.ts +2 -0
- package/build/ssg-adapters/gatsby/actions/restore.d.ts +3 -0
- package/build/ssg-adapters/gatsby/actions/ssg.d.ts +3 -0
- package/build/ssg-adapters/gatsby/actions/sync.d.ts +3 -0
- package/build/ssg-adapters/gatsby/index.d.ts +9 -0
- package/build/ssg-adapters/gatsby/shared/artifacts.d.ts +4 -0
- package/build/ssg-adapters/gatsby/shared/diff-assets.d.ts +15 -0
- package/build/ssg-adapters/gatsby/shared/extract-assets.d.ts +7 -0
- package/build/ssg-adapters/gatsby/shared/gatsby-build.d.ts +7 -0
- package/build/ssg-adapters/gatsby/shared/render-rollback.d.ts +18 -0
- package/build/ssg-adapters/gatsby/shared/sync-render.d.ts +26 -0
- package/build/ssg-adapters/gatsby/shared/types.d.ts +34 -0
- package/cli.mjs +231 -0
- package/exporter/build-esbuild.noop +42 -0
- package/exporter/build.sh +16 -24
- package/exporter/commands/README.md +142 -0
- package/exporter/commands/end-render.ts +53 -87
- package/exporter/commands/prepare-assets-directory.ts +35 -0
- package/exporter/commands/prepare-domains-render.ts +150 -33
- package/exporter/commands/reset-render.ts +13 -8
- package/exporter/commands/single-domain-upload-search-content.ts +206 -0
- package/exporter/commands/start-render.ts +14 -65
- package/exporter/commands/upload-search-content.ts +204 -26
- package/exporter/core/GriddoLog.ts +45 -0
- package/exporter/core/check-env-health.ts +203 -0
- package/exporter/core/db-class.ts +54 -0
- package/exporter/core/db.ts +33 -0
- package/exporter/core/dist-rollback.ts +49 -0
- package/exporter/core/errors.ts +93 -0
- package/exporter/core/fs.ts +385 -0
- package/exporter/{utils → core}/images.ts +1 -6
- package/exporter/{utils → core}/instance.ts +9 -13
- package/exporter/core/life-cycle.ts +73 -0
- package/exporter/core/logger.ts +137 -0
- package/exporter/core/objects.ts +37 -0
- package/exporter/core/print-logos.ts +21 -0
- package/exporter/index.ts +14 -56
- package/exporter/react/DynamicScript/index.tsx +33 -0
- package/exporter/react/{Favicon → GriddoFavicon}/index.tsx +3 -9
- package/exporter/react/GriddoIntegrations/index.tsx +17 -23
- package/exporter/react/GriddoIntegrations/utils.ts +24 -12
- package/exporter/react/GriddoOpenGraph/index.tsx +39 -0
- package/exporter/react/index.tsx +3 -9
- package/exporter/services/api.ts +306 -0
- package/exporter/services/auth.ts +8 -10
- package/exporter/services/domains.ts +23 -8
- package/exporter/services/manage-sites.ts +116 -0
- package/exporter/services/manage-store.ts +173 -0
- package/exporter/services/navigation.ts +12 -18
- package/exporter/{utils → services}/pages.ts +27 -92
- package/exporter/services/reference-fields.ts +14 -32
- package/exporter/services/render-artifacts.ts +44 -0
- package/exporter/services/render.ts +229 -0
- package/exporter/services/robots.ts +33 -61
- package/exporter/services/sitemaps.ts +129 -0
- package/exporter/services/sites.ts +40 -28
- package/exporter/services/store.ts +354 -321
- package/exporter/shared/context.ts +49 -0
- package/exporter/{constants → shared}/endpoints.ts +12 -11
- package/exporter/shared/envs.ts +58 -0
- package/exporter/{errors/errors-data.ts → shared/errors.ts} +24 -14
- package/exporter/shared/npm-modules/README.md +36 -0
- package/exporter/shared/npm-modules/brush.ts +34 -0
- package/exporter/shared/npm-modules/find-up-simple.ts +100 -0
- package/exporter/shared/npm-modules/pkg-dir.ts +17 -0
- package/exporter/shared/npm-modules/xml-parser.ts +57 -0
- package/exporter/{types → shared/types}/api.ts +40 -41
- package/exporter/{types → shared/types}/global.ts +17 -21
- package/exporter/{types → shared/types}/navigation.ts +3 -3
- package/exporter/{types → shared/types}/pages.ts +10 -11
- package/exporter/shared/types/render.ts +65 -0
- package/exporter/{types → shared/types}/sites.ts +18 -19
- package/exporter/shared/types.ts +15 -0
- package/exporter/ssg-adapters/gatsby/actions/clean.ts +26 -0
- package/exporter/ssg-adapters/gatsby/actions/close.ts +17 -0
- package/exporter/ssg-adapters/gatsby/actions/data.ts +22 -0
- package/exporter/ssg-adapters/gatsby/actions/healthCheck.ts +10 -0
- package/exporter/ssg-adapters/gatsby/actions/init.ts +12 -0
- package/exporter/ssg-adapters/gatsby/actions/logs.ts +10 -0
- package/exporter/ssg-adapters/gatsby/actions/meta.ts +13 -0
- package/exporter/ssg-adapters/gatsby/actions/prepare.ts +9 -0
- package/exporter/ssg-adapters/gatsby/actions/relocation.ts +15 -0
- package/exporter/ssg-adapters/gatsby/actions/restore.ts +21 -0
- package/exporter/ssg-adapters/gatsby/actions/ssg.ts +12 -0
- package/exporter/ssg-adapters/gatsby/actions/sync.ts +65 -0
- package/exporter/ssg-adapters/gatsby/index.ts +117 -0
- package/exporter/ssg-adapters/gatsby/shared/artifacts.ts +17 -0
- package/exporter/ssg-adapters/gatsby/shared/diff-assets.ts +128 -0
- package/exporter/ssg-adapters/gatsby/shared/extract-assets.ts +75 -0
- package/exporter/ssg-adapters/gatsby/shared/gatsby-build.ts +58 -0
- package/exporter/ssg-adapters/gatsby/shared/render-rollback.ts +33 -0
- package/exporter/ssg-adapters/gatsby/shared/sync-render.ts +298 -0
- package/exporter/ssg-adapters/gatsby/shared/types.ts +35 -0
- package/gatsby-browser.tsx +41 -58
- package/gatsby-config.ts +10 -17
- package/gatsby-node.ts +20 -79
- package/gatsby-ssr.tsx +2 -1
- package/package.json +41 -78
- package/plugins/gatsby-plugin-svgr-loader/gatsby-node.js +55 -0
- package/plugins/gatsby-plugin-svgr-loader/package.json +8 -0
- package/src/components/Head.tsx +28 -73
- package/src/components/template.tsx +6 -29
- package/src/gatsby-node-utils.ts +81 -2
- package/src/html.tsx +2 -11
- package/src/types.ts +3 -3
- package/tsconfig.commands.json +36 -0
- package/tsconfig.exporter.json +21 -0
- package/tsconfig.json +5 -3
- package/build/adapters/gatsby/index.d.ts +0 -4
- package/build/adapters/gatsby/utils.d.ts +0 -26
- package/build/artifacts/index.d.ts +0 -6
- package/build/constants/envs.d.ts +0 -37
- package/build/constants/index.d.ts +0 -57
- package/build/end-render.js +0 -74
- package/build/end-render.js.map +0 -7
- package/build/errors/index.d.ts +0 -15
- package/build/index.js.map +0 -7
- package/build/prepare-domains-render.js +0 -73
- package/build/prepare-domains-render.js.map +0 -7
- package/build/react/Favicon/index.d.ts +0 -5
- package/build/registers/api.d.ts +0 -9
- package/build/registers/gatsby.d.ts +0 -9
- package/build/registers/index.d.ts +0 -3
- package/build/reset-render.js +0 -74
- package/build/reset-render.js.map +0 -7
- package/build/services/register.d.ts +0 -36
- package/build/services/settings.d.ts +0 -4
- package/build/start-render.js +0 -100
- package/build/start-render.js.map +0 -7
- package/build/upload-search-content.js +0 -74
- package/build/upload-search-content.js.map +0 -7
- package/build/utils/alerts.d.ts +0 -3
- package/build/utils/cache.d.ts +0 -35
- package/build/utils/core-utils.d.ts +0 -107
- package/build/utils/create-build-data.d.ts +0 -8
- package/build/utils/domains.d.ts +0 -13
- package/build/utils/folders.d.ts +0 -53
- package/build/utils/loggin.d.ts +0 -51
- package/build/utils/render.d.ts +0 -13
- package/build/utils/searches.d.ts +0 -15
- package/build/utils/sites.d.ts +0 -31
- package/build/utils/store.d.ts +0 -81
- package/cx.config.d.ts +0 -5
- package/cx.config.js +0 -36
- package/exporter/adapters/gatsby/index.ts +0 -182
- package/exporter/adapters/gatsby/utils.ts +0 -186
- package/exporter/artifacts/README.md +0 -34
- package/exporter/artifacts/index.ts +0 -33
- package/exporter/commands/move-assets.ts +0 -11
- package/exporter/constants/envs.ts +0 -94
- package/exporter/constants/index.ts +0 -129
- package/exporter/errors/index.ts +0 -40
- package/exporter/registers/api.ts +0 -14
- package/exporter/registers/gatsby.ts +0 -14
- package/exporter/registers/index.ts +0 -4
- package/exporter/services/register.ts +0 -113
- package/exporter/services/settings.ts +0 -17
- package/exporter/utils/alerts.ts +0 -29
- package/exporter/utils/api.ts +0 -243
- package/exporter/utils/cache.ts +0 -142
- package/exporter/utils/core-utils.ts +0 -458
- package/exporter/utils/create-build-data.ts +0 -17
- package/exporter/utils/domains.ts +0 -39
- package/exporter/utils/folders.ts +0 -320
- package/exporter/utils/health-checks.ts +0 -64
- package/exporter/utils/loggin.ts +0 -184
- package/exporter/utils/render.ts +0 -71
- package/exporter/utils/searches.ts +0 -156
- package/exporter/utils/sites.ts +0 -312
- package/exporter/utils/store.ts +0 -314
- package/src/README.md +0 -7
- package/start-render.js +0 -7
- /package/build/commands/{move-assets.d.ts → prepare-assets-directory.d.ts} +0 -0
- /package/build/{utils → core}/images.d.ts +0 -0
- /package/build/{utils → core}/instance.d.ts +0 -0
- /package/build/react/{Favicon → GriddoFavicon}/utils.d.ts +0 -0
- /package/build/{constants → shared}/endpoints.d.ts +0 -0
- /package/build/{types → shared/types}/templates.d.ts +0 -0
- /package/exporter/react/{Favicon → GriddoFavicon}/utils.ts +0 -0
- /package/exporter/{types → shared/types}/templates.ts +0 -0
|
@@ -1,320 +0,0 @@
|
|
|
1
|
-
import fs from "node:fs";
|
|
2
|
-
import path from "node:path";
|
|
3
|
-
|
|
4
|
-
import fsx, { type MakeDirectoryOptions } from "fs-extra";
|
|
5
|
-
|
|
6
|
-
import { throwError } from "../errors";
|
|
7
|
-
import { getConfig, walkStore } from "./core-utils";
|
|
8
|
-
import { verboseLog } from "./loggin";
|
|
9
|
-
import { ArtifactError } from "../errors/errors-data";
|
|
10
|
-
|
|
11
|
-
const config = getConfig();
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Remove an empty directory from the basePath recursively.
|
|
15
|
-
* If the directory has only .xml files it will handle as empty too (empty site)
|
|
16
|
-
*
|
|
17
|
-
* @param baseDir - The base directory.
|
|
18
|
-
*/
|
|
19
|
-
function deleteDisposableSiteDirs() {
|
|
20
|
-
const { __cx } = config.paths();
|
|
21
|
-
const baseDir = path.join(__cx, "dist");
|
|
22
|
-
|
|
23
|
-
if (!fs.existsSync(baseDir)) {
|
|
24
|
-
return;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
const sitesDirs = fs
|
|
28
|
-
.readdirSync(baseDir, { withFileTypes: true })
|
|
29
|
-
.filter((file) => file.isDirectory());
|
|
30
|
-
|
|
31
|
-
for (const siteDir of sitesDirs) {
|
|
32
|
-
const sitePath = path.join(baseDir, siteDir.name);
|
|
33
|
-
if (siteIsEmpty(sitePath)) {
|
|
34
|
-
fs.rmSync(sitePath, { recursive: true });
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Creates multiple directories.
|
|
41
|
-
*
|
|
42
|
-
* @param dirs - An array of directory paths.
|
|
43
|
-
* @param options - Same option as `fs.mkdirSync()`
|
|
44
|
-
*/
|
|
45
|
-
function createArtifacts(dirs: Array<string>, options?: MakeDirectoryOptions) {
|
|
46
|
-
for (const dir of dirs) {
|
|
47
|
-
try {
|
|
48
|
-
if (!fs.existsSync(dir)) {
|
|
49
|
-
fs.mkdirSync(dir, { recursive: true, ...options });
|
|
50
|
-
verboseLog(`create directory: ${dir}`);
|
|
51
|
-
}
|
|
52
|
-
} catch (error) {
|
|
53
|
-
throwError(ArtifactError, error);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
function renameArtifact(src: string, dst: string) {
|
|
59
|
-
try {
|
|
60
|
-
if (fs.existsSync(src)) {
|
|
61
|
-
fs.renameSync(src, dst);
|
|
62
|
-
verboseLog(`rename ${src} to ${dst}`);
|
|
63
|
-
}
|
|
64
|
-
} catch (error) {
|
|
65
|
-
throwError(ArtifactError, error);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* Copy multiple directories with backup option.
|
|
71
|
-
*
|
|
72
|
-
* @param src - Source directory.
|
|
73
|
-
* @param dst - Destination directory.
|
|
74
|
-
* @param dirs - Directories to copy.
|
|
75
|
-
* @param options.withBackup - Create a previous backup before copy.
|
|
76
|
-
*/
|
|
77
|
-
function copyArtifacts(
|
|
78
|
-
src: string,
|
|
79
|
-
dst: string,
|
|
80
|
-
dirs: Array<string>,
|
|
81
|
-
options = {
|
|
82
|
-
withBackup: false,
|
|
83
|
-
},
|
|
84
|
-
) {
|
|
85
|
-
const { withBackup } = options;
|
|
86
|
-
for (const dir of dirs) {
|
|
87
|
-
const srcCompose = path.join(src, dir);
|
|
88
|
-
const dstCompose = path.join(dst, dir);
|
|
89
|
-
|
|
90
|
-
// The dir we want to copy, doesn't exist.
|
|
91
|
-
if (!fsx.existsSync(srcCompose)) {
|
|
92
|
-
console.log(
|
|
93
|
-
`(Maybe first render) Source directory does not exist: ${srcCompose}`,
|
|
94
|
-
);
|
|
95
|
-
continue;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
// Create the backup
|
|
99
|
-
if (withBackup) {
|
|
100
|
-
createBackup(dstCompose);
|
|
101
|
-
verboseLog(`create backup: ${dstCompose}`);
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
// Copy directory
|
|
105
|
-
try {
|
|
106
|
-
// First clean destination
|
|
107
|
-
if (fsx.existsSync(dstCompose)) {
|
|
108
|
-
fs.rmSync(dstCompose, { recursive: true, force: true });
|
|
109
|
-
verboseLog(`clean destination: ${dstCompose}`);
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
// Then copy src to dst
|
|
113
|
-
fs.cpSync(srcCompose, dstCompose, {
|
|
114
|
-
recursive: true,
|
|
115
|
-
preserveTimestamps: true,
|
|
116
|
-
});
|
|
117
|
-
verboseLog(`copy: ${srcCompose} to ${dstCompose}`);
|
|
118
|
-
|
|
119
|
-
if (withBackup) {
|
|
120
|
-
deleteBackup(dstCompose);
|
|
121
|
-
verboseLog(`delete backup: ${dstCompose}`);
|
|
122
|
-
}
|
|
123
|
-
} catch (error) {
|
|
124
|
-
if (withBackup) {
|
|
125
|
-
restoreBackup(dstCompose);
|
|
126
|
-
console.log("Backup has been restored.");
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
throwError(ArtifactError, error);
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
/**
|
|
135
|
-
* Move artifacts between cx-paths
|
|
136
|
-
*
|
|
137
|
-
* @param src - Source directory.
|
|
138
|
-
* @param dst - Destination directory.
|
|
139
|
-
* @param dirs - Directories to move.
|
|
140
|
-
* @param options - Options.
|
|
141
|
-
*/
|
|
142
|
-
function moveArtifacts(
|
|
143
|
-
src: string,
|
|
144
|
-
dst: string,
|
|
145
|
-
dirs: Array<string>,
|
|
146
|
-
options?: { withBackup?: boolean; override?: boolean },
|
|
147
|
-
) {
|
|
148
|
-
const { override, withBackup } = options || {};
|
|
149
|
-
|
|
150
|
-
for (const dir of dirs) {
|
|
151
|
-
const srcCompose = path.join(src, dir);
|
|
152
|
-
const dstCompose = path.join(dst, dir);
|
|
153
|
-
|
|
154
|
-
if (!fsx.existsSync(srcCompose)) {
|
|
155
|
-
continue;
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
if (withBackup) {
|
|
159
|
-
createBackup(dstCompose);
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
try {
|
|
163
|
-
// Clean destination
|
|
164
|
-
if (override && fsx.existsSync(dstCompose)) {
|
|
165
|
-
fs.rmSync(dstCompose, { recursive: true, force: true });
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
fs.renameSync(srcCompose, dstCompose);
|
|
169
|
-
verboseLog(`moved: ${srcCompose} to ${dstCompose}`);
|
|
170
|
-
|
|
171
|
-
if (withBackup) {
|
|
172
|
-
deleteBackup(dstCompose);
|
|
173
|
-
}
|
|
174
|
-
} catch (error) {
|
|
175
|
-
if (withBackup) {
|
|
176
|
-
restoreBackup(dstCompose);
|
|
177
|
-
console.log("Backup has been restored.");
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
throwError(ArtifactError, error);
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
/**
|
|
186
|
-
* Removes multiple artifact directories.
|
|
187
|
-
*
|
|
188
|
-
* @param artifacts - An array of artifact directory paths.
|
|
189
|
-
*/
|
|
190
|
-
function removeArtifacts(artifacts: Array<string>) {
|
|
191
|
-
for (const dir of artifacts) {
|
|
192
|
-
if (!dir) {
|
|
193
|
-
continue;
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
try {
|
|
197
|
-
if (fsx.existsSync(dir)) {
|
|
198
|
-
const kind = fs.statSync(dir).isDirectory() ? "dir" : "file";
|
|
199
|
-
fs.rmSync(dir, { recursive: true, force: true });
|
|
200
|
-
verboseLog(`artifact (${kind}) removed: ${dir}`);
|
|
201
|
-
}
|
|
202
|
-
} catch (error) {
|
|
203
|
-
throwError(ArtifactError, error);
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
function restoreBackup(src: string, suffix = "-BACKUP") {
|
|
209
|
-
const dst = src + suffix;
|
|
210
|
-
try {
|
|
211
|
-
fs.renameSync(dst, src);
|
|
212
|
-
console.log(`Backup ${dst} has been restored`);
|
|
213
|
-
} catch (error) {
|
|
214
|
-
console.log(error);
|
|
215
|
-
throw new Error(`Error while delete ${dst} backup`);
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
function deleteBackup(src: string, suffix = "-BACKUP") {
|
|
220
|
-
const dst = src + suffix;
|
|
221
|
-
|
|
222
|
-
if (!fsx.existsSync(dst)) {
|
|
223
|
-
return;
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
try {
|
|
227
|
-
fs.rmSync(dst, { recursive: true, force: true });
|
|
228
|
-
console.log(`Backup ${dst} has been deleted`);
|
|
229
|
-
} catch (error) {
|
|
230
|
-
console.log(error);
|
|
231
|
-
throw new Error(`Error while delete ${dst} backup`);
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
function createBackup(src: string, suffix = "-BACKUP") {
|
|
236
|
-
const dst = src + suffix;
|
|
237
|
-
|
|
238
|
-
if (!fsx.existsSync(src)) {
|
|
239
|
-
return;
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
if (fsx.existsSync(dst)) {
|
|
243
|
-
console.log(`Destination ${dst} already exists`);
|
|
244
|
-
return;
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
try {
|
|
248
|
-
fs.renameSync(src, dst);
|
|
249
|
-
console.log(`Backup of ${src} has been created in ${dst}`);
|
|
250
|
-
} catch (error) {
|
|
251
|
-
console.log(`Error while coping ${src} to ${dst} backup`);
|
|
252
|
-
throwError(ArtifactError, error);
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
/**
|
|
257
|
-
* Elimina todas las páginas del store (de todos los sites) cuyo nombre empiece con un guión "-".
|
|
258
|
-
* Estas páginas son "virtuales" y no tienen ids desde API por lo que mantenerlas en el store es un problema cuando se hacen modificaciones en la página "madre".
|
|
259
|
-
* La solución por ahora es borrarlas del store y rehacerlas en todos los renders.
|
|
260
|
-
*/
|
|
261
|
-
async function removeVirtualPagesFromStore() {
|
|
262
|
-
const { __cx } = config.paths();
|
|
263
|
-
const storePath = path.join(__cx, "store");
|
|
264
|
-
|
|
265
|
-
try {
|
|
266
|
-
const allJsonPageFilesPath = walkStore(storePath);
|
|
267
|
-
|
|
268
|
-
for (const filePath of allJsonPageFilesPath) {
|
|
269
|
-
if (path.basename(filePath).startsWith("-")) {
|
|
270
|
-
fs.unlinkSync(filePath);
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
} catch (error) {
|
|
274
|
-
console.info(
|
|
275
|
-
"`store` folder does not exist. Skipping multipage or static list template cleaning.",
|
|
276
|
-
error,
|
|
277
|
-
);
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
/**
|
|
282
|
-
* Return true if the site folder is empty or only has xml files. (Recursively)
|
|
283
|
-
*/
|
|
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
|
-
);
|
|
293
|
-
|
|
294
|
-
const xmlFiles = siteFiles.filter((file) => file.name.endsWith(".xml"));
|
|
295
|
-
|
|
296
|
-
if (siteFiles.length === xmlFiles.length) {
|
|
297
|
-
return true;
|
|
298
|
-
}
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
function prependFileSync(filePath: string, content: string) {
|
|
302
|
-
let currentContent = "";
|
|
303
|
-
|
|
304
|
-
if (fs.existsSync(filePath)) {
|
|
305
|
-
currentContent = fs.readFileSync(filePath, "utf8");
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
fs.writeFileSync(filePath, content + currentContent, "utf8");
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
export {
|
|
312
|
-
copyArtifacts,
|
|
313
|
-
createArtifacts,
|
|
314
|
-
deleteDisposableSiteDirs,
|
|
315
|
-
moveArtifacts,
|
|
316
|
-
prependFileSync,
|
|
317
|
-
removeArtifacts,
|
|
318
|
-
removeVirtualPagesFromStore,
|
|
319
|
-
renameArtifact,
|
|
320
|
-
};
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import { boxLog } from "./loggin";
|
|
2
|
-
import { envs } from "../constants";
|
|
3
|
-
|
|
4
|
-
const GRIDDO_ENVS_VARS: ReadonlyArray<string> = [];
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Check if the environment is secure to launch a render.
|
|
8
|
-
* If something fails then log an error message and exit from the process.
|
|
9
|
-
* Otherwise just return true.
|
|
10
|
-
*/
|
|
11
|
-
function checkRenderHealthOrExit() {
|
|
12
|
-
// Bypass the check using this env var, handy for local renders.
|
|
13
|
-
if (envs.GRIDDO_SKIP_BUILD_CHECKS) {
|
|
14
|
-
console.info("Build health check skipped");
|
|
15
|
-
|
|
16
|
-
return true;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
// Checklist
|
|
20
|
-
const envsVars = checkEnvsVars(GRIDDO_ENVS_VARS);
|
|
21
|
-
|
|
22
|
-
// Render is safe if...
|
|
23
|
-
const renderingIsSave = envsVars;
|
|
24
|
-
|
|
25
|
-
// The environment is suitable for a build-render
|
|
26
|
-
if (renderingIsSave) {
|
|
27
|
-
console.info("Build health check passed");
|
|
28
|
-
|
|
29
|
-
return true;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
// Error
|
|
33
|
-
boxLog(
|
|
34
|
-
"Error. The environment is not suitable for a build.",
|
|
35
|
-
"Not valid environment",
|
|
36
|
-
);
|
|
37
|
-
process.exit(1);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Check if a list of environments variables exist with any value.
|
|
42
|
-
*
|
|
43
|
-
* @todo Also check the value.
|
|
44
|
-
* @param envs An array of environments variables
|
|
45
|
-
* @returns exists with (1) if there are missing envs vars
|
|
46
|
-
*/
|
|
47
|
-
function checkEnvsVars(envs: ReadonlyArray<string>) {
|
|
48
|
-
const missingEnvs = envs.filter((envName) => {
|
|
49
|
-
return !process.env[envName];
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
if (missingEnvs.length) {
|
|
53
|
-
const missingEnvsMsg = missingEnvs.join("\n");
|
|
54
|
-
console.error(
|
|
55
|
-
`Env check failed. These envs vars are missing: \n\n${missingEnvsMsg}`,
|
|
56
|
-
);
|
|
57
|
-
|
|
58
|
-
return false;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
return true;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
export { checkRenderHealthOrExit };
|
package/exporter/utils/loggin.ts
DELETED
|
@@ -1,184 +0,0 @@
|
|
|
1
|
-
import type { Site } from "../types/sites";
|
|
2
|
-
|
|
3
|
-
import kleur from "kleur";
|
|
4
|
-
|
|
5
|
-
import { envs } from "../constants";
|
|
6
|
-
import { getConfig } from "./core-utils";
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Custom basic logging function controlled by a environment variable.
|
|
10
|
-
*
|
|
11
|
-
* @param str The string to be logged.
|
|
12
|
-
*/
|
|
13
|
-
function verboseLog(str: string) {
|
|
14
|
-
if (envs.GRIDDO_VERBOSE_LOGS) {
|
|
15
|
-
console.log(
|
|
16
|
-
kleur.yellow("verbose"),
|
|
17
|
-
kleur.dim(str.replace(/(\s)\s+/g, "$1").trim()),
|
|
18
|
-
);
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Custom log inside a line-box.
|
|
24
|
-
*
|
|
25
|
-
* @param stringValue The string to be logged.
|
|
26
|
-
* @param paddingInline The number of white spaces inside the box at left and right.
|
|
27
|
-
* @param paddingBlock The number of white spaces inside the box at top and bottom.
|
|
28
|
-
*/
|
|
29
|
-
function boxLog(
|
|
30
|
-
stringValue: string,
|
|
31
|
-
title = "",
|
|
32
|
-
paddingInline = 1,
|
|
33
|
-
paddingBlock = 1,
|
|
34
|
-
) {
|
|
35
|
-
const lines = stringValue
|
|
36
|
-
.split("\n") // lines
|
|
37
|
-
.map((line) => line.trim()); // remove extra spaces
|
|
38
|
-
const windowTitle = title ? ` ${title} ` : "";
|
|
39
|
-
const windowTitleLength = title ? windowTitle.length : 0;
|
|
40
|
-
const longerContent =
|
|
41
|
-
Math.max(...lines.map((l) => l.length)) + paddingInline * 2;
|
|
42
|
-
const longerLine = Math.max(longerContent, windowTitleLength);
|
|
43
|
-
const paddingBlockString = `│${" ".repeat(longerLine)}│\n`.repeat(
|
|
44
|
-
paddingBlock,
|
|
45
|
-
);
|
|
46
|
-
const minWidth = longerLine;
|
|
47
|
-
const borderTop = `╭${windowTitle}${"─".repeat(
|
|
48
|
-
minWidth - windowTitleLength,
|
|
49
|
-
)}╮\n`;
|
|
50
|
-
const borderBottom = `╰${"─".repeat(minWidth)}╯`;
|
|
51
|
-
const content = lines
|
|
52
|
-
.map((l) => {
|
|
53
|
-
const mr = " ".repeat(longerLine - l.length - paddingInline);
|
|
54
|
-
return `│${" ".repeat(paddingInline)}${l}${mr}│\n`;
|
|
55
|
-
})
|
|
56
|
-
.join("");
|
|
57
|
-
|
|
58
|
-
console.log(
|
|
59
|
-
`${borderTop}${paddingBlockString}${content}${paddingBlockString}${borderBottom}`,
|
|
60
|
-
);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* Custom basic logging function controlled by a environment variable.
|
|
65
|
-
* Strip double spaces.
|
|
66
|
-
*
|
|
67
|
-
* @param str The string to be logged.
|
|
68
|
-
*/
|
|
69
|
-
function buildLog(str: string) {
|
|
70
|
-
if (envs.GRIDDO_BUILD_LOGS) {
|
|
71
|
-
console.log(str.replace(/(\s)\s+/g, "$1").trim());
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* Console log with a blue color in the info prefix.
|
|
77
|
-
* @param str The string to be logged.
|
|
78
|
-
*/
|
|
79
|
-
function infoLog(str: string) {
|
|
80
|
-
console.log(`${kleur.blue("info")} ${str}`);
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* Console log with a green color in the success prefix.
|
|
85
|
-
* @param str The string to be logged.
|
|
86
|
-
*/
|
|
87
|
-
function successLog(str: string) {
|
|
88
|
-
console.log(`${kleur.green("success")} ${str}`);
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
* Internal log
|
|
93
|
-
* @param values The values to be logged.
|
|
94
|
-
*/
|
|
95
|
-
function debugLog(...values: Array<unknown>) {
|
|
96
|
-
if (!envs.GRIDDO_DEBUG_LOGS) {
|
|
97
|
-
return;
|
|
98
|
-
}
|
|
99
|
-
console.log(...values);
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
/**
|
|
103
|
-
* Return a scale size colors with a number and a measure string (KB by default).
|
|
104
|
-
*
|
|
105
|
-
* @param size The page size in KB.
|
|
106
|
-
* @param measure The measure string to be added in the log.
|
|
107
|
-
*/
|
|
108
|
-
function pageSizeLog(size: number, measure = "KB") {
|
|
109
|
-
const sizeScale = {
|
|
110
|
-
low: 50,
|
|
111
|
-
mid: 80,
|
|
112
|
-
large: 130,
|
|
113
|
-
extraLarge: 210,
|
|
114
|
-
};
|
|
115
|
-
|
|
116
|
-
// Ternary pawa!
|
|
117
|
-
const color =
|
|
118
|
-
size > sizeScale.large
|
|
119
|
-
? "red"
|
|
120
|
-
: size > sizeScale.mid
|
|
121
|
-
? "magenta"
|
|
122
|
-
: size > sizeScale.low
|
|
123
|
-
? "blue"
|
|
124
|
-
: "green";
|
|
125
|
-
|
|
126
|
-
return kleur[color](kleur.bold(`${size}${measure}`));
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
/**
|
|
130
|
-
* Console log the Griddo exporter version.
|
|
131
|
-
*/
|
|
132
|
-
function showExporterVersion() {
|
|
133
|
-
console.clear();
|
|
134
|
-
const config = getConfig();
|
|
135
|
-
const { griddoVersion } = config;
|
|
136
|
-
const logo = `\n${kleur
|
|
137
|
-
.bgYellow()
|
|
138
|
-
.black()
|
|
139
|
-
.bold(" Griddo Exporter " + griddoVersion + " ")}\n`;
|
|
140
|
-
|
|
141
|
-
console.log(logo);
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
function listSitesLog(title: string, sites: Array<Site>) {
|
|
145
|
-
const maxline = Math.max(
|
|
146
|
-
...sites.map(
|
|
147
|
-
(s) =>
|
|
148
|
-
s.name.length + (s.shouldBeUpdated ? 1 : 0) + s.id.toString().length,
|
|
149
|
-
),
|
|
150
|
-
);
|
|
151
|
-
|
|
152
|
-
const sitesStr = sites.map((s) => {
|
|
153
|
-
const shouldBeUpdated = s.shouldBeUpdated ? "*" : "";
|
|
154
|
-
const lineLen =
|
|
155
|
-
s.name.length + shouldBeUpdated.length + s.id.toString().length;
|
|
156
|
-
const padding = " ".repeat(maxline - lineLen);
|
|
157
|
-
return `${kleur.bold(s.name)} ${kleur.dim("(" + s.id + ")")} ${shouldBeUpdated} ${padding}${kleur.dim("-")} ${kleur.dim(s.slug)}`;
|
|
158
|
-
});
|
|
159
|
-
|
|
160
|
-
const sitesOutput =
|
|
161
|
-
sitesStr.length > 0
|
|
162
|
-
? "\n\n" + sitesStr.join("\n")
|
|
163
|
-
: kleur.dim("--none--\n");
|
|
164
|
-
|
|
165
|
-
console.log(`
|
|
166
|
-
${title} ${sitesOutput}`);
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
function errorLabelLog(msg: string) {
|
|
170
|
-
console.error("\n" + kleur.black().bgRed(" " + msg + " ") + "\n");
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
export {
|
|
174
|
-
boxLog,
|
|
175
|
-
buildLog,
|
|
176
|
-
debugLog,
|
|
177
|
-
errorLabelLog,
|
|
178
|
-
infoLog,
|
|
179
|
-
listSitesLog,
|
|
180
|
-
pageSizeLog,
|
|
181
|
-
showExporterVersion,
|
|
182
|
-
successLog,
|
|
183
|
-
verboseLog,
|
|
184
|
-
};
|
package/exporter/utils/render.ts
DELETED
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import fs from "node:fs";
|
|
2
|
-
import path from "node:path";
|
|
3
|
-
|
|
4
|
-
import { envs } from "../constants";
|
|
5
|
-
import { throwError } from "../errors";
|
|
6
|
-
import { RenderUUIDError } from "../errors/errors-data";
|
|
7
|
-
import { apiRegister } from "../registers";
|
|
8
|
-
import { insertAlert } from "./alerts";
|
|
9
|
-
import { getConfig } from "./core-utils";
|
|
10
|
-
import { debugLog } from "./loggin";
|
|
11
|
-
|
|
12
|
-
const config = getConfig();
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Creates a sentinel file with the current date and time.
|
|
16
|
-
* This file is used to track later if node_modules/@griddo/cx was cleaned by a
|
|
17
|
-
* npm install from a deploy.
|
|
18
|
-
*/
|
|
19
|
-
function createSentinelRenderFile() {
|
|
20
|
-
const { __cx } = config.paths();
|
|
21
|
-
const renderSentinelFile = path.join(__cx, ".render-sentinel");
|
|
22
|
-
fs.writeFileSync(renderSentinelFile, new Date().toISOString());
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
function deleteSentinelRenderFile() {
|
|
26
|
-
const { __cx } = config.paths();
|
|
27
|
-
const renderSentinelFile = path.join(__cx, ".render-sentinel");
|
|
28
|
-
fs.unlinkSync(renderSentinelFile);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
function isValidRender() {
|
|
32
|
-
const { __cx } = config.paths();
|
|
33
|
-
const renderSentinelFile = path.join(__cx, ".render-sentinel");
|
|
34
|
-
if (!fs.existsSync(renderSentinelFile)) {
|
|
35
|
-
throwError(RenderUUIDError);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Send the default registers through Griddo alerts.
|
|
41
|
-
*/
|
|
42
|
-
async function sendGriddoDefaultAlerts() {
|
|
43
|
-
if (envs.GRIDDO_ALERT_FEATURE) {
|
|
44
|
-
const registerContent = apiRegister.get("API_RESPONSE_TOO_BIG");
|
|
45
|
-
|
|
46
|
-
if (registerContent.entries.length < 1) {
|
|
47
|
-
return;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
debugLog("\nRender register report\n");
|
|
51
|
-
debugLog(registerContent);
|
|
52
|
-
debugLog();
|
|
53
|
-
|
|
54
|
-
await insertAlert({
|
|
55
|
-
description: `API response size is too large (${envs.GRIDDO_API_MAX_RESPONSE_SIZE}KB).`,
|
|
56
|
-
area: "Griddo",
|
|
57
|
-
level: "W",
|
|
58
|
-
fullData: {
|
|
59
|
-
output: registerContent,
|
|
60
|
-
date: new Date().toISOString(),
|
|
61
|
-
},
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
export {
|
|
67
|
-
createSentinelRenderFile,
|
|
68
|
-
deleteSentinelRenderFile,
|
|
69
|
-
isValidRender,
|
|
70
|
-
sendGriddoDefaultAlerts,
|
|
71
|
-
};
|