style: prettier

This commit is contained in:
2025-03-20 17:27:29 +03:00
parent a42fbb4fc6
commit c490d38d72
54 changed files with 1453 additions and 1107 deletions

View File

@ -16,7 +16,7 @@ function exit(err) {
if (err) {
console.error(err);
} else {
console.log('')
console.log('');
logger.info('Build completed successfully');
}

View File

@ -1,4 +1,4 @@
import { optimizeCss } from "./tasks/optimize-css.js";
import { optimizeCss } from './tasks/optimize-css.js';
import { cwd } from 'process';
import { join } from 'path';
@ -8,9 +8,10 @@ const distPath = join(cwd(), 'dist');
// useful to check issues with the css files optimization
// (in order to use this script, you need to first build the project removing the
// optimization step from the build.js file)
optimizeCss(distPath, false).then(() => {
console.log('Optimization completed');
}).catch((err) => {
console.error(err);
});
optimizeCss(distPath, false)
.then(() => {
console.log('Optimization completed');
})
.catch((err) => {
console.error(err);
});

View File

@ -30,12 +30,6 @@ const watcher = watch([`${src}/**/*`], {
ignoreInitial: true,
});
watcher.on('change', (file) => debouncer.add(
deploy,
srcPath,
distPath,
serverPath,
serviceName,
file,
true
));
watcher.on('change', (file) =>
debouncer.add(deploy, srcPath, distPath, serverPath, serviceName, file, true)
);

View File

@ -4,22 +4,29 @@ 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 { 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')
const sync = browsersync.create('lugit');
export async function deploy(srcPath, distPath, serverPath, serviceName, file = null, live = false) {
export async function deploy(
srcPath,
distPath,
serverPath,
serviceName,
file = null,
live = false
) {
logger.info('Deploying...');
if(live && !sync.active) {
if (live && !sync.active) {
sync.init({
proxy: 'http://lugit.local',
port: 8080,
})
});
}
let shouldRestart = true;
@ -34,10 +41,10 @@ export async function deploy(srcPath, distPath, serverPath, serviceName, file =
await buildFonts(srcPath, distPath);
// await buildImg(srcPath, distPath);
await buildTemplates(srcPath, distPath);
await copyTo(distPath, serverPath);
shouldRestart && await restartService(serviceName);
await copyTo(distPath, serverPath);
shouldRestart && (await restartService(serviceName));
if(!shouldRestart && live) {
if (!shouldRestart && live) {
sync.reload();
}

View File

@ -14,7 +14,9 @@ export async function buildFonts(srcHome, distHome) {
// if fontsSrcPath does not exist, return
if (!existsSync(fontsSrcPath)) {
logger.warn(`No fonts found in ${fontsSrcPath} (there's not even a folder there)`);
logger.warn(
`No fonts found in ${fontsSrcPath} (there's not even a folder there)`
);
return;
}

View File

@ -19,7 +19,7 @@ export async function buildImg(srcHome, distHome) {
mkdirSync(imgDestPath, { recursive: true });
const files = readFiles(imgSrcPath, ['.svg', '.png', '.jpg', '.webp', '.gif']);
// Separate logo.svg and favicon.svg from the rest
files.forEach((file) => {
if (file === 'logo.svg') {
@ -34,8 +34,8 @@ export async function buildImg(srcHome, distHome) {
await Promise.all([
processLogos(images.logos, imgDestPath),
processOthers(images.others, imgDestPath),
])
]);
logger.info('Images build has finished');
}
@ -53,7 +53,10 @@ async function processLogos(logos, distHome) {
promises.push(
generate(svg, join(distHome, 'favicon.svg'), { size: 32 }),
generate(svg, join(distHome, 'favicon.png'), { size: 180 }),
generate(svg, join(distHome, 'apple-touch-icon.png'), { size: 180, bg: true }),
generate(svg, join(distHome, 'apple-touch-icon.png'), {
size: 180,
bg: true,
}),
generate(svg, join(distHome, 'avatar_default.png'), { size: 200, bg: true })
);
}
@ -88,8 +91,7 @@ async function generate(svg, path, { size, bg }) {
const { objects, options } = await loadSvg(svg);
const canvas = new fabric.Canvas();
const newWidth = size * options.width / options.height;
const newWidth = (size * options.width) / options.height;
canvas.setDimensions({ width: newWidth, height: size });
const ctx = canvas.getContext('2d');
ctx.scale(
@ -126,4 +128,4 @@ async function processOthers(others, distHome) {
for (const img of others) {
copyFileSync(img, join(distHome, basename(img)));
}
}
}

View File

@ -25,7 +25,7 @@ export async function optimizeCss(distPath, replace = true) {
for (const file of cssFiles) {
logger.info(`Sanitizing ${file.name} css file`);
let usedCssVariables = [];
let usedCssVariables = [];
// read the css file
const cssContent = readFileSync(file.path, { encoding: 'utf-8' });
@ -45,8 +45,12 @@ export async function optimizeCss(distPath, replace = true) {
// could also be that the variable is assigned to another variable
if (node.type === 'Declaration' && node.property.startsWith('--')) {
// check if its assigned to another variable
if(node.property.startsWith('--')) {
if (node.value && node.value.type === 'Function' && node.value.name === 'var') {
if (node.property.startsWith('--')) {
if (
node.value &&
node.value.type === 'Function' &&
node.value.name === 'var'
) {
for (const child of node.value.children) {
if (child.type === 'Identifier') {
if (!usedCssVariables.includes(child.name)) {
@ -54,11 +58,15 @@ export async function optimizeCss(distPath, replace = true) {
}
}
}
} else if (node.value && node.value.type === 'Raw' && node.value.value) {
} else if (
node.value &&
node.value.type === 'Raw' &&
node.value.value
) {
const val = node.value.value.trimStart(); // var(--v-primary)
// if starts with var(, then its assigned to another variable or many variables, get everything that's inside
// var(...) using regex capturing
// var(...) using regex capturing
// get all varname groups
const matches = val.matchAll(/var\((?<varname>[^),\s]+)/g);
@ -72,7 +80,7 @@ export async function optimizeCss(distPath, replace = true) {
usedCssVariables.push(varname);
}
}
}
}
}
}

View File

@ -18,24 +18,21 @@ async function buildThemes(srcPath, distPath) {
quietDeps: true,
logger: {
debug: logger.simpleDebug.bind(logger),
info: logger.simpleInfo.bind(logger),
warn: logger.simpleWarn.bind(logger),
info: logger.simpleInfo.bind(logger),
warn: logger.simpleWarn.bind(logger),
error: logger.simpleError.bind(logger),
}
},
});
logger.debug(`Writing ${theme.name} theme to disk`);
writeFileSync(
join(distPath, cssDistPath, `theme-${theme.name}.css`),
result.css
);
writeFileSync(join(distPath, cssDistPath, `theme-${theme.name}.css`), result.css);
}
}
export async function buildScss(srcPath, distPath) {
logger.info('SCSS build has started');
mkdirSync(join(distPath, cssDistPath), { recursive: true });
await buildThemes(srcPath, distPath);
@ -44,12 +41,12 @@ export async function buildScss(srcPath, distPath) {
function getScssFiles(srcHome, path) {
try {
return readdirSync(join(srcHome, path)).filter(
(fn) => fn.endsWith('.scss') && !fn.startsWith('_')
).map((file) => ({
name: file.replace('.scss', ''),
path: join(srcHome, path, file),
}))
return readdirSync(join(srcHome, path))
.filter((fn) => fn.endsWith('.scss') && !fn.startsWith('_'))
.map((file) => ({
name: file.replace('.scss', ''),
path: join(srcHome, path, file),
}));
} catch (err) {
return [];
}

View File

@ -122,7 +122,6 @@ export async function sequence(tasks) {
return results;
}
async function tasksRunner(tasks, abort) {
let result = null;
for (const task of tasks) {
@ -144,19 +143,16 @@ export async function sequenceStream(tasks) {
console.log('sequenceStream aborted');
});
return [
tasksRunner(tasks, abort),
abort,
]
return [tasksRunner(tasks, abort), abort];
}
export const getArg = (flag, def) => {
const args = process.argv.slice(2);
const flagIndex = args.findIndex(arg => arg === flag);
const flagIndex = args.findIndex((arg) => arg === flag);
if (flagIndex !== -1 && flagIndex + 1 < args.length) {
return args[flagIndex + 1];
}
return def || null;
};
};

View File

@ -22,7 +22,7 @@ const ANSI_COLORS = {
brightBlue: '\x1b[94m',
brightMagenta: '\x1b[95m',
brightCyan: '\x1b[96m',
pink: '\x1b[38;2;255;182;193m'
pink: '\x1b[38;2;255;182;193m',
};
export class Logger {
@ -55,7 +55,6 @@ export class Logger {
warn(...args) {
if (!this.#canLog('warn')) return;
this.log('WARN', false, ...args);
}
error(...args) {
@ -91,7 +90,6 @@ export class Logger {
simpleWarn(...args) {
if (!this.#canLog('warn')) return;
this.log('WARN', true, ...args);
}
simpleError(...args) {