-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
47 lines (40 loc) · 1.48 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
#!/usr/bin/env node
import inquirer from 'inquirer';
import ora from 'ora';
import download from 'download-git-repo'
const templateOptions = {
comprehensive: {
gitHubRepository: 'chrome-extension-template',
displayName: 'Comprehensive Chrome Extension (approx. 496 KB)'
},
simple: {
gitHubRepository: 'simple-chrome-extension-template',
displayName: 'Simple Chrome Extension (approx. 12.0 KB)'
},
};
const spinner = ora('Downloading...');
const promptQuestions = [
{
name: 'template-choice',
type: 'list',
message: 'What extension template would you like to generate?',
choices: [templateOptions.comprehensive.displayName, templateOptions.simple.displayName]
}
];
inquirer.prompt(promptQuestions)
.then(answers => {
if (answers['template-choice'] === templateOptions.comprehensive.displayName) {
downloadRepository(templateOptions.comprehensive.gitHubRepository);
} else {
downloadRepository(templateOptions.simple.gitHubRepository);
}
}).catch((e) => {
spinner.fail('Download failed due to - ' + e);
});
const downloadRepository = (repository) => {
spinner.start();
const fileExclusionFilter = { filter: file => file.path.indexOf("docs") < 0 };
download(`clydedz/${repository}`, './', fileExclusionFilter, function (err) {
err ? spinner.fail('Download failed. Please try again later.') : spinner.succeed('Template generated!');
});
}