@hubspot/local-dev-lib 4.0.4 → 5.0.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (205) hide show
  1. package/api/appsDev.d.ts +2 -2
  2. package/api/appsDev.js +13 -22
  3. package/api/crm.d.ts +2 -2
  4. package/api/crm.js +9 -16
  5. package/api/customObjects.d.ts +2 -2
  6. package/api/customObjects.js +13 -22
  7. package/api/designManager.d.ts +2 -2
  8. package/api/designManager.js +5 -10
  9. package/api/devSecrets.d.ts +2 -2
  10. package/api/devSecrets.js +9 -16
  11. package/api/developerTestAccounts.d.ts +2 -4
  12. package/api/developerTestAccounts.js +23 -52
  13. package/api/fileManager.d.ts +2 -2
  14. package/api/fileManager.js +14 -24
  15. package/api/fileMapper.d.ts +2 -3
  16. package/api/fileMapper.js +34 -49
  17. package/api/fileTransport.d.ts +1 -1
  18. package/api/fileTransport.js +12 -21
  19. package/api/fireAlarm.d.ts +2 -3
  20. package/api/fireAlarm.js +5 -9
  21. package/api/functions.d.ts +2 -2
  22. package/api/functions.js +11 -19
  23. package/api/github.d.ts +2 -4
  24. package/api/github.js +16 -27
  25. package/api/hubdb.d.ts +2 -2
  26. package/api/hubdb.js +19 -31
  27. package/api/lighthouseScore.d.ts +2 -2
  28. package/api/lighthouseScore.js +7 -13
  29. package/api/localDevAuth.d.ts +3 -6
  30. package/api/localDevAuth.js +10 -37
  31. package/api/marketplaceValidation.d.ts +2 -2
  32. package/api/marketplaceValidation.js +7 -13
  33. package/api/projects.d.ts +6 -8
  34. package/api/projects.js +65 -100
  35. package/api/sandboxHubs.d.ts +2 -5
  36. package/api/sandboxHubs.js +15 -42
  37. package/api/sandboxSync.d.ts +2 -2
  38. package/api/sandboxSync.js +7 -12
  39. package/api/secrets.d.ts +2 -2
  40. package/api/secrets.js +9 -16
  41. package/api/validateHubl.d.ts +2 -2
  42. package/api/validateHubl.js +3 -7
  43. package/config/defaultAccountOverride.d.ts +2 -1
  44. package/config/defaultAccountOverride.js +16 -26
  45. package/config/index.d.ts +4 -4
  46. package/config/index.js +141 -177
  47. package/config/migrate.d.ts +2 -2
  48. package/config/migrate.js +26 -37
  49. package/config/state.d.ts +1 -1
  50. package/config/state.js +17 -45
  51. package/config/utils.d.ts +4 -4
  52. package/config/utils.js +85 -108
  53. package/constants/api.js +3 -6
  54. package/constants/auth.js +9 -12
  55. package/constants/config.js +37 -43
  56. package/constants/endpoints.d.ts +6 -0
  57. package/constants/endpoints.js +6 -0
  58. package/constants/environments.js +1 -4
  59. package/constants/extensions.js +6 -9
  60. package/constants/files.js +5 -8
  61. package/constants/ports.js +3 -6
  62. package/constants/projects.js +2 -5
  63. package/enums/build.d.ts +1 -0
  64. package/enums/build.js +6 -8
  65. package/enums/deploy.js +2 -5
  66. package/enums/project.js +1 -4
  67. package/errors/index.d.ts +4 -5
  68. package/errors/index.js +17 -39
  69. package/errors/isSystemError.d.ts +2 -0
  70. package/errors/isSystemError.js +9 -0
  71. package/http/addQueryParams.d.ts +1 -1
  72. package/http/addQueryParams.js +1 -5
  73. package/http/client.js +14 -42
  74. package/http/getAxiosConfig.d.ts +1 -1
  75. package/http/getAxiosConfig.js +21 -31
  76. package/http/index.d.ts +2 -2
  77. package/http/index.js +39 -46
  78. package/http/unauthed.d.ts +1 -1
  79. package/http/unauthed.js +15 -18
  80. package/lang/en.json +1 -1
  81. package/lib/archive.d.ts +1 -3
  82. package/lib/archive.js +37 -67
  83. package/lib/cms/functions.d.ts +1 -1
  84. package/lib/cms/functions.js +45 -55
  85. package/lib/cms/handleFieldsJS.js +36 -44
  86. package/lib/cms/modules.d.ts +2 -2
  87. package/lib/cms/modules.js +49 -59
  88. package/lib/cms/processFieldsJs.js +17 -32
  89. package/lib/cms/templates.js +17 -26
  90. package/lib/cms/themes.js +10 -18
  91. package/lib/cms/uploadFolder.d.ts +4 -4
  92. package/lib/cms/uploadFolder.js +55 -64
  93. package/lib/cms/validate.d.ts +1 -1
  94. package/lib/cms/validate.js +11 -18
  95. package/lib/cms/watch.d.ts +2 -2
  96. package/lib/cms/watch.js +66 -73
  97. package/lib/crm.d.ts +1 -1
  98. package/lib/crm.js +15 -23
  99. package/lib/customObjects.d.ts +1 -1
  100. package/lib/customObjects.js +15 -25
  101. package/lib/environment.d.ts +1 -1
  102. package/lib/environment.js +5 -11
  103. package/lib/escapeRegExp.js +1 -5
  104. package/lib/fileManager.js +43 -51
  105. package/lib/fileMapper.d.ts +1 -1
  106. package/lib/fileMapper.js +68 -84
  107. package/lib/fs.d.ts +1 -1
  108. package/lib/fs.js +18 -27
  109. package/lib/github.d.ts +1 -3
  110. package/lib/github.js +39 -51
  111. package/lib/gitignore.d.ts +1 -1
  112. package/lib/gitignore.js +16 -24
  113. package/lib/hubdb.d.ts +1 -1
  114. package/lib/hubdb.js +29 -40
  115. package/lib/ignoreRules.js +25 -34
  116. package/lib/isDeepEqual.js +1 -5
  117. package/lib/logger.d.ts +8 -20
  118. package/lib/logger.js +47 -59
  119. package/lib/notify.js +9 -16
  120. package/lib/oauth.d.ts +2 -2
  121. package/lib/oauth.js +12 -17
  122. package/lib/path.d.ts +0 -1
  123. package/lib/path.js +30 -48
  124. package/lib/personalAccessKey.d.ts +2 -4
  125. package/lib/personalAccessKey.js +43 -60
  126. package/lib/portManager.d.ts +2 -2
  127. package/lib/portManager.js +26 -41
  128. package/lib/text.js +2 -7
  129. package/lib/trackUsage.d.ts +0 -2
  130. package/lib/trackUsage.js +23 -29
  131. package/lib/urls.js +4 -9
  132. package/models/FileSystemError.d.ts +1 -1
  133. package/models/FileSystemError.js +12 -16
  134. package/models/HubSpotConfigError.d.ts +1 -1
  135. package/models/HubSpotConfigError.js +8 -12
  136. package/models/HubSpotHttpError.d.ts +1 -1
  137. package/models/HubSpotHttpError.js +22 -26
  138. package/models/OAuth2Manager.d.ts +1 -1
  139. package/models/OAuth2Manager.js +17 -24
  140. package/package.json +20 -16
  141. package/types/Accounts.d.ts +6 -5
  142. package/types/Accounts.js +1 -2
  143. package/types/Activity.d.ts +3 -3
  144. package/types/Activity.js +1 -2
  145. package/types/Api.d.ts +1 -1
  146. package/types/Api.js +1 -2
  147. package/types/Apps.js +1 -2
  148. package/types/Archive.js +1 -2
  149. package/types/Build.d.ts +4 -5
  150. package/types/Build.js +1 -2
  151. package/types/CLIOptions.js +1 -2
  152. package/types/ComponentStructure.d.ts +2 -2
  153. package/types/ComponentStructure.js +1 -2
  154. package/types/Config.d.ts +4 -6
  155. package/types/Config.js +1 -2
  156. package/types/Crm.js +1 -2
  157. package/types/Deploy.d.ts +5 -11
  158. package/types/Deploy.js +1 -2
  159. package/types/DesignManager.js +1 -2
  160. package/types/DevSecrets.js +1 -2
  161. package/types/Error.js +1 -2
  162. package/types/FieldsJS.js +1 -2
  163. package/types/FileManager.js +1 -2
  164. package/types/Files.d.ts +4 -4
  165. package/types/Files.js +1 -2
  166. package/types/FireAlarm.js +1 -2
  167. package/types/Functions.js +1 -2
  168. package/types/Github.d.ts +1 -1
  169. package/types/Github.js +1 -2
  170. package/types/Http.d.ts +0 -4
  171. package/types/Http.js +1 -2
  172. package/types/Hubdb.js +1 -2
  173. package/types/HublValidation.js +1 -2
  174. package/types/Lang.d.ts +1 -1
  175. package/types/Lang.js +1 -2
  176. package/types/Lighthouse.js +1 -2
  177. package/types/MarketplaceValidation.js +1 -2
  178. package/types/Migration.d.ts +2 -2
  179. package/types/Migration.js +1 -4
  180. package/types/Modules.js +1 -2
  181. package/types/PortManager.js +1 -2
  182. package/types/Project.d.ts +3 -21
  183. package/types/Project.js +1 -2
  184. package/types/ProjectComponents.d.ts +24 -0
  185. package/types/ProjectComponents.js +1 -0
  186. package/types/ProjectLog.js +1 -2
  187. package/types/Sandbox.js +2 -5
  188. package/types/Schemas.js +1 -2
  189. package/types/Secrets.js +1 -2
  190. package/types/Utils.js +1 -2
  191. package/types/developerTestAccounts.js +1 -2
  192. package/utils/PortManagerServer.d.ts +1 -2
  193. package/utils/PortManagerServer.js +32 -38
  194. package/utils/cms/fieldsJS.d.ts +1 -1
  195. package/utils/cms/fieldsJS.js +1 -5
  196. package/utils/cms/modules.d.ts +1 -1
  197. package/utils/cms/modules.js +13 -22
  198. package/utils/detectPort.js +12 -19
  199. package/utils/git.js +17 -26
  200. package/utils/lang.d.ts +1 -1
  201. package/utils/lang.js +5 -14
  202. package/utils/personalAccessKey.d.ts +8 -0
  203. package/utils/personalAccessKey.js +51 -0
  204. package/errors/errors_DEPRECATED.d.ts +0 -3
  205. package/errors/errors_DEPRECATED.js +0 -60
@@ -1,31 +1,23 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.createFunction = exports.createConfig = exports.createEndpoint = exports.isObjectOrFunction = void 0;
7
- const fs_extra_1 = __importDefault(require("fs-extra"));
8
- const path_1 = __importDefault(require("path"));
9
- const findup_sync_1 = __importDefault(require("findup-sync"));
10
- const path_2 = require("../path");
11
- const github_1 = require("../github");
12
- const logger_1 = require("../logger");
13
- const lang_1 = require("../../utils/lang");
14
- const FileSystemError_1 = require("../../models/FileSystemError");
1
+ import fs from 'fs-extra';
2
+ import path from 'path';
3
+ import findup from 'findup-sync';
4
+ import { getCwd } from '../path.js';
5
+ import { fetchFileFromRepository } from '../github.js';
6
+ import { logger } from '../logger.js';
7
+ import { i18n } from '../../utils/lang.js';
8
+ import { FileSystemError } from '../../models/FileSystemError.js';
15
9
  const i18nKey = 'lib.cms.functions';
16
- function isObjectOrFunction(value) {
10
+ export function isObjectOrFunction(value) {
17
11
  const type = typeof value;
18
12
  return value != null && (type === 'object' || type === 'function');
19
13
  }
20
- exports.isObjectOrFunction = isObjectOrFunction;
21
- function createEndpoint(endpointMethod, filename) {
14
+ export function createEndpoint(endpointMethod, filename) {
22
15
  return {
23
16
  method: endpointMethod || 'GET',
24
17
  file: filename,
25
18
  };
26
19
  }
27
- exports.createEndpoint = createEndpoint;
28
- function createConfig({ endpointPath, endpointMethod, functionFile, }) {
20
+ export function createConfig({ endpointPath, endpointMethod, functionFile, }) {
29
21
  return {
30
22
  runtime: 'nodejs18.x',
31
23
  version: '1.0',
@@ -36,21 +28,20 @@ function createConfig({ endpointPath, endpointMethod, functionFile, }) {
36
28
  },
37
29
  };
38
30
  }
39
- exports.createConfig = createConfig;
40
31
  function writeConfig(configFilePath, config) {
41
32
  const configJson = JSON.stringify(config, null, ' ');
42
- fs_extra_1.default.writeFileSync(configFilePath, configJson);
33
+ fs.writeFileSync(configFilePath, configJson);
43
34
  }
44
35
  function updateExistingConfig(configFilePath, { endpointPath, endpointMethod, functionFile }) {
45
36
  let configString;
46
37
  try {
47
- configString = fs_extra_1.default.readFileSync(configFilePath).toString();
38
+ configString = fs.readFileSync(configFilePath).toString();
48
39
  }
49
40
  catch (err) {
50
- logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.updateExistingConfig.unableToReadFile`, {
41
+ logger.debug(i18n(`${i18nKey}.updateExistingConfig.unableToReadFile`, {
51
42
  configFilePath,
52
43
  }));
53
- throw new FileSystemError_1.FileSystemError({ cause: err }, {
44
+ throw new FileSystemError({ cause: err }, {
54
45
  filepath: configFilePath,
55
46
  operation: 'read',
56
47
  });
@@ -60,22 +51,22 @@ function updateExistingConfig(configFilePath, { endpointPath, endpointMethod, fu
60
51
  config = JSON.parse(configString);
61
52
  }
62
53
  catch (err) {
63
- logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.updateExistingConfig.invalidJSON`, {
54
+ logger.debug(i18n(`${i18nKey}.updateExistingConfig.invalidJSON`, {
64
55
  configFilePath,
65
56
  }));
66
- throw new FileSystemError_1.FileSystemError({ cause: err }, {
57
+ throw new FileSystemError({ cause: err }, {
67
58
  filepath: configFilePath,
68
59
  operation: 'read',
69
60
  });
70
61
  }
71
62
  if (!isObjectOrFunction(config)) {
72
- throw new Error((0, lang_1.i18n)(`${i18nKey}.updateExistingConfig.errors.configIsNotObjectError`, {
63
+ throw new Error(i18n(`${i18nKey}.updateExistingConfig.errors.configIsNotObjectError`, {
73
64
  configFilePath,
74
65
  }));
75
66
  }
76
67
  if (config.endpoints) {
77
68
  if (config.endpoints[endpointPath]) {
78
- throw new Error((0, lang_1.i18n)(`${i18nKey}.updateExistingConfig.errors.endpointAreadyExistsError`, {
69
+ throw new Error(i18n(`${i18nKey}.updateExistingConfig.errors.endpointAreadyExistsError`, {
79
70
  configFilePath,
80
71
  endpointPath,
81
72
  }));
@@ -93,65 +84,65 @@ function updateExistingConfig(configFilePath, { endpointPath, endpointMethod, fu
93
84
  writeConfig(configFilePath, config);
94
85
  }
95
86
  catch (err) {
96
- logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.updateExistingConfig.couldNotUpdateFile`, {
87
+ logger.debug(i18n(`${i18nKey}.updateExistingConfig.couldNotUpdateFile`, {
97
88
  configFilePath,
98
89
  }));
99
- throw new FileSystemError_1.FileSystemError({ cause: err }, {
90
+ throw new FileSystemError({ cause: err }, {
100
91
  filepath: configFilePath,
101
92
  operation: 'read',
102
93
  });
103
94
  }
104
95
  }
105
- async function createFunction(functionInfo, dest, options = {}) {
96
+ export async function createFunction(functionInfo, dest, options = {}) {
106
97
  const { functionsFolder, filename, endpointPath, endpointMethod } = functionInfo;
107
98
  const allowExistingFile = options.allowExistingFile || false;
108
- const ancestorFunctionsConfig = (0, findup_sync_1.default)('serverless.json', {
109
- cwd: (0, path_2.getCwd)(),
99
+ const ancestorFunctionsConfig = findup('serverless.json', {
100
+ cwd: getCwd(),
110
101
  nocase: true,
111
102
  });
112
103
  if (ancestorFunctionsConfig) {
113
- throw new Error((0, lang_1.i18n)(`${i18nKey}.createFunction.errors.nestedConfigError`, {
114
- ancestorConfigPath: path_1.default.dirname(ancestorFunctionsConfig),
104
+ throw new Error(i18n(`${i18nKey}.createFunction.errors.nestedConfigError`, {
105
+ ancestorConfigPath: path.dirname(ancestorFunctionsConfig),
115
106
  }));
116
107
  }
117
108
  const folderName = functionsFolder.endsWith('.functions')
118
109
  ? functionsFolder
119
110
  : `${functionsFolder}.functions`;
120
111
  const functionFile = filename.endsWith('.js') ? filename : `${filename}.js`;
121
- const destPath = path_1.default.join(dest, folderName);
122
- if (fs_extra_1.default.existsSync(destPath)) {
123
- logger_1.logger.log((0, lang_1.i18n)(`${i18nKey}.createFunction.destPathAlreadyExists`, {
112
+ const destPath = path.join(dest, folderName);
113
+ if (fs.existsSync(destPath)) {
114
+ logger.log(i18n(`${i18nKey}.createFunction.destPathAlreadyExists`, {
124
115
  path: destPath,
125
116
  }));
126
117
  }
127
118
  else {
128
- fs_extra_1.default.mkdirp(destPath);
129
- logger_1.logger.log((0, lang_1.i18n)(`${i18nKey}.createFunction.createdDest`, {
119
+ fs.mkdirp(destPath);
120
+ logger.log(i18n(`${i18nKey}.createFunction.createdDest`, {
130
121
  path: destPath,
131
122
  }));
132
123
  }
133
- const functionFilePath = path_1.default.join(destPath, functionFile);
134
- const configFilePath = path_1.default.join(destPath, 'serverless.json');
135
- if (!allowExistingFile && fs_extra_1.default.existsSync(functionFilePath)) {
136
- throw new Error((0, lang_1.i18n)(`${i18nKey}.createFunction.errors.jsFileConflictError`, {
124
+ const functionFilePath = path.join(destPath, functionFile);
125
+ const configFilePath = path.join(destPath, 'serverless.json');
126
+ if (!allowExistingFile && fs.existsSync(functionFilePath)) {
127
+ throw new Error(i18n(`${i18nKey}.createFunction.errors.jsFileConflictError`, {
137
128
  functionFilePath,
138
129
  }));
139
130
  }
140
- const result = await (0, github_1.fetchFileFromRepository)('HubSpot/cms-sample-assets', 'functions/sample-function.js', 'main');
141
- fs_extra_1.default.writeFileSync(functionFilePath, result);
142
- logger_1.logger.log((0, lang_1.i18n)(`${i18nKey}.createFunction.createdFunctionFile`, {
131
+ const result = await fetchFileFromRepository('HubSpot/cms-sample-assets', 'functions/sample-function.js', 'main');
132
+ fs.writeFileSync(functionFilePath, result);
133
+ logger.log(i18n(`${i18nKey}.createFunction.createdFunctionFile`, {
143
134
  path: functionFilePath,
144
135
  }));
145
- if (fs_extra_1.default.existsSync(configFilePath)) {
136
+ if (fs.existsSync(configFilePath)) {
146
137
  updateExistingConfig(configFilePath, {
147
138
  endpointPath,
148
139
  endpointMethod,
149
140
  functionFile,
150
141
  });
151
- logger_1.logger.log((0, lang_1.i18n)(`${i18nKey}.createFunction.createdFunctionFile`, {
142
+ logger.log(i18n(`${i18nKey}.createFunction.createdFunctionFile`, {
152
143
  path: functionFilePath,
153
144
  }));
154
- logger_1.logger.log((0, lang_1.i18n)(`${i18nKey}.createFunction.success`, {
145
+ logger.log(i18n(`${i18nKey}.createFunction.success`, {
155
146
  endpointPath: endpointPath,
156
147
  folderName,
157
148
  }));
@@ -162,21 +153,20 @@ async function createFunction(functionInfo, dest, options = {}) {
162
153
  writeConfig(configFilePath, config);
163
154
  }
164
155
  catch (err) {
165
- logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.createFunction.failedToCreateFile`, {
156
+ logger.debug(i18n(`${i18nKey}.createFunction.failedToCreateFile`, {
166
157
  configFilePath,
167
158
  }));
168
- throw new FileSystemError_1.FileSystemError({ cause: err }, {
159
+ throw new FileSystemError({ cause: err }, {
169
160
  filepath: configFilePath,
170
161
  operation: 'write',
171
162
  });
172
163
  }
173
- logger_1.logger.log((0, lang_1.i18n)(`${i18nKey}.createFunction.createdConfigFile`, {
164
+ logger.log(i18n(`${i18nKey}.createFunction.createdConfigFile`, {
174
165
  path: configFilePath,
175
166
  }));
176
- logger_1.logger.log((0, lang_1.i18n)(`${i18nKey}.createFunction.success`, {
167
+ logger.log(i18n(`${i18nKey}.createFunction.success`, {
177
168
  endpointPath: endpointPath,
178
169
  folderName,
179
170
  }));
180
171
  }
181
172
  }
182
- exports.createFunction = createFunction;
@@ -1,19 +1,15 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.cleanupTmpDirSync = exports.createTmpDirSync = exports.isConvertableFieldJs = exports.FieldsJs = void 0;
7
- const fs_extra_1 = __importDefault(require("fs-extra"));
8
- const os_1 = __importDefault(require("os"));
9
- const path_1 = __importDefault(require("path"));
10
- const child_process_1 = require("child_process");
11
- const escapeRegExp_1 = require("../escapeRegExp");
12
- const modules_1 = require("../../utils/cms/modules");
13
- const logger_1 = require("../logger");
14
- const lang_1 = require("../../utils/lang");
1
+ import fs from 'fs-extra';
2
+ import os from 'os';
3
+ import path from 'path';
4
+ import { fork } from 'child_process';
5
+ import { fileURLToPath } from 'url';
6
+ import { escapeRegExp } from '../escapeRegExp.js';
7
+ import { isModuleFolderChild } from '../../utils/cms/modules.js';
8
+ import { logger } from '../logger.js';
9
+ import { i18n } from '../../utils/lang.js';
10
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
15
11
  const i18nKey = 'lib.cms.handleFieldsJs';
16
- class FieldsJs {
12
+ export class FieldsJs {
17
13
  projectDir;
18
14
  filePath;
19
15
  rootWriteDir;
@@ -40,12 +36,12 @@ class FieldsJs {
40
36
  // Converts a fields.js file into a fields.json file, writes, and returns of fields.json
41
37
  convertFieldsJs(writeDir) {
42
38
  const filePath = this.filePath;
43
- const dirName = path_1.default.dirname(filePath);
39
+ const dirName = path.dirname(filePath);
44
40
  return new Promise((resolve, reject) => {
45
41
  const fieldOptionsAsString = Array.isArray(this.fieldOptions)
46
42
  ? this.fieldOptions.join(',')
47
43
  : this.fieldOptions;
48
- const convertFieldsProcess = (0, child_process_1.fork)(path_1.default.join(__dirname, './processFieldsJs.js'), [], {
44
+ const convertFieldsProcess = fork(path.join(__dirname, './processFieldsJs.js'), [], {
49
45
  cwd: dirName,
50
46
  env: {
51
47
  dirName,
@@ -54,7 +50,7 @@ class FieldsJs {
54
50
  writeDir,
55
51
  },
56
52
  });
57
- logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.convertFieldsJs.creating`, {
53
+ logger.debug(i18n(`${i18nKey}.convertFieldsJs.creating`, {
58
54
  pid: convertFieldsProcess.pid || '',
59
55
  }));
60
56
  convertFieldsProcess.on('message', function (message) {
@@ -66,12 +62,12 @@ class FieldsJs {
66
62
  }
67
63
  });
68
64
  convertFieldsProcess.on('close', () => {
69
- logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.convertFieldsJs.terminating`, {
65
+ logger.debug(i18n(`${i18nKey}.convertFieldsJs.terminating`, {
70
66
  pid: convertFieldsProcess.pid || '',
71
67
  }));
72
68
  });
73
69
  }).catch((e) => {
74
- throw new Error((0, lang_1.i18n)(`${i18nKey}.convertFieldsJs.errors.errorConverting`, { filePath }), { cause: e });
70
+ throw new Error(i18n(`${i18nKey}.convertFieldsJs.errors.errorConverting`, { filePath }), { cause: e });
75
71
  });
76
72
  }
77
73
  /**
@@ -80,18 +76,18 @@ class FieldsJs {
80
76
  * Ex: path/to/tmp/example.module/fields.json => path/to/project/example.module/fields.output.json
81
77
  */
82
78
  saveOutput() {
83
- if (!this.outputPath || !fs_extra_1.default.existsSync(this.outputPath)) {
84
- throw new Error((0, lang_1.i18n)(`${i18nKey}.saveOutput.errors.saveFailed`, {
79
+ if (!this.outputPath || !fs.existsSync(this.outputPath)) {
80
+ throw new Error(i18n(`${i18nKey}.saveOutput.errors.saveFailed`, {
85
81
  path: this.filePath,
86
82
  }));
87
83
  }
88
- const relativePath = path_1.default.relative(this.rootWriteDir, path_1.default.dirname(this.outputPath));
89
- const savePath = path_1.default.join(this.projectDir, relativePath, 'fields.output.json');
84
+ const relativePath = path.relative(this.rootWriteDir, path.dirname(this.outputPath));
85
+ const savePath = path.join(this.projectDir, relativePath, 'fields.output.json');
90
86
  try {
91
- fs_extra_1.default.copyFileSync(this.outputPath, savePath);
87
+ fs.copyFileSync(this.outputPath, savePath);
92
88
  }
93
89
  catch (err) {
94
- throw new Error((0, lang_1.i18n)(`${i18nKey}.saveOutput.errors.saveFailed`, { path: savePath }), { cause: err });
90
+ throw new Error(i18n(`${i18nKey}.saveOutput.errors.saveFailed`, { path: savePath }), { cause: err });
95
91
  }
96
92
  }
97
93
  /**
@@ -101,51 +97,47 @@ class FieldsJs {
101
97
  * Ex: If rootWriteDir = 'path/to/temp', filePath = 'projectRoot/sample.module/fields.js'. Then getWriteDir() => path/to/temp/sample.module
102
98
  */
103
99
  getWriteDir() {
104
- const projectDirRegex = new RegExp(`^${(0, escapeRegExp_1.escapeRegExp)(this.projectDir)}`);
100
+ const projectDirRegex = new RegExp(`^${escapeRegExp(this.projectDir)}`);
105
101
  const relativePath = this.filePath.replace(projectDirRegex, '');
106
- return path_1.default.dirname(path_1.default.join(this.rootWriteDir, relativePath));
102
+ return path.dirname(path.join(this.rootWriteDir, relativePath));
107
103
  }
108
104
  getOutputPathPromise() {
109
105
  const writeDir = this.getWriteDir();
110
106
  return this.convertFieldsJs(writeDir).then(outputPath => outputPath);
111
107
  }
112
108
  }
113
- exports.FieldsJs = FieldsJs;
114
109
  /**
115
110
  * Determines if file is a convertable fields.js file i.e., if it is called
116
111
  * 'fields.js' and in a root or in a module folder, and if convertFields flag is true.
117
112
  */
118
- function isConvertableFieldJs(rootDir, filePath, convertFields = false) {
113
+ export function isConvertableFieldJs(rootDir, filePath, convertFields = false) {
119
114
  const allowedFieldsNames = ['fields.js', 'fields.mjs', 'fields.cjs'];
120
- const regex = new RegExp(`^${(0, escapeRegExp_1.escapeRegExp)(rootDir)}`);
121
- const relativePath = path_1.default.dirname(filePath.replace(regex, ''));
122
- const baseName = path_1.default.basename(filePath);
123
- const inModuleFolder = (0, modules_1.isModuleFolderChild)({ path: filePath, isLocal: true });
115
+ const regex = new RegExp(`^${escapeRegExp(rootDir)}`);
116
+ const relativePath = path.dirname(filePath.replace(regex, ''));
117
+ const baseName = path.basename(filePath);
118
+ const inModuleFolder = isModuleFolderChild({ path: filePath, isLocal: true });
124
119
  return !!(convertFields &&
125
120
  allowedFieldsNames.includes(baseName) &&
126
- (inModuleFolder || relativePath == path_1.default.sep));
121
+ (inModuleFolder || relativePath == path.sep));
127
122
  }
128
- exports.isConvertableFieldJs = isConvertableFieldJs;
129
123
  // Try creating tempdir
130
- function createTmpDirSync(prefix) {
124
+ export function createTmpDirSync(prefix) {
131
125
  let tmpDir;
132
126
  try {
133
- tmpDir = fs_extra_1.default.mkdtempSync(path_1.default.join(os_1.default.tmpdir(), prefix));
127
+ tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), prefix));
134
128
  }
135
129
  catch (err) {
136
- throw new Error((0, lang_1.i18n)(`${i18nKey}.createTmpDirSync.errors.writeFailed`), {
130
+ throw new Error(i18n(`${i18nKey}.createTmpDirSync.errors.writeFailed`), {
137
131
  cause: err,
138
132
  });
139
133
  }
140
134
  return tmpDir;
141
135
  }
142
- exports.createTmpDirSync = createTmpDirSync;
143
136
  // Try cleaning up resources from os's tempdir
144
- function cleanupTmpDirSync(tmpDir) {
145
- fs_extra_1.default.rm(tmpDir, { recursive: true }, err => {
137
+ export function cleanupTmpDirSync(tmpDir) {
138
+ fs.rm(tmpDir, { recursive: true }, err => {
146
139
  if (err) {
147
- throw new Error((0, lang_1.i18n)(`${i18nKey}.cleanupTmpDirSync.errors.deleteFailed`), { cause: err });
140
+ throw new Error(i18n(`${i18nKey}.cleanupTmpDirSync.errors.deleteFailed`), { cause: err });
148
141
  }
149
142
  });
150
143
  }
151
- exports.cleanupTmpDirSync = cleanupTmpDirSync;
@@ -1,5 +1,5 @@
1
- import { PathInput, ValidationResult, ModuleDefinition } from '../../types/Modules';
2
- import { GithubRepoFile } from '../../types/Github';
1
+ import { PathInput, ValidationResult, ModuleDefinition } from '../../types/Modules.js';
2
+ import { GithubRepoFile } from '../../types/Github.js';
3
3
  export declare const ValidationIds: {
4
4
  SRC_REQUIRED: string;
5
5
  DEST_REQUIRED: string;
@@ -1,20 +1,14 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.isModuleHTMLFile = exports.retrieveDefaultModule = exports.createModule = exports.validateSrcAndDestPaths = exports.ValidationIds = void 0;
7
- const path_1 = __importDefault(require("path"));
8
- const fs_extra_1 = __importDefault(require("fs-extra"));
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
- exports.ValidationIds = {
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 (!(0, modules_1.isPathInput)(src)) {
28
- results.push(getValidationResult(exports.ValidationIds.SRC_REQUIRED, '`src` is required.'));
21
+ if (!isPathInput(src)) {
22
+ results.push(getValidationResult(ValidationIds.SRC_REQUIRED, '`src` is required.'));
29
23
  }
30
- if (!(0, modules_1.isPathInput)(dest)) {
31
- results.push(getValidationResult(exports.ValidationIds.DEST_REQUIRED, '`dest` is required.'));
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 = path_1.default.resolve((0, path_2.getCwd)(), result.path);
33
+ result.path = path.resolve(getCwd(), result.path);
40
34
  }
41
35
  else if (result.isHubSpot) {
42
- result.path = path_1.default.posix.normalize(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 ((0, modules_1.isModuleFolder)(_src) && (0, modules_1.isModuleFolderChild)(_dest)) {
49
- return results.concat(getValidationResult(exports.ValidationIds.MODULE_TO_MODULE_NESTING, '`src` is a module path and `dest` is within a module.'));
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 ((0, modules_1.isModuleFolder)(_src) && !(0, modules_1.isModuleFolder)(_dest)) {
54
- return results.concat(getValidationResult(exports.ValidationIds.MODULE_FOLDER_REQUIRED, '`src` is a module path but `dest` is not.'));
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 && (0, modules_1.isModuleFolderChild)(_dest)) {
58
- const stat = await fs_extra_1.default.stat(_src.path);
51
+ if (_src.isLocal && isModuleFolderChild(_dest)) {
52
+ const stat = await fs.stat(_src.path);
59
53
  if (stat.isDirectory()) {
60
- const files = await (0, fs_1.walk)(_src.path);
61
- const srcHasModulesChildren = files.some(file => (0, modules_1.isModuleFolderChild)({ ..._src, path: 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(exports.ValidationIds.MODULE_NESTING, '`src` contains modules and `dest` is within a module.'));
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 fs_extra_1.default.readFile(file, 'utf8'); // returns Promise
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 fs_extra_1.default.writeFile(file, fileContents, 'utf8');
96
- await fs_extra_1.default.appendFile(file, 'export const meta = ' + JSON.stringify(metaData, null, ' '));
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((0, lang_1.i18n)(`${i18nKey}.createModule.errors.fileUpdateFailure`, {
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
- ? 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`, {
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
- logger_1.logger.log((0, lang_1.i18n)(`${i18nKey}.createModule.creatingPath`, {
126
+ logger.log(i18n(`${i18nKey}.createModule.creatingPath`, {
134
127
  path: destPath,
135
128
  }));
136
- fs_extra_1.default.ensureDirSync(destPath);
129
+ fs.ensureDirSync(destPath);
137
130
  }
138
- logger_1.logger.log((0, lang_1.i18n)(`${i18nKey}.createModule.creatingModule`, {
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 (path_1.default.basename(src)) {
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 (0, github_1.cloneGithubRepo)('HubSpot/cms-sample-assets', destPath, {
154
+ await cloneGithubRepo('HubSpot/cms-sample-assets', destPath, {
162
155
  sourceDir,
163
156
  });
164
- const files = await (0, fs_1.walk)(destPath);
157
+ const files = await walk(destPath);
165
158
  files
166
159
  .filter(filePath => !moduleFileFilter(filePath))
167
160
  .forEach(filePath => {
168
- fs_extra_1.default.unlinkSync(filePath);
161
+ fs.unlinkSync(filePath);
169
162
  });
170
163
  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'));
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 => path_1.default.basename(filePath) === 'meta.json');
168
+ const metaFiles = files.filter(filePath => path.basename(filePath) === 'meta.json');
176
169
  metaFiles.forEach(metaFile => {
177
- fs_extra_1.default.writeJSONSync(metaFile, moduleMetaData, {
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
- exports.createModule = createModule;
187
- async function retrieveDefaultModule(name, dest) {
179
+ export async function retrieveDefaultModule(name, dest) {
188
180
  if (!name) {
189
- const defaultReactModules = await (0, github_1.listGithubRepoContents)('HubSpot/cms-react', 'default-react-modules/src/components/modules/', 'dir');
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 (0, github_1.cloneGithubRepo)('HubSpot/cms-react', dest, {
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);