fix: allow local builds without git

This commit is contained in:
Sam Potts 2021-07-06 08:12:51 +10:00
parent ba4bdb335a
commit 3a01837561

View File

@ -51,11 +51,19 @@ const paths = {
], ],
}; };
// Get branch info // Get git branch info
const currentBranch = (() => {
try {
return gitbranch.sync();
} catch (_) {
return null;
}
})();
const branch = { const branch = {
current: gitbranch.sync(), current: currentBranch,
master: 'master', isMaster: currentBranch === 'master',
beta: 'beta', isBeta: currentBranch === 'beta',
}; };
const maxAge = 31536000; // 1 year const maxAge = 31536000; // 1 year
@ -66,7 +74,7 @@ const options = {
}, },
}, },
demo: { demo: {
uploadPath: branch.current === branch.beta ? '/beta' : null, uploadPath: branch.isBeta ? '/beta' : null,
headers: { headers: {
'Cache-Control': 'no-cache, no-store, must-revalidate, max-age=0', 'Cache-Control': 'no-cache, no-store, must-revalidate, max-age=0',
}, },
@ -99,11 +107,8 @@ const renameFile = rename((p) => {
// Check we're on the correct branch to deploy // Check we're on the correct branch to deploy
const canDeploy = () => { const canDeploy = () => {
const allowed = [branch.master, branch.beta]; if (![branch.isMaster, branch.isBeta].some(Boolean)) {
console.error(`Must be on an allowed branch to publish! (current: ${branch.current})`);
if (!allowed.includes(branch.current)) {
console.error(`Must be on ${allowed.join(', ')} to publish! (current: ${branch.current})`);
return false; return false;
} }
@ -195,7 +200,7 @@ gulp.task('demo', (done) => {
const error = `${paths.demo}error.html`; const error = `${paths.demo}error.html`;
const pages = [index]; const pages = [index];
if (branch.current === branch.master) { if (branch.isMaster) {
pages.push(error); pages.push(error);
} }
@ -220,7 +225,7 @@ gulp.task('open', () => {
return gulp.src(__filename).pipe( return gulp.src(__filename).pipe(
open({ open({
uri: `https://${domain}/${branch.current === branch.beta ? 'beta' : ''}`, uri: `https://${domain}/${branch.isBeta ? 'beta' : ''}`,
}), }),
); );
}); });