-
Notifications
You must be signed in to change notification settings - Fork 30
/
index.js
54 lines (47 loc) · 1.26 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
import ghUser from 'github-current-user';
import prompt from 'prompt';
import chalk from 'chalk';
import ncp from 'ncp';
import path from 'path';
console.log(chalk.blue('Creating user exercise folder...'));
const getUsername = () => {
const username = ghUser.current((err, username) => {
if (err || !username) {
return 'unknown';
}
return username;
});
return username;
};
const createUserCopy = ({ username }) => {
ncp(path.resolve('./exercises'), username, function (err) {
if (err) {
console.log(chalk.red('Unable to create user specific copy.'));
return console.log(err);
}
console.log(chalk.blue(`Your personal copy of the exercises in a newly created folder(${username}).`));
});
}
const run = async() => {
const username = await getUsername();
const schema = {
properties: {
username: {
default: username,
pattern: /^[A-Za-z0-9_-]{3,15}$/,
message: 'Name must be only letters, numbers, underscores, or dashes',
},
},
};
prompt.start();
prompt.get(schema, (err, results) => {
if (err) {
console.log(chalk.red('Failed to determine folder to create.'));
console.log(err);
process.exit(1);
return 1;
}
createUserCopy(results);
});
};
run();