-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
86 lines (65 loc) · 2.33 KB
/
app.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
const fs = require('fs');
const path = require('path');
// Get the folder name from the command-line argument.
const folderName = process.argv[2];
if (!folderName) {
console.error('Please provide a folder name as a command-line argument.');
process.exit(1);
}
// Function to create a unique project folder name.
function getUniqueFolderName(baseFolderName) {
let folderName = baseFolderName;
let count = 2;
while (fs.existsSync(folderName)) {
folderName = `${baseFolderName}${count}`;
count++;
}
return folderName;
}
// Create a unique project folder.
const projectFolder = getUniqueFolderName(folderName);
// Create frontend and backend folders.
const frontendFolder = path.join(projectFolder, 'frontend');
const backendFolder = path.join(projectFolder, 'backend');
fs.mkdirSync(projectFolder);
fs.mkdirSync(frontendFolder);
fs.mkdirSync(backendFolder);
// Create index.html content.
const indexHtmlContent = `<!-- Your html code goes here -->
<html>
<head>
<title>sample</title>
<link rel="stylesheet" type="text/css" href="style.css">
<script src="script.js"></script>
</head>
<body>
<p>Your project has been set up successfully</p>
</body>
</html>
`;
// Create index.html file in the frontend folder.
fs.writeFileSync(path.join(frontendFolder, 'index.html'), indexHtmlContent);
// Create style.css content.
const styleCssContent = `/* Your CSS styles go here */`;
// Create style.css file in the frontend folder.
fs.writeFileSync(path.join(frontendFolder, 'style.css'), styleCssContent);
// Create script.js content.
const scriptJsContent = `// Your JavaScript code goes here`;
// Create script.js file in the frontend folder.
fs.writeFileSync(path.join(frontendFolder, 'script.js'), scriptJsContent);
// Update app.js content to serve frontend files correctly.
const appJsContent = `// Your app.js file code goes here
const express = require('express');
const app = express();
const os = require('os');
const hostname = os.hostname();
const port = 3000;
app.use(express.static('frontend'));
app.listen(port, () => {
console.log('The server is running at ' + hostname + ':' + port);
});
`;
// Create app.js file in the backend folder.
fs.writeFileSync(path.join(backendFolder, 'app.js'), appJsContent);
// Log a success message.
console.log(`Your sample project has been set up successfully as "${projectFolder}"`);