@commercetools/frontend-netlify-plugin
Advanced tools
Comparing version 0.0.2 to 0.0.3
{ | ||
"name": "@commercetools/frontend-netlify-plugin", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"description": "Netlify Build plugin - Commercetools Frontend build extension", | ||
@@ -5,0 +5,0 @@ "type": "module", |
import * as dotenv from 'dotenv' | ||
import * as fs from 'fs' | ||
import fetch from 'node-fetch' | ||
import { waitForBackend } from "./backend-check.js"; | ||
@@ -50,61 +50,1 @@ dotenv.config() | ||
} | ||
/* | ||
* Checks if the backend is ready | ||
* Does an HTTP request to the appropriate extension runner | ||
*/ | ||
export const checkBackend = async (version, path) => { | ||
console.log('Calling ' + path, 'Version ' + version) | ||
const actualInit = { | ||
headers: { | ||
'Content-Type': 'application/json', | ||
Accept: 'application/json', | ||
'Commercetools-Frontend-Extension-Version': version, | ||
}, | ||
} | ||
try { | ||
const response = await fetch(path, actualInit) | ||
if (response) { | ||
return await response.json() | ||
} | ||
} catch (e) { | ||
console.log(`Error while calling extension runner ${path}:`, e) | ||
} | ||
return { up: false } | ||
} | ||
/** | ||
* Waits for the backend extension to be ready. | ||
* Will attempt the number of tries passed on the maxTries parameter. | ||
* If the extension is not up after the maxTries an error is thrown. | ||
* | ||
* @param shortCommitHash the extension version | ||
* @param maxTries the max number of attempts | ||
* @param path the path to be tested | ||
* @returns {Promise<void>} | ||
*/ | ||
export const waitForBackend = async (shortCommitHash, maxTries, path) => { | ||
for (let i = 0; i < maxTries; i++) { | ||
const attempt = i + 1 | ||
console.log('Checking if extension is up, attempt: ', attempt) | ||
const { up } = await checkBackend(shortCommitHash, path) | ||
if (!up) { | ||
console.error( | ||
'Extension is not available, waiting for', | ||
attempt, | ||
'seconds', | ||
) | ||
await sleep(i * 1000) | ||
} else { | ||
console.log('Extension is up!') | ||
return | ||
} | ||
} | ||
throw new Error('Extension is not up') | ||
} | ||
export const sleep = (ms) => { | ||
return new Promise((resolve) => setTimeout(resolve, ms)) | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
5219
5
98