generated from peter-evans/swagger-github-pages
-
Notifications
You must be signed in to change notification settings - Fork 0
/
addService.js
72 lines (62 loc) · 3.36 KB
/
addService.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
const inquirer = require('inquirer');
const fs = require('fs');
const path = require('path');
// Define the location of the template
const versionTemplatePath = path.join(__dirname, 'utils', 'version_page_template.html');
const randomEmojis = [
'🔗', '📊', '💾', '🛡️', '☁️', '🖊️', '✅', '📈', '🔍', '👁️', '🚀', '⚙️', '🔧', '💡',
'🗄️', '💻', '🌐', '🔒', '📂', '📡', '🎛️', '🧩', '📜', '🛠️', '📱', '💬', '🛰️', '📦', '🌍',
'🔋', '📉', '🎯', '🏗️', '📥', '🗂️', '🧬', '🛎️', '📶', '📋', '📞', '📑', '🗃️', '🗳️', '🧑💻',
'🤖', '🔑', '🚧', '🗑️', '🔍', '🖥️', '🗨️', '🛍️', '📧', '📊', '⚡', '📠', '💾', '🔓', '🖱️',
'📮', '🛠', '🧪', '📅', '🖨️', '🖼️', '🌐', '📬', '📤', '📊', '⚖️', '🎚️', '🗝️', '📖', '🎬',
'🗒️', '💭', '🎛️', '📑', '💳', '📈', '💼', '💬', '⚖️', '🧲', '🛢️', '🔌', '🧯', '📙', '🔐',
'📨', '📤', '📡', '⚙️', '🏗️'
];
// Function to add new service
async function addNewService() {
try {
// Step 1: Get service name and optional emoji from user
const answers = await inquirer.prompt([
{
type: 'input',
name: 'serviceName',
message: 'Enter the service name:',
validate: input => input ? true : 'Service name cannot be empty!',
},
{
type: 'input',
name: 'emoji',
message: 'Enter an emoji for the service (optional):',
default: () => randomEmojis[Math.floor(Math.random() * randomEmojis.length)],
}
]);
const { serviceName, emoji } = answers;
const serviceFolder = path.join(__dirname, 'services', serviceName);
// Step 2: Append service info to hosted_services.csv
const csvPath = path.join(__dirname, 'hosted_services.csv');
const newServiceLine = `${serviceName},${emoji}\n`;
fs.appendFileSync(csvPath, newServiceLine);
console.log(`Service "${serviceName}" with emoji "${emoji}" added to hosted_services.csv.`);
// Step 3: Create folder inside services/ with the service name
if (!fs.existsSync(serviceFolder)) {
fs.mkdirSync(serviceFolder, { recursive: true });
console.log(`Folder created: ${serviceFolder}`);
} else {
console.log(`Folder already exists: ${serviceFolder}`);
}
// Step 4: Read template from utils/version_page_template.html and replace the service name
const versionTemplate = fs.readFileSync(versionTemplatePath, 'utf-8');
const indexContent = versionTemplate.replace(/{{SERVICE_NAME}}/g, serviceName);
const indexPath = path.join(serviceFolder, 'index.html');
fs.writeFileSync(indexPath, indexContent);
console.log(`File created: ${indexPath}`);
// Step 5: Create an empty hosted_versions.txt file in the same folder
const versionsFilePath = path.join(serviceFolder, 'hosted_versions.txt');
fs.writeFileSync(versionsFilePath, '');
console.log(`File created: ${versionsFilePath}`);
} catch (error) {
console.error('Error adding new service:', error);
}
}
// Run the CLI
addNewService();