@hubspot/local-dev-lib 4.0.4 → 5.0.0-beta.1
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 -52
- 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 -37
- 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 -42
- 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 +141 -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.js +37 -43
- 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.js +14 -42
- 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 -46
- package/http/unauthed.d.ts +1 -1
- package/http/unauthed.js +15 -18
- package/lang/en.json +1 -1
- 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 +23 -29
- 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 +20 -16
- 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/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
|
*/
|
package/lib/github.js
CHANGED
|
@@ -1,38 +1,31 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
9
|
-
const archive_1 = require("./archive");
|
|
10
|
-
const logger_1 = require("./logger");
|
|
11
|
-
const github_1 = require("../api/github");
|
|
12
|
-
const lang_1 = require("../utils/lang");
|
|
13
|
-
const errors_1 = require("../errors");
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import fs from 'fs-extra';
|
|
3
|
+
import { extractZipArchive } from './archive.js';
|
|
4
|
+
import { logger } from './logger.js';
|
|
5
|
+
import { fetchRepoFile, fetchRepoFileByDownloadUrl, fetchRepoAsZip, fetchRepoReleaseData, fetchRepoContents, } from '../api/github.js';
|
|
6
|
+
import { i18n } from '../utils/lang.js';
|
|
7
|
+
import { isGithubRateLimitError, isHubSpotHttpError, isSystemError, } from '../errors/index.js';
|
|
14
8
|
const i18nKey = 'lib.github';
|
|
15
9
|
/**
|
|
16
10
|
* @deprecated Use `fetchRepoFile` instead - this util is a thin wrapper around it
|
|
17
11
|
*/
|
|
18
|
-
async function fetchFileFromRepository(repoPath, filePath, ref) {
|
|
12
|
+
export async function fetchFileFromRepository(repoPath, filePath, ref) {
|
|
19
13
|
try {
|
|
20
|
-
|
|
14
|
+
logger.debug(i18n(`${i18nKey}.fetchFileFromRepository.fetching`, {
|
|
21
15
|
path: `${repoPath}/${ref}/${filePath}`,
|
|
22
16
|
}));
|
|
23
|
-
const { data } = await
|
|
17
|
+
const { data } = await fetchRepoFile(repoPath, filePath, ref);
|
|
24
18
|
return data;
|
|
25
19
|
}
|
|
26
20
|
catch (err) {
|
|
27
21
|
checkGithubRateLimit(err);
|
|
28
|
-
throw new Error(
|
|
22
|
+
throw new Error(i18n(`${i18nKey}.fetchFileFromRepository.errors.fetchFail`), {
|
|
29
23
|
cause: err,
|
|
30
24
|
});
|
|
31
25
|
}
|
|
32
26
|
}
|
|
33
|
-
exports.fetchFileFromRepository = fetchFileFromRepository;
|
|
34
27
|
// Fetches information about a specific release (Defaults to latest)
|
|
35
|
-
async function fetchReleaseData(repoPath, tag) {
|
|
28
|
+
export async function fetchReleaseData(repoPath, tag) {
|
|
36
29
|
if (tag) {
|
|
37
30
|
tag = tag.trim().toLowerCase();
|
|
38
31
|
if (tag.length && tag[0] !== 'v') {
|
|
@@ -40,17 +33,16 @@ async function fetchReleaseData(repoPath, tag) {
|
|
|
40
33
|
}
|
|
41
34
|
}
|
|
42
35
|
try {
|
|
43
|
-
const { data } = await
|
|
36
|
+
const { data } = await fetchRepoReleaseData(repoPath, tag);
|
|
44
37
|
return data;
|
|
45
38
|
}
|
|
46
39
|
catch (err) {
|
|
47
40
|
checkGithubRateLimit(err);
|
|
48
|
-
throw new Error(
|
|
41
|
+
throw new Error(i18n(`${i18nKey}.fetchReleaseData.errors.fetchFail`, {
|
|
49
42
|
tag: tag || 'latest',
|
|
50
43
|
}), { cause: err });
|
|
51
44
|
}
|
|
52
45
|
}
|
|
53
|
-
exports.fetchReleaseData = fetchReleaseData;
|
|
54
46
|
async function downloadGithubRepoZip(repoPath, isRelease = false, options = {}) {
|
|
55
47
|
const { branch, tag } = options;
|
|
56
48
|
try {
|
|
@@ -61,48 +53,47 @@ async function downloadGithubRepoZip(repoPath, isRelease = false, options = {})
|
|
|
61
53
|
const releaseData = await fetchReleaseData(repoPath, tag);
|
|
62
54
|
zipUrl = releaseData.zipball_url;
|
|
63
55
|
const { name } = releaseData;
|
|
64
|
-
|
|
56
|
+
logger.debug(i18n(`${i18nKey}.downloadGithubRepoZip.fetchingName`, { name }));
|
|
65
57
|
}
|
|
66
58
|
else {
|
|
67
59
|
// If downloading a repository, manually construct the zip url. This url supports both branches and tags as refs
|
|
68
|
-
|
|
60
|
+
logger.debug(i18n(`${i18nKey}.downloadGithubRepoZip.fetching`, { repoPath }));
|
|
69
61
|
const ref = branch || tag;
|
|
70
62
|
zipUrl = `https://api.github.com/repos/${repoPath}/zipball${ref ? `/${ref}` : ''}`;
|
|
71
63
|
}
|
|
72
|
-
const { data } = await
|
|
73
|
-
|
|
64
|
+
const { data } = await fetchRepoAsZip(zipUrl);
|
|
65
|
+
logger.debug(i18n(`${i18nKey}.downloadGithubRepoZip.completed`));
|
|
74
66
|
return data;
|
|
75
67
|
}
|
|
76
68
|
catch (err) {
|
|
77
69
|
checkGithubRateLimit(err);
|
|
78
|
-
throw new Error(
|
|
70
|
+
throw new Error(i18n(`${i18nKey}.downloadGithubRepoZip.errors.fetchFail`), {
|
|
79
71
|
cause: err,
|
|
80
72
|
});
|
|
81
73
|
}
|
|
82
74
|
}
|
|
83
|
-
async function cloneGithubRepo(repoPath, dest, options = {}) {
|
|
75
|
+
export async function cloneGithubRepo(repoPath, dest, options = {}) {
|
|
84
76
|
const { tag, isRelease, branch, sourceDir, type, hideLogs, handleCollision } = options;
|
|
85
77
|
const zip = await downloadGithubRepoZip(repoPath, isRelease, {
|
|
86
78
|
tag,
|
|
87
79
|
branch,
|
|
88
80
|
});
|
|
89
81
|
const repoName = repoPath.split('/')[1];
|
|
90
|
-
const success = await
|
|
82
|
+
const success = await extractZipArchive(zip, repoName, dest, {
|
|
91
83
|
sourceDir,
|
|
92
84
|
hideLogs,
|
|
93
85
|
handleCollision,
|
|
94
86
|
});
|
|
95
87
|
if (success && !hideLogs) {
|
|
96
|
-
|
|
88
|
+
logger.log(i18n(`${i18nKey}.cloneGithubRepo.success`, {
|
|
97
89
|
type: type || '',
|
|
98
90
|
dest,
|
|
99
91
|
}));
|
|
100
92
|
}
|
|
101
93
|
return success;
|
|
102
94
|
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
const resp = await (0, github_1.fetchRepoFileByDownloadUrl)(downloadUrl);
|
|
95
|
+
export async function fetchGitHubRepoContentFromDownloadUrl(dest, downloadUrl) {
|
|
96
|
+
const resp = await fetchRepoFileByDownloadUrl(downloadUrl);
|
|
106
97
|
const contentType = resp.headers['content-type'];
|
|
107
98
|
let fileContents;
|
|
108
99
|
if (contentType.startsWith('text')) {
|
|
@@ -111,30 +102,29 @@ async function fetchGitHubRepoContentFromDownloadUrl(dest, downloadUrl) {
|
|
|
111
102
|
else {
|
|
112
103
|
fileContents = resp.data;
|
|
113
104
|
}
|
|
114
|
-
|
|
105
|
+
fs.outputFileSync(dest, fileContents);
|
|
115
106
|
}
|
|
116
|
-
exports.fetchGitHubRepoContentFromDownloadUrl = fetchGitHubRepoContentFromDownloadUrl;
|
|
117
107
|
/**
|
|
118
108
|
* Writes files from a public repository to the destination folder
|
|
119
109
|
@deprecated - This method fetches all the files individually, which can hit rate limits for unauthorized requests. Use `cloneGithubRepo` instead.
|
|
120
110
|
*/
|
|
121
|
-
async function downloadGithubRepoContents(repoPath, contentPath, dest, ref, filter) {
|
|
122
|
-
|
|
111
|
+
export async function downloadGithubRepoContents(repoPath, contentPath, dest, ref, filter) {
|
|
112
|
+
fs.ensureDirSync(path.dirname(dest));
|
|
123
113
|
try {
|
|
124
|
-
const { data: contentsResp } = await
|
|
114
|
+
const { data: contentsResp } = await fetchRepoContents(repoPath, contentPath, ref);
|
|
125
115
|
const downloadContent = async (contentPiece) => {
|
|
126
116
|
const { path: contentPiecePath, download_url, type: contentPieceType, } = contentPiece;
|
|
127
|
-
const downloadPath =
|
|
117
|
+
const downloadPath = path.join(dest, contentPiecePath.replace(contentPath, ''));
|
|
128
118
|
if (filter && !filter(contentPiecePath, downloadPath)) {
|
|
129
119
|
return Promise.resolve();
|
|
130
120
|
}
|
|
131
|
-
|
|
121
|
+
logger.debug(i18n(`${i18nKey}.downloadGithubRepoContents.downloading`, {
|
|
132
122
|
contentPiecePath,
|
|
133
123
|
downloadUrl: download_url,
|
|
134
124
|
downloadPath,
|
|
135
125
|
}));
|
|
136
126
|
if (contentPieceType === 'dir') {
|
|
137
|
-
const { data: innerDirContent } = await
|
|
127
|
+
const { data: innerDirContent } = await fetchRepoContents(repoPath, contentPiecePath, ref);
|
|
138
128
|
await Promise.all(innerDirContent.map(downloadContent));
|
|
139
129
|
return Promise.resolve();
|
|
140
130
|
}
|
|
@@ -151,19 +141,18 @@ async function downloadGithubRepoContents(repoPath, contentPath, dest, ref, filt
|
|
|
151
141
|
}
|
|
152
142
|
catch (e) {
|
|
153
143
|
checkGithubRateLimit(e);
|
|
154
|
-
if (
|
|
155
|
-
throw new Error(
|
|
144
|
+
if (isSystemError(e) && e?.error?.message) {
|
|
145
|
+
throw new Error(i18n(`${i18nKey}.downloadGithubRepoContents.errors.fetchFail`, {
|
|
156
146
|
errorMessage: e.error.message,
|
|
157
147
|
}), { cause: e });
|
|
158
148
|
}
|
|
159
149
|
throw e;
|
|
160
150
|
}
|
|
161
151
|
}
|
|
162
|
-
exports.downloadGithubRepoContents = downloadGithubRepoContents;
|
|
163
152
|
// Lists content from a public repository at the specified path
|
|
164
|
-
async function listGithubRepoContents(repoPath, contentPath, fileFilter) {
|
|
153
|
+
export async function listGithubRepoContents(repoPath, contentPath, fileFilter) {
|
|
165
154
|
try {
|
|
166
|
-
const { data: contentsResp } = await
|
|
155
|
+
const { data: contentsResp } = await fetchRepoContents(repoPath, contentPath);
|
|
167
156
|
const filteredFiles = fileFilter && fileFilter != undefined
|
|
168
157
|
? contentsResp.filter(item => item.type === fileFilter)
|
|
169
158
|
: contentsResp;
|
|
@@ -171,18 +160,17 @@ async function listGithubRepoContents(repoPath, contentPath, fileFilter) {
|
|
|
171
160
|
}
|
|
172
161
|
catch (e) {
|
|
173
162
|
checkGithubRateLimit(e);
|
|
174
|
-
if (
|
|
175
|
-
throw new Error(
|
|
163
|
+
if (isHubSpotHttpError(e) && e.data.message) {
|
|
164
|
+
throw new Error(i18n(`${i18nKey}.downloadGithubRepoContents.errors.fetchFail`, {
|
|
176
165
|
errorMessage: e.data.message,
|
|
177
166
|
}));
|
|
178
167
|
}
|
|
179
168
|
throw e;
|
|
180
169
|
}
|
|
181
170
|
}
|
|
182
|
-
exports.listGithubRepoContents = listGithubRepoContents;
|
|
183
171
|
function checkGithubRateLimit(err) {
|
|
184
|
-
if (
|
|
185
|
-
throw new Error(
|
|
172
|
+
if (isGithubRateLimitError(err)) {
|
|
173
|
+
throw new Error(i18n(`${i18nKey}.rateLimitError`), {
|
|
186
174
|
cause: err,
|
|
187
175
|
});
|
|
188
176
|
}
|
package/lib/gitignore.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { GitInclusionResult } from '../types/Config';
|
|
1
|
+
import { GitInclusionResult } from '../types/Config.js';
|
|
2
2
|
export declare function checkAndAddConfigToGitignore(configPath: string): void;
|
|
3
3
|
export declare function checkGitInclusion(configPath: string): GitInclusionResult;
|
package/lib/gitignore.js
CHANGED
|
@@ -1,49 +1,41 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
exports.checkGitInclusion = exports.checkAndAddConfigToGitignore = void 0;
|
|
7
|
-
const fs_extra_1 = require("fs-extra");
|
|
8
|
-
const path_1 = __importDefault(require("path"));
|
|
9
|
-
const git_1 = require("../utils/git");
|
|
10
|
-
const config_1 = require("../constants/config");
|
|
11
|
-
const lang_1 = require("../utils/lang");
|
|
1
|
+
import fs from 'fs-extra';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import { isConfigPathInGitRepo, getGitignoreFiles, configFilenameIsIgnoredByGitignore, } from '../utils/git.js';
|
|
4
|
+
import { DEFAULT_HUBSPOT_CONFIG_YAML_FILE_NAME } from '../constants/config.js';
|
|
5
|
+
import { i18n } from '../utils/lang.js';
|
|
12
6
|
const i18nKey = 'lib.gitignore';
|
|
13
7
|
const GITIGNORE_FILE = '.gitignore';
|
|
14
|
-
function checkAndAddConfigToGitignore(configPath) {
|
|
8
|
+
export function checkAndAddConfigToGitignore(configPath) {
|
|
15
9
|
try {
|
|
16
10
|
const { configIgnored, gitignoreFiles } = checkGitInclusion(configPath);
|
|
17
11
|
if (configIgnored)
|
|
18
12
|
return;
|
|
19
13
|
let gitignoreFilePath = gitignoreFiles && gitignoreFiles.length ? gitignoreFiles[0] : null;
|
|
20
14
|
if (!gitignoreFilePath) {
|
|
21
|
-
gitignoreFilePath =
|
|
22
|
-
|
|
15
|
+
gitignoreFilePath = path.join(path.dirname(configPath), GITIGNORE_FILE);
|
|
16
|
+
fs.writeFileSync(gitignoreFilePath, '');
|
|
23
17
|
}
|
|
24
|
-
const gitignoreContents =
|
|
25
|
-
const updatedContents = `${gitignoreContents.trim()}\n\n# HubSpot config file\n${
|
|
26
|
-
|
|
18
|
+
const gitignoreContents = fs.readFileSync(gitignoreFilePath).toString();
|
|
19
|
+
const updatedContents = `${gitignoreContents.trim()}\n\n# HubSpot config file\n${DEFAULT_HUBSPOT_CONFIG_YAML_FILE_NAME}\n`;
|
|
20
|
+
fs.writeFileSync(gitignoreFilePath, updatedContents);
|
|
27
21
|
}
|
|
28
22
|
catch (e) {
|
|
29
|
-
throw new Error(
|
|
23
|
+
throw new Error(i18n(`${i18nKey}.errors.configIgnore`), { cause: e });
|
|
30
24
|
}
|
|
31
25
|
}
|
|
32
|
-
|
|
33
|
-
function checkGitInclusion(configPath) {
|
|
26
|
+
export function checkGitInclusion(configPath) {
|
|
34
27
|
const result = {
|
|
35
28
|
inGit: false,
|
|
36
29
|
configIgnored: false,
|
|
37
30
|
gitignoreFiles: [],
|
|
38
31
|
};
|
|
39
|
-
if (
|
|
32
|
+
if (isConfigPathInGitRepo(configPath)) {
|
|
40
33
|
result.inGit = true;
|
|
41
|
-
result.gitignoreFiles =
|
|
42
|
-
if (
|
|
34
|
+
result.gitignoreFiles = getGitignoreFiles(configPath);
|
|
35
|
+
if (configFilenameIsIgnoredByGitignore(result.gitignoreFiles, configPath)) {
|
|
43
36
|
// Found ignore statement in .gitignore that matches config filename
|
|
44
37
|
result.configIgnored = true;
|
|
45
38
|
}
|
|
46
39
|
}
|
|
47
40
|
return result;
|
|
48
41
|
}
|
|
49
|
-
exports.checkGitInclusion = checkGitInclusion;
|
package/lib/hubdb.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AxiosResponse } from 'axios';
|
|
2
|
-
import { Row, Table } from '../types/Hubdb';
|
|
2
|
+
import { Row, Table } from '../types/Hubdb.js';
|
|
3
3
|
export declare function addRowsToHubDbTable(accountId: number, tableId: string, rows?: Array<Row>): Promise<{
|
|
4
4
|
tableId: string;
|
|
5
5
|
rowCount: number;
|
package/lib/hubdb.js
CHANGED
|
@@ -1,37 +1,31 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const path_1 = __importDefault(require("path"));
|
|
8
|
-
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
9
|
-
const prettier_1 = __importDefault(require("prettier"));
|
|
10
|
-
const hubdb_1 = require("../api/hubdb");
|
|
11
|
-
const path_2 = require("./path");
|
|
12
|
-
const lang_1 = require("../utils/lang");
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import fs from 'fs-extra';
|
|
3
|
+
import { format } from 'prettier';
|
|
4
|
+
import { createTable, updateTable, createRows, fetchTable, fetchRows, publishTable, deleteRows, } from '../api/hubdb.js';
|
|
5
|
+
import { getCwd } from './path.js';
|
|
6
|
+
import { i18n } from '../utils/lang.js';
|
|
13
7
|
const i18nKey = 'lib.hubdb';
|
|
14
8
|
function validateJsonPath(src) {
|
|
15
|
-
if (
|
|
16
|
-
throw new Error(
|
|
9
|
+
if (path.extname(src) !== '.json') {
|
|
10
|
+
throw new Error(i18n(`${i18nKey}.errors.invalidJsonPath`));
|
|
17
11
|
}
|
|
18
12
|
}
|
|
19
13
|
function validateJsonFile(src) {
|
|
20
14
|
let stats;
|
|
21
15
|
try {
|
|
22
|
-
stats =
|
|
16
|
+
stats = fs.statSync(src);
|
|
23
17
|
}
|
|
24
18
|
catch (err) {
|
|
25
|
-
throw new Error(
|
|
19
|
+
throw new Error(i18n(`${i18nKey}.errors.invalidJsonFile`, { src }), {
|
|
26
20
|
cause: err,
|
|
27
21
|
});
|
|
28
22
|
}
|
|
29
23
|
if (!stats.isFile()) {
|
|
30
|
-
throw new Error(
|
|
24
|
+
throw new Error(i18n(`${i18nKey}.errors.invalidJsonFile`, { src }));
|
|
31
25
|
}
|
|
32
26
|
validateJsonPath(src);
|
|
33
27
|
}
|
|
34
|
-
async function addRowsToHubDbTable(accountId, tableId, rows = []) {
|
|
28
|
+
export async function addRowsToHubDbTable(accountId, tableId, rows = []) {
|
|
35
29
|
const rowsToUpdate = rows.map(row => {
|
|
36
30
|
const values = row.values;
|
|
37
31
|
return {
|
|
@@ -42,30 +36,27 @@ async function addRowsToHubDbTable(accountId, tableId, rows = []) {
|
|
|
42
36
|
};
|
|
43
37
|
});
|
|
44
38
|
if (rowsToUpdate.length > 0) {
|
|
45
|
-
await
|
|
39
|
+
await createRows(accountId, tableId, rowsToUpdate);
|
|
46
40
|
}
|
|
47
|
-
const { data: { rowCount }, } = await
|
|
41
|
+
const { data: { rowCount }, } = await publishTable(accountId, tableId);
|
|
48
42
|
return {
|
|
49
43
|
tableId,
|
|
50
44
|
rowCount,
|
|
51
45
|
};
|
|
52
46
|
}
|
|
53
|
-
|
|
54
|
-
async function createHubDbTable(accountId, src) {
|
|
47
|
+
export async function createHubDbTable(accountId, src) {
|
|
55
48
|
validateJsonFile(src);
|
|
56
|
-
const table =
|
|
49
|
+
const table = fs.readJsonSync(src);
|
|
57
50
|
const { rows, ...schema } = table;
|
|
58
|
-
const { data: { id }, } = await
|
|
51
|
+
const { data: { id }, } = await createTable(accountId, schema);
|
|
59
52
|
return addRowsToHubDbTable(accountId, id, rows);
|
|
60
53
|
}
|
|
61
|
-
|
|
62
|
-
async function updateHubDbTable(accountId, tableId, src) {
|
|
54
|
+
export async function updateHubDbTable(accountId, tableId, src) {
|
|
63
55
|
validateJsonFile(src);
|
|
64
|
-
const table =
|
|
56
|
+
const table = fs.readJsonSync(src);
|
|
65
57
|
const { ...schema } = table;
|
|
66
|
-
return
|
|
58
|
+
return updateTable(accountId, tableId, schema);
|
|
67
59
|
}
|
|
68
|
-
exports.updateHubDbTable = updateHubDbTable;
|
|
69
60
|
function convertToJSON(table, rows) {
|
|
70
61
|
const { allowChildTables, allowPublicApiAccess, columns, dynamicMetaTags, enableChildTablePages, label, name, useForPages, } = table;
|
|
71
62
|
const cleanedColumns = columns
|
|
@@ -98,17 +89,17 @@ async function fetchAllRows(accountId, tableId) {
|
|
|
98
89
|
let rows = [];
|
|
99
90
|
let after = null;
|
|
100
91
|
do {
|
|
101
|
-
const axiosResponse = await
|
|
92
|
+
const axiosResponse = await fetchRows(accountId, tableId, after ? { after } : undefined);
|
|
102
93
|
const { paging, results } = axiosResponse.data;
|
|
103
94
|
rows = rows.concat(results);
|
|
104
95
|
after = paging && paging.next ? paging.next.after : null;
|
|
105
96
|
} while (after !== null);
|
|
106
97
|
return rows;
|
|
107
98
|
}
|
|
108
|
-
async function downloadHubDbTable(accountId, tableId, dest) {
|
|
109
|
-
const { data: table } = await
|
|
110
|
-
dest =
|
|
111
|
-
if (
|
|
99
|
+
export async function downloadHubDbTable(accountId, tableId, dest) {
|
|
100
|
+
const { data: table } = await fetchTable(accountId, tableId);
|
|
101
|
+
dest = path.resolve(getCwd(), dest || `${table.name}.hubdb.json`);
|
|
102
|
+
if (fs.pathExistsSync(dest)) {
|
|
112
103
|
validateJsonFile(dest);
|
|
113
104
|
}
|
|
114
105
|
else {
|
|
@@ -116,18 +107,16 @@ async function downloadHubDbTable(accountId, tableId, dest) {
|
|
|
116
107
|
}
|
|
117
108
|
const rows = await fetchAllRows(accountId, tableId);
|
|
118
109
|
const tableToWrite = JSON.stringify(convertToJSON(table, rows));
|
|
119
|
-
const tableJson = await
|
|
110
|
+
const tableJson = await format(tableToWrite, {
|
|
120
111
|
parser: 'json',
|
|
121
112
|
});
|
|
122
|
-
await
|
|
113
|
+
await fs.outputFile(dest, tableJson);
|
|
123
114
|
return { filePath: dest };
|
|
124
115
|
}
|
|
125
|
-
|
|
126
|
-
async function clearHubDbTableRows(accountId, tableId) {
|
|
116
|
+
export async function clearHubDbTableRows(accountId, tableId) {
|
|
127
117
|
const rows = await fetchAllRows(accountId, tableId);
|
|
128
|
-
await
|
|
118
|
+
await deleteRows(accountId, tableId, rows.map(row => row.id));
|
|
129
119
|
return {
|
|
130
120
|
deletedRowCount: rows.length,
|
|
131
121
|
};
|
|
132
122
|
}
|
|
133
|
-
exports.clearHubDbTableRows = clearHubDbTableRows;
|
package/lib/ignoreRules.js
CHANGED
|
@@ -1,36 +1,30 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.ignoreFile = exports.createIgnoreFilter = exports.shouldIgnoreFile = void 0;
|
|
7
|
-
const fs_1 = __importDefault(require("fs"));
|
|
8
|
-
const path_1 = __importDefault(require("path"));
|
|
9
|
-
const ignore_1 = __importDefault(require("ignore"));
|
|
10
|
-
const findup_sync_1 = __importDefault(require("findup-sync"));
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import ignore from 'ignore';
|
|
4
|
+
import findup from 'findup-sync';
|
|
11
5
|
const ignoreList = [
|
|
12
6
|
'fields.output.json',
|
|
13
7
|
'hubspot.config.yml',
|
|
14
8
|
'hubspot.config.yaml',
|
|
15
|
-
'node_modules',
|
|
16
|
-
'.*',
|
|
17
|
-
'*.log',
|
|
18
|
-
'*.swp',
|
|
19
|
-
'.env',
|
|
9
|
+
'node_modules', // dependencies
|
|
10
|
+
'.*', // hidden files/folders
|
|
11
|
+
'*.log', // Error log for npm
|
|
12
|
+
'*.swp', // Swap file for vim state
|
|
13
|
+
'.env', // Dotenv file
|
|
20
14
|
// # macOS
|
|
21
|
-
'Icon\\r',
|
|
22
|
-
'__MACOSX',
|
|
15
|
+
'Icon\\r', // Custom Finder icon: http://superuser.com/questions/298785/icon-file-on-os-x-desktop
|
|
16
|
+
'__MACOSX', // Resource fork
|
|
23
17
|
// # Linux
|
|
24
|
-
'~',
|
|
18
|
+
'~', // Backup file
|
|
25
19
|
// # Emacs
|
|
26
|
-
'*~',
|
|
20
|
+
'*~', // Backup file
|
|
27
21
|
// # Windows
|
|
28
|
-
'Thumbs.db',
|
|
29
|
-
'ehthumbs.db',
|
|
30
|
-
'Desktop.ini',
|
|
22
|
+
'Thumbs.db', // Image file cache
|
|
23
|
+
'ehthumbs.db', // Folder config file
|
|
24
|
+
'Desktop.ini', // Stores custom folder attributes
|
|
31
25
|
'@eaDir', // Synology Diskstation "hidden" folder where the server stores thumbnails
|
|
32
26
|
];
|
|
33
|
-
const ignoreRules = (
|
|
27
|
+
const ignoreRules = ignore().add(ignoreList);
|
|
34
28
|
let searchDomain = null;
|
|
35
29
|
let loaded = false;
|
|
36
30
|
function loadIgnoreConfig(isInProject = false) {
|
|
@@ -42,28 +36,25 @@ function loadIgnoreConfig(isInProject = false) {
|
|
|
42
36
|
if (!isInProject) {
|
|
43
37
|
ignoreRules.add('package-lock.json');
|
|
44
38
|
}
|
|
45
|
-
const file = (
|
|
39
|
+
const file = findup('.hsignore');
|
|
46
40
|
if (file) {
|
|
47
|
-
if (
|
|
48
|
-
ignoreRules.add(
|
|
49
|
-
searchDomain =
|
|
41
|
+
if (fs.existsSync(file)) {
|
|
42
|
+
ignoreRules.add(fs.readFileSync(file).toString());
|
|
43
|
+
searchDomain = path.dirname(file);
|
|
50
44
|
}
|
|
51
45
|
}
|
|
52
46
|
loaded = true;
|
|
53
47
|
}
|
|
54
|
-
function shouldIgnoreFile(file, isInProject = false) {
|
|
48
|
+
export function shouldIgnoreFile(file, isInProject = false) {
|
|
55
49
|
loadIgnoreConfig(isInProject);
|
|
56
50
|
const relativeTo = searchDomain || '/';
|
|
57
|
-
const relativePath =
|
|
51
|
+
const relativePath = path.relative(relativeTo, file);
|
|
58
52
|
return !!relativePath && ignoreRules.ignores(relativePath);
|
|
59
53
|
}
|
|
60
|
-
|
|
61
|
-
function createIgnoreFilter(isInProject) {
|
|
54
|
+
export function createIgnoreFilter(isInProject) {
|
|
62
55
|
loadIgnoreConfig(isInProject);
|
|
63
56
|
return (file) => !shouldIgnoreFile(file);
|
|
64
57
|
}
|
|
65
|
-
|
|
66
|
-
function ignoreFile(filePath) {
|
|
58
|
+
export function ignoreFile(filePath) {
|
|
67
59
|
ignoreRules.add(filePath);
|
|
68
60
|
}
|
|
69
|
-
exports.ignoreFile = ignoreFile;
|
package/lib/isDeepEqual.js
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isDeepEqual = void 0;
|
|
4
|
-
function isDeepEqual(object1, object2, ignoreKeys) {
|
|
1
|
+
export function isDeepEqual(object1, object2, ignoreKeys) {
|
|
5
2
|
if (object1 === object2) {
|
|
6
3
|
return true;
|
|
7
4
|
}
|
|
@@ -32,4 +29,3 @@ function isDeepEqual(object1, object2, ignoreKeys) {
|
|
|
32
29
|
}
|
|
33
30
|
return true;
|
|
34
31
|
}
|
|
35
|
-
exports.isDeepEqual = isDeepEqual;
|