@hubspot/local-dev-lib 0.6.1-experimental.0 → 0.6.3-experimental.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/api/appsDev.d.ts +2 -2
- package/api/appsDev.js +13 -22
- package/api/crm.d.ts +2 -2
- package/api/crm.js +9 -16
- package/api/customObjects.d.ts +2 -2
- package/api/customObjects.js +13 -22
- package/api/designManager.d.ts +2 -2
- package/api/designManager.js +5 -10
- package/api/devSecrets.d.ts +2 -2
- package/api/devSecrets.js +9 -16
- package/api/developerTestAccounts.d.ts +2 -4
- package/api/developerTestAccounts.js +23 -55
- package/api/fileManager.d.ts +2 -2
- package/api/fileManager.js +14 -24
- package/api/fileMapper.d.ts +2 -3
- package/api/fileMapper.js +34 -49
- package/api/fileTransport.d.ts +1 -1
- package/api/fileTransport.js +12 -21
- package/api/fireAlarm.d.ts +2 -3
- package/api/fireAlarm.js +5 -9
- package/api/functions.d.ts +2 -2
- package/api/functions.js +11 -19
- package/api/github.d.ts +2 -4
- package/api/github.js +16 -27
- package/api/hubdb.d.ts +2 -2
- package/api/hubdb.js +19 -31
- package/api/lighthouseScore.d.ts +2 -2
- package/api/lighthouseScore.js +7 -13
- package/api/localDevAuth.d.ts +3 -6
- package/api/localDevAuth.js +10 -40
- package/api/marketplaceValidation.d.ts +2 -2
- package/api/marketplaceValidation.js +7 -13
- package/api/projects.d.ts +6 -8
- package/api/projects.js +65 -100
- package/api/sandboxHubs.d.ts +2 -5
- package/api/sandboxHubs.js +15 -45
- package/api/sandboxSync.d.ts +2 -2
- package/api/sandboxSync.js +7 -12
- package/api/secrets.d.ts +2 -2
- package/api/secrets.js +9 -16
- package/api/validateHubl.d.ts +2 -2
- package/api/validateHubl.js +3 -7
- package/config/defaultAccountOverride.d.ts +2 -1
- package/config/defaultAccountOverride.js +16 -26
- package/config/index.d.ts +4 -4
- package/config/index.js +144 -177
- package/config/migrate.d.ts +2 -2
- package/config/migrate.js +26 -37
- package/config/state.d.ts +1 -1
- package/config/state.js +17 -45
- package/config/utils.d.ts +4 -4
- package/config/utils.js +85 -108
- package/constants/api.js +3 -6
- package/constants/auth.js +9 -12
- package/constants/config.d.ts +30 -1
- package/constants/config.js +65 -42
- package/constants/endpoints.d.ts +6 -0
- package/constants/endpoints.js +6 -0
- package/constants/environments.js +1 -4
- package/constants/extensions.js +6 -9
- package/constants/files.js +5 -8
- package/constants/ports.js +3 -6
- package/constants/projects.js +2 -5
- package/enums/build.d.ts +1 -0
- package/enums/build.js +6 -8
- package/enums/deploy.js +2 -5
- package/enums/project.js +1 -4
- package/errors/index.d.ts +4 -5
- package/errors/index.js +17 -39
- package/errors/isSystemError.d.ts +2 -0
- package/errors/isSystemError.js +9 -0
- package/http/addQueryParams.d.ts +1 -1
- package/http/addQueryParams.js +1 -5
- package/http/client.d.ts +1 -0
- package/http/client.js +54 -0
- package/http/getAxiosConfig.d.ts +1 -1
- package/http/getAxiosConfig.js +21 -31
- package/http/index.d.ts +2 -2
- package/http/index.js +39 -124
- package/http/unauthed.d.ts +1 -1
- package/http/unauthed.js +15 -21
- package/lang/en.json +3 -2
- package/lib/archive.d.ts +1 -3
- package/lib/archive.js +37 -67
- package/lib/cms/functions.d.ts +1 -1
- package/lib/cms/functions.js +45 -55
- package/lib/cms/handleFieldsJS.js +36 -44
- package/lib/cms/modules.d.ts +2 -2
- package/lib/cms/modules.js +49 -59
- package/lib/cms/processFieldsJs.js +17 -32
- package/lib/cms/templates.js +17 -26
- package/lib/cms/themes.js +10 -18
- package/lib/cms/uploadFolder.d.ts +4 -4
- package/lib/cms/uploadFolder.js +55 -64
- package/lib/cms/validate.d.ts +1 -1
- package/lib/cms/validate.js +11 -18
- package/lib/cms/watch.d.ts +2 -2
- package/lib/cms/watch.js +66 -73
- package/lib/crm.d.ts +1 -1
- package/lib/crm.js +15 -23
- package/lib/customObjects.d.ts +1 -1
- package/lib/customObjects.js +15 -25
- package/lib/environment.d.ts +1 -1
- package/lib/environment.js +5 -11
- package/lib/escapeRegExp.js +1 -5
- package/lib/fileManager.js +43 -51
- package/lib/fileMapper.d.ts +1 -1
- package/lib/fileMapper.js +68 -84
- package/lib/fs.d.ts +1 -1
- package/lib/fs.js +18 -27
- package/lib/github.d.ts +1 -3
- package/lib/github.js +39 -51
- package/lib/gitignore.d.ts +1 -1
- package/lib/gitignore.js +16 -24
- package/lib/hubdb.d.ts +1 -1
- package/lib/hubdb.js +29 -40
- package/lib/ignoreRules.js +25 -34
- package/lib/isDeepEqual.js +1 -5
- package/lib/logger.d.ts +8 -20
- package/lib/logger.js +47 -59
- package/lib/notify.js +9 -16
- package/lib/oauth.d.ts +2 -2
- package/lib/oauth.js +12 -17
- package/lib/path.d.ts +0 -1
- package/lib/path.js +30 -48
- package/lib/personalAccessKey.d.ts +2 -4
- package/lib/personalAccessKey.js +43 -60
- package/lib/portManager.d.ts +2 -2
- package/lib/portManager.js +26 -41
- package/lib/text.js +2 -7
- package/lib/trackUsage.d.ts +0 -2
- package/lib/trackUsage.js +27 -31
- package/lib/urls.js +4 -9
- package/models/FileSystemError.d.ts +1 -1
- package/models/FileSystemError.js +12 -16
- package/models/HubSpotConfigError.d.ts +1 -1
- package/models/HubSpotConfigError.js +8 -12
- package/models/HubSpotHttpError.d.ts +1 -1
- package/models/HubSpotHttpError.js +22 -26
- package/models/OAuth2Manager.d.ts +1 -1
- package/models/OAuth2Manager.js +17 -24
- package/package.json +21 -17
- package/types/Accounts.d.ts +6 -5
- package/types/Accounts.js +1 -2
- package/types/Activity.d.ts +3 -3
- package/types/Activity.js +1 -2
- package/types/Api.d.ts +1 -1
- package/types/Api.js +1 -2
- package/types/Apps.js +1 -2
- package/types/Archive.js +1 -2
- package/types/Build.d.ts +4 -5
- package/types/Build.js +1 -2
- package/types/CLIOptions.js +1 -2
- package/types/ComponentStructure.d.ts +2 -2
- package/types/ComponentStructure.js +1 -2
- package/types/Config.d.ts +4 -6
- package/types/Config.js +1 -2
- package/types/Crm.js +1 -2
- package/types/Deploy.d.ts +5 -11
- package/types/Deploy.js +1 -2
- package/types/DesignManager.js +1 -2
- package/types/DevSecrets.js +1 -2
- package/types/Error.js +1 -2
- package/types/FieldsJS.js +1 -2
- package/types/FileManager.js +1 -2
- package/types/Files.d.ts +4 -4
- package/types/Files.js +1 -2
- package/types/FireAlarm.js +1 -2
- package/types/Functions.js +1 -2
- package/types/Github.d.ts +1 -1
- package/types/Github.js +1 -2
- package/types/Http.d.ts +0 -4
- package/types/Http.js +1 -2
- package/types/Hubdb.js +1 -2
- package/types/HublValidation.js +1 -2
- package/types/Lang.d.ts +1 -1
- package/types/Lang.js +1 -2
- package/types/Lighthouse.js +1 -2
- package/types/MarketplaceValidation.js +1 -2
- package/types/Migration.d.ts +2 -2
- package/types/Migration.js +1 -4
- package/types/Modules.js +1 -2
- package/types/PortManager.js +1 -2
- package/types/Project.d.ts +3 -21
- package/types/Project.js +1 -2
- package/types/ProjectComponents.d.ts +24 -0
- package/types/ProjectComponents.js +1 -0
- package/types/ProjectLog.js +1 -2
- package/types/Sandbox.js +2 -5
- package/types/Schemas.js +1 -2
- package/types/Secrets.js +1 -2
- package/types/Utils.js +1 -2
- package/types/developerTestAccounts.js +1 -2
- package/utils/PortManagerServer.d.ts +1 -2
- package/utils/PortManagerServer.js +32 -38
- package/utils/cms/fieldsJS.d.ts +1 -1
- package/utils/cms/fieldsJS.js +1 -5
- package/utils/cms/modules.d.ts +1 -1
- package/utils/cms/modules.js +13 -22
- package/utils/detectPort.js +12 -19
- package/utils/git.js +17 -26
- package/utils/lang.d.ts +1 -1
- package/utils/lang.js +5 -14
- package/utils/personalAccessKey.d.ts +8 -0
- package/utils/personalAccessKey.js +51 -0
- package/errors/errors_DEPRECATED.d.ts +0 -3
- package/errors/errors_DEPRECATED.js +0 -60
package/lib/fileMapper.js
CHANGED
|
@@ -1,53 +1,43 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
// FILE MAPPER - not to be confused with fileManager.ts
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
const extensions_1 = require("../constants/extensions");
|
|
15
|
-
const files_1 = require("../constants/files");
|
|
16
|
-
const errors_1 = require("../errors");
|
|
17
|
-
const lang_1 = require("../utils/lang");
|
|
18
|
-
const FileSystemError_1 = require("../models/FileSystemError");
|
|
2
|
+
import fs from 'fs-extra';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
import PQueue from 'p-queue';
|
|
5
|
+
import { getCwd, getExt, convertToLocalFileSystemPath, isAllowedExtension, } from './path.js';
|
|
6
|
+
import { logger } from './logger.js';
|
|
7
|
+
import { fetchFileStream, download, downloadDefault, } from '../api/fileMapper.js';
|
|
8
|
+
import { MODULE_EXTENSION, FUNCTIONS_EXTENSION, JSR_ALLOWED_EXTENSIONS, } from '../constants/extensions.js';
|
|
9
|
+
import { CMS_PUBLISH_MODE } from '../constants/files.js';
|
|
10
|
+
import { isTimeoutError } from '../errors/index.js';
|
|
11
|
+
import { i18n } from '../utils/lang.js';
|
|
12
|
+
import { FileSystemError } from '../models/FileSystemError.js';
|
|
19
13
|
const i18nKey = 'lib.fileMapper';
|
|
20
|
-
const queue = new
|
|
14
|
+
const queue = new PQueue({
|
|
21
15
|
concurrency: 10,
|
|
22
16
|
});
|
|
23
|
-
function isPathToFile(filepath) {
|
|
24
|
-
const ext =
|
|
25
|
-
return !!ext && ext !==
|
|
17
|
+
export function isPathToFile(filepath) {
|
|
18
|
+
const ext = getExt(filepath);
|
|
19
|
+
return !!ext && ext !== MODULE_EXTENSION && ext !== FUNCTIONS_EXTENSION;
|
|
26
20
|
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
return ext === extensions_1.MODULE_EXTENSION;
|
|
21
|
+
export function isPathToModule(filepath) {
|
|
22
|
+
const ext = getExt(filepath);
|
|
23
|
+
return ext === MODULE_EXTENSION;
|
|
31
24
|
}
|
|
32
|
-
|
|
33
|
-
function isPathToRoot(filepath) {
|
|
25
|
+
export function isPathToRoot(filepath) {
|
|
34
26
|
if (typeof filepath !== 'string')
|
|
35
27
|
return false;
|
|
36
28
|
// Root pattern matches empty strings and: / \
|
|
37
29
|
return /^(\/|\\)?$/.test(filepath.trim());
|
|
38
30
|
}
|
|
39
|
-
|
|
40
|
-
function isPathToHubspot(filepath) {
|
|
31
|
+
export function isPathToHubspot(filepath) {
|
|
41
32
|
if (typeof filepath !== 'string')
|
|
42
33
|
return false;
|
|
43
34
|
return /^(\/|\\)?@hubspot/i.test(filepath.trim());
|
|
44
35
|
}
|
|
45
|
-
exports.isPathToHubspot = isPathToHubspot;
|
|
46
36
|
function useApiBuffer(cmsPublishMode) {
|
|
47
|
-
return cmsPublishMode ===
|
|
37
|
+
return cmsPublishMode === CMS_PUBLISH_MODE.draft;
|
|
48
38
|
}
|
|
49
39
|
// Determines API param based on publish mode and options
|
|
50
|
-
function getFileMapperQueryValues(cmsPublishMode, { staging, assetVersion } = {}) {
|
|
40
|
+
export function getFileMapperQueryValues(cmsPublishMode, { staging, assetVersion } = {}) {
|
|
51
41
|
return {
|
|
52
42
|
params: {
|
|
53
43
|
buffer: useApiBuffer(cmsPublishMode),
|
|
@@ -56,7 +46,6 @@ function getFileMapperQueryValues(cmsPublishMode, { staging, assetVersion } = {}
|
|
|
56
46
|
},
|
|
57
47
|
};
|
|
58
48
|
}
|
|
59
|
-
exports.getFileMapperQueryValues = getFileMapperQueryValues;
|
|
60
49
|
// Determines version number to log based on input.options
|
|
61
50
|
function getAssetVersionIdentifier(assetVersion, src) {
|
|
62
51
|
if (typeof assetVersion !== 'undefined' &&
|
|
@@ -76,11 +65,11 @@ function validateFileMapperNode(node) {
|
|
|
76
65
|
catch (err) {
|
|
77
66
|
json = node;
|
|
78
67
|
}
|
|
79
|
-
throw new Error(
|
|
68
|
+
throw new Error(i18n(`${i18nKey}.errors.invalidNode`, {
|
|
80
69
|
json: JSON.stringify(json),
|
|
81
70
|
}));
|
|
82
71
|
}
|
|
83
|
-
function getTypeDataFromPath(src) {
|
|
72
|
+
export function getTypeDataFromPath(src) {
|
|
84
73
|
const isModule = isPathToModule(src);
|
|
85
74
|
const isHubspot = isPathToHubspot(src);
|
|
86
75
|
const isFile = !isModule && isPathToFile(src);
|
|
@@ -94,8 +83,7 @@ function getTypeDataFromPath(src) {
|
|
|
94
83
|
isFolder,
|
|
95
84
|
};
|
|
96
85
|
}
|
|
97
|
-
|
|
98
|
-
function recurseFolder(node, callback, filepath = '', depth = 0) {
|
|
86
|
+
export function recurseFolder(node, callback, filepath = '', depth = 0) {
|
|
99
87
|
validateFileMapperNode(node);
|
|
100
88
|
const isRootFolder = node.folder && depth === 0;
|
|
101
89
|
if (isRootFolder) {
|
|
@@ -104,7 +92,7 @@ function recurseFolder(node, callback, filepath = '', depth = 0) {
|
|
|
104
92
|
}
|
|
105
93
|
}
|
|
106
94
|
else {
|
|
107
|
-
filepath =
|
|
95
|
+
filepath = path.join(filepath, node.name);
|
|
108
96
|
}
|
|
109
97
|
let __break = callback(node, filepath, depth);
|
|
110
98
|
if (__break === false)
|
|
@@ -115,28 +103,26 @@ function recurseFolder(node, callback, filepath = '', depth = 0) {
|
|
|
115
103
|
});
|
|
116
104
|
return depth === 0 ? false : __break;
|
|
117
105
|
}
|
|
118
|
-
|
|
119
|
-
async function writeUtimes(accountId, filepath, node) {
|
|
106
|
+
export async function writeUtimes(accountId, filepath, node) {
|
|
120
107
|
try {
|
|
121
108
|
const now = new Date();
|
|
122
109
|
const atime = node.createdAt ? new Date(node.createdAt) : now;
|
|
123
110
|
const mtime = node.updatedAt ? new Date(node.updatedAt) : now;
|
|
124
|
-
await
|
|
111
|
+
await fs.utimes(filepath, atime, mtime);
|
|
125
112
|
}
|
|
126
113
|
catch (err) {
|
|
127
|
-
throw new
|
|
114
|
+
throw new FileSystemError({ cause: err }, {
|
|
128
115
|
filepath,
|
|
129
116
|
accountId,
|
|
130
117
|
operation: 'write',
|
|
131
118
|
});
|
|
132
119
|
}
|
|
133
120
|
}
|
|
134
|
-
exports.writeUtimes = writeUtimes;
|
|
135
121
|
async function skipExisting(filepath, overwrite = false) {
|
|
136
122
|
if (overwrite) {
|
|
137
123
|
return false;
|
|
138
124
|
}
|
|
139
|
-
if (await
|
|
125
|
+
if (await fs.pathExists(filepath)) {
|
|
140
126
|
return true;
|
|
141
127
|
}
|
|
142
128
|
return false;
|
|
@@ -146,21 +132,21 @@ async function fetchAndWriteFileStream(accountId, srcPath, filepath, cmsPublishM
|
|
|
146
132
|
return;
|
|
147
133
|
}
|
|
148
134
|
if (await skipExisting(filepath, options.overwrite)) {
|
|
149
|
-
|
|
135
|
+
logger.log(i18n(`${i18nKey}.skippedExisting`, { filepath }));
|
|
150
136
|
return;
|
|
151
137
|
}
|
|
152
|
-
if (!
|
|
153
|
-
throw new Error(
|
|
138
|
+
if (!isAllowedExtension(srcPath, Array.from(JSR_ALLOWED_EXTENSIONS))) {
|
|
139
|
+
throw new Error(i18n(`${i18nKey}.errors.invalidFileType`, { srcPath }));
|
|
154
140
|
}
|
|
155
|
-
const node = await
|
|
141
|
+
const node = await fetchFileStream(accountId, srcPath, filepath, getFileMapperQueryValues(cmsPublishMode, options));
|
|
156
142
|
await writeUtimes(accountId, filepath, node);
|
|
157
143
|
}
|
|
158
144
|
// Writes an individual file or folder (not recursive). If file source is missing, the
|
|
159
145
|
//file is fetched.
|
|
160
146
|
async function writeFileMapperNode(accountId, filepath, node, cmsPublishMode, options = {}) {
|
|
161
|
-
const localFilepath =
|
|
147
|
+
const localFilepath = convertToLocalFileSystemPath(path.resolve(filepath));
|
|
162
148
|
if (await skipExisting(localFilepath, options.overwrite)) {
|
|
163
|
-
|
|
149
|
+
logger.log(i18n(`${i18nKey}.skippedExisting`, {
|
|
164
150
|
filepath: localFilepath,
|
|
165
151
|
}));
|
|
166
152
|
return true;
|
|
@@ -175,13 +161,13 @@ async function writeFileMapperNode(accountId, filepath, node, cmsPublishMode, op
|
|
|
175
161
|
}
|
|
176
162
|
}
|
|
177
163
|
try {
|
|
178
|
-
await
|
|
179
|
-
|
|
164
|
+
await fs.ensureDir(localFilepath);
|
|
165
|
+
logger.log(i18n(`${i18nKey}.wroteFolder`, {
|
|
180
166
|
filepath: localFilepath,
|
|
181
167
|
}));
|
|
182
168
|
}
|
|
183
169
|
catch (err) {
|
|
184
|
-
throw new
|
|
170
|
+
throw new FileSystemError({ cause: err }, {
|
|
185
171
|
filepath: localFilepath,
|
|
186
172
|
accountId,
|
|
187
173
|
operation: 'write',
|
|
@@ -192,31 +178,31 @@ async function writeFileMapperNode(accountId, filepath, node, cmsPublishMode, op
|
|
|
192
178
|
async function downloadFile(accountId, src, destPath, cmsPublishMode, options = {}) {
|
|
193
179
|
const { isFile, isHubspot } = getTypeDataFromPath(src);
|
|
194
180
|
if (!isFile) {
|
|
195
|
-
throw new Error(
|
|
181
|
+
throw new Error(i18n(`${i18nKey}.errors.invalidRequest`, { src }));
|
|
196
182
|
}
|
|
197
183
|
try {
|
|
198
|
-
const dest =
|
|
199
|
-
const cwd =
|
|
184
|
+
const dest = path.resolve(destPath);
|
|
185
|
+
const cwd = getCwd();
|
|
200
186
|
let filepath;
|
|
201
187
|
if (dest === cwd) {
|
|
202
188
|
// Dest: CWD
|
|
203
|
-
filepath =
|
|
189
|
+
filepath = path.resolve(cwd, path.basename(src));
|
|
204
190
|
}
|
|
205
191
|
else if (isPathToFile(dest)) {
|
|
206
192
|
// Dest: file path
|
|
207
|
-
filepath =
|
|
193
|
+
filepath = path.isAbsolute(dest) ? dest : path.resolve(cwd, dest);
|
|
208
194
|
}
|
|
209
195
|
else {
|
|
210
196
|
// Dest: folder path
|
|
211
|
-
const name =
|
|
212
|
-
filepath =
|
|
213
|
-
?
|
|
214
|
-
:
|
|
197
|
+
const name = path.basename(src);
|
|
198
|
+
filepath = path.isAbsolute(dest)
|
|
199
|
+
? path.resolve(dest, name)
|
|
200
|
+
: path.resolve(cwd, dest, name);
|
|
215
201
|
}
|
|
216
|
-
const localFsPath =
|
|
202
|
+
const localFsPath = convertToLocalFileSystemPath(filepath);
|
|
217
203
|
await fetchAndWriteFileStream(accountId, src, localFsPath, cmsPublishMode, options);
|
|
218
204
|
await queue.onIdle();
|
|
219
|
-
|
|
205
|
+
logger.success(i18n(`${i18nKey}.completedFetch`, {
|
|
220
206
|
src,
|
|
221
207
|
version: getAssetVersionIdentifier(options.assetVersion, src),
|
|
222
208
|
dest,
|
|
@@ -224,39 +210,38 @@ async function downloadFile(accountId, src, destPath, cmsPublishMode, options =
|
|
|
224
210
|
}
|
|
225
211
|
catch (err) {
|
|
226
212
|
const error = err;
|
|
227
|
-
if (isHubspot &&
|
|
228
|
-
throw new Error(
|
|
213
|
+
if (isHubspot && isTimeoutError(error)) {
|
|
214
|
+
throw new Error(i18n(`${i18nKey}.errors.assetTimeout`), { cause: error });
|
|
229
215
|
}
|
|
230
216
|
else {
|
|
231
|
-
throw new Error(
|
|
217
|
+
throw new Error(i18n(`${i18nKey}.errors.failedToFetchFile`, { src, dest: destPath }), { cause: error });
|
|
232
218
|
}
|
|
233
219
|
}
|
|
234
220
|
}
|
|
235
|
-
async function fetchFolderFromApi(accountId, src, cmsPublishMode, options = {}) {
|
|
221
|
+
export async function fetchFolderFromApi(accountId, src, cmsPublishMode, options = {}) {
|
|
236
222
|
const { isRoot, isFolder, isHubspot } = getTypeDataFromPath(src);
|
|
237
223
|
if (!isFolder) {
|
|
238
|
-
throw new Error(
|
|
224
|
+
throw new Error(i18n(`${i18nKey}.errors.invalidFetchFolderRequest`, {
|
|
239
225
|
src,
|
|
240
226
|
}));
|
|
241
227
|
}
|
|
242
228
|
const srcPath = isRoot ? '@root' : src;
|
|
243
229
|
const queryValues = getFileMapperQueryValues(cmsPublishMode, options);
|
|
244
230
|
const { data: node } = isHubspot
|
|
245
|
-
? await
|
|
246
|
-
: await
|
|
247
|
-
|
|
231
|
+
? await downloadDefault(accountId, srcPath, queryValues)
|
|
232
|
+
: await download(accountId, srcPath, queryValues);
|
|
233
|
+
logger.log(i18n(`${i18nKey}.folderFetch`, { src, accountId }));
|
|
248
234
|
return node;
|
|
249
235
|
}
|
|
250
|
-
exports.fetchFolderFromApi = fetchFolderFromApi;
|
|
251
236
|
async function downloadFolder(accountId, src, destPath, cmsPublishMode, options = {}) {
|
|
252
237
|
try {
|
|
253
238
|
const node = await fetchFolderFromApi(accountId, src, cmsPublishMode, options);
|
|
254
239
|
if (!node) {
|
|
255
240
|
return;
|
|
256
241
|
}
|
|
257
|
-
const dest =
|
|
258
|
-
const rootPath = dest ===
|
|
259
|
-
?
|
|
242
|
+
const dest = path.resolve(destPath);
|
|
243
|
+
const rootPath = dest === getCwd()
|
|
244
|
+
? convertToLocalFileSystemPath(path.resolve(dest, node.name))
|
|
260
245
|
: dest;
|
|
261
246
|
let success = true;
|
|
262
247
|
recurseFolder(node, (childNode, filepath) => {
|
|
@@ -264,7 +249,7 @@ async function downloadFolder(accountId, src, destPath, cmsPublishMode, options
|
|
|
264
249
|
const succeeded = await writeFileMapperNode(accountId, filepath || '', childNode, cmsPublishMode, options);
|
|
265
250
|
if (succeeded === false) {
|
|
266
251
|
success = false;
|
|
267
|
-
|
|
252
|
+
logger.debug(i18n(`${i18nKey}.errors.failedToFetchFile`, {
|
|
268
253
|
src: childNode.path,
|
|
269
254
|
dest: filepath || '',
|
|
270
255
|
}));
|
|
@@ -274,7 +259,7 @@ async function downloadFolder(accountId, src, destPath, cmsPublishMode, options
|
|
|
274
259
|
}, rootPath);
|
|
275
260
|
await queue.onIdle();
|
|
276
261
|
if (success) {
|
|
277
|
-
|
|
262
|
+
logger.success(i18n(`${i18nKey}.completedFolderFetch`, {
|
|
278
263
|
src,
|
|
279
264
|
version: getAssetVersionIdentifier(options.assetVersion, src),
|
|
280
265
|
dest,
|
|
@@ -282,16 +267,16 @@ async function downloadFolder(accountId, src, destPath, cmsPublishMode, options
|
|
|
282
267
|
}
|
|
283
268
|
else {
|
|
284
269
|
// TODO: Fix this exception. It is triggering the catch block so this error is being rewritten
|
|
285
|
-
throw new Error(
|
|
270
|
+
throw new Error(i18n(`${i18nKey}.errors.incompleteFetch`, { src }));
|
|
286
271
|
}
|
|
287
272
|
}
|
|
288
273
|
catch (err) {
|
|
289
274
|
const error = err;
|
|
290
|
-
if (
|
|
291
|
-
throw new Error(
|
|
275
|
+
if (isTimeoutError(error)) {
|
|
276
|
+
throw new Error(i18n(`${i18nKey}.errors.assetTimeout`), { cause: error });
|
|
292
277
|
}
|
|
293
278
|
else {
|
|
294
|
-
throw new Error(
|
|
279
|
+
throw new Error(i18n(`${i18nKey}.errors.failedToFetchFolder`, { src, dest: destPath }), { cause: err });
|
|
295
280
|
}
|
|
296
281
|
}
|
|
297
282
|
}
|
|
@@ -302,7 +287,7 @@ async function downloadFolder(accountId, src, destPath, cmsPublishMode, options
|
|
|
302
287
|
* @param {FileMapperInputArguments} input
|
|
303
288
|
* @returns {Promise}
|
|
304
289
|
*/
|
|
305
|
-
async function downloadFileOrFolder(accountId, src, dest, cmsPublishMode, options = {}) {
|
|
290
|
+
export async function downloadFileOrFolder(accountId, src, dest, cmsPublishMode, options = {}) {
|
|
306
291
|
if (!src) {
|
|
307
292
|
return;
|
|
308
293
|
}
|
|
@@ -314,4 +299,3 @@ async function downloadFileOrFolder(accountId, src, dest, cmsPublishMode, option
|
|
|
314
299
|
await downloadFolder(accountId, src, dest, cmsPublishMode, options);
|
|
315
300
|
}
|
|
316
301
|
}
|
|
317
|
-
exports.downloadFileOrFolder = downloadFileOrFolder;
|
package/lib/fs.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { FileData } from '../types/Files';
|
|
1
|
+
import { FileData } from '../types/Files.js';
|
|
2
2
|
export declare function getFileInfoAsync(dir: string, file: string): Promise<FileData>;
|
|
3
3
|
export declare function flattenAndRemoveSymlinks(filesData: Array<FileData>): Array<string>;
|
|
4
4
|
export declare function walk(dir: string, ignoreDirs?: string[]): Promise<Array<string>>;
|
package/lib/fs.js
CHANGED
|
@@ -1,51 +1,43 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
exports.walk = exports.flattenAndRemoveSymlinks = exports.getFileInfoAsync = void 0;
|
|
7
|
-
const fs_1 = __importDefault(require("fs"));
|
|
8
|
-
const path_1 = __importDefault(require("path"));
|
|
9
|
-
const files_1 = require("../constants/files");
|
|
10
|
-
const FileSystemError_1 = require("../models/FileSystemError");
|
|
11
|
-
function getFileInfoAsync(dir, file) {
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import { STAT_TYPES } from '../constants/files.js';
|
|
4
|
+
import { FileSystemError } from '../models/FileSystemError.js';
|
|
5
|
+
export function getFileInfoAsync(dir, file) {
|
|
12
6
|
return new Promise((resolve, reject) => {
|
|
13
|
-
const filepath =
|
|
14
|
-
|
|
7
|
+
const filepath = path.join(dir, file);
|
|
8
|
+
fs.lstat(filepath, (error, stats) => {
|
|
15
9
|
if (error) {
|
|
16
10
|
reject(error);
|
|
17
11
|
}
|
|
18
|
-
let type =
|
|
12
|
+
let type = STAT_TYPES.FILE;
|
|
19
13
|
if (stats.isSymbolicLink()) {
|
|
20
|
-
type =
|
|
14
|
+
type = STAT_TYPES.SYMBOLIC_LINK;
|
|
21
15
|
}
|
|
22
16
|
else if (stats.isDirectory()) {
|
|
23
|
-
type =
|
|
17
|
+
type = STAT_TYPES.DIRECTORY;
|
|
24
18
|
}
|
|
25
19
|
resolve({ filepath, type });
|
|
26
20
|
});
|
|
27
21
|
});
|
|
28
22
|
}
|
|
29
|
-
|
|
30
|
-
function flattenAndRemoveSymlinks(filesData) {
|
|
23
|
+
export function flattenAndRemoveSymlinks(filesData) {
|
|
31
24
|
return filesData.reduce((acc, fileData) => {
|
|
32
25
|
switch (fileData.type) {
|
|
33
|
-
case
|
|
26
|
+
case STAT_TYPES.FILE:
|
|
34
27
|
return acc.concat(fileData.filepath);
|
|
35
|
-
case
|
|
28
|
+
case STAT_TYPES.DIRECTORY:
|
|
36
29
|
return acc.concat(fileData.files || []);
|
|
37
|
-
case
|
|
30
|
+
case STAT_TYPES.SYMBOLIC_LINK:
|
|
38
31
|
return acc;
|
|
39
32
|
default:
|
|
40
33
|
return acc;
|
|
41
34
|
}
|
|
42
35
|
}, []);
|
|
43
36
|
}
|
|
44
|
-
exports.flattenAndRemoveSymlinks = flattenAndRemoveSymlinks;
|
|
45
37
|
const generateRecursiveFilePromise = async (dir, file, ignoreDirs) => {
|
|
46
38
|
return getFileInfoAsync(dir, file).then(fileData => {
|
|
47
39
|
return new Promise(resolve => {
|
|
48
|
-
if (fileData.type ===
|
|
40
|
+
if (fileData.type === STAT_TYPES.DIRECTORY) {
|
|
49
41
|
walk(fileData.filepath, ignoreDirs).then(files => {
|
|
50
42
|
resolve({ ...fileData, files });
|
|
51
43
|
});
|
|
@@ -56,7 +48,7 @@ const generateRecursiveFilePromise = async (dir, file, ignoreDirs) => {
|
|
|
56
48
|
});
|
|
57
49
|
});
|
|
58
50
|
};
|
|
59
|
-
async function walk(dir, ignoreDirs) {
|
|
51
|
+
export async function walk(dir, ignoreDirs) {
|
|
60
52
|
function processFiles(files) {
|
|
61
53
|
// If the directory is in the ignore list, return an empty array to skip the directory contents
|
|
62
54
|
if (ignoreDirs?.some(ignored => dir.includes(ignored))) {
|
|
@@ -64,12 +56,11 @@ async function walk(dir, ignoreDirs) {
|
|
|
64
56
|
}
|
|
65
57
|
return Promise.all(files.map(file => generateRecursiveFilePromise(dir, file, ignoreDirs)));
|
|
66
58
|
}
|
|
67
|
-
return
|
|
59
|
+
return fs.promises
|
|
68
60
|
.readdir(dir)
|
|
69
61
|
.then(processFiles)
|
|
70
62
|
.then(flattenAndRemoveSymlinks)
|
|
71
63
|
.catch(err => {
|
|
72
|
-
throw new
|
|
64
|
+
throw new FileSystemError({ cause: err });
|
|
73
65
|
});
|
|
74
66
|
}
|
|
75
|
-
exports.walk = walk;
|
package/lib/github.d.ts
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
/// <reference types="node" />
|
|
3
|
-
import { GithubReleaseData, GithubRepoFile, RepoPath, CloneGithubRepoOptions } from '../types/Github';
|
|
1
|
+
import { GithubReleaseData, GithubRepoFile, RepoPath, CloneGithubRepoOptions } from '../types/Github.js';
|
|
4
2
|
/**
|
|
5
3
|
* @deprecated Use `fetchRepoFile` instead - this util is a thin wrapper around it
|
|
6
4
|
*/
|