@hubspot/local-dev-lib 0.2.4 → 0.3.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/sandboxHubs.d.ts +1 -1
- package/config/CLIConfiguration.d.ts +4 -4
- package/config/CLIConfiguration.js +42 -33
- package/config/configFile.js +5 -4
- package/config/configUtils.js +3 -2
- package/config/config_DEPRECATED.d.ts +2 -1
- package/config/config_DEPRECATED.js +23 -3
- package/config/environment.js +5 -4
- package/config/index.d.ts +2 -1
- package/config/index.js +8 -1
- package/constants/config.d.ts +7 -0
- package/constants/config.js +8 -1
- package/errors/apiErrors.d.ts +7 -2
- package/errors/apiErrors.js +12 -11
- package/errors/standardErrors.d.ts +1 -1
- package/http/index.d.ts +2 -4
- package/http/index.js +6 -7
- package/lang/en.json +10 -10
- package/lang/lang/en.json +10 -10
- package/lib/archive.d.ts +1 -3
- package/lib/archive.js +14 -16
- package/lib/cms/functions.d.ts +1 -3
- package/lib/cms/functions.js +25 -32
- package/lib/cms/handleFieldsJS.js +6 -5
- package/lib/cms/modules.d.ts +2 -3
- package/lib/cms/modules.js +16 -9
- package/lib/cms/templates.d.ts +1 -3
- package/lib/cms/templates.js +6 -7
- package/lib/cms/uploadFolder.d.ts +1 -3
- package/lib/cms/uploadFolder.js +14 -16
- package/lib/cms/watch.d.ts +1 -4
- package/lib/cms/watch.js +34 -47
- package/lib/fileManager.d.ts +2 -6
- package/lib/fileManager.js +31 -42
- package/lib/fileMapper.d.ts +2 -4
- package/lib/fileMapper.js +24 -35
- package/lib/github.d.ts +3 -4
- package/lib/github.js +35 -14
- package/lib/oauth.d.ts +1 -4
- package/lib/oauth.js +6 -8
- package/lib/personalAccessKey.js +19 -2
- package/lib/sandboxes.d.ts +1 -1
- package/lib/sandboxes.js +7 -8
- package/lib/trackUsage.js +5 -4
- package/models/OAuth2Manager.js +8 -7
- package/package.json +1 -1
- package/types/Accounts.d.ts +5 -0
- package/types/Sandbox.d.ts +13 -12
- package/utils/PortManagerServer.js +7 -7
- package/types/LogCallbacks.d.ts +0 -7
- package/types/LogCallbacks.js +0 -2
- package/utils/logger.d.ts +0 -5
- package/utils/logger.js +0 -23
package/lang/en.json
CHANGED
|
@@ -57,6 +57,11 @@
|
|
|
57
57
|
"errors": {
|
|
58
58
|
"fetchFail": "Failed to fetch contents: {{ errorMessage }}"
|
|
59
59
|
}
|
|
60
|
+
},
|
|
61
|
+
"listGitHubRepoContents": {
|
|
62
|
+
"errors": {
|
|
63
|
+
"fetchFail": "Failed to fetch contents: {{ errorMessage }}"
|
|
64
|
+
}
|
|
60
65
|
}
|
|
61
66
|
},
|
|
62
67
|
"hubdb": {
|
|
@@ -71,16 +76,6 @@
|
|
|
71
76
|
"invalidPersonalAccessKey": "Error while retrieving new access token: {{ errorMessage }}"
|
|
72
77
|
}
|
|
73
78
|
},
|
|
74
|
-
"sandboxes": {
|
|
75
|
-
"errors": {
|
|
76
|
-
"createSandbox": "There was an error creating your sandbox.",
|
|
77
|
-
"deleteSandbox": "There was an error deleting your sandbox.",
|
|
78
|
-
"getSandboxUsageLimits": "There was an error fetching sandbox usage limits.",
|
|
79
|
-
"initiateSync": "There was an error initiating the sandbox sync.",
|
|
80
|
-
"fetchTaskStatus": "There was an error fetching the task status while syncing sandboxes.",
|
|
81
|
-
"fetchTypes": "There was an error fetching sandbox types."
|
|
82
|
-
}
|
|
83
|
-
},
|
|
84
79
|
"cms": {
|
|
85
80
|
"modules": {
|
|
86
81
|
"createModule": {
|
|
@@ -92,6 +87,11 @@
|
|
|
92
87
|
"fileReadFailure": "Failed to read file at {{ path }}",
|
|
93
88
|
"failedToWrite": "failed to write to file at {{ path }}"
|
|
94
89
|
}
|
|
90
|
+
},
|
|
91
|
+
"retrieveDefaultModule": {
|
|
92
|
+
"errors": {
|
|
93
|
+
"pathExists": "Folder already exists at \"{{ path }}\""
|
|
94
|
+
}
|
|
95
95
|
}
|
|
96
96
|
},
|
|
97
97
|
"functions": {
|
package/lang/lang/en.json
CHANGED
|
@@ -57,6 +57,11 @@
|
|
|
57
57
|
"errors": {
|
|
58
58
|
"fetchFail": "Failed to fetch contents: {{ errorMessage }}"
|
|
59
59
|
}
|
|
60
|
+
},
|
|
61
|
+
"listGitHubRepoContents": {
|
|
62
|
+
"errors": {
|
|
63
|
+
"fetchFail": "Failed to fetch contents: {{ errorMessage }}"
|
|
64
|
+
}
|
|
60
65
|
}
|
|
61
66
|
},
|
|
62
67
|
"hubdb": {
|
|
@@ -71,16 +76,6 @@
|
|
|
71
76
|
"invalidPersonalAccessKey": "Error while retrieving new access token: {{ errorMessage }}"
|
|
72
77
|
}
|
|
73
78
|
},
|
|
74
|
-
"sandboxes": {
|
|
75
|
-
"errors": {
|
|
76
|
-
"createSandbox": "There was an error creating your sandbox.",
|
|
77
|
-
"deleteSandbox": "There was an error deleting your sandbox.",
|
|
78
|
-
"getSandboxUsageLimits": "There was an error fetching sandbox usage limits.",
|
|
79
|
-
"initiateSync": "There was an error initiating the sandbox sync.",
|
|
80
|
-
"fetchTaskStatus": "There was an error fetching the task status while syncing sandboxes.",
|
|
81
|
-
"fetchTypes": "There was an error fetching sandbox types."
|
|
82
|
-
}
|
|
83
|
-
},
|
|
84
79
|
"cms": {
|
|
85
80
|
"modules": {
|
|
86
81
|
"createModule": {
|
|
@@ -92,6 +87,11 @@
|
|
|
92
87
|
"fileReadFailure": "Failed to read file at {{ path }}",
|
|
93
88
|
"failedToWrite": "failed to write to file at {{ path }}"
|
|
94
89
|
}
|
|
90
|
+
},
|
|
91
|
+
"retrieveDefaultModule": {
|
|
92
|
+
"errors": {
|
|
93
|
+
"pathExists": "Folder already exists at \"{{ path }}\""
|
|
94
|
+
}
|
|
95
95
|
}
|
|
96
96
|
},
|
|
97
97
|
"functions": {
|
package/lib/archive.d.ts
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import { LogCallbacksArg } from '../types/LogCallbacks';
|
|
3
|
-
declare const archiveCallbackKeys: readonly ["init", "copy"];
|
|
4
2
|
type CopySourceToDestOptions = {
|
|
5
3
|
sourceDir?: string;
|
|
6
4
|
includesRootDir?: boolean;
|
|
7
5
|
};
|
|
8
|
-
export declare function extractZipArchive(zip: Buffer, name: string, dest: string, { sourceDir, includesRootDir }?: CopySourceToDestOptions
|
|
6
|
+
export declare function extractZipArchive(zip: Buffer, name: string, dest: string, { sourceDir, includesRootDir }?: CopySourceToDestOptions): Promise<boolean>;
|
|
9
7
|
export {};
|
package/lib/archive.js
CHANGED
|
@@ -10,14 +10,13 @@ const os_1 = require("os");
|
|
|
10
10
|
const extract_zip_1 = __importDefault(require("extract-zip"));
|
|
11
11
|
const fileSystemErrors_1 = require("../errors/fileSystemErrors");
|
|
12
12
|
const standardErrors_1 = require("../errors/standardErrors");
|
|
13
|
-
const logger_1 = require("
|
|
13
|
+
const logger_1 = require("./logging/logger");
|
|
14
|
+
const lang_1 = require("../utils/lang");
|
|
14
15
|
const i18nKey = 'lib.archive';
|
|
15
|
-
|
|
16
|
-
async function extractZip(name, zip, logCallbacks) {
|
|
17
|
-
const logger = (0, logger_1.makeTypedLogger)(logCallbacks);
|
|
16
|
+
async function extractZip(name, zip) {
|
|
18
17
|
const result = { extractDir: '', tmpDir: '' };
|
|
19
18
|
const TMP_FOLDER_PREFIX = `hubspot-temp-${name}-`;
|
|
20
|
-
logger(
|
|
19
|
+
logger_1.logger.log((0, lang_1.i18n)(`${i18nKey}.extractZip.init`));
|
|
21
20
|
// Write zip to disk
|
|
22
21
|
let tmpZipPath = '';
|
|
23
22
|
try {
|
|
@@ -49,19 +48,18 @@ async function extractZip(name, zip, logCallbacks) {
|
|
|
49
48
|
catch (err) {
|
|
50
49
|
(0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.extractZip.errors.extract`, {}, err);
|
|
51
50
|
}
|
|
52
|
-
(0,
|
|
51
|
+
logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.extractZip.success`));
|
|
53
52
|
return result;
|
|
54
53
|
}
|
|
55
|
-
async function copySourceToDest(src, dest, { sourceDir, includesRootDir = true } = {}
|
|
54
|
+
async function copySourceToDest(src, dest, { sourceDir, includesRootDir = true } = {}) {
|
|
56
55
|
try {
|
|
57
|
-
|
|
58
|
-
logger('copy', `${i18nKey}.copySourceToDest.init`);
|
|
56
|
+
logger_1.logger.log((0, lang_1.i18n)(`${i18nKey}.copySourceToDest.init`));
|
|
59
57
|
const srcDirPath = [src];
|
|
60
58
|
if (includesRootDir) {
|
|
61
59
|
const files = await fs_extra_1.default.readdir(src);
|
|
62
60
|
const rootDir = files[0];
|
|
63
61
|
if (!rootDir) {
|
|
64
|
-
(0,
|
|
62
|
+
logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.copySourceToDest.sourceEmpty`));
|
|
65
63
|
// Create the dest path if it doesn't already exist
|
|
66
64
|
fs_extra_1.default.ensureDir(dest);
|
|
67
65
|
// No root found so nothing to copy
|
|
@@ -74,11 +72,11 @@ async function copySourceToDest(src, dest, { sourceDir, includesRootDir = true }
|
|
|
74
72
|
}
|
|
75
73
|
const projectSrcDir = (0, path_1.join)(...srcDirPath);
|
|
76
74
|
await fs_extra_1.default.copy(projectSrcDir, dest);
|
|
77
|
-
(0,
|
|
75
|
+
logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.copySourceToDest.success`));
|
|
78
76
|
return true;
|
|
79
77
|
}
|
|
80
78
|
catch (err) {
|
|
81
|
-
(0,
|
|
79
|
+
logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.copySourceToDest.error`, { dest }));
|
|
82
80
|
(0, fileSystemErrors_1.throwFileSystemError)(err, {
|
|
83
81
|
filepath: dest,
|
|
84
82
|
write: true,
|
|
@@ -93,18 +91,18 @@ function cleanupTempDir(tmpDir) {
|
|
|
93
91
|
fs_extra_1.default.remove(tmpDir);
|
|
94
92
|
}
|
|
95
93
|
catch (e) {
|
|
96
|
-
(0,
|
|
94
|
+
logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.cleanupTempDir.error`, { tmpDir }));
|
|
97
95
|
}
|
|
98
96
|
}
|
|
99
|
-
async function extractZipArchive(zip, name, dest, { sourceDir, includesRootDir } = {}
|
|
97
|
+
async function extractZipArchive(zip, name, dest, { sourceDir, includesRootDir } = {}) {
|
|
100
98
|
let success = false;
|
|
101
99
|
if (zip) {
|
|
102
|
-
const { extractDir, tmpDir } = await extractZip(name, zip
|
|
100
|
+
const { extractDir, tmpDir } = await extractZip(name, zip);
|
|
103
101
|
if (extractDir !== null) {
|
|
104
102
|
success = await copySourceToDest(extractDir, dest, {
|
|
105
103
|
sourceDir,
|
|
106
104
|
includesRootDir,
|
|
107
|
-
}
|
|
105
|
+
});
|
|
108
106
|
}
|
|
109
107
|
cleanupTempDir(tmpDir);
|
|
110
108
|
}
|
package/lib/cms/functions.d.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { LogCallbacksArg } from '../../types/LogCallbacks';
|
|
2
|
-
declare const createFunctionCallbackKeys: readonly ["destPathAlreadyExists", "createdDest", "createdFunctionFile", "createdConfigFile", "success"];
|
|
3
1
|
type FunctionInfo = {
|
|
4
2
|
functionsFolder: string;
|
|
5
3
|
filename: string;
|
|
@@ -9,5 +7,5 @@ type FunctionInfo = {
|
|
|
9
7
|
type FunctionOptions = {
|
|
10
8
|
allowExistingFile?: boolean;
|
|
11
9
|
};
|
|
12
|
-
export declare function createFunction(functionInfo: FunctionInfo, dest: string, options?: FunctionOptions
|
|
10
|
+
export declare function createFunction(functionInfo: FunctionInfo, dest: string, options?: FunctionOptions): Promise<void>;
|
|
13
11
|
export {};
|
package/lib/cms/functions.js
CHANGED
|
@@ -9,17 +9,11 @@ const path_1 = __importDefault(require("path"));
|
|
|
9
9
|
const findup_sync_1 = __importDefault(require("findup-sync"));
|
|
10
10
|
const path_2 = require("../path");
|
|
11
11
|
const github_1 = require("../github");
|
|
12
|
-
const logger_1 = require("
|
|
12
|
+
const logger_1 = require("../logging/logger");
|
|
13
13
|
const standardErrors_1 = require("../../errors/standardErrors");
|
|
14
14
|
const fileSystemErrors_1 = require("../../errors/fileSystemErrors");
|
|
15
|
+
const lang_1 = require("../../utils/lang");
|
|
15
16
|
const i18nKey = 'lib.cms.functions';
|
|
16
|
-
const createFunctionCallbackKeys = [
|
|
17
|
-
'destPathAlreadyExists',
|
|
18
|
-
'createdDest',
|
|
19
|
-
'createdFunctionFile',
|
|
20
|
-
'createdConfigFile',
|
|
21
|
-
'success',
|
|
22
|
-
];
|
|
23
17
|
function isObjectOrFunction(value) {
|
|
24
18
|
const type = typeof value;
|
|
25
19
|
return value != null && (type === 'object' || type === 'function');
|
|
@@ -51,9 +45,9 @@ function updateExistingConfig(configFilePath, { endpointPath, endpointMethod, fu
|
|
|
51
45
|
configString = fs_extra_1.default.readFileSync(configFilePath).toString();
|
|
52
46
|
}
|
|
53
47
|
catch (err) {
|
|
54
|
-
(0,
|
|
48
|
+
logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.updateExistingConfig.unableToReadFile`, {
|
|
55
49
|
configFilePath,
|
|
56
|
-
});
|
|
50
|
+
}));
|
|
57
51
|
(0, fileSystemErrors_1.throwFileSystemError)(err, {
|
|
58
52
|
filepath: configFilePath,
|
|
59
53
|
read: true,
|
|
@@ -64,9 +58,9 @@ function updateExistingConfig(configFilePath, { endpointPath, endpointMethod, fu
|
|
|
64
58
|
config = JSON.parse(configString);
|
|
65
59
|
}
|
|
66
60
|
catch (err) {
|
|
67
|
-
(0,
|
|
61
|
+
logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.updateExistingConfig.invalidJSON`, {
|
|
68
62
|
configFilePath,
|
|
69
|
-
});
|
|
63
|
+
}));
|
|
70
64
|
(0, fileSystemErrors_1.throwFileSystemError)(err, {
|
|
71
65
|
filepath: configFilePath,
|
|
72
66
|
read: true,
|
|
@@ -95,17 +89,16 @@ function updateExistingConfig(configFilePath, { endpointPath, endpointMethod, fu
|
|
|
95
89
|
writeConfig(configFilePath, config);
|
|
96
90
|
}
|
|
97
91
|
catch (err) {
|
|
98
|
-
(0,
|
|
92
|
+
logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.updateExistingConfig.couldNotUpdateFile`, {
|
|
99
93
|
configFilePath,
|
|
100
|
-
});
|
|
94
|
+
}));
|
|
101
95
|
(0, fileSystemErrors_1.throwFileSystemError)(err, {
|
|
102
96
|
filepath: configFilePath,
|
|
103
97
|
write: true,
|
|
104
98
|
});
|
|
105
99
|
}
|
|
106
100
|
}
|
|
107
|
-
async function createFunction(functionInfo, dest, options = {}
|
|
108
|
-
const logger = (0, logger_1.makeTypedLogger)(logCallbacks);
|
|
101
|
+
async function createFunction(functionInfo, dest, options = {}) {
|
|
109
102
|
const { functionsFolder, filename, endpointPath, endpointMethod } = functionInfo;
|
|
110
103
|
const allowExistingFile = options.allowExistingFile || false;
|
|
111
104
|
const ancestorFunctionsConfig = (0, findup_sync_1.default)('serverless.json', {
|
|
@@ -123,15 +116,15 @@ async function createFunction(functionInfo, dest, options = {}, logCallbacks) {
|
|
|
123
116
|
const functionFile = filename.endsWith('.js') ? filename : `${filename}.js`;
|
|
124
117
|
const destPath = path_1.default.join(dest, folderName);
|
|
125
118
|
if (fs_extra_1.default.existsSync(destPath)) {
|
|
126
|
-
logger(
|
|
119
|
+
logger_1.logger.log((0, lang_1.i18n)(`${i18nKey}.createFunction.destPathAlreadyExists`, {
|
|
127
120
|
path: destPath,
|
|
128
|
-
});
|
|
121
|
+
}));
|
|
129
122
|
}
|
|
130
123
|
else {
|
|
131
124
|
fs_extra_1.default.mkdirp(destPath);
|
|
132
|
-
logger(
|
|
125
|
+
logger_1.logger.log((0, lang_1.i18n)(`${i18nKey}.createFunction.createdDest`, {
|
|
133
126
|
path: destPath,
|
|
134
|
-
});
|
|
127
|
+
}));
|
|
135
128
|
}
|
|
136
129
|
const functionFilePath = path_1.default.join(destPath, functionFile);
|
|
137
130
|
const configFilePath = path_1.default.join(destPath, 'serverless.json');
|
|
@@ -141,22 +134,22 @@ async function createFunction(functionInfo, dest, options = {}, logCallbacks) {
|
|
|
141
134
|
});
|
|
142
135
|
}
|
|
143
136
|
await (0, github_1.downloadGithubRepoContents)('HubSpot/cms-sample-assets', 'functions/sample-function.js', functionFilePath);
|
|
144
|
-
logger(
|
|
137
|
+
logger_1.logger.log((0, lang_1.i18n)(`${i18nKey}.createFunction.createdFunctionFile`, {
|
|
145
138
|
path: functionFilePath,
|
|
146
|
-
});
|
|
139
|
+
}));
|
|
147
140
|
if (fs_extra_1.default.existsSync(configFilePath)) {
|
|
148
141
|
updateExistingConfig(configFilePath, {
|
|
149
142
|
endpointPath,
|
|
150
143
|
endpointMethod,
|
|
151
144
|
functionFile,
|
|
152
145
|
});
|
|
153
|
-
logger(
|
|
146
|
+
logger_1.logger.log((0, lang_1.i18n)(`${i18nKey}.createFunction.createdFunctionFile`, {
|
|
154
147
|
path: functionFilePath,
|
|
155
|
-
});
|
|
156
|
-
logger(
|
|
148
|
+
}));
|
|
149
|
+
logger_1.logger.log((0, lang_1.i18n)(`${i18nKey}.createFunction.success`, {
|
|
157
150
|
endpointPath: endpointPath,
|
|
158
151
|
folderName,
|
|
159
|
-
});
|
|
152
|
+
}));
|
|
160
153
|
}
|
|
161
154
|
else {
|
|
162
155
|
const config = createConfig({ endpointPath, endpointMethod, functionFile });
|
|
@@ -164,21 +157,21 @@ async function createFunction(functionInfo, dest, options = {}, logCallbacks) {
|
|
|
164
157
|
writeConfig(configFilePath, config);
|
|
165
158
|
}
|
|
166
159
|
catch (err) {
|
|
167
|
-
(0,
|
|
160
|
+
logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.createFunction.failedToCreateFile`, {
|
|
168
161
|
configFilePath,
|
|
169
|
-
});
|
|
162
|
+
}));
|
|
170
163
|
(0, fileSystemErrors_1.throwFileSystemError)(err, {
|
|
171
164
|
filepath: configFilePath,
|
|
172
165
|
write: true,
|
|
173
166
|
});
|
|
174
167
|
}
|
|
175
|
-
logger(
|
|
168
|
+
logger_1.logger.log((0, lang_1.i18n)(`${i18nKey}.createFunction.createdConfigFile`, {
|
|
176
169
|
path: configFilePath,
|
|
177
|
-
});
|
|
178
|
-
logger(
|
|
170
|
+
}));
|
|
171
|
+
logger_1.logger.log((0, lang_1.i18n)(`${i18nKey}.createFunction.success`, {
|
|
179
172
|
endpointPath: endpointPath,
|
|
180
173
|
folderName,
|
|
181
|
-
});
|
|
174
|
+
}));
|
|
182
175
|
}
|
|
183
176
|
}
|
|
184
177
|
exports.createFunction = createFunction;
|
|
@@ -10,8 +10,9 @@ const path_1 = __importDefault(require("path"));
|
|
|
10
10
|
const child_process_1 = require("child_process");
|
|
11
11
|
const escapeRegExp_1 = require("../../utils/escapeRegExp");
|
|
12
12
|
const modules_1 = require("../../utils/cms/modules");
|
|
13
|
-
const logger_1 = require("
|
|
13
|
+
const logger_1 = require("../logging/logger");
|
|
14
14
|
const standardErrors_1 = require("../../errors/standardErrors");
|
|
15
|
+
const lang_1 = require("../../utils/lang");
|
|
15
16
|
const i18nKey = 'lib.cms.handleFieldsJs';
|
|
16
17
|
class FieldsJs {
|
|
17
18
|
projectDir;
|
|
@@ -51,9 +52,9 @@ class FieldsJs {
|
|
|
51
52
|
writeDir,
|
|
52
53
|
},
|
|
53
54
|
});
|
|
54
|
-
(0,
|
|
55
|
+
logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.convertFieldsJs.creating`, {
|
|
55
56
|
pid: convertFieldsProcess.pid || '',
|
|
56
|
-
});
|
|
57
|
+
}));
|
|
57
58
|
convertFieldsProcess.on('message', function (message) {
|
|
58
59
|
if (message.action === 'ERROR') {
|
|
59
60
|
reject(message.message);
|
|
@@ -63,9 +64,9 @@ class FieldsJs {
|
|
|
63
64
|
}
|
|
64
65
|
});
|
|
65
66
|
convertFieldsProcess.on('close', () => {
|
|
66
|
-
(0,
|
|
67
|
+
logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.convertFieldsJs.terminating`, {
|
|
67
68
|
pid: convertFieldsProcess.pid || '',
|
|
68
|
-
});
|
|
69
|
+
}));
|
|
69
70
|
});
|
|
70
71
|
}).catch((e) => {
|
|
71
72
|
(0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.convertFieldsJs.errors.errorConverting`, { filePath }, e);
|
package/lib/cms/modules.d.ts
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import { LogCallbacksArg } from '../../types/LogCallbacks';
|
|
2
1
|
import { PathInput } from '../../types/Modules';
|
|
3
|
-
declare const createModuleCallbackKeys: readonly ["creatingPath", "creatingModule"];
|
|
4
2
|
export declare const ValidationIds: {
|
|
5
3
|
SRC_REQUIRED: string;
|
|
6
4
|
DEST_REQUIRED: string;
|
|
@@ -21,5 +19,6 @@ type ModuleDefinition = {
|
|
|
21
19
|
};
|
|
22
20
|
export declare function createModule(moduleDefinition: ModuleDefinition, name: string, dest: string, getInternalVersion: boolean, options?: {
|
|
23
21
|
allowExistingDir: boolean;
|
|
24
|
-
}
|
|
22
|
+
}): Promise<void>;
|
|
23
|
+
export declare function retrieveDefaultModule(name: string | undefined, dest: string): Promise<import("../../types/Github").GithubRepoFile[] | undefined>;
|
|
25
24
|
export {};
|
package/lib/cms/modules.js
CHANGED
|
@@ -3,17 +3,17 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.createModule = exports.validateSrcAndDestPaths = exports.ValidationIds = void 0;
|
|
6
|
+
exports.retrieveDefaultModule = exports.createModule = exports.validateSrcAndDestPaths = exports.ValidationIds = void 0;
|
|
7
7
|
const path_1 = __importDefault(require("path"));
|
|
8
8
|
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
9
9
|
const path_2 = require("../path");
|
|
10
10
|
const fs_1 = require("../fs");
|
|
11
11
|
const github_1 = require("../github");
|
|
12
12
|
const standardErrors_1 = require("../../errors/standardErrors");
|
|
13
|
-
const logger_1 = require("
|
|
13
|
+
const logger_1 = require("../logging/logger");
|
|
14
14
|
const modules_1 = require("../../utils/cms/modules");
|
|
15
|
+
const lang_1 = require("../../utils/lang");
|
|
15
16
|
const i18nKey = 'lib.cms.modules';
|
|
16
|
-
const createModuleCallbackKeys = ['creatingPath', 'creatingModule'];
|
|
17
17
|
// Ids for testing
|
|
18
18
|
exports.ValidationIds = {
|
|
19
19
|
SRC_REQUIRED: 'SRC_REQUIRED',
|
|
@@ -116,8 +116,7 @@ const transformFileContents = (file, metaData, getInternalVersion) => {
|
|
|
116
116
|
};
|
|
117
117
|
async function createModule(moduleDefinition, name, dest, getInternalVersion, options = {
|
|
118
118
|
allowExistingDir: false,
|
|
119
|
-
}
|
|
120
|
-
const logger = (0, logger_1.makeTypedLogger)(logCallbacks);
|
|
119
|
+
}) {
|
|
121
120
|
const { reactType: isReactModule } = moduleDefinition;
|
|
122
121
|
const folderName = name.endsWith('.module') ? name : `${name}.module`;
|
|
123
122
|
const destPath = !isReactModule
|
|
@@ -129,14 +128,14 @@ async function createModule(moduleDefinition, name, dest, getInternalVersion, op
|
|
|
129
128
|
});
|
|
130
129
|
}
|
|
131
130
|
else {
|
|
132
|
-
logger(
|
|
131
|
+
logger_1.logger.log((0, lang_1.i18n)(`${i18nKey}.createModule.creatingPath`, {
|
|
133
132
|
path: destPath,
|
|
134
|
-
});
|
|
133
|
+
}));
|
|
135
134
|
fs_extra_1.default.ensureDirSync(destPath);
|
|
136
135
|
}
|
|
137
|
-
logger(
|
|
136
|
+
logger_1.logger.log((0, lang_1.i18n)(`${i18nKey}.createModule.creatingModule`, {
|
|
138
137
|
path: destPath,
|
|
139
|
-
});
|
|
138
|
+
}));
|
|
140
139
|
// Write module meta
|
|
141
140
|
const writeModuleMeta = ({ moduleLabel, contentTypes, global, reactType }, dest) => {
|
|
142
141
|
const metaData = {
|
|
@@ -194,3 +193,11 @@ async function createModule(moduleDefinition, name, dest, getInternalVersion, op
|
|
|
194
193
|
}
|
|
195
194
|
}
|
|
196
195
|
exports.createModule = createModule;
|
|
196
|
+
async function retrieveDefaultModule(name, dest) {
|
|
197
|
+
if (!name) {
|
|
198
|
+
const defaultReactModules = await (0, github_1.listGithubRepoContents)('HubSpot/cms-sample-assets', 'modules/', 'dir');
|
|
199
|
+
return defaultReactModules;
|
|
200
|
+
}
|
|
201
|
+
await (0, github_1.downloadGithubRepoContents)('HubSpot/cms-sample-assets', `modules/${name}`, dest);
|
|
202
|
+
}
|
|
203
|
+
exports.retrieveDefaultModule = retrieveDefaultModule;
|
package/lib/cms/templates.d.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { LogCallbacksArg } from '../../types/LogCallbacks';
|
|
2
|
-
declare const templatesCallbackKeys: readonly ["creatingFile"];
|
|
3
1
|
export declare const ANNOTATION_KEYS: {
|
|
4
2
|
isAvailableForNewContent: string;
|
|
5
3
|
templateType: string;
|
|
@@ -21,5 +19,5 @@ declare const ASSET_PATHS: {
|
|
|
21
19
|
};
|
|
22
20
|
export declare function createTemplate(name: string, dest: string, type?: keyof typeof ASSET_PATHS, options?: {
|
|
23
21
|
allowExisting: boolean;
|
|
24
|
-
}
|
|
22
|
+
}): Promise<void>;
|
|
25
23
|
export {};
|
package/lib/cms/templates.js
CHANGED
|
@@ -8,9 +8,9 @@ const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
|
8
8
|
const path_1 = __importDefault(require("path"));
|
|
9
9
|
const github_1 = require("../github");
|
|
10
10
|
const standardErrors_1 = require("../../errors/standardErrors");
|
|
11
|
-
const logger_1 = require("
|
|
11
|
+
const logger_1 = require("../logging/logger");
|
|
12
|
+
const lang_1 = require("../../utils/lang");
|
|
12
13
|
const i18nKey = 'lib.cms.templates';
|
|
13
|
-
const templatesCallbackKeys = ['creatingFile'];
|
|
14
14
|
// Matches the .html file extension, excluding module.html
|
|
15
15
|
const TEMPLATE_EXTENSION_REGEX = new RegExp(/(?<!module)\.html$/);
|
|
16
16
|
// Matches an annotation value, ending at space, newline, or end of string
|
|
@@ -47,7 +47,7 @@ const ASSET_PATHS = {
|
|
|
47
47
|
'search-template': 'templates/search-template.html',
|
|
48
48
|
section: 'templates/section.html',
|
|
49
49
|
};
|
|
50
|
-
async function createTemplate(name, dest, type = 'page-template', options = { allowExisting: false }
|
|
50
|
+
async function createTemplate(name, dest, type = 'page-template', options = { allowExisting: false }) {
|
|
51
51
|
const assetPath = ASSET_PATHS[type];
|
|
52
52
|
const filename = name.endsWith('.html') ? name : `${name}.html`;
|
|
53
53
|
const filePath = path_1.default.join(dest, filename);
|
|
@@ -56,12 +56,11 @@ async function createTemplate(name, dest, type = 'page-template', options = { al
|
|
|
56
56
|
path: filePath,
|
|
57
57
|
});
|
|
58
58
|
}
|
|
59
|
-
(0,
|
|
59
|
+
logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.createTemplate.creatingPath`, { path: dest }));
|
|
60
60
|
fs_extra_1.default.mkdirp(dest);
|
|
61
|
-
|
|
62
|
-
logger('creatingFile', `${i18nKey}.createTemplate.creatingFile`, {
|
|
61
|
+
logger_1.logger.log((0, lang_1.i18n)(`${i18nKey}.createTemplate.creatingFile`, {
|
|
63
62
|
path: filePath,
|
|
64
|
-
});
|
|
63
|
+
}));
|
|
65
64
|
await (0, github_1.downloadGithubRepoContents)('HubSpot/cms-sample-assets', assetPath, filePath);
|
|
66
65
|
}
|
|
67
66
|
exports.createTemplate = createTemplate;
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import { FieldsJs } from './handleFieldsJS';
|
|
2
2
|
import { FileMapperInputOptions } from '../../types/Files';
|
|
3
|
-
import { LogCallbacksArg } from '../../types/LogCallbacks';
|
|
4
3
|
import { UploadFolderResults } from '../../types/Files';
|
|
5
4
|
import { Mode } from '../../types/Files';
|
|
6
|
-
declare const uploadFolderCallbackKeys: readonly ["success"];
|
|
7
5
|
type CommandOptions = {
|
|
8
6
|
convertFields?: boolean;
|
|
9
7
|
fieldOptions?: string;
|
|
@@ -13,6 +11,6 @@ type FilePathsByType = {
|
|
|
13
11
|
[key: string]: Array<string>;
|
|
14
12
|
};
|
|
15
13
|
export declare function getFilesByType(filePaths: Array<string>, projectDir: string, rootWriteDir: string | null, commandOptions: CommandOptions): Promise<[FilePathsByType, Array<FieldsJs>]>;
|
|
16
|
-
export declare function uploadFolder(accountId: number, src: string, dest: string, fileMapperOptions: FileMapperInputOptions, commandOptions?: CommandOptions, filePaths?: Array<string>, mode?: Mode | null
|
|
14
|
+
export declare function uploadFolder(accountId: number, src: string, dest: string, fileMapperOptions: FileMapperInputOptions, commandOptions?: CommandOptions, filePaths?: Array<string>, mode?: Mode | null): Promise<Array<UploadFolderResults>>;
|
|
17
15
|
export declare function hasUploadErrors(results: Array<UploadFolderResults>): boolean;
|
|
18
16
|
export {};
|
package/lib/cms/uploadFolder.js
CHANGED
|
@@ -11,14 +11,13 @@ const fileMapper_1 = require("../fileMapper");
|
|
|
11
11
|
const fileMapper_2 = require("../../api/fileMapper");
|
|
12
12
|
const modules_1 = require("../../utils/cms/modules");
|
|
13
13
|
const escapeRegExp_1 = require("../../utils/escapeRegExp");
|
|
14
|
-
const logger_1 = require("../../utils/logger");
|
|
15
14
|
const path_2 = require("../path");
|
|
16
15
|
const standardErrors_1 = require("../../errors/standardErrors");
|
|
17
16
|
const apiErrors_1 = require("../../errors/apiErrors");
|
|
18
|
-
const
|
|
17
|
+
const logger_1 = require("../logging/logger");
|
|
19
18
|
const files_1 = require("../../constants/files");
|
|
19
|
+
const lang_1 = require("../../utils/lang");
|
|
20
20
|
const i18nKey = 'lib.cms.uploadFolder';
|
|
21
|
-
const uploadFolderCallbackKeys = ['success'];
|
|
22
21
|
const queue = new p_queue_1.default({
|
|
23
22
|
concurrency: 10,
|
|
24
23
|
});
|
|
@@ -77,8 +76,7 @@ async function getFilesByType(filePaths, projectDir, rootWriteDir, commandOption
|
|
|
77
76
|
return [filePathsByType, fieldsJsObjects];
|
|
78
77
|
}
|
|
79
78
|
exports.getFilesByType = getFilesByType;
|
|
80
|
-
async function uploadFolder(accountId, src, dest, fileMapperOptions, commandOptions = {}, filePaths = [], mode = null
|
|
81
|
-
const logger = (0, logger_2.makeTypedLogger)(logCallbacks);
|
|
79
|
+
async function uploadFolder(accountId, src, dest, fileMapperOptions, commandOptions = {}, filePaths = [], mode = null) {
|
|
82
80
|
const { saveOutput, convertFields } = commandOptions;
|
|
83
81
|
const tmpDir = convertFields
|
|
84
82
|
? (0, handleFieldsJS_1.createTmpDirSync)('hubspot-temp-fieldsjs-output-')
|
|
@@ -105,28 +103,28 @@ async function uploadFolder(accountId, src, dest, fileMapperOptions, commandOpti
|
|
|
105
103
|
const relativePath = file.replace(fieldsJsFileInfo ? tmpDirRegex : regex, '');
|
|
106
104
|
const destPath = (0, path_2.convertToUnixPath)(path_1.default.join(dest, relativePath));
|
|
107
105
|
return async () => {
|
|
108
|
-
(0,
|
|
106
|
+
logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.uploadFolder.attempt`, {
|
|
109
107
|
file: originalFilePath || '',
|
|
110
108
|
destPath,
|
|
111
|
-
});
|
|
109
|
+
}));
|
|
112
110
|
try {
|
|
113
111
|
await (0, fileMapper_2.upload)(accountId, file, destPath, apiOptions);
|
|
114
|
-
logger(
|
|
112
|
+
logger_1.logger.log((0, lang_1.i18n)(`${i18nKey}.uploadFolder.success`, {
|
|
115
113
|
file: originalFilePath || '',
|
|
116
114
|
destPath,
|
|
117
|
-
});
|
|
115
|
+
}));
|
|
118
116
|
}
|
|
119
117
|
catch (err) {
|
|
120
118
|
const error = err;
|
|
121
119
|
if ((0, standardErrors_1.isFatalError)(error)) {
|
|
122
120
|
throw error;
|
|
123
121
|
}
|
|
124
|
-
(0,
|
|
122
|
+
logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.uploadFolder.failed`, { file, destPath }));
|
|
125
123
|
if (error.response && error.response.data) {
|
|
126
|
-
|
|
124
|
+
logger_1.logger.debug(error.response.data);
|
|
127
125
|
}
|
|
128
126
|
else {
|
|
129
|
-
|
|
127
|
+
logger_1.logger.debug(error.message);
|
|
130
128
|
}
|
|
131
129
|
failures.push({
|
|
132
130
|
file,
|
|
@@ -142,13 +140,13 @@ async function uploadFolder(accountId, src, dest, fileMapperOptions, commandOpti
|
|
|
142
140
|
const results = await queue
|
|
143
141
|
.addAll(failures.map(({ file, destPath }) => {
|
|
144
142
|
return async () => {
|
|
145
|
-
(0,
|
|
143
|
+
logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.uploadFolder.retry`, { file, destPath }));
|
|
146
144
|
try {
|
|
147
145
|
await (0, fileMapper_2.upload)(accountId, file, destPath, apiOptions);
|
|
148
|
-
logger(
|
|
146
|
+
logger_1.logger.log((0, lang_1.i18n)(`${i18nKey}.uploadFolder.success`, {
|
|
149
147
|
file,
|
|
150
148
|
destPath,
|
|
151
|
-
});
|
|
149
|
+
}));
|
|
152
150
|
return {
|
|
153
151
|
resultType: files_1.FILE_UPLOAD_RESULT_TYPES.SUCCESS,
|
|
154
152
|
error: null,
|
|
@@ -156,7 +154,7 @@ async function uploadFolder(accountId, src, dest, fileMapperOptions, commandOpti
|
|
|
156
154
|
};
|
|
157
155
|
}
|
|
158
156
|
catch (err) {
|
|
159
|
-
(0,
|
|
157
|
+
logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.uploadFolder.retryFailed`, { file, destPath }));
|
|
160
158
|
const error = err;
|
|
161
159
|
if ((0, standardErrors_1.isFatalError)(error)) {
|
|
162
160
|
throw error;
|
package/lib/cms/watch.d.ts
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
import chokidar from 'chokidar';
|
|
2
2
|
import { AxiosError } from 'axios';
|
|
3
|
-
import { LogCallbacksArg } from '../../types/LogCallbacks';
|
|
4
3
|
import { Mode } from '../../types/Files';
|
|
5
4
|
import { UploadFolderResults } from '../../types/Files';
|
|
6
|
-
declare const watchCallbackKeys: readonly ["notifyOfThemePreview", "uploadSuccess", "deleteSuccess", "folderUploadSuccess", "ready", "deleteSuccessWithType"];
|
|
7
|
-
type WatchLogCallbacks = LogCallbacksArg<typeof watchCallbackKeys>;
|
|
8
5
|
type WatchOptions = {
|
|
9
6
|
mode?: Mode;
|
|
10
7
|
remove?: boolean;
|
|
@@ -16,5 +13,5 @@ type WatchOptions = {
|
|
|
16
13
|
filePaths?: Array<string>;
|
|
17
14
|
};
|
|
18
15
|
type ErrorHandler = (error: AxiosError) => void;
|
|
19
|
-
export declare function watch(accountId: number, src: string, dest: string, { mode, remove, disableInitial, notify, commandOptions, filePaths, }: WatchOptions, postInitialUploadCallback?: ((result: Array<UploadFolderResults>) => void) | null, onUploadFolderError?: ErrorHandler, onQueueAddError?: ErrorHandler
|
|
16
|
+
export declare function watch(accountId: number, src: string, dest: string, { mode, remove, disableInitial, notify, commandOptions, filePaths, }: WatchOptions, postInitialUploadCallback?: ((result: Array<UploadFolderResults>) => void) | null, onUploadFolderError?: ErrorHandler, onQueueAddError?: ErrorHandler): chokidar.FSWatcher;
|
|
20
17
|
export {};
|