Skip to content

Commit

Permalink
feat(up): check if the site is on helix 5, and use aem.page as previe…
Browse files Browse the repository at this point in the history
…w host if that's the case
  • Loading branch information
trieloff committed Jan 12, 2024
1 parent 27b8fdc commit adc2837
Showing 1 changed file with 30 additions and 2 deletions.
32 changes: 30 additions & 2 deletions src/up.cmd.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,39 @@ export default class UpCommand extends AbstractServerCommand {
}

async verifyUrl(gitUrl, inref) {
// check if the site is on helix5
// https://admin.hlx.page/sidekick/adobe/www-aem-live/main/config.json
// {
// "host": "aem.live",
// "liveHost": "main--www-aem-live--adobe.aem.live",
// "plugins": [
// {
// "id": "doc",
// "title": "Documentation",
// "url": "https://www.aem.live/docs/"
// }
// ],
// "previewHost": "main--www-aem-live--adobe.aem.page",
// "project": "Helix Website (AEM Live)",
// "testProperty": "header";
// }
const configUrl = `https://admin.hlx.page/sidekick/${gitUrl.repo}/${gitUrl.owner}/${inref}/config.json`;
const configResp = await getFetch()(configUrl);
let previewHostBase = 'hlx.page';
if (configResp.ok) {
// this is best effort for now
const config = await configResp.json();
const { previewHost } = config;
if (previewHost && previewHost.endsWith('.aem.page')) {
previewHostBase = 'aem.page';
}
}

let ref = inref;

// replace `/` by `-` in ref.
ref = ref.replace(/\//g, '-');
this._url = `https://${ref}--${gitUrl.repo}--${gitUrl.owner}.hlx.page`;
this._url = `https://${ref}--${gitUrl.repo}--${gitUrl.owner}.${previewHostBase}`;
// check length limit
if (this._url.split('.')
.map((part) => part.replace(/^https:\/\//, ''))
Expand All @@ -125,7 +153,7 @@ export default class UpCommand extends AbstractServerCommand {
this.log.warn(chalk`Unable to verify {yellow main} branch via {blue ${fstabUrl}} (${resp.status}). Maybe not pushed yet?`);
} else {
this.log.warn(chalk`Unable to verify {yellow ${ref}} branch on {blue ${fstabUrl}} (${resp.status}). Fallback to {yellow main} branch.`);
this._url = `https://main--${gitUrl.repo}--${gitUrl.owner}.hlx.page`;
this._url = `https://main--${gitUrl.repo}--${gitUrl.owner}.${previewHostBase}`;
}
}
}
Expand Down

0 comments on commit adc2837

Please sign in to comment.