cryptocom-react-cli
Version:
It's a quick tool to help you build a react project with one command
42 lines (38 loc) • 1.32 kB
JavaScript
#!usr/bin/env node
import chalk from 'chalk'
import fs from 'fs'
import shell from 'shelljs'
import config from './config.js'
import download from 'download-git-repo'
import ora from 'ora'
import path from 'path'
/**
* 下载包
* @param {string} dirPath destination path is a absolute path
* @param {string} githubUrl the download github address
*/
export function getGitDemoPackages(dirPath, githubUrl) {
const spinner = ora('Init project...\n').start();
return new Promise((resolve, reject) => {
const downloadUrl = githubUrl || config.reactCliTplStoreNameForGithub
if (!fs.existsSync(dirPath)) {
fs.mkdirSync(dirPath);
}
if (shell.which('git')) {
download(downloadUrl, dirPath, {clone: true}, function(err) {
if (err) {
console.log(chalk.red(err))
spinner.fail('Download template failed.')
reject(new Error(err))
} else {
spinner.succeed('Downloaded template.')
resolve();
}
});
} else {
spinner.fail('Download template failed.')
console.log(chalk.yellow('please install git '))
reject(new Error('pease install git '));
}
});
}