-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
executable file
·54 lines (47 loc) · 1.44 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#! /usr/bin/env node
const info = console.info;
const ora = require('ora');
const path = require('path');
const pg = require('./package');
const colors = require('colors');
const figlet = require('figlet');
const shell = require('shelljs');
const inquirer = require('inquirer');
const download = require('download-git-repo');
// const commander = require('commander');
// Output the project name
const name = figlet.textSync(pg.name.toUpperCase());
info(colors.green(name));
// Setting commander
// commander
// .version(pg.version)
// .option('-i, --init', 'init project')
// .parse(process.argv);
inquirer.prompt([
{
type: 'text',
name: 'directory',
message: 'Please input your directory'
}
]).then(answers => {
const { directory } = answers;
const pwdDir = shell.pwd().stdout;
// Setting download directory of the project
const projectPath = path.join(pwdDir, directory);
shell.rm('-rf', projectPath);
shell.mkdir(projectPath);
const remoteSourceName = pg.resource.fullStack.name;
const remoteSourceUrl = pg.resource.fullStack.url;
const spinner = ora(`Download ${remoteSourceName}...\n`);
spinner.start();
// Start to download remote source code
download(`direct:${remoteSourceUrl}`, projectPath, { clone: true }, err => {
if (err) {
info(err);
process.exit(1);
}
spinner.succeed(`The ${remoteSourceName} is downloaded successfully`);
});
}).catch(err => {
info('fail start', err);
});