@hubspot/local-dev-lib 0.0.2 → 0.0.3

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 (171) hide show
  1. package/config/CLIConfiguration.d.ts +55 -0
  2. package/config/CLIConfiguration.js +392 -0
  3. package/config/configFile.d.ts +21 -0
  4. package/config/configFile.js +110 -0
  5. package/config/configUtils.d.ts +24 -0
  6. package/config/configUtils.js +85 -0
  7. package/config/environment.d.ts +3 -0
  8. package/config/environment.js +64 -0
  9. package/constants/auth.d.ts +24 -0
  10. package/constants/auth.js +31 -0
  11. package/constants/config.d.ts +8 -0
  12. package/constants/config.js +12 -0
  13. package/constants/environments.d.ts +13 -0
  14. package/constants/environments.js +16 -0
  15. package/constants/extensions.d.ts +1 -0
  16. package/constants/extensions.js +22 -0
  17. package/constants/index.d.ts +16 -0
  18. package/constants/index.js +12 -0
  19. package/errors/HubSpotAuthError.d.ts +3 -0
  20. package/errors/HubSpotAuthError.js +6 -0
  21. package/errors/cmsFieldsJsErrors.d.ts +9 -0
  22. package/errors/cmsFieldsJsErrors.js +31 -0
  23. package/errors/fileSystemErrors.d.ts +2 -0
  24. package/errors/fileSystemErrors.js +29 -0
  25. package/errors/standardErrors.d.ts +9 -0
  26. package/errors/standardErrors.js +63 -0
  27. package/index.d.ts +2 -0
  28. package/index.js +5 -0
  29. package/lib/archive.d.ts +7 -0
  30. package/lib/archive.js +113 -0
  31. package/lib/path.d.ts +13 -0
  32. package/lib/path.js +101 -0
  33. package/package.json +1 -4
  34. package/src/config/CLIConfiguration.d.ts +55 -0
  35. package/src/config/CLIConfiguration.js +392 -0
  36. package/src/config/configFile.d.ts +21 -0
  37. package/src/config/configFile.js +109 -0
  38. package/src/config/configUtils.d.ts +24 -0
  39. package/src/config/configUtils.js +85 -0
  40. package/src/config/environment.d.ts +3 -0
  41. package/src/config/environment.js +64 -0
  42. package/src/constants/auth.d.ts +24 -0
  43. package/src/constants/auth.js +31 -0
  44. package/src/constants/config.d.ts +8 -0
  45. package/src/constants/config.js +12 -0
  46. package/src/constants/environments.d.ts +13 -0
  47. package/src/constants/environments.js +16 -0
  48. package/src/constants/extensions.d.ts +2 -0
  49. package/src/constants/extensions.js +23 -0
  50. package/src/constants/files.d.ts +5 -0
  51. package/src/constants/files.js +8 -0
  52. package/src/constants/github.d.ts +4 -0
  53. package/src/constants/github.js +7 -0
  54. package/src/constants/index.d.ts +16 -0
  55. package/src/constants/index.js +12 -0
  56. package/src/errors/HubSpotAuthError.d.ts +3 -0
  57. package/src/errors/HubSpotAuthError.js +6 -0
  58. package/src/errors/cmsFieldsJsErrors.d.ts +9 -0
  59. package/src/errors/cmsFieldsJsErrors.js +31 -0
  60. package/src/errors/fileSystemErrors.d.ts +8 -0
  61. package/src/errors/fileSystemErrors.js +28 -0
  62. package/src/errors/standardErrors.d.ts +19 -0
  63. package/src/errors/standardErrors.js +67 -0
  64. package/src/http/requestOptions.d.ts +20 -0
  65. package/src/http/requestOptions.js +27 -0
  66. package/src/index.d.ts +2 -0
  67. package/src/index.js +5 -0
  68. package/src/lib/archive.d.ts +7 -0
  69. package/src/lib/archive.js +111 -0
  70. package/src/lib/cms/handleFieldsJS.d.ts +32 -0
  71. package/src/lib/cms/handleFieldsJS.js +143 -0
  72. package/src/lib/cms/index.d.ts +10 -0
  73. package/src/lib/cms/index.js +13 -0
  74. package/src/lib/cms/modules.d.ts +24 -0
  75. package/src/lib/cms/modules.js +124 -0
  76. package/src/lib/cms/themes.d.ts +2 -0
  77. package/src/lib/cms/themes.js +34 -0
  78. package/src/lib/environment.d.ts +1 -0
  79. package/src/lib/environment.js +16 -0
  80. package/src/lib/fs.d.ts +4 -0
  81. package/src/lib/fs.js +71 -0
  82. package/src/lib/github.d.ts +17 -0
  83. package/src/lib/github.js +133 -0
  84. package/src/lib/gitignore.d.ts +1 -0
  85. package/src/lib/gitignore.js +76 -0
  86. package/src/lib/index.d.ts +11 -0
  87. package/src/lib/index.js +14 -0
  88. package/src/lib/modules.d.ts +28 -0
  89. package/src/lib/modules.js +174 -0
  90. package/src/lib/path.d.ts +10 -0
  91. package/src/lib/path.js +84 -0
  92. package/src/lib/text.d.ts +1 -0
  93. package/src/lib/text.js +16 -0
  94. package/src/lib/urls.d.ts +2 -0
  95. package/src/lib/urls.js +20 -0
  96. package/src/types/Accounts.d.ts +50 -0
  97. package/src/types/Accounts.js +2 -0
  98. package/src/types/CLIOptions.d.ts +3 -0
  99. package/src/types/CLIOptions.js +2 -0
  100. package/src/types/Config.d.ts +10 -0
  101. package/src/types/Config.js +2 -0
  102. package/src/types/Error.d.ts +31 -0
  103. package/src/types/Error.js +2 -0
  104. package/src/types/Files.d.ts +8 -0
  105. package/src/types/Files.js +2 -0
  106. package/src/types/Github.d.ts +58 -0
  107. package/src/types/Github.js +2 -0
  108. package/src/types/LogCallbacks.d.ts +6 -0
  109. package/src/types/LogCallbacks.js +2 -0
  110. package/src/types/Modules.d.ts +5 -0
  111. package/src/types/Modules.js +2 -0
  112. package/src/types/Utils.d.ts +1 -0
  113. package/src/types/Utils.js +2 -0
  114. package/src/utils/encoding.d.ts +1 -0
  115. package/src/utils/encoding.js +11 -0
  116. package/src/utils/environment.d.ts +1 -0
  117. package/src/utils/environment.js +16 -0
  118. package/src/utils/escapeRegExp.d.ts +1 -0
  119. package/src/utils/escapeRegExp.js +7 -0
  120. package/src/utils/fieldsJS.d.ts +3 -0
  121. package/src/utils/fieldsJS.js +18 -0
  122. package/src/utils/files.d.ts +3 -0
  123. package/src/utils/files.js +35 -0
  124. package/src/utils/fs/read.d.ts +4 -0
  125. package/src/utils/fs/read.js +55 -0
  126. package/src/utils/fs/walk.d.ts +2 -0
  127. package/src/utils/fs/walk.js +44 -0
  128. package/src/utils/git.d.ts +4 -0
  129. package/src/utils/git.js +40 -0
  130. package/src/utils/handleFieldsJS.d.ts +35 -0
  131. package/src/utils/handleFieldsJS.js +158 -0
  132. package/src/utils/interpolation.d.ts +5 -0
  133. package/src/utils/interpolation.js +31 -0
  134. package/src/utils/lang.d.ts +8 -0
  135. package/src/utils/lang.js +83 -0
  136. package/src/utils/logger.d.ts +10 -0
  137. package/src/utils/logger.js +22 -0
  138. package/src/utils/modules.d.ts +4 -0
  139. package/src/utils/modules.js +53 -0
  140. package/src/utils/text.d.ts +1 -0
  141. package/src/utils/text.js +16 -0
  142. package/src/utils/urls.d.ts +2 -0
  143. package/src/utils/urls.js +20 -0
  144. package/types/Accounts.d.ts +50 -0
  145. package/types/Accounts.js +2 -0
  146. package/types/CLIOptions.d.ts +3 -0
  147. package/types/CLIOptions.js +2 -0
  148. package/types/Config.d.ts +10 -0
  149. package/types/Config.js +2 -0
  150. package/types/Error.d.ts +38 -0
  151. package/types/Error.js +2 -0
  152. package/types/LogCallbacks.d.ts +6 -0
  153. package/types/LogCallbacks.js +2 -0
  154. package/types/Utils.d.ts +1 -0
  155. package/types/Utils.js +2 -0
  156. package/utils/encoding.d.ts +1 -0
  157. package/utils/encoding.js +11 -0
  158. package/utils/environment.d.ts +1 -0
  159. package/utils/environment.js +16 -0
  160. package/utils/escapeRegExp.d.ts +1 -0
  161. package/utils/escapeRegExp.js +7 -0
  162. package/utils/git.d.ts +3 -0
  163. package/utils/git.js +104 -0
  164. package/utils/interpolation.d.ts +5 -0
  165. package/utils/interpolation.js +31 -0
  166. package/utils/lang.d.ts +3 -0
  167. package/utils/lang.js +58 -0
  168. package/utils/logger.d.ts +10 -0
  169. package/utils/logger.js +22 -0
  170. package/utils/text.d.ts +1 -0
  171. package/utils/text.js +16 -0
@@ -0,0 +1,53 @@
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.isModuleFolderChild = exports.isModuleFolder = exports.isPathInput = void 0;
7
+ const path_1 = __importDefault(require("path"));
8
+ const path_2 = require("../lib/path");
9
+ const extensions_1 = require("../constants/extensions");
10
+ const standardErrors_1 = require("../errors/standardErrors");
11
+ const isBool = (x) => !!x === x;
12
+ function isPathInput(pathInput) {
13
+ return !!(pathInput &&
14
+ typeof pathInput.path === 'string' &&
15
+ (isBool(pathInput.isLocal) || isBool(pathInput.isHubSpot)));
16
+ }
17
+ exports.isPathInput = isPathInput;
18
+ function throwInvalidPathInput(pathInput) {
19
+ if (isPathInput(pathInput))
20
+ return;
21
+ (0, standardErrors_1.throwTypeErrorWithMessage)('modules.throwInvalidPathInput');
22
+ }
23
+ function isModuleFolder(pathInput) {
24
+ throwInvalidPathInput(pathInput);
25
+ const _path = pathInput.isHubSpot
26
+ ? path_1.default.posix.normalize(pathInput.path)
27
+ : path_1.default.normalize(pathInput.path);
28
+ return (0, path_2.getExt)(_path) === extensions_1.MODULE_EXTENSION;
29
+ }
30
+ exports.isModuleFolder = isModuleFolder;
31
+ function isModuleFolderChild(pathInput, ignoreLocales = false) {
32
+ throwInvalidPathInput(pathInput);
33
+ let pathParts = [];
34
+ if (pathInput.isLocal) {
35
+ pathParts = (0, path_2.splitLocalPath)(pathInput.path);
36
+ }
37
+ else if (pathInput.isHubSpot) {
38
+ pathParts = (0, path_2.splitHubSpotPath)(pathInput.path);
39
+ }
40
+ const { length } = pathParts;
41
+ // Not a child path?
42
+ if (length <= 1)
43
+ return false;
44
+ // Check if we should ignore this file
45
+ if (ignoreLocales && pathParts.find(part => part === '_locales')) {
46
+ return false;
47
+ }
48
+ // Check if any parent folders are module folders.
49
+ return pathParts
50
+ .slice(0, length - 1)
51
+ .some(part => isModuleFolder({ ...pathInput, path: part }));
52
+ }
53
+ exports.isModuleFolderChild = isModuleFolderChild;
@@ -0,0 +1 @@
1
+ export declare function commaSeparatedValues(arr: Array<string>, conjunction?: string, ifempty?: string): string;
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.commaSeparatedValues = void 0;
4
+ function commaSeparatedValues(arr, conjunction = 'and', ifempty = '') {
5
+ const l = arr.length;
6
+ if (!l)
7
+ return ifempty;
8
+ if (l < 2)
9
+ return arr[0];
10
+ if (l < 3)
11
+ return arr.join(` ${conjunction} `);
12
+ arr = arr.slice();
13
+ arr[l - 1] = `${conjunction} ${arr[l - 1]}`;
14
+ return arr.join(', ');
15
+ }
16
+ exports.commaSeparatedValues = commaSeparatedValues;
@@ -0,0 +1,2 @@
1
+ export declare const getHubSpotWebsiteOrigin: (env: string) => string;
2
+ export declare function getHubSpotApiOrigin(env?: string, useLocalHost?: boolean): string;
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getHubSpotApiOrigin = exports.getHubSpotWebsiteOrigin = void 0;
4
+ const environments_1 = require("../constants/environments");
5
+ function getEnvUrlString(env) {
6
+ if (typeof env !== 'string') {
7
+ return '';
8
+ }
9
+ return env.toLowerCase() === environments_1.ENVIRONMENTS.QA ? environments_1.ENVIRONMENTS.QA : '';
10
+ }
11
+ const getHubSpotWebsiteOrigin = (env) => `https://app.hubspot${getEnvUrlString(env)}.com`;
12
+ exports.getHubSpotWebsiteOrigin = getHubSpotWebsiteOrigin;
13
+ function getHubSpotApiOrigin(env, useLocalHost) {
14
+ let domain = process.env.HUBAPI_DOMAIN_OVERRIDE;
15
+ if (!domain || typeof domain !== 'string') {
16
+ domain = `${useLocalHost ? 'local' : 'api'}.hubapi${getEnvUrlString(env)}`;
17
+ }
18
+ return `https://${domain}.com`;
19
+ }
20
+ exports.getHubSpotApiOrigin = getHubSpotApiOrigin;
@@ -0,0 +1,50 @@
1
+ import { DEFAULT_MODES } from '../constants/config';
2
+ import { ValueOf } from './Utils';
3
+ export type AuthType = 'personalaccesskey' | 'apikey' | 'oauth2';
4
+ export interface CLIAccount {
5
+ name?: string;
6
+ accountId: number;
7
+ defaultMode?: ValueOf<typeof DEFAULT_MODES>;
8
+ env?: string;
9
+ authType?: AuthType;
10
+ auth?: object;
11
+ sandboxAccountType?: string | null;
12
+ parentAccountId?: number | null;
13
+ apiKey?: string;
14
+ personalAccessKey?: string;
15
+ }
16
+ export type PersonalAccessKeyTokenInfo = {
17
+ accessToken: string;
18
+ expiresAt: string;
19
+ };
20
+ export type OauthTokenInfo = {
21
+ refreshToken?: string;
22
+ };
23
+ export interface PersonalAccessKeyAccount extends CLIAccount {
24
+ authType: 'personalaccesskey';
25
+ auth?: {
26
+ tokenInfo: PersonalAccessKeyTokenInfo;
27
+ };
28
+ personalAccessKey: string;
29
+ }
30
+ export interface OAuthAccount extends CLIAccount {
31
+ authType: 'oauth2';
32
+ auth?: {
33
+ clientId?: string;
34
+ clientSecret?: string;
35
+ scopes?: Array<string>;
36
+ tokenInfo?: OauthTokenInfo;
37
+ };
38
+ }
39
+ export interface APIKeyAccount extends CLIAccount {
40
+ authType: 'apikey';
41
+ apiKey: string;
42
+ }
43
+ export interface FlatAccountFields<T extends OauthTokenInfo | PersonalAccessKeyTokenInfo> extends CLIAccount {
44
+ tokenInfo?: T;
45
+ clientId?: string;
46
+ clientSecret?: string;
47
+ scopes?: Array<string>;
48
+ apiKey?: string;
49
+ personalAccessKey?: string;
50
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,3 @@
1
+ export interface CLIOptions {
2
+ useEnv?: boolean;
3
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,10 @@
1
+ import { CLIAccount } from './Accounts';
2
+ export interface CLIConfig {
3
+ accounts: Array<CLIAccount>;
4
+ allowUsageTracking?: boolean;
5
+ defaultAccount?: string | number;
6
+ defaultMode?: string;
7
+ httpTimeout?: number;
8
+ env?: string;
9
+ test: number;
10
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,38 @@
1
+ export interface BaseError extends Error {
2
+ name: string;
3
+ message: string;
4
+ errno?: number | null;
5
+ code?: string | null;
6
+ syscall?: string | null;
7
+ reason?: string;
8
+ }
9
+ export interface SystemError extends BaseError {
10
+ errno: number;
11
+ code: string;
12
+ syscall: string;
13
+ }
14
+ export interface StatusCodeError extends SystemError {
15
+ name: 'StatusCodeError';
16
+ statusCode: number;
17
+ message: string;
18
+ response: {
19
+ request: {
20
+ href: string;
21
+ method: string;
22
+ };
23
+ body: {
24
+ [key: string]: string;
25
+ };
26
+ headers: {
27
+ [key: string]: string;
28
+ };
29
+ };
30
+ }
31
+ export type ErrorContext = {
32
+ accountId?: number;
33
+ };
34
+ export interface FileSystemErrorContext extends ErrorContext {
35
+ filepath?: string;
36
+ read?: boolean;
37
+ write?: boolean;
38
+ }
package/types/Error.js ADDED
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,6 @@
1
+ export type LogCallbacks<T extends string> = {
2
+ [key in T]?: () => void;
3
+ };
4
+ export type LogCallbacksArg<T extends readonly string[]> = {
5
+ [key in T[number]]?: () => void;
6
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1 @@
1
+ export type ValueOf<T> = T[keyof T];
package/types/Utils.js ADDED
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1 @@
1
+ export declare function base64EncodeString(valueToEncode: string): string;
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.base64EncodeString = void 0;
4
+ function base64EncodeString(valueToEncode) {
5
+ if (typeof valueToEncode !== 'string') {
6
+ return valueToEncode;
7
+ }
8
+ const stringBuffer = Buffer.from(valueToEncode);
9
+ return encodeURIComponent(stringBuffer.toString('base64'));
10
+ }
11
+ exports.base64EncodeString = base64EncodeString;
@@ -0,0 +1 @@
1
+ export declare function getValidEnv(env: string, maskedProductionValue?: string): string;
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getValidEnv = void 0;
4
+ const environments_1 = require("../constants/environments");
5
+ function getValidEnv(env, maskedProductionValue) {
6
+ const prodValue = maskedProductionValue
7
+ ? maskedProductionValue
8
+ : environments_1.ENVIRONMENTS.PROD;
9
+ const returnVal = typeof env &&
10
+ typeof env === 'string' &&
11
+ env.toLowerCase() === environments_1.ENVIRONMENTS.QA
12
+ ? environments_1.ENVIRONMENTS.QA
13
+ : prodValue;
14
+ return returnVal;
15
+ }
16
+ exports.getValidEnv = getValidEnv;
@@ -0,0 +1 @@
1
+ export declare function escapeRegExp(string: string): string;
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.escapeRegExp = void 0;
4
+ function escapeRegExp(string) {
5
+ return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); // $& means the whole matched string
6
+ }
7
+ exports.escapeRegExp = escapeRegExp;
package/utils/git.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ export declare function isConfigPathInGitRepo(configPath: string): boolean;
2
+ export declare function configFilenameIsIgnoredByGitignore(ignoreFiles: Array<string>, configPath: string): boolean;
3
+ export declare function checkAndAddConfigToGitignore(configPath: string): void;
package/utils/git.js ADDED
@@ -0,0 +1,104 @@
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.checkAndAddConfigToGitignore = exports.configFilenameIsIgnoredByGitignore = exports.isConfigPathInGitRepo = void 0;
7
+ const fs_extra_1 = require("fs-extra");
8
+ const path_1 = __importDefault(require("path"));
9
+ const ignore_1 = __importDefault(require("ignore"));
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
+ function makeComparisonDir(filepath) {
15
+ if (typeof filepath !== 'string')
16
+ return null;
17
+ // Append sep to make comparisons easier e.g. 'foos'.startsWith('foo')
18
+ return path_1.default.dirname(path_1.default.resolve(filepath)).toLowerCase() + path_1.default.sep;
19
+ }
20
+ 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
+ }
49
+ function isConfigPathInGitRepo(configPath) {
50
+ const gitDir = getGitComparisonDir();
51
+ if (!gitDir)
52
+ return false;
53
+ const configDir = makeComparisonDir(configPath);
54
+ if (!configDir)
55
+ return false;
56
+ return configDir.startsWith(gitDir);
57
+ }
58
+ exports.isConfigPathInGitRepo = isConfigPathInGitRepo;
59
+ function configFilenameIsIgnoredByGitignore(ignoreFiles, configPath) {
60
+ return ignoreFiles.some(gitignore => {
61
+ const gitignoreContents = (0, fs_extra_1.readFileSync)(gitignore).toString();
62
+ const gitignoreConfig = (0, ignore_1.default)().add(gitignoreContents);
63
+ if (gitignoreConfig.ignores(path_1.default.relative(path_1.default.dirname(gitignore), configPath))) {
64
+ return true;
65
+ }
66
+ return false;
67
+ });
68
+ }
69
+ 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;
@@ -0,0 +1,5 @@
1
+ type InterpolationData = {
2
+ [identifier: string]: string | number;
3
+ };
4
+ export declare function interpolate(stringValue: string, interpolationData: InterpolationData): string;
5
+ export {};
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.interpolate = void 0;
4
+ const delimiters = {
5
+ interpolation: {
6
+ start: '{{',
7
+ end: '}}',
8
+ },
9
+ };
10
+ function generateReplaceFn(matchedText, startIndex, replacementString) {
11
+ return function (currentStringValue) {
12
+ return `${currentStringValue.slice(0, startIndex)}${replacementString || ''}${currentStringValue.slice(startIndex + matchedText.length)}`;
13
+ };
14
+ }
15
+ function interpolate(stringValue, interpolationData) {
16
+ const interpolationIdentifierRegEx = new RegExp(`${delimiters.interpolation.start}(.*?)${delimiters.interpolation.end}`, 'g');
17
+ const replaceQueue = [];
18
+ let match;
19
+ // while & reduce necessary because RegExp.exec is stateful and only runs
20
+ // from beginning to end of string
21
+ while ((match = interpolationIdentifierRegEx.exec(stringValue)) != null) {
22
+ const { 0: matchedText, 1: rawIdentifier, index } = match;
23
+ const identifier = rawIdentifier.trim();
24
+ if (identifier) {
25
+ replaceQueue.unshift(generateReplaceFn(matchedText, index, interpolationData[identifier]));
26
+ }
27
+ }
28
+ const compiledString = replaceQueue.reduce((currentValue, replaceFn) => replaceFn(currentValue), stringValue);
29
+ return compiledString;
30
+ }
31
+ exports.interpolate = interpolate;
@@ -0,0 +1,3 @@
1
+ export declare function i18n(lookupDotNotation: string, options?: {
2
+ [identifier: string]: string | number;
3
+ }): string;
package/utils/lang.js ADDED
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.i18n = void 0;
4
+ const util_1 = require("util");
5
+ const path_1 = require("path");
6
+ const fs_extra_1 = require("fs-extra");
7
+ const js_yaml_1 = require("js-yaml");
8
+ const interpolation_1 = require("./interpolation");
9
+ const MISSING_LANGUAGE_DATA_PREFIX = '[Missing language data]';
10
+ let locale = '';
11
+ let languageObj;
12
+ function loadLanguageFromYaml() {
13
+ if (languageObj)
14
+ return;
15
+ try {
16
+ const nodeLocale = Intl.DateTimeFormat()
17
+ .resolvedOptions()
18
+ .locale.split('-')[0];
19
+ const languageFilePath = (0, path_1.join)(__dirname, `../lang/${nodeLocale}.lyaml`);
20
+ const languageFileExists = (0, fs_extra_1.existsSync)(languageFilePath);
21
+ // Fall back to using the default language file
22
+ locale = languageFileExists ? nodeLocale : 'en';
23
+ 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
+ }
26
+ catch (e) {
27
+ throw new Error(`Error loading language data: ${e}`);
28
+ }
29
+ }
30
+ function getTextValue(lookupDotNotation) {
31
+ const lookupProps = [locale, ...lookupDotNotation.split('.')];
32
+ const missingTextData = `${MISSING_LANGUAGE_DATA_PREFIX}: ${lookupProps.join('.')}`;
33
+ let textValue = languageObj;
34
+ let previouslyCheckedProp = lookupProps[0];
35
+ lookupProps.forEach(prop => {
36
+ previouslyCheckedProp = prop;
37
+ if (typeof textValue === 'object') {
38
+ textValue = textValue[prop];
39
+ }
40
+ else {
41
+ console.debug(`Unable to access language property: ${lookupProps.join('.')}. Failed to access prop "${previouslyCheckedProp}".`);
42
+ }
43
+ });
44
+ if (typeof textValue !== 'string') {
45
+ return missingTextData;
46
+ }
47
+ return textValue;
48
+ }
49
+ function i18n(lookupDotNotation, options = {}) {
50
+ if (typeof lookupDotNotation !== 'string') {
51
+ throw new Error(`i18n must be passed a string value for lookupDotNotation, received ${typeof lookupDotNotation}`);
52
+ }
53
+ const textValue = getTextValue(lookupDotNotation);
54
+ const shouldInterpolate = !textValue.startsWith(MISSING_LANGUAGE_DATA_PREFIX);
55
+ return shouldInterpolate ? (0, interpolation_1.interpolate)(textValue, options) : textValue;
56
+ }
57
+ exports.i18n = i18n;
58
+ loadLanguageFromYaml();
@@ -0,0 +1,10 @@
1
+ import { LogCallbacks } from '../types/LogCallbacks';
2
+ export declare function log<T extends string>(key: T, callbacks?: LogCallbacks<T>, debugKey?: string, debugInterpolation?: {
3
+ [key: string]: string | number;
4
+ }): void;
5
+ export declare function makeTypedLogger<T extends readonly string[]>(callbacks?: LogCallbacks<T[number]>, debugKey?: string): (key: T[number], debugInterpolation?: {
6
+ [key: string]: string | number;
7
+ } | undefined) => void;
8
+ export declare function debug(identifier: string, interpolation?: {
9
+ [key: string]: string | number;
10
+ }): void;
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.debug = exports.makeTypedLogger = exports.log = void 0;
4
+ const lang_1 = require("./lang");
5
+ function log(key, callbacks, debugKey, debugInterpolation) {
6
+ if (callbacks && callbacks[key]) {
7
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
8
+ callbacks[key]();
9
+ }
10
+ else if (debugKey) {
11
+ debug(debugKey, debugInterpolation);
12
+ }
13
+ }
14
+ exports.log = log;
15
+ function makeTypedLogger(callbacks, debugKey) {
16
+ return (key, debugInterpolation) => log(key, callbacks, `${debugKey}.${key}`, debugInterpolation);
17
+ }
18
+ exports.makeTypedLogger = makeTypedLogger;
19
+ function debug(identifier, interpolation) {
20
+ console.debug((0, lang_1.i18n)(`debug.${identifier}`, interpolation));
21
+ }
22
+ exports.debug = debug;
@@ -0,0 +1 @@
1
+ export declare function commaSeparatedValues(arr: Array<string>, conjunction?: string, ifempty?: string): string;
package/utils/text.js ADDED
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.commaSeparatedValues = void 0;
4
+ function commaSeparatedValues(arr, conjunction = 'and', ifempty = '') {
5
+ const l = arr.length;
6
+ if (!l)
7
+ return ifempty;
8
+ if (l < 2)
9
+ return arr[0];
10
+ if (l < 3)
11
+ return arr.join(` ${conjunction} `);
12
+ arr = arr.slice();
13
+ arr[l - 1] = `${conjunction} ${arr[l - 1]}`;
14
+ return arr.join(', ');
15
+ }
16
+ exports.commaSeparatedValues = commaSeparatedValues;