From 851ed35880f090a7a4e8826b38064d442e95c473 Mon Sep 17 00:00:00 2001 From: Nikola Hristov Date: Thu, 9 Jan 2025 02:00:33 +0200 Subject: [PATCH] --- README.md | 28 ++++++++++++++-------------- Source/Function/Integration.ts | 2 +- Target/Function/Integration.js | 2 +- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index b18bdc23..a6bf3cef 100644 --- a/README.md +++ b/README.md @@ -45,19 +45,19 @@ the prompts: Using NPM: ```sh -npx astro add astro-compress +npx astro add @playform/compress ``` Using Yarn: ```sh -yarn astro add astro-compress +yarn astro add @playform/compress ``` Using PNPM: ```sh -pnpx astro add astro-compress +pnpx astro add @playform/compress ``` ### Install dependencies manually @@ -65,7 +65,7 @@ pnpx astro add astro-compress First, install the `Compress` integration like so: ```sh -npm install -D -E astro-compress +npm install -D -E @playform/compress ``` Then, apply this integration to your `astro.config.*` file using the @@ -75,7 +75,7 @@ Then, apply this integration to your `astro.config.*` file using the ```ts export default { - integrations: [(await import("astro-compress")).default()], + integrations: [(await import("@playform/compress")).default()], }; ``` @@ -124,7 +124,7 @@ You can override any of the default options from the configurations of: ```ts export default { integrations: [ - (await import("astro-compress")).default({ + (await import("@playform/compress")).default({ CSS: false, HTML: { "html-minifier-terser": { @@ -146,7 +146,7 @@ or disable them entirely: ```ts export default { integrations: [ - (await import("astro-compress")).default({ + (await import("@playform/compress")).default({ CSS: false, HTML: false, Image: false, @@ -169,7 +169,7 @@ it to compress a different directory you would have to add it to the `Compress` ```ts export default { integrations: [ - (await import("astro-compress")).default({ + (await import("@playform/compress")).default({ Path: ["./dist", "./Compress"], }), ], @@ -186,7 +186,7 @@ variable. ```ts export default { integrations: [ - (await import("astro-compress")).default({ + (await import("@playform/compress")).default({ Path: ["./Target", "./Build"], }), ], @@ -202,7 +202,7 @@ You can also provide a map of paths for different input output directories. ```ts export default { integrations: [ - (await import("astro-compress")).default({ + (await import("@playform/compress")).default({ Path: new Map([["./Source", "./Target"]]), }), ], @@ -216,7 +216,7 @@ Or an array of the two: ```ts export default { integrations: [ - (await import("astro-compress")).default({ + (await import("@playform/compress")).default({ Path: [ // Compress Target "./Target", @@ -239,7 +239,7 @@ match on file names: ```ts export default { integrations: [ - (await import("astro-compress")).default({ + (await import("@playform/compress")).default({ Exclude: [ "File.png", (File: string) => @@ -260,14 +260,14 @@ value is `2`, but you can set it to `0` if you don't want to see debug messages: ```ts export default { integrations: [ - (await import("astro-compress")).default({ + (await import("@playform/compress")).default({ Logger: 0, }), ], }; ``` -[Compress]: HTTPS://NPMJS.Org/astro-compress +[Compress]: HTTPS://NPMJS.Org/@playform/compress [csso]: HTTPS://NPMJS.Org/csso [lightningcss]: HTTPS://NPMJS.Org/lightningcss [html-minifier-terser]: HTTPS://NPMJS.Org/html-minifier-terser diff --git a/Source/Function/Integration.ts b/Source/Function/Integration.ts index a9597215..6a73cda7 100644 --- a/Source/Function/Integration.ts +++ b/Source/Function/Integration.ts @@ -57,7 +57,7 @@ export default ((...[_Option = {}]) => { } return { - name: "astro-compress", + name: "@playform/compress", hooks: { "astro:config:done": async ({ config: { diff --git a/Target/Function/Integration.js b/Target/Function/Integration.js index afa88d71..519ed3ae 100644 --- a/Target/Function/Integration.js +++ b/Target/Function/Integration.js @@ -1 +1 @@ -let d;var M=(...[p={}])=>{Object.entries(p).forEach(([a,r])=>Object.defineProperty(p,a,{value:r===!0?u[a]:p[a]}));const{Path:i,Cache:m,Logger:S,Map:h,Exclude:j,Action:w,CSS:b,HTML:A,Image:c,JavaScript:I,SVG:P,Parser:g}=n(u,p),f=new Set;return typeof i<"u"&&((Array.isArray(i)||i instanceof Set)&&i.forEach(a=>f.add(a)),i instanceof Map&&f.add(i)),typeof g=="object"&&Object.entries(g).forEach(([a,r])=>Object.defineProperty(g,a,{value:Array.isArray(r)?r:[r]})),{name:"astro-compress",hooks:{"astro:config:done":async({config:{outDir:{pathname:a}}})=>{d=(await import("path")).parse(a).dir.replace(/\\/g,"/"),d.startsWith("/")&&(d=d.substring(1))},"astro:build:done":async({dir:a})=>{if(typeof h=="object"){f.size===0&&f.add(a),typeof m=="object"&&m.Search===x&&(m.Search=a.toString());for(const[r,o]of Object.entries({CSS:b,HTML:A,Image:c,JavaScript:I,SVG:P}))if(!(!(o&&h[r])||typeof o!="object")){y=n(w,n(w,{Wrote:async({Buffer:t,Input:s})=>{switch(r){case"CSS":{let e=t.toString();try{o.lightningcss&&(e=(await import("lightningcss")).transform(n({code:(await import("buffer")).Buffer.from(e),filename:s},o.lightningcss)).code.toString()),o.csso&&(e=(await import("csso")).minify(e,o.csso).css)}catch(l){console.log(l)}return e}case"HTML":return await(await import("html-minifier-terser")).minify(t.toString(),o["html-minifier-terser"]);case"JavaScript":return(await(await import("terser")).minify(t.toString(),o.terser)).code??t;case"Image":try{return t instanceof(await import("sharp")).default?await(await import("./Image/Writesharp.js")).default(o.sharp,{Buffer:t,Input:s}):t}catch(e){return console.log(e),t}case"SVG":return(await import("svgo")).optimize(t.toString(),o.svgo).data??t;default:return t}},Fulfilled:async({File:t,Info:{Total:s}})=>t>0?`${(await import("kleur/colors")).green(`\u2713\u2001Successfully compressed a total of ${t} ${r} file${t!==1?"s":""} for ${(await import("@playform/pipe/Target/Function/Bytes.js")).default(s)}.`)}`:!1})),r==="Image"&&(y=n(y,{Read:async({Input:t,Buffer:s})=>{try{(await import("sharp")).default.cache(!1);const{format:e}=await(await import("sharp")).default(t).metadata(),l={animated:e==="webp"||e==="gif"};return(await import("sharp")).default(t,typeof c=="object"&&typeof c.sharp=="object"&&typeof c.sharp.sharp=="object"?n(l,c.sharp?.sharp):l)}catch(e){return console.log(e),s}}}));for(const t of f)await(await(await(await new(await import("@playform/pipe")).default(m,S).In(t)).By(h[r]??"**/*")).Not(j)).Pipe(y)}}}}}};const{default:u}=await import("../Variable/Option.js"),{default:{Cache:{Search:x}}}=await import("@playform/pipe/Target/Variable/Option.js"),{default:n}=await import("./Merge.js");let y;export{u as Default,n as Merge,x as Search,d as System,y as _Action,M as default}; +let y;var M=(...[p={}])=>{Object.entries(p).forEach(([a,r])=>Object.defineProperty(p,a,{value:r===!0?u[a]:p[a]}));const{Path:i,Cache:m,Logger:S,Map:h,Exclude:j,Action:w,CSS:b,HTML:A,Image:c,JavaScript:I,SVG:P,Parser:g}=n(u,p),f=new Set;return typeof i<"u"&&((Array.isArray(i)||i instanceof Set)&&i.forEach(a=>f.add(a)),i instanceof Map&&f.add(i)),typeof g=="object"&&Object.entries(g).forEach(([a,r])=>Object.defineProperty(g,a,{value:Array.isArray(r)?r:[r]})),{name:"@playform/compress",hooks:{"astro:config:done":async({config:{outDir:{pathname:a}}})=>{y=(await import("path")).parse(a).dir.replace(/\\/g,"/"),y.startsWith("/")&&(y=y.substring(1))},"astro:build:done":async({dir:a})=>{if(typeof h=="object"){f.size===0&&f.add(a),typeof m=="object"&&m.Search===x&&(m.Search=a.toString());for(const[r,o]of Object.entries({CSS:b,HTML:A,Image:c,JavaScript:I,SVG:P}))if(!(!(o&&h[r])||typeof o!="object")){d=n(w,n(w,{Wrote:async({Buffer:t,Input:s})=>{switch(r){case"CSS":{let e=t.toString();try{o.lightningcss&&(e=(await import("lightningcss")).transform(n({code:(await import("buffer")).Buffer.from(e),filename:s},o.lightningcss)).code.toString()),o.csso&&(e=(await import("csso")).minify(e,o.csso).css)}catch(l){console.log(l)}return e}case"HTML":return await(await import("html-minifier-terser")).minify(t.toString(),o["html-minifier-terser"]);case"JavaScript":return(await(await import("terser")).minify(t.toString(),o.terser)).code??t;case"Image":try{return t instanceof(await import("sharp")).default?await(await import("./Image/Writesharp.js")).default(o.sharp,{Buffer:t,Input:s}):t}catch(e){return console.log(e),t}case"SVG":return(await import("svgo")).optimize(t.toString(),o.svgo).data??t;default:return t}},Fulfilled:async({File:t,Info:{Total:s}})=>t>0?`${(await import("kleur/colors")).green(`\u2713\u2001Successfully compressed a total of ${t} ${r} file${t!==1?"s":""} for ${(await import("@playform/pipe/Target/Function/Bytes.js")).default(s)}.`)}`:!1})),r==="Image"&&(d=n(d,{Read:async({Input:t,Buffer:s})=>{try{(await import("sharp")).default.cache(!1);const{format:e}=await(await import("sharp")).default(t).metadata(),l={animated:e==="webp"||e==="gif"};return(await import("sharp")).default(t,typeof c=="object"&&typeof c.sharp=="object"&&typeof c.sharp.sharp=="object"?n(l,c.sharp?.sharp):l)}catch(e){return console.log(e),s}}}));for(const t of f)await(await(await(await new(await import("@playform/pipe")).default(m,S).In(t)).By(h[r]??"**/*")).Not(j)).Pipe(d)}}}}}};const{default:u}=await import("../Variable/Option.js"),{default:{Cache:{Search:x}}}=await import("@playform/pipe/Target/Variable/Option.js"),{default:n}=await import("./Merge.js");let d;export{u as Default,n as Merge,x as Search,y as System,d as _Action,M as default};