forked from naveennamani/offline-docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cli.js
162 lines (153 loc) · 3.83 KB
/
cli.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
import { closeSync, openSync } from "fs";
import { resolve } from "path";
import inquirer from "inquirer";
import { updateReadMe } from "./scripts/updateReadme.js";
import {
getProjectDetails,
getProjectGroupDetails,
updateProjectDetails,
updateProjectGroupDetails,
} from "./scripts/utils.js";
async function getProjectGroupFromUser() {
const project_groups = getProjectGroupDetails();
const project_group_name = (
await inquirer.prompt({
type: "list",
name: "project_group",
message: "Select a project group",
choices: project_groups.map(({ name }) => name),
})
).project_group;
const project_group_details = project_groups.filter(
({ name }) => name === project_group_name
)[0];
const project_data_file = project_group_details.data_file;
return { project_group_details, project_data_file };
}
async function askNewProjectDetails() {
let answers1 = await inquirer.prompt([
{
name: "name",
message: "Enter website name",
},
{
name: "website",
message: "Enter website URL",
},
{
name: "description",
message: "Enter short description of the project",
},
{
name: "repo",
message: "Enter URL of source code",
},
{
name: "repo_branch",
message: "Enter branch name for the repo",
},
{
type: "confirm",
name: "direct_links_ask",
message: "Do you find any direct URLs for downloading the docs?",
},
]);
let direct_links = [];
if (answers1.direct_links_ask) {
let url_answers = {};
do {
url_answers = await inquirer.prompt([
{
name: "text",
message: "Description of the URL",
},
{
name: "link",
message: "Enter URL",
},
{
type: "confirm",
name: "more_links",
message: "Want to add more URLs?",
},
]);
direct_links.push(url_answers);
} while (url_answers.more_links);
}
let commands = [];
console.log("Enter commands");
let command;
do {
command = await inquirer.prompt({ name: "command", message: ">>>" });
commands.push(command.command);
} while (command.command);
commands.pop();
let answers2 = await inquirer.prompt([
{
name: "output_dir",
message: "Output directory for build files",
},
{
name: "last_tested",
message: "Last tested on",
},
{
name: "note",
message: "Special notes",
},
{
name: "license",
message: "License of the repo",
},
]);
return Object.assign(
{},
answers1,
{ commands },
{
direct_links: direct_links.map(({ text, link }) => {
text, link;
}),
},
answers2
);
}
function askNewProjectGroupDetails() {
return inquirer.prompt([
{
name: "name",
message: "Title for the new project group",
},
{
name: "description",
message: "Description of the project group",
},
{
name: "data_file",
message: "name of the data file",
},
]);
}
const choices = ["Add a new project", "Create a new project group"];
const selection = (
await inquirer.prompt({
type: "list",
name: "choice_type",
message: "Choose an option to continue",
choices,
})
).choice_type;
if (selection === choices[0]) {
const { project_data_file } = await getProjectGroupFromUser();
let newProjectDetails = await askNewProjectDetails();
let projects = getProjectDetails(project_data_file);
projects.push(newProjectDetails);
updateProjectDetails(project_data_file, projects);
} else {
const newPGDetails = await askNewProjectGroupDetails();
let projectGroups = getProjectGroupDetails();
projectGroups.push(newPGDetails);
updateProjectGroupDetails(projectGroups);
closeSync(openSync(resolve("projects", newPGDetails.data_file), "a"));
}
updateReadMe();