Skip to content

Support Projects-compatible theme boilerplate #632

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions packages/cli-lib/projects.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 =
Expand Down
13 changes: 12 additions & 1 deletion packages/cli/commands/create/website-theme.js
Original file line number Diff line number Diff line change
@@ -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);
},
};
13 changes: 12 additions & 1 deletion packages/cli/lib/projects.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,24 @@ const writeProjectConfig = (configPath, config) => {
}
};

const getProjectConfig = async _dir => {
const getIsInProject = async _dir => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

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, {
cwd: projectDir,
nocase: true,
});

return configPath;
};

const getProjectConfig = async _dir => {
const configPath = await getProjectConfigPath(_dir);
if (!configPath) {
return { projectConfig: null, projectDir: null };
}
Expand Down Expand Up @@ -381,6 +391,7 @@ const makeGetTaskStatus = taskType => {
module.exports = {
writeProjectConfig,
getProjectConfig,
getIsInProject,
createProjectConfig,
validateProjectConfig,
showWelcomeMessage,
Expand Down