UNPKG

@applicaster/zapplicaster-cli

Version:

CLI Tool for the zapp app and Quick Brick project

50 lines (42 loc) 1.27 kB
const { runInShellAsync } = require("../../shell"); const { isPackagePublished } = require("./isPackagePublished"); const { wait } = require("./wait"); const logger = require("../../logger"); const { isErrorAlreadyPublished } = require("./index"); const { PUBLISH_RETRY_ATTEMPTS, RE_TRY_MESSAGE, RE_TRY_TIMER, } = require("../const"); const retryPublishCommand = async (publishCommand, cmdOptions, version) => { for (let i = 0; i < PUBLISH_RETRY_ATTEMPTS; i++) { if (i !== 0) { logger.warn(RE_TRY_MESSAGE); await wait(RE_TRY_TIMER); const isPublished = await isPackagePublished(version); if (isPublished) { logger.warn(`version: ${version} is already published. Skipping...`); break; } else { logger.log(`version: ${version} is not published yet. Re-trying...`); } } try { logger.log(`running command ${publishCommand}`); await runInShellAsync(publishCommand, cmdOptions); break; } catch (e) { if (isErrorAlreadyPublished(e)) { logger.log("Package already published, continue..."); break; } if (i === PUBLISH_RETRY_ATTEMPTS - 1) { throw e; } } } return true; }; module.exports = { retryPublishCommand, };