UNPKG

@modyo/cli

Version:

Modyo CLI Command line to expose local development tools

40 lines (39 loc) 1.57 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const tslib_1 = require("tslib"); /* eslint-disable functional/immutable-data */ const core_1 = require("@oclif/core"); const debug_1 = tslib_1.__importDefault(require("debug")); const open_1 = tslib_1.__importDefault(require("open")); const debugError = (0, debug_1.default)('error::get/get-modyo-site-id.ts'); async function openPreview(accountUrl, siteHost, port, domId, entryJs) { try { const url = new URL(`${accountUrl}/${siteHost}/preview/local_widget`); url.search = new URLSearchParams({ port, dom_id: domId, entry_js: entryJs, }).toString(); core_1.ux.action.start(`Previewing widget at ${url}`); try { await (0, open_1.default)(url.toString()); core_1.ux.action.stop(); } catch (openError) { core_1.ux.action.stop('failed'); // Fallback: show URL for manual copying // eslint-disable-next-line no-console console.log('\nUnable to open browser automatically.'); // eslint-disable-next-line no-console console.log('Please open this URL manually:'); // eslint-disable-next-line no-console console.log(`${url.toString()}\n`); debugError(`Browser launch failed: ${openError instanceof Error ? openError.message : String(openError)}`); } } catch (error) { debugError(error); throw error; } } exports.default = openPreview;