diff --git a/packages/cli-lib/projects.js b/packages/cli-lib/projects.js index b417c9815..cad1fef11 100644 --- a/packages/cli-lib/projects.js +++ b/packages/cli-lib/projects.js @@ -57,13 +57,16 @@ async function fetchReleaseData(repoName, tag = '') { async function downloadProject( repoName, tag = '', - releaseType = GITHUB_RELEASE_TYPES.RELEASE + releaseType = GITHUB_RELEASE_TYPES.RELEASE, + ref ) { try { let zipUrl; if (releaseType === GITHUB_RELEASE_TYPES.REPOSITORY) { logger.log(`Fetching ${releaseType} with name ${repoName}...`); - zipUrl = `https://api.github.com/repos/HubSpot/${repoName}/zipball`; + zipUrl = `https://api.github.com/repos/HubSpot/${repoName}/zipball${ + ref ? `/${ref}` : '' + }`; } else { const releaseData = await fetchReleaseData(repoName, tag); if (!releaseData) return; @@ -180,9 +183,9 @@ function cleanupTemp(tmpDir) { * @returns {Boolean} `true` if successful, `false` otherwise. */ async function createProject(dest, type, repoName, sourceDir, options = {}) { - const { themeVersion, projectVersion, releaseType } = options; + const { themeVersion, projectVersion, releaseType, ref } = options; const tag = projectVersion || themeVersion; - const zip = await downloadProject(repoName, tag, releaseType); + const zip = await downloadProject(repoName, tag, releaseType, ref); if (!zip) return false; const { extractDir, tmpDir } = (await extractProjectZip(repoName, zip)) || {}; const success = diff --git a/packages/cli/commands/create/website-theme.js b/packages/cli/commands/create/website-theme.js index 7b084e054..6b005da8a 100644 --- a/packages/cli/commands/create/website-theme.js +++ b/packages/cli/commands/create/website-theme.js @@ -1,8 +1,19 @@ const { createProject } = require('@hubspot/cli-lib/projects'); +const { GITHUB_RELEASE_TYPES } = require('@hubspot/cli-lib/lib/constants'); +const { getIsInProject } = require('../../lib/projects'); + +const PROJECT_BOILERPLATE_REF = 'cms-boilerplate-developer-projects'; module.exports = { dest: ({ name, assetType }) => name || assetType, - execute: ({ dest, assetType, options }) => { + execute: async ({ dest, assetType, options }) => { + const isInProject = await getIsInProject(dest); + + if (isInProject) { + options.ref = PROJECT_BOILERPLATE_REF; + // releaseType has to be 'REPOSITORY' to download a specific branch + options.releaseType = GITHUB_RELEASE_TYPES.REPOSITORY; + } createProject(dest, assetType, 'cms-theme-boilerplate', 'src', options); }, }; diff --git a/packages/cli/lib/projects.js b/packages/cli/lib/projects.js index b8a65767c..0ad9ba4d5 100644 --- a/packages/cli/lib/projects.js +++ b/packages/cli/lib/projects.js @@ -69,7 +69,12 @@ const writeProjectConfig = (configPath, config) => { } }; -const getProjectConfig = async _dir => { +const getIsInProject = async _dir => { + const configPath = await getProjectConfigPath(_dir); + return !!configPath; +}; + +const getProjectConfigPath = async _dir => { const projectDir = _dir ? path.resolve(getCwd(), _dir) : getCwd(); const configPath = findup(PROJECT_CONFIG_FILE, { @@ -77,6 +82,11 @@ const getProjectConfig = async _dir => { nocase: true, }); + return configPath; +}; + +const getProjectConfig = async _dir => { + const configPath = await getProjectConfigPath(_dir); if (!configPath) { return { projectConfig: null, projectDir: null }; } @@ -381,6 +391,7 @@ const makeGetTaskStatus = taskType => { module.exports = { writeProjectConfig, getProjectConfig, + getIsInProject, createProjectConfig, validateProjectConfig, showWelcomeMessage,