import download from 'download-git-repo'; import path from 'path'; import { IPromptOption } from '@/assets/inquirer'; import RepositoryList from '@/assets/repository'; import { privateClone } from './privateClone'; function downloadTemplate(options: IPromptOption): Promise { return new Promise((resolve) => { const CURRENT_PATH = process.cwd(); const { projectName, templateName, repositoryUrl } = options; const targetPath = path.resolve(CURRENT_PATH, projectName); const rpUrl = repositoryUrl ? `direct:${repositoryUrl}` : (>RepositoryList)[templateName]; download(rpUrl, targetPath, {clone: true}, (err) => { if (err) { console.log(err); resolve(false); } resolve(true); }); }); } export { privateClone, downloadTemplate };