UNPKG

j-2024-cli

Version:

一个mini版的脚手架

49 lines (44 loc) 1.54 kB
const axios = require('axios'); const { exec } = require("child_process"); const util = require("util"); // node中的内置模块 const { wrapLoading } = require("./loading.js"); const { rm } = require("fs/promises");; const { getAllConfig } = require("../commands/config.js"); const execPromisified = util.promisify(exec); const { organization, accessToken } = getAllConfig().config; async function getOrganizationProjects() { const res = await axios.get( `https://gitee.com/api/v5/orgs/${organization}/repos`, { headers: { Authorization: `Bearer ${accessToken}`, }, } ); return res.data.map((item) => item.name); } async function getProjectVersions(repo) { console.log('getProjectVersions:', `https://gitee.com/api/v5/repos/${organization}/${repo}/tags`) const res = await axios.get( `https://gitee.com/api/v5/repos/${organization}/${repo}/tags`, { headers: { Authorization: `Bearer ${accessToken}`, }, } ); return res.data.map((item) => item.name); } async function cloneAndCheckoutTag(tag, projectName, repo) { const cmd = `git clone --branch ${tag} --depth 1 https://gitee.com/${organization}/${projectName}.git ${repo}`; console.log('cloneAndCheckoutTag:', cmd) return wrapLoading("create project", async () => { await execPromisified(cmd); return rm(`${repo}/.git`, { recursive: true }); }); } module.exports = { getOrganizationProjects, getProjectVersions, cloneAndCheckoutTag }