Skip to content

Commit

Permalink
correction after runtime test 1
Browse files Browse the repository at this point in the history
  • Loading branch information
darsan-in committed Dec 17, 2024
1 parent c5e0cf2 commit d34562c
Show file tree
Hide file tree
Showing 11 changed files with 4,486 additions and 4,642 deletions.
2 changes: 1 addition & 1 deletion bin/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { terminate } from "../lib/utils";
import iconAssociator from "./iconAssociator";
import initConfig from "./initConfig";

import Minomax from "../minomax";
import { Minomax } from "../minomax";
const {
compressImages,
compressVideos,
Expand Down
4 changes: 2 additions & 2 deletions bin/iconAssociator.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { readFile, writeFile } from "fs/promises";
import { terminate } from "lib/utils";
import { copyFileSync, mkdirSync } from "node:fs";
import { readFile, writeFile } from "node:fs/promises";
import { dirname, join } from "node:path";
import { terminate } from "../lib/utils";

const defaultConfigPaths: Record<string, string> = {
win32: `${process.env.APPDATA}/Code/User/settings.json`,
Expand Down
19 changes: 19 additions & 0 deletions bin/user-config-template.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ const config = {
removeStyleLinkTypeAttributes: true,
removeTagWhitespace: true,
},
lookupPatterns: ["**/*.css", "**/*.js", "**/*.html", "**/*.htm"],
},
imageSetConfigurations: {
screenSizes: {
Expand All @@ -139,6 +140,24 @@ const config = {
upscaleLevel: "level2",
},
destPath: "./dist",
removeOld: true,
ignorePatterns: ["node_modules/**"],
imagePatterns: [
"**/*.png",
"**/*.jpg",
"**/*.jpeg",
"**/*.bmp",
"**/*.webp",
],
videoLookupPatterns: [
"**/*.mp4",
"**/*.webm",
"**/*.mkv",
"**/*.wmv",
"**/*.flv",
"**/*.avi",
"**/*.mov",
],
};

exports.default = config;
2 changes: 1 addition & 1 deletion configLoader.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { terminate } from "lib/utils";
import { existsSync } from "node:fs";
import { join } from "node:path";
import { ConfigurationOptions } from "./lib/types";
import { terminate } from "./lib/utils";

export default function loadConfig(): ConfigurationOptions {
const CONFIG_FILE_NAME = "minomax.config";
Expand Down
14 changes: 13 additions & 1 deletion lib/core/imageset/imageset.lib/cssrender.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import puppeteer, { type Browser, Page } from "puppeteer";
import { ImageSizeResponse } from "../../../types";
import { terminate } from "../../../utils";

async function _closeBrowser(browser: Browser) {
if (browser) {
Expand All @@ -15,10 +16,12 @@ async function _closeBrowser(browser: Browser) {

function _getImageSize({
page,
screenKey,
screenWidth,
selector,
}: {
page: Page;
screenKey: string;
screenWidth: number;
selector: string;
}): Promise<ImageSizeResponse> {
Expand All @@ -38,7 +41,11 @@ function _getImageSize({
};
}, selector);

resolve({ screenWidth: imageSize });
const result: Record<string, { width: number; height?: number }> =
{};
result[screenKey] = imageSize;

resolve(result);
} catch (err) {
reject(`Error calculating image size, at ${selector}\n${err}`);
}
Expand All @@ -61,7 +68,11 @@ export function getImageSizes(
headless: true,
args: ["--start-maximized"],
});
} catch (err) {
terminate({ reason: `Failed to launch browser, ${err}` });
}

try {
const page = await browser.newPage();

await page.goto(htmlPath, { timeout: 60000 });
Expand All @@ -74,6 +85,7 @@ export function getImageSizes(
(screenKey: string) => (): Promise<ImageSizeResponse> =>
_getImageSize({
page: page,
screenKey: screenKey,
screenWidth: screenSizes[screenKey],
selector: selector,
}),
Expand Down
8 changes: 6 additions & 2 deletions lib/core/imageset/imageset.lib/htmlparser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@ export default class HTMLParser {
// extracting src
let imageLink: string = htmlTree(tag).attr("src") || "";
if (!imageLink) {
terminate({ reason: "Image link not found in this img tag " + tag });
terminate({
reason: `Image link not found in this img tag at file: ${htmlfile} : ${htmlTree(
tag,
).html()} `,
});
} else {
imageLink = join(dirname(htmlfile), imageLink);
}
Expand Down Expand Up @@ -123,7 +127,7 @@ export default class HTMLParser {
const htmlTree: CheerioAPI = load(htmlContent);

//find img tags
const imgTags: any = htmlTree("img");
const imgTags: any = htmlTree("img")?.toArray() || false;

if (!imgTags) {
//close if it's no img tag
Expand Down
8 changes: 5 additions & 3 deletions lib/core/imageset/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ export default class ImageSetGenerator {

if (isAvif) {
console.log(
"Avif image source is not supported to make image sets, so skipping it.\n->\t" +
baseImagePath,
"⭕ Skipping: AVIF is not supported in image set generator\n->\t" +
relative(process.cwd(), baseImagePath),
);

continue;
Expand Down Expand Up @@ -117,7 +117,9 @@ export default class ImageSetGenerator {
);
}
} else {
console.log(`${baseImagePath} not existing so skipping it.`);
console.log(
`⭕ Skipping: ${relative(process.cwd(), baseImagePath)}`,
);
}
}

Expand Down
2 changes: 1 addition & 1 deletion minomax.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
} from "./lib/types";
import { copyFiles } from "./lib/utils";

export default class Minomax {
export class Minomax {
configurations: ConfigurationOptions;
#videoWorker: VideoWorker;
#imageWorker: ImageWorker;
Expand Down
4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,8 @@
"private": false,
"scripts": {
"dev": "cls && rimraf dist && tsc -p tscdev.json && ncp ./bin/user-config-template.js ./dist/bin/user-config-template.js",
"dr": "yarn dev && yarn rp",
"rp": "node ./dist/minomax.js",
"test": "jest",
"build": "cls && rimraf dist && tsc -p tsconfig.json && ncp ./bin/user-config-template.js ./dist/bin/user-config-template.js",
"test": "jest",
"clean": "cls && rimraf dist",
"deploy": "yarn test && yarn build && yarn publish --access public && git push"
},
Expand Down
9 changes: 6 additions & 3 deletions tscdev.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,16 @@
"noImplicitOverride": false,
"noUnusedParameters": true,
"noUncheckedIndexedAccess": false,
"sourceMap": false,
"sourceMap": true,
"removeComments": true,
"skipLibCheck": true
"skipLibCheck": true,
"declaration": true,
"declarationDir": "dist/types"
},
"exclude": [
"node_modules",
"test",
"jest.config.ts"
"jest.config.ts",
"dist"
]
}
Loading

0 comments on commit d34562c

Please sign in to comment.