style: prettier
This commit is contained in:
@ -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();
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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 [];
|
||||
}
|
||||
|
Reference in New Issue
Block a user