UNPKG

piral-cli

Version:

The standard CLI for creating and building a Piral instance or a Pilet.

146 lines • 6.85 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.publishPiralDefaults = void 0; exports.publishPiral = publishPiral; const path_1 = require("path"); const types_1 = require("../types"); const common_1 = require("../common"); exports.publishPiralDefaults = { source: './dist', logLevel: types_1.LogLevels.info, url: undefined, interactive: false, apiKey: undefined, fresh: false, mode: 'basic', headers: {}, type: 'emulator', cert: undefined, allowSelfSigned: common_1.config.allowSelfSigned, }; async function publishPiral(baseDir = process.cwd(), options = {}) { const { source = exports.publishPiralDefaults.source, logLevel = exports.publishPiralDefaults.logLevel, interactive = exports.publishPiralDefaults.interactive, fresh = exports.publishPiralDefaults.fresh, url = common_1.config.url ?? exports.publishPiralDefaults.url, apiKey = common_1.config.apiKeys?.[url] ?? common_1.config.apiKey ?? exports.publishPiralDefaults.apiKey, headers = exports.publishPiralDefaults.headers, mode = exports.publishPiralDefaults.mode, type = exports.publishPiralDefaults.type, cert = exports.publishPiralDefaults.cert, allowSelfSigned = exports.publishPiralDefaults.allowSelfSigned, _ = {}, hooks = {}, bundlerName, } = options; (0, common_1.ensure)('baseDir', baseDir, 'string'); (0, common_1.ensure)('headers', headers, 'object'); (0, common_1.ensure)('_', _, 'object'); (0, common_1.ensure)('hooks', hooks, 'object'); const fullBase = (0, path_1.resolve)(process.cwd(), baseDir); (0, common_1.setLogLevel)(logLevel); (0, common_1.progress)('Reading configuration ...'); if (!url) { (0, common_1.fail)('missingPiletFeedUrl_0060'); } const ca = await (0, common_1.getCertificate)(cert); const agent = (0, common_1.getAgent)({ ca, allowSelfSigned }); (0, common_1.log)('generalDebug_0003', 'Getting the files ...'); const entryFiles = await (0, common_1.retrievePiralRoot)(fullBase, './'); const { name, root, ignored, externals, scripts, emulator = common_1.emulatorPackageName, } = await (0, common_1.retrievePiletsInfo)(entryFiles); if (type === 'emulator' && ![common_1.emulatorPackageName, common_1.emulatorWebsiteName].includes(emulator)) { (0, common_1.fail)('generalError_0002', `The emulator type "${emulator}" is not supported. Select one of these types to use the publish command: "${common_1.emulatorWebsiteName}", "${common_1.emulatorPackageName}".`); } const dir = type === 'release' ? common_1.releaseName : common_1.emulatorName; const targetDir = (0, path_1.resolve)(fullBase, source, dir); if (fresh) { const piralInstances = [name]; (0, common_1.validateSharedDependencies)(externals); if (type === 'release') { await (0, common_1.triggerBuildShell)({ targetDir, logLevel, bundlerName, contentHash: true, externals, ignored, minify: true, optimizeModules: false, publicUrl: '/', outFile: 'index.html', root, sourceMaps: true, watch: false, hooks, entryFiles, piralInstances, scripts, _, }); } else { await (0, common_1.triggerBuildEmulator)({ root, logLevel, bundlerName, emulatorType: emulator, hooks, targetDir, ignored, externals, entryFiles, piralInstances, optimizeModules: true, sourceMaps: true, watch: false, scripts, contentHash: true, outFile: 'index.html', _, }); } (0, common_1.logReset)(); } if (type === 'release') { const { version } = await (0, common_1.readJson)(root, common_1.packageJson); (0, common_1.log)('generalInfo_0000', `Using feed service "${url}".`); const files = await (0, common_1.matchFiles)(targetDir, '**/*'); (0, common_1.progress)(`Publishing release artifacts to "%s" ...`, url); const result = await (0, common_1.publishWebsiteEmulator)(version, url, apiKey, mode, targetDir, files, interactive, headers, agent); if (!result.success) { (0, common_1.fail)('failedUploading_0064'); } if (result.response) { (0, common_1.log)('httpPostResponse_0067', result); } (0, common_1.progress)(`Published successfully!`); (0, common_1.logDone)(`Release artifacts published successfully!`); } else if (emulator === common_1.emulatorWebsiteName) { const { version } = await (0, common_1.readJson)(targetDir, common_1.emulatorJson); if (!version) { (0, common_1.fail)('missingEmulatorWebsite_0130', targetDir); } (0, common_1.log)('generalInfo_0000', `Using feed service "${url}".`); const files = await (0, common_1.matchFiles)(targetDir, '**/*'); (0, common_1.progress)(`Publishing emulator to "%s" ...`, url); const result = await (0, common_1.publishWebsiteEmulator)(version, url, apiKey, mode, targetDir, files, interactive, headers, agent); if (!result.success) { (0, common_1.fail)('failedUploading_0064'); } if (result.response) { (0, common_1.log)('httpPostResponse_0067', result); } (0, common_1.progress)(`Published successfully!`); (0, common_1.logDone)(`Emulator published successfully!`); } else if (emulator === common_1.emulatorPackageName) { (0, common_1.log)('generalInfo_0000', `Using npm registry "${url}".`); const files = await (0, common_1.matchFiles)(targetDir, '*.tgz'); (0, common_1.log)('generalDebug_0003', `Found ${files.length} in "${targetDir}": ${files.join(', ')}`); const file = files[0]; if (!file) { (0, common_1.fail)('publishEmulatorFilesUnexpected_0111', targetDir); } (0, common_1.progress)(`Publishing emulator to "%s" ...`, url); try { await (0, common_1.publishPackageEmulator)(targetDir, file, url, interactive, apiKey); (0, common_1.progress)(`Published successfully!`); } catch { (0, common_1.fail)('failedUploading_0064'); } (0, common_1.logDone)(`Emulator published successfully!`); } else { // we should not enter here - anyway let's do nothing } } //# sourceMappingURL=publish-piral.js.map