Skip to content

Commit 7389baa

Browse files
Merge pull request #632 from HubSpot/support-project-compatible-theme-boilerplate
Support Projects-compatible theme boilerplate
2 parents f365463 + fe42874 commit 7389baa

File tree

3 files changed

+31
-6
lines changed

3 files changed

+31
-6
lines changed

packages/cli-lib/projects.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,16 @@ async function fetchReleaseData(repoName, tag = '') {
5757
async function downloadProject(
5858
repoName,
5959
tag = '',
60-
releaseType = GITHUB_RELEASE_TYPES.RELEASE
60+
releaseType = GITHUB_RELEASE_TYPES.RELEASE,
61+
ref
6162
) {
6263
try {
6364
let zipUrl;
6465
if (releaseType === GITHUB_RELEASE_TYPES.REPOSITORY) {
6566
logger.log(`Fetching ${releaseType} with name ${repoName}...`);
66-
zipUrl = `https://api.github.com/repos/HubSpot/${repoName}/zipball`;
67+
zipUrl = `https://api.github.com/repos/HubSpot/${repoName}/zipball${
68+
ref ? `/${ref}` : ''
69+
}`;
6770
} else {
6871
const releaseData = await fetchReleaseData(repoName, tag);
6972
if (!releaseData) return;
@@ -180,9 +183,9 @@ function cleanupTemp(tmpDir) {
180183
* @returns {Boolean} `true` if successful, `false` otherwise.
181184
*/
182185
async function createProject(dest, type, repoName, sourceDir, options = {}) {
183-
const { themeVersion, projectVersion, releaseType } = options;
186+
const { themeVersion, projectVersion, releaseType, ref } = options;
184187
const tag = projectVersion || themeVersion;
185-
const zip = await downloadProject(repoName, tag, releaseType);
188+
const zip = await downloadProject(repoName, tag, releaseType, ref);
186189
if (!zip) return false;
187190
const { extractDir, tmpDir } = (await extractProjectZip(repoName, zip)) || {};
188191
const success =
Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,19 @@
11
const { createProject } = require('@hubspot/cli-lib/projects');
2+
const { GITHUB_RELEASE_TYPES } = require('@hubspot/cli-lib/lib/constants');
3+
const { getIsInProject } = require('../../lib/projects');
4+
5+
const PROJECT_BOILERPLATE_REF = 'cms-boilerplate-developer-projects';
26

37
module.exports = {
48
dest: ({ name, assetType }) => name || assetType,
5-
execute: ({ dest, assetType, options }) => {
9+
execute: async ({ dest, assetType, options }) => {
10+
const isInProject = await getIsInProject(dest);
11+
12+
if (isInProject) {
13+
options.ref = PROJECT_BOILERPLATE_REF;
14+
// releaseType has to be 'REPOSITORY' to download a specific branch
15+
options.releaseType = GITHUB_RELEASE_TYPES.REPOSITORY;
16+
}
617
createProject(dest, assetType, 'cms-theme-boilerplate', 'src', options);
718
},
819
};

packages/cli/lib/projects.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,24 @@ const writeProjectConfig = (configPath, config) => {
6969
}
7070
};
7171

72-
const getProjectConfig = async _dir => {
72+
const getIsInProject = async _dir => {
73+
const configPath = await getProjectConfigPath(_dir);
74+
return !!configPath;
75+
};
76+
77+
const getProjectConfigPath = async _dir => {
7378
const projectDir = _dir ? path.resolve(getCwd(), _dir) : getCwd();
7479

7580
const configPath = findup(PROJECT_CONFIG_FILE, {
7681
cwd: projectDir,
7782
nocase: true,
7883
});
7984

85+
return configPath;
86+
};
87+
88+
const getProjectConfig = async _dir => {
89+
const configPath = await getProjectConfigPath(_dir);
8090
if (!configPath) {
8191
return { projectConfig: null, projectDir: null };
8292
}
@@ -381,6 +391,7 @@ const makeGetTaskStatus = taskType => {
381391
module.exports = {
382392
writeProjectConfig,
383393
getProjectConfig,
394+
getIsInProject,
384395
createProjectConfig,
385396
validateProjectConfig,
386397
showWelcomeMessage,

0 commit comments

Comments
 (0)