@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,76 @@
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 = void 0;
7
+ const fs_extra_1 = require("fs-extra");
8
+ const path_1 = __importDefault(require("path"));
9
+ const findup_sync_1 = __importDefault(require("findup-sync"));
10
+ const git_1 = require("../utils/git");
11
+ const config_1 = require("../constants/config");
12
+ const standardErrors_1 = require("../errors/standardErrors");
13
+ const GITIGNORE_FILE = '.gitignore';
14
+ // Get all .gitignore files since they can cascade down directory structures
15
+ function getGitignoreFiles(configPath) {
16
+ const gitDir = (0, git_1.getGitComparisonDir)();
17
+ const files = [];
18
+ if (!gitDir) {
19
+ // Not in git
20
+ return files;
21
+ }
22
+ // Start findup from config dir
23
+ let cwd = configPath && path_1.default.dirname(configPath);
24
+ while (cwd) {
25
+ const ignorePath = (0, findup_sync_1.default)(GITIGNORE_FILE, { cwd });
26
+ const ignorePathComparisonDir = (0, git_1.makeComparisonDir)(ignorePath);
27
+ const gitComparisonDir = (0, git_1.makeComparisonDir)(gitDir);
28
+ if (ignorePath &&
29
+ ignorePathComparisonDir &&
30
+ gitComparisonDir &&
31
+ ignorePathComparisonDir.startsWith(gitComparisonDir)) {
32
+ const file = path_1.default.resolve(ignorePath);
33
+ files.push(file);
34
+ cwd = path_1.default.resolve(path_1.default.dirname(file) + '..');
35
+ }
36
+ else {
37
+ cwd = null;
38
+ }
39
+ }
40
+ return files;
41
+ }
42
+ function checkGitInclusion(configPath) {
43
+ const result = {
44
+ inGit: false,
45
+ configIgnored: false,
46
+ gitignoreFiles: [],
47
+ };
48
+ if ((0, git_1.isConfigPathInGitRepo)(configPath)) {
49
+ result.inGit = true;
50
+ result.gitignoreFiles = getGitignoreFiles(configPath);
51
+ if ((0, git_1.configFilenameIsIgnoredByGitignore)(result.gitignoreFiles, configPath)) {
52
+ // Found ignore statement in .gitignore that matches config filename
53
+ result.configIgnored = true;
54
+ }
55
+ }
56
+ return result;
57
+ }
58
+ function checkAndAddConfigToGitignore(configPath) {
59
+ try {
60
+ const { configIgnored, gitignoreFiles } = checkGitInclusion(configPath);
61
+ if (configIgnored)
62
+ return;
63
+ let gitignoreFilePath = gitignoreFiles && gitignoreFiles.length ? gitignoreFiles[0] : null;
64
+ if (!gitignoreFilePath) {
65
+ gitignoreFilePath = path_1.default.resolve(configPath, GITIGNORE_FILE);
66
+ (0, fs_extra_1.writeFileSync)(gitignoreFilePath, '');
67
+ }
68
+ const gitignoreContents = (0, fs_extra_1.readFileSync)(gitignoreFilePath).toString();
69
+ const updatedContents = `${gitignoreContents.trim()}\n\n# HubSpot config file\n${config_1.DEFAULT_HUBSPOT_CONFIG_YAML_FILE_NAME}\n`;
70
+ (0, fs_extra_1.writeFileSync)(gitignoreFilePath, updatedContents);
71
+ }
72
+ catch (e) {
73
+ (0, standardErrors_1.throwErrorWithMessage)('utils.git.configIgnore', {}, e);
74
+ }
75
+ }
76
+ exports.checkAndAddConfigToGitignore = checkAndAddConfigToGitignore;
@@ -0,0 +1,11 @@
1
+ import { extractZipArchive as __extractZipArchive } from './archive';
2
+ import { getValidEnv as __getValidEnv } from './environment';
3
+ import { walk as __walk } from './fs';
4
+ import { commaSeparatedValues as __commaSeparatedValues } from './text';
5
+ import { getHubSpotApiOrigin as __getHubSpotApiOrigin } from './urls';
6
+ export declare const extractZipArchive: typeof __extractZipArchive;
7
+ export declare const getValidEnv: typeof __getValidEnv;
8
+ export declare const walk: typeof __walk;
9
+ export declare const commaSeparatedValues: typeof __commaSeparatedValues;
10
+ export declare const getHubSpotApiOrigin: typeof __getHubSpotApiOrigin;
11
+ export declare const getHubSpotWebsiteOrigin: (env: string) => string;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getHubSpotWebsiteOrigin = exports.getHubSpotApiOrigin = exports.commaSeparatedValues = exports.walk = exports.getValidEnv = exports.extractZipArchive = void 0;
4
+ const archive_1 = require("./archive");
5
+ const environment_1 = require("./environment");
6
+ const fs_1 = require("./fs");
7
+ const text_1 = require("./text");
8
+ const urls_1 = require("./urls");
9
+ exports.extractZipArchive = archive_1.extractZipArchive;
10
+ exports.getValidEnv = environment_1.getValidEnv;
11
+ exports.walk = fs_1.walk;
12
+ exports.commaSeparatedValues = text_1.commaSeparatedValues;
13
+ exports.getHubSpotApiOrigin = urls_1.getHubSpotApiOrigin;
14
+ exports.getHubSpotWebsiteOrigin = urls_1.getHubSpotWebsiteOrigin;
@@ -0,0 +1,28 @@
1
+ import { LogCallbacksArg } from '../types/LogCallbacks';
2
+ import { PathInput } from '../types/Modules';
3
+ export declare function isModuleFolder(pathInput: PathInput): boolean;
4
+ export declare function isModuleFolderChild(pathInput: PathInput, ignoreLocales?: boolean): boolean;
5
+ export declare const ValidationIds: {
6
+ SRC_REQUIRED: string;
7
+ DEST_REQUIRED: string;
8
+ MODULE_FOLDER_REQUIRED: string;
9
+ MODULE_TO_MODULE_NESTING: string;
10
+ MODULE_NESTING: string;
11
+ };
12
+ type ValidationResult = {
13
+ id: string;
14
+ message: string;
15
+ };
16
+ export declare function validateSrcAndDestPaths(src?: PathInput, dest?: PathInput): Promise<Array<ValidationResult>>;
17
+ export declare const isModuleHTMLFile: (filePath: string) => boolean;
18
+ export declare const isModuleCSSFile: (filePath: string) => boolean;
19
+ type ModuleDefinition = {
20
+ contentTypes: Array<string>;
21
+ moduleLabel: string;
22
+ global: boolean;
23
+ };
24
+ declare const createModuleCallbackKeys: readonly ["creatingPath", "creatingModule"];
25
+ export declare function createModule(moduleDefinition: ModuleDefinition, name: string, dest: string, options?: {
26
+ allowExistingDir: boolean;
27
+ }, logCallbacks?: LogCallbacksArg<typeof createModuleCallbackKeys>): Promise<void>;
28
+ export {};
@@ -0,0 +1,174 @@
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.createModule = exports.isModuleCSSFile = exports.isModuleHTMLFile = exports.validateSrcAndDestPaths = exports.ValidationIds = exports.isModuleFolderChild = exports.isModuleFolder = 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 walk_1 = require("../utils/fs/walk");
11
+ const extensions_1 = require("../constants/extensions");
12
+ const github_1 = require("./github");
13
+ const standardErrors_1 = require("../errors/standardErrors");
14
+ const logger_1 = require("../utils/logger");
15
+ // Matches files named module.html
16
+ const MODULE_HTML_EXTENSION_REGEX = new RegExp(/\.module(?:\/|\\)module\.html$/);
17
+ // Matches files named module.css
18
+ const MODULE_CSS_EXTENSION_REGEX = new RegExp(/\.module(?:\/|\\)module\.css$/);
19
+ const isBool = (x) => !!x === x;
20
+ function isPathInput(pathInput) {
21
+ return !!(pathInput &&
22
+ typeof pathInput.path === 'string' &&
23
+ (isBool(pathInput.isLocal) || isBool(pathInput.isHubSpot)));
24
+ }
25
+ function throwInvalidPathInput(pathInput) {
26
+ if (isPathInput(pathInput))
27
+ return;
28
+ (0, standardErrors_1.throwTypeErrorWithMessage)('modules.throwInvalidPathInput');
29
+ }
30
+ function isModuleFolder(pathInput) {
31
+ throwInvalidPathInput(pathInput);
32
+ const _path = pathInput.isHubSpot
33
+ ? path_1.default.posix.normalize(pathInput.path)
34
+ : path_1.default.normalize(pathInput.path);
35
+ return (0, path_2.getExt)(_path) === extensions_1.MODULE_EXTENSION;
36
+ }
37
+ exports.isModuleFolder = isModuleFolder;
38
+ function isModuleFolderChild(pathInput, ignoreLocales = false) {
39
+ throwInvalidPathInput(pathInput);
40
+ let pathParts = [];
41
+ if (pathInput.isLocal) {
42
+ pathParts = (0, path_2.splitLocalPath)(pathInput.path);
43
+ }
44
+ else if (pathInput.isHubSpot) {
45
+ pathParts = (0, path_2.splitHubSpotPath)(pathInput.path);
46
+ }
47
+ const { length } = pathParts;
48
+ // Not a child path?
49
+ if (length <= 1)
50
+ return false;
51
+ // Check if we should ignore this file
52
+ if (ignoreLocales && pathParts.find(part => part === '_locales')) {
53
+ return false;
54
+ }
55
+ // Check if any parent folders are module folders.
56
+ return pathParts
57
+ .slice(0, length - 1)
58
+ .some(part => isModuleFolder({ ...pathInput, path: part }));
59
+ }
60
+ exports.isModuleFolderChild = isModuleFolderChild;
61
+ // Ids for testing
62
+ exports.ValidationIds = {
63
+ SRC_REQUIRED: 'SRC_REQUIRED',
64
+ DEST_REQUIRED: 'DEST_REQUIRED',
65
+ MODULE_FOLDER_REQUIRED: 'MODULE_FOLDER_REQUIRED',
66
+ MODULE_TO_MODULE_NESTING: 'MODULE_TO_MODULE_NESTING',
67
+ MODULE_NESTING: 'MODULE_NESTING',
68
+ };
69
+ const getValidationResult = (id, message) => ({ id, message });
70
+ async function validateSrcAndDestPaths(src, dest) {
71
+ const results = [];
72
+ if (!isPathInput(src)) {
73
+ results.push(getValidationResult(exports.ValidationIds.SRC_REQUIRED, '`src` is required.'));
74
+ }
75
+ if (!isPathInput(dest)) {
76
+ results.push(getValidationResult(exports.ValidationIds.DEST_REQUIRED, '`dest` is required.'));
77
+ }
78
+ if (results.length || !src || !dest) {
79
+ return results;
80
+ }
81
+ const [_src, _dest] = [src, dest].map(inputPath => {
82
+ const result = { ...inputPath };
83
+ if (result.isLocal) {
84
+ result.path = path_1.default.resolve((0, path_2.getCwd)(), result.path);
85
+ }
86
+ else if (result.isHubSpot) {
87
+ result.path = path_1.default.posix.normalize(result.path);
88
+ }
89
+ return result;
90
+ });
91
+ // src is a .module folder and dest is within a module. (Nesting)
92
+ // e.g. `upload foo.module bar.module/zzz`
93
+ if (isModuleFolder(_src) && isModuleFolderChild(_dest)) {
94
+ return results.concat(getValidationResult(exports.ValidationIds.MODULE_TO_MODULE_NESTING, '`src` is a module path and `dest` is within a module.'));
95
+ }
96
+ // src is a .module folder but dest is not
97
+ // e.g. `upload foo.module bar`
98
+ if (isModuleFolder(_src) && !isModuleFolder(_dest)) {
99
+ return results.concat(getValidationResult(exports.ValidationIds.MODULE_FOLDER_REQUIRED, '`src` is a module path but `dest` is not.'));
100
+ }
101
+ // src is a folder that includes modules and dest is within a module. (Nesting)
102
+ if (_src.isLocal && isModuleFolderChild(_dest)) {
103
+ const stat = await fs_extra_1.default.stat(_src.path);
104
+ if (stat.isDirectory()) {
105
+ const files = await (0, walk_1.walk)(_src.path + 'l');
106
+ const srcHasModulesChildren = files.some(file => isModuleFolderChild({ ..._src, path: file }));
107
+ if (srcHasModulesChildren) {
108
+ return results.concat(getValidationResult(exports.ValidationIds.MODULE_NESTING, '`src` contains modules and `dest` is within a module.'));
109
+ }
110
+ }
111
+ }
112
+ return results;
113
+ }
114
+ exports.validateSrcAndDestPaths = validateSrcAndDestPaths;
115
+ const isModuleHTMLFile = (filePath) => MODULE_HTML_EXTENSION_REGEX.test(filePath);
116
+ exports.isModuleHTMLFile = isModuleHTMLFile;
117
+ const isModuleCSSFile = (filePath) => MODULE_CSS_EXTENSION_REGEX.test(filePath);
118
+ exports.isModuleCSSFile = isModuleCSSFile;
119
+ const createModuleCallbackKeys = ['creatingPath', 'creatingModule'];
120
+ async function createModule(moduleDefinition, name, dest, options = {
121
+ allowExistingDir: false,
122
+ }, logCallbacks) {
123
+ const logger = (0, logger_1.makeTypedLogger)(logCallbacks, 'modules.createModule');
124
+ const writeModuleMeta = ({ contentTypes, moduleLabel, global }, dest) => {
125
+ const metaData = {
126
+ label: moduleLabel,
127
+ css_assets: [],
128
+ external_js: [],
129
+ global: global,
130
+ help_text: '',
131
+ host_template_types: contentTypes,
132
+ js_assets: [],
133
+ other_assets: [],
134
+ smart_type: 'NOT_SMART',
135
+ tags: [],
136
+ is_available_for_new_content: false,
137
+ };
138
+ fs_extra_1.default.writeJSONSync(dest, metaData, { spaces: 2 });
139
+ };
140
+ const moduleFileFilter = (src, dest) => {
141
+ const emailEnabled = moduleDefinition.contentTypes.includes('EMAIL');
142
+ switch (path_1.default.basename(src)) {
143
+ case 'meta.json':
144
+ writeModuleMeta(moduleDefinition, dest);
145
+ return false;
146
+ case 'module.js':
147
+ case 'module.css':
148
+ if (emailEnabled) {
149
+ return false;
150
+ }
151
+ return true;
152
+ default:
153
+ return true;
154
+ }
155
+ };
156
+ const folderName = !name || name.endsWith('.module') ? name : `${name}.module`;
157
+ const destPath = path_1.default.join(dest, folderName);
158
+ if (!options.allowExistingDir && fs_extra_1.default.existsSync(destPath)) {
159
+ (0, standardErrors_1.throwErrorWithMessage)('modules.createModule', {
160
+ path: destPath,
161
+ });
162
+ }
163
+ else {
164
+ logger('creatingPath', {
165
+ path: destPath,
166
+ });
167
+ fs_extra_1.default.ensureDirSync(destPath);
168
+ }
169
+ logger('creatingModule', {
170
+ path: destPath,
171
+ });
172
+ await (0, github_1.downloadGithubRepoContents)('cms-sample-assets', 'modules/Sample.module', destPath, moduleFileFilter);
173
+ }
174
+ exports.createModule = createModule;
@@ -0,0 +1,10 @@
1
+ /// <reference types="node" />
2
+ import path from 'path';
3
+ export declare function convertToUnixPath(_path: string): string;
4
+ export declare function convertToLocalFileSystemPath(_path: string): string;
5
+ export declare function splitLocalPath(filepath: string, pathImplementation?: path.PlatformPath): Array<string>;
6
+ export declare function splitHubSpotPath(filepath: string): Array<string>;
7
+ export declare function getCwd(): string;
8
+ export declare function getExt(filepath: string): string;
9
+ export declare function isAllowedExtension(filepath: string): boolean;
10
+ export declare function getAbsoluteFilePath(_path: string): string;
@@ -0,0 +1,84 @@
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.getAbsoluteFilePath = exports.isAllowedExtension = exports.getExt = exports.getCwd = exports.splitHubSpotPath = exports.splitLocalPath = exports.convertToLocalFileSystemPath = exports.convertToUnixPath = void 0;
7
+ const path_1 = __importDefault(require("path"));
8
+ const unixify_1 = __importDefault(require("unixify"));
9
+ const extensions_1 = require("../constants/extensions");
10
+ function convertToUnixPath(_path) {
11
+ return (0, unixify_1.default)(path_1.default.normalize(_path));
12
+ }
13
+ exports.convertToUnixPath = convertToUnixPath;
14
+ function convertToWindowsPath(_path) {
15
+ const rgx = new RegExp(`\\${path_1.default.posix.sep}`, 'g');
16
+ return path_1.default.normalize(_path).replace(rgx, path_1.default.win32.sep);
17
+ }
18
+ function convertToLocalFileSystemPath(_path) {
19
+ switch (path_1.default.sep) {
20
+ case path_1.default.posix.sep:
21
+ return convertToUnixPath(_path);
22
+ case path_1.default.win32.sep:
23
+ return convertToWindowsPath(_path);
24
+ default:
25
+ return path_1.default.normalize(_path);
26
+ }
27
+ }
28
+ exports.convertToLocalFileSystemPath = convertToLocalFileSystemPath;
29
+ function removeTrailingSlashFromSplits(parts) {
30
+ if (parts.length > 1 && parts[parts.length - 1] === '') {
31
+ return parts.slice(0, parts.length - 1);
32
+ }
33
+ return parts;
34
+ }
35
+ // Splits a filepath for local file system sources.
36
+ function splitLocalPath(filepath, pathImplementation = path_1.default) {
37
+ if (!filepath)
38
+ return [];
39
+ const { sep } = pathImplementation;
40
+ const rgx = new RegExp(`\\${sep}+`, 'g');
41
+ const parts = pathImplementation.normalize(filepath).split(rgx);
42
+ // Restore posix root if present
43
+ if (sep === path_1.default.posix.sep && parts[0] === '') {
44
+ parts[0] = '/';
45
+ }
46
+ return removeTrailingSlashFromSplits(parts);
47
+ }
48
+ exports.splitLocalPath = splitLocalPath;
49
+ // Splits a filepath for remote sources (HubSpot).
50
+ function splitHubSpotPath(filepath) {
51
+ if (!filepath)
52
+ return [];
53
+ const rgx = new RegExp(`\\${path_1.default.posix.sep}+`, 'g');
54
+ const parts = convertToUnixPath(filepath).split(rgx);
55
+ // Restore root if present
56
+ if (parts[0] === '') {
57
+ parts[0] = '/';
58
+ }
59
+ return removeTrailingSlashFromSplits(parts);
60
+ }
61
+ exports.splitHubSpotPath = splitHubSpotPath;
62
+ function getCwd() {
63
+ if (process.env.INIT_CWD) {
64
+ return process.env.INIT_CWD;
65
+ }
66
+ return process.cwd();
67
+ }
68
+ exports.getCwd = getCwd;
69
+ function getExt(filepath) {
70
+ if (typeof filepath !== 'string')
71
+ return '';
72
+ const ext = path_1.default.extname(filepath).trim().toLowerCase();
73
+ return ext[0] === '.' ? ext.slice(1) : ext;
74
+ }
75
+ exports.getExt = getExt;
76
+ function isAllowedExtension(filepath) {
77
+ const ext = getExt(filepath);
78
+ return extensions_1.ALLOWED_EXTENSIONS.has(ext);
79
+ }
80
+ exports.isAllowedExtension = isAllowedExtension;
81
+ function getAbsoluteFilePath(_path) {
82
+ return path_1.default.resolve(getCwd(), _path);
83
+ }
84
+ exports.getAbsoluteFilePath = getAbsoluteFilePath;
@@ -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
+ httpUseLocalhost?: boolean;
10
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,31 @@
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
+ statusCode?: number;
9
+ }
10
+ export interface StatusCodeError extends BaseError {
11
+ name: 'StatusCodeError';
12
+ statusCode: number;
13
+ message: string;
14
+ response: {
15
+ request: {
16
+ href: string;
17
+ method: string;
18
+ };
19
+ body: {
20
+ [key: string]: string;
21
+ };
22
+ headers: {
23
+ [key: string]: string;
24
+ };
25
+ };
26
+ }
27
+ export interface GithubError extends BaseError {
28
+ error: {
29
+ message?: string;
30
+ };
31
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,8 @@
1
+ import { ValueOf } from '../types/Utils';
2
+ import { STAT_TYPES } from '../constants/files';
3
+ export type StatType = ValueOf<typeof STAT_TYPES>;
4
+ export type FileData = {
5
+ filepath: string;
6
+ files?: Array<string>;
7
+ type: StatType;
8
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,58 @@
1
+ type GithubAuthor = {
2
+ login: string;
3
+ id: number;
4
+ node_id: string;
5
+ avatar_url: string;
6
+ gravatar_id: string;
7
+ url: string;
8
+ html_url: string;
9
+ followers_url: string;
10
+ following_url: string;
11
+ gists_url: string;
12
+ starred_url: string;
13
+ subscriptions_url: string;
14
+ organizations_url: string;
15
+ repos_url: string;
16
+ events_url: string;
17
+ received_events_url: string;
18
+ type: string;
19
+ site_admin: boolean;
20
+ };
21
+ export type GithubReleaseData = {
22
+ url: string;
23
+ assets_url: string;
24
+ upload_url: string;
25
+ html_url: string;
26
+ id: number;
27
+ author: GithubAuthor;
28
+ node_id: string;
29
+ tag_name: string;
30
+ target_commitish: string;
31
+ name: string;
32
+ draft: boolean;
33
+ prerelease: boolean;
34
+ created_at: string;
35
+ published_at: string;
36
+ assets: Array<object>;
37
+ tarball_url: string;
38
+ zipball_url: string;
39
+ body: string;
40
+ mentions_count: number;
41
+ };
42
+ export type GithubRepoFile = {
43
+ name: string;
44
+ path: string;
45
+ sha: string;
46
+ size: number;
47
+ url: string;
48
+ html_url: string;
49
+ git_url: string;
50
+ download_url: string;
51
+ type: string;
52
+ _links: {
53
+ self: string;
54
+ git: string;
55
+ html: string;
56
+ };
57
+ };
58
+ export {};
@@ -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,5 @@
1
+ export type PathInput = {
2
+ isLocal?: boolean;
3
+ isHubSpot?: boolean;
4
+ path: string;
5
+ };
@@ -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];