@hubspot/local-dev-lib 0.1.0 → 0.1.1-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/LICENSE +12 -0
- package/README.md +17 -0
- package/api/appsDev.d.ts +6 -0
- package/api/appsDev.js +29 -0
- package/api/customObjects.d.ts +8 -7
- package/api/customObjects.js +13 -16
- package/api/designManager.d.ts +4 -13
- package/api/designManager.js +6 -9
- package/api/developerTestAccounts.d.ts +7 -0
- package/api/developerTestAccounts.js +48 -0
- package/api/fileManager.d.ts +6 -5
- package/api/fileManager.js +13 -12
- package/api/fileMapper.d.ts +8 -7
- package/api/fileMapper.js +19 -18
- package/api/fileTransport.d.ts +4 -0
- package/api/fileTransport.js +39 -0
- package/api/functions.d.ts +7 -4
- package/api/functions.js +22 -11
- package/api/github.d.ts +7 -9
- package/api/github.js +31 -13
- package/api/hubdb.d.ts +11 -10
- package/api/hubdb.js +28 -22
- package/api/lighthouseScore.d.ts +4 -4
- package/api/lighthouseScore.js +9 -12
- package/api/localDevAuth.d.ts +7 -15
- package/api/localDevAuth.js +28 -13
- package/api/marketplaceValidation.d.ts +4 -4
- package/api/marketplaceValidation.js +8 -11
- package/api/projects.d.ts +31 -24
- package/api/projects.js +166 -45
- package/api/sandboxHubs.d.ts +6 -4
- package/api/sandboxHubs.js +10 -11
- package/api/sandboxSync.d.ts +4 -4
- package/api/sandboxSync.js +4 -13
- package/api/secrets.d.ts +6 -8
- package/api/secrets.js +9 -12
- package/api/validateHubl.d.ts +2 -1
- package/api/validateHubl.js +3 -6
- package/config/CLIConfiguration.d.ts +13 -10
- package/config/CLIConfiguration.js +129 -77
- package/config/configFile.js +12 -18
- package/config/configUtils.d.ts +2 -21
- package/config/configUtils.js +5 -4
- package/config/config_DEPRECATED.d.ts +6 -8
- package/config/config_DEPRECATED.js +79 -25
- package/config/environment.js +5 -4
- package/config/getAccountIdentifier.d.ts +2 -0
- package/config/getAccountIdentifier.js +15 -0
- package/config/index.d.ts +10 -7
- package/config/index.js +83 -55
- package/constants/config.d.ts +15 -1
- package/constants/config.js +17 -3
- package/constants/environments.d.ts +1 -0
- package/constants/environments.js +1 -0
- package/constants/extensions.d.ts +2 -0
- package/constants/extensions.js +3 -1
- package/constants/files.d.ts +2 -2
- package/constants/files.js +3 -3
- package/errors/errors_DEPRECATED.d.ts +1 -5
- package/errors/errors_DEPRECATED.js +2 -2
- package/errors/index.d.ts +18 -0
- package/errors/index.js +63 -0
- package/http/addQueryParams.d.ts +2 -0
- package/http/addQueryParams.js +14 -0
- package/http/getAxiosConfig.d.ts +6 -3
- package/http/getAxiosConfig.js +51 -7
- package/http/index.d.ts +11 -12
- package/http/index.js +35 -41
- package/http/unauthed.d.ts +14 -0
- package/http/unauthed.js +38 -0
- package/lang/en.json +374 -368
- package/lib/archive.d.ts +2 -8
- package/lib/archive.js +34 -30
- package/lib/cms/functions.d.ts +7 -12
- package/lib/cms/functions.js +49 -51
- package/lib/cms/handleFieldsJS.js +16 -14
- package/lib/cms/modules.d.ts +5 -15
- package/lib/cms/modules.js +116 -42
- package/lib/cms/processFieldsJs.js +10 -33
- package/lib/cms/templates.d.ts +43 -3
- package/lib/cms/templates.js +53 -11
- package/lib/cms/uploadFolder.d.ts +3 -14
- package/lib/cms/uploadFolder.js +58 -42
- package/lib/cms/validate.js +1 -1
- package/lib/cms/watch.d.ts +2 -18
- package/lib/cms/watch.js +63 -68
- package/lib/customObjects.js +4 -15
- package/lib/fileManager.d.ts +2 -0
- package/lib/fileManager.js +184 -0
- package/lib/fileMapper.d.ts +4 -15
- package/lib/fileMapper.js +68 -82
- package/lib/fs.d.ts +1 -1
- package/lib/fs.js +10 -6
- package/lib/github.d.ts +9 -14
- package/lib/github.js +61 -29
- package/lib/gitignore.d.ts +2 -0
- package/lib/gitignore.js +21 -4
- package/lib/hubdb.d.ts +3 -2
- package/lib/hubdb.js +11 -9
- package/lib/{logging/logger.d.ts → logger.d.ts} +20 -8
- package/{utils → lib}/notify.js +2 -2
- package/lib/oauth.d.ts +2 -5
- package/lib/oauth.js +14 -25
- package/lib/path.d.ts +3 -0
- package/lib/path.js +46 -1
- package/lib/personalAccessKey.d.ts +7 -10
- package/lib/personalAccessKey.js +74 -47
- package/lib/portManager.d.ts +3 -5
- package/lib/portManager.js +18 -6
- package/lib/text.d.ts +1 -0
- package/lib/text.js +9 -1
- package/lib/trackUsage.js +18 -11
- package/lib/urls.js +5 -1
- package/models/FileSystemError.d.ts +6 -0
- package/models/FileSystemError.js +47 -0
- package/models/HubSpotHttpError.d.ts +24 -0
- package/models/HubSpotHttpError.js +197 -0
- package/models/OAuth2Manager.d.ts +5 -27
- package/models/OAuth2Manager.js +41 -64
- package/package.json +19 -18
- package/types/Accounts.d.ts +90 -3
- package/types/Apps.d.ts +77 -0
- package/types/Archive.d.ts +9 -0
- package/types/Archive.js +2 -0
- package/types/Build.d.ts +4 -2
- package/types/ComponentStructure.d.ts +30 -10
- package/types/Config.d.ts +19 -2
- package/types/Deploy.d.ts +3 -2
- package/types/DesignManager.d.ts +10 -0
- package/types/DesignManager.js +2 -0
- package/types/Error.d.ts +11 -6
- package/types/FieldsJS.d.ts +1 -0
- package/types/FieldsJS.js +2 -0
- package/types/FileManager.d.ts +12 -7
- package/types/Files.d.ts +43 -4
- package/types/Functions.d.ts +52 -0
- package/types/Github.d.ts +12 -0
- package/types/Http.d.ts +12 -12
- package/types/Hubdb.d.ts +9 -0
- package/types/Lang.d.ts +3 -0
- package/types/MarketplaceValidation.d.ts +7 -3
- package/types/Migration.d.ts +28 -0
- package/types/Migration.js +10 -0
- package/types/Modules.d.ts +11 -0
- package/types/PortManager.d.ts +7 -0
- package/types/Project.d.ts +30 -0
- package/types/ProjectLog.d.ts +9 -0
- package/types/ProjectLog.js +2 -0
- package/types/Sandbox.d.ts +37 -47
- package/types/Schemas.d.ts +12 -0
- package/types/Secrets.d.ts +3 -0
- package/types/Secrets.js +2 -0
- package/types/developerTestAccounts.d.ts +13 -0
- package/types/developerTestAccounts.js +2 -0
- package/utils/PortManagerServer.d.ts +6 -7
- package/utils/PortManagerServer.js +22 -16
- package/utils/{getAccountIdentifier.d.ts → accounts.d.ts} +0 -6
- package/utils/{getAccountIdentifier.js → accounts.js} +1 -13
- package/utils/cms/fieldsJS.d.ts +1 -2
- package/utils/cms/modules.js +2 -2
- package/utils/detectPort.js +3 -3
- package/utils/git.d.ts +1 -7
- package/utils/git.js +2 -18
- package/utils/lang.d.ts +1 -5
- package/errors/apiErrors.d.ts +0 -19
- package/errors/apiErrors.js +0 -179
- package/errors/fileSystemErrors.d.ts +0 -5
- package/errors/fileSystemErrors.js +0 -31
- package/errors/standardErrors.d.ts +0 -27
- package/errors/standardErrors.js +0 -59
- package/lang/lang/en.json +0 -383
- package/lib/logging/git.d.ts +0 -2
- package/lib/logging/git.js +0 -54
- package/lib/logging/logs.d.ts +0 -22
- package/lib/logging/logs.js +0 -86
- package/lib/logging/table.d.ts +0 -3
- package/lib/logging/table.js +0 -47
- package/lib/sandboxes.d.ts +0 -14
- package/lib/sandboxes.js +0 -71
- package/models/HubSpotAuthError.d.ts +0 -12
- package/models/HubSpotAuthError.js +0 -20
- package/types/LogCallbacks.d.ts +0 -6
- package/utils/logger.d.ts +0 -11
- package/utils/logger.js +0 -23
- package/utils/objectUtils.d.ts +0 -8
- package/utils/objectUtils.js +0 -33
- /package/{utils → lib}/escapeRegExp.d.ts +0 -0
- /package/{utils → lib}/escapeRegExp.js +0 -0
- /package/lib/{logging/logger.js → logger.js} +0 -0
- /package/{utils → lib}/notify.d.ts +0 -0
- /package/types/{LogCallbacks.js → Apps.js} +0 -0
package/lib/cms/modules.js
CHANGED
|
@@ -3,15 +3,15 @@ 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.isModuleHTMLFile = 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
|
-
const
|
|
13
|
-
const logger_1 = require("../../utils/logger");
|
|
12
|
+
const logger_1 = require("../logger");
|
|
14
13
|
const modules_1 = require("../../utils/cms/modules");
|
|
14
|
+
const lang_1 = require("../../utils/lang");
|
|
15
15
|
const i18nKey = 'lib.cms.modules';
|
|
16
16
|
// Ids for testing
|
|
17
17
|
exports.ValidationIds = {
|
|
@@ -67,59 +67,133 @@ async function validateSrcAndDestPaths(src, dest) {
|
|
|
67
67
|
return results;
|
|
68
68
|
}
|
|
69
69
|
exports.validateSrcAndDestPaths = validateSrcAndDestPaths;
|
|
70
|
-
|
|
71
|
-
|
|
70
|
+
/* createModule() helper
|
|
71
|
+
* Takes a file and uses the constants above to transform the contents
|
|
72
|
+
*/
|
|
73
|
+
// Strings to replace in React module files
|
|
74
|
+
const MODULE_STRING_TRANSFORMATIONS = [
|
|
75
|
+
{
|
|
76
|
+
regex: /\/\* import global styles \*\//g,
|
|
77
|
+
string: 'import "./global-sample-react-module.css";',
|
|
78
|
+
fallback: '',
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
regex: /\/\* Default config \*\//g,
|
|
82
|
+
string: 'export const defaultModuleConfig = { \n moduleName: "sample_react-module", \n version: 0, \n};',
|
|
83
|
+
fallback: '',
|
|
84
|
+
},
|
|
85
|
+
];
|
|
86
|
+
const updateFileContents = async (file, metaData, getInternalVersion) => {
|
|
87
|
+
try {
|
|
88
|
+
let fileContents = await fs_extra_1.default.readFile(file, 'utf8'); // returns Promise
|
|
89
|
+
MODULE_STRING_TRANSFORMATIONS.forEach(entry => {
|
|
90
|
+
const replacementString = getInternalVersion
|
|
91
|
+
? entry.string
|
|
92
|
+
: entry.fallback;
|
|
93
|
+
fileContents = fileContents.replace(entry.regex, replacementString);
|
|
94
|
+
});
|
|
95
|
+
await fs_extra_1.default.writeFile(file, fileContents, 'utf8');
|
|
96
|
+
await fs_extra_1.default.appendFile(file, 'export const meta = ' + JSON.stringify(metaData, null, ' '));
|
|
97
|
+
}
|
|
98
|
+
catch (error) {
|
|
99
|
+
const { message } = error;
|
|
100
|
+
throw new Error((0, lang_1.i18n)(`${i18nKey}.createModule.errors.fileUpdateFailure`, {
|
|
101
|
+
path: file,
|
|
102
|
+
errorMessage: message,
|
|
103
|
+
}));
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
async function createModule(moduleDefinition, name, dest, getInternalVersion, options = {
|
|
72
107
|
allowExistingDir: false,
|
|
73
|
-
}
|
|
74
|
-
const
|
|
75
|
-
const
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
is_available_for_new_content: false,
|
|
88
|
-
};
|
|
89
|
-
fs_extra_1.default.writeJSONSync(dest, metaData, { spaces: 2 });
|
|
108
|
+
}) {
|
|
109
|
+
const { moduleLabel, contentTypes, global, reactType: isReactModule, availableForNewContent, } = moduleDefinition;
|
|
110
|
+
const moduleMetaData = {
|
|
111
|
+
label: moduleLabel,
|
|
112
|
+
css_assets: [],
|
|
113
|
+
external_js: [],
|
|
114
|
+
global: global,
|
|
115
|
+
help_text: '',
|
|
116
|
+
content_types: contentTypes,
|
|
117
|
+
js_assets: [],
|
|
118
|
+
other_assets: [],
|
|
119
|
+
smart_type: 'NOT_SMART',
|
|
120
|
+
tags: [],
|
|
121
|
+
is_available_for_new_content: availableForNewContent,
|
|
90
122
|
};
|
|
91
|
-
const
|
|
123
|
+
const folderName = name.endsWith('.module') ? name : `${name}.module`;
|
|
124
|
+
const destPath = !isReactModule
|
|
125
|
+
? path_1.default.join(dest, folderName)
|
|
126
|
+
: path_1.default.join(dest, `${name}`);
|
|
127
|
+
if (!options.allowExistingDir && fs_extra_1.default.existsSync(destPath)) {
|
|
128
|
+
throw new Error((0, lang_1.i18n)(`${i18nKey}.createModule.errors.pathExists`, {
|
|
129
|
+
path: destPath,
|
|
130
|
+
}));
|
|
131
|
+
}
|
|
132
|
+
else {
|
|
133
|
+
logger_1.logger.log((0, lang_1.i18n)(`${i18nKey}.createModule.creatingPath`, {
|
|
134
|
+
path: destPath,
|
|
135
|
+
}));
|
|
136
|
+
fs_extra_1.default.ensureDirSync(destPath);
|
|
137
|
+
}
|
|
138
|
+
logger_1.logger.log((0, lang_1.i18n)(`${i18nKey}.createModule.creatingModule`, {
|
|
139
|
+
path: destPath,
|
|
140
|
+
}));
|
|
141
|
+
// Filter out certain fetched files from the response
|
|
142
|
+
const moduleFileFilter = (src) => {
|
|
92
143
|
const emailEnabled = moduleDefinition.contentTypes.includes('EMAIL');
|
|
93
144
|
switch (path_1.default.basename(src)) {
|
|
94
145
|
case 'meta.json':
|
|
95
|
-
writeModuleMeta(moduleDefinition, dest);
|
|
96
146
|
return false;
|
|
97
147
|
case 'module.js':
|
|
98
148
|
case 'module.css':
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
return true;
|
|
149
|
+
return !emailEnabled;
|
|
150
|
+
case 'global-sample-react-module.css':
|
|
151
|
+
return getInternalVersion;
|
|
103
152
|
default:
|
|
104
153
|
return true;
|
|
105
154
|
}
|
|
106
155
|
};
|
|
107
|
-
|
|
108
|
-
const
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
156
|
+
// Download gitHub contents to the dest directory
|
|
157
|
+
const sampleAssetPath = !isReactModule
|
|
158
|
+
? 'Sample.module'
|
|
159
|
+
: 'SampleReactModule';
|
|
160
|
+
const sourceDir = `modules/${sampleAssetPath}`;
|
|
161
|
+
await (0, github_1.cloneGithubRepo)('HubSpot/cms-sample-assets', destPath, {
|
|
162
|
+
sourceDir,
|
|
163
|
+
});
|
|
164
|
+
const files = await (0, fs_1.walk)(destPath);
|
|
165
|
+
files
|
|
166
|
+
.filter(filePath => !moduleFileFilter(filePath))
|
|
167
|
+
.forEach(filePath => {
|
|
168
|
+
fs_extra_1.default.unlinkSync(filePath);
|
|
169
|
+
});
|
|
170
|
+
if (!getInternalVersion) {
|
|
171
|
+
fs_extra_1.default.removeSync(path_1.default.join(destPath, 'stories'));
|
|
172
|
+
fs_extra_1.default.removeSync(path_1.default.join(destPath, 'tests'));
|
|
113
173
|
}
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
174
|
+
// Get and write the metafiles
|
|
175
|
+
const metaFiles = files.filter(filePath => path_1.default.basename(filePath) === 'meta.json');
|
|
176
|
+
metaFiles.forEach(metaFile => {
|
|
177
|
+
fs_extra_1.default.writeJSONSync(metaFile, moduleMetaData, {
|
|
178
|
+
spaces: 2,
|
|
117
179
|
});
|
|
118
|
-
fs_extra_1.default.ensureDirSync(destPath);
|
|
119
|
-
}
|
|
120
|
-
logger('creatingModule', `${i18nKey}.createModule.creatingModule`, {
|
|
121
|
-
path: destPath,
|
|
122
180
|
});
|
|
123
|
-
|
|
181
|
+
// Updating React module files after fetch
|
|
182
|
+
if (isReactModule) {
|
|
183
|
+
await updateFileContents(`${destPath}/index.tsx`, moduleMetaData, getInternalVersion);
|
|
184
|
+
}
|
|
124
185
|
}
|
|
125
186
|
exports.createModule = createModule;
|
|
187
|
+
async function retrieveDefaultModule(name, dest) {
|
|
188
|
+
if (!name) {
|
|
189
|
+
const defaultReactModules = await (0, github_1.listGithubRepoContents)('HubSpot/cms-react', 'default-react-modules/src/components/modules/', 'dir');
|
|
190
|
+
return defaultReactModules;
|
|
191
|
+
}
|
|
192
|
+
await (0, github_1.cloneGithubRepo)('HubSpot/cms-react', dest, {
|
|
193
|
+
sourceDir: `default-react-modules/src/components/modules/${name}`,
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
exports.retrieveDefaultModule = retrieveDefaultModule;
|
|
197
|
+
const MODULE_HTML_EXTENSION_REGEX = new RegExp(/\.module(?:\/|\\)module\.html$/);
|
|
198
|
+
const isModuleHTMLFile = (filePath) => MODULE_HTML_EXTENSION_REGEX.test(filePath);
|
|
199
|
+
exports.isModuleHTMLFile = isModuleHTMLFile;
|
|
@@ -1,28 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
3
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
|
-
if (k2 === undefined) k2 = k;
|
|
5
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
6
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
8
|
-
}
|
|
9
|
-
Object.defineProperty(o, k2, desc);
|
|
10
|
-
}) : (function(o, m, k, k2) {
|
|
11
|
-
if (k2 === undefined) k2 = k;
|
|
12
|
-
o[k2] = m[k];
|
|
13
|
-
}));
|
|
14
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
15
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
16
|
-
}) : function(o, v) {
|
|
17
|
-
o["default"] = v;
|
|
18
|
-
});
|
|
19
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
20
|
-
if (mod && mod.__esModule) return mod;
|
|
21
|
-
var result = {};
|
|
22
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
23
|
-
__setModuleDefault(result, mod);
|
|
24
|
-
return result;
|
|
25
|
-
};
|
|
26
3
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
27
4
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
28
5
|
};
|
|
@@ -32,7 +9,6 @@ const fs_1 = __importDefault(require("fs"));
|
|
|
32
9
|
const semver_1 = __importDefault(require("semver"));
|
|
33
10
|
const url_1 = require("url");
|
|
34
11
|
const path_2 = require("../path");
|
|
35
|
-
const standardErrors_1 = require("../../errors/standardErrors");
|
|
36
12
|
const lang_1 = require("../../utils/lang");
|
|
37
13
|
const i18nKey = 'lib.cms.processFieldsJs';
|
|
38
14
|
const { dirName, fieldOptions, filePath, writeDir } = process.env;
|
|
@@ -48,21 +24,23 @@ console.info((0, lang_1.i18n)(`${i18nKey}.converting`, {
|
|
|
48
24
|
* This function has optional return type of Promise<Array> | Array. In order to have uniform handling,
|
|
49
25
|
* we wrap the return value of the function in a Promise.resolve(), and then process.
|
|
50
26
|
*/
|
|
51
|
-
const fieldsPromise = dynamicImport(filePath).catch(e =>
|
|
27
|
+
const fieldsPromise = dynamicImport(filePath).catch(e => {
|
|
28
|
+
throw e;
|
|
29
|
+
});
|
|
52
30
|
fieldsPromise.then(fieldsFunc => {
|
|
53
31
|
const fieldsFuncType = typeof fieldsFunc;
|
|
54
32
|
if (fieldsFuncType !== 'function') {
|
|
55
|
-
(0,
|
|
33
|
+
throw new Error((0, lang_1.i18n)(`${i18nKey}.errors.notFunction`, {
|
|
56
34
|
path: filePath,
|
|
57
35
|
returned: fieldsFuncType,
|
|
58
|
-
});
|
|
36
|
+
}));
|
|
59
37
|
}
|
|
60
38
|
return Promise.resolve(fieldsFunc(fieldOptions)).then(fields => {
|
|
61
39
|
if (!Array.isArray(fields)) {
|
|
62
|
-
(0,
|
|
40
|
+
throw new Error((0, lang_1.i18n)(`${i18nKey}.errors.notArray`, {
|
|
63
41
|
path: filePath,
|
|
64
42
|
returned: typeof fields,
|
|
65
|
-
});
|
|
43
|
+
}));
|
|
66
44
|
}
|
|
67
45
|
const finalPath = path_1.default.join(writeDir, '/fields.json');
|
|
68
46
|
return fieldsArrayToJson(fields).then(json => {
|
|
@@ -106,14 +84,13 @@ async function fieldsArrayToJson(fields) {
|
|
|
106
84
|
* @returns {Promise | undefined} - Returns _default_ exported content if ESM, or exported module content if CJS, or undefined if node version < 13.2 and file is .mjs.
|
|
107
85
|
*/
|
|
108
86
|
async function dynamicImport(filePath) {
|
|
109
|
-
var _a;
|
|
110
87
|
if (semver_1.default.gte(process.version, '13.2.0')) {
|
|
111
|
-
const exported = await (
|
|
112
|
-
return exported;
|
|
88
|
+
const exported = await new Function(`return import("${(0, url_1.pathToFileURL)(filePath)}")`)();
|
|
89
|
+
return exported.default;
|
|
113
90
|
}
|
|
114
91
|
else {
|
|
115
92
|
if ((0, path_2.getExt)(filePath) == 'mjs') {
|
|
116
|
-
(0,
|
|
93
|
+
throw new Error((0, lang_1.i18n)(`${i18nKey}.errors.invalidMjsFile`));
|
|
117
94
|
}
|
|
118
95
|
return require(filePath);
|
|
119
96
|
}
|
package/lib/cms/templates.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { LogCallbacksArg } from '../../types/LogCallbacks';
|
|
2
1
|
export declare const ANNOTATION_KEYS: {
|
|
3
2
|
isAvailableForNewContent: string;
|
|
4
3
|
templateType: string;
|
|
@@ -18,8 +17,49 @@ declare const ASSET_PATHS: {
|
|
|
18
17
|
readonly 'search-template': "templates/search-template.html";
|
|
19
18
|
readonly section: "templates/section.html";
|
|
20
19
|
};
|
|
21
|
-
declare const templatesCallbackKeys: string[];
|
|
22
20
|
export declare function createTemplate(name: string, dest: string, type?: keyof typeof ASSET_PATHS, options?: {
|
|
23
21
|
allowExisting: boolean;
|
|
24
|
-
}
|
|
22
|
+
}): Promise<void>;
|
|
23
|
+
export declare const TEMPLATE_TYPES: {
|
|
24
|
+
unmapped: number;
|
|
25
|
+
email_base_template: number;
|
|
26
|
+
email: number;
|
|
27
|
+
landing_page_base_template: number;
|
|
28
|
+
landing_page: number;
|
|
29
|
+
blog_base: number;
|
|
30
|
+
blog: number;
|
|
31
|
+
blog_listing: number;
|
|
32
|
+
site_page: number;
|
|
33
|
+
blog_listing_context: number;
|
|
34
|
+
blog_post_context: number;
|
|
35
|
+
error_page: number;
|
|
36
|
+
subscription_preferences: number;
|
|
37
|
+
unsubscribe_confirmation: number;
|
|
38
|
+
unsubscribe_simple: number;
|
|
39
|
+
optin_email: number;
|
|
40
|
+
optin_followup_email: number;
|
|
41
|
+
optin_confirmation_page: number;
|
|
42
|
+
global_group: number;
|
|
43
|
+
password_prompt_page: number;
|
|
44
|
+
resubscribe_email: number;
|
|
45
|
+
unsubscribe_confirmation_email: number;
|
|
46
|
+
resubscribe_confirmation_email: number;
|
|
47
|
+
custom_module: number;
|
|
48
|
+
css: number;
|
|
49
|
+
js: number;
|
|
50
|
+
search_results: number;
|
|
51
|
+
membership_login: number;
|
|
52
|
+
membership_register: number;
|
|
53
|
+
membership_reset: number;
|
|
54
|
+
membership_reset_request: number;
|
|
55
|
+
drag_drop_email: number;
|
|
56
|
+
knowledge_article: number;
|
|
57
|
+
membership_email: number;
|
|
58
|
+
section: number;
|
|
59
|
+
global_content_partial: number;
|
|
60
|
+
simple_landing_page_template: number;
|
|
61
|
+
proposal: number;
|
|
62
|
+
blog_post: number;
|
|
63
|
+
quote: number;
|
|
64
|
+
};
|
|
25
65
|
export {};
|
package/lib/cms/templates.js
CHANGED
|
@@ -3,12 +3,12 @@ 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.createTemplate = exports.isCodedFile = exports.getAnnotationValue = exports.ANNOTATION_KEYS = void 0;
|
|
6
|
+
exports.TEMPLATE_TYPES = exports.createTemplate = exports.isCodedFile = exports.getAnnotationValue = exports.ANNOTATION_KEYS = void 0;
|
|
7
7
|
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
8
8
|
const path_1 = __importDefault(require("path"));
|
|
9
9
|
const github_1 = require("../github");
|
|
10
|
-
const
|
|
11
|
-
const
|
|
10
|
+
const logger_1 = require("../logger");
|
|
11
|
+
const lang_1 = require("../../utils/lang");
|
|
12
12
|
const i18nKey = 'lib.cms.templates';
|
|
13
13
|
// Matches the .html file extension, excluding module.html
|
|
14
14
|
const TEMPLATE_EXTENSION_REGEX = new RegExp(/(?<!module)\.html$/);
|
|
@@ -46,22 +46,64 @@ const ASSET_PATHS = {
|
|
|
46
46
|
'search-template': 'templates/search-template.html',
|
|
47
47
|
section: 'templates/section.html',
|
|
48
48
|
};
|
|
49
|
-
|
|
50
|
-
async function createTemplate(name, dest, type = 'page-template', options = { allowExisting: false }, logCallbacks) {
|
|
49
|
+
async function createTemplate(name, dest, type = 'page-template', options = { allowExisting: false }) {
|
|
51
50
|
const assetPath = ASSET_PATHS[type];
|
|
52
51
|
const filename = name.endsWith('.html') ? name : `${name}.html`;
|
|
53
52
|
const filePath = path_1.default.join(dest, filename);
|
|
54
53
|
if (!options.allowExisting && fs_extra_1.default.existsSync(filePath)) {
|
|
55
|
-
(0,
|
|
54
|
+
throw new Error((0, lang_1.i18n)(`${i18nKey}.createTemplate.errors.pathExists`, {
|
|
56
55
|
path: filePath,
|
|
57
|
-
});
|
|
56
|
+
}));
|
|
58
57
|
}
|
|
59
|
-
(0,
|
|
58
|
+
logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.createTemplate.creatingPath`, { path: dest }));
|
|
60
59
|
fs_extra_1.default.mkdirp(dest);
|
|
61
|
-
|
|
62
|
-
logger('creatingFile', `${i18nKey}.createTemplate.creatingFile`, {
|
|
60
|
+
logger_1.logger.log((0, lang_1.i18n)(`${i18nKey}.createTemplate.creatingFile`, {
|
|
63
61
|
path: filePath,
|
|
62
|
+
}));
|
|
63
|
+
await (0, github_1.cloneGithubRepo)('HubSpot/cms-sample-assets', filePath, {
|
|
64
|
+
sourceDir: assetPath,
|
|
64
65
|
});
|
|
65
|
-
await (0, github_1.downloadGithubRepoContents)('HubSpot/cms-sample-assets', assetPath, filePath);
|
|
66
66
|
}
|
|
67
67
|
exports.createTemplate = createTemplate;
|
|
68
|
+
exports.TEMPLATE_TYPES = {
|
|
69
|
+
unmapped: 0,
|
|
70
|
+
email_base_template: 1,
|
|
71
|
+
email: 2,
|
|
72
|
+
landing_page_base_template: 3,
|
|
73
|
+
landing_page: 4,
|
|
74
|
+
blog_base: 5,
|
|
75
|
+
blog: 6,
|
|
76
|
+
blog_listing: 42,
|
|
77
|
+
site_page: 8,
|
|
78
|
+
blog_listing_context: 9,
|
|
79
|
+
blog_post_context: 10,
|
|
80
|
+
error_page: 11,
|
|
81
|
+
subscription_preferences: 12,
|
|
82
|
+
unsubscribe_confirmation: 13,
|
|
83
|
+
unsubscribe_simple: 14,
|
|
84
|
+
optin_email: 15,
|
|
85
|
+
optin_followup_email: 16,
|
|
86
|
+
optin_confirmation_page: 17,
|
|
87
|
+
global_group: 18,
|
|
88
|
+
password_prompt_page: 19,
|
|
89
|
+
resubscribe_email: 20,
|
|
90
|
+
unsubscribe_confirmation_email: 21,
|
|
91
|
+
resubscribe_confirmation_email: 22,
|
|
92
|
+
custom_module: 23,
|
|
93
|
+
css: 24,
|
|
94
|
+
js: 25,
|
|
95
|
+
search_results: 27,
|
|
96
|
+
membership_login: 29,
|
|
97
|
+
membership_register: 30,
|
|
98
|
+
membership_reset: 31,
|
|
99
|
+
membership_reset_request: 32,
|
|
100
|
+
drag_drop_email: 34,
|
|
101
|
+
knowledge_article: 35,
|
|
102
|
+
membership_email: 36,
|
|
103
|
+
section: 37,
|
|
104
|
+
global_content_partial: 38,
|
|
105
|
+
simple_landing_page_template: 39,
|
|
106
|
+
proposal: 40,
|
|
107
|
+
blog_post: 41,
|
|
108
|
+
quote: 43,
|
|
109
|
+
};
|
|
@@ -1,18 +1,7 @@
|
|
|
1
1
|
import { FieldsJs } from './handleFieldsJS';
|
|
2
2
|
import { FileMapperInputOptions } from '../../types/Files';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { Mode } from '../../types/Files';
|
|
6
|
-
type CommandOptions = {
|
|
7
|
-
convertFields?: boolean;
|
|
8
|
-
fieldOptions?: string;
|
|
9
|
-
saveOutput?: boolean;
|
|
10
|
-
};
|
|
11
|
-
type FilePathsByType = {
|
|
12
|
-
[key: string]: Array<string>;
|
|
13
|
-
};
|
|
3
|
+
import { UploadFolderResults, CommandOptions, FilePathsByType } from '../../types/Files';
|
|
4
|
+
import { CmsPublishMode } from '../../types/Files';
|
|
14
5
|
export declare function getFilesByType(filePaths: Array<string>, projectDir: string, rootWriteDir: string | null, commandOptions: CommandOptions): Promise<[FilePathsByType, Array<FieldsJs>]>;
|
|
15
|
-
declare
|
|
16
|
-
export declare function uploadFolder(accountId: number, src: string, dest: string, fileMapperOptions: FileMapperInputOptions, commandOptions?: CommandOptions, filePaths?: Array<string>, mode?: Mode | null, logCallbacks?: LogCallbacksArg<typeof uploadFolderCallbackKeys>): Promise<Array<UploadFolderResults>>;
|
|
6
|
+
export declare function uploadFolder(accountId: number, src: string, dest: string, fileMapperOptions: FileMapperInputOptions, commandOptions?: CommandOptions, filePaths?: Array<string>, cmsPublishMode?: CmsPublishMode | null): Promise<Array<UploadFolderResults>>;
|
|
17
7
|
export declare function hasUploadErrors(results: Array<UploadFolderResults>): boolean;
|
|
18
|
-
export {};
|
package/lib/cms/uploadFolder.js
CHANGED
|
@@ -10,13 +10,13 @@ const handleFieldsJS_1 = require("./handleFieldsJS");
|
|
|
10
10
|
const fileMapper_1 = require("../fileMapper");
|
|
11
11
|
const fileMapper_2 = require("../../api/fileMapper");
|
|
12
12
|
const modules_1 = require("../../utils/cms/modules");
|
|
13
|
-
const escapeRegExp_1 = require("
|
|
14
|
-
const logger_1 = require("../../utils/logger");
|
|
13
|
+
const escapeRegExp_1 = require("../escapeRegExp");
|
|
15
14
|
const path_2 = require("../path");
|
|
16
|
-
const
|
|
17
|
-
const
|
|
18
|
-
const logger_2 = require("../../utils/logger");
|
|
15
|
+
const errors_1 = require("../../errors");
|
|
16
|
+
const logger_1 = require("../logger");
|
|
19
17
|
const files_1 = require("../../constants/files");
|
|
18
|
+
const lang_1 = require("../../utils/lang");
|
|
19
|
+
const HubSpotHttpError_1 = require("../../models/HubSpotHttpError");
|
|
20
20
|
const i18nKey = 'lib.cms.uploadFolder';
|
|
21
21
|
const queue = new p_queue_1.default({
|
|
22
22
|
concurrency: 10,
|
|
@@ -76,15 +76,48 @@ async function getFilesByType(filePaths, projectDir, rootWriteDir, commandOption
|
|
|
76
76
|
return [filePathsByType, fieldsJsObjects];
|
|
77
77
|
}
|
|
78
78
|
exports.getFilesByType = getFilesByType;
|
|
79
|
-
const
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
79
|
+
const defaultUploadAttemptCallback = (file, destPath) => logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.uploadFolder.attempt`, {
|
|
80
|
+
file: file || '',
|
|
81
|
+
destPath,
|
|
82
|
+
}));
|
|
83
|
+
const defaultUploadSuccessCallback = (file, destPath) => logger_1.logger.log((0, lang_1.i18n)(`${i18nKey}.uploadFolder.success`, {
|
|
84
|
+
file: file || '',
|
|
85
|
+
destPath,
|
|
86
|
+
}));
|
|
87
|
+
const defaultUploadFirstErrorCallback = (file, destPath, error) => {
|
|
88
|
+
logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.uploadFolder.failed`, { file, destPath }));
|
|
89
|
+
if ((0, errors_1.isHubSpotHttpError)(error)) {
|
|
90
|
+
logger_1.logger.debug(error.data);
|
|
91
|
+
}
|
|
92
|
+
else if (error instanceof Error) {
|
|
93
|
+
logger_1.logger.debug(error.message);
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
const defaultUploadRetryCallback = (file, destPath) => logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.uploadFolder.retry`, { file, destPath }));
|
|
97
|
+
const defaultUploadFinalErrorCallback = (accountId, file, destPath, error) => {
|
|
98
|
+
const retryFailed = (0, lang_1.i18n)(`${i18nKey}.uploadFolder.retryFailed`, {
|
|
99
|
+
file,
|
|
100
|
+
destPath,
|
|
101
|
+
});
|
|
102
|
+
logger_1.logger.debug(retryFailed);
|
|
103
|
+
throw new HubSpotHttpError_1.HubSpotHttpError(retryFailed, { cause: error }, {
|
|
104
|
+
accountId,
|
|
105
|
+
request: destPath,
|
|
106
|
+
payload: file,
|
|
107
|
+
});
|
|
108
|
+
};
|
|
109
|
+
async function uploadFolder(accountId, src, dest, fileMapperOptions, commandOptions = {}, filePaths = [], cmsPublishMode = null) {
|
|
110
|
+
const { saveOutput, convertFields, onAttemptCallback, onSuccessCallback, onFirstErrorCallback, onRetryCallback, onFinalErrorCallback, } = commandOptions;
|
|
111
|
+
const _onAttemptCallback = onAttemptCallback || defaultUploadAttemptCallback;
|
|
112
|
+
const _onSuccessCallback = onSuccessCallback || defaultUploadSuccessCallback;
|
|
113
|
+
const _onFirstErrorCallback = onFirstErrorCallback || defaultUploadFirstErrorCallback;
|
|
114
|
+
const _onRetryCallback = onRetryCallback || defaultUploadRetryCallback;
|
|
115
|
+
const _onFinalErrorCallback = onFinalErrorCallback || defaultUploadFinalErrorCallback;
|
|
83
116
|
const tmpDir = convertFields
|
|
84
117
|
? (0, handleFieldsJS_1.createTmpDirSync)('hubspot-temp-fieldsjs-output-')
|
|
85
118
|
: null;
|
|
86
119
|
const regex = new RegExp(`^${(0, escapeRegExp_1.escapeRegExp)(src)}`);
|
|
87
|
-
const apiOptions = (0, fileMapper_1.getFileMapperQueryValues)(
|
|
120
|
+
const apiOptions = (0, fileMapper_1.getFileMapperQueryValues)(cmsPublishMode, fileMapperOptions);
|
|
88
121
|
const failures = [];
|
|
89
122
|
let fieldsJsPaths = [];
|
|
90
123
|
let tmpDirRegex;
|
|
@@ -105,29 +138,16 @@ async function uploadFolder(accountId, src, dest, fileMapperOptions, commandOpti
|
|
|
105
138
|
const relativePath = file.replace(fieldsJsFileInfo ? tmpDirRegex : regex, '');
|
|
106
139
|
const destPath = (0, path_2.convertToUnixPath)(path_1.default.join(dest, relativePath));
|
|
107
140
|
return async () => {
|
|
108
|
-
(
|
|
109
|
-
file: originalFilePath || '',
|
|
110
|
-
destPath,
|
|
111
|
-
});
|
|
141
|
+
_onAttemptCallback(originalFilePath, destPath);
|
|
112
142
|
try {
|
|
113
143
|
await (0, fileMapper_2.upload)(accountId, file, destPath, apiOptions);
|
|
114
|
-
|
|
115
|
-
file: originalFilePath || '',
|
|
116
|
-
destPath,
|
|
117
|
-
});
|
|
144
|
+
_onSuccessCallback(originalFilePath, destPath);
|
|
118
145
|
}
|
|
119
146
|
catch (err) {
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
throw error;
|
|
123
|
-
}
|
|
124
|
-
(0, logger_1.debug)(`${i18nKey}.uploadFolder.failed`, { file, destPath });
|
|
125
|
-
if (error.response && error.response.data) {
|
|
126
|
-
console.debug(error.response.data);
|
|
127
|
-
}
|
|
128
|
-
else {
|
|
129
|
-
console.debug(error.message);
|
|
147
|
+
if ((0, errors_1.isAuthError)(err)) {
|
|
148
|
+
throw err;
|
|
130
149
|
}
|
|
150
|
+
_onFirstErrorCallback(file, destPath, err);
|
|
131
151
|
failures.push({
|
|
132
152
|
file,
|
|
133
153
|
destPath,
|
|
@@ -142,30 +162,26 @@ async function uploadFolder(accountId, src, dest, fileMapperOptions, commandOpti
|
|
|
142
162
|
const results = await queue
|
|
143
163
|
.addAll(failures.map(({ file, destPath }) => {
|
|
144
164
|
return async () => {
|
|
145
|
-
(
|
|
165
|
+
_onRetryCallback(file, destPath);
|
|
146
166
|
try {
|
|
147
167
|
await (0, fileMapper_2.upload)(accountId, file, destPath, apiOptions);
|
|
148
|
-
|
|
149
|
-
file,
|
|
150
|
-
destPath,
|
|
151
|
-
});
|
|
168
|
+
_onSuccessCallback(file, destPath);
|
|
152
169
|
return {
|
|
153
170
|
resultType: files_1.FILE_UPLOAD_RESULT_TYPES.SUCCESS,
|
|
154
171
|
error: null,
|
|
155
172
|
file,
|
|
156
173
|
};
|
|
157
174
|
}
|
|
158
|
-
catch (
|
|
159
|
-
(0,
|
|
160
|
-
const error = err;
|
|
161
|
-
if ((0, standardErrors_1.isFatalError)(error)) {
|
|
175
|
+
catch (error) {
|
|
176
|
+
if ((0, errors_1.isAuthError)(error)) {
|
|
162
177
|
throw error;
|
|
163
178
|
}
|
|
164
|
-
(
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
179
|
+
_onFinalErrorCallback(accountId, file, destPath, error);
|
|
180
|
+
return {
|
|
181
|
+
resultType: files_1.FILE_UPLOAD_RESULT_TYPES.FAILURE,
|
|
182
|
+
error,
|
|
183
|
+
file,
|
|
184
|
+
};
|
|
169
185
|
}
|
|
170
186
|
};
|
|
171
187
|
}))
|
package/lib/cms/validate.js
CHANGED
|
@@ -26,7 +26,7 @@ async function lint(accountId, filepath, callback) {
|
|
|
26
26
|
}
|
|
27
27
|
return result;
|
|
28
28
|
}
|
|
29
|
-
const validation = await (0, validateHubl_1.validateHubl)(accountId, source);
|
|
29
|
+
const { data: validation } = await (0, validateHubl_1.validateHubl)(accountId, source);
|
|
30
30
|
const result = {
|
|
31
31
|
file,
|
|
32
32
|
validation,
|
package/lib/cms/watch.d.ts
CHANGED
|
@@ -1,20 +1,4 @@
|
|
|
1
1
|
import chokidar from 'chokidar';
|
|
2
|
-
import {
|
|
3
|
-
import { LogCallbacksArg } from '../../types/LogCallbacks';
|
|
4
|
-
import { Mode } from '../../types/Files';
|
|
2
|
+
import { WatchOptions, WatchErrorHandler } from '../../types/Files';
|
|
5
3
|
import { UploadFolderResults } from '../../types/Files';
|
|
6
|
-
declare
|
|
7
|
-
type WatchLogCallbacks = LogCallbacksArg<typeof watchCallbackKeys>;
|
|
8
|
-
type WatchOptions = {
|
|
9
|
-
mode?: Mode;
|
|
10
|
-
remove?: boolean;
|
|
11
|
-
disableInitial?: boolean;
|
|
12
|
-
notify?: string;
|
|
13
|
-
commandOptions: {
|
|
14
|
-
convertFields?: boolean;
|
|
15
|
-
};
|
|
16
|
-
filePaths?: Array<string>;
|
|
17
|
-
};
|
|
18
|
-
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, logCallbacks?: WatchLogCallbacks): chokidar.FSWatcher;
|
|
20
|
-
export {};
|
|
4
|
+
export declare function watch(accountId: number, src: string, dest: string, { cmsPublishMode, remove, disableInitial, notify, commandOptions, filePaths, }: WatchOptions, postInitialUploadCallback?: ((result: Array<UploadFolderResults>) => void) | null, onUploadFolderError?: WatchErrorHandler, onQueueAddError?: WatchErrorHandler, onUploadFileError?: (file: string, dest: string, accountId: number) => WatchErrorHandler): chokidar.FSWatcher;
|