UNPKG

843 BJavaScriptView Raw
1const T = require('../lib/tools'),
2 downloader = require('download-github-repo'),
3 userHome = require('user-home'),
4 LoadingORA = require('../lib/loadProgress').LoadingORA;
5
6function downloadTemplateRepo(template) {
7 let url = template.url;
8 let tempPath = T.Path.resolve(userHome, '.gupack-templates/', url);
9 if (!url) throw Error(T.msg.red('Not found template as github'));
10 const loading = new LoadingORA();
11 loading.start('→ Downloading you selected template, Please wait a moment......');
12
13 return new Promise((resove, reject) => {
14 downloader(url, tempPath, err => {
15 err ? reject({ message: '× Download failed' }) : resove({ message: '√ Download Successfully', tempPath });
16 loading.stop();
17 });
18 });
19}
20
21module.exports = downloadTemplateRepo;