UNPKG

@kiwicom/orbit-tracking

Version:

Tracking for orbit design system

76 lines (73 loc) 2.17 kB
import { saveToApi } from "./chunk-DJ5Q2GKT.js"; import { queries } from "./chunk-UPI6M7GE.js"; import { mapProjects } from "./chunk-2Z4LJGFM.js"; import { apiRequest } from "./chunk-ACWUZZNH.js"; import { timestamp } from "./chunk-FYZ3OT32.js"; import { projectCmd } from "./chunk-E7RP5HO2.js"; import { errorMessage, infoMessage } from "./chunk-ZXUFWPBJ.js"; import { getOutputPath } from "./chunk-5T6242DN.js"; import { PROJECTS, TMP_FOLDER } from "./chunk-NCG23OMG.js"; // src/fetcher.ts import { fs, path, chalk } from "zx"; import "dotenv/config"; var gitlabApiCall = async ({ ids, folder = "./", outputPath, config }) => { const res = await apiRequest(queries.projectsQuery, { ids }); if (res == null ? void 0 : res.data) { const commands = mapProjects(res.data.projects.nodes, folder); await Promise.all(commands.map((p) => projectCmd(config, p))).then((result) => { if (outputPath) { fs.writeFile(getOutputPath(outputPath, timestamp()), JSON.stringify(result, null, 2), "utf8").then(() => { infoMessage(`Successfully created ${timestamp()}.json file in the ${outputPath}`); }); } else { saveToApi(JSON.stringify(result, null, 2)).then((data) => { infoMessage(`Successfully created MR: ${data == null ? void 0 : data.mergeRequestCreate.mergeRequest.title}`); console.info(chalk.underline.bold.green(`url: ${data == null ? void 0 : data.mergeRequestCreate.mergeRequest.webUrl} \u{1F517}`)); }); } }); } return null; }; async function fetcher({ scope, outputPath, config }) { try { const ids = scope.map((n) => `gid://gitlab/Project/${PROJECTS[n]}`); await gitlabApiCall({ ids, folder: TMP_FOLDER, outputPath, config }); } catch (err) { errorMessage(` ${err}`); } finally { try { if (path.resolve(TMP_FOLDER)) { fs.rmSync(TMP_FOLDER, { recursive: true }); } } catch (e) { errorMessage(`An error has occurred while removing the temp folder at ${TMP_FOLDER}. Please remove it manually. Error: ${e}`); } } } var fetcher_default = fetcher; export { gitlabApiCall, fetcher_default };