Skip to content

Commit

Permalink
[feat]: Log only outDir path (#228)
Browse files Browse the repository at this point in the history
* print only from outDir and onwards

* Create .gitignore
  • Loading branch information
vasfvitor authored Nov 29, 2023
1 parent fe8d2f2 commit 8e493f0
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 7 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules/
8 changes: 8 additions & 0 deletions Source/Function/Integration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
* @module Integration
*
*/
export let systemDir: string;

export default ((...[_Option = {}]: Parameters<Type>) => {
Object.entries(_Option).forEach(([Key, Value]) =>
Object.defineProperty(_Option, Key, {
Expand Down Expand Up @@ -46,6 +48,12 @@ export default ((...[_Option = {}]: Parameters<Type>) => {
return {
name: "astro-compress",
hooks: {
"astro:config:done": async (options) => {
const { dir } = (await import("node:path")).parse(options.config.outDir.pathname);
// normalize slash and remove leading slash that always appears (conditional just in case)
systemDir = dir.replace(/\\/g, '/');
if (systemDir.startsWith("/")) { systemDir = systemDir.substring(1) }
},
"astro:build:done": async ({ dir }) => {
console.log(
`\n${(await import("kleur")).bgGreen(
Expand Down
27 changes: 20 additions & 7 deletions Source/Variable/Option.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,19 @@
*/
import { blue, green } from "kleur/colors";

import { systemDir } from "../Function/Integration";
import path from "node:path";
function sanitizePath(inputPath: string): { base: string, dir: string } {
let { base, dir } = path.parse(inputPath);
dir = path.normalize(dir)
dir = dir.replace(/\\/g, '/');
dir = dir.replace(systemDir, '');
if (!dir.endsWith("/")) {
dir = dir + '/'
}
return { base, dir };
}

export default (
await import("typescript-esbuild/Target/Function/Merge.js")
).default((await import("files-pipe/Target/Variable/Option.js")).default, {
Expand All @@ -28,17 +41,17 @@ export default (
Parser: (await import("./Parser.js")).default,
Action: {
Failed: async ({ Input }) => {
const idx = Input.lastIndexOf("/");

const { base, dir } = sanitizePath(Input);
return `${red("Error:")} Cannot compress file ${gray(
Input.slice(0, idx + 1)
)}${red(Input.slice(idx + 1))}`;
dir
)}${red(base)}`;
},
Passed: async ({ Before, Buffer: _Buffer }) =>
Before > Buffer.byteLength(_Buffer.toString()),
Accomplished: async ({ Input, Before, After }) => {
const { base, dir } = sanitizePath(Input);

const compressed = Before - After;
const idx = Input.lastIndexOf("/");

console.log("├─ ");

Expand All @@ -48,8 +61,8 @@ export default (
).default(compressed)})`
)} ${green(
`${((compressed / Before) * 100).toFixed(2)}%`
)} reduction in ${gray(Input.slice(0, idx + 1))}${blue(
Input.slice(idx + 1)
)} reduction in ${gray(dir)}${blue(
base
)}`;

return msg;
Expand Down

0 comments on commit 8e493f0

Please sign in to comment.