@hubspot/local-dev-lib 3.1.2 → 3.1.3-beta.0

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.
@@ -137,7 +137,8 @@ async function createFunction(functionInfo, dest, options = {}) {
137
137
  functionFilePath,
138
138
  }));
139
139
  }
140
- await (0, github_1.downloadGithubRepoContents)('HubSpot/cms-sample-assets', 'functions/sample-function.js', functionFilePath);
140
+ const result = await (0, github_1.fetchFileFromRepository)('HubSpot/cms-sample-assets', 'functions/sample-function.js', 'main');
141
+ fs_extra_1.default.writeFileSync(functionFilePath, result);
141
142
  logger_1.logger.log((0, lang_1.i18n)(`${i18nKey}.createFunction.createdFunctionFile`, {
142
143
  path: functionFilePath,
143
144
  }));
@@ -139,25 +139,16 @@ async function createModule(moduleDefinition, name, dest, getInternalVersion, op
139
139
  path: destPath,
140
140
  }));
141
141
  // Filter out certain fetched files from the response
142
- const moduleFileFilter = (src, dest) => {
142
+ const moduleFileFilter = (src) => {
143
143
  const emailEnabled = moduleDefinition.contentTypes.includes('EMAIL');
144
144
  switch (path_1.default.basename(src)) {
145
145
  case 'meta.json':
146
- fs_extra_1.default.writeJSONSync(dest, moduleMetaData, { spaces: 2 }); // writing a meta.json file to standard HubL modules
147
146
  return false;
148
147
  case 'module.js':
149
148
  case 'module.css':
150
- if (emailEnabled) {
151
- return false;
152
- }
153
- return true;
149
+ return !emailEnabled;
154
150
  case 'global-sample-react-module.css':
155
- case 'stories':
156
- case 'tests':
157
- if (getInternalVersion) {
158
- return true;
159
- }
160
- return false;
151
+ return getInternalVersion;
161
152
  default:
162
153
  return true;
163
154
  }
@@ -166,7 +157,27 @@ async function createModule(moduleDefinition, name, dest, getInternalVersion, op
166
157
  const sampleAssetPath = !isReactModule
167
158
  ? 'Sample.module'
168
159
  : 'SampleReactModule';
169
- await (0, github_1.downloadGithubRepoContents)('HubSpot/cms-sample-assets', `modules/${sampleAssetPath}`, destPath, '', moduleFileFilter);
160
+ const sourceDir = `modules/${sampleAssetPath}`;
161
+ await (0, github_1.cloneGithubRepo)('HubSpot/cms-sample-assets', destPath, {
162
+ sourceDir,
163
+ });
164
+ const files = await (0, fs_1.walk)(destPath);
165
+ files
166
+ .filter(filePath => !moduleFileFilter(filePath))
167
+ .forEach(filePath => {
168
+ fs_extra_1.default.unlinkSync(filePath);
169
+ });
170
+ if (!getInternalVersion) {
171
+ fs_extra_1.default.removeSync(path_1.default.join(destPath, 'stories'));
172
+ fs_extra_1.default.removeSync(path_1.default.join(destPath, 'tests'));
173
+ }
174
+ // Get and write the metafiles
175
+ const metaFiles = files.filter(filePath => path_1.default.basename(filePath) === 'meta.json');
176
+ metaFiles.forEach(metaFile => {
177
+ fs_extra_1.default.writeJSONSync(metaFile, moduleMetaData, {
178
+ spaces: 2,
179
+ });
180
+ });
170
181
  // Updating React module files after fetch
171
182
  if (isReactModule) {
172
183
  await updateFileContents(`${destPath}/index.tsx`, moduleMetaData, getInternalVersion);
@@ -178,7 +189,9 @@ async function retrieveDefaultModule(name, dest) {
178
189
  const defaultReactModules = await (0, github_1.listGithubRepoContents)('HubSpot/cms-react', 'default-react-modules/src/components/modules/', 'dir');
179
190
  return defaultReactModules;
180
191
  }
181
- await (0, github_1.downloadGithubRepoContents)('HubSpot/cms-react', `default-react-modules/src/components/modules/${name}`, dest);
192
+ await (0, github_1.cloneGithubRepo)('HubSpot/cms-react', dest, {
193
+ sourceDir: `default-react-modules/src/components/modules/${name}`,
194
+ });
182
195
  }
183
196
  exports.retrieveDefaultModule = retrieveDefaultModule;
184
197
  const MODULE_HTML_EXTENSION_REGEX = new RegExp(/\.module(?:\/|\\)module\.html$/);
@@ -60,7 +60,9 @@ async function createTemplate(name, dest, type = 'page-template', options = { al
60
60
  logger_1.logger.log((0, lang_1.i18n)(`${i18nKey}.createTemplate.creatingFile`, {
61
61
  path: filePath,
62
62
  }));
63
- await (0, github_1.downloadGithubRepoContents)('HubSpot/cms-sample-assets', assetPath, filePath);
63
+ await (0, github_1.cloneGithubRepo)('HubSpot/cms-sample-assets', filePath, {
64
+ sourceDir: assetPath,
65
+ });
64
66
  }
65
67
  exports.createTemplate = createTemplate;
66
68
  exports.TEMPLATE_TYPES = {
package/lib/github.d.ts CHANGED
@@ -4,5 +4,9 @@ export declare function fetchFileFromRepository<T = Buffer>(repoPath: RepoPath,
4
4
  export declare function fetchReleaseData(repoPath: RepoPath, tag?: string): Promise<GithubReleaseData>;
5
5
  export declare function cloneGithubRepo(repoPath: RepoPath, dest: string, options?: CloneGithubRepoOptions): Promise<boolean>;
6
6
  export declare function fetchGitHubRepoContentFromDownloadUrl(dest: string, downloadUrl: string): Promise<void>;
7
+ /**
8
+ * Writes files from a public repository to the destination folder
9
+ @deprecated - This method fetches all the files individually, which can hit rate limits for unauthorized requests. Use `cloneGithubRepo` instead.
10
+ */
7
11
  export declare function downloadGithubRepoContents(repoPath: RepoPath, contentPath: string, dest: string, ref?: string, filter?: (contentPiecePath: string, downloadPath: string) => boolean): Promise<void>;
8
12
  export declare function listGithubRepoContents(repoPath: RepoPath, contentPath: string, fileFilter?: 'file' | 'dir'): Promise<GithubRepoFile[]>;
package/lib/github.js CHANGED
@@ -104,7 +104,10 @@ async function fetchGitHubRepoContentFromDownloadUrl(dest, downloadUrl) {
104
104
  fs_extra_1.default.outputFileSync(dest, fileContents);
105
105
  }
106
106
  exports.fetchGitHubRepoContentFromDownloadUrl = fetchGitHubRepoContentFromDownloadUrl;
107
- // Writes files from a public repository to the destination folder
107
+ /**
108
+ * Writes files from a public repository to the destination folder
109
+ @deprecated - This method fetches all the files individually, which can hit rate limits for unauthorized requests. Use `cloneGithubRepo` instead.
110
+ */
108
111
  async function downloadGithubRepoContents(repoPath, contentPath, dest, ref, filter) {
109
112
  fs_extra_1.default.ensureDirSync(path_1.default.dirname(dest));
110
113
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hubspot/local-dev-lib",
3
- "version": "3.1.2",
3
+ "version": "3.1.3-beta.0",
4
4
  "description": "Provides library functionality for HubSpot local development tooling, including the HubSpot CLI",
5
5
  "main": "lib/index.js",
6
6
  "repository": {