tailoring to my taste

This commit is contained in:
2024-08-09 15:58:14 +03:00
parent 422f0c1fc7
commit 29ceab6753
23 changed files with 4395 additions and 208 deletions

View File

@@ -1,48 +0,0 @@
import { Logger } from '../utils/logger.js';
import { buildScss } from './scss.js';
import { buildFonts } from './fonts.js';
import { buildTemplates } from './templates.js';
import { copyTo } from './copy-to.js';
import { restartService } from './restart-service.js';
import { extname } from 'path';
import browsersync from 'browser-sync';
import { optimizeCss } from './optimize-css.js';
const logger = new Logger('deploy', 'info', 'brightMagenta');
const sync = browsersync.create('lugit')
export async function deploy(srcPath, distPath, serverPath, serviceName, file = null, live = false) {
logger.info('Deploying...');
if(live && !sync.active) {
sync.init({
proxy: 'http://lugit.local',
port: 8080,
})
}
let shouldRestart = true;
// check if it's an scss
if (file !== null && file !== undefined && extname(file) === '.scss') {
shouldRestart = false;
}
try {
await buildScss(srcPath, distPath).then(() => optimizeCss(distPath));
await buildFonts(srcPath, distPath);
// await buildImg(srcPath, distPath);
await buildTemplates(srcPath, distPath);
await copyTo(distPath, serverPath);
shouldRestart && await restartService(serviceName);
if(!shouldRestart && live) {
sync.reload();
}
logger.info('Deployment successful!');
} catch (error) {
logger.error(`Deployment failed: ${error}`);
}
}

View File

@@ -1,31 +0,0 @@
import { exec } from 'child_process';
import { Logger } from '../utils/logger.js';
const logger = new Logger(restartService.name, 'info', 'brightRed');
export async function restartService(serviceName) {
return new Promise((resolve, reject) => {
logger.info(`Restarting '${serviceName}' service...`);
let command;
let args;
if (process.platform === 'win32') {
command = 'cmd.exe';
args = ['/c', 'net', 'stop', serviceName, '&&', 'net', 'start', serviceName];
} else {
command = 'sudo';
args = ['systemctl', 'restart', serviceName];
}
exec(`${command} ${args.join(' ')}`, (error, stdout) => {
if (error) {
logger.error(`Failed to restart '${serviceName}' service: ${error}`);
reject(error);
} else {
logger.info(`'${serviceName}' service restarted!`);
resolve(stdout);
}
});
});
}