@hubspot/local-dev-lib 0.0.3 → 0.0.5

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 (143) 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/lang/en.lyaml +109 -0
  12. package/lang/lang/en.lyaml +109 -0
  13. package/lib/archive.js +2 -4
  14. package/lib/path.d.ts +0 -3
  15. package/lib/path.js +2 -19
  16. package/package.json +10 -9
  17. package/types/Config.d.ts +1 -1
  18. package/types/Error.d.ts +6 -13
  19. package/utils/git.d.ts +2 -1
  20. package/utils/git.js +4 -68
  21. package/utils/lang.d.ts +5 -0
  22. package/utils/lang.js +30 -5
  23. package/errors/cmsFieldsJsErrors.d.ts +0 -9
  24. package/errors/cmsFieldsJsErrors.js +0 -31
  25. package/index.d.ts +0 -2
  26. package/index.js +0 -5
  27. package/src/config/CLIConfiguration.d.ts +0 -55
  28. package/src/config/CLIConfiguration.js +0 -392
  29. package/src/config/configFile.d.ts +0 -21
  30. package/src/config/configFile.js +0 -109
  31. package/src/config/configUtils.d.ts +0 -24
  32. package/src/config/configUtils.js +0 -85
  33. package/src/config/environment.d.ts +0 -3
  34. package/src/config/environment.js +0 -64
  35. package/src/constants/auth.d.ts +0 -24
  36. package/src/constants/auth.js +0 -31
  37. package/src/constants/config.d.ts +0 -8
  38. package/src/constants/config.js +0 -12
  39. package/src/constants/environments.d.ts +0 -13
  40. package/src/constants/environments.js +0 -16
  41. package/src/constants/extensions.d.ts +0 -2
  42. package/src/constants/extensions.js +0 -23
  43. package/src/constants/index.d.ts +0 -16
  44. package/src/constants/index.js +0 -12
  45. package/src/errors/HubSpotAuthError.d.ts +0 -3
  46. package/src/errors/HubSpotAuthError.js +0 -6
  47. package/src/errors/cmsFieldsJsErrors.d.ts +0 -9
  48. package/src/errors/cmsFieldsJsErrors.js +0 -31
  49. package/src/errors/fileSystemErrors.d.ts +0 -8
  50. package/src/errors/fileSystemErrors.js +0 -28
  51. package/src/errors/standardErrors.d.ts +0 -19
  52. package/src/errors/standardErrors.js +0 -67
  53. package/src/index.d.ts +0 -2
  54. package/src/index.js +0 -5
  55. package/src/lib/archive.d.ts +0 -7
  56. package/src/lib/archive.js +0 -111
  57. package/src/lib/modules.d.ts +0 -28
  58. package/src/lib/modules.js +0 -174
  59. package/src/lib/path.d.ts +0 -10
  60. package/src/lib/path.js +0 -84
  61. package/src/types/Accounts.d.ts +0 -50
  62. package/src/types/Accounts.js +0 -2
  63. package/src/types/CLIOptions.d.ts +0 -3
  64. package/src/types/CLIOptions.js +0 -2
  65. package/src/types/Config.d.ts +0 -10
  66. package/src/types/Config.js +0 -2
  67. package/src/types/Error.d.ts +0 -31
  68. package/src/types/Error.js +0 -2
  69. package/src/types/LogCallbacks.d.ts +0 -6
  70. package/src/types/LogCallbacks.js +0 -2
  71. package/src/types/Utils.d.ts +0 -1
  72. package/src/types/Utils.js +0 -2
  73. package/src/utils/encoding.d.ts +0 -1
  74. package/src/utils/encoding.js +0 -11
  75. package/src/utils/environment.d.ts +0 -1
  76. package/src/utils/environment.js +0 -16
  77. package/src/utils/escapeRegExp.d.ts +0 -1
  78. package/src/utils/escapeRegExp.js +0 -7
  79. package/src/utils/files.d.ts +0 -3
  80. package/src/utils/files.js +0 -35
  81. package/src/utils/fs/read.d.ts +0 -4
  82. package/src/utils/fs/read.js +0 -55
  83. package/src/utils/fs/walk.d.ts +0 -2
  84. package/src/utils/fs/walk.js +0 -44
  85. package/src/utils/git.d.ts +0 -4
  86. package/src/utils/git.js +0 -40
  87. package/src/utils/handleFieldsJS.d.ts +0 -35
  88. package/src/utils/handleFieldsJS.js +0 -158
  89. package/src/utils/interpolation.d.ts +0 -5
  90. package/src/utils/interpolation.js +0 -31
  91. package/src/utils/lang.d.ts +0 -8
  92. package/src/utils/lang.js +0 -83
  93. package/src/utils/logger.d.ts +0 -10
  94. package/src/utils/logger.js +0 -22
  95. package/src/utils/text.d.ts +0 -1
  96. package/src/utils/text.js +0 -16
  97. package/src/utils/urls.d.ts +0 -2
  98. package/src/utils/urls.js +0 -20
  99. package/utils/encoding.d.ts +0 -1
  100. package/utils/encoding.js +0 -11
  101. package/utils/environment.d.ts +0 -1
  102. package/utils/environment.js +0 -16
  103. package/utils/interpolation.d.ts +0 -5
  104. package/utils/interpolation.js +0 -31
  105. package/utils/text.d.ts +0 -1
  106. package/utils/text.js +0 -16
  107. /package/{src/constants → constants}/files.d.ts +0 -0
  108. /package/{src/constants → constants}/files.js +0 -0
  109. /package/{src/constants → constants}/github.d.ts +0 -0
  110. /package/{src/constants → constants}/github.js +0 -0
  111. /package/{src/http → http}/requestOptions.d.ts +0 -0
  112. /package/{src/lib → lib}/cms/handleFieldsJS.d.ts +0 -0
  113. /package/{src/lib → lib}/cms/handleFieldsJS.js +0 -0
  114. /package/{src/lib → lib}/cms/index.d.ts +0 -0
  115. /package/{src/lib → lib}/cms/index.js +0 -0
  116. /package/{src/lib → lib}/cms/modules.d.ts +0 -0
  117. /package/{src/lib → lib}/cms/modules.js +0 -0
  118. /package/{src/lib → lib}/cms/themes.d.ts +0 -0
  119. /package/{src/lib → lib}/cms/themes.js +0 -0
  120. /package/{src/lib → lib}/environment.d.ts +0 -0
  121. /package/{src/lib → lib}/environment.js +0 -0
  122. /package/{src/lib → lib}/fs.d.ts +0 -0
  123. /package/{src/lib → lib}/fs.js +0 -0
  124. /package/{src/lib → lib}/github.d.ts +0 -0
  125. /package/{src/lib → lib}/github.js +0 -0
  126. /package/{src/lib → lib}/gitignore.d.ts +0 -0
  127. /package/{src/lib → lib}/gitignore.js +0 -0
  128. /package/{src/lib → lib}/index.d.ts +0 -0
  129. /package/{src/lib → lib}/index.js +0 -0
  130. /package/{src/lib → lib}/text.d.ts +0 -0
  131. /package/{src/lib → lib}/text.js +0 -0
  132. /package/{src/lib → lib}/urls.d.ts +0 -0
  133. /package/{src/lib → lib}/urls.js +0 -0
  134. /package/{src/types → types}/Files.d.ts +0 -0
  135. /package/{src/types → types}/Files.js +0 -0
  136. /package/{src/types → types}/Github.d.ts +0 -0
  137. /package/{src/types → types}/Github.js +0 -0
  138. /package/{src/types → types}/Modules.d.ts +0 -0
  139. /package/{src/types → types}/Modules.js +0 -0
  140. /package/{src/utils → utils}/fieldsJS.d.ts +0 -0
  141. /package/{src/utils → utils}/fieldsJS.js +0 -0
  142. /package/{src/utils → utils}/modules.d.ts +0 -0
  143. /package/{src/utils → utils}/modules.js +0 -0
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;
@@ -1,31 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.throwFieldsJsError = exports.FieldErrors = void 0;
4
- const standardErrors_1 = require("./standardErrors");
5
- const i18nKey = 'errorTypes.cmsFields';
6
- exports.FieldErrors = {
7
- IsNotFunction: 'IsNotFunction',
8
- DoesNotReturnArray: 'DoesNotReturnArray',
9
- };
10
- function throwFieldsJsError(e, path, info = {}) {
11
- if (e instanceof SyntaxError ||
12
- (typeof e === 'object' && e.code === 'MODULE_NOT_FOUND')) {
13
- (0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.syntaxError`, { path });
14
- }
15
- if (e === exports.FieldErrors.IsNotFunction) {
16
- (0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.notFunction`, {
17
- path,
18
- returned: info.returned || '',
19
- });
20
- }
21
- if (e === exports.FieldErrors.DoesNotReturnArray) {
22
- (0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.notReturnArray`, {
23
- path,
24
- returned: info.returned || '',
25
- });
26
- }
27
- if (typeof e === 'object' && e.code === 'ENOENT') {
28
- (0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.invalidPath`, { path });
29
- }
30
- }
31
- exports.throwFieldsJsError = throwFieldsJsError;
package/index.d.ts DELETED
@@ -1,2 +0,0 @@
1
- import { extractZipArchive as __extractZipArchive } from './lib/archive';
2
- export declare const extractZipArchive: typeof __extractZipArchive;
package/index.js DELETED
@@ -1,5 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.extractZipArchive = void 0;
4
- const archive_1 = require("./lib/archive");
5
- exports.extractZipArchive = archive_1.extractZipArchive;
@@ -1,55 +0,0 @@
1
- import { CLIConfig } from '../types/Config';
2
- import { CLIAccount, FlatAccountFields, OauthTokenInfo } from '../types/Accounts';
3
- import { CLIOptions } from '../types/CLIOptions';
4
- import { LogCallbacksArg } from '../types/LogCallbacks';
5
- declare const validateLogCallbackKeys: readonly ["noConfig", "noConfigAccounts", "emptyAccountConfig", "noAccountId", "duplicateAccountIds", "duplicateAccountNames", "nameContainsSpaces"];
6
- declare class CLIConfiguration {
7
- options: CLIOptions;
8
- useEnvConfig: boolean;
9
- config: CLIConfig | null;
10
- constructor();
11
- init(options?: CLIOptions): void;
12
- load(): CLIConfig | null;
13
- configIsEmpty(): boolean;
14
- delete(): void;
15
- write(updatedConfig?: CLIConfig): CLIConfig | null;
16
- validate(logCallbacks?: LogCallbacksArg<typeof validateLogCallbackKeys>): boolean;
17
- getAccount(nameOrId: string | number | undefined): CLIAccount | null;
18
- getAccountId(nameOrId: string | number): number | null;
19
- getDefaultAccount(): string | number | null;
20
- getResolvedDefaultAccountForCWD(nameOrId: string | number): CLIAccount | null;
21
- getConfigAccountIndex(accountId: number): number;
22
- isAccountInConfig(nameOrId: string | number): boolean;
23
- getAndLoadConfigIfNeeded(options?: CLIOptions): CLIConfig;
24
- getEnv(nameOrId?: string | number): string;
25
- /**
26
- * @throws {Error}
27
- */
28
- updateAccount(updatedAccountFields: FlatAccountFields<OauthTokenInfo>, writeUpdate?: boolean): CLIAccount | null;
29
- /**
30
- * @throws {Error}
31
- */
32
- updateDefaultAccount(defaultAccount: string | number): CLIConfig | null;
33
- /**
34
- * @throws {Error}
35
- */
36
- renameAccount(currentName: string, newName: string): void;
37
- /**
38
- * @throws {Error}
39
- */
40
- removeAccountFromConfig(nameOrId: string | number): boolean;
41
- /**
42
- * @throws {Error}
43
- */
44
- updateDefaultMode(defaultMode: string): CLIConfig | null;
45
- /**
46
- * @throws {Error}
47
- */
48
- updateHttpTimeout(timeout: string): CLIConfig | null;
49
- /**
50
- * @throws {Error}
51
- */
52
- updateAllowUsageTracking(isEnabled: boolean): CLIConfig | null;
53
- }
54
- declare const _default: CLIConfiguration;
55
- export default _default;