-
Notifications
You must be signed in to change notification settings - Fork 8
/
index.js
32 lines (31 loc) · 871 Bytes
/
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
const chalk = require('chalk');
const DB = require('./lib/db.json');
const {
isGithubCliInstalled,
cloneDbRepository,
convertURL,
isInRepo,
isRepoExist
} = require('./lib/utils');
const URL_REG = /[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)?/gi;
module.exports = function (url, options) {
// check url rule
if (!url.match(URL_REG)) {
console.log(chalk.red('Invalid URL!'));
return;
}
// whether install github cli
if (!isGithubCliInstalled()) {
return;
}
console.log(chalk.cyan('Converting...'));
const { database = DB.db, user = DB.user, pages = DB.pages } = options;
if (isInRepo(database)) {
convertURL(url, pages);
} else if (isRepoExist(database)) {
convertURL(url, pages, database)
} else {
cloneDbRepository(user, database);
convertURL(url, pages, database);
}
}