mirror of
https://github.com/sailor-sh/CK-X.git
synced 2026-07-11 00:29:20 +00:00
35 lines
941 B
JavaScript
35 lines
941 B
JavaScript
const fs = require('fs');
|
|
const path = require('path');
|
|
|
|
class PublicService {
|
|
constructor(publicDir) {
|
|
this.publicDir = publicDir;
|
|
this.indexHtmlSrc = path.join(__dirname, '..', 'index.html');
|
|
this.indexHtmlDest = path.join(publicDir, 'index.html');
|
|
}
|
|
|
|
initialize() {
|
|
this.createPublicDirectory();
|
|
this.copyIndexHtml();
|
|
}
|
|
|
|
createPublicDirectory() {
|
|
if (!fs.existsSync(this.publicDir)) {
|
|
fs.mkdirSync(this.publicDir, { recursive: true });
|
|
console.log('Created public directory');
|
|
}
|
|
}
|
|
|
|
copyIndexHtml() {
|
|
if (fs.existsSync(this.indexHtmlSrc) && !fs.existsSync(this.indexHtmlDest)) {
|
|
fs.copyFileSync(this.indexHtmlSrc, this.indexHtmlDest);
|
|
console.log('Copied index.html to public directory');
|
|
}
|
|
}
|
|
|
|
getPublicDir() {
|
|
return this.publicDir;
|
|
}
|
|
}
|
|
|
|
module.exports = PublicService;
|