-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.js
More file actions
167 lines (141 loc) · 4.86 KB
/
setup.js
File metadata and controls
167 lines (141 loc) · 4.86 KB
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
163
164
165
166
167
const fs = require('fs');
const path = require('path');
const bcrypt = require('bcrypt');
const readline = require('readline');
const DATA_DIR = path.join(__dirname, 'data');
// Create readline interface for user input
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
// Promisify readline question
function question(query) {
return new Promise(resolve => rl.question(query, resolve));
}
// Ensure data directory exists
function ensureDataDirectory() {
if (!fs.existsSync(DATA_DIR)) {
fs.mkdirSync(DATA_DIR, { recursive: true });
console.log('✓ Created data directory');
}
}
// Create default links.json
function createDefaultLinks() {
const linksPath = path.join(DATA_DIR, 'links.json');
const defaultLinks = [
{
id: 'link-1',
label: 'GitHub',
url: 'https://github.com',
imageUrl: '',
order: 0,
active: true
},
{
id: 'link-2',
label: 'Twitter',
url: 'https://twitter.com',
imageUrl: '',
order: 1,
active: true
},
{
id: 'link-3',
label: 'LinkedIn',
url: 'https://linkedin.com',
imageUrl: '',
order: 2,
active: true
}
];
fs.writeFileSync(linksPath, JSON.stringify(defaultLinks, null, 2));
console.log('✓ Created links.json with sample data');
}
// Create default theme.json
function createDefaultTheme() {
const themePath = path.join(DATA_DIR, 'theme.json');
const defaultTheme = {
backgroundColor: '#f0f0f0',
backgroundImageUrl: '',
textColor: '#333333',
buttonColor: '#4a90e2',
buttonTextColor: '#ffffff'
};
fs.writeFileSync(themePath, JSON.stringify(defaultTheme, null, 2));
console.log('✓ Created theme.json with default settings');
}
// Create default profile.json
function createDefaultProfile() {
const profilePath = path.join(DATA_DIR, 'profile.json');
const defaultProfile = {
photoUrl: '',
bio: 'Welcome to my link sharing page! Find all my important links below.'
};
fs.writeFileSync(profilePath, JSON.stringify(defaultProfile, null, 2));
console.log('✓ Created profile.json with default profile');
}
// Create config.json with API keys
async function createConfig() {
const configPath = path.join(DATA_DIR, 'config.json');
console.log('\n--- The Noun Project API Configuration (Optional) ---');
console.log('To enable icon selection features, you need API credentials from The Noun Project.');
console.log('Visit https://thenounproject.com/developers/ to get your API key and secret.');
console.log('You can skip this step and configure it later from the admin panel.\n');
const apiKey = await question('Enter The Noun Project API key (or press Enter to skip): ');
const apiSecret = await question('Enter The Noun Project API secret (or press Enter to skip): ');
const configData = {
nounProjectApiKey: apiKey.trim() || '',
nounProjectApiSecret: apiSecret.trim() || ''
};
fs.writeFileSync(configPath, JSON.stringify(configData, null, 2));
if (apiKey.trim() && apiSecret.trim()) {
console.log('✓ Created config.json with API credentials');
} else {
console.log('✓ Created config.json (API credentials not configured)');
console.log(' You can add them later from the admin panel');
}
}
// Create auth.json with admin credentials
async function createAdminCredentials() {
const authPath = path.join(DATA_DIR, 'auth.json');
console.log('\n--- Admin Account Setup ---');
const username = await question('Enter admin username (default: admin): ');
const password = await question('Enter admin password (default: admin123): ');
const finalUsername = username.trim() || 'admin';
const finalPassword = password.trim() || 'admin123';
// Hash the password
const passwordHash = await bcrypt.hash(finalPassword, 10);
const authData = {
username: finalUsername,
passwordHash: passwordHash
};
fs.writeFileSync(authPath, JSON.stringify(authData, null, 2));
console.log('✓ Created auth.json with admin credentials');
console.log(` Username: ${finalUsername}`);
console.log(` Password: ${finalPassword}`);
}
// Main setup function
async function setup() {
console.log('=== Link Sharing Page Setup ===\n');
try {
ensureDataDirectory();
createDefaultLinks();
createDefaultTheme();
createDefaultProfile();
await createAdminCredentials();
await createConfig();
console.log('\n✓ Setup complete!');
console.log('\nNext steps:');
console.log('1. Run "npm start" to start the server');
console.log('2. Visit http://localhost:3000 to view the landing page');
console.log('3. Visit http://localhost:3000/login.html to access the admin panel');
console.log('\nNote: Keep your admin credentials secure!');
} catch (error) {
console.error('\n✗ Setup failed:', error.message);
process.exit(1);
} finally {
rl.close();
}
}
// Run setup
setup();