Skip to content

Commit

Permalink
refactor based on feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
cjtantay committed Jul 16, 2024
1 parent 672d00e commit be73372
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 11,412 deletions.
10 changes: 5 additions & 5 deletions lib/blocks/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export function createScriptBlock(pathPrefix, source) {
if (shouldPreload) {
preloads.forEach((preload) => {
output.push(
`<link rel="preload" href="${determineOutput(
`<link rel="preload" href="${getStaticAssetAbsolutePath(
pathSrc,
preload
)}" as="script" crossorigin>`
Expand All @@ -41,20 +41,20 @@ export function createScriptBlock(pathPrefix, source) {

if (cssEntry) {
output.push(
`<link rel="stylesheet" href="${determineOutput(pathSrc, cssEntry)}">`
`<link rel="stylesheet" href="${getStaticAssetAbsolutePath(pathSrc, cssEntry)}">`
);
}

output.push(
`<script type="module" src="${determineOutput(
`<script type="module" src="${getStaticAssetAbsolutePath(
pathSrc,
modernEntry
)}"></script>`
);

if ('legacy' in manifest) {
output.push(
`<script nomodule defer src="${determineOutput(
`<script nomodule defer src="${getStaticAssetAbsolutePath(
pathSrc,
legacy[entry]
)}"></script>`
Expand All @@ -72,7 +72,7 @@ export function createScriptBlock(pathPrefix, source) {
* @param {string} srcType
* @returns {string}
*/
function determineOutput(pathSrc, srcType) {
function getStaticAssetAbsolutePath(pathSrc, srcType) {
if (
isProductionEnv &&
process.env.BAKER_BASE_PATH &&
Expand Down
11 changes: 6 additions & 5 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { premove } from 'premove';
import glob from 'fast-glob';
import fetch from 'node-fetch';
import path from 'node:path';
import { v4 as uuidv4 } from 'uuid';

// local
import { isProductionEnv } from './env.js';
Expand Down Expand Up @@ -324,10 +325,10 @@ export class Baker extends EventEmitter {
}

/**
* Sends a webhook to notify of build completion
* Sends a successful build notification to the currently defined webhook url
* @returns {Promise<void>}
*/
async sendWebhook() {
async sendWebhookRequest() {
if (!process.env.BUILD_NOTIFICATION_WEBHOOK_URL) return;

const files = await glob(join(this.embeds, '*.html'));
Expand All @@ -339,7 +340,7 @@ export class Baker extends EventEmitter {

const payload = {
data: {
id: Date.now(),
id: uuidv4(),
objType: 'baker-project',
attributes: {
projectSlug,
Expand All @@ -348,7 +349,7 @@ export class Baker extends EventEmitter {
},
};

await fetch(process.env.BUILD_NOTIFICATION_WEBHOOK_URL, {
fetch(process.env.BUILD_NOTIFICATION_WEBHOOK_URL, {
method: 'post',
body: JSON.stringify(payload),
headers: { 'Content-Type': 'application/json' },
Expand Down Expand Up @@ -573,7 +574,7 @@ export class Baker extends EventEmitter {
await this.nunjucks.build();

// send webhook to notify of build completion
await this.sendWebhook();
await this.sendWebhookRequest();

// emit event that a bake has completed
this.emit('bake:end');
Expand Down
Loading

0 comments on commit be73372

Please sign in to comment.