UNPKG

@modyo/cli

Version:

Modyo CLI Command line to expose local development tools

38 lines (37 loc) 1.85 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const tslib_1 = require("tslib"); const path = tslib_1.__importStar(require("node:path")); const node_util_1 = require("node:util"); const stream = tslib_1.__importStar(require("node:stream")); const fs_extra_1 = require("fs-extra"); const core_1 = require("@oclif/core"); const debug_1 = tslib_1.__importDefault(require("debug")); const axios_1 = tslib_1.__importDefault(require("axios")); const github_api_client_1 = tslib_1.__importDefault(require("../utils/github-api-client")); const streamPipeline = (0, node_util_1.promisify)(stream.pipeline); const debug = (0, debug_1.default)('get/getting-template.ts'); async function gettingTemplate({ organization, templateName, templateVersion, tempDirectory, }) { var _a; try { const ref = templateVersion === 'latest' ? 'master' : templateVersion; const url = `https://api.github.com/repos/${organization}/${templateName}/zipball/${ref}`; debug(`fetching zip from ${url}`); const response = await github_api_client_1.default.get(url, { responseType: 'stream' }); const templateZipPath = path.resolve(tempDirectory.path, 'template.zip'); debug(`setting zipPath ${templateZipPath}`); core_1.ux.action.start('Downloading resources'); debug('starting download'); await streamPipeline(response.data, (0, fs_extra_1.createWriteStream)(templateZipPath)); core_1.ux.action.stop(); debug(`zip downloaded in ${templateZipPath}`); return templateZipPath; } catch (error) { if (axios_1.default.isAxiosError(error)) { throw new Error(`unexpected response ${(_a = error.response) === null || _a === void 0 ? void 0 : _a.statusText}`); } throw error; } } exports.default = gettingTemplate;