From 247f661f02f7a5ed37974253f18e39fcdd952799 Mon Sep 17 00:00:00 2001 From: vasfvitor Date: Tue, 28 Nov 2023 19:46:02 -0300 Subject: [PATCH 1/2] print only from outDir and onwards --- Source/Function/Integration.ts | 8 ++++++++ Source/Variable/Option.ts | 27 ++++++++++++++++++++------- 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/Source/Function/Integration.ts b/Source/Function/Integration.ts index 174d45ff..0d6c2d0f 100644 --- a/Source/Function/Integration.ts +++ b/Source/Function/Integration.ts @@ -2,6 +2,8 @@ * @module Integration * */ +export let systemDir: string; + export default ((...[_Option = {}]: Parameters) => { Object.entries(_Option).forEach(([Key, Value]) => Object.defineProperty(_Option, Key, { @@ -46,6 +48,12 @@ export default ((...[_Option = {}]: Parameters) => { 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( diff --git a/Source/Variable/Option.ts b/Source/Variable/Option.ts index 8587dd88..3dd6c405 100644 --- a/Source/Variable/Option.ts +++ b/Source/Variable/Option.ts @@ -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, { @@ -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("├─ "); @@ -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; From 1ddfb6e29800a307f6d15702fbfe79d79684fddd Mon Sep 17 00:00:00 2001 From: vasfvitor Date: Tue, 28 Nov 2023 20:01:08 -0300 Subject: [PATCH 2/2] Create .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..40b878db --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +node_modules/ \ No newline at end of file