@hubspot/local-dev-lib 0.0.3 → 0.0.4

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 (141) hide show
  1. package/config/CLIConfiguration.d.ts +6 -6
  2. package/config/CLIConfiguration.js +11 -11
  3. package/config/configFile.js +1 -2
  4. package/constants/extensions.d.ts +1 -0
  5. package/constants/extensions.js +2 -1
  6. package/errors/fileSystemErrors.d.ts +7 -1
  7. package/errors/fileSystemErrors.js +1 -2
  8. package/errors/standardErrors.d.ts +14 -4
  9. package/errors/standardErrors.js +38 -34
  10. package/{src/http → http}/requestOptions.js +1 -1
  11. package/lib/archive.js +2 -4
  12. package/lib/path.d.ts +0 -3
  13. package/lib/path.js +2 -19
  14. package/package.json +8 -8
  15. package/types/Config.d.ts +1 -1
  16. package/types/Error.d.ts +6 -13
  17. package/utils/git.d.ts +2 -1
  18. package/utils/git.js +4 -68
  19. package/utils/lang.d.ts +5 -0
  20. package/utils/lang.js +30 -5
  21. package/errors/cmsFieldsJsErrors.d.ts +0 -9
  22. package/errors/cmsFieldsJsErrors.js +0 -31
  23. package/index.d.ts +0 -2
  24. package/index.js +0 -5
  25. package/src/config/CLIConfiguration.d.ts +0 -55
  26. package/src/config/CLIConfiguration.js +0 -392
  27. package/src/config/configFile.d.ts +0 -21
  28. package/src/config/configFile.js +0 -109
  29. package/src/config/configUtils.d.ts +0 -24
  30. package/src/config/configUtils.js +0 -85
  31. package/src/config/environment.d.ts +0 -3
  32. package/src/config/environment.js +0 -64
  33. package/src/constants/auth.d.ts +0 -24
  34. package/src/constants/auth.js +0 -31
  35. package/src/constants/config.d.ts +0 -8
  36. package/src/constants/config.js +0 -12
  37. package/src/constants/environments.d.ts +0 -13
  38. package/src/constants/environments.js +0 -16
  39. package/src/constants/extensions.d.ts +0 -2
  40. package/src/constants/extensions.js +0 -23
  41. package/src/constants/index.d.ts +0 -16
  42. package/src/constants/index.js +0 -12
  43. package/src/errors/HubSpotAuthError.d.ts +0 -3
  44. package/src/errors/HubSpotAuthError.js +0 -6
  45. package/src/errors/cmsFieldsJsErrors.d.ts +0 -9
  46. package/src/errors/cmsFieldsJsErrors.js +0 -31
  47. package/src/errors/fileSystemErrors.d.ts +0 -8
  48. package/src/errors/fileSystemErrors.js +0 -28
  49. package/src/errors/standardErrors.d.ts +0 -19
  50. package/src/errors/standardErrors.js +0 -67
  51. package/src/index.d.ts +0 -2
  52. package/src/index.js +0 -5
  53. package/src/lib/archive.d.ts +0 -7
  54. package/src/lib/archive.js +0 -111
  55. package/src/lib/modules.d.ts +0 -28
  56. package/src/lib/modules.js +0 -174
  57. package/src/lib/path.d.ts +0 -10
  58. package/src/lib/path.js +0 -84
  59. package/src/types/Accounts.d.ts +0 -50
  60. package/src/types/Accounts.js +0 -2
  61. package/src/types/CLIOptions.d.ts +0 -3
  62. package/src/types/CLIOptions.js +0 -2
  63. package/src/types/Config.d.ts +0 -10
  64. package/src/types/Config.js +0 -2
  65. package/src/types/Error.d.ts +0 -31
  66. package/src/types/Error.js +0 -2
  67. package/src/types/LogCallbacks.d.ts +0 -6
  68. package/src/types/LogCallbacks.js +0 -2
  69. package/src/types/Utils.d.ts +0 -1
  70. package/src/types/Utils.js +0 -2
  71. package/src/utils/encoding.d.ts +0 -1
  72. package/src/utils/encoding.js +0 -11
  73. package/src/utils/environment.d.ts +0 -1
  74. package/src/utils/environment.js +0 -16
  75. package/src/utils/escapeRegExp.d.ts +0 -1
  76. package/src/utils/escapeRegExp.js +0 -7
  77. package/src/utils/files.d.ts +0 -3
  78. package/src/utils/files.js +0 -35
  79. package/src/utils/fs/read.d.ts +0 -4
  80. package/src/utils/fs/read.js +0 -55
  81. package/src/utils/fs/walk.d.ts +0 -2
  82. package/src/utils/fs/walk.js +0 -44
  83. package/src/utils/git.d.ts +0 -4
  84. package/src/utils/git.js +0 -40
  85. package/src/utils/handleFieldsJS.d.ts +0 -35
  86. package/src/utils/handleFieldsJS.js +0 -158
  87. package/src/utils/interpolation.d.ts +0 -5
  88. package/src/utils/interpolation.js +0 -31
  89. package/src/utils/lang.d.ts +0 -8
  90. package/src/utils/lang.js +0 -83
  91. package/src/utils/logger.d.ts +0 -10
  92. package/src/utils/logger.js +0 -22
  93. package/src/utils/text.d.ts +0 -1
  94. package/src/utils/text.js +0 -16
  95. package/src/utils/urls.d.ts +0 -2
  96. package/src/utils/urls.js +0 -20
  97. package/utils/encoding.d.ts +0 -1
  98. package/utils/encoding.js +0 -11
  99. package/utils/environment.d.ts +0 -1
  100. package/utils/environment.js +0 -16
  101. package/utils/interpolation.d.ts +0 -5
  102. package/utils/interpolation.js +0 -31
  103. package/utils/text.d.ts +0 -1
  104. package/utils/text.js +0 -16
  105. /package/{src/constants → constants}/files.d.ts +0 -0
  106. /package/{src/constants → constants}/files.js +0 -0
  107. /package/{src/constants → constants}/github.d.ts +0 -0
  108. /package/{src/constants → constants}/github.js +0 -0
  109. /package/{src/http → http}/requestOptions.d.ts +0 -0
  110. /package/{src/lib → lib}/cms/handleFieldsJS.d.ts +0 -0
  111. /package/{src/lib → lib}/cms/handleFieldsJS.js +0 -0
  112. /package/{src/lib → lib}/cms/index.d.ts +0 -0
  113. /package/{src/lib → lib}/cms/index.js +0 -0
  114. /package/{src/lib → lib}/cms/modules.d.ts +0 -0
  115. /package/{src/lib → lib}/cms/modules.js +0 -0
  116. /package/{src/lib → lib}/cms/themes.d.ts +0 -0
  117. /package/{src/lib → lib}/cms/themes.js +0 -0
  118. /package/{src/lib → lib}/environment.d.ts +0 -0
  119. /package/{src/lib → lib}/environment.js +0 -0
  120. /package/{src/lib → lib}/fs.d.ts +0 -0
  121. /package/{src/lib → lib}/fs.js +0 -0
  122. /package/{src/lib → lib}/github.d.ts +0 -0
  123. /package/{src/lib → lib}/github.js +0 -0
  124. /package/{src/lib → lib}/gitignore.d.ts +0 -0
  125. /package/{src/lib → lib}/gitignore.js +0 -0
  126. /package/{src/lib → lib}/index.d.ts +0 -0
  127. /package/{src/lib → lib}/index.js +0 -0
  128. /package/{src/lib → lib}/text.d.ts +0 -0
  129. /package/{src/lib → lib}/text.js +0 -0
  130. /package/{src/lib → lib}/urls.d.ts +0 -0
  131. /package/{src/lib → lib}/urls.js +0 -0
  132. /package/{src/types → types}/Files.d.ts +0 -0
  133. /package/{src/types → types}/Files.js +0 -0
  134. /package/{src/types → types}/Github.d.ts +0 -0
  135. /package/{src/types → types}/Github.js +0 -0
  136. /package/{src/types → types}/Modules.d.ts +0 -0
  137. /package/{src/types → types}/Modules.js +0 -0
  138. /package/{src/utils → utils}/fieldsJS.d.ts +0 -0
  139. /package/{src/utils → utils}/fieldsJS.js +0 -0
  140. /package/{src/utils → utils}/modules.d.ts +0 -0
  141. /package/{src/utils → utils}/modules.js +0 -0
@@ -4,13 +4,11 @@ import { CLIOptions } from '../types/CLIOptions';
4
4
  import { LogCallbacksArg } from '../types/LogCallbacks';
5
5
  declare const validateLogCallbackKeys: readonly ["noConfig", "noConfigAccounts", "emptyAccountConfig", "noAccountId", "duplicateAccountIds", "duplicateAccountNames", "nameContainsSpaces"];
6
6
  declare class CLIConfiguration {
7
- active: boolean;
8
7
  options: CLIOptions;
9
8
  useEnvConfig: boolean;
10
9
  config: CLIConfig | null;
11
- constructor(options: CLIOptions);
12
- setActive(isActive: boolean): void;
13
- init(options: CLIOptions): void;
10
+ constructor();
11
+ init(options?: CLIOptions): void;
14
12
  load(): CLIConfig | null;
15
13
  configIsEmpty(): boolean;
16
14
  delete(): void;
@@ -22,7 +20,8 @@ declare class CLIConfiguration {
22
20
  getResolvedDefaultAccountForCWD(nameOrId: string | number): CLIAccount | null;
23
21
  getConfigAccountIndex(accountId: number): number;
24
22
  isAccountInConfig(nameOrId: string | number): boolean;
25
- getEnv(nameOrId: string | number): string;
23
+ getAndLoadConfigIfNeeded(options?: CLIOptions): CLIConfig;
24
+ getEnv(nameOrId?: string | number): string;
26
25
  /**
27
26
  * @throws {Error}
28
27
  */
@@ -52,4 +51,5 @@ declare class CLIConfiguration {
52
51
  */
53
52
  updateAllowUsageTracking(isEnabled: boolean): CLIConfig | null;
54
53
  }
55
- export default CLIConfiguration;
54
+ declare const _default: CLIConfiguration;
55
+ export default _default;
@@ -4,7 +4,7 @@ const logger_1 = require("../utils/logger");
4
4
  const standardErrors_1 = require("../errors/standardErrors");
5
5
  const environment_1 = require("./environment");
6
6
  const configFile_1 = require("./configFile");
7
- const text_1 = require("../utils/text");
7
+ const text_1 = require("../lib/text");
8
8
  const constants_1 = require("../constants");
9
9
  const auth_1 = require("../constants/auth");
10
10
  const config_1 = require("../constants/config");
@@ -19,23 +19,17 @@ const validateLogCallbackKeys = [
19
19
  'nameContainsSpaces',
20
20
  ];
21
21
  class CLIConfiguration {
22
- active;
23
22
  options;
24
23
  useEnvConfig;
25
24
  config;
26
- constructor(options) {
27
- this.active = false;
28
- this.options = options || {};
25
+ constructor() {
26
+ this.options = {};
29
27
  this.useEnvConfig = false;
30
28
  this.config = null;
31
29
  }
32
- setActive(isActive) {
33
- this.active = isActive;
34
- }
35
- init(options) {
30
+ init(options = {}) {
36
31
  this.options = options;
37
32
  this.load();
38
- this.active = true;
39
33
  }
40
34
  load() {
41
35
  if (this.options.useEnv) {
@@ -192,6 +186,12 @@ class CLIConfiguration {
192
186
  isAccountInConfig(nameOrId) {
193
187
  return (!!this.config && this.config.accounts && !!this.getAccountId(nameOrId));
194
188
  }
189
+ getAndLoadConfigIfNeeded(options) {
190
+ if (!this.config) {
191
+ this.init(options);
192
+ }
193
+ return this.config;
194
+ }
195
195
  getEnv(nameOrId) {
196
196
  const accountConfig = this.getAccount(nameOrId);
197
197
  if (accountConfig && accountConfig.accountId && accountConfig.env) {
@@ -389,4 +389,4 @@ class CLIConfiguration {
389
389
  return this.write();
390
390
  }
391
391
  }
392
- exports.default = CLIConfiguration;
392
+ exports.default = new CLIConfiguration();
@@ -60,8 +60,7 @@ function parseConfig(configSource) {
60
60
  parsed = js_yaml_1.default.load(configSource);
61
61
  }
62
62
  catch (err) {
63
- (0, logger_1.debug)(`${i18nKey}.errorParsing`);
64
- (0, standardErrors_1.throwError)(err);
63
+ (0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.parsing`, {}, err);
65
64
  }
66
65
  return parsed;
67
66
  }
@@ -1 +1,2 @@
1
1
  export declare const ALLOWED_EXTENSIONS: Set<string>;
2
+ export declare const MODULE_EXTENSION = "module";
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ALLOWED_EXTENSIONS = void 0;
3
+ exports.MODULE_EXTENSION = exports.ALLOWED_EXTENSIONS = void 0;
4
4
  exports.ALLOWED_EXTENSIONS = new Set([
5
5
  'css',
6
6
  'js',
@@ -20,3 +20,4 @@ exports.ALLOWED_EXTENSIONS = new Set([
20
20
  'woff2',
21
21
  'graphql',
22
22
  ]);
23
+ exports.MODULE_EXTENSION = 'module';
@@ -1,2 +1,8 @@
1
- import { BaseError, FileSystemErrorContext } from '../types/Error';
1
+ import { BaseError } from '../types/Error';
2
+ type FileSystemErrorContext = {
3
+ filepath: string;
4
+ write?: boolean;
5
+ read?: boolean;
6
+ };
2
7
  export declare function throwFileSystemError(error: BaseError, context: FileSystemErrorContext): void;
8
+ export {};
@@ -5,7 +5,6 @@ const lang_1 = require("../utils/lang");
5
5
  const standardErrors_1 = require("./standardErrors");
6
6
  const i18nKey = 'errors.errorTypes.fileSystem';
7
7
  function throwFileSystemError(error, context) {
8
- (0, standardErrors_1.debugErrorAndContext)(error, context);
9
8
  let fileAction = '';
10
9
  if (context.read) {
11
10
  fileAction = (0, lang_1.i18n)(`${i18nKey}.readAction`);
@@ -24,6 +23,6 @@ function throwFileSystemError(error, context) {
24
23
  if ((0, standardErrors_1.isSystemError)(error)) {
25
24
  message.push((0, lang_1.i18n)(`${i18nKey}.baseMessage`, { errorMessage: error.message }));
26
25
  }
27
- throw new Error(message.join(' '));
26
+ throw new Error(message.join(' '), { cause: error });
28
27
  }
29
28
  exports.throwFileSystemError = throwFileSystemError;
@@ -1,9 +1,19 @@
1
- import { ErrorContext } from '../types/Error';
2
1
  import { BaseError } from '../types/Error';
3
2
  export declare function isSystemError(err: BaseError): boolean;
4
3
  export declare function isFatalError(err: BaseError): boolean;
5
- export declare function debugErrorAndContext(error: BaseError, context?: ErrorContext): void;
4
+ /**
5
+ * @throws
6
+ */
6
7
  export declare function throwErrorWithMessage(identifier: string, interpolation?: {
7
8
  [key: string]: string | number;
8
- }): never;
9
- export declare function throwError(error: BaseError, context?: ErrorContext): never;
9
+ }, cause?: BaseError): never;
10
+ /**
11
+ * @throws
12
+ */
13
+ export declare function throwTypeErrorWithMessage(identifier: string, interpolation?: {
14
+ [key: string]: string | number;
15
+ }, cause?: BaseError): never;
16
+ /**
17
+ * @throws
18
+ */
19
+ export declare function throwError(error: BaseError): never;
@@ -1,8 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.throwError = exports.throwErrorWithMessage = exports.debugErrorAndContext = exports.isFatalError = exports.isSystemError = void 0;
3
+ exports.throwError = exports.throwTypeErrorWithMessage = exports.throwErrorWithMessage = exports.isFatalError = exports.isSystemError = void 0;
4
4
  const HubSpotAuthError_1 = require("./HubSpotAuthError");
5
- const logger_1 = require("../utils/logger");
6
5
  const lang_1 = require("../utils/lang");
7
6
  function isSystemError(err) {
8
7
  return err.errno != null && err.code != null && err.syscall != null;
@@ -12,52 +11,57 @@ function isFatalError(err) {
12
11
  return err instanceof HubSpotAuthError_1.HubSpotAuthError;
13
12
  }
14
13
  exports.isFatalError = isFatalError;
15
- function debugErrorAndContext(error, context) {
16
- if (error.name === 'StatusCodeError') {
17
- const { statusCode, message, response } = error;
18
- (0, logger_1.debug)('standardErrors.error', {
19
- error: JSON.stringify({
20
- statusCode,
21
- message,
22
- url: response.request.href,
23
- method: response.request.method,
24
- response: response.body,
25
- headers: response.headers,
26
- }),
27
- });
28
- }
29
- else {
30
- (0, logger_1.debug)('standardErrors.error', { error: JSON.stringify(error) });
14
+ /**
15
+ * @throws
16
+ */
17
+ function throwErrorWithMessage(identifier, interpolation, cause) {
18
+ const message = (0, lang_1.i18n)(`errors.${identifier}`, interpolation);
19
+ if (cause) {
20
+ throw new Error(message, { cause });
31
21
  }
32
- (0, logger_1.debug)('standardErrors.context', { context: JSON.stringify(context) });
33
- }
34
- exports.debugErrorAndContext = debugErrorAndContext;
35
- function throwErrorWithMessage(identifier, interpolation) {
36
- throw new Error((0, lang_1.i18n)(`errors.${identifier}`, interpolation));
22
+ throw new Error(message);
37
23
  }
38
24
  exports.throwErrorWithMessage = throwErrorWithMessage;
39
- function throwSystemError(error, context) {
40
- debugErrorAndContext(error, context);
41
- throwErrorWithMessage('errorTypes.standard.system', {
42
- message: error.message,
25
+ /**
26
+ * @throws
27
+ */
28
+ function throwTypeErrorWithMessage(identifier, interpolation, cause) {
29
+ const message = (0, lang_1.i18n)(`errors.${identifier}`, interpolation);
30
+ if (cause) {
31
+ throw new TypeError(message, { cause });
32
+ }
33
+ throw new TypeError(message);
34
+ }
35
+ exports.throwTypeErrorWithMessage = throwTypeErrorWithMessage;
36
+ function throwStatusCodeError(error) {
37
+ const { statusCode, message, response } = error;
38
+ const errorData = JSON.stringify({
39
+ statusCode,
40
+ message,
41
+ url: response.request.href,
42
+ method: response.request.method,
43
+ response: response.body,
44
+ headers: response.headers,
43
45
  });
46
+ throw new Error(errorData, { cause: error });
44
47
  }
45
- // formally logErrorInstance
46
- function throwError(error, context) {
47
- debugErrorAndContext(error, context);
48
- if (isSystemError(error)) {
49
- throwSystemError(error, context);
48
+ /**
49
+ * @throws
50
+ */
51
+ function throwError(error) {
52
+ if (error.name === 'StatusCodeError') {
53
+ throwStatusCodeError(error);
50
54
  }
51
55
  else {
52
56
  // Error or Error subclass
53
57
  const name = error.name || 'Error';
54
- const message = [(0, lang_1.i18n)('errors.errorTypes.standard.generic', { name })];
58
+ const message = [(0, lang_1.i18n)('errors.errorTypes.generic', { name })];
55
59
  [error.message, error.reason].forEach(msg => {
56
60
  if (msg) {
57
61
  message.push(msg);
58
62
  }
59
63
  });
60
- throw new Error(message.join(' '));
64
+ throw new Error(message.join(' '), { cause: error });
61
65
  }
62
66
  }
63
67
  exports.throwError = throwError;
@@ -4,7 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.getRequestOptions = exports.DEFAULT_USER_AGENT_HEADERS = void 0;
7
- const package_json_1 = require("../../package.json");
7
+ const package_json_1 = require("../package.json");
8
8
  const CLIConfiguration_1 = __importDefault(require("../config/CLIConfiguration"));
9
9
  const urls_1 = require("../lib/urls");
10
10
  exports.DEFAULT_USER_AGENT_HEADERS = {
package/lib/archive.js CHANGED
@@ -28,7 +28,6 @@ async function extractZip(name, zip) {
28
28
  });
29
29
  }
30
30
  catch (err) {
31
- (0, logger_1.debug)('archive.extractZip.writeError');
32
31
  if (tmpZipPath || result.tmpDir) {
33
32
  (0, fileSystemErrors_1.throwFileSystemError)(err, {
34
33
  filepath: tmpZipPath || result.tmpDir,
@@ -36,7 +35,7 @@ async function extractZip(name, zip) {
36
35
  });
37
36
  }
38
37
  else {
39
- (0, standardErrors_1.throwError)(err);
38
+ (0, standardErrors_1.throwErrorWithMessage)('archive.extractZip.write', {}, err);
40
39
  }
41
40
  return result;
42
41
  }
@@ -47,8 +46,7 @@ async function extractZip(name, zip) {
47
46
  result.extractDir = tmpExtractPath;
48
47
  }
49
48
  catch (err) {
50
- (0, logger_1.debug)('archive.extractZip.extractError');
51
- (0, standardErrors_1.throwError)(err);
49
+ (0, standardErrors_1.throwErrorWithMessage)('archive.extractZip.extract', {}, err);
52
50
  }
53
51
  (0, logger_1.debug)('archive.extractZip.success');
54
52
  return result;
package/lib/path.d.ts CHANGED
@@ -1,13 +1,10 @@
1
1
  /// <reference types="node" />
2
2
  import path from 'path';
3
3
  export declare function convertToUnixPath(_path: string): string;
4
- export declare function convertToImportPath(_path: string): string;
5
4
  export declare function convertToLocalFileSystemPath(_path: string): string;
6
5
  export declare function splitLocalPath(filepath: string, pathImplementation?: path.PlatformPath): Array<string>;
7
6
  export declare function splitHubSpotPath(filepath: string): Array<string>;
8
7
  export declare function getCwd(): string;
9
8
  export declare function getExt(filepath: string): string;
10
- export declare const getAllowedExtensions: () => Set<string>;
11
9
  export declare function isAllowedExtension(filepath: string): boolean;
12
10
  export declare function getAbsoluteFilePath(_path: string): string;
13
- export declare function isRelativePath(_path: string): boolean;
package/lib/path.js CHANGED
@@ -3,7 +3,7 @@ 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.isRelativePath = exports.getAbsoluteFilePath = exports.isAllowedExtension = exports.getAllowedExtensions = exports.getExt = exports.getCwd = exports.splitHubSpotPath = exports.splitLocalPath = exports.convertToLocalFileSystemPath = exports.convertToImportPath = exports.convertToUnixPath = void 0;
6
+ exports.getAbsoluteFilePath = exports.isAllowedExtension = exports.getExt = exports.getCwd = exports.splitHubSpotPath = exports.splitLocalPath = exports.convertToLocalFileSystemPath = exports.convertToUnixPath = void 0;
7
7
  const path_1 = __importDefault(require("path"));
8
8
  const unixify_1 = __importDefault(require("unixify"));
9
9
  const extensions_1 = require("../constants/extensions");
@@ -15,14 +15,6 @@ function convertToWindowsPath(_path) {
15
15
  const rgx = new RegExp(`\\${path_1.default.posix.sep}`, 'g');
16
16
  return path_1.default.normalize(_path).replace(rgx, path_1.default.win32.sep);
17
17
  }
18
- // Converts a Win32 path to Posix, retaining the drive letter (ex. 'c:')
19
- function convertToImportPath(_path) {
20
- if (path_1.default.sep === path_1.default.win32.sep) {
21
- return _path.split(path_1.default.win32.sep).join(path_1.default.posix.sep);
22
- }
23
- return _path;
24
- }
25
- exports.convertToImportPath = convertToImportPath;
26
18
  function convertToLocalFileSystemPath(_path) {
27
19
  switch (path_1.default.sep) {
28
20
  case path_1.default.posix.sep:
@@ -81,21 +73,12 @@ function getExt(filepath) {
81
73
  return ext[0] === '.' ? ext.slice(1) : ext;
82
74
  }
83
75
  exports.getExt = getExt;
84
- const getAllowedExtensions = () => {
85
- return extensions_1.ALLOWED_EXTENSIONS;
86
- };
87
- exports.getAllowedExtensions = getAllowedExtensions;
88
76
  function isAllowedExtension(filepath) {
89
77
  const ext = getExt(filepath);
90
- const allowedExtensions = (0, exports.getAllowedExtensions)();
91
- return allowedExtensions.has(ext);
78
+ return extensions_1.ALLOWED_EXTENSIONS.has(ext);
92
79
  }
93
80
  exports.isAllowedExtension = isAllowedExtension;
94
81
  function getAbsoluteFilePath(_path) {
95
82
  return path_1.default.resolve(getCwd(), _path);
96
83
  }
97
84
  exports.getAbsoluteFilePath = getAbsoluteFilePath;
98
- function isRelativePath(_path) {
99
- return !path_1.default.isAbsolute(_path);
100
- }
101
- exports.isRelativePath = isRelativePath;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hubspot/local-dev-lib",
3
- "version": "0.0.3",
3
+ "version": "0.0.4",
4
4
  "description": "Provides library functionality for HubSpot local development tooling, including the HubSpot CLI",
5
5
  "main": "dist/index.js",
6
6
  "repository": {
@@ -14,12 +14,12 @@
14
14
  "scripts": {
15
15
  "build": "tsc --rootDir . --outdir dist",
16
16
  "check-main": "branch=$(git rev-parse --abbrev-ref HEAD) && [ $branch = main ] || (echo 'Error: New release can only be published on main branch' && exit 1)",
17
- "lint": "eslint --max-warnings=0 . && prettier --check src/**/*.ts",
17
+ "lint": "eslint --max-warnings=0 . && prettier --check ./**/*.ts",
18
18
  "local-dev": "yarn build && cd dist && yarn link && cd .. && tsc --watch --rootDir . --outdir dist",
19
19
  "_postinstall": "husky install",
20
20
  "prepack": "pinst --disable",
21
21
  "postpack": "pinst --enable",
22
- "prettier:write": "prettier --write src/**/*.{js,json}",
22
+ "prettier:write": "prettier --write ./**/*.{js,json}",
23
23
  "pub": "cd dist && npm publish --tag latest && cd ..",
24
24
  "push": "git push --atomic origin main v$npm_package_version",
25
25
  "release:major": "yarn check-main && yarn version --major && yarn build && yarn pub && yarn push",
@@ -46,11 +46,11 @@
46
46
  "typescript": "^4.9.5"
47
47
  },
48
48
  "exports": {
49
- ".": "./dist/lib/index.js",
50
- "./cms": "./dist/lib/cms",
51
- "./constants": "./dist/constants.js",
52
- "./github": "./dist/lib/github.js",
53
- "./path": "./dist/lib/path.js"
49
+ ".": "./lib/index.js",
50
+ "./cms": "./lib/cms",
51
+ "./constants": "./constants",
52
+ "./github": "./lib/github.js",
53
+ "./path": "./lib/path.js"
54
54
  },
55
55
  "dependencies": {
56
56
  "axios": "^1.3.5",
package/types/Config.d.ts CHANGED
@@ -6,5 +6,5 @@ export interface CLIConfig {
6
6
  defaultMode?: string;
7
7
  httpTimeout?: number;
8
8
  env?: string;
9
- test: number;
9
+ httpUseLocalhost?: boolean;
10
10
  }
package/types/Error.d.ts CHANGED
@@ -5,13 +5,9 @@ export interface BaseError extends Error {
5
5
  code?: string | null;
6
6
  syscall?: string | null;
7
7
  reason?: string;
8
+ statusCode?: number;
8
9
  }
9
- export interface SystemError extends BaseError {
10
- errno: number;
11
- code: string;
12
- syscall: string;
13
- }
14
- export interface StatusCodeError extends SystemError {
10
+ export interface StatusCodeError extends BaseError {
15
11
  name: 'StatusCodeError';
16
12
  statusCode: number;
17
13
  message: string;
@@ -28,11 +24,8 @@ export interface StatusCodeError extends SystemError {
28
24
  };
29
25
  };
30
26
  }
31
- export type ErrorContext = {
32
- accountId?: number;
33
- };
34
- export interface FileSystemErrorContext extends ErrorContext {
35
- filepath?: string;
36
- read?: boolean;
37
- write?: boolean;
27
+ export interface GithubError extends BaseError {
28
+ error: {
29
+ message?: string;
30
+ };
38
31
  }
package/utils/git.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ export declare function makeComparisonDir(filepath: string | null): string | null;
2
+ export declare const getGitComparisonDir: () => string | null;
1
3
  export declare function isConfigPathInGitRepo(configPath: string): boolean;
2
4
  export declare function configFilenameIsIgnoredByGitignore(ignoreFiles: Array<string>, configPath: string): boolean;
3
- export declare function checkAndAddConfigToGitignore(configPath: string): void;
package/utils/git.js CHANGED
@@ -3,51 +3,22 @@ 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.checkAndAddConfigToGitignore = exports.configFilenameIsIgnoredByGitignore = exports.isConfigPathInGitRepo = void 0;
6
+ exports.configFilenameIsIgnoredByGitignore = exports.isConfigPathInGitRepo = exports.getGitComparisonDir = exports.makeComparisonDir = void 0;
7
7
  const fs_extra_1 = require("fs-extra");
8
8
  const path_1 = __importDefault(require("path"));
9
9
  const ignore_1 = __importDefault(require("ignore"));
10
10
  const findup_sync_1 = __importDefault(require("findup-sync"));
11
- const config_1 = require("../constants/config");
12
- const standardErrors_1 = require("../errors/standardErrors");
13
- const GITIGNORE_FILE = '.gitignore';
14
11
  function makeComparisonDir(filepath) {
15
12
  if (typeof filepath !== 'string')
16
13
  return null;
17
14
  // Append sep to make comparisons easier e.g. 'foos'.startsWith('foo')
18
15
  return path_1.default.dirname(path_1.default.resolve(filepath)).toLowerCase() + path_1.default.sep;
19
16
  }
17
+ exports.makeComparisonDir = makeComparisonDir;
20
18
  const getGitComparisonDir = () => makeComparisonDir((0, findup_sync_1.default)('.git'));
21
- // Get all .gitignore files since they can cascade down directory structures
22
- function getGitignoreFiles(configPath) {
23
- const gitDir = getGitComparisonDir();
24
- const files = [];
25
- if (!gitDir) {
26
- // Not in git
27
- return files;
28
- }
29
- // Start findup from config dir
30
- let cwd = configPath && path_1.default.dirname(configPath);
31
- while (cwd) {
32
- const ignorePath = (0, findup_sync_1.default)(GITIGNORE_FILE, { cwd });
33
- const ignorePathComparisonDir = makeComparisonDir(ignorePath);
34
- const gitComparisonDir = makeComparisonDir(gitDir);
35
- if (ignorePath &&
36
- ignorePathComparisonDir &&
37
- gitComparisonDir &&
38
- ignorePathComparisonDir.startsWith(gitComparisonDir)) {
39
- const file = path_1.default.resolve(ignorePath);
40
- files.push(file);
41
- cwd = path_1.default.resolve(path_1.default.dirname(file) + '..');
42
- }
43
- else {
44
- cwd = null;
45
- }
46
- }
47
- return files;
48
- }
19
+ exports.getGitComparisonDir = getGitComparisonDir;
49
20
  function isConfigPathInGitRepo(configPath) {
50
- const gitDir = getGitComparisonDir();
21
+ const gitDir = (0, exports.getGitComparisonDir)();
51
22
  if (!gitDir)
52
23
  return false;
53
24
  const configDir = makeComparisonDir(configPath);
@@ -67,38 +38,3 @@ function configFilenameIsIgnoredByGitignore(ignoreFiles, configPath) {
67
38
  });
68
39
  }
69
40
  exports.configFilenameIsIgnoredByGitignore = configFilenameIsIgnoredByGitignore;
70
- function checkGitInclusion(configPath) {
71
- const result = {
72
- inGit: false,
73
- configIgnored: false,
74
- gitignoreFiles: [],
75
- };
76
- if (isConfigPathInGitRepo(configPath)) {
77
- result.inGit = true;
78
- result.gitignoreFiles = getGitignoreFiles(configPath);
79
- if (configFilenameIsIgnoredByGitignore(result.gitignoreFiles, configPath)) {
80
- // Found ignore statement in .gitignore that matches config filename
81
- result.configIgnored = true;
82
- }
83
- }
84
- return result;
85
- }
86
- function checkAndAddConfigToGitignore(configPath) {
87
- try {
88
- const { configIgnored, gitignoreFiles } = checkGitInclusion(configPath);
89
- if (configIgnored)
90
- return;
91
- let gitignoreFilePath = gitignoreFiles && gitignoreFiles.length ? gitignoreFiles[0] : null;
92
- if (!gitignoreFilePath) {
93
- gitignoreFilePath = path_1.default.resolve(configPath, GITIGNORE_FILE);
94
- (0, fs_extra_1.writeFileSync)(gitignoreFilePath, '');
95
- }
96
- const gitignoreContents = (0, fs_extra_1.readFileSync)(gitignoreFilePath).toString();
97
- const updatedContents = `${gitignoreContents.trim()}\n\n# HubSpot config file\n${config_1.DEFAULT_HUBSPOT_CONFIG_YAML_FILE_NAME}\n`;
98
- (0, fs_extra_1.writeFileSync)(gitignoreFilePath, updatedContents);
99
- }
100
- catch (e) {
101
- throw (0, standardErrors_1.throwErrorWithMessage)('utils.git.configIgnore');
102
- }
103
- }
104
- exports.checkAndAddConfigToGitignore = checkAndAddConfigToGitignore;
package/utils/lang.d.ts CHANGED
@@ -1,3 +1,8 @@
1
+ type InterpolationData = {
2
+ [identifier: string]: string | number;
3
+ };
4
+ export declare function interpolate(stringValue: string, interpolationData: InterpolationData): string;
1
5
  export declare function i18n(lookupDotNotation: string, options?: {
2
6
  [identifier: string]: string | number;
3
7
  }): string;
8
+ export {};
package/utils/lang.js CHANGED
@@ -1,11 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.i18n = void 0;
4
- const util_1 = require("util");
3
+ exports.i18n = exports.interpolate = void 0;
5
4
  const path_1 = require("path");
6
5
  const fs_extra_1 = require("fs-extra");
7
6
  const js_yaml_1 = require("js-yaml");
8
- const interpolation_1 = require("./interpolation");
9
7
  const MISSING_LANGUAGE_DATA_PREFIX = '[Missing language data]';
10
8
  let locale = '';
11
9
  let languageObj;
@@ -21,7 +19,6 @@ function loadLanguageFromYaml() {
21
19
  // Fall back to using the default language file
22
20
  locale = languageFileExists ? nodeLocale : 'en';
23
21
  languageObj = (0, js_yaml_1.load)((0, fs_extra_1.readFileSync)((0, path_1.join)(__dirname, `../lang/${locale}.lyaml`), 'utf8'));
24
- console.debug('Loaded language data: ', (0, util_1.inspect)(languageObj, true, 999, true));
25
22
  }
26
23
  catch (e) {
27
24
  throw new Error(`Error loading language data: ${e}`);
@@ -46,13 +43,41 @@ function getTextValue(lookupDotNotation) {
46
43
  }
47
44
  return textValue;
48
45
  }
46
+ const delimiters = {
47
+ interpolation: {
48
+ start: '{{',
49
+ end: '}}',
50
+ },
51
+ };
52
+ function generateReplaceFn(matchedText, startIndex, replacementString) {
53
+ return function (currentStringValue) {
54
+ return `${currentStringValue.slice(0, startIndex)}${replacementString || ''}${currentStringValue.slice(startIndex + matchedText.length)}`;
55
+ };
56
+ }
57
+ function interpolate(stringValue, interpolationData) {
58
+ const interpolationIdentifierRegEx = new RegExp(`${delimiters.interpolation.start}(.*?)${delimiters.interpolation.end}`, 'g');
59
+ const replaceQueue = [];
60
+ let match;
61
+ // while & reduce necessary because RegExp.exec is stateful and only runs
62
+ // from beginning to end of string
63
+ while ((match = interpolationIdentifierRegEx.exec(stringValue)) != null) {
64
+ const { 0: matchedText, 1: rawIdentifier, index } = match;
65
+ const identifier = rawIdentifier.trim();
66
+ if (identifier) {
67
+ replaceQueue.unshift(generateReplaceFn(matchedText, index, interpolationData[identifier]));
68
+ }
69
+ }
70
+ const compiledString = replaceQueue.reduce((currentValue, replaceFn) => replaceFn(currentValue), stringValue);
71
+ return compiledString;
72
+ }
73
+ exports.interpolate = interpolate;
49
74
  function i18n(lookupDotNotation, options = {}) {
50
75
  if (typeof lookupDotNotation !== 'string') {
51
76
  throw new Error(`i18n must be passed a string value for lookupDotNotation, received ${typeof lookupDotNotation}`);
52
77
  }
53
78
  const textValue = getTextValue(lookupDotNotation);
54
79
  const shouldInterpolate = !textValue.startsWith(MISSING_LANGUAGE_DATA_PREFIX);
55
- return shouldInterpolate ? (0, interpolation_1.interpolate)(textValue, options) : textValue;
80
+ return shouldInterpolate ? interpolate(textValue, options) : textValue;
56
81
  }
57
82
  exports.i18n = i18n;
58
83
  loadLanguageFromYaml();
@@ -1,9 +0,0 @@
1
- import { ValueOf } from '../types/Utils';
2
- import { BaseError } from '../types/Error';
3
- export declare const FieldErrors: {
4
- readonly IsNotFunction: "IsNotFunction";
5
- readonly DoesNotReturnArray: "DoesNotReturnArray";
6
- };
7
- export declare function throwFieldsJsError(e: BaseError | ValueOf<typeof FieldErrors>, path: string, info?: {
8
- returned?: string;
9
- }): void;