@hubspot/local-dev-lib 0.6.1-experimental.0 → 0.6.3-experimental.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/api/appsDev.d.ts +2 -2
- package/api/appsDev.js +13 -22
- package/api/crm.d.ts +2 -2
- package/api/crm.js +9 -16
- package/api/customObjects.d.ts +2 -2
- package/api/customObjects.js +13 -22
- package/api/designManager.d.ts +2 -2
- package/api/designManager.js +5 -10
- package/api/devSecrets.d.ts +2 -2
- package/api/devSecrets.js +9 -16
- package/api/developerTestAccounts.d.ts +2 -4
- package/api/developerTestAccounts.js +23 -55
- package/api/fileManager.d.ts +2 -2
- package/api/fileManager.js +14 -24
- package/api/fileMapper.d.ts +2 -3
- package/api/fileMapper.js +34 -49
- package/api/fileTransport.d.ts +1 -1
- package/api/fileTransport.js +12 -21
- package/api/fireAlarm.d.ts +2 -3
- package/api/fireAlarm.js +5 -9
- package/api/functions.d.ts +2 -2
- package/api/functions.js +11 -19
- package/api/github.d.ts +2 -4
- package/api/github.js +16 -27
- package/api/hubdb.d.ts +2 -2
- package/api/hubdb.js +19 -31
- package/api/lighthouseScore.d.ts +2 -2
- package/api/lighthouseScore.js +7 -13
- package/api/localDevAuth.d.ts +3 -6
- package/api/localDevAuth.js +10 -40
- package/api/marketplaceValidation.d.ts +2 -2
- package/api/marketplaceValidation.js +7 -13
- package/api/projects.d.ts +6 -8
- package/api/projects.js +65 -100
- package/api/sandboxHubs.d.ts +2 -5
- package/api/sandboxHubs.js +15 -45
- package/api/sandboxSync.d.ts +2 -2
- package/api/sandboxSync.js +7 -12
- package/api/secrets.d.ts +2 -2
- package/api/secrets.js +9 -16
- package/api/validateHubl.d.ts +2 -2
- package/api/validateHubl.js +3 -7
- package/config/defaultAccountOverride.d.ts +2 -1
- package/config/defaultAccountOverride.js +16 -26
- package/config/index.d.ts +4 -4
- package/config/index.js +144 -177
- package/config/migrate.d.ts +2 -2
- package/config/migrate.js +26 -37
- package/config/state.d.ts +1 -1
- package/config/state.js +17 -45
- package/config/utils.d.ts +4 -4
- package/config/utils.js +85 -108
- package/constants/api.js +3 -6
- package/constants/auth.js +9 -12
- package/constants/config.d.ts +30 -1
- package/constants/config.js +65 -42
- package/constants/endpoints.d.ts +6 -0
- package/constants/endpoints.js +6 -0
- package/constants/environments.js +1 -4
- package/constants/extensions.js +6 -9
- package/constants/files.js +5 -8
- package/constants/ports.js +3 -6
- package/constants/projects.js +2 -5
- package/enums/build.d.ts +1 -0
- package/enums/build.js +6 -8
- package/enums/deploy.js +2 -5
- package/enums/project.js +1 -4
- package/errors/index.d.ts +4 -5
- package/errors/index.js +17 -39
- package/errors/isSystemError.d.ts +2 -0
- package/errors/isSystemError.js +9 -0
- package/http/addQueryParams.d.ts +1 -1
- package/http/addQueryParams.js +1 -5
- package/http/client.d.ts +1 -0
- package/http/client.js +54 -0
- package/http/getAxiosConfig.d.ts +1 -1
- package/http/getAxiosConfig.js +21 -31
- package/http/index.d.ts +2 -2
- package/http/index.js +39 -124
- package/http/unauthed.d.ts +1 -1
- package/http/unauthed.js +15 -21
- package/lang/en.json +3 -2
- package/lib/archive.d.ts +1 -3
- package/lib/archive.js +37 -67
- package/lib/cms/functions.d.ts +1 -1
- package/lib/cms/functions.js +45 -55
- package/lib/cms/handleFieldsJS.js +36 -44
- package/lib/cms/modules.d.ts +2 -2
- package/lib/cms/modules.js +49 -59
- package/lib/cms/processFieldsJs.js +17 -32
- package/lib/cms/templates.js +17 -26
- package/lib/cms/themes.js +10 -18
- package/lib/cms/uploadFolder.d.ts +4 -4
- package/lib/cms/uploadFolder.js +55 -64
- package/lib/cms/validate.d.ts +1 -1
- package/lib/cms/validate.js +11 -18
- package/lib/cms/watch.d.ts +2 -2
- package/lib/cms/watch.js +66 -73
- package/lib/crm.d.ts +1 -1
- package/lib/crm.js +15 -23
- package/lib/customObjects.d.ts +1 -1
- package/lib/customObjects.js +15 -25
- package/lib/environment.d.ts +1 -1
- package/lib/environment.js +5 -11
- package/lib/escapeRegExp.js +1 -5
- package/lib/fileManager.js +43 -51
- package/lib/fileMapper.d.ts +1 -1
- package/lib/fileMapper.js +68 -84
- package/lib/fs.d.ts +1 -1
- package/lib/fs.js +18 -27
- package/lib/github.d.ts +1 -3
- package/lib/github.js +39 -51
- package/lib/gitignore.d.ts +1 -1
- package/lib/gitignore.js +16 -24
- package/lib/hubdb.d.ts +1 -1
- package/lib/hubdb.js +29 -40
- package/lib/ignoreRules.js +25 -34
- package/lib/isDeepEqual.js +1 -5
- package/lib/logger.d.ts +8 -20
- package/lib/logger.js +47 -59
- package/lib/notify.js +9 -16
- package/lib/oauth.d.ts +2 -2
- package/lib/oauth.js +12 -17
- package/lib/path.d.ts +0 -1
- package/lib/path.js +30 -48
- package/lib/personalAccessKey.d.ts +2 -4
- package/lib/personalAccessKey.js +43 -60
- package/lib/portManager.d.ts +2 -2
- package/lib/portManager.js +26 -41
- package/lib/text.js +2 -7
- package/lib/trackUsage.d.ts +0 -2
- package/lib/trackUsage.js +27 -31
- package/lib/urls.js +4 -9
- package/models/FileSystemError.d.ts +1 -1
- package/models/FileSystemError.js +12 -16
- package/models/HubSpotConfigError.d.ts +1 -1
- package/models/HubSpotConfigError.js +8 -12
- package/models/HubSpotHttpError.d.ts +1 -1
- package/models/HubSpotHttpError.js +22 -26
- package/models/OAuth2Manager.d.ts +1 -1
- package/models/OAuth2Manager.js +17 -24
- package/package.json +21 -17
- package/types/Accounts.d.ts +6 -5
- package/types/Accounts.js +1 -2
- package/types/Activity.d.ts +3 -3
- package/types/Activity.js +1 -2
- package/types/Api.d.ts +1 -1
- package/types/Api.js +1 -2
- package/types/Apps.js +1 -2
- package/types/Archive.js +1 -2
- package/types/Build.d.ts +4 -5
- package/types/Build.js +1 -2
- package/types/CLIOptions.js +1 -2
- package/types/ComponentStructure.d.ts +2 -2
- package/types/ComponentStructure.js +1 -2
- package/types/Config.d.ts +4 -6
- package/types/Config.js +1 -2
- package/types/Crm.js +1 -2
- package/types/Deploy.d.ts +5 -11
- package/types/Deploy.js +1 -2
- package/types/DesignManager.js +1 -2
- package/types/DevSecrets.js +1 -2
- package/types/Error.js +1 -2
- package/types/FieldsJS.js +1 -2
- package/types/FileManager.js +1 -2
- package/types/Files.d.ts +4 -4
- package/types/Files.js +1 -2
- package/types/FireAlarm.js +1 -2
- package/types/Functions.js +1 -2
- package/types/Github.d.ts +1 -1
- package/types/Github.js +1 -2
- package/types/Http.d.ts +0 -4
- package/types/Http.js +1 -2
- package/types/Hubdb.js +1 -2
- package/types/HublValidation.js +1 -2
- package/types/Lang.d.ts +1 -1
- package/types/Lang.js +1 -2
- package/types/Lighthouse.js +1 -2
- package/types/MarketplaceValidation.js +1 -2
- package/types/Migration.d.ts +2 -2
- package/types/Migration.js +1 -4
- package/types/Modules.js +1 -2
- package/types/PortManager.js +1 -2
- package/types/Project.d.ts +3 -21
- package/types/Project.js +1 -2
- package/types/ProjectComponents.d.ts +24 -0
- package/types/ProjectComponents.js +1 -0
- package/types/ProjectLog.js +1 -2
- package/types/Sandbox.js +2 -5
- package/types/Schemas.js +1 -2
- package/types/Secrets.js +1 -2
- package/types/Utils.js +1 -2
- package/types/developerTestAccounts.js +1 -2
- package/utils/PortManagerServer.d.ts +1 -2
- package/utils/PortManagerServer.js +32 -38
- package/utils/cms/fieldsJS.d.ts +1 -1
- package/utils/cms/fieldsJS.js +1 -5
- package/utils/cms/modules.d.ts +1 -1
- package/utils/cms/modules.js +13 -22
- package/utils/detectPort.js +12 -19
- package/utils/git.js +17 -26
- package/utils/lang.d.ts +1 -1
- package/utils/lang.js +5 -14
- package/utils/personalAccessKey.d.ts +8 -0
- package/utils/personalAccessKey.js +51 -0
- package/errors/errors_DEPRECATED.d.ts +0 -3
- package/errors/errors_DEPRECATED.js +0 -60
package/lib/cms/modules.js
CHANGED
|
@@ -1,20 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const path_2 = require("../path");
|
|
10
|
-
const fs_1 = require("../fs");
|
|
11
|
-
const github_1 = require("../github");
|
|
12
|
-
const logger_1 = require("../logger");
|
|
13
|
-
const modules_1 = require("../../utils/cms/modules");
|
|
14
|
-
const lang_1 = require("../../utils/lang");
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import fs from 'fs-extra';
|
|
3
|
+
import { getCwd } from '../path.js';
|
|
4
|
+
import { walk } from '../fs.js';
|
|
5
|
+
import { listGithubRepoContents, cloneGithubRepo } from '../github.js';
|
|
6
|
+
import { logger } from '../logger.js';
|
|
7
|
+
import { isPathInput, isModuleFolder, isModuleFolderChild, } from '../../utils/cms/modules.js';
|
|
8
|
+
import { i18n } from '../../utils/lang.js';
|
|
15
9
|
const i18nKey = 'lib.cms.modules';
|
|
16
10
|
// Ids for testing
|
|
17
|
-
|
|
11
|
+
export const ValidationIds = {
|
|
18
12
|
SRC_REQUIRED: 'SRC_REQUIRED',
|
|
19
13
|
DEST_REQUIRED: 'DEST_REQUIRED',
|
|
20
14
|
MODULE_FOLDER_REQUIRED: 'MODULE_FOLDER_REQUIRED',
|
|
@@ -22,13 +16,13 @@ exports.ValidationIds = {
|
|
|
22
16
|
MODULE_NESTING: 'MODULE_NESTING',
|
|
23
17
|
};
|
|
24
18
|
const getValidationResult = (id, message) => ({ id, message });
|
|
25
|
-
async function validateSrcAndDestPaths(src, dest) {
|
|
19
|
+
export async function validateSrcAndDestPaths(src, dest) {
|
|
26
20
|
const results = [];
|
|
27
|
-
if (!
|
|
28
|
-
results.push(getValidationResult(
|
|
21
|
+
if (!isPathInput(src)) {
|
|
22
|
+
results.push(getValidationResult(ValidationIds.SRC_REQUIRED, '`src` is required.'));
|
|
29
23
|
}
|
|
30
|
-
if (!
|
|
31
|
-
results.push(getValidationResult(
|
|
24
|
+
if (!isPathInput(dest)) {
|
|
25
|
+
results.push(getValidationResult(ValidationIds.DEST_REQUIRED, '`dest` is required.'));
|
|
32
26
|
}
|
|
33
27
|
if (results.length || !src || !dest) {
|
|
34
28
|
return results;
|
|
@@ -36,37 +30,36 @@ async function validateSrcAndDestPaths(src, dest) {
|
|
|
36
30
|
const [_src, _dest] = [src, dest].map(inputPath => {
|
|
37
31
|
const result = { ...inputPath };
|
|
38
32
|
if (result.isLocal) {
|
|
39
|
-
result.path =
|
|
33
|
+
result.path = path.resolve(getCwd(), result.path);
|
|
40
34
|
}
|
|
41
35
|
else if (result.isHubSpot) {
|
|
42
|
-
result.path =
|
|
36
|
+
result.path = path.posix.normalize(result.path);
|
|
43
37
|
}
|
|
44
38
|
return result;
|
|
45
39
|
});
|
|
46
40
|
// src is a .module folder and dest is within a module. (Nesting)
|
|
47
41
|
// e.g. `upload foo.module bar.module/zzz`
|
|
48
|
-
if (
|
|
49
|
-
return results.concat(getValidationResult(
|
|
42
|
+
if (isModuleFolder(_src) && isModuleFolderChild(_dest)) {
|
|
43
|
+
return results.concat(getValidationResult(ValidationIds.MODULE_TO_MODULE_NESTING, '`src` is a module path and `dest` is within a module.'));
|
|
50
44
|
}
|
|
51
45
|
// src is a .module folder but dest is not
|
|
52
46
|
// e.g. `upload foo.module bar`
|
|
53
|
-
if (
|
|
54
|
-
return results.concat(getValidationResult(
|
|
47
|
+
if (isModuleFolder(_src) && !isModuleFolder(_dest)) {
|
|
48
|
+
return results.concat(getValidationResult(ValidationIds.MODULE_FOLDER_REQUIRED, '`src` is a module path but `dest` is not.'));
|
|
55
49
|
}
|
|
56
50
|
// src is a folder that includes modules and dest is within a module. (Nesting)
|
|
57
|
-
if (_src.isLocal &&
|
|
58
|
-
const stat = await
|
|
51
|
+
if (_src.isLocal && isModuleFolderChild(_dest)) {
|
|
52
|
+
const stat = await fs.stat(_src.path);
|
|
59
53
|
if (stat.isDirectory()) {
|
|
60
|
-
const files = await
|
|
61
|
-
const srcHasModulesChildren = files.some(file =>
|
|
54
|
+
const files = await walk(_src.path);
|
|
55
|
+
const srcHasModulesChildren = files.some(file => isModuleFolderChild({ ..._src, path: file }));
|
|
62
56
|
if (srcHasModulesChildren) {
|
|
63
|
-
return results.concat(getValidationResult(
|
|
57
|
+
return results.concat(getValidationResult(ValidationIds.MODULE_NESTING, '`src` contains modules and `dest` is within a module.'));
|
|
64
58
|
}
|
|
65
59
|
}
|
|
66
60
|
}
|
|
67
61
|
return results;
|
|
68
62
|
}
|
|
69
|
-
exports.validateSrcAndDestPaths = validateSrcAndDestPaths;
|
|
70
63
|
/* createModule() helper
|
|
71
64
|
* Takes a file and uses the constants above to transform the contents
|
|
72
65
|
*/
|
|
@@ -85,25 +78,25 @@ const MODULE_STRING_TRANSFORMATIONS = [
|
|
|
85
78
|
];
|
|
86
79
|
const updateFileContents = async (file, metaData, getInternalVersion) => {
|
|
87
80
|
try {
|
|
88
|
-
let fileContents = await
|
|
81
|
+
let fileContents = await fs.readFile(file, 'utf8'); // returns Promise
|
|
89
82
|
MODULE_STRING_TRANSFORMATIONS.forEach(entry => {
|
|
90
83
|
const replacementString = getInternalVersion
|
|
91
84
|
? entry.string
|
|
92
85
|
: entry.fallback;
|
|
93
86
|
fileContents = fileContents.replace(entry.regex, replacementString);
|
|
94
87
|
});
|
|
95
|
-
await
|
|
96
|
-
await
|
|
88
|
+
await fs.writeFile(file, fileContents, 'utf8');
|
|
89
|
+
await fs.appendFile(file, 'export const meta = ' + JSON.stringify(metaData, null, ' '));
|
|
97
90
|
}
|
|
98
91
|
catch (error) {
|
|
99
92
|
const { message } = error;
|
|
100
|
-
throw new Error(
|
|
93
|
+
throw new Error(i18n(`${i18nKey}.createModule.errors.fileUpdateFailure`, {
|
|
101
94
|
path: file,
|
|
102
95
|
errorMessage: message,
|
|
103
96
|
}));
|
|
104
97
|
}
|
|
105
98
|
};
|
|
106
|
-
async function createModule(moduleDefinition, name, dest, getInternalVersion, options = {
|
|
99
|
+
export async function createModule(moduleDefinition, name, dest, getInternalVersion, options = {
|
|
107
100
|
allowExistingDir: false,
|
|
108
101
|
}) {
|
|
109
102
|
const { moduleLabel, contentTypes, global, reactType: isReactModule, availableForNewContent, } = moduleDefinition;
|
|
@@ -122,26 +115,26 @@ async function createModule(moduleDefinition, name, dest, getInternalVersion, op
|
|
|
122
115
|
};
|
|
123
116
|
const folderName = name.endsWith('.module') ? name : `${name}.module`;
|
|
124
117
|
const destPath = !isReactModule
|
|
125
|
-
?
|
|
126
|
-
:
|
|
127
|
-
if (!options.allowExistingDir &&
|
|
128
|
-
throw new Error(
|
|
118
|
+
? path.join(dest, folderName)
|
|
119
|
+
: path.join(dest, `${name}`);
|
|
120
|
+
if (!options.allowExistingDir && fs.existsSync(destPath)) {
|
|
121
|
+
throw new Error(i18n(`${i18nKey}.createModule.errors.pathExists`, {
|
|
129
122
|
path: destPath,
|
|
130
123
|
}));
|
|
131
124
|
}
|
|
132
125
|
else {
|
|
133
|
-
|
|
126
|
+
logger.log(i18n(`${i18nKey}.createModule.creatingPath`, {
|
|
134
127
|
path: destPath,
|
|
135
128
|
}));
|
|
136
|
-
|
|
129
|
+
fs.ensureDirSync(destPath);
|
|
137
130
|
}
|
|
138
|
-
|
|
131
|
+
logger.log(i18n(`${i18nKey}.createModule.creatingModule`, {
|
|
139
132
|
path: destPath,
|
|
140
133
|
}));
|
|
141
134
|
// Filter out certain fetched files from the response
|
|
142
135
|
const moduleFileFilter = (src) => {
|
|
143
136
|
const emailEnabled = moduleDefinition.contentTypes.includes('EMAIL');
|
|
144
|
-
switch (
|
|
137
|
+
switch (path.basename(src)) {
|
|
145
138
|
case 'meta.json':
|
|
146
139
|
return false;
|
|
147
140
|
case 'module.js':
|
|
@@ -158,23 +151,23 @@ async function createModule(moduleDefinition, name, dest, getInternalVersion, op
|
|
|
158
151
|
? 'Sample.module'
|
|
159
152
|
: 'SampleReactModule';
|
|
160
153
|
const sourceDir = `modules/${sampleAssetPath}`;
|
|
161
|
-
await
|
|
154
|
+
await cloneGithubRepo('HubSpot/cms-sample-assets', destPath, {
|
|
162
155
|
sourceDir,
|
|
163
156
|
});
|
|
164
|
-
const files = await
|
|
157
|
+
const files = await walk(destPath);
|
|
165
158
|
files
|
|
166
159
|
.filter(filePath => !moduleFileFilter(filePath))
|
|
167
160
|
.forEach(filePath => {
|
|
168
|
-
|
|
161
|
+
fs.unlinkSync(filePath);
|
|
169
162
|
});
|
|
170
163
|
if (!getInternalVersion) {
|
|
171
|
-
|
|
172
|
-
|
|
164
|
+
fs.removeSync(path.join(destPath, 'stories'));
|
|
165
|
+
fs.removeSync(path.join(destPath, 'tests'));
|
|
173
166
|
}
|
|
174
167
|
// Get and write the metafiles
|
|
175
|
-
const metaFiles = files.filter(filePath =>
|
|
168
|
+
const metaFiles = files.filter(filePath => path.basename(filePath) === 'meta.json');
|
|
176
169
|
metaFiles.forEach(metaFile => {
|
|
177
|
-
|
|
170
|
+
fs.writeJSONSync(metaFile, moduleMetaData, {
|
|
178
171
|
spaces: 2,
|
|
179
172
|
});
|
|
180
173
|
});
|
|
@@ -183,19 +176,16 @@ async function createModule(moduleDefinition, name, dest, getInternalVersion, op
|
|
|
183
176
|
await updateFileContents(`${destPath}/index.tsx`, moduleMetaData, getInternalVersion);
|
|
184
177
|
}
|
|
185
178
|
}
|
|
186
|
-
|
|
187
|
-
async function retrieveDefaultModule(name, dest) {
|
|
179
|
+
export async function retrieveDefaultModule(name, dest) {
|
|
188
180
|
if (!name) {
|
|
189
|
-
const defaultReactModules = await
|
|
181
|
+
const defaultReactModules = await listGithubRepoContents('HubSpot/cms-react', 'default-react-modules/src/components/modules/', 'dir');
|
|
190
182
|
return defaultReactModules;
|
|
191
183
|
}
|
|
192
184
|
if (dest) {
|
|
193
|
-
await
|
|
185
|
+
await cloneGithubRepo('HubSpot/cms-react', dest, {
|
|
194
186
|
sourceDir: `default-react-modules/src/components/modules/${name}`,
|
|
195
187
|
});
|
|
196
188
|
}
|
|
197
189
|
}
|
|
198
|
-
exports.retrieveDefaultModule = retrieveDefaultModule;
|
|
199
190
|
const MODULE_HTML_EXTENSION_REGEX = new RegExp(/\.module(?:\/|\\)module\.html$/);
|
|
200
|
-
const isModuleHTMLFile = (filePath) => MODULE_HTML_EXTENSION_REGEX.test(filePath);
|
|
201
|
-
exports.isModuleHTMLFile = isModuleHTMLFile;
|
|
191
|
+
export const isModuleHTMLFile = (filePath) => MODULE_HTML_EXTENSION_REGEX.test(filePath);
|
|
@@ -1,20 +1,13 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
};
|
|
6
|
-
|
|
7
|
-
const path_1 = __importDefault(require("path"));
|
|
8
|
-
const fs_1 = __importDefault(require("fs"));
|
|
9
|
-
const semver_1 = __importDefault(require("semver"));
|
|
10
|
-
const url_1 = require("url");
|
|
11
|
-
const path_2 = require("../path");
|
|
12
|
-
const lang_1 = require("../../utils/lang");
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import fs from 'fs';
|
|
4
|
+
import { pathToFileURL } from 'url';
|
|
5
|
+
import { i18n } from '../../utils/lang.js';
|
|
13
6
|
const i18nKey = 'lib.cms.processFieldsJs';
|
|
14
7
|
const { dirName, fieldOptions, filePath, writeDir } = process.env;
|
|
15
|
-
const baseName =
|
|
8
|
+
const baseName = path.basename(filePath);
|
|
16
9
|
//TODO - Figure out agnostic logging
|
|
17
|
-
console.info(
|
|
10
|
+
console.info(i18n(`${i18nKey}.converting`, {
|
|
18
11
|
src: dirName + `/${baseName}`,
|
|
19
12
|
dest: dirName + '/fields.json',
|
|
20
13
|
}));
|
|
@@ -30,26 +23,26 @@ const fieldsPromise = dynamicImport(filePath).catch(e => {
|
|
|
30
23
|
fieldsPromise.then(fieldsFunc => {
|
|
31
24
|
const fieldsFuncType = typeof fieldsFunc;
|
|
32
25
|
if (fieldsFuncType !== 'function') {
|
|
33
|
-
throw new Error(
|
|
26
|
+
throw new Error(i18n(`${i18nKey}.errors.notFunction`, {
|
|
34
27
|
path: filePath,
|
|
35
28
|
returned: fieldsFuncType,
|
|
36
29
|
}));
|
|
37
30
|
}
|
|
38
31
|
return Promise.resolve(fieldsFunc(fieldOptions)).then(fields => {
|
|
39
32
|
if (!Array.isArray(fields)) {
|
|
40
|
-
throw new Error(
|
|
33
|
+
throw new Error(i18n(`${i18nKey}.errors.notArray`, {
|
|
41
34
|
path: filePath,
|
|
42
35
|
returned: typeof fields,
|
|
43
36
|
}));
|
|
44
37
|
}
|
|
45
|
-
const finalPath =
|
|
38
|
+
const finalPath = path.join(writeDir, '/fields.json');
|
|
46
39
|
return fieldsArrayToJson(fields).then(json => {
|
|
47
|
-
if (!
|
|
48
|
-
|
|
40
|
+
if (!fs.existsSync(writeDir)) {
|
|
41
|
+
fs.mkdirSync(writeDir, { recursive: true });
|
|
49
42
|
}
|
|
50
|
-
|
|
43
|
+
fs.writeFileSync(finalPath, json);
|
|
51
44
|
//TODO - Figure out agnostic logging
|
|
52
|
-
console.log(
|
|
45
|
+
console.log(i18n(`${i18nKey}.converted`, {
|
|
53
46
|
src: dirName + `/${baseName}`,
|
|
54
47
|
dest: dirName + '/fields.json',
|
|
55
48
|
}));
|
|
@@ -79,19 +72,11 @@ async function fieldsArrayToJson(fields) {
|
|
|
79
72
|
return JSON.stringify(jsonFields, null, 2);
|
|
80
73
|
}
|
|
81
74
|
/**
|
|
82
|
-
* Takes in a path to a javascript file and
|
|
75
|
+
* Takes in a path to a javascript file and dynamically imports it.
|
|
83
76
|
* @param {string} filePath - Path to javascript file
|
|
84
|
-
* @returns {Promise
|
|
77
|
+
* @returns {Promise} - Returns _default_ exported content if ESM, or exported module content if CJS.
|
|
85
78
|
*/
|
|
86
79
|
async function dynamicImport(filePath) {
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
return exported.default;
|
|
90
|
-
}
|
|
91
|
-
else {
|
|
92
|
-
if ((0, path_2.getExt)(filePath) == 'mjs') {
|
|
93
|
-
throw new Error((0, lang_1.i18n)(`${i18nKey}.errors.invalidMjsFile`));
|
|
94
|
-
}
|
|
95
|
-
return require(filePath);
|
|
96
|
-
}
|
|
80
|
+
const exported = await import(pathToFileURL(filePath).href);
|
|
81
|
+
return exported.default || exported;
|
|
97
82
|
}
|
package/lib/cms/templates.js
CHANGED
|
@@ -1,20 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
exports.TEMPLATE_TYPES = exports.createTemplate = exports.isCodedFile = exports.getAnnotationValue = exports.ANNOTATION_KEYS = void 0;
|
|
7
|
-
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
8
|
-
const path_1 = __importDefault(require("path"));
|
|
9
|
-
const github_1 = require("../github");
|
|
10
|
-
const logger_1 = require("../logger");
|
|
11
|
-
const lang_1 = require("../../utils/lang");
|
|
1
|
+
import fs from 'fs-extra';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import { cloneGithubRepo } from '../github.js';
|
|
4
|
+
import { logger } from '../logger.js';
|
|
5
|
+
import { i18n } from '../../utils/lang.js';
|
|
12
6
|
const i18nKey = 'lib.cms.templates';
|
|
13
7
|
// Matches the .html file extension, excluding module.html
|
|
14
8
|
const TEMPLATE_EXTENSION_REGEX = new RegExp(/(?<!module)\.html$/);
|
|
15
9
|
// Matches an annotation value, ending at space, newline, or end of string
|
|
16
10
|
const ANNOTATION_VALUE_REGEX = ':\\s?([\\S|\\s]*?)(\n|$)';
|
|
17
|
-
|
|
11
|
+
export const ANNOTATION_KEYS = {
|
|
18
12
|
isAvailableForNewContent: 'isAvailableForNewContent',
|
|
19
13
|
templateType: 'templateType',
|
|
20
14
|
label: 'label',
|
|
@@ -22,20 +16,18 @@ exports.ANNOTATION_KEYS = {
|
|
|
22
16
|
// 'description' is specific to Sections
|
|
23
17
|
description: 'description',
|
|
24
18
|
};
|
|
25
|
-
function getAnnotationValue(annotations, key) {
|
|
19
|
+
export function getAnnotationValue(annotations, key) {
|
|
26
20
|
const valueRegex = new RegExp(`${key}${ANNOTATION_VALUE_REGEX}`);
|
|
27
21
|
const match = annotations.match(valueRegex);
|
|
28
22
|
return match ? match[1].trim() : null;
|
|
29
23
|
}
|
|
30
|
-
exports.getAnnotationValue = getAnnotationValue;
|
|
31
24
|
/*
|
|
32
25
|
* Returns true if:
|
|
33
26
|
* .html extension (ignoring module.html)
|
|
34
27
|
*/
|
|
35
|
-
function isCodedFile(filePath) {
|
|
28
|
+
export function isCodedFile(filePath) {
|
|
36
29
|
return TEMPLATE_EXTENSION_REGEX.test(filePath);
|
|
37
30
|
}
|
|
38
|
-
exports.isCodedFile = isCodedFile;
|
|
39
31
|
const ASSET_PATHS = {
|
|
40
32
|
'page-template': 'templates/page-template.html',
|
|
41
33
|
partial: 'templates/partial.html',
|
|
@@ -46,26 +38,25 @@ const ASSET_PATHS = {
|
|
|
46
38
|
'search-template': 'templates/search-template.html',
|
|
47
39
|
section: 'templates/section.html',
|
|
48
40
|
};
|
|
49
|
-
async function createTemplate(name, dest, type = 'page-template', options = { allowExisting: false }) {
|
|
41
|
+
export async function createTemplate(name, dest, type = 'page-template', options = { allowExisting: false }) {
|
|
50
42
|
const assetPath = ASSET_PATHS[type];
|
|
51
43
|
const filename = name.endsWith('.html') ? name : `${name}.html`;
|
|
52
|
-
const filePath =
|
|
53
|
-
if (!options.allowExisting &&
|
|
54
|
-
throw new Error(
|
|
44
|
+
const filePath = path.join(dest, filename);
|
|
45
|
+
if (!options.allowExisting && fs.existsSync(filePath)) {
|
|
46
|
+
throw new Error(i18n(`${i18nKey}.createTemplate.errors.pathExists`, {
|
|
55
47
|
path: filePath,
|
|
56
48
|
}));
|
|
57
49
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
50
|
+
logger.debug(i18n(`${i18nKey}.createTemplate.creatingPath`, { path: dest }));
|
|
51
|
+
fs.mkdirp(dest);
|
|
52
|
+
logger.log(i18n(`${i18nKey}.createTemplate.creatingFile`, {
|
|
61
53
|
path: filePath,
|
|
62
54
|
}));
|
|
63
|
-
await
|
|
55
|
+
await cloneGithubRepo('HubSpot/cms-sample-assets', filePath, {
|
|
64
56
|
sourceDir: assetPath,
|
|
65
57
|
});
|
|
66
58
|
}
|
|
67
|
-
|
|
68
|
-
exports.TEMPLATE_TYPES = {
|
|
59
|
+
export const TEMPLATE_TYPES = {
|
|
69
60
|
unmapped: 0,
|
|
70
61
|
email_base_template: 1,
|
|
71
62
|
email: 2,
|
package/lib/cms/themes.js
CHANGED
|
@@ -1,20 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const findup_sync_1 = __importDefault(require("findup-sync"));
|
|
8
|
-
const urls_1 = require("../urls");
|
|
9
|
-
const environments_1 = require("../../constants/environments");
|
|
10
|
-
const config_1 = require("../../config");
|
|
11
|
-
function getThemeJSONPath(path) {
|
|
12
|
-
return (0, findup_sync_1.default)('theme.json', {
|
|
1
|
+
import findup from 'findup-sync';
|
|
2
|
+
import { getHubSpotWebsiteOrigin } from '../urls.js';
|
|
3
|
+
import { ENVIRONMENTS } from '../../constants/environments.js';
|
|
4
|
+
import { getConfigAccountEnvironment } from '../../config/index.js';
|
|
5
|
+
export function getThemeJSONPath(path) {
|
|
6
|
+
return findup('theme.json', {
|
|
13
7
|
cwd: path,
|
|
14
8
|
nocase: true,
|
|
15
9
|
});
|
|
16
10
|
}
|
|
17
|
-
exports.getThemeJSONPath = getThemeJSONPath;
|
|
18
11
|
function getThemeNameFromPath(filePath) {
|
|
19
12
|
const themeJSONPath = getThemeJSONPath(filePath);
|
|
20
13
|
if (!themeJSONPath)
|
|
@@ -24,13 +17,12 @@ function getThemeNameFromPath(filePath) {
|
|
|
24
17
|
return;
|
|
25
18
|
return pathParts[pathParts.length - 2];
|
|
26
19
|
}
|
|
27
|
-
function getThemePreviewUrl(filePath, accountId) {
|
|
20
|
+
export function getThemePreviewUrl(filePath, accountId) {
|
|
28
21
|
const themeName = getThemeNameFromPath(filePath);
|
|
29
22
|
if (!themeName)
|
|
30
23
|
return;
|
|
31
|
-
const baseUrl =
|
|
32
|
-
?
|
|
33
|
-
:
|
|
24
|
+
const baseUrl = getHubSpotWebsiteOrigin(getConfigAccountEnvironment(accountId) === 'qa'
|
|
25
|
+
? ENVIRONMENTS.QA
|
|
26
|
+
: ENVIRONMENTS.PROD);
|
|
34
27
|
return `${baseUrl}/theme-previewer/${accountId}/edit/${encodeURIComponent(themeName)}`;
|
|
35
28
|
}
|
|
36
|
-
exports.getThemePreviewUrl = getThemePreviewUrl;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { FieldsJs } from './handleFieldsJS';
|
|
2
|
-
import { FileMapperInputOptions } from '../../types/Files';
|
|
3
|
-
import { UploadFolderResults, CommandOptions, FilePathsByType } from '../../types/Files';
|
|
4
|
-
import { CmsPublishMode } from '../../types/Files';
|
|
1
|
+
import { FieldsJs } from './handleFieldsJS.js';
|
|
2
|
+
import { FileMapperInputOptions } from '../../types/Files.js';
|
|
3
|
+
import { UploadFolderResults, CommandOptions, FilePathsByType } from '../../types/Files.js';
|
|
4
|
+
import { CmsPublishMode } from '../../types/Files.js';
|
|
5
5
|
export declare function getFilesByType(filePaths: Array<string>, projectDir: string, rootWriteDir: string | null, commandOptions: CommandOptions): Promise<[FilePathsByType, Array<FieldsJs>]>;
|
|
6
6
|
export declare function uploadFolder(accountId: number, src: string, dest: string, fileMapperOptions: FileMapperInputOptions, commandOptions?: CommandOptions, filePaths?: Array<string>, cmsPublishMode?: CmsPublishMode | null): Promise<Array<UploadFolderResults>>;
|
|
7
7
|
export declare function hasUploadErrors(results: Array<UploadFolderResults>): boolean;
|